@@ -9,11 +9,11 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | $from_archive = false; |
| 11 | 11 | if (isset($_GET['ident'])) { |
| 12 | - $ident = filter_input(INPUT_GET,'ident',FILTER_SANITIZE_STRING); |
|
| 12 | + $ident = filter_input(INPUT_GET, 'ident', FILTER_SANITIZE_STRING); |
|
| 13 | 13 | if (isset($_GET['currenttime'])) { |
| 14 | - $currenttime = filter_input(INPUT_GET,'currenttime',FILTER_SANITIZE_NUMBER_INT); |
|
| 14 | + $currenttime = filter_input(INPUT_GET, 'currenttime', FILTER_SANITIZE_NUMBER_INT); |
|
| 15 | 15 | $currenttime = round($currenttime/1000); |
| 16 | - $spotter_array = $MarineLive->getDateLiveMarineDataByIdent($ident,$currenttime); |
|
| 16 | + $spotter_array = $MarineLive->getDateLiveMarineDataByIdent($ident, $currenttime); |
|
| 17 | 17 | /* |
| 18 | 18 | if (empty($spotter_array)) { |
| 19 | 19 | $from_archive = true; |
@@ -31,11 +31,11 @@ discard block |
||
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | 33 | if (isset($_GET['fammarine_id'])) { |
| 34 | - $fammarine_id = filter_input(INPUT_GET,'fammarine_id',FILTER_SANITIZE_STRING); |
|
| 34 | + $fammarine_id = filter_input(INPUT_GET, 'fammarine_id', FILTER_SANITIZE_STRING); |
|
| 35 | 35 | if (isset($_GET['currenttime'])) { |
| 36 | - $currenttime = filter_input(INPUT_GET,'currenttime',FILTER_SANITIZE_NUMBER_INT); |
|
| 36 | + $currenttime = filter_input(INPUT_GET, 'currenttime', FILTER_SANITIZE_NUMBER_INT); |
|
| 37 | 37 | $currenttime = round($currenttime/1000); |
| 38 | - $spotter_array = $MarineLive->getDateLiveMarineDataById($fammarine_id,$currenttime); |
|
| 38 | + $spotter_array = $MarineLive->getDateLiveMarineDataById($fammarine_id, $currenttime); |
|
| 39 | 39 | /* |
| 40 | 40 | if (empty($spotter_array)) { |
| 41 | 41 | $from_archive = true; |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | if (isset($spotter_item['image_thumbnail']) && $spotter_item['image_thumbnail'] != "") |
| 63 | 63 | { |
| 64 | 64 | if ($spotter_item['image_source'] == 'flickr' || $spotter_item['image_source'] == 'wikimedia' || $spotter_item['image_source'] == 'devianart') { |
| 65 | - $image = preg_replace("/^http:/i","https:",$spotter_item['image_thumbnail']); |
|
| 65 | + $image = preg_replace("/^http:/i", "https:", $spotter_item['image_thumbnail']); |
|
| 66 | 66 | } else $image = $spotter_item['image_thumbnail']; |
| 67 | 67 | |
| 68 | 68 | } |
@@ -63,7 +63,9 @@ |
||
| 63 | 63 | { |
| 64 | 64 | if ($spotter_item['image_source'] == 'flickr' || $spotter_item['image_source'] == 'wikimedia' || $spotter_item['image_source'] == 'devianart') { |
| 65 | 65 | $image = preg_replace("/^http:/i","https:",$spotter_item['image_thumbnail']); |
| 66 | - } else $image = $spotter_item['image_thumbnail']; |
|
| 66 | + } else { |
|
| 67 | + $image = $spotter_item['image_thumbnail']; |
|
| 68 | + } |
|
| 67 | 69 | |
| 68 | 70 | } |
| 69 | 71 | /* else { |
@@ -9,11 +9,11 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | $from_archive = false; |
| 11 | 11 | if (isset($_GET['ident'])) { |
| 12 | - $ident = filter_input(INPUT_GET,'ident',FILTER_SANITIZE_STRING); |
|
| 12 | + $ident = filter_input(INPUT_GET, 'ident', FILTER_SANITIZE_STRING); |
|
| 13 | 13 | if (isset($_GET['currenttime'])) { |
| 14 | - $currenttime = filter_input(INPUT_GET,'currenttime',FILTER_SANITIZE_NUMBER_INT); |
|
| 14 | + $currenttime = filter_input(INPUT_GET, 'currenttime', FILTER_SANITIZE_NUMBER_INT); |
|
| 15 | 15 | $currenttime = round($currenttime/1000); |
| 16 | - $spotter_array = $TrackerLive->getDateLiveTrackerDataByIdent($ident,$currenttime); |
|
| 16 | + $spotter_array = $TrackerLive->getDateLiveTrackerDataByIdent($ident, $currenttime); |
|
| 17 | 17 | /* |
| 18 | 18 | if (empty($spotter_array)) { |
| 19 | 19 | $from_archive = true; |
@@ -31,11 +31,11 @@ discard block |
||
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | 33 | if (isset($_GET['famtrackid'])) { |
| 34 | - $famtrackid = filter_input(INPUT_GET,'famtrackid',FILTER_SANITIZE_STRING); |
|
| 34 | + $famtrackid = filter_input(INPUT_GET, 'famtrackid', FILTER_SANITIZE_STRING); |
|
| 35 | 35 | if (isset($_GET['currenttime'])) { |
| 36 | - $currenttime = filter_input(INPUT_GET,'currenttime',FILTER_SANITIZE_NUMBER_INT); |
|
| 36 | + $currenttime = filter_input(INPUT_GET, 'currenttime', FILTER_SANITIZE_NUMBER_INT); |
|
| 37 | 37 | $currenttime = round($currenttime/1000); |
| 38 | - $spotter_array = $TrackerLive->getDateLiveTrackerDataById($famtrackid,$currenttime); |
|
| 38 | + $spotter_array = $TrackerLive->getDateLiveTrackerDataById($famtrackid, $currenttime); |
|
| 39 | 39 | /* |
| 40 | 40 | if (empty($spotter_array)) { |
| 41 | 41 | $from_archive = true; |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | if (isset($spotter_item['image_thumbnail']) && $spotter_item['image_thumbnail'] != "") |
| 63 | 63 | { |
| 64 | 64 | if ($spotter_item['image_source'] == 'flickr' || $spotter_item['image_source'] == 'wikimedia' || $spotter_item['image_source'] == 'devianart') { |
| 65 | - $image = preg_replace("/^http:/i","https:",$spotter_item['image_thumbnail']); |
|
| 65 | + $image = preg_replace("/^http:/i", "https:", $spotter_item['image_thumbnail']); |
|
| 66 | 66 | } else $image = $spotter_item['image_thumbnail']; |
| 67 | 67 | |
| 68 | 68 | } |
@@ -63,7 +63,9 @@ |
||
| 63 | 63 | { |
| 64 | 64 | if ($spotter_item['image_source'] == 'flickr' || $spotter_item['image_source'] == 'wikimedia' || $spotter_item['image_source'] == 'devianart') { |
| 65 | 65 | $image = preg_replace("/^http:/i","https:",$spotter_item['image_thumbnail']); |
| 66 | - } else $image = $spotter_item['image_thumbnail']; |
|
| 66 | + } else { |
|
| 67 | + $image = $spotter_item['image_thumbnail']; |
|
| 68 | + } |
|
| 67 | 69 | |
| 68 | 70 | } |
| 69 | 71 | /* else { |
@@ -68,6 +68,10 @@ discard block |
||
| 68 | 68 | 't', 'u', 'v', 'w' // 119 |
| 69 | 69 | ); // char 64 |
| 70 | 70 | */ |
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @param integer $ascii |
|
| 74 | + */ |
|
| 71 | 75 | private function asciidec_2_8bit($ascii) { |
| 72 | 76 | //only process in the following range: 48-87, 96-119 |
| 73 | 77 | if ($ascii < 48) { } |
@@ -93,6 +97,10 @@ discard block |
||
| 93 | 97 | return(substr($bin, -6)); |
| 94 | 98 | } |
| 95 | 99 | |
| 100 | + /** |
|
| 101 | + * @param integer $_start |
|
| 102 | + * @param integer $_size |
|
| 103 | + */ |
|
| 96 | 104 | private function binchar($_str, $_start, $_size) { |
| 97 | 105 | // ' ' --- '?', // 0x20 - 0x3F |
| 98 | 106 | // '@' --- '_', // 0x40 - 0x5F |
@@ -118,6 +126,10 @@ discard block |
||
| 118 | 126 | } |
| 119 | 127 | |
| 120 | 128 | // function for decoding the AIS Message ITU Payload |
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @param string $_aisdata |
|
| 132 | + */ |
|
| 121 | 133 | private function decode_ais($_aisdata) { |
| 122 | 134 | $ro = new stdClass(); // return object |
| 123 | 135 | $ro->cls = 0; // AIS class undefined, also indicate unparsed msg |
@@ -351,6 +363,12 @@ discard block |
||
| 351 | 363 | elseif ($code == 99) return 'Other Type, no additional information'; |
| 352 | 364 | } |
| 353 | 365 | |
| 366 | + /** |
|
| 367 | + * @param string $_itu |
|
| 368 | + * @param integer $_len |
|
| 369 | + * @param integer $_filler |
|
| 370 | + * @param string $aux |
|
| 371 | + */ |
|
| 354 | 372 | public function process_ais_itu($_itu, $_len, $_filler, $aux /*, $ais_ch*/) { |
| 355 | 373 | global $port; // tcpip port... |
| 356 | 374 | |
@@ -371,6 +389,10 @@ discard block |
||
| 371 | 389 | |
| 372 | 390 | // char* - AIS \r terminated string |
| 373 | 391 | // TCP based streams which send messages in full can use this instead of calling process_ais_buf |
| 392 | + |
|
| 393 | + /** |
|
| 394 | + * @param string $rawdata |
|
| 395 | + */ |
|
| 374 | 396 | public function process_ais_raw($rawdata, $aux = '') { // return int |
| 375 | 397 | static $num_seq; // 1 to 9 |
| 376 | 398 | static $seq; // 1 to 9 |
@@ -589,6 +611,9 @@ discard block |
||
| 589 | 611 | return $result; |
| 590 | 612 | } |
| 591 | 613 | |
| 614 | + /** |
|
| 615 | + * @param string $mmsi |
|
| 616 | + */ |
|
| 592 | 617 | public function mmsitype($mmsi) { |
| 593 | 618 | if (strlen($mmsi) == 9) { |
| 594 | 619 | if (substr($mmsi,0,3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS'; |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | return ($dec); |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - /* |
|
| 60 | + /* |
|
| 61 | 61 | $ais_map64 = array( |
| 62 | 62 | '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', // 48 |
| 63 | 63 | ':', ';', '<', '=', '>', '?', '@', 'A', 'B', 'C', |
@@ -97,13 +97,13 @@ discard block |
||
| 97 | 97 | // ' ' --- '?', // 0x20 - 0x3F |
| 98 | 98 | // '@' --- '_', // 0x40 - 0x5F |
| 99 | 99 | $ais_chars = array( |
| 100 | - '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', |
|
| 101 | - 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', |
|
| 102 | - 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', |
|
| 103 | - '^', '_', ' ', '!', '\"', '#', '$', '%', '&', '\'', |
|
| 104 | - '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', |
|
| 105 | - '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', |
|
| 106 | - '<', '=', '>', '?' |
|
| 100 | + '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', |
|
| 101 | + 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', |
|
| 102 | + 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', |
|
| 103 | + '^', '_', ' ', '!', '\"', '#', '$', '%', '&', '\'', |
|
| 104 | + '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', |
|
| 105 | + '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', |
|
| 106 | + '<', '=', '>', '?' |
|
| 107 | 107 | ); |
| 108 | 108 | // " |
| 109 | 109 | $rv = ''; |
@@ -419,8 +419,8 @@ discard block |
||
| 419 | 419 | } |
| 420 | 420 | if ($num_seq > 1) { // for multipart messages |
| 421 | 421 | if ($cmsg_sid != $msg_sid // different msg_sid |
| 422 | - || $msg_sid == -1 // invalid initial msg_sid |
|
| 423 | - || ($seq - $pseq) != 1 // not insequence |
|
| 422 | + || $msg_sid == -1 // invalid initial msg_sid |
|
| 423 | + || ($seq - $pseq) != 1 // not insequence |
|
| 424 | 424 | ) { // invalid for multipart message |
| 425 | 425 | $msg_sid = -1; |
| 426 | 426 | $cmsg_sid = -1; |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | $itu = $itu.$pcs[5]; // get itu message |
| 434 | 434 | $filler += (int)$pcs[6][0]; // get filler |
| 435 | 435 | if ($num_seq == 1 // valid single message |
| 436 | - || $num_seq == $pseq // valid multi-part message |
|
| 436 | + || $num_seq == $pseq // valid multi-part message |
|
| 437 | 437 | ) { |
| 438 | 438 | if ($num_seq != 1) { // test |
| 439 | 439 | //echo $rawdata; |
@@ -516,13 +516,13 @@ discard block |
||
| 516 | 516 | else $pad = ''; |
| 517 | 517 | $rv = ''; |
| 518 | 518 | $ais_chars = array( |
| 519 | - '@'=>0, 'A'=>1, 'B'=>2, 'C'=>3, 'D'=>4, 'E'=>5, 'F'=>6, 'G'=>7, 'H'=>8, 'I'=>9, |
|
| 520 | - 'J'=>10, 'K'=>11, 'L'=>12, 'M'=>13, 'N'=>14, 'O'=>15, 'P'=>16, 'Q'=>17, 'R'=>18, 'S'=>19, |
|
| 521 | - 'T'=>20, 'U'=>21, 'V'=>22, 'W'=>23, 'X'=>24, 'Y'=>25, 'Z'=>26, '['=>27, '\\'=>28, ']'=>29, |
|
| 522 | - '^'=>30, '_'=>31, ' '=>32, '!'=>33, '\"'=>34, '#'=>35, '$'=>36, '%'=>37, '&'=>38, '\''=>39, |
|
| 523 | - '('=>40, ')'=>41, '*'=>42, '+'=>43, ','=>44, '-'=>45, '.'=>46, '/'=>47, '0'=>48, '1'=>49, |
|
| 524 | - '2'=>50, '3'=>51, '4'=>52, '5'=>53, '6'=>54, '7'=>55, '8'=>56, '9'=>57, ':'=>58, ';'=>59, |
|
| 525 | - '<'=>60, '='=>61, '>'=>62, '?'=>63 |
|
| 519 | + '@'=>0, 'A'=>1, 'B'=>2, 'C'=>3, 'D'=>4, 'E'=>5, 'F'=>6, 'G'=>7, 'H'=>8, 'I'=>9, |
|
| 520 | + 'J'=>10, 'K'=>11, 'L'=>12, 'M'=>13, 'N'=>14, 'O'=>15, 'P'=>16, 'Q'=>17, 'R'=>18, 'S'=>19, |
|
| 521 | + 'T'=>20, 'U'=>21, 'V'=>22, 'W'=>23, 'X'=>24, 'Y'=>25, 'Z'=>26, '['=>27, '\\'=>28, ']'=>29, |
|
| 522 | + '^'=>30, '_'=>31, ' '=>32, '!'=>33, '\"'=>34, '#'=>35, '$'=>36, '%'=>37, '&'=>38, '\''=>39, |
|
| 523 | + '('=>40, ')'=>41, '*'=>42, '+'=>43, ','=>44, '-'=>45, '.'=>46, '/'=>47, '0'=>48, '1'=>49, |
|
| 524 | + '2'=>50, '3'=>51, '4'=>52, '5'=>53, '6'=>54, '7'=>55, '8'=>56, '9'=>57, ':'=>58, ';'=>59, |
|
| 525 | + '<'=>60, '='=>61, '>'=>62, '?'=>63 |
|
| 526 | 526 | ); |
| 527 | 527 | // " |
| 528 | 528 | $_a = str_split($name); |
@@ -29,31 +29,31 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | private function make_latf($temp) { // unsigned long |
| 31 | 31 | $flat = 0.0; // float |
| 32 | - $temp = $temp & 0x07FFFFFF; |
|
| 33 | - if ($temp & 0x04000000) { |
|
| 34 | - $temp = $temp ^ 0x07FFFFFF; |
|
| 32 | + $temp = $temp&0x07FFFFFF; |
|
| 33 | + if ($temp&0x04000000) { |
|
| 34 | + $temp = $temp^0x07FFFFFF; |
|
| 35 | 35 | $temp += 1; |
| 36 | - $flat = (float)($temp / (60.0 * 10000.0)); |
|
| 36 | + $flat = (float) ($temp/(60.0*10000.0)); |
|
| 37 | 37 | $flat *= -1.0; |
| 38 | - } else $flat = (float)($temp / (60.0 * 10000.0)); |
|
| 38 | + } else $flat = (float) ($temp/(60.0*10000.0)); |
|
| 39 | 39 | return $flat; // float |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | private function make_lonf($temp) { // unsigned long |
| 43 | 43 | $flon = 0.0; // float |
| 44 | - $temp = $temp & 0x0FFFFFFF; |
|
| 45 | - if ($temp & 0x08000000) { |
|
| 46 | - $temp = $temp ^ 0x0FFFFFFF; |
|
| 44 | + $temp = $temp&0x0FFFFFFF; |
|
| 45 | + if ($temp&0x08000000) { |
|
| 46 | + $temp = $temp^0x0FFFFFFF; |
|
| 47 | 47 | $temp += 1; |
| 48 | - $flon = (float)($temp / (60.0 * 10000.0)); |
|
| 48 | + $flon = (float) ($temp/(60.0*10000.0)); |
|
| 49 | 49 | $flon *= -1.0; |
| 50 | - } else $flon = (float)($temp / (60.0 * 10000.0)); |
|
| 50 | + } else $flon = (float) ($temp/(60.0*10000.0)); |
|
| 51 | 51 | return $flon; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | private function ascii_2_dec($chr) { |
| 55 | - $dec=ord($chr);//get decimal ascii code |
|
| 56 | - $hex=dechex($dec);//convert decimal to hex |
|
| 55 | + $dec = ord($chr); //get decimal ascii code |
|
| 56 | + $hex = dechex($dec); //convert decimal to hex |
|
| 57 | 57 | return ($dec); |
| 58 | 58 | } |
| 59 | 59 | |
@@ -72,15 +72,15 @@ discard block |
||
| 72 | 72 | //only process in the following range: 48-87, 96-119 |
| 73 | 73 | if ($ascii < 48) { } |
| 74 | 74 | else { |
| 75 | - if($ascii>119) { } |
|
| 75 | + if ($ascii > 119) { } |
|
| 76 | 76 | else { |
| 77 | - if ($ascii>87 && $ascii<96) ; |
|
| 77 | + if ($ascii > 87 && $ascii < 96); |
|
| 78 | 78 | else { |
| 79 | - $ascii=$ascii+40; |
|
| 80 | - if ($ascii>128){ |
|
| 81 | - $ascii=$ascii+32; |
|
| 79 | + $ascii = $ascii + 40; |
|
| 80 | + if ($ascii > 128) { |
|
| 81 | + $ascii = $ascii + 32; |
|
| 82 | 82 | } else { |
| 83 | - $ascii=$ascii+40; |
|
| 83 | + $ascii = $ascii + 40; |
|
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | 86 | } |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | private function dec_2_6bit($dec) { |
| 92 | - $bin=decbin($dec); |
|
| 92 | + $bin = decbin($dec); |
|
| 93 | 93 | return(substr($bin, -6)); |
| 94 | 94 | } |
| 95 | 95 | |
@@ -107,11 +107,11 @@ discard block |
||
| 107 | 107 | ); |
| 108 | 108 | // " |
| 109 | 109 | $rv = ''; |
| 110 | - if ($_size % 6 == 0) { |
|
| 111 | - $len = $_size / 6; |
|
| 112 | - for ($i=0; $i<$len; $i++) { |
|
| 113 | - $offset = $i * 6; |
|
| 114 | - $rv .= $ais_chars[ bindec(substr($_str,$_start + $offset,6)) ]; |
|
| 110 | + if ($_size%6 == 0) { |
|
| 111 | + $len = $_size/6; |
|
| 112 | + for ($i = 0; $i < $len; $i++) { |
|
| 113 | + $offset = $i*6; |
|
| 114 | + $rv .= $ais_chars[bindec(substr($_str, $_start + $offset, 6))]; |
|
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | 117 | return $rv; |
@@ -138,93 +138,93 @@ discard block |
||
| 138 | 138 | $ro->eta_hour = ''; |
| 139 | 139 | $ro->eta_minute = ''; |
| 140 | 140 | $ro->ts = time(); |
| 141 | - $ro->id = bindec(substr($_aisdata,0,6)); |
|
| 142 | - $ro->mmsi = bindec(substr($_aisdata,8,30)); |
|
| 141 | + $ro->id = bindec(substr($_aisdata, 0, 6)); |
|
| 142 | + $ro->mmsi = bindec(substr($_aisdata, 8, 30)); |
|
| 143 | 143 | if ($ro->id >= 1 && $ro->id <= 3) { |
| 144 | - $ro->cog = bindec(substr($_aisdata,116,12))/10; |
|
| 145 | - $ro->sog = bindec(substr($_aisdata,50,10))/10; |
|
| 146 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,61,28))); |
|
| 147 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,89,27))); |
|
| 144 | + $ro->cog = bindec(substr($_aisdata, 116, 12))/10; |
|
| 145 | + $ro->sog = bindec(substr($_aisdata, 50, 10))/10; |
|
| 146 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 61, 28))); |
|
| 147 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 89, 27))); |
|
| 148 | 148 | $ro->cls = 1; // class A |
| 149 | 149 | } else if ($ro->id == 4) { |
| 150 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,79,28))); |
|
| 151 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,107,27))); |
|
| 150 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 79, 28))); |
|
| 151 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 107, 27))); |
|
| 152 | 152 | $ro->cls = 1; // class A |
| 153 | 153 | } else if ($ro->id == 5) { |
| 154 | - $ro->imo = bindec(substr($_aisdata,40,30)); |
|
| 155 | - $ro->callsign = $this->binchar($_aisdata,70,42); |
|
| 156 | - $ro->name = $this->binchar($_aisdata,112,120); |
|
| 157 | - $ro->typeid = bindec(substr($_aisdata,232,8)); |
|
| 154 | + $ro->imo = bindec(substr($_aisdata, 40, 30)); |
|
| 155 | + $ro->callsign = $this->binchar($_aisdata, 70, 42); |
|
| 156 | + $ro->name = $this->binchar($_aisdata, 112, 120); |
|
| 157 | + $ro->typeid = bindec(substr($_aisdata, 232, 8)); |
|
| 158 | 158 | $ro->type = $this->getShipType($ro->typeid); |
| 159 | 159 | //$ro->to_bow = bindec(substr($_aisdata,240,9)); |
| 160 | 160 | //$ro->to_stern = bindec(substr($_aisdata,249,9)); |
| 161 | 161 | //$ro->to_port = bindec(substr($_aisdata,258,6)); |
| 162 | 162 | //$ro->to_starboard = bindec(substr($_aisdata,264,6)); |
| 163 | - $ro->eta_month = bindec(substr($_aisdata,274,4)); |
|
| 164 | - $ro->eta_day = bindec(substr($_aisdata,278,5)); |
|
| 165 | - $ro->eta_hour = bindec(substr($_aisdata,283,5)); |
|
| 166 | - $ro->eta_minute = bindec(substr($_aisdata,288,6)); |
|
| 163 | + $ro->eta_month = bindec(substr($_aisdata, 274, 4)); |
|
| 164 | + $ro->eta_day = bindec(substr($_aisdata, 278, 5)); |
|
| 165 | + $ro->eta_hour = bindec(substr($_aisdata, 283, 5)); |
|
| 166 | + $ro->eta_minute = bindec(substr($_aisdata, 288, 6)); |
|
| 167 | 167 | //$ro->draught = bindec(substr($_aisdata,294,8)); |
| 168 | - $ro->destination = $this->binchar($_aisdata,302,120); |
|
| 168 | + $ro->destination = $this->binchar($_aisdata, 302, 120); |
|
| 169 | 169 | $ro->cls = 1; // class A |
| 170 | 170 | } else if ($ro->id == 9) { |
| 171 | 171 | // Search and Rescue aircraft position report |
| 172 | 172 | } else if ($ro->id == 18) { |
| 173 | - $ro->cog = bindec(substr($_aisdata,112,12))/10; |
|
| 174 | - $ro->sog = bindec(substr($_aisdata,46,10))/10; |
|
| 175 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,57,28))); |
|
| 176 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,85,27))); |
|
| 177 | - $ro->heading = bindec(substr($_aisdata,124,9)); |
|
| 173 | + $ro->cog = bindec(substr($_aisdata, 112, 12))/10; |
|
| 174 | + $ro->sog = bindec(substr($_aisdata, 46, 10))/10; |
|
| 175 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 57, 28))); |
|
| 176 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 85, 27))); |
|
| 177 | + $ro->heading = bindec(substr($_aisdata, 124, 9)); |
|
| 178 | 178 | if ($ro->heading == 511) $ro->heading = ''; |
| 179 | 179 | $ro->cls = 2; // class B |
| 180 | 180 | } else if ($ro->id == 19) { |
| 181 | - $ro->cog = bindec(substr($_aisdata,112,12))/10; |
|
| 182 | - $ro->sog = bindec(substr($_aisdata,46,10))/10; |
|
| 183 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,61,28))); |
|
| 184 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,89,27))); |
|
| 185 | - $ro->name = $this->binchar($_aisdata,143,120); |
|
| 181 | + $ro->cog = bindec(substr($_aisdata, 112, 12))/10; |
|
| 182 | + $ro->sog = bindec(substr($_aisdata, 46, 10))/10; |
|
| 183 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 61, 28))); |
|
| 184 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 89, 27))); |
|
| 185 | + $ro->name = $this->binchar($_aisdata, 143, 120); |
|
| 186 | 186 | $ro->cls = 2; // class B |
| 187 | - $ro->heading = bindec(substr($_aisdata,124,9)); |
|
| 187 | + $ro->heading = bindec(substr($_aisdata, 124, 9)); |
|
| 188 | 188 | if ($ro->heading == 511) $ro->heading = ''; |
| 189 | - $ro->typeid = bindec(substr($_aisdata,263,8)); |
|
| 189 | + $ro->typeid = bindec(substr($_aisdata, 263, 8)); |
|
| 190 | 190 | $ro->type = $this->getShipType($ro->typeid); |
| 191 | 191 | //$ro->to_bow = bindec(substr($_aisdata,271,9)); |
| 192 | 192 | //$ro->to_stern = bindec(substr($_aisdata,280,9)); |
| 193 | 193 | //$ro->to_port = bindec(substr($_aisdata,289,6)); |
| 194 | 194 | //$ro->to_starboard = bindec(substr($_aisdata,295,6)); |
| 195 | 195 | } else if ($ro->id == 21) { |
| 196 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,164,28))); |
|
| 197 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,192,27))); |
|
| 198 | - $ro->name = $this->binchar($_aisdata,43,120); |
|
| 196 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 164, 28))); |
|
| 197 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 192, 27))); |
|
| 198 | + $ro->name = $this->binchar($_aisdata, 43, 120); |
|
| 199 | 199 | //$ro->to_bow = bindec(substr($_aisdata,219,9)); |
| 200 | 200 | //$ro->to_stern = bindec(substr($_aisdata,228,9)); |
| 201 | 201 | //$ro->to_port = bindec(substr($_aisdata,237,6)); |
| 202 | 202 | //$ro->to_starboard = bindec(substr($_aisdata,243,6)); |
| 203 | 203 | $ro->cls = 2; // class B |
| 204 | 204 | } else if ($ro->id == 24) { |
| 205 | - $pn = bindec(substr($_aisdata,38,2)); |
|
| 205 | + $pn = bindec(substr($_aisdata, 38, 2)); |
|
| 206 | 206 | if ($pn == 0) { |
| 207 | - $ro->name = $this->binchar($_aisdata,40,120); |
|
| 207 | + $ro->name = $this->binchar($_aisdata, 40, 120); |
|
| 208 | 208 | } |
| 209 | - $ro->typeid = bindec(substr($_aisdata,40,8)); |
|
| 209 | + $ro->typeid = bindec(substr($_aisdata, 40, 8)); |
|
| 210 | 210 | $ro->type = $this->getShipType($ro->typeid); |
| 211 | - $ro->callsign = $this->binchar($_aisdata,90,42); |
|
| 211 | + $ro->callsign = $this->binchar($_aisdata, 90, 42); |
|
| 212 | 212 | //$ro->to_bow = bindec(substr($_aisdata,132,9)); |
| 213 | 213 | //$ro->to_stern = bindec(substr($_aisdata,141,9)); |
| 214 | 214 | //$ro->to_port = bindec(substr($_aisdata,150,6)); |
| 215 | 215 | //$ro->to_starboard = bindec(substr($_aisdata,156,6)); |
| 216 | 216 | $ro->cls = 2; // class B |
| 217 | 217 | } else if ($ro->id == 27) { |
| 218 | - $ro->cog = bindec(substr($_aisdata,85,9)); |
|
| 218 | + $ro->cog = bindec(substr($_aisdata, 85, 9)); |
|
| 219 | 219 | if ($ro->cog == 511) $ro->cog = 0.0; |
| 220 | - $ro->sog = bindec(substr($_aisdata,79,6)); |
|
| 220 | + $ro->sog = bindec(substr($_aisdata, 79, 6)); |
|
| 221 | 221 | if ($ro->sog == 63) $ro->sog = 0.0; |
| 222 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,44,18))*10); |
|
| 223 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,62,17))*10); |
|
| 222 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 44, 18))*10); |
|
| 223 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 62, 17))*10); |
|
| 224 | 224 | $ro->cls = 1; // class A |
| 225 | 225 | |
| 226 | 226 | } |
| 227 | - $ro->statusid = bindec(substr($_aisdata,38,4)); |
|
| 227 | + $ro->statusid = bindec(substr($_aisdata, 38, 4)); |
|
| 228 | 228 | $ro->status = $this->getStatus($ro->statusid); |
| 229 | 229 | //var_dump($ro); // dump results here for demo purpose |
| 230 | 230 | return $ro; |
@@ -355,14 +355,14 @@ discard block |
||
| 355 | 355 | global $port; // tcpip port... |
| 356 | 356 | |
| 357 | 357 | static $debug_counter = 0; |
| 358 | - $aisdata168='';//six bit array of ascii characters |
|
| 358 | + $aisdata168 = ''; //six bit array of ascii characters |
|
| 359 | 359 | $ais_nmea_array = str_split($_itu); // convert to an array |
| 360 | 360 | foreach ($ais_nmea_array as $value) { |
| 361 | 361 | $dec = $this->ascii_2_dec($value); |
| 362 | 362 | $bit8 = $this->asciidec_2_8bit($dec); |
| 363 | 363 | $bit6 = $this->dec_2_6bit($bit8); |
| 364 | 364 | //echo $value ."-" .$bit6 .""; |
| 365 | - $aisdata168 .=$bit6; |
|
| 365 | + $aisdata168 .= $bit6; |
|
| 366 | 366 | } |
| 367 | 367 | //echo $aisdata168 . "<br/>"; |
| 368 | 368 | //return $this->decode_ais($aisdata168, $aux); |
@@ -385,20 +385,20 @@ discard block |
||
| 385 | 385 | // calculate checksum after ! till * |
| 386 | 386 | // assume 1st ! is valid |
| 387 | 387 | // find * ensure that it is at correct position |
| 388 | - $end = strrpos ( $rawdata , '*' ); |
|
| 388 | + $end = strrpos($rawdata, '*'); |
|
| 389 | 389 | if ($end === FALSE) return -1; // check for NULLS!!! |
| 390 | - $cs = substr( $rawdata, $end + 1 ); |
|
| 391 | - if ( strlen($cs) != 2 ) return -1; // correct cs length |
|
| 392 | - $dcs = (int)hexdec( $cs ); |
|
| 393 | - for ( $alias=1; $alias<$end; $alias++) $chksum ^= ord( $rawdata[$alias] ); // perform XOR for NMEA checksum |
|
| 394 | - if ( $chksum == $dcs ) { // NMEA checksum pass |
|
| 390 | + $cs = substr($rawdata, $end + 1); |
|
| 391 | + if (strlen($cs) != 2) return -1; // correct cs length |
|
| 392 | + $dcs = (int) hexdec($cs); |
|
| 393 | + for ($alias = 1; $alias < $end; $alias++) $chksum ^= ord($rawdata[$alias]); // perform XOR for NMEA checksum |
|
| 394 | + if ($chksum == $dcs) { // NMEA checksum pass |
|
| 395 | 395 | $pcs = explode(',', $rawdata); |
| 396 | 396 | // !AI??? identifier |
| 397 | - $num_seq = (int)$pcs[1]; // number of sequences |
|
| 398 | - $seq = (int)$pcs[2]; // get sequence |
|
| 397 | + $num_seq = (int) $pcs[1]; // number of sequences |
|
| 398 | + $seq = (int) $pcs[2]; // get sequence |
|
| 399 | 399 | // get msg sequence id |
| 400 | 400 | if ($pcs[3] == '') $msg_sid = -1; // non-multipart message, set to -1 |
| 401 | - else $msg_sid = (int)$pcs[3]; // multipart message |
|
| 401 | + else $msg_sid = (int) $pcs[3]; // multipart message |
|
| 402 | 402 | $ais_ch = $pcs[4]; // get AIS channel |
| 403 | 403 | // message sequence checking |
| 404 | 404 | if ($num_seq < 1 || $num_seq > 9) { |
@@ -431,7 +431,7 @@ discard block |
||
| 431 | 431 | } |
| 432 | 432 | } |
| 433 | 433 | $itu = $itu.$pcs[5]; // get itu message |
| 434 | - $filler += (int)$pcs[6][0]; // get filler |
|
| 434 | + $filler += (int) $pcs[6][0]; // get filler |
|
| 435 | 435 | if ($num_seq == 1 // valid single message |
| 436 | 436 | || $num_seq == $pseq // valid multi-part message |
| 437 | 437 | ) { |
@@ -451,13 +451,13 @@ discard block |
||
| 451 | 451 | $cbuf = $cbuf.$ibuf; |
| 452 | 452 | $last_pos = 0; |
| 453 | 453 | $result = new stdClass(); |
| 454 | - while ( ($start = strpos($cbuf,"VDM",$last_pos)) !== FALSE) { |
|
| 454 | + while (($start = strpos($cbuf, "VDM", $last_pos)) !== FALSE) { |
|
| 455 | 455 | //while ( ($start = strpos($cbuf,"!AI",$last_pos)) !== FALSE) { |
| 456 | 456 | //DEBUG echo $cbuf; |
| 457 | - if ( ($end = strpos($cbuf,"\r\n", $start)) !== FALSE) { //TBD need to trim? |
|
| 457 | + if (($end = strpos($cbuf, "\r\n", $start)) !== FALSE) { //TBD need to trim? |
|
| 458 | 458 | $tst = substr($cbuf, $start - 3, ($end - $start + 3)); |
| 459 | 459 | //DEBUG echo "[$start $end $tst]\n"; |
| 460 | - $result = $this->process_ais_raw( $tst, "" ); |
|
| 460 | + $result = $this->process_ais_raw($tst, ""); |
|
| 461 | 461 | $last_pos = $end + 1; |
| 462 | 462 | } else break; |
| 463 | 463 | } |
@@ -469,41 +469,41 @@ discard block |
||
| 469 | 469 | // incoming data from serial or IP comms |
| 470 | 470 | public function process_ais_line($cbuf) { |
| 471 | 471 | $result = new stdClass(); |
| 472 | - $start = strpos($cbuf,"VDM"); |
|
| 472 | + $start = strpos($cbuf, "VDM"); |
|
| 473 | 473 | $tst = substr($cbuf, $start - 3); |
| 474 | - $result = $this->process_ais_raw( $tst, "" ); |
|
| 474 | + $result = $this->process_ais_raw($tst, ""); |
|
| 475 | 475 | return $result; |
| 476 | 476 | } |
| 477 | 477 | |
| 478 | 478 | /* AIS Encoding |
| 479 | 479 | */ |
| 480 | - private function mk_ais_lat( $lat ) { |
|
| 480 | + private function mk_ais_lat($lat) { |
|
| 481 | 481 | //$lat = 1.2569; |
| 482 | - if ($lat<0.0) { |
|
| 482 | + if ($lat < 0.0) { |
|
| 483 | 483 | $lat = -$lat; |
| 484 | - $neg=true; |
|
| 485 | - } else $neg=false; |
|
| 484 | + $neg = true; |
|
| 485 | + } else $neg = false; |
|
| 486 | 486 | $latd = 0x00000000; |
| 487 | - $latd = intval ($lat * 600000.0); |
|
| 488 | - if ($neg==true) { |
|
| 487 | + $latd = intval($lat*600000.0); |
|
| 488 | + if ($neg == true) { |
|
| 489 | 489 | $latd = ~$latd; |
| 490 | - $latd+=1; |
|
| 490 | + $latd += 1; |
|
| 491 | 491 | $latd &= 0x07FFFFFF; |
| 492 | 492 | } |
| 493 | 493 | return $latd; |
| 494 | 494 | } |
| 495 | 495 | |
| 496 | - private function mk_ais_lon( $lon ) { |
|
| 496 | + private function mk_ais_lon($lon) { |
|
| 497 | 497 | //$lon = 103.851; |
| 498 | - if ($lon<0.0) { |
|
| 498 | + if ($lon < 0.0) { |
|
| 499 | 499 | $lon = -$lon; |
| 500 | - $neg=true; |
|
| 501 | - } else $neg=false; |
|
| 500 | + $neg = true; |
|
| 501 | + } else $neg = false; |
|
| 502 | 502 | $lond = 0x00000000; |
| 503 | - $lond = intval ($lon * 600000.0); |
|
| 504 | - if ($neg==true) { |
|
| 503 | + $lond = intval($lon*600000.0); |
|
| 504 | + if ($neg == true) { |
|
| 505 | 505 | $lond = ~$lond; |
| 506 | - $lond+=1; |
|
| 506 | + $lond += 1; |
|
| 507 | 507 | $lond &= 0x0FFFFFFF; |
| 508 | 508 | } |
| 509 | 509 | return $lond; |
@@ -511,8 +511,8 @@ discard block |
||
| 511 | 511 | |
| 512 | 512 | private function char2bin($name, $max_len) { |
| 513 | 513 | $len = strlen($name); |
| 514 | - if ($len > $max_len) $name = substr($name,0,$max_len); |
|
| 515 | - if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len) * 6); |
|
| 514 | + if ($len > $max_len) $name = substr($name, 0, $max_len); |
|
| 515 | + if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len)*6); |
|
| 516 | 516 | else $pad = ''; |
| 517 | 517 | $rv = ''; |
| 518 | 518 | $ais_chars = array( |
@@ -529,26 +529,26 @@ discard block |
||
| 529 | 529 | if ($_a) foreach ($_a as $_1) { |
| 530 | 530 | if (isset($ais_chars[$_1])) $dec = $ais_chars[$_1]; |
| 531 | 531 | else $dec = 0; |
| 532 | - $bin = str_pad(decbin( $dec ), 6, '0', STR_PAD_LEFT); |
|
| 532 | + $bin = str_pad(decbin($dec), 6, '0', STR_PAD_LEFT); |
|
| 533 | 533 | $rv .= $bin; |
| 534 | 534 | //echo "$_1 $dec ($bin)<br/>"; |
| 535 | 535 | } |
| 536 | 536 | return $rv.$pad; |
| 537 | 537 | } |
| 538 | 538 | |
| 539 | - private function mk_ais($_enc, $_part=1,$_total=1,$_seq='',$_ch='A') { |
|
| 539 | + private function mk_ais($_enc, $_part = 1, $_total = 1, $_seq = '', $_ch = 'A') { |
|
| 540 | 540 | $len_bit = strlen($_enc); |
| 541 | - $rem6 = $len_bit % 6; |
|
| 541 | + $rem6 = $len_bit%6; |
|
| 542 | 542 | $pad6_len = 0; |
| 543 | 543 | if ($rem6) $pad6_len = 6 - $rem6; |
| 544 | 544 | //echo $pad6_len.'<br>'; |
| 545 | 545 | $_enc .= str_repeat("0", $pad6_len); // pad the text... |
| 546 | - $len_enc = strlen($_enc) / 6; |
|
| 546 | + $len_enc = strlen($_enc)/6; |
|
| 547 | 547 | //echo $_enc.' '.$len_enc.'<br/>'; |
| 548 | 548 | $itu = ''; |
| 549 | - for ($i=0; $i<$len_enc; $i++) { |
|
| 550 | - $offset = $i * 6; |
|
| 551 | - $dec = bindec(substr($_enc,$offset,6)); |
|
| 549 | + for ($i = 0; $i < $len_enc; $i++) { |
|
| 550 | + $offset = $i*6; |
|
| 551 | + $dec = bindec(substr($_enc, $offset, 6)); |
|
| 552 | 552 | if ($dec < 40) $dec += 48; |
| 553 | 553 | else $dec += 56; |
| 554 | 554 | //echo chr($dec)." $dec<br/>"; |
@@ -558,15 +558,15 @@ discard block |
||
| 558 | 558 | $chksum = 0; |
| 559 | 559 | $itu = "AIVDM,$_part,$_total,$_seq,$_ch,".$itu.",0"; |
| 560 | 560 | $len_itu = strlen($itu); |
| 561 | - for ($i=0; $i<$len_itu; $i++) { |
|
| 562 | - $chksum ^= ord( $itu[$i] ); |
|
| 561 | + for ($i = 0; $i < $len_itu; $i++) { |
|
| 562 | + $chksum ^= ord($itu[$i]); |
|
| 563 | 563 | } |
| 564 | - $hex_arr = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); |
|
| 565 | - $lsb = $chksum & 0x0F; |
|
| 566 | - if ($lsb >=0 && $lsb <= 15 ) $lsbc = $hex_arr[$lsb]; |
|
| 564 | + $hex_arr = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); |
|
| 565 | + $lsb = $chksum&0x0F; |
|
| 566 | + if ($lsb >= 0 && $lsb <= 15) $lsbc = $hex_arr[$lsb]; |
|
| 567 | 567 | else $lsbc = '0'; |
| 568 | - $msb = (($chksum & 0xF0) >> 4) & 0x0F; |
|
| 569 | - if ($msb >=0 && $msb <= 15 ) $msbc = $hex_arr[$msb]; |
|
| 568 | + $msb = (($chksum&0xF0) >> 4)&0x0F; |
|
| 569 | + if ($msb >= 0 && $msb <= 15) $msbc = $hex_arr[$msb]; |
|
| 570 | 570 | else $msbc = '0'; |
| 571 | 571 | $itu = '!'.$itu."*{$msbc}{$lsbc}\r\n"; |
| 572 | 572 | return $itu; |
@@ -591,14 +591,14 @@ discard block |
||
| 591 | 591 | |
| 592 | 592 | public function mmsitype($mmsi) { |
| 593 | 593 | if (strlen($mmsi) == 9) { |
| 594 | - if (substr($mmsi,0,3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS'; |
|
| 595 | - elseif (substr($mmsi,0,3) == '972') return 'MOB (Man Overboard) device'; |
|
| 596 | - elseif (substr($mmsi,0,3) == '970') return 'AIS SART (Search and Rescue Transmitter)'; |
|
| 597 | - elseif (substr($mmsi,0,3) == '111') return 'SAR (Search and Rescue) aircraft'; |
|
| 598 | - elseif (substr($mmsi,0,2) == '98') return 'Auxiliary craft associated with a parent ship'; |
|
| 599 | - elseif (substr($mmsi,0,2) == '99') return 'Aids to Navigation'; |
|
| 600 | - elseif (substr($mmsi,0,2) == '00') return 'Coastal stations'; |
|
| 601 | - elseif (substr($mmsi,0,1) == '0') return 'Group of ships'; |
|
| 594 | + if (substr($mmsi, 0, 3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS'; |
|
| 595 | + elseif (substr($mmsi, 0, 3) == '972') return 'MOB (Man Overboard) device'; |
|
| 596 | + elseif (substr($mmsi, 0, 3) == '970') return 'AIS SART (Search and Rescue Transmitter)'; |
|
| 597 | + elseif (substr($mmsi, 0, 3) == '111') return 'SAR (Search and Rescue) aircraft'; |
|
| 598 | + elseif (substr($mmsi, 0, 2) == '98') return 'Auxiliary craft associated with a parent ship'; |
|
| 599 | + elseif (substr($mmsi, 0, 2) == '99') return 'Aids to Navigation'; |
|
| 600 | + elseif (substr($mmsi, 0, 2) == '00') return 'Coastal stations'; |
|
| 601 | + elseif (substr($mmsi, 0, 1) == '0') return 'Group of ships'; |
|
| 602 | 602 | else return 'Ship'; |
| 603 | 603 | } |
| 604 | 604 | |
@@ -609,19 +609,19 @@ discard block |
||
| 609 | 609 | global $globalDebug; |
| 610 | 610 | $result = array(); |
| 611 | 611 | $data = new stdClass(); |
| 612 | - $start = strpos($buffer,"VDM"); |
|
| 612 | + $start = strpos($buffer, "VDM"); |
|
| 613 | 613 | $tst = substr($buffer, $start - 3); |
| 614 | - $data = $this->process_ais_raw( $tst, "" ); |
|
| 614 | + $data = $this->process_ais_raw($tst, ""); |
|
| 615 | 615 | if (!is_object($data)) { |
| 616 | 616 | //if ($globalDebug) echo '==== Line format not supported : '.$buffer."\n"; |
| 617 | 617 | return array(); |
| 618 | 618 | } |
| 619 | 619 | if ($data->lon != 0) $result['longitude'] = $data->lon; |
| 620 | 620 | if ($data->lat != 0) $result['latitude'] = $data->lat; |
| 621 | - $result['ident'] = trim(str_replace('@','',$data->name)); |
|
| 621 | + $result['ident'] = trim(str_replace('@', '', $data->name)); |
|
| 622 | 622 | $result['timestamp'] = $data->ts; |
| 623 | 623 | $result['mmsi'] = $data->mmsi; |
| 624 | - if (strlen($result['mmsi']) == 8 && substr($result['mmsi'],0,3) == '669') $result['mmsi'] = '3'.$result['mmsi']; |
|
| 624 | + if (strlen($result['mmsi']) == 8 && substr($result['mmsi'], 0, 3) == '669') $result['mmsi'] = '3'.$result['mmsi']; |
|
| 625 | 625 | $result['mmsi_type'] = $this->mmsitype($result['mmsi']); |
| 626 | 626 | if ($data->sog != -1.0) $result['speed'] = $data->sog; |
| 627 | 627 | if ($data->heading !== '') $result['heading'] = $data->heading; |
@@ -631,16 +631,16 @@ discard block |
||
| 631 | 631 | if ($data->type !== '') $result['type'] = $data->type; |
| 632 | 632 | if ($data->typeid !== '') $result['typeid'] = $data->typeid; |
| 633 | 633 | if ($data->imo !== '') $result['imo'] = $data->imo; |
| 634 | - if ($data->callsign !== '') $result['callsign'] = trim(str_replace('@','',$data->callsign)); |
|
| 634 | + if ($data->callsign !== '') $result['callsign'] = trim(str_replace('@', '', $data->callsign)); |
|
| 635 | 635 | if (is_numeric($data->eta_month) && $data->eta_month != 0 && is_numeric($data->eta_day) && $data->eta_day != 0 && $data->eta_hour !== '' && $data->eta_minute !== '') { |
| 636 | - $eta_ts = strtotime(date('Y').'-'.sprintf("%02d",$data->eta_month).'-'.sprintf("%02d",$data->eta_day).' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00'); |
|
| 636 | + $eta_ts = strtotime(date('Y').'-'.sprintf("%02d", $data->eta_month).'-'.sprintf("%02d", $data->eta_day).' '.sprintf("%02d", $data->eta_hour).':'.sprintf("%02d", $data->eta_minute).':00'); |
|
| 637 | 637 | if ($eta_ts != '') $result['eta_ts'] = $eta_ts; |
| 638 | 638 | } elseif (is_numeric($data->eta_hour) && is_numeric($data->eta_minute)) { |
| 639 | - $eta_ts = strtotime(date('Y-m-d').' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00'); |
|
| 639 | + $eta_ts = strtotime(date('Y-m-d').' '.sprintf("%02d", $data->eta_hour).':'.sprintf("%02d", $data->eta_minute).':00'); |
|
| 640 | 640 | if ($eta_ts != '') $result['eta_ts'] = $eta_ts; |
| 641 | 641 | } |
| 642 | 642 | if ($data->destination != '') { |
| 643 | - $dest = trim(str_replace('@','',$data->destination)); |
|
| 643 | + $dest = trim(str_replace('@', '', $data->destination)); |
|
| 644 | 644 | if ($dest != '') $result['destination'] = $dest; |
| 645 | 645 | } |
| 646 | 646 | $result['all'] = (array) $data; |
@@ -35,7 +35,9 @@ discard block |
||
| 35 | 35 | $temp += 1; |
| 36 | 36 | $flat = (float)($temp / (60.0 * 10000.0)); |
| 37 | 37 | $flat *= -1.0; |
| 38 | - } else $flat = (float)($temp / (60.0 * 10000.0)); |
|
| 38 | + } else { |
|
| 39 | + $flat = (float)($temp / (60.0 * 10000.0)); |
|
| 40 | + } |
|
| 39 | 41 | return $flat; // float |
| 40 | 42 | } |
| 41 | 43 | |
@@ -47,7 +49,9 @@ discard block |
||
| 47 | 49 | $temp += 1; |
| 48 | 50 | $flon = (float)($temp / (60.0 * 10000.0)); |
| 49 | 51 | $flon *= -1.0; |
| 50 | - } else $flon = (float)($temp / (60.0 * 10000.0)); |
|
| 52 | + } else { |
|
| 53 | + $flon = (float)($temp / (60.0 * 10000.0)); |
|
| 54 | + } |
|
| 51 | 55 | return $flon; |
| 52 | 56 | } |
| 53 | 57 | |
@@ -70,10 +74,8 @@ discard block |
||
| 70 | 74 | */ |
| 71 | 75 | private function asciidec_2_8bit($ascii) { |
| 72 | 76 | //only process in the following range: 48-87, 96-119 |
| 73 | - if ($ascii < 48) { } |
|
| 74 | - else { |
|
| 75 | - if($ascii>119) { } |
|
| 76 | - else { |
|
| 77 | + if ($ascii < 48) { } else { |
|
| 78 | + if($ascii>119) { } else { |
|
| 77 | 79 | if ($ascii>87 && $ascii<96) ; |
| 78 | 80 | else { |
| 79 | 81 | $ascii=$ascii+40; |
@@ -175,7 +177,9 @@ discard block |
||
| 175 | 177 | $ro->lon = $this->make_lonf(bindec(substr($_aisdata,57,28))); |
| 176 | 178 | $ro->lat = $this->make_latf(bindec(substr($_aisdata,85,27))); |
| 177 | 179 | $ro->heading = bindec(substr($_aisdata,124,9)); |
| 178 | - if ($ro->heading == 511) $ro->heading = ''; |
|
| 180 | + if ($ro->heading == 511) { |
|
| 181 | + $ro->heading = ''; |
|
| 182 | + } |
|
| 179 | 183 | $ro->cls = 2; // class B |
| 180 | 184 | } else if ($ro->id == 19) { |
| 181 | 185 | $ro->cog = bindec(substr($_aisdata,112,12))/10; |
@@ -185,7 +189,9 @@ discard block |
||
| 185 | 189 | $ro->name = $this->binchar($_aisdata,143,120); |
| 186 | 190 | $ro->cls = 2; // class B |
| 187 | 191 | $ro->heading = bindec(substr($_aisdata,124,9)); |
| 188 | - if ($ro->heading == 511) $ro->heading = ''; |
|
| 192 | + if ($ro->heading == 511) { |
|
| 193 | + $ro->heading = ''; |
|
| 194 | + } |
|
| 189 | 195 | $ro->typeid = bindec(substr($_aisdata,263,8)); |
| 190 | 196 | $ro->type = $this->getShipType($ro->typeid); |
| 191 | 197 | //$ro->to_bow = bindec(substr($_aisdata,271,9)); |
@@ -216,9 +222,13 @@ discard block |
||
| 216 | 222 | $ro->cls = 2; // class B |
| 217 | 223 | } else if ($ro->id == 27) { |
| 218 | 224 | $ro->cog = bindec(substr($_aisdata,85,9)); |
| 219 | - if ($ro->cog == 511) $ro->cog = 0.0; |
|
| 225 | + if ($ro->cog == 511) { |
|
| 226 | + $ro->cog = 0.0; |
|
| 227 | + } |
|
| 220 | 228 | $ro->sog = bindec(substr($_aisdata,79,6)); |
| 221 | - if ($ro->sog == 63) $ro->sog = 0.0; |
|
| 229 | + if ($ro->sog == 63) { |
|
| 230 | + $ro->sog = 0.0; |
|
| 231 | + } |
|
| 222 | 232 | $ro->lon = $this->make_lonf(bindec(substr($_aisdata,44,18))*10); |
| 223 | 233 | $ro->lat = $this->make_latf(bindec(substr($_aisdata,62,17))*10); |
| 224 | 234 | $ro->cls = 1; // class A |
@@ -267,88 +277,171 @@ discard block |
||
| 267 | 277 | } |
| 268 | 278 | |
| 269 | 279 | public function getShipType($code) { |
| 270 | - if ($code == 0) return 'Not available (default)'; |
|
| 271 | - elseif ($code >= 1 && $code <= 19) return 'Reserved for future use'; |
|
| 272 | - elseif ($code == 20) return 'Wing in ground (WIG), all ships of this type'; |
|
| 273 | - elseif ($code == 21) return 'Wing in ground (WIG), Hazardous category A'; |
|
| 274 | - elseif ($code == 22) return 'Wing in ground (WIG), Hazardous category B'; |
|
| 275 | - elseif ($code == 23) return 'Wing in ground (WIG), Hazardous category C'; |
|
| 276 | - elseif ($code == 24) return 'Wing in ground (WIG), Hazardous category D'; |
|
| 277 | - elseif ($code == 25) return 'Wing in ground (WIG), Reserved for future use'; |
|
| 278 | - elseif ($code == 26) return 'Wing in ground (WIG), Reserved for future use'; |
|
| 279 | - elseif ($code == 27) return 'Wing in ground (WIG), Reserved for future use'; |
|
| 280 | - elseif ($code == 28) return 'Wing in ground (WIG), Reserved for future use'; |
|
| 281 | - elseif ($code == 29) return 'Wing in ground (WIG), Reserved for future use'; |
|
| 282 | - elseif ($code == 30) return 'Fishing'; |
|
| 283 | - elseif ($code == 31) return 'Towing'; |
|
| 284 | - elseif ($code == 32) return 'Towing: length exceeds 200m or breadth exceeds 25m'; |
|
| 285 | - elseif ($code == 33) return 'Dredging or underwater ops'; |
|
| 286 | - elseif ($code == 34) return 'Diving ops'; |
|
| 287 | - elseif ($code == 35) return 'Military ops'; |
|
| 288 | - elseif ($code == 36) return 'Sailing'; |
|
| 289 | - elseif ($code == 37) return 'Pleasure Craft'; |
|
| 290 | - elseif ($code == 38) return 'Reserved'; |
|
| 291 | - elseif ($code == 39) return 'Reserved'; |
|
| 292 | - elseif ($code == 40) return 'High speed craft (HSC), all ships of this type'; |
|
| 293 | - elseif ($code == 41) return 'High speed craft (HSC), Hazardous category A'; |
|
| 294 | - elseif ($code == 42) return 'High speed craft (HSC), Hazardous category B'; |
|
| 295 | - elseif ($code == 43) return 'High speed craft (HSC), Hazardous category C'; |
|
| 296 | - elseif ($code == 44) return 'High speed craft (HSC), Hazardous category D'; |
|
| 297 | - elseif ($code == 45) return 'High speed craft (HSC), Reserved for future use'; |
|
| 298 | - elseif ($code == 46) return 'High speed craft (HSC), Reserved for future use'; |
|
| 299 | - elseif ($code == 47) return 'High speed craft (HSC), Reserved for future use'; |
|
| 300 | - elseif ($code == 48) return 'High speed craft (HSC), Reserved for future use'; |
|
| 301 | - elseif ($code == 49) return 'High speed craft (HSC), No additional information'; |
|
| 302 | - elseif ($code == 50) return 'Pilot Vessel'; |
|
| 303 | - elseif ($code == 51) return 'Search and Rescue vessel'; |
|
| 304 | - elseif ($code == 52) return 'Tug'; |
|
| 305 | - elseif ($code == 53) return 'Port Tender'; |
|
| 306 | - elseif ($code == 54) return 'Anti-pollution equipment'; |
|
| 307 | - elseif ($code == 55) return 'Law Enforcement'; |
|
| 308 | - elseif ($code == 56) return 'Spare - Local Vessel'; |
|
| 309 | - elseif ($code == 57) return 'Spare - Local Vessel'; |
|
| 310 | - elseif ($code == 58) return 'Medical Transport'; |
|
| 311 | - elseif ($code == 59) return 'Noncombatant ship according to RR Resolution No. 18'; |
|
| 312 | - elseif ($code == 60) return 'Passenger, all ships of this type'; |
|
| 313 | - elseif ($code == 61) return 'Passenger, Hazardous category A'; |
|
| 314 | - elseif ($code == 62) return 'Passenger, Hazardous category B'; |
|
| 315 | - elseif ($code == 63) return 'Passenger, Hazardous category C'; |
|
| 316 | - elseif ($code == 64) return 'Passenger, Hazardous category D'; |
|
| 317 | - elseif ($code == 65) return 'Passenger, Reserved for future use'; |
|
| 318 | - elseif ($code == 66) return 'Passenger, Reserved for future use'; |
|
| 319 | - elseif ($code == 67) return 'Passenger, Reserved for future use'; |
|
| 320 | - elseif ($code == 68) return 'Passenger, Reserved for future use'; |
|
| 321 | - elseif ($code == 69) return 'Passenger, No additional information'; |
|
| 322 | - elseif ($code == 70) return 'Cargo, all ships of this type'; |
|
| 323 | - elseif ($code == 71) return 'Cargo, Hazardous category A'; |
|
| 324 | - elseif ($code == 72) return 'Cargo, Hazardous category B'; |
|
| 325 | - elseif ($code == 73) return 'Cargo, Hazardous category C'; |
|
| 326 | - elseif ($code == 74) return 'Cargo, Hazardous category D'; |
|
| 327 | - elseif ($code == 75) return 'Cargo, Reserved for future use'; |
|
| 328 | - elseif ($code == 76) return 'Cargo, Reserved for future use'; |
|
| 329 | - elseif ($code == 77) return 'Cargo, Reserved for future use'; |
|
| 330 | - elseif ($code == 78) return 'Cargo, Reserved for future use'; |
|
| 331 | - elseif ($code == 79) return 'Cargo, No additional information'; |
|
| 332 | - elseif ($code == 80) return 'Tanker, all ships of this type'; |
|
| 333 | - elseif ($code == 81) return 'Tanker, Hazardous category A'; |
|
| 334 | - elseif ($code == 82) return 'Tanker, Hazardous category B'; |
|
| 335 | - elseif ($code == 83) return 'Tanker, Hazardous category C'; |
|
| 336 | - elseif ($code == 84) return 'Tanker, Hazardous category D'; |
|
| 337 | - elseif ($code == 85) return 'Tanker, Reserved for future use'; |
|
| 338 | - elseif ($code == 86) return 'Tanker, Reserved for future use'; |
|
| 339 | - elseif ($code == 87) return 'Tanker, Reserved for future use'; |
|
| 340 | - elseif ($code == 88) return 'Tanker, Reserved for future use'; |
|
| 341 | - elseif ($code == 89) return 'Tanker, No additional information'; |
|
| 342 | - elseif ($code == 90) return 'Other Type, all ships of this type'; |
|
| 343 | - elseif ($code == 91) return 'Other Type, Hazardous category A'; |
|
| 344 | - elseif ($code == 92) return 'Other Type, Hazardous category B'; |
|
| 345 | - elseif ($code == 93) return 'Other Type, Hazardous category C'; |
|
| 346 | - elseif ($code == 94) return 'Other Type, Hazardous category D'; |
|
| 347 | - elseif ($code == 95) return 'Other Type, Reserved for future use'; |
|
| 348 | - elseif ($code == 96) return 'Other Type, Reserved for future use'; |
|
| 349 | - elseif ($code == 97) return 'Other Type, Reserved for future use'; |
|
| 350 | - elseif ($code == 98) return 'Other Type, Reserved for future use'; |
|
| 351 | - elseif ($code == 99) return 'Other Type, no additional information'; |
|
| 280 | + if ($code == 0) { |
|
| 281 | + return 'Not available (default)'; |
|
| 282 | + } elseif ($code >= 1 && $code <= 19) { |
|
| 283 | + return 'Reserved for future use'; |
|
| 284 | + } elseif ($code == 20) { |
|
| 285 | + return 'Wing in ground (WIG), all ships of this type'; |
|
| 286 | + } elseif ($code == 21) { |
|
| 287 | + return 'Wing in ground (WIG), Hazardous category A'; |
|
| 288 | + } elseif ($code == 22) { |
|
| 289 | + return 'Wing in ground (WIG), Hazardous category B'; |
|
| 290 | + } elseif ($code == 23) { |
|
| 291 | + return 'Wing in ground (WIG), Hazardous category C'; |
|
| 292 | + } elseif ($code == 24) { |
|
| 293 | + return 'Wing in ground (WIG), Hazardous category D'; |
|
| 294 | + } elseif ($code == 25) { |
|
| 295 | + return 'Wing in ground (WIG), Reserved for future use'; |
|
| 296 | + } elseif ($code == 26) { |
|
| 297 | + return 'Wing in ground (WIG), Reserved for future use'; |
|
| 298 | + } elseif ($code == 27) { |
|
| 299 | + return 'Wing in ground (WIG), Reserved for future use'; |
|
| 300 | + } elseif ($code == 28) { |
|
| 301 | + return 'Wing in ground (WIG), Reserved for future use'; |
|
| 302 | + } elseif ($code == 29) { |
|
| 303 | + return 'Wing in ground (WIG), Reserved for future use'; |
|
| 304 | + } elseif ($code == 30) { |
|
| 305 | + return 'Fishing'; |
|
| 306 | + } elseif ($code == 31) { |
|
| 307 | + return 'Towing'; |
|
| 308 | + } elseif ($code == 32) { |
|
| 309 | + return 'Towing: length exceeds 200m or breadth exceeds 25m'; |
|
| 310 | + } elseif ($code == 33) { |
|
| 311 | + return 'Dredging or underwater ops'; |
|
| 312 | + } elseif ($code == 34) { |
|
| 313 | + return 'Diving ops'; |
|
| 314 | + } elseif ($code == 35) { |
|
| 315 | + return 'Military ops'; |
|
| 316 | + } elseif ($code == 36) { |
|
| 317 | + return 'Sailing'; |
|
| 318 | + } elseif ($code == 37) { |
|
| 319 | + return 'Pleasure Craft'; |
|
| 320 | + } elseif ($code == 38) { |
|
| 321 | + return 'Reserved'; |
|
| 322 | + } elseif ($code == 39) { |
|
| 323 | + return 'Reserved'; |
|
| 324 | + } elseif ($code == 40) { |
|
| 325 | + return 'High speed craft (HSC), all ships of this type'; |
|
| 326 | + } elseif ($code == 41) { |
|
| 327 | + return 'High speed craft (HSC), Hazardous category A'; |
|
| 328 | + } elseif ($code == 42) { |
|
| 329 | + return 'High speed craft (HSC), Hazardous category B'; |
|
| 330 | + } elseif ($code == 43) { |
|
| 331 | + return 'High speed craft (HSC), Hazardous category C'; |
|
| 332 | + } elseif ($code == 44) { |
|
| 333 | + return 'High speed craft (HSC), Hazardous category D'; |
|
| 334 | + } elseif ($code == 45) { |
|
| 335 | + return 'High speed craft (HSC), Reserved for future use'; |
|
| 336 | + } elseif ($code == 46) { |
|
| 337 | + return 'High speed craft (HSC), Reserved for future use'; |
|
| 338 | + } elseif ($code == 47) { |
|
| 339 | + return 'High speed craft (HSC), Reserved for future use'; |
|
| 340 | + } elseif ($code == 48) { |
|
| 341 | + return 'High speed craft (HSC), Reserved for future use'; |
|
| 342 | + } elseif ($code == 49) { |
|
| 343 | + return 'High speed craft (HSC), No additional information'; |
|
| 344 | + } elseif ($code == 50) { |
|
| 345 | + return 'Pilot Vessel'; |
|
| 346 | + } elseif ($code == 51) { |
|
| 347 | + return 'Search and Rescue vessel'; |
|
| 348 | + } elseif ($code == 52) { |
|
| 349 | + return 'Tug'; |
|
| 350 | + } elseif ($code == 53) { |
|
| 351 | + return 'Port Tender'; |
|
| 352 | + } elseif ($code == 54) { |
|
| 353 | + return 'Anti-pollution equipment'; |
|
| 354 | + } elseif ($code == 55) { |
|
| 355 | + return 'Law Enforcement'; |
|
| 356 | + } elseif ($code == 56) { |
|
| 357 | + return 'Spare - Local Vessel'; |
|
| 358 | + } elseif ($code == 57) { |
|
| 359 | + return 'Spare - Local Vessel'; |
|
| 360 | + } elseif ($code == 58) { |
|
| 361 | + return 'Medical Transport'; |
|
| 362 | + } elseif ($code == 59) { |
|
| 363 | + return 'Noncombatant ship according to RR Resolution No. 18'; |
|
| 364 | + } elseif ($code == 60) { |
|
| 365 | + return 'Passenger, all ships of this type'; |
|
| 366 | + } elseif ($code == 61) { |
|
| 367 | + return 'Passenger, Hazardous category A'; |
|
| 368 | + } elseif ($code == 62) { |
|
| 369 | + return 'Passenger, Hazardous category B'; |
|
| 370 | + } elseif ($code == 63) { |
|
| 371 | + return 'Passenger, Hazardous category C'; |
|
| 372 | + } elseif ($code == 64) { |
|
| 373 | + return 'Passenger, Hazardous category D'; |
|
| 374 | + } elseif ($code == 65) { |
|
| 375 | + return 'Passenger, Reserved for future use'; |
|
| 376 | + } elseif ($code == 66) { |
|
| 377 | + return 'Passenger, Reserved for future use'; |
|
| 378 | + } elseif ($code == 67) { |
|
| 379 | + return 'Passenger, Reserved for future use'; |
|
| 380 | + } elseif ($code == 68) { |
|
| 381 | + return 'Passenger, Reserved for future use'; |
|
| 382 | + } elseif ($code == 69) { |
|
| 383 | + return 'Passenger, No additional information'; |
|
| 384 | + } elseif ($code == 70) { |
|
| 385 | + return 'Cargo, all ships of this type'; |
|
| 386 | + } elseif ($code == 71) { |
|
| 387 | + return 'Cargo, Hazardous category A'; |
|
| 388 | + } elseif ($code == 72) { |
|
| 389 | + return 'Cargo, Hazardous category B'; |
|
| 390 | + } elseif ($code == 73) { |
|
| 391 | + return 'Cargo, Hazardous category C'; |
|
| 392 | + } elseif ($code == 74) { |
|
| 393 | + return 'Cargo, Hazardous category D'; |
|
| 394 | + } elseif ($code == 75) { |
|
| 395 | + return 'Cargo, Reserved for future use'; |
|
| 396 | + } elseif ($code == 76) { |
|
| 397 | + return 'Cargo, Reserved for future use'; |
|
| 398 | + } elseif ($code == 77) { |
|
| 399 | + return 'Cargo, Reserved for future use'; |
|
| 400 | + } elseif ($code == 78) { |
|
| 401 | + return 'Cargo, Reserved for future use'; |
|
| 402 | + } elseif ($code == 79) { |
|
| 403 | + return 'Cargo, No additional information'; |
|
| 404 | + } elseif ($code == 80) { |
|
| 405 | + return 'Tanker, all ships of this type'; |
|
| 406 | + } elseif ($code == 81) { |
|
| 407 | + return 'Tanker, Hazardous category A'; |
|
| 408 | + } elseif ($code == 82) { |
|
| 409 | + return 'Tanker, Hazardous category B'; |
|
| 410 | + } elseif ($code == 83) { |
|
| 411 | + return 'Tanker, Hazardous category C'; |
|
| 412 | + } elseif ($code == 84) { |
|
| 413 | + return 'Tanker, Hazardous category D'; |
|
| 414 | + } elseif ($code == 85) { |
|
| 415 | + return 'Tanker, Reserved for future use'; |
|
| 416 | + } elseif ($code == 86) { |
|
| 417 | + return 'Tanker, Reserved for future use'; |
|
| 418 | + } elseif ($code == 87) { |
|
| 419 | + return 'Tanker, Reserved for future use'; |
|
| 420 | + } elseif ($code == 88) { |
|
| 421 | + return 'Tanker, Reserved for future use'; |
|
| 422 | + } elseif ($code == 89) { |
|
| 423 | + return 'Tanker, No additional information'; |
|
| 424 | + } elseif ($code == 90) { |
|
| 425 | + return 'Other Type, all ships of this type'; |
|
| 426 | + } elseif ($code == 91) { |
|
| 427 | + return 'Other Type, Hazardous category A'; |
|
| 428 | + } elseif ($code == 92) { |
|
| 429 | + return 'Other Type, Hazardous category B'; |
|
| 430 | + } elseif ($code == 93) { |
|
| 431 | + return 'Other Type, Hazardous category C'; |
|
| 432 | + } elseif ($code == 94) { |
|
| 433 | + return 'Other Type, Hazardous category D'; |
|
| 434 | + } elseif ($code == 95) { |
|
| 435 | + return 'Other Type, Reserved for future use'; |
|
| 436 | + } elseif ($code == 96) { |
|
| 437 | + return 'Other Type, Reserved for future use'; |
|
| 438 | + } elseif ($code == 97) { |
|
| 439 | + return 'Other Type, Reserved for future use'; |
|
| 440 | + } elseif ($code == 98) { |
|
| 441 | + return 'Other Type, Reserved for future use'; |
|
| 442 | + } elseif ($code == 99) { |
|
| 443 | + return 'Other Type, no additional information'; |
|
| 444 | + } |
|
| 352 | 445 | } |
| 353 | 446 | |
| 354 | 447 | public function process_ais_itu($_itu, $_len, $_filler, $aux /*, $ais_ch*/) { |
@@ -386,19 +479,34 @@ discard block |
||
| 386 | 479 | // assume 1st ! is valid |
| 387 | 480 | // find * ensure that it is at correct position |
| 388 | 481 | $end = strrpos ( $rawdata , '*' ); |
| 389 | - if ($end === FALSE) return -1; // check for NULLS!!! |
|
| 482 | + if ($end === FALSE) { |
|
| 483 | + return -1; |
|
| 484 | + } |
|
| 485 | + // check for NULLS!!! |
|
| 390 | 486 | $cs = substr( $rawdata, $end + 1 ); |
| 391 | - if ( strlen($cs) != 2 ) return -1; // correct cs length |
|
| 487 | + if ( strlen($cs) != 2 ) { |
|
| 488 | + return -1; |
|
| 489 | + } |
|
| 490 | + // correct cs length |
|
| 392 | 491 | $dcs = (int)hexdec( $cs ); |
| 393 | - for ( $alias=1; $alias<$end; $alias++) $chksum ^= ord( $rawdata[$alias] ); // perform XOR for NMEA checksum |
|
| 492 | + for ( $alias=1; $alias<$end; $alias++) { |
|
| 493 | + $chksum ^= ord( $rawdata[$alias] ); |
|
| 494 | + } |
|
| 495 | + // perform XOR for NMEA checksum |
|
| 394 | 496 | if ( $chksum == $dcs ) { // NMEA checksum pass |
| 395 | 497 | $pcs = explode(',', $rawdata); |
| 396 | 498 | // !AI??? identifier |
| 397 | 499 | $num_seq = (int)$pcs[1]; // number of sequences |
| 398 | 500 | $seq = (int)$pcs[2]; // get sequence |
| 399 | 501 | // get msg sequence id |
| 400 | - if ($pcs[3] == '') $msg_sid = -1; // non-multipart message, set to -1 |
|
| 401 | - else $msg_sid = (int)$pcs[3]; // multipart message |
|
| 502 | + if ($pcs[3] == '') { |
|
| 503 | + $msg_sid = -1; |
|
| 504 | + } |
|
| 505 | + // non-multipart message, set to -1 |
|
| 506 | + else { |
|
| 507 | + $msg_sid = (int)$pcs[3]; |
|
| 508 | + } |
|
| 509 | + // multipart message |
|
| 402 | 510 | $ais_ch = $pcs[4]; // get AIS channel |
| 403 | 511 | // message sequence checking |
| 404 | 512 | if ($num_seq < 1 || $num_seq > 9) { |
@@ -459,10 +567,18 @@ discard block |
||
| 459 | 567 | //DEBUG echo "[$start $end $tst]\n"; |
| 460 | 568 | $result = $this->process_ais_raw( $tst, "" ); |
| 461 | 569 | $last_pos = $end + 1; |
| 462 | - } else break; |
|
| 570 | + } else { |
|
| 571 | + break; |
|
| 572 | + } |
|
| 573 | + } |
|
| 574 | + if ($last_pos > 0) { |
|
| 575 | + $cbuf = substr($cbuf, $last_pos); |
|
| 576 | + } |
|
| 577 | + // move... |
|
| 578 | + if (strlen($cbuf) > 1024) { |
|
| 579 | + $cbuf = ""; |
|
| 463 | 580 | } |
| 464 | - if ($last_pos > 0) $cbuf = substr($cbuf, $last_pos); // move... |
|
| 465 | - if (strlen($cbuf) > 1024) $cbuf = ""; // prevent overflow simple mode... |
|
| 581 | + // prevent overflow simple mode... |
|
| 466 | 582 | return $result; |
| 467 | 583 | } |
| 468 | 584 | |
@@ -482,7 +598,9 @@ discard block |
||
| 482 | 598 | if ($lat<0.0) { |
| 483 | 599 | $lat = -$lat; |
| 484 | 600 | $neg=true; |
| 485 | - } else $neg=false; |
|
| 601 | + } else { |
|
| 602 | + $neg=false; |
|
| 603 | + } |
|
| 486 | 604 | $latd = 0x00000000; |
| 487 | 605 | $latd = intval ($lat * 600000.0); |
| 488 | 606 | if ($neg==true) { |
@@ -498,7 +616,9 @@ discard block |
||
| 498 | 616 | if ($lon<0.0) { |
| 499 | 617 | $lon = -$lon; |
| 500 | 618 | $neg=true; |
| 501 | - } else $neg=false; |
|
| 619 | + } else { |
|
| 620 | + $neg=false; |
|
| 621 | + } |
|
| 502 | 622 | $lond = 0x00000000; |
| 503 | 623 | $lond = intval ($lon * 600000.0); |
| 504 | 624 | if ($neg==true) { |
@@ -511,9 +631,14 @@ discard block |
||
| 511 | 631 | |
| 512 | 632 | private function char2bin($name, $max_len) { |
| 513 | 633 | $len = strlen($name); |
| 514 | - if ($len > $max_len) $name = substr($name,0,$max_len); |
|
| 515 | - if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len) * 6); |
|
| 516 | - else $pad = ''; |
|
| 634 | + if ($len > $max_len) { |
|
| 635 | + $name = substr($name,0,$max_len); |
|
| 636 | + } |
|
| 637 | + if ($len < $max_len) { |
|
| 638 | + $pad = str_repeat('0', ($max_len - $len) * 6); |
|
| 639 | + } else { |
|
| 640 | + $pad = ''; |
|
| 641 | + } |
|
| 517 | 642 | $rv = ''; |
| 518 | 643 | $ais_chars = array( |
| 519 | 644 | '@'=>0, 'A'=>1, 'B'=>2, 'C'=>3, 'D'=>4, 'E'=>5, 'F'=>6, 'G'=>7, 'H'=>8, 'I'=>9, |
@@ -526,9 +651,12 @@ discard block |
||
| 526 | 651 | ); |
| 527 | 652 | // " |
| 528 | 653 | $_a = str_split($name); |
| 529 | - if ($_a) foreach ($_a as $_1) { |
|
| 654 | + if ($_a) { |
|
| 655 | + foreach ($_a as $_1) { |
|
| 530 | 656 | if (isset($ais_chars[$_1])) $dec = $ais_chars[$_1]; |
| 531 | - else $dec = 0; |
|
| 657 | + } else { |
|
| 658 | + $dec = 0; |
|
| 659 | + } |
|
| 532 | 660 | $bin = str_pad(decbin( $dec ), 6, '0', STR_PAD_LEFT); |
| 533 | 661 | $rv .= $bin; |
| 534 | 662 | //echo "$_1 $dec ($bin)<br/>"; |
@@ -540,7 +668,9 @@ discard block |
||
| 540 | 668 | $len_bit = strlen($_enc); |
| 541 | 669 | $rem6 = $len_bit % 6; |
| 542 | 670 | $pad6_len = 0; |
| 543 | - if ($rem6) $pad6_len = 6 - $rem6; |
|
| 671 | + if ($rem6) { |
|
| 672 | + $pad6_len = 6 - $rem6; |
|
| 673 | + } |
|
| 544 | 674 | //echo $pad6_len.'<br>'; |
| 545 | 675 | $_enc .= str_repeat("0", $pad6_len); // pad the text... |
| 546 | 676 | $len_enc = strlen($_enc) / 6; |
@@ -549,8 +679,11 @@ discard block |
||
| 549 | 679 | for ($i=0; $i<$len_enc; $i++) { |
| 550 | 680 | $offset = $i * 6; |
| 551 | 681 | $dec = bindec(substr($_enc,$offset,6)); |
| 552 | - if ($dec < 40) $dec += 48; |
|
| 553 | - else $dec += 56; |
|
| 682 | + if ($dec < 40) { |
|
| 683 | + $dec += 48; |
|
| 684 | + } else { |
|
| 685 | + $dec += 56; |
|
| 686 | + } |
|
| 554 | 687 | //echo chr($dec)." $dec<br/>"; |
| 555 | 688 | $itu .= chr($dec); |
| 556 | 689 | } |
@@ -563,25 +696,41 @@ discard block |
||
| 563 | 696 | } |
| 564 | 697 | $hex_arr = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); |
| 565 | 698 | $lsb = $chksum & 0x0F; |
| 566 | - if ($lsb >=0 && $lsb <= 15 ) $lsbc = $hex_arr[$lsb]; |
|
| 567 | - else $lsbc = '0'; |
|
| 699 | + if ($lsb >=0 && $lsb <= 15 ) { |
|
| 700 | + $lsbc = $hex_arr[$lsb]; |
|
| 701 | + } else { |
|
| 702 | + $lsbc = '0'; |
|
| 703 | + } |
|
| 568 | 704 | $msb = (($chksum & 0xF0) >> 4) & 0x0F; |
| 569 | - if ($msb >=0 && $msb <= 15 ) $msbc = $hex_arr[$msb]; |
|
| 570 | - else $msbc = '0'; |
|
| 705 | + if ($msb >=0 && $msb <= 15 ) { |
|
| 706 | + $msbc = $hex_arr[$msb]; |
|
| 707 | + } else { |
|
| 708 | + $msbc = '0'; |
|
| 709 | + } |
|
| 571 | 710 | $itu = '!'.$itu."*{$msbc}{$lsbc}\r\n"; |
| 572 | 711 | return $itu; |
| 573 | 712 | } |
| 574 | 713 | |
| 575 | 714 | public function parse($buffer) { |
| 576 | 715 | $data = $this->process_ais_buf($buffer); |
| 577 | - if (!is_object($data)) return array(); |
|
| 578 | - if ($data->lon != 0) $result['longitude'] = $data->lon; |
|
| 579 | - if ($data->lat != 0) $result['latitude'] = $data->lat; |
|
| 716 | + if (!is_object($data)) { |
|
| 717 | + return array(); |
|
| 718 | + } |
|
| 719 | + if ($data->lon != 0) { |
|
| 720 | + $result['longitude'] = $data->lon; |
|
| 721 | + } |
|
| 722 | + if ($data->lat != 0) { |
|
| 723 | + $result['latitude'] = $data->lat; |
|
| 724 | + } |
|
| 580 | 725 | $result['ident'] = trim($data->name); |
| 581 | 726 | $result['timestamp'] = $data->ts; |
| 582 | 727 | $result['mmsi'] = $data->mmsi; |
| 583 | - if ($data->sog != -1.0) $result['speed'] = $data->sog; |
|
| 584 | - if ($data->cog != 0) $result['heading'] = $data->cog; |
|
| 728 | + if ($data->sog != -1.0) { |
|
| 729 | + $result['speed'] = $data->sog; |
|
| 730 | + } |
|
| 731 | + if ($data->cog != 0) { |
|
| 732 | + $result['heading'] = $data->cog; |
|
| 733 | + } |
|
| 585 | 734 | /* |
| 586 | 735 | $ro->cls = 0; // AIS class undefined, also indicate unparsed msg |
| 587 | 736 | $ro->id = bindec(substr($_aisdata,0,6)); |
@@ -591,15 +740,25 @@ discard block |
||
| 591 | 740 | |
| 592 | 741 | public function mmsitype($mmsi) { |
| 593 | 742 | if (strlen($mmsi) == 9) { |
| 594 | - if (substr($mmsi,0,3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS'; |
|
| 595 | - elseif (substr($mmsi,0,3) == '972') return 'MOB (Man Overboard) device'; |
|
| 596 | - elseif (substr($mmsi,0,3) == '970') return 'AIS SART (Search and Rescue Transmitter)'; |
|
| 597 | - elseif (substr($mmsi,0,3) == '111') return 'SAR (Search and Rescue) aircraft'; |
|
| 598 | - elseif (substr($mmsi,0,2) == '98') return 'Auxiliary craft associated with a parent ship'; |
|
| 599 | - elseif (substr($mmsi,0,2) == '99') return 'Aids to Navigation'; |
|
| 600 | - elseif (substr($mmsi,0,2) == '00') return 'Coastal stations'; |
|
| 601 | - elseif (substr($mmsi,0,1) == '0') return 'Group of ships'; |
|
| 602 | - else return 'Ship'; |
|
| 743 | + if (substr($mmsi,0,3) == '974') { |
|
| 744 | + return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS'; |
|
| 745 | + } elseif (substr($mmsi,0,3) == '972') { |
|
| 746 | + return 'MOB (Man Overboard) device'; |
|
| 747 | + } elseif (substr($mmsi,0,3) == '970') { |
|
| 748 | + return 'AIS SART (Search and Rescue Transmitter)'; |
|
| 749 | + } elseif (substr($mmsi,0,3) == '111') { |
|
| 750 | + return 'SAR (Search and Rescue) aircraft'; |
|
| 751 | + } elseif (substr($mmsi,0,2) == '98') { |
|
| 752 | + return 'Auxiliary craft associated with a parent ship'; |
|
| 753 | + } elseif (substr($mmsi,0,2) == '99') { |
|
| 754 | + return 'Aids to Navigation'; |
|
| 755 | + } elseif (substr($mmsi,0,2) == '00') { |
|
| 756 | + return 'Coastal stations'; |
|
| 757 | + } elseif (substr($mmsi,0,1) == '0') { |
|
| 758 | + return 'Group of ships'; |
|
| 759 | + } else { |
|
| 760 | + return 'Ship'; |
|
| 761 | + } |
|
| 603 | 762 | } |
| 604 | 763 | |
| 605 | 764 | |
@@ -616,32 +775,61 @@ discard block |
||
| 616 | 775 | //if ($globalDebug) echo '==== Line format not supported : '.$buffer."\n"; |
| 617 | 776 | return array(); |
| 618 | 777 | } |
| 619 | - if ($data->lon != 0) $result['longitude'] = $data->lon; |
|
| 620 | - if ($data->lat != 0) $result['latitude'] = $data->lat; |
|
| 778 | + if ($data->lon != 0) { |
|
| 779 | + $result['longitude'] = $data->lon; |
|
| 780 | + } |
|
| 781 | + if ($data->lat != 0) { |
|
| 782 | + $result['latitude'] = $data->lat; |
|
| 783 | + } |
|
| 621 | 784 | $result['ident'] = trim(str_replace('@','',$data->name)); |
| 622 | 785 | $result['timestamp'] = $data->ts; |
| 623 | 786 | $result['mmsi'] = $data->mmsi; |
| 624 | - if (strlen($result['mmsi']) == 8 && substr($result['mmsi'],0,3) == '669') $result['mmsi'] = '3'.$result['mmsi']; |
|
| 787 | + if (strlen($result['mmsi']) == 8 && substr($result['mmsi'],0,3) == '669') { |
|
| 788 | + $result['mmsi'] = '3'.$result['mmsi']; |
|
| 789 | + } |
|
| 625 | 790 | $result['mmsi_type'] = $this->mmsitype($result['mmsi']); |
| 626 | - if ($data->sog != -1.0) $result['speed'] = $data->sog; |
|
| 627 | - if ($data->heading !== '') $result['heading'] = $data->heading; |
|
| 628 | - elseif ($data->cog != 0) $result['heading'] = $data->cog; |
|
| 629 | - if ($data->status != '') $result['status'] = $data->status; |
|
| 630 | - if ($data->statusid !== '') $result['statusid'] = $data->statusid; |
|
| 631 | - if ($data->type !== '') $result['type'] = $data->type; |
|
| 632 | - if ($data->typeid !== '') $result['typeid'] = $data->typeid; |
|
| 633 | - if ($data->imo !== '') $result['imo'] = $data->imo; |
|
| 634 | - if ($data->callsign !== '') $result['callsign'] = trim(str_replace('@','',$data->callsign)); |
|
| 791 | + if ($data->sog != -1.0) { |
|
| 792 | + $result['speed'] = $data->sog; |
|
| 793 | + } |
|
| 794 | + if ($data->heading !== '') { |
|
| 795 | + $result['heading'] = $data->heading; |
|
| 796 | + } elseif ($data->cog != 0) { |
|
| 797 | + $result['heading'] = $data->cog; |
|
| 798 | + } |
|
| 799 | + if ($data->status != '') { |
|
| 800 | + $result['status'] = $data->status; |
|
| 801 | + } |
|
| 802 | + if ($data->statusid !== '') { |
|
| 803 | + $result['statusid'] = $data->statusid; |
|
| 804 | + } |
|
| 805 | + if ($data->type !== '') { |
|
| 806 | + $result['type'] = $data->type; |
|
| 807 | + } |
|
| 808 | + if ($data->typeid !== '') { |
|
| 809 | + $result['typeid'] = $data->typeid; |
|
| 810 | + } |
|
| 811 | + if ($data->imo !== '') { |
|
| 812 | + $result['imo'] = $data->imo; |
|
| 813 | + } |
|
| 814 | + if ($data->callsign !== '') { |
|
| 815 | + $result['callsign'] = trim(str_replace('@','',$data->callsign)); |
|
| 816 | + } |
|
| 635 | 817 | if (is_numeric($data->eta_month) && $data->eta_month != 0 && is_numeric($data->eta_day) && $data->eta_day != 0 && $data->eta_hour !== '' && $data->eta_minute !== '') { |
| 636 | 818 | $eta_ts = strtotime(date('Y').'-'.sprintf("%02d",$data->eta_month).'-'.sprintf("%02d",$data->eta_day).' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00'); |
| 637 | - if ($eta_ts != '') $result['eta_ts'] = $eta_ts; |
|
| 819 | + if ($eta_ts != '') { |
|
| 820 | + $result['eta_ts'] = $eta_ts; |
|
| 821 | + } |
|
| 638 | 822 | } elseif (is_numeric($data->eta_hour) && is_numeric($data->eta_minute)) { |
| 639 | 823 | $eta_ts = strtotime(date('Y-m-d').' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00'); |
| 640 | - if ($eta_ts != '') $result['eta_ts'] = $eta_ts; |
|
| 824 | + if ($eta_ts != '') { |
|
| 825 | + $result['eta_ts'] = $eta_ts; |
|
| 826 | + } |
|
| 641 | 827 | } |
| 642 | 828 | if ($data->destination != '') { |
| 643 | 829 | $dest = trim(str_replace('@','',$data->destination)); |
| 644 | - if ($dest != '') $result['destination'] = $dest; |
|
| 830 | + if ($dest != '') { |
|
| 831 | + $result['destination'] = $dest; |
|
| 832 | + } |
|
| 645 | 833 | } |
| 646 | 834 | $result['all'] = (array) $data; |
| 647 | 835 | /* |
@@ -90,6 +90,10 @@ discard block |
||
| 90 | 90 | return strlen($headerLine); // Needed by curl |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | + /** |
|
| 94 | + * @param string $url |
|
| 95 | + * @param string $file |
|
| 96 | + */ |
|
| 93 | 97 | public static function download($url, $file, $referer = '') { |
| 94 | 98 | global $globalDebug; |
| 95 | 99 | $fp = fopen($file, 'w'); |
@@ -190,7 +194,7 @@ discard block |
||
| 190 | 194 | * Check is distance realistic |
| 191 | 195 | * @param int $timeDifference the time between the reception of both messages |
| 192 | 196 | * @param float $distance distance covered |
| 193 | - * @return whether distance is realistic |
|
| 197 | + * @return boolean distance is realistic |
|
| 194 | 198 | */ |
| 195 | 199 | public function withinThreshold ($timeDifference, $distance) { |
| 196 | 200 | $x = abs($timeDifference); |
@@ -213,6 +217,9 @@ discard block |
||
| 213 | 217 | } |
| 214 | 218 | |
| 215 | 219 | |
| 220 | + /** |
|
| 221 | + * @param string $latlong |
|
| 222 | + */ |
|
| 216 | 223 | public function convertDec($dms,$latlong) { |
| 217 | 224 | if ($latlong == 'latitude') { |
| 218 | 225 | $deg = substr($dms, 0, 2); |
@@ -224,6 +231,9 @@ discard block |
||
| 224 | 231 | return $deg+(($min*60)/3600); |
| 225 | 232 | } |
| 226 | 233 | |
| 234 | + /** |
|
| 235 | + * @param string $latlong |
|
| 236 | + */ |
|
| 227 | 237 | public function convertDM($coord,$latlong) { |
| 228 | 238 | if ($latlong == 'latitude') { |
| 229 | 239 | if ($coord < 0) $NSEW = 'S'; |
@@ -352,7 +362,7 @@ discard block |
||
| 352 | 362 | /** |
| 353 | 363 | * Returns list of available locales |
| 354 | 364 | * |
| 355 | - * @return array |
|
| 365 | + * @return string[] |
|
| 356 | 366 | */ |
| 357 | 367 | public function listLocaleDir() |
| 358 | 368 | { |
@@ -37,8 +37,11 @@ discard block |
||
| 37 | 37 | } else { |
| 38 | 38 | curl_setopt($ch, CURLOPT_USERAGENT, $useragent); |
| 39 | 39 | } |
| 40 | - if ($timeout == '') curl_setopt($ch, CURLOPT_TIMEOUT, 10); |
|
| 41 | - else curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
|
| 40 | + if ($timeout == '') { |
|
| 41 | + curl_setopt($ch, CURLOPT_TIMEOUT, 10); |
|
| 42 | + } else { |
|
| 43 | + curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
|
| 44 | + } |
|
| 42 | 45 | curl_setopt($ch, CURLOPT_HEADERFUNCTION, array('Common',"curlResponseHeaderCallback")); |
| 43 | 46 | if ($type == 'post') { |
| 44 | 47 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
@@ -85,8 +88,9 @@ discard block |
||
| 85 | 88 | private function curlResponseHeaderCallback($ch, $headerLine) { |
| 86 | 89 | //global $cookies; |
| 87 | 90 | $cookies = array(); |
| 88 | - if (preg_match('/^Set-Cookie:\s*([^;]*)/mi', $headerLine, $cookie) == 1) |
|
| 89 | - $cookies[] = $cookie; |
|
| 91 | + if (preg_match('/^Set-Cookie:\s*([^;]*)/mi', $headerLine, $cookie) == 1) { |
|
| 92 | + $cookies[] = $cookie; |
|
| 93 | + } |
|
| 90 | 94 | return strlen($headerLine); // Needed by curl |
| 91 | 95 | } |
| 92 | 96 | |
@@ -97,11 +101,15 @@ discard block |
||
| 97 | 101 | curl_setopt($ch, CURLOPT_URL, $url); |
| 98 | 102 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
| 99 | 103 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
| 100 | - if ($referer != '') curl_setopt($ch, CURLOPT_REFERER, $referer); |
|
| 104 | + if ($referer != '') { |
|
| 105 | + curl_setopt($ch, CURLOPT_REFERER, $referer); |
|
| 106 | + } |
|
| 101 | 107 | curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5'); |
| 102 | 108 | curl_setopt($ch, CURLOPT_FILE, $fp); |
| 103 | 109 | curl_exec($ch); |
| 104 | - if (curl_errno($ch) && $globalDebug) echo 'Download error: '.curl_error($ch); |
|
| 110 | + if (curl_errno($ch) && $globalDebug) { |
|
| 111 | + echo 'Download error: '.curl_error($ch); |
|
| 112 | + } |
|
| 105 | 113 | curl_close($ch); |
| 106 | 114 | fclose($fp); |
| 107 | 115 | } |
@@ -112,10 +120,16 @@ discard block |
||
| 112 | 120 | * @return Array array of the tables in HTML page |
| 113 | 121 | */ |
| 114 | 122 | public function table2array($data) { |
| 115 | - if (!is_string($data)) return array(); |
|
| 116 | - if ($data == '') return array(); |
|
| 123 | + if (!is_string($data)) { |
|
| 124 | + return array(); |
|
| 125 | + } |
|
| 126 | + if ($data == '') { |
|
| 127 | + return array(); |
|
| 128 | + } |
|
| 117 | 129 | $html = str_get_html($data); |
| 118 | - if ($html === false) return array(); |
|
| 130 | + if ($html === false) { |
|
| 131 | + return array(); |
|
| 132 | + } |
|
| 119 | 133 | $tabledata=array(); |
| 120 | 134 | foreach($html->find('tr') as $element) |
| 121 | 135 | { |
@@ -150,7 +164,9 @@ discard block |
||
| 150 | 164 | */ |
| 151 | 165 | public function text2array($data) { |
| 152 | 166 | $html = str_get_html($data); |
| 153 | - if ($html === false) return array(); |
|
| 167 | + if ($html === false) { |
|
| 168 | + return array(); |
|
| 169 | + } |
|
| 154 | 170 | $tabledata=array(); |
| 155 | 171 | foreach($html->find('p') as $element) |
| 156 | 172 | { |
@@ -171,7 +187,9 @@ discard block |
||
| 171 | 187 | * @return Float Distance in $unit |
| 172 | 188 | */ |
| 173 | 189 | public function distance($lat, $lon, $latc, $lonc, $unit = 'km') { |
| 174 | - if ($lat == $latc && $lon == $lonc) return 0; |
|
| 190 | + if ($lat == $latc && $lon == $lonc) { |
|
| 191 | + return 0; |
|
| 192 | + } |
|
| 175 | 193 | $dist = rad2deg(acos(sin(deg2rad(floatval($lat)))*sin(deg2rad(floatval($latc)))+ cos(deg2rad(floatval($lat)))*cos(deg2rad(floatval($latc)))*cos(deg2rad(floatval($lon)-floatval($lonc)))))*60*1.1515; |
| 176 | 194 | if ($unit == "km") { |
| 177 | 195 | return round($dist * 1.609344); |
@@ -195,10 +213,16 @@ discard block |
||
| 195 | 213 | public function withinThreshold ($timeDifference, $distance) { |
| 196 | 214 | $x = abs($timeDifference); |
| 197 | 215 | $d = abs($distance); |
| 198 | - if ($x == 0 || $d == 0) return true; |
|
| 216 | + if ($x == 0 || $d == 0) { |
|
| 217 | + return true; |
|
| 218 | + } |
|
| 199 | 219 | // may be due to Internet jitter; distance is realistic |
| 200 | - if ($x < 0.7 && $d < 2000) return true; |
|
| 201 | - else return $d/$x < 1500*0.27778; // 1500 km/h max |
|
| 220 | + if ($x < 0.7 && $d < 2000) { |
|
| 221 | + return true; |
|
| 222 | + } else { |
|
| 223 | + return $d/$x < 1500*0.27778; |
|
| 224 | + } |
|
| 225 | + // 1500 km/h max |
|
| 202 | 226 | } |
| 203 | 227 | |
| 204 | 228 | |
@@ -226,11 +250,17 @@ discard block |
||
| 226 | 250 | |
| 227 | 251 | public function convertDM($coord,$latlong) { |
| 228 | 252 | if ($latlong == 'latitude') { |
| 229 | - if ($coord < 0) $NSEW = 'S'; |
|
| 230 | - else $NSEW = 'N'; |
|
| 253 | + if ($coord < 0) { |
|
| 254 | + $NSEW = 'S'; |
|
| 255 | + } else { |
|
| 256 | + $NSEW = 'N'; |
|
| 257 | + } |
|
| 231 | 258 | } elseif ($latlong == 'longitude') { |
| 232 | - if ($coord < 0) $NSEW = 'W'; |
|
| 233 | - else $NSEW = 'E'; |
|
| 259 | + if ($coord < 0) { |
|
| 260 | + $NSEW = 'W'; |
|
| 261 | + } else { |
|
| 262 | + $NSEW = 'E'; |
|
| 263 | + } |
|
| 234 | 264 | } |
| 235 | 265 | $coord = abs($coord); |
| 236 | 266 | $deg = floor($coord); |
@@ -273,7 +303,9 @@ discard block |
||
| 273 | 303 | public function hex2str($hex) { |
| 274 | 304 | $str = ''; |
| 275 | 305 | $hexln = strlen($hex); |
| 276 | - for($i=0;$i<$hexln;$i+=2) $str .= chr(hexdec(substr($hex,$i,2))); |
|
| 306 | + for($i=0;$i<$hexln;$i+=2) { |
|
| 307 | + $str .= chr(hexdec(substr($hex,$i,2))); |
|
| 308 | + } |
|
| 277 | 309 | return $str; |
| 278 | 310 | } |
| 279 | 311 | |
@@ -301,8 +333,11 @@ discard block |
||
| 301 | 333 | $b = $lat2 - $lat1; |
| 302 | 334 | $c = -($a*$lat1+$b*$lon1); |
| 303 | 335 | $d = $a*$lat3+$b*$lon3+$c; |
| 304 | - if ($d > -$approx && $d < $approx) return true; |
|
| 305 | - else return false; |
|
| 336 | + if ($d > -$approx && $d < $approx) { |
|
| 337 | + return true; |
|
| 338 | + } else { |
|
| 339 | + return false; |
|
| 340 | + } |
|
| 306 | 341 | } |
| 307 | 342 | |
| 308 | 343 | public function array_merge_noappend() { |
@@ -361,7 +396,9 @@ discard block |
||
| 361 | 396 | return $result; |
| 362 | 397 | } |
| 363 | 398 | $handle = @opendir('./locale'); |
| 364 | - if ($handle === false) return $result; |
|
| 399 | + if ($handle === false) { |
|
| 400 | + return $result; |
|
| 401 | + } |
|
| 365 | 402 | while (false !== ($file = readdir($handle))) { |
| 366 | 403 | $path = './locale'.'/'.$file.'/LC_MESSAGES/fam.mo'; |
| 367 | 404 | if ($file != "." && $file != ".." && @file_exists($path)) { |
@@ -428,8 +465,9 @@ discard block |
||
| 428 | 465 | $error = false; |
| 429 | 466 | if ($fp_out = gzopen($dest, $mode)) { |
| 430 | 467 | if ($fp_in = fopen($source,'rb')) { |
| 431 | - while (!feof($fp_in)) |
|
| 432 | - gzwrite($fp_out, fread($fp_in, 1024 * 512)); |
|
| 468 | + while (!feof($fp_in)) { |
|
| 469 | + gzwrite($fp_out, fread($fp_in, 1024 * 512)); |
|
| 470 | + } |
|
| 433 | 471 | fclose($fp_in); |
| 434 | 472 | } else { |
| 435 | 473 | $error = true; |
@@ -438,14 +476,17 @@ discard block |
||
| 438 | 476 | } else { |
| 439 | 477 | $error = true; |
| 440 | 478 | } |
| 441 | - if ($error) |
|
| 442 | - return false; |
|
| 443 | - else |
|
| 444 | - return $dest; |
|
| 479 | + if ($error) { |
|
| 480 | + return false; |
|
| 481 | + } else { |
|
| 482 | + return $dest; |
|
| 483 | + } |
|
| 445 | 484 | } |
| 446 | 485 | |
| 447 | 486 | public function remove_accents($string) { |
| 448 | - if ( !preg_match('/[\x80-\xff]/', $string) ) return $string; |
|
| 487 | + if ( !preg_match('/[\x80-\xff]/', $string) ) { |
|
| 488 | + return $string; |
|
| 489 | + } |
|
| 449 | 490 | $chars = array( |
| 450 | 491 | // Decompositions for Latin-1 Supplement |
| 451 | 492 | chr(195).chr(128) => 'A', chr(195).chr(129) => 'A', |
@@ -569,7 +610,9 @@ discard block |
||
| 569 | 610 | $ip = gethostbyname($host); |
| 570 | 611 | $s = socket_create(AF_INET, SOCK_STREAM, 0); |
| 571 | 612 | $r = @socket_connect($s, $ip, $port); |
| 572 | - if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n"; |
|
| 613 | + if (!socket_set_nonblock($s)) { |
|
| 614 | + echo "Unable to set nonblock on socket\n"; |
|
| 615 | + } |
|
| 573 | 616 | if ($r || socket_last_error() == 114 || socket_last_error() == 115) { |
| 574 | 617 | return $s; |
| 575 | 618 | } |
@@ -7,13 +7,13 @@ discard block |
||
| 7 | 7 | //protected $cookies = array(); |
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | - * Get data from form result |
|
| 11 | - * @param String $url form URL |
|
| 12 | - * @param String $type type of submit form method (get or post) |
|
| 13 | - * @param String|Array $data values form post method |
|
| 14 | - * @param Array $headers header to submit with the form |
|
| 15 | - * @return String the result |
|
| 16 | - */ |
|
| 10 | + * Get data from form result |
|
| 11 | + * @param String $url form URL |
|
| 12 | + * @param String $type type of submit form method (get or post) |
|
| 13 | + * @param String|Array $data values form post method |
|
| 14 | + * @param Array $headers header to submit with the form |
|
| 15 | + * @return String the result |
|
| 16 | + */ |
|
| 17 | 17 | public function getData($url, $type = 'get', $data = '', $headers = '',$cookie = '',$referer = '',$timeout = '',$useragent = '') { |
| 18 | 18 | global $globalProxy, $globalForceIPv4; |
| 19 | 19 | $ch = curl_init(); |
@@ -107,10 +107,10 @@ discard block |
||
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
| 110 | - * Convert a HTML table to an array |
|
| 111 | - * @param String $data HTML page |
|
| 112 | - * @return Array array of the tables in HTML page |
|
| 113 | - */ |
|
| 110 | + * Convert a HTML table to an array |
|
| 111 | + * @param String $data HTML page |
|
| 112 | + * @return Array array of the tables in HTML page |
|
| 113 | + */ |
|
| 114 | 114 | public function table2array($data) { |
| 115 | 115 | if (!is_string($data)) return array(); |
| 116 | 116 | if ($data == '') return array(); |
@@ -144,10 +144,10 @@ discard block |
||
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
| 147 | - * Convert <p> part of a HTML page to an array |
|
| 148 | - * @param String $data HTML page |
|
| 149 | - * @return Array array of the <p> in HTML page |
|
| 150 | - */ |
|
| 147 | + * Convert <p> part of a HTML page to an array |
|
| 148 | + * @param String $data HTML page |
|
| 149 | + * @return Array array of the <p> in HTML page |
|
| 150 | + */ |
|
| 151 | 151 | public function text2array($data) { |
| 152 | 152 | $html = str_get_html($data); |
| 153 | 153 | if ($html === false) return array(); |
@@ -162,14 +162,14 @@ discard block |
||
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
| 165 | - * Give distance between 2 coordonnates |
|
| 166 | - * @param Float $lat latitude of first point |
|
| 167 | - * @param Float $lon longitude of first point |
|
| 168 | - * @param Float $latc latitude of second point |
|
| 169 | - * @param Float $lonc longitude of second point |
|
| 170 | - * @param String $unit km else no unit used |
|
| 171 | - * @return Float Distance in $unit |
|
| 172 | - */ |
|
| 165 | + * Give distance between 2 coordonnates |
|
| 166 | + * @param Float $lat latitude of first point |
|
| 167 | + * @param Float $lon longitude of first point |
|
| 168 | + * @param Float $latc latitude of second point |
|
| 169 | + * @param Float $lonc longitude of second point |
|
| 170 | + * @param String $unit km else no unit used |
|
| 171 | + * @return Float Distance in $unit |
|
| 172 | + */ |
|
| 173 | 173 | public function distance($lat, $lon, $latc, $lonc, $unit = 'km') { |
| 174 | 174 | if ($lat == $latc && $lon == $lonc) return 0; |
| 175 | 175 | $dist = rad2deg(acos(sin(deg2rad(floatval($lat)))*sin(deg2rad(floatval($latc)))+ cos(deg2rad(floatval($lat)))*cos(deg2rad(floatval($latc)))*cos(deg2rad(floatval($lon)-floatval($lonc)))))*60*1.1515; |
@@ -187,11 +187,11 @@ discard block |
||
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | /** |
| 190 | - * Check is distance realistic |
|
| 191 | - * @param int $timeDifference the time between the reception of both messages |
|
| 192 | - * @param float $distance distance covered |
|
| 193 | - * @return whether distance is realistic |
|
| 194 | - */ |
|
| 190 | + * Check is distance realistic |
|
| 191 | + * @param int $timeDifference the time between the reception of both messages |
|
| 192 | + * @param float $distance distance covered |
|
| 193 | + * @return whether distance is realistic |
|
| 194 | + */ |
|
| 195 | 195 | public function withinThreshold ($timeDifference, $distance) { |
| 196 | 196 | $x = abs($timeDifference); |
| 197 | 197 | $d = abs($distance); |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | public function isInteger($input){ |
| 212 | - return(ctype_digit(strval($input))); |
|
| 212 | + return(ctype_digit(strval($input))); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | |
@@ -240,11 +240,11 @@ discard block |
||
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
| 243 | - * Copy folder contents |
|
| 244 | - * @param string $source Source path |
|
| 245 | - * @param string $dest Destination path |
|
| 246 | - * @return bool Returns true on success, false on failure |
|
| 247 | - */ |
|
| 243 | + * Copy folder contents |
|
| 244 | + * @param string $source Source path |
|
| 245 | + * @param string $dest Destination path |
|
| 246 | + * @return bool Returns true on success, false on failure |
|
| 247 | + */ |
|
| 248 | 248 | public function xcopy($source, $dest) |
| 249 | 249 | { |
| 250 | 250 | $files = glob($source.'*.*'); |
@@ -256,20 +256,20 @@ discard block |
||
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | /** |
| 259 | - * Check if an url exist |
|
| 260 | - * @param String $url url to check |
|
| 261 | - * @return bool Return true on succes false on failure |
|
| 262 | - */ |
|
| 259 | + * Check if an url exist |
|
| 260 | + * @param String $url url to check |
|
| 261 | + * @return bool Return true on succes false on failure |
|
| 262 | + */ |
|
| 263 | 263 | public function urlexist($url){ |
| 264 | 264 | $headers=get_headers($url); |
| 265 | 265 | return stripos($headers[0],"200 OK")?true:false; |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | /** |
| 269 | - * Convert hexa to string |
|
| 270 | - * @param String $hex data in hexa |
|
| 271 | - * @return String Return result |
|
| 272 | - */ |
|
| 269 | + * Convert hexa to string |
|
| 270 | + * @param String $hex data in hexa |
|
| 271 | + * @return String Return result |
|
| 272 | + */ |
|
| 273 | 273 | public function hex2str($hex) { |
| 274 | 274 | $str = ''; |
| 275 | 275 | $hexln = strlen($hex); |
@@ -278,10 +278,10 @@ discard block |
||
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | /** |
| 281 | - * Convert hexa color to rgb |
|
| 282 | - * @param String $hex data in hexa |
|
| 283 | - * @return String Return result |
|
| 284 | - */ |
|
| 281 | + * Convert hexa color to rgb |
|
| 282 | + * @param String $hex data in hexa |
|
| 283 | + * @return String Return result |
|
| 284 | + */ |
|
| 285 | 285 | public function hex2rgb($hex) { |
| 286 | 286 | $hex = str_replace('#','',$hex); |
| 287 | 287 | return sscanf($hex, "%02x%02x%02x"); |
@@ -359,9 +359,9 @@ discard block |
||
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | /** |
| 362 | - * Returns list of available locales |
|
| 363 | - * |
|
| 364 | - * @return array |
|
| 362 | + * Returns list of available locales |
|
| 363 | + * |
|
| 364 | + * @return array |
|
| 365 | 365 | */ |
| 366 | 366 | public function listLocaleDir() |
| 367 | 367 | { |
@@ -456,100 +456,100 @@ discard block |
||
| 456 | 456 | public function remove_accents($string) { |
| 457 | 457 | if ( !preg_match('/[\x80-\xff]/', $string) ) return $string; |
| 458 | 458 | $chars = array( |
| 459 | - // Decompositions for Latin-1 Supplement |
|
| 460 | - chr(195).chr(128) => 'A', chr(195).chr(129) => 'A', |
|
| 461 | - chr(195).chr(130) => 'A', chr(195).chr(131) => 'A', |
|
| 462 | - chr(195).chr(132) => 'A', chr(195).chr(133) => 'A', |
|
| 463 | - chr(195).chr(135) => 'C', chr(195).chr(136) => 'E', |
|
| 464 | - chr(195).chr(137) => 'E', chr(195).chr(138) => 'E', |
|
| 465 | - chr(195).chr(139) => 'E', chr(195).chr(140) => 'I', |
|
| 466 | - chr(195).chr(141) => 'I', chr(195).chr(142) => 'I', |
|
| 467 | - chr(195).chr(143) => 'I', chr(195).chr(145) => 'N', |
|
| 468 | - chr(195).chr(146) => 'O', chr(195).chr(147) => 'O', |
|
| 469 | - chr(195).chr(148) => 'O', chr(195).chr(149) => 'O', |
|
| 470 | - chr(195).chr(150) => 'O', chr(195).chr(153) => 'U', |
|
| 471 | - chr(195).chr(154) => 'U', chr(195).chr(155) => 'U', |
|
| 472 | - chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y', |
|
| 473 | - chr(195).chr(159) => 's', chr(195).chr(160) => 'a', |
|
| 474 | - chr(195).chr(161) => 'a', chr(195).chr(162) => 'a', |
|
| 475 | - chr(195).chr(163) => 'a', chr(195).chr(164) => 'a', |
|
| 476 | - chr(195).chr(165) => 'a', chr(195).chr(167) => 'c', |
|
| 477 | - chr(195).chr(168) => 'e', chr(195).chr(169) => 'e', |
|
| 478 | - chr(195).chr(170) => 'e', chr(195).chr(171) => 'e', |
|
| 479 | - chr(195).chr(172) => 'i', chr(195).chr(173) => 'i', |
|
| 480 | - chr(195).chr(174) => 'i', chr(195).chr(175) => 'i', |
|
| 481 | - chr(195).chr(177) => 'n', chr(195).chr(178) => 'o', |
|
| 482 | - chr(195).chr(179) => 'o', chr(195).chr(180) => 'o', |
|
| 483 | - chr(195).chr(181) => 'o', chr(195).chr(182) => 'o', |
|
| 484 | - chr(195).chr(182) => 'o', chr(195).chr(185) => 'u', |
|
| 485 | - chr(195).chr(186) => 'u', chr(195).chr(187) => 'u', |
|
| 486 | - chr(195).chr(188) => 'u', chr(195).chr(189) => 'y', |
|
| 487 | - chr(195).chr(191) => 'y', |
|
| 488 | - // Decompositions for Latin Extended-A |
|
| 489 | - chr(196).chr(128) => 'A', chr(196).chr(129) => 'a', |
|
| 490 | - chr(196).chr(130) => 'A', chr(196).chr(131) => 'a', |
|
| 491 | - chr(196).chr(132) => 'A', chr(196).chr(133) => 'a', |
|
| 492 | - chr(196).chr(134) => 'C', chr(196).chr(135) => 'c', |
|
| 493 | - chr(196).chr(136) => 'C', chr(196).chr(137) => 'c', |
|
| 494 | - chr(196).chr(138) => 'C', chr(196).chr(139) => 'c', |
|
| 495 | - chr(196).chr(140) => 'C', chr(196).chr(141) => 'c', |
|
| 496 | - chr(196).chr(142) => 'D', chr(196).chr(143) => 'd', |
|
| 497 | - chr(196).chr(144) => 'D', chr(196).chr(145) => 'd', |
|
| 498 | - chr(196).chr(146) => 'E', chr(196).chr(147) => 'e', |
|
| 499 | - chr(196).chr(148) => 'E', chr(196).chr(149) => 'e', |
|
| 500 | - chr(196).chr(150) => 'E', chr(196).chr(151) => 'e', |
|
| 501 | - chr(196).chr(152) => 'E', chr(196).chr(153) => 'e', |
|
| 502 | - chr(196).chr(154) => 'E', chr(196).chr(155) => 'e', |
|
| 503 | - chr(196).chr(156) => 'G', chr(196).chr(157) => 'g', |
|
| 504 | - chr(196).chr(158) => 'G', chr(196).chr(159) => 'g', |
|
| 505 | - chr(196).chr(160) => 'G', chr(196).chr(161) => 'g', |
|
| 506 | - chr(196).chr(162) => 'G', chr(196).chr(163) => 'g', |
|
| 507 | - chr(196).chr(164) => 'H', chr(196).chr(165) => 'h', |
|
| 508 | - chr(196).chr(166) => 'H', chr(196).chr(167) => 'h', |
|
| 509 | - chr(196).chr(168) => 'I', chr(196).chr(169) => 'i', |
|
| 510 | - chr(196).chr(170) => 'I', chr(196).chr(171) => 'i', |
|
| 511 | - chr(196).chr(172) => 'I', chr(196).chr(173) => 'i', |
|
| 512 | - chr(196).chr(174) => 'I', chr(196).chr(175) => 'i', |
|
| 513 | - chr(196).chr(176) => 'I', chr(196).chr(177) => 'i', |
|
| 514 | - chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij', |
|
| 515 | - chr(196).chr(180) => 'J', chr(196).chr(181) => 'j', |
|
| 516 | - chr(196).chr(182) => 'K', chr(196).chr(183) => 'k', |
|
| 517 | - chr(196).chr(184) => 'k', chr(196).chr(185) => 'L', |
|
| 518 | - chr(196).chr(186) => 'l', chr(196).chr(187) => 'L', |
|
| 519 | - chr(196).chr(188) => 'l', chr(196).chr(189) => 'L', |
|
| 520 | - chr(196).chr(190) => 'l', chr(196).chr(191) => 'L', |
|
| 521 | - chr(197).chr(128) => 'l', chr(197).chr(129) => 'L', |
|
| 522 | - chr(197).chr(130) => 'l', chr(197).chr(131) => 'N', |
|
| 523 | - chr(197).chr(132) => 'n', chr(197).chr(133) => 'N', |
|
| 524 | - chr(197).chr(134) => 'n', chr(197).chr(135) => 'N', |
|
| 525 | - chr(197).chr(136) => 'n', chr(197).chr(137) => 'N', |
|
| 526 | - chr(197).chr(138) => 'n', chr(197).chr(139) => 'N', |
|
| 527 | - chr(197).chr(140) => 'O', chr(197).chr(141) => 'o', |
|
| 528 | - chr(197).chr(142) => 'O', chr(197).chr(143) => 'o', |
|
| 529 | - chr(197).chr(144) => 'O', chr(197).chr(145) => 'o', |
|
| 530 | - chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe', |
|
| 531 | - chr(197).chr(148) => 'R',chr(197).chr(149) => 'r', |
|
| 532 | - chr(197).chr(150) => 'R',chr(197).chr(151) => 'r', |
|
| 533 | - chr(197).chr(152) => 'R',chr(197).chr(153) => 'r', |
|
| 534 | - chr(197).chr(154) => 'S',chr(197).chr(155) => 's', |
|
| 535 | - chr(197).chr(156) => 'S',chr(197).chr(157) => 's', |
|
| 536 | - chr(197).chr(158) => 'S',chr(197).chr(159) => 's', |
|
| 537 | - chr(197).chr(160) => 'S', chr(197).chr(161) => 's', |
|
| 538 | - chr(197).chr(162) => 'T', chr(197).chr(163) => 't', |
|
| 539 | - chr(197).chr(164) => 'T', chr(197).chr(165) => 't', |
|
| 540 | - chr(197).chr(166) => 'T', chr(197).chr(167) => 't', |
|
| 541 | - chr(197).chr(168) => 'U', chr(197).chr(169) => 'u', |
|
| 542 | - chr(197).chr(170) => 'U', chr(197).chr(171) => 'u', |
|
| 543 | - chr(197).chr(172) => 'U', chr(197).chr(173) => 'u', |
|
| 544 | - chr(197).chr(174) => 'U', chr(197).chr(175) => 'u', |
|
| 545 | - chr(197).chr(176) => 'U', chr(197).chr(177) => 'u', |
|
| 546 | - chr(197).chr(178) => 'U', chr(197).chr(179) => 'u', |
|
| 547 | - chr(197).chr(180) => 'W', chr(197).chr(181) => 'w', |
|
| 548 | - chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y', |
|
| 549 | - chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z', |
|
| 550 | - chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z', |
|
| 551 | - chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z', |
|
| 552 | - chr(197).chr(190) => 'z', chr(197).chr(191) => 's' |
|
| 459 | + // Decompositions for Latin-1 Supplement |
|
| 460 | + chr(195).chr(128) => 'A', chr(195).chr(129) => 'A', |
|
| 461 | + chr(195).chr(130) => 'A', chr(195).chr(131) => 'A', |
|
| 462 | + chr(195).chr(132) => 'A', chr(195).chr(133) => 'A', |
|
| 463 | + chr(195).chr(135) => 'C', chr(195).chr(136) => 'E', |
|
| 464 | + chr(195).chr(137) => 'E', chr(195).chr(138) => 'E', |
|
| 465 | + chr(195).chr(139) => 'E', chr(195).chr(140) => 'I', |
|
| 466 | + chr(195).chr(141) => 'I', chr(195).chr(142) => 'I', |
|
| 467 | + chr(195).chr(143) => 'I', chr(195).chr(145) => 'N', |
|
| 468 | + chr(195).chr(146) => 'O', chr(195).chr(147) => 'O', |
|
| 469 | + chr(195).chr(148) => 'O', chr(195).chr(149) => 'O', |
|
| 470 | + chr(195).chr(150) => 'O', chr(195).chr(153) => 'U', |
|
| 471 | + chr(195).chr(154) => 'U', chr(195).chr(155) => 'U', |
|
| 472 | + chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y', |
|
| 473 | + chr(195).chr(159) => 's', chr(195).chr(160) => 'a', |
|
| 474 | + chr(195).chr(161) => 'a', chr(195).chr(162) => 'a', |
|
| 475 | + chr(195).chr(163) => 'a', chr(195).chr(164) => 'a', |
|
| 476 | + chr(195).chr(165) => 'a', chr(195).chr(167) => 'c', |
|
| 477 | + chr(195).chr(168) => 'e', chr(195).chr(169) => 'e', |
|
| 478 | + chr(195).chr(170) => 'e', chr(195).chr(171) => 'e', |
|
| 479 | + chr(195).chr(172) => 'i', chr(195).chr(173) => 'i', |
|
| 480 | + chr(195).chr(174) => 'i', chr(195).chr(175) => 'i', |
|
| 481 | + chr(195).chr(177) => 'n', chr(195).chr(178) => 'o', |
|
| 482 | + chr(195).chr(179) => 'o', chr(195).chr(180) => 'o', |
|
| 483 | + chr(195).chr(181) => 'o', chr(195).chr(182) => 'o', |
|
| 484 | + chr(195).chr(182) => 'o', chr(195).chr(185) => 'u', |
|
| 485 | + chr(195).chr(186) => 'u', chr(195).chr(187) => 'u', |
|
| 486 | + chr(195).chr(188) => 'u', chr(195).chr(189) => 'y', |
|
| 487 | + chr(195).chr(191) => 'y', |
|
| 488 | + // Decompositions for Latin Extended-A |
|
| 489 | + chr(196).chr(128) => 'A', chr(196).chr(129) => 'a', |
|
| 490 | + chr(196).chr(130) => 'A', chr(196).chr(131) => 'a', |
|
| 491 | + chr(196).chr(132) => 'A', chr(196).chr(133) => 'a', |
|
| 492 | + chr(196).chr(134) => 'C', chr(196).chr(135) => 'c', |
|
| 493 | + chr(196).chr(136) => 'C', chr(196).chr(137) => 'c', |
|
| 494 | + chr(196).chr(138) => 'C', chr(196).chr(139) => 'c', |
|
| 495 | + chr(196).chr(140) => 'C', chr(196).chr(141) => 'c', |
|
| 496 | + chr(196).chr(142) => 'D', chr(196).chr(143) => 'd', |
|
| 497 | + chr(196).chr(144) => 'D', chr(196).chr(145) => 'd', |
|
| 498 | + chr(196).chr(146) => 'E', chr(196).chr(147) => 'e', |
|
| 499 | + chr(196).chr(148) => 'E', chr(196).chr(149) => 'e', |
|
| 500 | + chr(196).chr(150) => 'E', chr(196).chr(151) => 'e', |
|
| 501 | + chr(196).chr(152) => 'E', chr(196).chr(153) => 'e', |
|
| 502 | + chr(196).chr(154) => 'E', chr(196).chr(155) => 'e', |
|
| 503 | + chr(196).chr(156) => 'G', chr(196).chr(157) => 'g', |
|
| 504 | + chr(196).chr(158) => 'G', chr(196).chr(159) => 'g', |
|
| 505 | + chr(196).chr(160) => 'G', chr(196).chr(161) => 'g', |
|
| 506 | + chr(196).chr(162) => 'G', chr(196).chr(163) => 'g', |
|
| 507 | + chr(196).chr(164) => 'H', chr(196).chr(165) => 'h', |
|
| 508 | + chr(196).chr(166) => 'H', chr(196).chr(167) => 'h', |
|
| 509 | + chr(196).chr(168) => 'I', chr(196).chr(169) => 'i', |
|
| 510 | + chr(196).chr(170) => 'I', chr(196).chr(171) => 'i', |
|
| 511 | + chr(196).chr(172) => 'I', chr(196).chr(173) => 'i', |
|
| 512 | + chr(196).chr(174) => 'I', chr(196).chr(175) => 'i', |
|
| 513 | + chr(196).chr(176) => 'I', chr(196).chr(177) => 'i', |
|
| 514 | + chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij', |
|
| 515 | + chr(196).chr(180) => 'J', chr(196).chr(181) => 'j', |
|
| 516 | + chr(196).chr(182) => 'K', chr(196).chr(183) => 'k', |
|
| 517 | + chr(196).chr(184) => 'k', chr(196).chr(185) => 'L', |
|
| 518 | + chr(196).chr(186) => 'l', chr(196).chr(187) => 'L', |
|
| 519 | + chr(196).chr(188) => 'l', chr(196).chr(189) => 'L', |
|
| 520 | + chr(196).chr(190) => 'l', chr(196).chr(191) => 'L', |
|
| 521 | + chr(197).chr(128) => 'l', chr(197).chr(129) => 'L', |
|
| 522 | + chr(197).chr(130) => 'l', chr(197).chr(131) => 'N', |
|
| 523 | + chr(197).chr(132) => 'n', chr(197).chr(133) => 'N', |
|
| 524 | + chr(197).chr(134) => 'n', chr(197).chr(135) => 'N', |
|
| 525 | + chr(197).chr(136) => 'n', chr(197).chr(137) => 'N', |
|
| 526 | + chr(197).chr(138) => 'n', chr(197).chr(139) => 'N', |
|
| 527 | + chr(197).chr(140) => 'O', chr(197).chr(141) => 'o', |
|
| 528 | + chr(197).chr(142) => 'O', chr(197).chr(143) => 'o', |
|
| 529 | + chr(197).chr(144) => 'O', chr(197).chr(145) => 'o', |
|
| 530 | + chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe', |
|
| 531 | + chr(197).chr(148) => 'R',chr(197).chr(149) => 'r', |
|
| 532 | + chr(197).chr(150) => 'R',chr(197).chr(151) => 'r', |
|
| 533 | + chr(197).chr(152) => 'R',chr(197).chr(153) => 'r', |
|
| 534 | + chr(197).chr(154) => 'S',chr(197).chr(155) => 's', |
|
| 535 | + chr(197).chr(156) => 'S',chr(197).chr(157) => 's', |
|
| 536 | + chr(197).chr(158) => 'S',chr(197).chr(159) => 's', |
|
| 537 | + chr(197).chr(160) => 'S', chr(197).chr(161) => 's', |
|
| 538 | + chr(197).chr(162) => 'T', chr(197).chr(163) => 't', |
|
| 539 | + chr(197).chr(164) => 'T', chr(197).chr(165) => 't', |
|
| 540 | + chr(197).chr(166) => 'T', chr(197).chr(167) => 't', |
|
| 541 | + chr(197).chr(168) => 'U', chr(197).chr(169) => 'u', |
|
| 542 | + chr(197).chr(170) => 'U', chr(197).chr(171) => 'u', |
|
| 543 | + chr(197).chr(172) => 'U', chr(197).chr(173) => 'u', |
|
| 544 | + chr(197).chr(174) => 'U', chr(197).chr(175) => 'u', |
|
| 545 | + chr(197).chr(176) => 'U', chr(197).chr(177) => 'u', |
|
| 546 | + chr(197).chr(178) => 'U', chr(197).chr(179) => 'u', |
|
| 547 | + chr(197).chr(180) => 'W', chr(197).chr(181) => 'w', |
|
| 548 | + chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y', |
|
| 549 | + chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z', |
|
| 550 | + chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z', |
|
| 551 | + chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z', |
|
| 552 | + chr(197).chr(190) => 'z', chr(197).chr(191) => 's' |
|
| 553 | 553 | ); |
| 554 | 554 | $string = strtr($string, $chars); |
| 555 | 555 | return $string; |
@@ -14,12 +14,12 @@ discard block |
||
| 14 | 14 | * @param Array $headers header to submit with the form |
| 15 | 15 | * @return String the result |
| 16 | 16 | */ |
| 17 | - public function getData($url, $type = 'get', $data = '', $headers = '',$cookie = '',$referer = '',$timeout = '',$useragent = '') { |
|
| 17 | + public function getData($url, $type = 'get', $data = '', $headers = '', $cookie = '', $referer = '', $timeout = '', $useragent = '') { |
|
| 18 | 18 | global $globalProxy, $globalForceIPv4; |
| 19 | 19 | $ch = curl_init(); |
| 20 | 20 | curl_setopt($ch, CURLOPT_URL, $url); |
| 21 | 21 | if (isset($globalForceIPv4) && $globalForceIPv4) { |
| 22 | - if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')){ |
|
| 22 | + if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')) { |
|
| 23 | 23 | curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); |
| 24 | 24 | } |
| 25 | 25 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| 30 | 30 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
| 31 | 31 | curl_setopt($ch, CURLINFO_HEADER_OUT, true); |
| 32 | - curl_setopt($ch,CURLOPT_ENCODING , "gzip"); |
|
| 32 | + curl_setopt($ch, CURLOPT_ENCODING, "gzip"); |
|
| 33 | 33 | //curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5'); |
| 34 | 34 | // curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64; rv:42.0) Gecko/20100101 Firefox/42.0'); |
| 35 | 35 | if ($useragent == '') { |
@@ -39,13 +39,13 @@ discard block |
||
| 39 | 39 | } |
| 40 | 40 | if ($timeout == '') curl_setopt($ch, CURLOPT_TIMEOUT, 10); |
| 41 | 41 | else curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
| 42 | - curl_setopt($ch, CURLOPT_HEADERFUNCTION, array('Common',"curlResponseHeaderCallback")); |
|
| 42 | + curl_setopt($ch, CURLOPT_HEADERFUNCTION, array('Common', "curlResponseHeaderCallback")); |
|
| 43 | 43 | if ($type == 'post') { |
| 44 | 44 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
| 45 | 45 | if (is_array($data)) { |
| 46 | 46 | curl_setopt($ch, CURLOPT_POST, count($data)); |
| 47 | 47 | $data_string = ''; |
| 48 | - foreach($data as $key=>$value) { $data_string .= $key.'='.$value.'&'; } |
|
| 48 | + foreach ($data as $key=>$value) { $data_string .= $key.'='.$value.'&'; } |
|
| 49 | 49 | rtrim($data_string, '&'); |
| 50 | 50 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); |
| 51 | 51 | } else { |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | } |
| 58 | 58 | if ($cookie != '') { |
| 59 | 59 | if (is_array($cookie)) { |
| 60 | - curl_setopt($ch, CURLOPT_COOKIE, implode($cookie,';')); |
|
| 60 | + curl_setopt($ch, CURLOPT_COOKIE, implode($cookie, ';')); |
|
| 61 | 61 | } else { |
| 62 | 62 | curl_setopt($ch, CURLOPT_COOKIE, $cookie); |
| 63 | 63 | } |
@@ -69,13 +69,13 @@ discard block |
||
| 69 | 69 | $info = curl_getinfo($ch); |
| 70 | 70 | //var_dump($info); |
| 71 | 71 | curl_close($ch); |
| 72 | - if ($info['http_code'] == '503' && strstr($result,'DDoS protection by CloudFlare')) { |
|
| 72 | + if ($info['http_code'] == '503' && strstr($result, 'DDoS protection by CloudFlare')) { |
|
| 73 | 73 | echo "Cloudflare Detected\n"; |
| 74 | 74 | require_once(dirname(__FILE__).'/libs/cloudflare-bypass/libraries/cloudflareClass.php'); |
| 75 | 75 | $useragent = UAgent::random(); |
| 76 | 76 | cloudflare::useUserAgent($useragent); |
| 77 | 77 | if ($clearanceCookie = cloudflare::bypass($url)) { |
| 78 | - return $this->getData($url,'get',$data,$headers,$clearanceCookie,$referer,$timeout,$useragent); |
|
| 78 | + return $this->getData($url, 'get', $data, $headers, $clearanceCookie, $referer, $timeout, $useragent); |
|
| 79 | 79 | } |
| 80 | 80 | } else { |
| 81 | 81 | return $result; |
@@ -116,27 +116,27 @@ discard block |
||
| 116 | 116 | if ($data == '') return array(); |
| 117 | 117 | $html = str_get_html($data); |
| 118 | 118 | if ($html === false) return array(); |
| 119 | - $tabledata=array(); |
|
| 120 | - foreach($html->find('tr') as $element) |
|
| 119 | + $tabledata = array(); |
|
| 120 | + foreach ($html->find('tr') as $element) |
|
| 121 | 121 | { |
| 122 | 122 | $td = array(); |
| 123 | - foreach( $element->find('th') as $row) |
|
| 123 | + foreach ($element->find('th') as $row) |
|
| 124 | 124 | { |
| 125 | 125 | $td [] = trim($row->plaintext); |
| 126 | 126 | } |
| 127 | - $td=array_filter($td); |
|
| 127 | + $td = array_filter($td); |
|
| 128 | 128 | $tabledata[] = $td; |
| 129 | 129 | |
| 130 | 130 | $td = array(); |
| 131 | 131 | $tdi = array(); |
| 132 | - foreach( $element->find('td') as $row) |
|
| 132 | + foreach ($element->find('td') as $row) |
|
| 133 | 133 | { |
| 134 | 134 | $td [] = trim($row->plaintext); |
| 135 | 135 | $tdi [] = trim($row->innertext); |
| 136 | 136 | } |
| 137 | - $td=array_filter($td); |
|
| 138 | - $tdi=array_filter($tdi); |
|
| 139 | - $tabledata[]=array_merge($td,$tdi); |
|
| 137 | + $td = array_filter($td); |
|
| 138 | + $tdi = array_filter($tdi); |
|
| 139 | + $tabledata[] = array_merge($td, $tdi); |
|
| 140 | 140 | } |
| 141 | 141 | $html->clear(); |
| 142 | 142 | unset($html); |
@@ -151,8 +151,8 @@ discard block |
||
| 151 | 151 | public function text2array($data) { |
| 152 | 152 | $html = str_get_html($data); |
| 153 | 153 | if ($html === false) return array(); |
| 154 | - $tabledata=array(); |
|
| 155 | - foreach($html->find('p') as $element) |
|
| 154 | + $tabledata = array(); |
|
| 155 | + foreach ($html->find('p') as $element) |
|
| 156 | 156 | { |
| 157 | 157 | $tabledata [] = trim($element->plaintext); |
| 158 | 158 | } |
@@ -172,11 +172,11 @@ discard block |
||
| 172 | 172 | */ |
| 173 | 173 | public function distance($lat, $lon, $latc, $lonc, $unit = 'km') { |
| 174 | 174 | if ($lat == $latc && $lon == $lonc) return 0; |
| 175 | - $dist = rad2deg(acos(sin(deg2rad(floatval($lat)))*sin(deg2rad(floatval($latc)))+ cos(deg2rad(floatval($lat)))*cos(deg2rad(floatval($latc)))*cos(deg2rad(floatval($lon)-floatval($lonc)))))*60*1.1515; |
|
| 175 | + $dist = rad2deg(acos(sin(deg2rad(floatval($lat)))*sin(deg2rad(floatval($latc))) + cos(deg2rad(floatval($lat)))*cos(deg2rad(floatval($latc)))*cos(deg2rad(floatval($lon) - floatval($lonc)))))*60*1.1515; |
|
| 176 | 176 | if ($unit == "km") { |
| 177 | - return round($dist * 1.609344); |
|
| 177 | + return round($dist*1.609344); |
|
| 178 | 178 | } elseif ($unit == "m") { |
| 179 | - return round($dist * 1.609344 * 1000); |
|
| 179 | + return round($dist*1.609344*1000); |
|
| 180 | 180 | } elseif ($unit == "mile" || $unit == "mi") { |
| 181 | 181 | return round($dist); |
| 182 | 182 | } elseif ($unit == "nm") { |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | * @param float $distance distance covered |
| 193 | 193 | * @return whether distance is realistic |
| 194 | 194 | */ |
| 195 | - public function withinThreshold ($timeDifference, $distance) { |
|
| 195 | + public function withinThreshold($timeDifference, $distance) { |
|
| 196 | 196 | $x = abs($timeDifference); |
| 197 | 197 | $d = abs($distance); |
| 198 | 198 | if ($x == 0 || $d == 0) return true; |
@@ -208,12 +208,12 @@ discard block |
||
| 208 | 208 | return ($array !== array_values($array)); |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - public function isInteger($input){ |
|
| 211 | + public function isInteger($input) { |
|
| 212 | 212 | return(ctype_digit(strval($input))); |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | |
| 216 | - public function convertDec($dms,$latlong) { |
|
| 216 | + public function convertDec($dms, $latlong) { |
|
| 217 | 217 | if ($latlong == 'latitude') { |
| 218 | 218 | $deg = substr($dms, 0, 2); |
| 219 | 219 | $min = substr($dms, 2, 4); |
@@ -221,10 +221,10 @@ discard block |
||
| 221 | 221 | $deg = substr($dms, 0, 3); |
| 222 | 222 | $min = substr($dms, 3, 5); |
| 223 | 223 | } |
| 224 | - return $deg+(($min*60)/3600); |
|
| 224 | + return $deg + (($min*60)/3600); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - public function convertDM($coord,$latlong) { |
|
| 227 | + public function convertDM($coord, $latlong) { |
|
| 228 | 228 | if ($latlong == 'latitude') { |
| 229 | 229 | if ($coord < 0) $NSEW = 'S'; |
| 230 | 230 | else $NSEW = 'N'; |
@@ -234,9 +234,9 @@ discard block |
||
| 234 | 234 | } |
| 235 | 235 | $coord = abs($coord); |
| 236 | 236 | $deg = floor($coord); |
| 237 | - $coord = ($coord-$deg)*60; |
|
| 237 | + $coord = ($coord - $deg)*60; |
|
| 238 | 238 | $min = $coord; |
| 239 | - return array('deg' => $deg,'min' => $min,'NSEW' => $NSEW); |
|
| 239 | + return array('deg' => $deg, 'min' => $min, 'NSEW' => $NSEW); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -248,8 +248,8 @@ discard block |
||
| 248 | 248 | public function xcopy($source, $dest) |
| 249 | 249 | { |
| 250 | 250 | $files = glob($source.'*.*'); |
| 251 | - foreach($files as $file){ |
|
| 252 | - $file_to_go = str_replace($source,$dest,$file); |
|
| 251 | + foreach ($files as $file) { |
|
| 252 | + $file_to_go = str_replace($source, $dest, $file); |
|
| 253 | 253 | copy($file, $file_to_go); |
| 254 | 254 | } |
| 255 | 255 | return true; |
@@ -260,9 +260,9 @@ discard block |
||
| 260 | 260 | * @param String $url url to check |
| 261 | 261 | * @return bool Return true on succes false on failure |
| 262 | 262 | */ |
| 263 | - public function urlexist($url){ |
|
| 264 | - $headers=get_headers($url); |
|
| 265 | - return stripos($headers[0],"200 OK")?true:false; |
|
| 263 | + public function urlexist($url) { |
|
| 264 | + $headers = get_headers($url); |
|
| 265 | + return stripos($headers[0], "200 OK") ? true : false; |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | /** |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | public function hex2str($hex) { |
| 274 | 274 | $str = ''; |
| 275 | 275 | $hexln = strlen($hex); |
| 276 | - for($i=0;$i<$hexln;$i+=2) $str .= chr(hexdec(substr($hex,$i,2))); |
|
| 276 | + for ($i = 0; $i < $hexln; $i += 2) $str .= chr(hexdec(substr($hex, $i, 2))); |
|
| 277 | 277 | return $str; |
| 278 | 278 | } |
| 279 | 279 | |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | * @return String Return result |
| 284 | 284 | */ |
| 285 | 285 | public function hex2rgb($hex) { |
| 286 | - $hex = str_replace('#','',$hex); |
|
| 286 | + $hex = str_replace('#', '', $hex); |
|
| 287 | 287 | return sscanf($hex, "%02x%02x%02x"); |
| 288 | 288 | } |
| 289 | 289 | |
@@ -291,33 +291,33 @@ discard block |
||
| 291 | 291 | //difference in longitudinal coordinates |
| 292 | 292 | $dLon = deg2rad($lon2) - deg2rad($lon1); |
| 293 | 293 | //difference in the phi of latitudinal coordinates |
| 294 | - $dPhi = log(tan(deg2rad($lat2) / 2 + pi() / 4) / tan(deg2rad($lat1) / 2 + pi() / 4)); |
|
| 294 | + $dPhi = log(tan(deg2rad($lat2)/2 + pi()/4)/tan(deg2rad($lat1)/2 + pi()/4)); |
|
| 295 | 295 | //we need to recalculate $dLon if it is greater than pi |
| 296 | - if(abs($dLon) > pi()) { |
|
| 297 | - if($dLon > 0) { |
|
| 298 | - $dLon = (2 * pi() - $dLon) * -1; |
|
| 296 | + if (abs($dLon) > pi()) { |
|
| 297 | + if ($dLon > 0) { |
|
| 298 | + $dLon = (2*pi() - $dLon)*-1; |
|
| 299 | 299 | } else { |
| 300 | - $dLon = 2 * pi() + $dLon; |
|
| 300 | + $dLon = 2*pi() + $dLon; |
|
| 301 | 301 | } |
| 302 | 302 | } |
| 303 | 303 | //return the angle, normalized |
| 304 | - return (rad2deg(atan2($dLon, $dPhi)) + 360) % 360; |
|
| 304 | + return (rad2deg(atan2($dLon, $dPhi)) + 360)%360; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | - public function checkLine($lat1,$lon1,$lat2,$lon2,$lat3,$lon3,$approx = 0.2) { |
|
| 307 | + public function checkLine($lat1, $lon1, $lat2, $lon2, $lat3, $lon3, $approx = 0.2) { |
|
| 308 | 308 | //$a = ($lon2-$lon1)*$lat3+($lat2-$lat1)*$lon3+($lat1*$lon2+$lat2*$lon1); |
| 309 | - $a = -($lon2-$lon1); |
|
| 309 | + $a = -($lon2 - $lon1); |
|
| 310 | 310 | $b = $lat2 - $lat1; |
| 311 | - $c = -($a*$lat1+$b*$lon1); |
|
| 312 | - $d = $a*$lat3+$b*$lon3+$c; |
|
| 311 | + $c = -($a*$lat1 + $b*$lon1); |
|
| 312 | + $d = $a*$lat3 + $b*$lon3 + $c; |
|
| 313 | 313 | if ($d > -$approx && $d < $approx) return true; |
| 314 | 314 | else return false; |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | public function array_merge_noappend() { |
| 318 | 318 | $output = array(); |
| 319 | - foreach(func_get_args() as $array) { |
|
| 320 | - foreach($array as $key => $value) { |
|
| 319 | + foreach (func_get_args() as $array) { |
|
| 320 | + foreach ($array as $key => $value) { |
|
| 321 | 321 | $output[$key] = isset($output[$key]) ? |
| 322 | 322 | array_merge($output[$key], $value) : $value; |
| 323 | 323 | } |
@@ -381,34 +381,34 @@ discard block |
||
| 381 | 381 | return $result; |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | - public function nextcoord($latitude, $longitude, $speed, $heading, $archivespeed = 1){ |
|
| 384 | + public function nextcoord($latitude, $longitude, $speed, $heading, $archivespeed = 1) { |
|
| 385 | 385 | global $globalMapRefresh; |
| 386 | 386 | $distance = ($speed*0.514444*$globalMapRefresh*$archivespeed)/1000; |
| 387 | 387 | $r = 6378; |
| 388 | 388 | $latitude = deg2rad($latitude); |
| 389 | 389 | $longitude = deg2rad($longitude); |
| 390 | 390 | $bearing = deg2rad($heading); |
| 391 | - $latitude2 = asin( (sin($latitude) * cos($distance/$r)) + (cos($latitude) * sin($distance/$r) * cos($bearing)) ); |
|
| 392 | - $longitude2 = $longitude + atan2( sin($bearing)*sin($distance/$r)*cos($latitude), cos($distance/$r)-(sin($latitude)*sin($latitude2)) ); |
|
| 393 | - return array('latitude' => number_format(rad2deg($latitude2),5,'.',''),'longitude' => number_format(rad2deg($longitude2),5,'.','')); |
|
| 391 | + $latitude2 = asin((sin($latitude)*cos($distance/$r)) + (cos($latitude)*sin($distance/$r)*cos($bearing))); |
|
| 392 | + $longitude2 = $longitude + atan2(sin($bearing)*sin($distance/$r)*cos($latitude), cos($distance/$r) - (sin($latitude)*sin($latitude2))); |
|
| 393 | + return array('latitude' => number_format(rad2deg($latitude2), 5, '.', ''), 'longitude' => number_format(rad2deg($longitude2), 5, '.', '')); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | - public function getCoordfromDistanceBearing($latitude,$longitude,$bearing,$distance) { |
|
| 396 | + public function getCoordfromDistanceBearing($latitude, $longitude, $bearing, $distance) { |
|
| 397 | 397 | // distance in meter |
| 398 | 398 | $R = 6378.14; |
| 399 | - $latitude1 = $latitude * (M_PI/180); |
|
| 400 | - $longitude1 = $longitude * (M_PI/180); |
|
| 401 | - $brng = $bearing * (M_PI/180); |
|
| 399 | + $latitude1 = $latitude*(M_PI/180); |
|
| 400 | + $longitude1 = $longitude*(M_PI/180); |
|
| 401 | + $brng = $bearing*(M_PI/180); |
|
| 402 | 402 | $d = $distance; |
| 403 | 403 | |
| 404 | 404 | $latitude2 = asin(sin($latitude1)*cos($d/$R) + cos($latitude1)*sin($d/$R)*cos($brng)); |
| 405 | - $longitude2 = $longitude1 + atan2(sin($brng)*sin($d/$R)*cos($latitude1),cos($d/$R)-sin($latitude1)*sin($latitude2)); |
|
| 405 | + $longitude2 = $longitude1 + atan2(sin($brng)*sin($d/$R)*cos($latitude1), cos($d/$R) - sin($latitude1)*sin($latitude2)); |
|
| 406 | 406 | |
| 407 | - $latitude2 = $latitude2 * (180/M_PI); |
|
| 408 | - $longitude2 = $longitude2 * (180/M_PI); |
|
| 407 | + $latitude2 = $latitude2*(180/M_PI); |
|
| 408 | + $longitude2 = $longitude2*(180/M_PI); |
|
| 409 | 409 | |
| 410 | - $flat = round ($latitude2,6); |
|
| 411 | - $flong = round ($longitude2,6); |
|
| 410 | + $flat = round($latitude2, 6); |
|
| 411 | + $flong = round($longitude2, 6); |
|
| 412 | 412 | /* |
| 413 | 413 | $dx = $distance*cos($bearing); |
| 414 | 414 | $dy = $distance*sin($bearing); |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | $flong = $longitude + $dlong; |
| 418 | 418 | $flat = $latitude + $dlat; |
| 419 | 419 | */ |
| 420 | - return array('latitude' => $flat,'longitude' => $flong); |
|
| 420 | + return array('latitude' => $flat, 'longitude' => $flong); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | /** |
@@ -431,14 +431,14 @@ discard block |
||
| 431 | 431 | * @param integer $level GZIP compression level (default: 9) |
| 432 | 432 | * @return string New filename (with .gz appended) if success, or false if operation fails |
| 433 | 433 | */ |
| 434 | - public function gzCompressFile($source, $level = 9){ |
|
| 435 | - $dest = $source . '.gz'; |
|
| 436 | - $mode = 'wb' . $level; |
|
| 434 | + public function gzCompressFile($source, $level = 9) { |
|
| 435 | + $dest = $source.'.gz'; |
|
| 436 | + $mode = 'wb'.$level; |
|
| 437 | 437 | $error = false; |
| 438 | 438 | if ($fp_out = gzopen($dest, $mode)) { |
| 439 | - if ($fp_in = fopen($source,'rb')) { |
|
| 439 | + if ($fp_in = fopen($source, 'rb')) { |
|
| 440 | 440 | while (!feof($fp_in)) |
| 441 | - gzwrite($fp_out, fread($fp_in, 1024 * 512)); |
|
| 441 | + gzwrite($fp_out, fread($fp_in, 1024*512)); |
|
| 442 | 442 | fclose($fp_in); |
| 443 | 443 | } else { |
| 444 | 444 | $error = true; |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | public function remove_accents($string) { |
| 457 | - if ( !preg_match('/[\x80-\xff]/', $string) ) return $string; |
|
| 457 | + if (!preg_match('/[\x80-\xff]/', $string)) return $string; |
|
| 458 | 458 | $chars = array( |
| 459 | 459 | // Decompositions for Latin-1 Supplement |
| 460 | 460 | chr(195).chr(128) => 'A', chr(195).chr(129) => 'A', |
@@ -511,7 +511,7 @@ discard block |
||
| 511 | 511 | chr(196).chr(172) => 'I', chr(196).chr(173) => 'i', |
| 512 | 512 | chr(196).chr(174) => 'I', chr(196).chr(175) => 'i', |
| 513 | 513 | chr(196).chr(176) => 'I', chr(196).chr(177) => 'i', |
| 514 | - chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij', |
|
| 514 | + chr(196).chr(178) => 'IJ', chr(196).chr(179) => 'ij', |
|
| 515 | 515 | chr(196).chr(180) => 'J', chr(196).chr(181) => 'j', |
| 516 | 516 | chr(196).chr(182) => 'K', chr(196).chr(183) => 'k', |
| 517 | 517 | chr(196).chr(184) => 'k', chr(196).chr(185) => 'L', |
@@ -527,13 +527,13 @@ discard block |
||
| 527 | 527 | chr(197).chr(140) => 'O', chr(197).chr(141) => 'o', |
| 528 | 528 | chr(197).chr(142) => 'O', chr(197).chr(143) => 'o', |
| 529 | 529 | chr(197).chr(144) => 'O', chr(197).chr(145) => 'o', |
| 530 | - chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe', |
|
| 531 | - chr(197).chr(148) => 'R',chr(197).chr(149) => 'r', |
|
| 532 | - chr(197).chr(150) => 'R',chr(197).chr(151) => 'r', |
|
| 533 | - chr(197).chr(152) => 'R',chr(197).chr(153) => 'r', |
|
| 534 | - chr(197).chr(154) => 'S',chr(197).chr(155) => 's', |
|
| 535 | - chr(197).chr(156) => 'S',chr(197).chr(157) => 's', |
|
| 536 | - chr(197).chr(158) => 'S',chr(197).chr(159) => 's', |
|
| 530 | + chr(197).chr(146) => 'OE', chr(197).chr(147) => 'oe', |
|
| 531 | + chr(197).chr(148) => 'R', chr(197).chr(149) => 'r', |
|
| 532 | + chr(197).chr(150) => 'R', chr(197).chr(151) => 'r', |
|
| 533 | + chr(197).chr(152) => 'R', chr(197).chr(153) => 'r', |
|
| 534 | + chr(197).chr(154) => 'S', chr(197).chr(155) => 's', |
|
| 535 | + chr(197).chr(156) => 'S', chr(197).chr(157) => 's', |
|
| 536 | + chr(197).chr(158) => 'S', chr(197).chr(159) => 's', |
|
| 537 | 537 | chr(197).chr(160) => 'S', chr(197).chr(161) => 's', |
| 538 | 538 | chr(197).chr(162) => 'T', chr(197).chr(163) => 't', |
| 539 | 539 | chr(197).chr(164) => 'T', chr(197).chr(165) => 't', |
@@ -567,7 +567,7 @@ discard block |
||
| 567 | 567 | for ($i = 0, $int = '', $concat_flag = true; $i < $length; $i++) { |
| 568 | 568 | if (is_numeric($string[$i]) && $concat_flag) { |
| 569 | 569 | $int .= $string[$i]; |
| 570 | - } elseif(!$concat && $concat_flag && strlen($int) > 0) { |
|
| 570 | + } elseif (!$concat && $concat_flag && strlen($int) > 0) { |
|
| 571 | 571 | $concat_flag = false; |
| 572 | 572 | } |
| 573 | 573 | } |
@@ -46,6 +46,10 @@ |
||
| 46 | 46 | |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | + /** |
|
| 50 | + * @param string $id |
|
| 51 | + * @param string $ident |
|
| 52 | + */ |
|
| 49 | 53 | public function get_Schedule($id,$ident) { |
| 50 | 54 | global $globalDebug, $globalFork, $globalSchedulesFetch; |
| 51 | 55 | // Get schedule here, so it's done only one time |
@@ -8,20 +8,20 @@ discard block |
||
| 8 | 8 | require_once(dirname(__FILE__).'/class.Stats.php'); |
| 9 | 9 | require_once(dirname(__FILE__).'/class.Source.php'); |
| 10 | 10 | if (isset($globalServerAPRS) && $globalServerAPRS) { |
| 11 | - require_once(dirname(__FILE__).'/class.APRS.php'); |
|
| 11 | + require_once(dirname(__FILE__).'/class.APRS.php'); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | class SpotterImport { |
| 15 | - private $all_flights = array(); |
|
| 16 | - private $last_delete_hourly = 0; |
|
| 17 | - private $last_delete = 0; |
|
| 18 | - private $stats = array(); |
|
| 19 | - private $tmd = 0; |
|
| 20 | - private $source_location = array(); |
|
| 21 | - public $db = null; |
|
| 22 | - public $nb = 0; |
|
| 15 | + private $all_flights = array(); |
|
| 16 | + private $last_delete_hourly = 0; |
|
| 17 | + private $last_delete = 0; |
|
| 18 | + private $stats = array(); |
|
| 19 | + private $tmd = 0; |
|
| 20 | + private $source_location = array(); |
|
| 21 | + public $db = null; |
|
| 22 | + public $nb = 0; |
|
| 23 | 23 | |
| 24 | - public function __construct($dbc = null) { |
|
| 24 | + public function __construct($dbc = null) { |
|
| 25 | 25 | global $globalBeta, $globalServerAPRS, $APRSSpotter, $globalNoDB; |
| 26 | 26 | if (!(isset($globalNoDB) && $globalNoDB)) { |
| 27 | 27 | $Connection = new Connection($dbc); |
@@ -33,14 +33,14 @@ discard block |
||
| 33 | 33 | $currentdate = date('Y-m-d'); |
| 34 | 34 | $sourcestat = $Stats->getStatsSource($currentdate); |
| 35 | 35 | if (!empty($sourcestat)) { |
| 36 | - foreach($sourcestat as $srcst) { |
|
| 37 | - $type = $srcst['stats_type']; |
|
| 36 | + foreach($sourcestat as $srcst) { |
|
| 37 | + $type = $srcst['stats_type']; |
|
| 38 | 38 | if ($type == 'polar' || $type == 'hist') { |
| 39 | - $source = $srcst['source_name']; |
|
| 40 | - $data = $srcst['source_data']; |
|
| 41 | - $this->stats[$currentdate][$source][$type] = json_decode($data,true); |
|
| 42 | - } |
|
| 43 | - } |
|
| 39 | + $source = $srcst['source_name']; |
|
| 40 | + $data = $srcst['source_data']; |
|
| 41 | + $this->stats[$currentdate][$source][$type] = json_decode($data,true); |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | if (isset($globalServerAPRS) && $globalServerAPRS) { |
@@ -48,9 +48,9 @@ discard block |
||
| 48 | 48 | //$APRSSpotter->connect(); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - } |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - public function get_Schedule($id,$ident) { |
|
| 53 | + public function get_Schedule($id,$ident) { |
|
| 54 | 54 | global $globalDebug, $globalFork, $globalSchedulesFetch; |
| 55 | 55 | // Get schedule here, so it's done only one time |
| 56 | 56 | |
@@ -70,42 +70,42 @@ discard block |
||
| 70 | 70 | $operator = $Spotter->getOperator($ident); |
| 71 | 71 | $scheduleexist = false; |
| 72 | 72 | if ($Schedule->checkSchedule($operator) == 0) { |
| 73 | - $operator = $Translation->checkTranslation($ident); |
|
| 74 | - if ($Schedule->checkSchedule($operator) == 0) { |
|
| 73 | + $operator = $Translation->checkTranslation($ident); |
|
| 74 | + if ($Schedule->checkSchedule($operator) == 0) { |
|
| 75 | 75 | $schedule = $Schedule->fetchSchedule($operator); |
| 76 | 76 | if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) { |
| 77 | - if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n"; |
|
| 78 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime'])); |
|
| 79 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime'])); |
|
| 80 | - // Should also check if route schedule = route from DB |
|
| 81 | - if ($schedule['DepartureAirportIATA'] != '') { |
|
| 77 | + if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n"; |
|
| 78 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime'])); |
|
| 79 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime'])); |
|
| 80 | + // Should also check if route schedule = route from DB |
|
| 81 | + if ($schedule['DepartureAirportIATA'] != '') { |
|
| 82 | 82 | if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) { |
| 83 | - $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']); |
|
| 84 | - if (trim($airport_icao) != '') { |
|
| 83 | + $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']); |
|
| 84 | + if (trim($airport_icao) != '') { |
|
| 85 | 85 | $this->all_flights[$id]['departure_airport'] = $airport_icao; |
| 86 | 86 | if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n"; |
| 87 | - } |
|
| 87 | + } |
|
| 88 | + } |
|
| 88 | 89 | } |
| 89 | - } |
|
| 90 | - if ($schedule['ArrivalAirportIATA'] != '') { |
|
| 90 | + if ($schedule['ArrivalAirportIATA'] != '') { |
|
| 91 | 91 | if ($this->all_flights[$id]['arrival_airport'] != $Spotter->getAirportIcao($schedule['ArrivalAirportIATA'])) { |
| 92 | - $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']); |
|
| 93 | - if (trim($airport_icao) != '') { |
|
| 92 | + $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']); |
|
| 93 | + if (trim($airport_icao) != '') { |
|
| 94 | 94 | $this->all_flights[$id]['arrival_airport'] = $airport_icao; |
| 95 | 95 | if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n"; |
| 96 | - } |
|
| 96 | + } |
|
| 97 | 97 | } |
| 98 | - } |
|
| 99 | - $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']); |
|
| 98 | + } |
|
| 99 | + $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']); |
|
| 100 | 100 | } |
| 101 | - } else $scheduleexist = true; |
|
| 101 | + } else $scheduleexist = true; |
|
| 102 | 102 | } else $scheduleexist = true; |
| 103 | 103 | // close connection, at least one way will work ? |
| 104 | - if ($scheduleexist) { |
|
| 104 | + if ($scheduleexist) { |
|
| 105 | 105 | if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n"; |
| 106 | - $sch = $Schedule->getSchedule($operator); |
|
| 106 | + $sch = $Schedule->getSchedule($operator); |
|
| 107 | 107 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time'])); |
| 108 | - } |
|
| 108 | + } |
|
| 109 | 109 | $Spotter->db = null; |
| 110 | 110 | $Schedule->db = null; |
| 111 | 111 | $Translation->db = null; |
@@ -120,78 +120,78 @@ discard block |
||
| 120 | 120 | } |
| 121 | 121 | */ |
| 122 | 122 | } |
| 123 | - } |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - public function checkAll() { |
|
| 125 | + public function checkAll() { |
|
| 126 | 126 | global $globalDebug, $globalNoImport; |
| 127 | 127 | if ($globalDebug) echo "Update last seen flights data...\n"; |
| 128 | 128 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
| 129 | - foreach ($this->all_flights as $key => $flight) { |
|
| 129 | + foreach ($this->all_flights as $key => $flight) { |
|
| 130 | 130 | if (isset($this->all_flights[$key]['id'])) { |
| 131 | - //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].' '.$this->all_flights[$key]['longitude']."\n"; |
|
| 132 | - $Spotter = new Spotter($this->db); |
|
| 133 | - $real_arrival = $this->arrival($key); |
|
| 134 | - if (isset($this->all_flights[$key]['altitude'])) $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']); |
|
| 135 | - } |
|
| 136 | - } |
|
| 131 | + //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].' '.$this->all_flights[$key]['longitude']."\n"; |
|
| 132 | + $Spotter = new Spotter($this->db); |
|
| 133 | + $real_arrival = $this->arrival($key); |
|
| 134 | + if (isset($this->all_flights[$key]['altitude'])) $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']); |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + } |
|
| 137 | 138 | } |
| 138 | - } |
|
| 139 | 139 | |
| 140 | - public function arrival($key) { |
|
| 140 | + public function arrival($key) { |
|
| 141 | 141 | global $globalClosestMinDist, $globalDebug; |
| 142 | 142 | if ($globalDebug) echo 'Update arrival...'."\n"; |
| 143 | 143 | $Spotter = new Spotter($this->db); |
| 144 | - $airport_icao = ''; |
|
| 145 | - $airport_time = ''; |
|
| 146 | - if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50; |
|
| 144 | + $airport_icao = ''; |
|
| 145 | + $airport_time = ''; |
|
| 146 | + if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50; |
|
| 147 | 147 | if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') { |
| 148 | - $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist); |
|
| 149 | - if (isset($closestAirports[0])) { |
|
| 150 | - if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) { |
|
| 151 | - $airport_icao = $closestAirports[0]['icao']; |
|
| 152 | - $airport_time = $this->all_flights[$key]['datetime']; |
|
| 153 | - if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
| 154 | - } elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') { |
|
| 155 | - foreach ($closestAirports as $airport) { |
|
| 156 | - if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) { |
|
| 157 | - $airport_icao = $airport['icao']; |
|
| 158 | - $airport_time = $this->all_flights[$key]['datetime']; |
|
| 159 | - if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
| 160 | - break; |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - } elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) { |
|
| 164 | - $airport_icao = $closestAirports[0]['icao']; |
|
| 165 | - $airport_time = $this->all_flights[$key]['datetime']; |
|
| 166 | - } else { |
|
| 167 | - if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n"; |
|
| 168 | - } |
|
| 169 | - } else { |
|
| 170 | - if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n"; |
|
| 171 | - } |
|
| 148 | + $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist); |
|
| 149 | + if (isset($closestAirports[0])) { |
|
| 150 | + if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) { |
|
| 151 | + $airport_icao = $closestAirports[0]['icao']; |
|
| 152 | + $airport_time = $this->all_flights[$key]['datetime']; |
|
| 153 | + if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
| 154 | + } elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') { |
|
| 155 | + foreach ($closestAirports as $airport) { |
|
| 156 | + if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) { |
|
| 157 | + $airport_icao = $airport['icao']; |
|
| 158 | + $airport_time = $this->all_flights[$key]['datetime']; |
|
| 159 | + if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
| 160 | + break; |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + } elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) { |
|
| 164 | + $airport_icao = $closestAirports[0]['icao']; |
|
| 165 | + $airport_time = $this->all_flights[$key]['datetime']; |
|
| 166 | + } else { |
|
| 167 | + if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n"; |
|
| 168 | + } |
|
| 169 | + } else { |
|
| 170 | + if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n"; |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | - } else { |
|
| 174 | - if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n"; |
|
| 175 | - } |
|
| 176 | - return array('airport_icao' => $airport_icao,'airport_time' => $airport_time); |
|
| 177 | - } |
|
| 173 | + } else { |
|
| 174 | + if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n"; |
|
| 175 | + } |
|
| 176 | + return array('airport_icao' => $airport_icao,'airport_time' => $airport_time); |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | 179 | |
| 180 | 180 | |
| 181 | - public function del() { |
|
| 181 | + public function del() { |
|
| 182 | 182 | global $globalDebug, $globalNoImport, $globalNoDB; |
| 183 | 183 | // Delete old infos |
| 184 | 184 | if ($globalDebug) echo 'Delete old values and update latest data...'."\n"; |
| 185 | 185 | foreach ($this->all_flights as $key => $flight) { |
| 186 | - if (isset($flight['lastupdate'])) { |
|
| 186 | + if (isset($flight['lastupdate'])) { |
|
| 187 | 187 | if ($flight['lastupdate'] < (time()-5900)) { |
| 188 | - $this->delKey($key); |
|
| 188 | + $this->delKey($key); |
|
| 189 | 189 | } |
| 190 | - } |
|
| 190 | + } |
|
| 191 | + } |
|
| 191 | 192 | } |
| 192 | - } |
|
| 193 | 193 | |
| 194 | - public function delKey($key) { |
|
| 194 | + public function delKey($key) { |
|
| 195 | 195 | global $globalDebug, $globalNoImport, $globalNoDB; |
| 196 | 196 | // Delete old infos |
| 197 | 197 | if (isset($this->all_flights[$key]['id'])) { |
@@ -206,9 +206,9 @@ discard block |
||
| 206 | 206 | } |
| 207 | 207 | } |
| 208 | 208 | unset($this->all_flights[$key]); |
| 209 | - } |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | - public function add($line) { |
|
| 211 | + public function add($line) { |
|
| 212 | 212 | global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights, $globalServerAPRS, $APRSSpotter, $globalNoImport, $globalNoDB, $globalVA, $globalAircraftMaxUpdate, $globalAircraftMinUpdate, $globalLiveInterval; |
| 213 | 213 | //if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE; |
| 214 | 214 | if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02'; |
@@ -234,20 +234,20 @@ discard block |
||
| 234 | 234 | |
| 235 | 235 | // SBS format is CSV format |
| 236 | 236 | if(is_array($line) && (isset($line['hex']) || isset($line['id']))) { |
| 237 | - //print_r($line); |
|
| 238 | - if (isset($line['hex'])) $line['hex'] = strtoupper($line['hex']); |
|
| 239 | - if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) { |
|
| 237 | + //print_r($line); |
|
| 238 | + if (isset($line['hex'])) $line['hex'] = strtoupper($line['hex']); |
|
| 239 | + if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) { |
|
| 240 | 240 | |
| 241 | 241 | // Increment message number |
| 242 | 242 | if (isset($line['sourcestats']) && $line['sourcestats'] === TRUE) { |
| 243 | - $current_date = date('Y-m-d'); |
|
| 244 | - if (isset($line['source_name'])) $source = $line['source_name']; |
|
| 245 | - else $source = ''; |
|
| 246 | - if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source']; |
|
| 247 | - if (!isset($this->stats[$current_date][$source]['msg'])) { |
|
| 248 | - $this->stats[$current_date][$source]['msg']['date'] = time(); |
|
| 249 | - $this->stats[$current_date][$source]['msg']['nb'] = 1; |
|
| 250 | - } else $this->stats[$current_date][$source]['msg']['nb'] += 1; |
|
| 243 | + $current_date = date('Y-m-d'); |
|
| 244 | + if (isset($line['source_name'])) $source = $line['source_name']; |
|
| 245 | + else $source = ''; |
|
| 246 | + if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source']; |
|
| 247 | + if (!isset($this->stats[$current_date][$source]['msg'])) { |
|
| 248 | + $this->stats[$current_date][$source]['msg']['date'] = time(); |
|
| 249 | + $this->stats[$current_date][$source]['msg']['nb'] = 1; |
|
| 250 | + } else $this->stats[$current_date][$source]['msg']['nb'] += 1; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /* |
@@ -263,54 +263,54 @@ discard block |
||
| 263 | 263 | //$this->db = $dbc; |
| 264 | 264 | |
| 265 | 265 | //$hex = trim($line['hex']); |
| 266 | - if (!isset($line['id'])) $id = trim($line['hex']); |
|
| 267 | - else $id = trim($line['id']); |
|
| 266 | + if (!isset($line['id'])) $id = trim($line['hex']); |
|
| 267 | + else $id = trim($line['id']); |
|
| 268 | 268 | |
| 269 | 269 | if (!isset($this->all_flights[$id])) { |
| 270 | - if ($globalDebug) echo 'New flight...'."\n"; |
|
| 271 | - $this->all_flights[$id] = array(); |
|
| 272 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
|
| 273 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '','altitude_previous' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => '')); |
|
| 274 | - if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time())); |
|
| 275 | - if (!isset($line['id'])) { |
|
| 270 | + if ($globalDebug) echo 'New flight...'."\n"; |
|
| 271 | + $this->all_flights[$id] = array(); |
|
| 272 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
|
| 273 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '','altitude_previous' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => '')); |
|
| 274 | + if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time())); |
|
| 275 | + if (!isset($line['id'])) { |
|
| 276 | 276 | if (!isset($globalDaemon)) $globalDaemon = TRUE; |
| 277 | 277 | // if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi'))); |
| 278 | 278 | // if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
| 279 | 279 | if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); |
| 280 | - //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 281 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 282 | - if ($globalAllFlights !== FALSE) $dataFound = true; |
|
| 280 | + //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 281 | + } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 282 | + if ($globalAllFlights !== FALSE) $dataFound = true; |
|
| 283 | 283 | } |
| 284 | 284 | if (isset($line['source_type']) && $line['source_type'] != '') { |
| 285 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type'])); |
|
| 285 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type'])); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | //print_r($this->all_flights); |
| 289 | 289 | if (isset($line['hex']) && !isset($this->all_flights[$id]['hex']) && ctype_xdigit($line['hex'])) { |
| 290 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex']))); |
|
| 291 | - //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) { |
|
| 290 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex']))); |
|
| 291 | + //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) { |
|
| 292 | 292 | //$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime'])); |
| 293 | - //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s'))); |
|
| 294 | - if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????') && $line['format_source'] != 'whazzup' && $line['format_source'] != 'vatsimtxt' && $line['format_source'] != 'pireps' && $line['format_source'] != 'phpvmacars' && $line['format_source'] != 'vam' && $line['format_source'] != 'flightgearsp' && $line['format_source'] != 'flightgearmp') { |
|
| 293 | + //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s'))); |
|
| 294 | + if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????') && $line['format_source'] != 'whazzup' && $line['format_source'] != 'vatsimtxt' && $line['format_source'] != 'pireps' && $line['format_source'] != 'phpvmacars' && $line['format_source'] != 'vam' && $line['format_source'] != 'flightgearsp' && $line['format_source'] != 'flightgearmp') { |
|
| 295 | 295 | $timeelapsed = microtime(true); |
| 296 | 296 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 297 | - $Spotter = new Spotter($this->db); |
|
| 298 | - if (isset($this->all_flights[$id]['source_type'])) { |
|
| 297 | + $Spotter = new Spotter($this->db); |
|
| 298 | + if (isset($this->all_flights[$id]['source_type'])) { |
|
| 299 | 299 | $aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']),$this->all_flights[$id]['source_type']); |
| 300 | - } else { |
|
| 300 | + } else { |
|
| 301 | 301 | $aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex'])); |
| 302 | - } |
|
| 303 | - $Spotter->db = null; |
|
| 304 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 305 | - if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
| 302 | + } |
|
| 303 | + $Spotter->db = null; |
|
| 304 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 305 | + if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
| 306 | 306 | } |
| 307 | - } |
|
| 308 | - if ($globalAllFlights !== FALSE) $dataFound = true; |
|
| 309 | - if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n"; |
|
| 307 | + } |
|
| 308 | + if ($globalAllFlights !== FALSE) $dataFound = true; |
|
| 309 | + if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n"; |
|
| 310 | 310 | } |
| 311 | - if (isset($line['id']) && !isset($line['hex'])) { |
|
| 312 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => '')); |
|
| 313 | - } |
|
| 311 | + if (isset($line['id']) && !isset($line['hex'])) { |
|
| 312 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => '')); |
|
| 313 | + } |
|
| 314 | 314 | if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') { |
| 315 | 315 | $icao = $line['aircraft_icao']; |
| 316 | 316 | $Spotter = new Spotter($this->db); |
@@ -339,9 +339,9 @@ discard block |
||
| 339 | 339 | } |
| 340 | 340 | //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) { |
| 341 | 341 | if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60 && strtotime($line['datetime']) < time()+20*60) { |
| 342 | - if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) { |
|
| 342 | + if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) { |
|
| 343 | 343 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime'])); |
| 344 | - } else { |
|
| 344 | + } else { |
|
| 345 | 345 | if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n"; |
| 346 | 346 | elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n"; |
| 347 | 347 | /* |
@@ -350,7 +350,7 @@ discard block |
||
| 350 | 350 | print_r($line); |
| 351 | 351 | */ |
| 352 | 352 | return ''; |
| 353 | - } |
|
| 353 | + } |
|
| 354 | 354 | } elseif (isset($line['datetime']) && strtotime($line['datetime']) < time()-20*60) { |
| 355 | 355 | if ($globalDebug) echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n"; |
| 356 | 356 | return ''; |
@@ -367,21 +367,21 @@ discard block |
||
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') { |
| 370 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration'])); |
|
| 370 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration'])); |
|
| 371 | 371 | } |
| 372 | 372 | if (isset($line['waypoints']) && $line['waypoints'] != '') { |
| 373 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints'])); |
|
| 373 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints'])); |
|
| 374 | 374 | } |
| 375 | 375 | if (isset($line['pilot_id']) && $line['pilot_id'] != '') { |
| 376 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => trim($line['pilot_id']))); |
|
| 376 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => trim($line['pilot_id']))); |
|
| 377 | 377 | } |
| 378 | 378 | if (isset($line['pilot_name']) && $line['pilot_name'] != '') { |
| 379 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => trim($line['pilot_name']))); |
|
| 379 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => trim($line['pilot_name']))); |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_flights[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9]+$/', $line['ident'])) { |
| 383 | 383 | |
| 384 | - if ($this->all_flights[$id]['addedSpotter'] == 1) { |
|
| 384 | + if ($this->all_flights[$id]['addedSpotter'] == 1) { |
|
| 385 | 385 | if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE && $this->all_flights[$id]['lastupdate'] < time() - 1600) { |
| 386 | 386 | if ($globalDebug) echo '---!!!! New ident, reset aircraft data...'."\n"; |
| 387 | 387 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
@@ -390,23 +390,23 @@ discard block |
||
| 390 | 390 | elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
| 391 | 391 | elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
| 392 | 392 | } else { |
| 393 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident']))); |
|
| 394 | - if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
| 393 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident']))); |
|
| 394 | + if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
| 395 | 395 | $timeelapsed = microtime(true); |
| 396 | - $Spotter = new Spotter($this->db); |
|
| 397 | - $fromsource = NULL; |
|
| 398 | - if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource; |
|
| 399 | - elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim'; |
|
| 396 | + $Spotter = new Spotter($this->db); |
|
| 397 | + $fromsource = NULL; |
|
| 398 | + if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource; |
|
| 399 | + elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim'; |
|
| 400 | 400 | elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao'; |
| 401 | 401 | elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim'; |
| 402 | 402 | elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao'; |
| 403 | - $result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource); |
|
| 403 | + $result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource); |
|
| 404 | 404 | if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
| 405 | 405 | $Spotter->db = null; |
| 406 | 406 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
| 407 | - } |
|
| 407 | + } |
|
| 408 | 408 | } |
| 409 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident']))); |
|
| 409 | + } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident']))); |
|
| 410 | 410 | |
| 411 | 411 | /* |
| 412 | 412 | if (!isset($line['id'])) { |
@@ -416,109 +416,109 @@ discard block |
||
| 416 | 416 | else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
| 417 | 417 | } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
| 418 | 418 | */ |
| 419 | - if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 419 | + if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 420 | 420 | |
| 421 | - //$putinarchive = true; |
|
| 422 | - if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) { |
|
| 421 | + //$putinarchive = true; |
|
| 422 | + if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) { |
|
| 423 | 423 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time'])); |
| 424 | - } |
|
| 425 | - if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) { |
|
| 424 | + } |
|
| 425 | + if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) { |
|
| 426 | 426 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time'])); |
| 427 | - } |
|
| 428 | - if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) { |
|
| 429 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => '')); |
|
| 430 | - } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) { |
|
| 427 | + } |
|
| 428 | + if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) { |
|
| 429 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => '')); |
|
| 430 | + } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) { |
|
| 431 | 431 | $timeelapsed = microtime(true); |
| 432 | 432 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 433 | 433 | $Spotter = new Spotter($this->db); |
| 434 | 434 | $line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']); |
| 435 | 435 | $line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']); |
| 436 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => '')); |
|
| 436 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => '')); |
|
| 437 | 437 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
| 438 | - } |
|
| 439 | - } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') { |
|
| 438 | + } |
|
| 439 | + } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') { |
|
| 440 | 440 | $timeelapsed = microtime(true); |
| 441 | 441 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 442 | - $Spotter = new Spotter($this->db); |
|
| 443 | - $route = $Spotter->getRouteInfo(trim($line['ident'])); |
|
| 444 | - if (!isset($route['fromairport_icao']) && !isset($route['toairport_icao'])) { |
|
| 442 | + $Spotter = new Spotter($this->db); |
|
| 443 | + $route = $Spotter->getRouteInfo(trim($line['ident'])); |
|
| 444 | + if (!isset($route['fromairport_icao']) && !isset($route['toairport_icao'])) { |
|
| 445 | 445 | $Translation = new Translation($this->db); |
| 446 | 446 | $ident = $Translation->checkTranslation(trim($line['ident'])); |
| 447 | 447 | $route = $Spotter->getRouteInfo($ident); |
| 448 | 448 | $Translation->db = null; |
| 449 | - } |
|
| 450 | - $Spotter->db = null; |
|
| 451 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 452 | - } |
|
| 449 | + } |
|
| 450 | + $Spotter->db = null; |
|
| 451 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 452 | + } |
|
| 453 | 453 | if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) { |
| 454 | - //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) { |
|
| 455 | - if ($route['fromairport_icao'] != $route['toairport_icao']) { |
|
| 454 | + //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) { |
|
| 455 | + if ($route['fromairport_icao'] != $route['toairport_icao']) { |
|
| 456 | 456 | // $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['FromAirport_ICAO'],'arrival_airport' => $route['ToAirport_ICAO'],'route_stop' => $route['RouteStop'])); |
| 457 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop'])); |
|
| 458 | - } |
|
| 457 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop'])); |
|
| 458 | + } |
|
| 459 | 459 | } |
| 460 | 460 | if (!isset($globalFork)) $globalFork = TRUE; |
| 461 | 461 | if (!$globalVA && !$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) { |
| 462 | 462 | if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident'])); |
| 463 | 463 | } |
| 464 | - } |
|
| 464 | + } |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | if (isset($line['speed']) && $line['speed'] != '') { |
| 468 | 468 | // $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12])); |
| 469 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed']))); |
|
| 470 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true)); |
|
| 471 | - //$dataFound = true; |
|
| 469 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed']))); |
|
| 470 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true)); |
|
| 471 | + //$dataFound = true; |
|
| 472 | 472 | } else if (!isset($this->all_flights[$id]['speed_fromsrc']) && isset($this->all_flights[$id]['time_last_coord']) && $this->all_flights[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) { |
| 473 | - $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m'); |
|
| 474 | - if ($distance > 1000 && $distance < 10000) { |
|
| 475 | - // use datetime |
|
| 473 | + $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m'); |
|
| 474 | + if ($distance > 1000 && $distance < 10000) { |
|
| 475 | + // use datetime |
|
| 476 | 476 | $speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']); |
| 477 | 477 | $speed = $speed*3.6; |
| 478 | 478 | if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed))); |
| 479 | 479 | if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n"; |
| 480 | - } |
|
| 480 | + } |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | |
| 484 | 484 | |
| 485 | - if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
|
| 486 | - if (ctype_digit(strval($line['latitude'])) || ctype_digit(strval($line['longitude']))) { |
|
| 487 | - if ($globalDebug) echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n"; |
|
| 488 | - return false; |
|
| 489 | - } |
|
| 490 | - if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']); |
|
| 491 | - else unset($timediff); |
|
| 492 | - if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']); |
|
| 493 | - else unset($timediff_archive); |
|
| 494 | - if ($this->tmd > 5 |
|
| 495 | - || (isset($line['format_source']) |
|
| 496 | - && $line['format_source'] == 'airwhere' |
|
| 497 | - && ((!isset($this->all_flights[$id]['latitude']) |
|
| 498 | - || !isset($this->all_flights[$id]['longitude'])) |
|
| 499 | - || (isset($this->all_flights[$id]['latitude']) |
|
| 500 | - && isset($this->all_flights[$id]['longitude']) |
|
| 501 | - && $this->all_flights[$id]['latitude'] != $line['latitude'] |
|
| 502 | - && $this->all_flights[$id]['longitude'] != $line['longitude'] |
|
| 503 | - ) |
|
| 504 | - ) |
|
| 505 | - ) |
|
| 506 | - || (isset($globalVA) && $globalVA) |
|
| 507 | - || (isset($globalIVAO) && $globalIVAO) |
|
| 508 | - || (isset($globalVATSIM) && $globalVATSIM) |
|
| 509 | - || (isset($globalphpVMS) && $globalphpVMS) |
|
| 510 | - || (isset($globalVAM) && $globalVAM) |
|
| 511 | - || !isset($timediff) |
|
| 512 | - || $timediff > $globalLiveInterval |
|
| 513 | - || ($timediff > 30 |
|
| 514 | - && isset($this->all_flights[$id]['latitude']) |
|
| 515 | - && isset($this->all_flights[$id]['longitude']) |
|
| 516 | - && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')) |
|
| 517 | - ) |
|
| 518 | - ) { |
|
| 485 | + if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
|
| 486 | + if (ctype_digit(strval($line['latitude'])) || ctype_digit(strval($line['longitude']))) { |
|
| 487 | + if ($globalDebug) echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n"; |
|
| 488 | + return false; |
|
| 489 | + } |
|
| 490 | + if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']); |
|
| 491 | + else unset($timediff); |
|
| 492 | + if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']); |
|
| 493 | + else unset($timediff_archive); |
|
| 494 | + if ($this->tmd > 5 |
|
| 495 | + || (isset($line['format_source']) |
|
| 496 | + && $line['format_source'] == 'airwhere' |
|
| 497 | + && ((!isset($this->all_flights[$id]['latitude']) |
|
| 498 | + || !isset($this->all_flights[$id]['longitude'])) |
|
| 499 | + || (isset($this->all_flights[$id]['latitude']) |
|
| 500 | + && isset($this->all_flights[$id]['longitude']) |
|
| 501 | + && $this->all_flights[$id]['latitude'] != $line['latitude'] |
|
| 502 | + && $this->all_flights[$id]['longitude'] != $line['longitude'] |
|
| 503 | + ) |
|
| 504 | + ) |
|
| 505 | + ) |
|
| 506 | + || (isset($globalVA) && $globalVA) |
|
| 507 | + || (isset($globalIVAO) && $globalIVAO) |
|
| 508 | + || (isset($globalVATSIM) && $globalVATSIM) |
|
| 509 | + || (isset($globalphpVMS) && $globalphpVMS) |
|
| 510 | + || (isset($globalVAM) && $globalVAM) |
|
| 511 | + || !isset($timediff) |
|
| 512 | + || $timediff > $globalLiveInterval |
|
| 513 | + || ($timediff > 30 |
|
| 514 | + && isset($this->all_flights[$id]['latitude']) |
|
| 515 | + && isset($this->all_flights[$id]['longitude']) |
|
| 516 | + && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')) |
|
| 517 | + ) |
|
| 518 | + ) { |
|
| 519 | 519 | |
| 520 | 520 | if ((isset($timediff) && !isset($timediff_archive)) || (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude']))) { |
| 521 | - if ((isset($timediff_archive) && $timediff_archive > $globalAircraftMaxUpdate) |
|
| 521 | + if ((isset($timediff_archive) && $timediff_archive > $globalAircraftMaxUpdate) |
|
| 522 | 522 | || (isset($line['format_source']) && $line['format_source'] == 'airwhere') |
| 523 | 523 | || !$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) { |
| 524 | 524 | $this->all_flights[$id]['archive_latitude'] = $line['latitude']; |
@@ -526,9 +526,9 @@ discard block |
||
| 526 | 526 | $this->all_flights[$id]['putinarchive'] = true; |
| 527 | 527 | $this->tmd = 0; |
| 528 | 528 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
| 529 | - if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
|
| 530 | - $timeelapsed = microtime(true); |
|
| 531 | - if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
| 529 | + if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
|
| 530 | + $timeelapsed = microtime(true); |
|
| 531 | + if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
| 532 | 532 | $Spotter = new Spotter($this->db); |
| 533 | 533 | $all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
| 534 | 534 | if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2']; |
@@ -536,11 +536,11 @@ discard block |
||
| 536 | 536 | $Spotter->db = null; |
| 537 | 537 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
| 538 | 538 | if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n"; |
| 539 | - } |
|
| 539 | + } |
|
| 540 | 540 | } |
| 541 | 541 | $this->all_flights[$id]['time_last_archive_coord'] = time(); |
| 542 | - } |
|
| 543 | - /* |
|
| 542 | + } |
|
| 543 | + /* |
|
| 544 | 544 | else { |
| 545 | 545 | if (!isset($timediff)) echo 'NO TIMEDIFF'; |
| 546 | 546 | else { |
@@ -554,16 +554,16 @@ discard block |
||
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) { |
| 557 | - //if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) { |
|
| 557 | + //if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) { |
|
| 558 | 558 | if (!isset($this->all_flights[$id]['archive_latitude'])) { |
| 559 | 559 | $this->all_flights[$id]['archive_latitude'] = $line['latitude']; |
| 560 | 560 | $this->all_flights[$id]['time_last_coord'] = time(); |
| 561 | 561 | } |
| 562 | 562 | //if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs' || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > 0.0001)) { |
| 563 | 563 | if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > 0.0001)) { |
| 564 | - $this->all_flights[$id]['livedb_latitude'] = $line['latitude']; |
|
| 565 | - $dataFound = true; |
|
| 566 | - $this->all_flights[$id]['time_last_coord'] = time(); |
|
| 564 | + $this->all_flights[$id]['livedb_latitude'] = $line['latitude']; |
|
| 565 | + $dataFound = true; |
|
| 566 | + $this->all_flights[$id]['time_last_coord'] = time(); |
|
| 567 | 567 | } |
| 568 | 568 | // elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n"; |
| 569 | 569 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude'])); |
@@ -574,24 +574,24 @@ discard block |
||
| 574 | 574 | //$putinarchive = true; |
| 575 | 575 | } |
| 576 | 576 | */ |
| 577 | - /* |
|
| 577 | + /* |
|
| 578 | 578 | } elseif (isset($this->all_flights[$id]['latitude'])) { |
| 579 | 579 | if ($globalDebug) echo '!!! Strange latitude value - diff : '.abs($this->all_flights[$id]['latitude']-$line['latitude']).'- previous lat : '.$this->all_flights[$id]['latitude'].'- new lat : '.$line['latitude']."\n"; |
| 580 | 580 | } |
| 581 | 581 | */ |
| 582 | 582 | } |
| 583 | 583 | if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) { |
| 584 | - if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
|
| 585 | - //if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == '' || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) { |
|
| 584 | + if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
|
| 585 | + //if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == '' || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) { |
|
| 586 | 586 | if (!isset($this->all_flights[$id]['archive_longitude'])) { |
| 587 | 587 | $this->all_flights[$id]['archive_longitude'] = $line['longitude']; |
| 588 | 588 | $this->all_flights[$id]['time_last_coord'] = time(); |
| 589 | 589 | } |
| 590 | 590 | //if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs' || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > 0.0001)) { |
| 591 | 591 | if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > 0.0001)) { |
| 592 | - $this->all_flights[$id]['livedb_longitude'] = $line['longitude']; |
|
| 593 | - $dataFound = true; |
|
| 594 | - $this->all_flights[$id]['time_last_coord'] = time(); |
|
| 592 | + $this->all_flights[$id]['livedb_longitude'] = $line['longitude']; |
|
| 593 | + $dataFound = true; |
|
| 594 | + $this->all_flights[$id]['time_last_coord'] = time(); |
|
| 595 | 595 | } |
| 596 | 596 | // elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n"; |
| 597 | 597 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude'])); |
@@ -609,77 +609,77 @@ discard block |
||
| 609 | 609 | */ |
| 610 | 610 | } |
| 611 | 611 | |
| 612 | - } else if ($globalDebug && $timediff > 30) { |
|
| 612 | + } else if ($globalDebug && $timediff > 30) { |
|
| 613 | 613 | $this->tmd = $this->tmd + 1; |
| 614 | 614 | echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n"; |
| 615 | 615 | echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -"; |
| 616 | 616 | echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - "; |
| 617 | 617 | echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n"; |
| 618 | - } |
|
| 618 | + } |
|
| 619 | 619 | } |
| 620 | 620 | if (isset($line['last_update']) && $line['last_update'] != '') { |
| 621 | - if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true; |
|
| 622 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update'])); |
|
| 621 | + if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true; |
|
| 622 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update'])); |
|
| 623 | 623 | } |
| 624 | 624 | if (isset($line['verticalrate']) && $line['verticalrate'] != '') { |
| 625 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate'])); |
|
| 626 | - //$dataFound = true; |
|
| 625 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate'])); |
|
| 626 | + //$dataFound = true; |
|
| 627 | 627 | } |
| 628 | 628 | if (isset($line['format_source']) && $line['format_source'] != '') { |
| 629 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source'])); |
|
| 629 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source'])); |
|
| 630 | 630 | } |
| 631 | 631 | if (isset($line['source_name']) && $line['source_name'] != '') { |
| 632 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name'])); |
|
| 632 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name'])); |
|
| 633 | 633 | } |
| 634 | 634 | if (isset($line['emergency']) && $line['emergency'] != '') { |
| 635 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency'])); |
|
| 636 | - //$dataFound = true; |
|
| 635 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency'])); |
|
| 636 | + //$dataFound = true; |
|
| 637 | 637 | } |
| 638 | 638 | if (isset($line['ground']) && $line['ground'] != '') { |
| 639 | - if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) { |
|
| 639 | + if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) { |
|
| 640 | 640 | // Here we force archive of flight because after ground it's a new one (or should be) |
| 641 | 641 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
| 642 | 642 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1)); |
| 643 | 643 | if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); |
| 644 | - elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 644 | + elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 645 | 645 | elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
| 646 | - } |
|
| 647 | - if ($line['ground'] != 1) $line['ground'] = 0; |
|
| 648 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground'])); |
|
| 649 | - //$dataFound = true; |
|
| 646 | + } |
|
| 647 | + if ($line['ground'] != 1) $line['ground'] = 0; |
|
| 648 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground'])); |
|
| 649 | + //$dataFound = true; |
|
| 650 | 650 | } |
| 651 | 651 | if (isset($line['squawk']) && $line['squawk'] != '') { |
| 652 | - if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) { |
|
| 653 | - if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true; |
|
| 654 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
|
| 655 | - $highlight = ''; |
|
| 656 | - if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC'; |
|
| 657 | - if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC'; |
|
| 658 | - if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC'; |
|
| 659 | - if ($highlight != '') { |
|
| 652 | + if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) { |
|
| 653 | + if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true; |
|
| 654 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
|
| 655 | + $highlight = ''; |
|
| 656 | + if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC'; |
|
| 657 | + if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC'; |
|
| 658 | + if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC'; |
|
| 659 | + if ($highlight != '') { |
|
| 660 | 660 | $timeelapsed = microtime(true); |
| 661 | 661 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 662 | - $Spotter = new Spotter($this->db); |
|
| 663 | - $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight); |
|
| 664 | - $Spotter->db = null; |
|
| 665 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 662 | + $Spotter = new Spotter($this->db); |
|
| 663 | + $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight); |
|
| 664 | + $Spotter->db = null; |
|
| 665 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 666 | 666 | } |
| 667 | 667 | //$putinarchive = true; |
| 668 | 668 | //$highlight = ''; |
| 669 | - } |
|
| 669 | + } |
|
| 670 | 670 | |
| 671 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
|
| 672 | - //$dataFound = true; |
|
| 671 | + } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
|
| 672 | + //$dataFound = true; |
|
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | if (isset($line['altitude']) && $line['altitude'] != '') { |
| 676 | - //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) { |
|
| 676 | + //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) { |
|
| 677 | 677 | if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true; |
| 678 | 678 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100))); |
| 679 | 679 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude'])); |
| 680 | 680 | //$dataFound = true; |
| 681 | - //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n"; |
|
| 682 | - if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) { |
|
| 681 | + //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n"; |
|
| 682 | + if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) { |
|
| 683 | 683 | if (isset($this->all_flights[$id]['over_country']) && $this->all_flights[$id]['over_country'] != '' && isset($this->all_flights[$id]['altitude_previous']) && $this->all_flights[$id]['altitude_previous'] != '' && $this->all_flights[$id]['altitude_previous'] < $this->all_flights[$id]['altitude_real'] && isset($this->all_flights[$id]['lastupdate']) && $this->all_flights[$id]['lastupdate'] < time() - 1600) { |
| 684 | 684 | if ($globalDebug) echo '--- Reset because of altitude'."\n"; |
| 685 | 685 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
@@ -688,27 +688,27 @@ discard block |
||
| 688 | 688 | elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
| 689 | 689 | elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
| 690 | 690 | } |
| 691 | - } |
|
| 692 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude'])); |
|
| 691 | + } |
|
| 692 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude'])); |
|
| 693 | 693 | } |
| 694 | 694 | |
| 695 | 695 | if (isset($line['noarchive']) && $line['noarchive'] === true) { |
| 696 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true)); |
|
| 696 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true)); |
|
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | if (isset($line['heading']) && $line['heading'] != '') { |
| 700 | - if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true; |
|
| 701 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading']))); |
|
| 702 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true)); |
|
| 703 | - //$dataFound = true; |
|
| 700 | + if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true; |
|
| 701 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading']))); |
|
| 702 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true)); |
|
| 703 | + //$dataFound = true; |
|
| 704 | 704 | } elseif (!isset($this->all_flights[$id]['heading_fromsrc']) && isset($this->all_flights[$id]['archive_latitude']) && $this->all_flights[$id]['archive_latitude'] != $this->all_flights[$id]['latitude'] && isset($this->all_flights[$id]['archive_longitude']) && $this->all_flights[$id]['archive_longitude'] != $this->all_flights[$id]['longitude']) { |
| 705 | - $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']); |
|
| 706 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading))); |
|
| 707 | - if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true; |
|
| 708 | - if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['id']." : ".$heading."\n"; |
|
| 705 | + $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']); |
|
| 706 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading))); |
|
| 707 | + if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true; |
|
| 708 | + if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['id']." : ".$heading."\n"; |
|
| 709 | 709 | } elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') { |
| 710 | - // If not enough messages and ACARS set heading to 0 |
|
| 711 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0)); |
|
| 710 | + // If not enough messages and ACARS set heading to 0 |
|
| 711 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0)); |
|
| 712 | 712 | } |
| 713 | 713 | if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
| 714 | 714 | elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false; |
@@ -721,125 +721,125 @@ discard block |
||
| 721 | 721 | //if ($dataFound === true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['heading'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') { |
| 722 | 722 | //if ($dataFound === true && isset($this->all_flights[$id]['hex'])) { |
| 723 | 723 | if ($dataFound === true && isset($this->all_flights[$id]['id'])) { |
| 724 | - $this->all_flights[$id]['lastupdate'] = time(); |
|
| 725 | - if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) { |
|
| 726 | - if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == '' || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
|
| 727 | - //print_r($this->all_flights); |
|
| 728 | - //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n"; |
|
| 729 | - //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']); |
|
| 730 | - if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) { |
|
| 724 | + $this->all_flights[$id]['lastupdate'] = time(); |
|
| 725 | + if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) { |
|
| 726 | + if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == '' || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
|
| 727 | + //print_r($this->all_flights); |
|
| 728 | + //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n"; |
|
| 729 | + //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']); |
|
| 730 | + if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) { |
|
| 731 | 731 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 732 | - if ($globalDebug) echo "Check if aircraft is already in DB..."; |
|
| 733 | - $timeelapsed = microtime(true); |
|
| 734 | - $SpotterLive = new SpotterLive($this->db); |
|
| 735 | - if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) { |
|
| 732 | + if ($globalDebug) echo "Check if aircraft is already in DB..."; |
|
| 733 | + $timeelapsed = microtime(true); |
|
| 734 | + $SpotterLive = new SpotterLive($this->db); |
|
| 735 | + if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) { |
|
| 736 | 736 | $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']); |
| 737 | 737 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
| 738 | - } elseif (isset($line['id'])) { |
|
| 738 | + } elseif (isset($line['id'])) { |
|
| 739 | 739 | $recent_ident = $SpotterLive->checkIdRecent($line['id']); |
| 740 | 740 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
| 741 | - } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') { |
|
| 741 | + } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') { |
|
| 742 | 742 | $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']); |
| 743 | 743 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
| 744 | - } else $recent_ident = ''; |
|
| 745 | - $SpotterLive->db=null; |
|
| 746 | - if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
|
| 747 | - elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
|
| 744 | + } else $recent_ident = ''; |
|
| 745 | + $SpotterLive->db=null; |
|
| 746 | + if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
|
| 747 | + elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
|
| 748 | 748 | } else $recent_ident = ''; |
| 749 | - } else { |
|
| 749 | + } else { |
|
| 750 | 750 | $recent_ident = ''; |
| 751 | 751 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0)); |
| 752 | - } |
|
| 753 | - //if there was no aircraft with the same callsign within the last hour and go post it into the archive |
|
| 754 | - if($recent_ident == "") |
|
| 755 | - { |
|
| 752 | + } |
|
| 753 | + //if there was no aircraft with the same callsign within the last hour and go post it into the archive |
|
| 754 | + if($recent_ident == "") |
|
| 755 | + { |
|
| 756 | 756 | if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : "; |
| 757 | 757 | if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; } |
| 758 | 758 | if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; } |
| 759 | 759 | //adds the spotter data for the archive |
| 760 | 760 | $ignoreImport = false; |
| 761 | 761 | foreach($globalAirportIgnore as $airportIgnore) { |
| 762 | - if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
|
| 762 | + if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
|
| 763 | 763 | $ignoreImport = true; |
| 764 | - } |
|
| 764 | + } |
|
| 765 | 765 | } |
| 766 | 766 | if (count($globalAirportAccept) > 0) { |
| 767 | - $ignoreImport = true; |
|
| 768 | - foreach($globalAirportIgnore as $airportIgnore) { |
|
| 767 | + $ignoreImport = true; |
|
| 768 | + foreach($globalAirportIgnore as $airportIgnore) { |
|
| 769 | 769 | if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
| 770 | - $ignoreImport = false; |
|
| 770 | + $ignoreImport = false; |
|
| 771 | + } |
|
| 771 | 772 | } |
| 772 | - } |
|
| 773 | 773 | } |
| 774 | 774 | if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) { |
| 775 | - foreach($globalAirlineIgnore as $airlineIgnore) { |
|
| 775 | + foreach($globalAirlineIgnore as $airlineIgnore) { |
|
| 776 | 776 | if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) { |
| 777 | - $ignoreImport = true; |
|
| 777 | + $ignoreImport = true; |
|
| 778 | + } |
|
| 778 | 779 | } |
| 779 | - } |
|
| 780 | 780 | } |
| 781 | 781 | if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) { |
| 782 | - $ignoreImport = true; |
|
| 783 | - foreach($globalAirlineAccept as $airlineAccept) { |
|
| 782 | + $ignoreImport = true; |
|
| 783 | + foreach($globalAirlineAccept as $airlineAccept) { |
|
| 784 | 784 | if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) { |
| 785 | - $ignoreImport = false; |
|
| 785 | + $ignoreImport = false; |
|
| 786 | + } |
|
| 786 | 787 | } |
| 787 | - } |
|
| 788 | 788 | } |
| 789 | 789 | if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) { |
| 790 | - $ignoreImport = true; |
|
| 791 | - foreach($globalPilotIdAccept as $pilotIdAccept) { |
|
| 790 | + $ignoreImport = true; |
|
| 791 | + foreach($globalPilotIdAccept as $pilotIdAccept) { |
|
| 792 | 792 | if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) { |
| 793 | - $ignoreImport = false; |
|
| 793 | + $ignoreImport = false; |
|
| 794 | + } |
|
| 794 | 795 | } |
| 795 | - } |
|
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | if (!$ignoreImport) { |
| 799 | - $highlight = ''; |
|
| 800 | - if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack'; |
|
| 801 | - if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)'; |
|
| 802 | - if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency'; |
|
| 803 | - if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
|
| 804 | - $timeelapsed = microtime(true); |
|
| 805 | - if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
|
| 799 | + $highlight = ''; |
|
| 800 | + if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack'; |
|
| 801 | + if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)'; |
|
| 802 | + if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency'; |
|
| 803 | + if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
|
| 804 | + $timeelapsed = microtime(true); |
|
| 805 | + if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
|
| 806 | 806 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 807 | - $Spotter = new Spotter($this->db); |
|
| 808 | - $result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['source_type']); |
|
| 809 | - $Spotter->db = null; |
|
| 810 | - if ($globalDebug && isset($result)) echo $result."\n"; |
|
| 807 | + $Spotter = new Spotter($this->db); |
|
| 808 | + $result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['source_type']); |
|
| 809 | + $Spotter->db = null; |
|
| 810 | + if ($globalDebug && isset($result)) echo $result."\n"; |
|
| 811 | 811 | } |
| 812 | - } |
|
| 813 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 814 | - if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
| 812 | + } |
|
| 813 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 814 | + if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
| 815 | 815 | |
| 816 | - // Add source stat in DB |
|
| 817 | - $Stats = new Stats($this->db); |
|
| 818 | - if (!empty($this->stats)) { |
|
| 816 | + // Add source stat in DB |
|
| 817 | + $Stats = new Stats($this->db); |
|
| 818 | + if (!empty($this->stats)) { |
|
| 819 | 819 | if ($globalDebug) echo 'Add source stats : '; |
| 820 | - foreach($this->stats as $date => $data) { |
|
| 821 | - foreach($data as $source => $sourced) { |
|
| 822 | - //print_r($sourced); |
|
| 823 | - if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date); |
|
| 824 | - if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date); |
|
| 825 | - if (isset($sourced['msg'])) { |
|
| 826 | - if (time() - $sourced['msg']['date'] > 10) { |
|
| 827 | - $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date'])); |
|
| 828 | - echo $Stats->addStatSource($nbmsg,$source,'msg',$date); |
|
| 829 | - unset($this->stats[$date][$source]['msg']); |
|
| 830 | - } |
|
| 831 | - } |
|
| 832 | - } |
|
| 833 | - if ($date != date('Y-m-d')) { |
|
| 834 | - unset($this->stats[$date]); |
|
| 835 | - } |
|
| 836 | - } |
|
| 837 | - if ($globalDebug) echo 'Done'."\n"; |
|
| 820 | + foreach($this->stats as $date => $data) { |
|
| 821 | + foreach($data as $source => $sourced) { |
|
| 822 | + //print_r($sourced); |
|
| 823 | + if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date); |
|
| 824 | + if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date); |
|
| 825 | + if (isset($sourced['msg'])) { |
|
| 826 | + if (time() - $sourced['msg']['date'] > 10) { |
|
| 827 | + $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date'])); |
|
| 828 | + echo $Stats->addStatSource($nbmsg,$source,'msg',$date); |
|
| 829 | + unset($this->stats[$date][$source]['msg']); |
|
| 830 | + } |
|
| 831 | + } |
|
| 832 | + } |
|
| 833 | + if ($date != date('Y-m-d')) { |
|
| 834 | + unset($this->stats[$date]); |
|
| 835 | + } |
|
| 836 | + } |
|
| 837 | + if ($globalDebug) echo 'Done'."\n"; |
|
| 838 | 838 | |
| 839 | - } |
|
| 840 | - $Stats->db = null; |
|
| 841 | - } |
|
| 842 | - $this->del(); |
|
| 839 | + } |
|
| 840 | + $Stats->db = null; |
|
| 841 | + } |
|
| 842 | + $this->del(); |
|
| 843 | 843 | } elseif ($globalDebug) echo 'Ignore data'."\n"; |
| 844 | 844 | //$ignoreImport = false; |
| 845 | 845 | $this->all_flights[$id]['addedSpotter'] = 1; |
@@ -857,41 +857,41 @@ discard block |
||
| 857 | 857 | */ |
| 858 | 858 | //SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']); |
| 859 | 859 | if ($this->last_delete == 0 || time() - $this->last_delete > 1800) { |
| 860 | - if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours..."; |
|
| 861 | - //SpotterLive->deleteLiveSpotterDataNotUpdated(); |
|
| 862 | - if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
|
| 860 | + if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours..."; |
|
| 861 | + //SpotterLive->deleteLiveSpotterDataNotUpdated(); |
|
| 862 | + if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
|
| 863 | 863 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 864 | - $SpotterLive = new SpotterLive($this->db); |
|
| 865 | - $SpotterLive->deleteLiveSpotterData(); |
|
| 866 | - $SpotterLive->db=null; |
|
| 864 | + $SpotterLive = new SpotterLive($this->db); |
|
| 865 | + $SpotterLive->deleteLiveSpotterData(); |
|
| 866 | + $SpotterLive->db=null; |
|
| 867 | 867 | } |
| 868 | - } |
|
| 869 | - if ($globalDebug) echo " Done\n"; |
|
| 870 | - $this->last_delete = time(); |
|
| 868 | + } |
|
| 869 | + if ($globalDebug) echo " Done\n"; |
|
| 870 | + $this->last_delete = time(); |
|
| 871 | 871 | } |
| 872 | - } else { |
|
| 872 | + } else { |
|
| 873 | 873 | if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt'|| $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'famaprs' || $line['format_source'] === 'airwhere')) { |
| 874 | - $this->all_flights[$id]['id'] = $recent_ident; |
|
| 875 | - $this->all_flights[$id]['addedSpotter'] = 1; |
|
| 874 | + $this->all_flights[$id]['id'] = $recent_ident; |
|
| 875 | + $this->all_flights[$id]['addedSpotter'] = 1; |
|
| 876 | 876 | } |
| 877 | 877 | if (isset($globalDaemon) && !$globalDaemon) { |
| 878 | - if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
|
| 878 | + if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
|
| 879 | 879 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 880 | - $Spotter = new Spotter($this->db); |
|
| 881 | - $Spotter->updateLatestSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time']); |
|
| 882 | - $Spotter->db = null; |
|
| 880 | + $Spotter = new Spotter($this->db); |
|
| 881 | + $Spotter->updateLatestSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time']); |
|
| 882 | + $Spotter->db = null; |
|
| 883 | + } |
|
| 883 | 884 | } |
| 884 | - } |
|
| 885 | 885 | } |
| 886 | 886 | |
| 887 | - } |
|
| 887 | + } |
|
| 888 | 888 | } |
| 889 | - } |
|
| 890 | - //adds the spotter LIVE data |
|
| 891 | - //SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed); |
|
| 892 | - //echo "\nAdd in Live !! \n"; |
|
| 893 | - //echo "{$line[8]} {$line[7]} - MODES:{$line[4]} CALLSIGN:{$line[10]} ALT:{$line[11]} VEL:{$line[12]} HDG:{$line[13]} LAT:{$line[14]} LON:{$line[15]} VR:{$line[16]} SQUAWK:{$line[17]}\n"; |
|
| 894 | - if ($globalDebug) { |
|
| 889 | + } |
|
| 890 | + //adds the spotter LIVE data |
|
| 891 | + //SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed); |
|
| 892 | + //echo "\nAdd in Live !! \n"; |
|
| 893 | + //echo "{$line[8]} {$line[7]} - MODES:{$line[4]} CALLSIGN:{$line[10]} ALT:{$line[11]} VEL:{$line[12]} HDG:{$line[13]} LAT:{$line[14]} LON:{$line[15]} VR:{$line[16]} SQUAWK:{$line[17]}\n"; |
|
| 894 | + if ($globalDebug) { |
|
| 895 | 895 | if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) { |
| 896 | 896 | if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n"; |
| 897 | 897 | else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n"; |
@@ -899,60 +899,60 @@ discard block |
||
| 899 | 899 | if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n"; |
| 900 | 900 | else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n"; |
| 901 | 901 | } |
| 902 | - } |
|
| 903 | - $ignoreImport = false; |
|
| 904 | - if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; } |
|
| 905 | - if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; } |
|
| 902 | + } |
|
| 903 | + $ignoreImport = false; |
|
| 904 | + if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; } |
|
| 905 | + if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; } |
|
| 906 | 906 | |
| 907 | - foreach($globalAirportIgnore as $airportIgnore) { |
|
| 908 | - if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
|
| 909 | - $ignoreImport = true; |
|
| 907 | + foreach($globalAirportIgnore as $airportIgnore) { |
|
| 908 | + if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
|
| 909 | + $ignoreImport = true; |
|
| 910 | + } |
|
| 910 | 911 | } |
| 911 | - } |
|
| 912 | - if (count($globalAirportAccept) > 0) { |
|
| 913 | - $ignoreImport = true; |
|
| 914 | - foreach($globalAirportIgnore as $airportIgnore) { |
|
| 915 | - if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
|
| 912 | + if (count($globalAirportAccept) > 0) { |
|
| 913 | + $ignoreImport = true; |
|
| 914 | + foreach($globalAirportIgnore as $airportIgnore) { |
|
| 915 | + if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
|
| 916 | 916 | $ignoreImport = false; |
| 917 | - } |
|
| 917 | + } |
|
| 918 | 918 | } |
| 919 | - } |
|
| 920 | - if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) { |
|
| 919 | + } |
|
| 920 | + if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) { |
|
| 921 | 921 | foreach($globalAirlineIgnore as $airlineIgnore) { |
| 922 | - if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) { |
|
| 922 | + if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) { |
|
| 923 | 923 | $ignoreImport = true; |
| 924 | - } |
|
| 924 | + } |
|
| 925 | 925 | } |
| 926 | - } |
|
| 927 | - if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) { |
|
| 926 | + } |
|
| 927 | + if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) { |
|
| 928 | 928 | $ignoreImport = true; |
| 929 | 929 | foreach($globalAirlineAccept as $airlineAccept) { |
| 930 | - if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) { |
|
| 930 | + if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) { |
|
| 931 | 931 | $ignoreImport = false; |
| 932 | - } |
|
| 932 | + } |
|
| 933 | + } |
|
| 933 | 934 | } |
| 934 | - } |
|
| 935 | - if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) { |
|
| 935 | + if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) { |
|
| 936 | 936 | $ignoreImport = true; |
| 937 | 937 | foreach($globalPilotIdAccept as $pilotIdAccept) { |
| 938 | - if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) { |
|
| 939 | - $ignoreImport = false; |
|
| 940 | - } |
|
| 938 | + if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) { |
|
| 939 | + $ignoreImport = false; |
|
| 940 | + } |
|
| 941 | + } |
|
| 941 | 942 | } |
| 942 | - } |
|
| 943 | 943 | |
| 944 | - if (!$ignoreImport) { |
|
| 944 | + if (!$ignoreImport) { |
|
| 945 | 945 | if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
| 946 | 946 | if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
| 947 | 947 | $timeelapsed = microtime(true); |
| 948 | 948 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
| 949 | - if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
| 949 | + if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
| 950 | 950 | if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : "; |
| 951 | 951 | $SpotterLive = new SpotterLive($this->db); |
| 952 | 952 | $result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']); |
| 953 | 953 | $SpotterLive->db = null; |
| 954 | 954 | if ($globalDebug) echo $result."\n"; |
| 955 | - } |
|
| 955 | + } |
|
| 956 | 956 | } |
| 957 | 957 | if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_flights[$id]['putinarchive']) { |
| 958 | 958 | $APRSSpotter->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']); |
@@ -964,7 +964,7 @@ discard block |
||
| 964 | 964 | //if ($line['format_source'] != 'aprs') { |
| 965 | 965 | //if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt')) { |
| 966 | 966 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 967 | - if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') { |
|
| 967 | + if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') { |
|
| 968 | 968 | $source = $this->all_flights[$id]['source_name']; |
| 969 | 969 | if ($source == '') $source = $this->all_flights[$id]['format_source']; |
| 970 | 970 | if (!isset($this->source_location[$source])) { |
@@ -990,7 +990,7 @@ discard block |
||
| 990 | 990 | if ($stats_heading == 16) $stats_heading = 0; |
| 991 | 991 | if (!isset($this->stats[$current_date][$source]['polar'][1])) { |
| 992 | 992 | for ($i=0;$i<=15;$i++) { |
| 993 | - $this->stats[$current_date][$source]['polar'][$i] = 0; |
|
| 993 | + $this->stats[$current_date][$source]['polar'][$i] = 0; |
|
| 994 | 994 | } |
| 995 | 995 | $this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance; |
| 996 | 996 | } else { |
@@ -1003,17 +1003,17 @@ discard block |
||
| 1003 | 1003 | //var_dump($this->stats); |
| 1004 | 1004 | if (!isset($this->stats[$current_date][$source]['hist'][$distance])) { |
| 1005 | 1005 | if (isset($this->stats[$current_date][$source]['hist'][0])) { |
| 1006 | - end($this->stats[$current_date][$source]['hist']); |
|
| 1007 | - $mini = key($this->stats[$current_date][$source]['hist'])+10; |
|
| 1006 | + end($this->stats[$current_date][$source]['hist']); |
|
| 1007 | + $mini = key($this->stats[$current_date][$source]['hist'])+10; |
|
| 1008 | 1008 | } else $mini = 0; |
| 1009 | 1009 | for ($i=$mini;$i<=$distance;$i+=10) { |
| 1010 | - $this->stats[$current_date][$source]['hist'][$i] = 0; |
|
| 1010 | + $this->stats[$current_date][$source]['hist'][$i] = 0; |
|
| 1011 | 1011 | } |
| 1012 | 1012 | $this->stats[$current_date][$source]['hist'][$distance] = 1; |
| 1013 | 1013 | } else { |
| 1014 | 1014 | $this->stats[$current_date][$source]['hist'][$distance] += 1; |
| 1015 | 1015 | } |
| 1016 | - } |
|
| 1016 | + } |
|
| 1017 | 1017 | } |
| 1018 | 1018 | |
| 1019 | 1019 | $this->all_flights[$id]['lastupdate'] = time(); |
@@ -1023,7 +1023,7 @@ discard block |
||
| 1023 | 1023 | //$this->del(); |
| 1024 | 1024 | |
| 1025 | 1025 | if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) { |
| 1026 | - if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) { |
|
| 1026 | + if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) { |
|
| 1027 | 1027 | if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour..."; |
| 1028 | 1028 | $SpotterLive = new SpotterLive($this->db); |
| 1029 | 1029 | $SpotterLive->deleteLiveSpotterDataNotUpdated(); |
@@ -1031,19 +1031,19 @@ discard block |
||
| 1031 | 1031 | //SpotterLive->deleteLiveSpotterData(); |
| 1032 | 1032 | if ($globalDebug) echo " Done\n"; |
| 1033 | 1033 | $this->last_delete_hourly = time(); |
| 1034 | - } else { |
|
| 1034 | + } else { |
|
| 1035 | 1035 | $this->del(); |
| 1036 | 1036 | $this->last_delete_hourly = time(); |
| 1037 | - } |
|
| 1037 | + } |
|
| 1038 | 1038 | } |
| 1039 | 1039 | |
| 1040 | - } |
|
| 1041 | - //$ignoreImport = false; |
|
| 1040 | + } |
|
| 1041 | + //$ignoreImport = false; |
|
| 1042 | 1042 | } |
| 1043 | 1043 | //if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN); |
| 1044 | 1044 | if ($send) return $this->all_flights[$id]; |
| 1045 | - } |
|
| 1045 | + } |
|
| 1046 | + } |
|
| 1046 | 1047 | } |
| 1047 | - } |
|
| 1048 | 1048 | } |
| 1049 | 1049 | ?> |
@@ -33,12 +33,12 @@ discard block |
||
| 33 | 33 | $currentdate = date('Y-m-d'); |
| 34 | 34 | $sourcestat = $Stats->getStatsSource($currentdate); |
| 35 | 35 | if (!empty($sourcestat)) { |
| 36 | - foreach($sourcestat as $srcst) { |
|
| 36 | + foreach ($sourcestat as $srcst) { |
|
| 37 | 37 | $type = $srcst['stats_type']; |
| 38 | 38 | if ($type == 'polar' || $type == 'hist') { |
| 39 | 39 | $source = $srcst['source_name']; |
| 40 | 40 | $data = $srcst['source_data']; |
| 41 | - $this->stats[$currentdate][$source][$type] = json_decode($data,true); |
|
| 41 | + $this->stats[$currentdate][$source][$type] = json_decode($data, true); |
|
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | 44 | } |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - public function get_Schedule($id,$ident) { |
|
| 53 | + public function get_Schedule($id, $ident) { |
|
| 54 | 54 | global $globalDebug, $globalFork, $globalSchedulesFetch; |
| 55 | 55 | // Get schedule here, so it's done only one time |
| 56 | 56 | |
@@ -75,8 +75,8 @@ discard block |
||
| 75 | 75 | $schedule = $Schedule->fetchSchedule($operator); |
| 76 | 76 | if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) { |
| 77 | 77 | if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n"; |
| 78 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime'])); |
|
| 79 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime'])); |
|
| 78 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport_time' => $schedule['DepartureTime'])); |
|
| 79 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport_time' => $schedule['ArrivalTime'])); |
|
| 80 | 80 | // Should also check if route schedule = route from DB |
| 81 | 81 | if ($schedule['DepartureAirportIATA'] != '') { |
| 82 | 82 | if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) { |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | - $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']); |
|
| 99 | + $Schedule->addSchedule($operator, $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['arrival_airport_time'], $schedule['Source']); |
|
| 100 | 100 | } |
| 101 | 101 | } else $scheduleexist = true; |
| 102 | 102 | } else $scheduleexist = true; |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | if ($scheduleexist) { |
| 105 | 105 | if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n"; |
| 106 | 106 | $sch = $Schedule->getSchedule($operator); |
| 107 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time'])); |
|
| 107 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport' => $sch['arrival_airport_icao'], 'departure_airport' => $sch['departure_airport_icao'], 'departure_airport_time' => $sch['departure_airport_time'], 'arrival_airport_time' => $sch['arrival_airport_time'])); |
|
| 108 | 108 | } |
| 109 | 109 | $Spotter->db = null; |
| 110 | 110 | $Schedule->db = null; |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].' '.$this->all_flights[$key]['longitude']."\n"; |
| 132 | 132 | $Spotter = new Spotter($this->db); |
| 133 | 133 | $real_arrival = $this->arrival($key); |
| 134 | - if (isset($this->all_flights[$key]['altitude'])) $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']); |
|
| 134 | + if (isset($this->all_flights[$key]['altitude'])) $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'], $this->all_flights[$key]['ident'], $this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $this->all_flights[$key]['altitude'], $this->all_flights[$key]['ground'], $this->all_flights[$key]['speed'], $this->all_flights[$key]['datetime'], $real_arrival['airport_icao'], $real_arrival['airport_time']); |
|
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 137 | } |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | $airport_time = ''; |
| 146 | 146 | if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50; |
| 147 | 147 | if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') { |
| 148 | - $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist); |
|
| 148 | + $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $globalClosestMinDist); |
|
| 149 | 149 | if (isset($closestAirports[0])) { |
| 150 | 150 | if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) { |
| 151 | 151 | $airport_icao = $closestAirports[0]['icao']; |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | break; |
| 161 | 161 | } |
| 162 | 162 | } |
| 163 | - } elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) { |
|
| 163 | + } elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude'] + 5000))) { |
|
| 164 | 164 | $airport_icao = $closestAirports[0]['icao']; |
| 165 | 165 | $airport_time = $this->all_flights[$key]['datetime']; |
| 166 | 166 | } else { |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | } else { |
| 174 | 174 | if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n"; |
| 175 | 175 | } |
| 176 | - return array('airport_icao' => $airport_icao,'airport_time' => $airport_time); |
|
| 176 | + return array('airport_icao' => $airport_icao, 'airport_time' => $airport_time); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | if ($globalDebug) echo 'Delete old values and update latest data...'."\n"; |
| 185 | 185 | foreach ($this->all_flights as $key => $flight) { |
| 186 | 186 | if (isset($flight['lastupdate'])) { |
| 187 | - if ($flight['lastupdate'] < (time()-5900)) { |
|
| 187 | + if ($flight['lastupdate'] < (time() - 5900)) { |
|
| 188 | 188 | $this->delKey($key); |
| 189 | 189 | } |
| 190 | 190 | } |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | $real_arrival = $this->arrival($key); |
| 201 | 201 | $Spotter = new Spotter($this->db); |
| 202 | 202 | if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') { |
| 203 | - $result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']); |
|
| 203 | + $result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'], $this->all_flights[$key]['ident'], $this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $this->all_flights[$key]['altitude'], $this->all_flights[$key]['ground'], $this->all_flights[$key]['speed'], $this->all_flights[$key]['datetime'], $real_arrival['airport_icao'], $real_arrival['airport_time']); |
|
| 204 | 204 | if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
| 205 | 205 | } |
| 206 | 206 | } |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | $send = false; |
| 234 | 234 | |
| 235 | 235 | // SBS format is CSV format |
| 236 | - if(is_array($line) && (isset($line['hex']) || isset($line['id']))) { |
|
| 236 | + if (is_array($line) && (isset($line['hex']) || isset($line['id']))) { |
|
| 237 | 237 | //print_r($line); |
| 238 | 238 | if (isset($line['hex'])) $line['hex'] = strtoupper($line['hex']); |
| 239 | 239 | if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) { |
@@ -269,25 +269,25 @@ discard block |
||
| 269 | 269 | if (!isset($this->all_flights[$id])) { |
| 270 | 270 | if ($globalDebug) echo 'New flight...'."\n"; |
| 271 | 271 | $this->all_flights[$id] = array(); |
| 272 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
|
| 273 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '','altitude_previous' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => '')); |
|
| 274 | - if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time())); |
|
| 272 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0)); |
|
| 273 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => '', 'departure_airport' => '', 'arrival_airport' => '', 'latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '', 'altitude_real' => '', 'altitude_previous' => '', 'heading' => '', 'departure_airport_time' => '', 'arrival_airport_time' => '', 'squawk' => '', 'route_stop' => '', 'registration' => '', 'pilot_id' => '', 'pilot_name' => '', 'waypoints' => '', 'ground' => '0', 'format_source' => '', 'source_name' => '', 'over_country' => '', 'verticalrate' => '', 'noarchive' => false, 'putinarchive' => true, 'source_type' => '')); |
|
| 274 | + if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('lastupdate' => time())); |
|
| 275 | 275 | if (!isset($line['id'])) { |
| 276 | 276 | if (!isset($globalDaemon)) $globalDaemon = TRUE; |
| 277 | 277 | // if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi'))); |
| 278 | 278 | // if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
| 279 | - if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
| 279 | + if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $id.'-'.date('YmdHi'))); |
|
| 280 | 280 | //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
| 281 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 281 | + } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id'])); |
|
| 282 | 282 | if ($globalAllFlights !== FALSE) $dataFound = true; |
| 283 | 283 | } |
| 284 | 284 | if (isset($line['source_type']) && $line['source_type'] != '') { |
| 285 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type'])); |
|
| 285 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('source_type' => $line['source_type'])); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | //print_r($this->all_flights); |
| 289 | 289 | if (isset($line['hex']) && !isset($this->all_flights[$id]['hex']) && ctype_xdigit($line['hex'])) { |
| 290 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => trim($line['hex']))); |
|
| 290 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('hex' => trim($line['hex']))); |
|
| 291 | 291 | //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) { |
| 292 | 292 | //$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime'])); |
| 293 | 293 | //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s'))); |
@@ -296,27 +296,27 @@ discard block |
||
| 296 | 296 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 297 | 297 | $Spotter = new Spotter($this->db); |
| 298 | 298 | if (isset($this->all_flights[$id]['source_type'])) { |
| 299 | - $aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']),$this->all_flights[$id]['source_type']); |
|
| 299 | + $aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex']), $this->all_flights[$id]['source_type']); |
|
| 300 | 300 | } else { |
| 301 | 301 | $aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex'])); |
| 302 | 302 | } |
| 303 | 303 | $Spotter->db = null; |
| 304 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 305 | - if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
| 304 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 305 | + if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao)); |
|
| 306 | 306 | } |
| 307 | 307 | } |
| 308 | 308 | if ($globalAllFlights !== FALSE) $dataFound = true; |
| 309 | 309 | if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n"; |
| 310 | 310 | } |
| 311 | 311 | if (isset($line['id']) && !isset($line['hex'])) { |
| 312 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => '')); |
|
| 312 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('hex' => '')); |
|
| 313 | 313 | } |
| 314 | 314 | if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') { |
| 315 | 315 | $icao = $line['aircraft_icao']; |
| 316 | 316 | $Spotter = new Spotter($this->db); |
| 317 | 317 | if (isset($Spotter->aircraft_correct_icaotype[$icao])) $icao = $Spotter->aircraft_correct_icaotype[$icao]; |
| 318 | 318 | $Spotter->db = null; |
| 319 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $icao)); |
|
| 319 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $icao)); |
|
| 320 | 320 | } |
| 321 | 321 | if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_name'])) { |
| 322 | 322 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | $Spotter = new Spotter($this->db); |
| 325 | 325 | $aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']); |
| 326 | 326 | $Spotter->db = null; |
| 327 | - if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
| 327 | + if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao)); |
|
| 328 | 328 | } |
| 329 | 329 | } |
| 330 | 330 | if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_type'])) { |
@@ -332,15 +332,15 @@ discard block |
||
| 332 | 332 | elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL'; |
| 333 | 333 | elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE'; |
| 334 | 334 | elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC'; |
| 335 | - if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
| 335 | + if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao)); |
|
| 336 | 336 | } |
| 337 | 337 | if (!isset($this->all_flights[$id]['aircraft_icao'])) { |
| 338 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA')); |
|
| 338 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => 'NA')); |
|
| 339 | 339 | } |
| 340 | 340 | //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) { |
| 341 | - if (isset($line['datetime']) && strtotime($line['datetime']) > time()-20*60 && strtotime($line['datetime']) < time()+20*60) { |
|
| 341 | + if (isset($line['datetime']) && strtotime($line['datetime']) > time() - 20*60 && strtotime($line['datetime']) < time() + 20*60) { |
|
| 342 | 342 | if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) { |
| 343 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime'])); |
|
| 343 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('datetime' => $line['datetime'])); |
|
| 344 | 344 | } else { |
| 345 | 345 | if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n"; |
| 346 | 346 | elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n"; |
@@ -351,32 +351,32 @@ discard block |
||
| 351 | 351 | */ |
| 352 | 352 | return ''; |
| 353 | 353 | } |
| 354 | - } elseif (isset($line['datetime']) && strtotime($line['datetime']) < time()-20*60) { |
|
| 354 | + } elseif (isset($line['datetime']) && strtotime($line['datetime']) < time() - 20*60) { |
|
| 355 | 355 | if ($globalDebug) echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n"; |
| 356 | 356 | return ''; |
| 357 | - } elseif (isset($line['datetime']) && strtotime($line['datetime']) > time()+20*60) { |
|
| 357 | + } elseif (isset($line['datetime']) && strtotime($line['datetime']) > time() + 20*60) { |
|
| 358 | 358 | if ($globalDebug) echo "!!! Date is in the future ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n |
| 359 | 359 | "; |
| 360 | 360 | return ''; |
| 361 | 361 | } elseif (!isset($line['datetime'])) { |
| 362 | 362 | date_default_timezone_set('UTC'); |
| 363 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s'))); |
|
| 363 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('datetime' => date('Y-m-d H:i:s'))); |
|
| 364 | 364 | } else { |
| 365 | 365 | if ($globalDebug) echo "!!! Unknow date error ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!"; |
| 366 | 366 | return ''; |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') { |
| 370 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration'])); |
|
| 370 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('registration' => $line['registration'])); |
|
| 371 | 371 | } |
| 372 | 372 | if (isset($line['waypoints']) && $line['waypoints'] != '') { |
| 373 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints'])); |
|
| 373 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('waypoints' => $line['waypoints'])); |
|
| 374 | 374 | } |
| 375 | 375 | if (isset($line['pilot_id']) && $line['pilot_id'] != '') { |
| 376 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => trim($line['pilot_id']))); |
|
| 376 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('pilot_id' => trim($line['pilot_id']))); |
|
| 377 | 377 | } |
| 378 | 378 | if (isset($line['pilot_name']) && $line['pilot_name'] != '') { |
| 379 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => trim($line['pilot_name']))); |
|
| 379 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('pilot_name' => trim($line['pilot_name']))); |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_flights[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9]+$/', $line['ident'])) { |
@@ -384,13 +384,13 @@ discard block |
||
| 384 | 384 | if ($this->all_flights[$id]['addedSpotter'] == 1) { |
| 385 | 385 | if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE && $this->all_flights[$id]['lastupdate'] < time() - 1600) { |
| 386 | 386 | if ($globalDebug) echo '---!!!! New ident, reset aircraft data...'."\n"; |
| 387 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
|
| 388 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1)); |
|
| 389 | - if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
| 390 | - elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 391 | - elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 387 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0)); |
|
| 388 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 1)); |
|
| 389 | + if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $id.'-'.date('YmdHi'))); |
|
| 390 | + elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id'])); |
|
| 391 | + elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 392 | 392 | } else { |
| 393 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident']))); |
|
| 393 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => trim($line['ident']))); |
|
| 394 | 394 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 395 | 395 | $timeelapsed = microtime(true); |
| 396 | 396 | $Spotter = new Spotter($this->db); |
@@ -400,13 +400,13 @@ discard block |
||
| 400 | 400 | elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao'; |
| 401 | 401 | elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim'; |
| 402 | 402 | elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao'; |
| 403 | - $result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource); |
|
| 403 | + $result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $fromsource); |
|
| 404 | 404 | if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
| 405 | 405 | $Spotter->db = null; |
| 406 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 406 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 407 | 407 | } |
| 408 | 408 | } |
| 409 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident']))); |
|
| 409 | + } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => trim($line['ident']))); |
|
| 410 | 410 | |
| 411 | 411 | /* |
| 412 | 412 | if (!isset($line['id'])) { |
@@ -416,25 +416,25 @@ discard block |
||
| 416 | 416 | else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
| 417 | 417 | } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
| 418 | 418 | */ |
| 419 | - if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 419 | + if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 420 | 420 | |
| 421 | 421 | //$putinarchive = true; |
| 422 | 422 | if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) { |
| 423 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time'])); |
|
| 423 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport_time' => $line['departure_airport_time'])); |
|
| 424 | 424 | } |
| 425 | 425 | if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) { |
| 426 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time'])); |
|
| 426 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport_time' => $line['arrival_airport_time'])); |
|
| 427 | 427 | } |
| 428 | 428 | if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) { |
| 429 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => '')); |
|
| 429 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport' => $line['departure_airport_icao'], 'arrival_airport' => $line['arrival_airport_icao'], 'route_stop' => '')); |
|
| 430 | 430 | } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) { |
| 431 | 431 | $timeelapsed = microtime(true); |
| 432 | 432 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 433 | 433 | $Spotter = new Spotter($this->db); |
| 434 | 434 | $line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']); |
| 435 | 435 | $line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']); |
| 436 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => '')); |
|
| 437 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 436 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport' => $line['departure_airport_icao'], 'arrival_airport' => $line['arrival_airport_icao'], 'route_stop' => '')); |
|
| 437 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 438 | 438 | } |
| 439 | 439 | } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') { |
| 440 | 440 | $timeelapsed = microtime(true); |
@@ -448,34 +448,34 @@ discard block |
||
| 448 | 448 | $Translation->db = null; |
| 449 | 449 | } |
| 450 | 450 | $Spotter->db = null; |
| 451 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 451 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 452 | 452 | } |
| 453 | 453 | if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) { |
| 454 | 454 | //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) { |
| 455 | 455 | if ($route['fromairport_icao'] != $route['toairport_icao']) { |
| 456 | 456 | // $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['FromAirport_ICAO'],'arrival_airport' => $route['ToAirport_ICAO'],'route_stop' => $route['RouteStop'])); |
| 457 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop'])); |
|
| 457 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport' => $route['fromairport_icao'], 'arrival_airport' => $route['toairport_icao'], 'route_stop' => $route['routestop'])); |
|
| 458 | 458 | } |
| 459 | 459 | } |
| 460 | 460 | if (!isset($globalFork)) $globalFork = TRUE; |
| 461 | 461 | if (!$globalVA && !$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) { |
| 462 | - if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident'])); |
|
| 462 | + if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id, trim($line['ident'])); |
|
| 463 | 463 | } |
| 464 | 464 | } |
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | if (isset($line['speed']) && $line['speed'] != '') { |
| 468 | 468 | // $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12])); |
| 469 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed']))); |
|
| 470 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true)); |
|
| 469 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed' => round($line['speed']))); |
|
| 470 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed_fromsrc' => true)); |
|
| 471 | 471 | //$dataFound = true; |
| 472 | 472 | } else if (!isset($this->all_flights[$id]['speed_fromsrc']) && isset($this->all_flights[$id]['time_last_coord']) && $this->all_flights[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) { |
| 473 | - $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m'); |
|
| 473 | + $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm'); |
|
| 474 | 474 | if ($distance > 1000 && $distance < 10000) { |
| 475 | 475 | // use datetime |
| 476 | 476 | $speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']); |
| 477 | 477 | $speed = $speed*3.6; |
| 478 | - if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed))); |
|
| 478 | + if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed' => round($speed))); |
|
| 479 | 479 | if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n"; |
| 480 | 480 | } |
| 481 | 481 | } |
@@ -487,9 +487,9 @@ discard block |
||
| 487 | 487 | if ($globalDebug) echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n"; |
| 488 | 488 | return false; |
| 489 | 489 | } |
| 490 | - if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']); |
|
| 490 | + if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time() - $this->all_flights[$id]['time_last_coord']); |
|
| 491 | 491 | else unset($timediff); |
| 492 | - if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']); |
|
| 492 | + if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time() - $this->all_flights[$id]['time_last_archive_coord']); |
|
| 493 | 493 | else unset($timediff_archive); |
| 494 | 494 | if ($this->tmd > 5 |
| 495 | 495 | || (isset($line['format_source']) |
@@ -513,14 +513,14 @@ discard block |
||
| 513 | 513 | || ($timediff > 30 |
| 514 | 514 | && isset($this->all_flights[$id]['latitude']) |
| 515 | 515 | && isset($this->all_flights[$id]['longitude']) |
| 516 | - && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')) |
|
| 516 | + && $Common->withinThreshold($timediff, $Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')) |
|
| 517 | 517 | ) |
| 518 | 518 | ) { |
| 519 | 519 | |
| 520 | 520 | if ((isset($timediff) && !isset($timediff_archive)) || (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude']))) { |
| 521 | 521 | if ((isset($timediff_archive) && $timediff_archive > $globalAircraftMaxUpdate) |
| 522 | 522 | || (isset($line['format_source']) && $line['format_source'] == 'airwhere') |
| 523 | - || !$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) { |
|
| 523 | + || !$Common->checkLine($this->all_flights[$id]['archive_latitude'], $this->all_flights[$id]['archive_longitude'], $this->all_flights[$id]['livedb_latitude'], $this->all_flights[$id]['livedb_longitude'], $line['latitude'], $line['longitude'])) { |
|
| 524 | 524 | $this->all_flights[$id]['archive_latitude'] = $line['latitude']; |
| 525 | 525 | $this->all_flights[$id]['archive_longitude'] = $line['longitude']; |
| 526 | 526 | $this->all_flights[$id]['putinarchive'] = true; |
@@ -530,11 +530,11 @@ discard block |
||
| 530 | 530 | $timeelapsed = microtime(true); |
| 531 | 531 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 532 | 532 | $Spotter = new Spotter($this->db); |
| 533 | - $all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
|
| 533 | + $all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']); |
|
| 534 | 534 | if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2']; |
| 535 | 535 | else $this->all_flights[$id]['over_country'] = ''; |
| 536 | 536 | $Spotter->db = null; |
| 537 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 537 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 538 | 538 | if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n"; |
| 539 | 539 | } |
| 540 | 540 | } |
@@ -560,13 +560,13 @@ discard block |
||
| 560 | 560 | $this->all_flights[$id]['time_last_coord'] = time(); |
| 561 | 561 | } |
| 562 | 562 | //if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs' || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > 0.0001)) { |
| 563 | - if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > 0.0001)) { |
|
| 563 | + if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude'] - $line['latitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_latitude'] - $line['latitude']) > 0.0001)) { |
|
| 564 | 564 | $this->all_flights[$id]['livedb_latitude'] = $line['latitude']; |
| 565 | 565 | $dataFound = true; |
| 566 | 566 | $this->all_flights[$id]['time_last_coord'] = time(); |
| 567 | 567 | } |
| 568 | 568 | // elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n"; |
| 569 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude'])); |
|
| 569 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('latitude' => $line['latitude'])); |
|
| 570 | 570 | /* |
| 571 | 571 | if (abs($this->all_flights[$id]['archive_latitude']-$this->all_flights[$id]['latitude']) > 0.3) { |
| 572 | 572 | $this->all_flights[$id]['archive_latitude'] = $line['latitude']; |
@@ -588,13 +588,13 @@ discard block |
||
| 588 | 588 | $this->all_flights[$id]['time_last_coord'] = time(); |
| 589 | 589 | } |
| 590 | 590 | //if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs' || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > 0.0001)) { |
| 591 | - if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > 0.0001)) { |
|
| 591 | + if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude'] - $line['longitude']) > $globalCoordMinChange || ($this->all_flights[$id]['format_source'] == 'airwhere' && abs($this->all_flights[$id]['livedb_longitude'] - $line['longitude']) > 0.0001)) { |
|
| 592 | 592 | $this->all_flights[$id]['livedb_longitude'] = $line['longitude']; |
| 593 | 593 | $dataFound = true; |
| 594 | 594 | $this->all_flights[$id]['time_last_coord'] = time(); |
| 595 | 595 | } |
| 596 | 596 | // elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n"; |
| 597 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude'])); |
|
| 597 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('longitude' => $line['longitude'])); |
|
| 598 | 598 | /* |
| 599 | 599 | if (abs($this->all_flights[$id]['archive_longitude']-$this->all_flights[$id]['longitude']) > 0.3) { |
| 600 | 600 | $this->all_flights[$id]['archive_longitude'] = $line['longitude']; |
@@ -612,46 +612,46 @@ discard block |
||
| 612 | 612 | } else if ($globalDebug && $timediff > 30) { |
| 613 | 613 | $this->tmd = $this->tmd + 1; |
| 614 | 614 | echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n"; |
| 615 | - echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -"; |
|
| 616 | - echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - "; |
|
| 615 | + echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')."m -"; |
|
| 616 | + echo 'Speed : '.(($Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')/$timediff)*3.6)." km/h - "; |
|
| 617 | 617 | echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n"; |
| 618 | 618 | } |
| 619 | 619 | } |
| 620 | 620 | if (isset($line['last_update']) && $line['last_update'] != '') { |
| 621 | 621 | if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true; |
| 622 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update'])); |
|
| 622 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('last_update' => $line['last_update'])); |
|
| 623 | 623 | } |
| 624 | 624 | if (isset($line['verticalrate']) && $line['verticalrate'] != '') { |
| 625 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate'])); |
|
| 625 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('verticalrate' => $line['verticalrate'])); |
|
| 626 | 626 | //$dataFound = true; |
| 627 | 627 | } |
| 628 | 628 | if (isset($line['format_source']) && $line['format_source'] != '') { |
| 629 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source'])); |
|
| 629 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('format_source' => $line['format_source'])); |
|
| 630 | 630 | } |
| 631 | 631 | if (isset($line['source_name']) && $line['source_name'] != '') { |
| 632 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name'])); |
|
| 632 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('source_name' => $line['source_name'])); |
|
| 633 | 633 | } |
| 634 | 634 | if (isset($line['emergency']) && $line['emergency'] != '') { |
| 635 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency'])); |
|
| 635 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('emergency' => $line['emergency'])); |
|
| 636 | 636 | //$dataFound = true; |
| 637 | 637 | } |
| 638 | 638 | if (isset($line['ground']) && $line['ground'] != '') { |
| 639 | 639 | if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) { |
| 640 | 640 | // Here we force archive of flight because after ground it's a new one (or should be) |
| 641 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
|
| 642 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1)); |
|
| 643 | - if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
| 644 | - elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 645 | - elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 641 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0)); |
|
| 642 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 1)); |
|
| 643 | + if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $id.'-'.date('YmdHi'))); |
|
| 644 | + elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id'])); |
|
| 645 | + elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 646 | 646 | } |
| 647 | 647 | if ($line['ground'] != 1) $line['ground'] = 0; |
| 648 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground'])); |
|
| 648 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ground' => $line['ground'])); |
|
| 649 | 649 | //$dataFound = true; |
| 650 | 650 | } |
| 651 | 651 | if (isset($line['squawk']) && $line['squawk'] != '') { |
| 652 | 652 | if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) { |
| 653 | 653 | if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true; |
| 654 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
|
| 654 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk'])); |
|
| 655 | 655 | $highlight = ''; |
| 656 | 656 | if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC'; |
| 657 | 657 | if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC'; |
@@ -660,59 +660,59 @@ discard block |
||
| 660 | 660 | $timeelapsed = microtime(true); |
| 661 | 661 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 662 | 662 | $Spotter = new Spotter($this->db); |
| 663 | - $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight); |
|
| 663 | + $Spotter->setHighlightFlight($this->all_flights[$id]['id'], $highlight); |
|
| 664 | 664 | $Spotter->db = null; |
| 665 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 665 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 666 | 666 | } |
| 667 | 667 | //$putinarchive = true; |
| 668 | 668 | //$highlight = ''; |
| 669 | 669 | } |
| 670 | 670 | |
| 671 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
|
| 671 | + } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk'])); |
|
| 672 | 672 | //$dataFound = true; |
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | if (isset($line['altitude']) && $line['altitude'] != '') { |
| 676 | 676 | //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) { |
| 677 | - if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true; |
|
| 678 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100))); |
|
| 679 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude'])); |
|
| 677 | + if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100) - $this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true; |
|
| 678 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude' => round($line['altitude']/100))); |
|
| 679 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude_real' => $line['altitude'])); |
|
| 680 | 680 | //$dataFound = true; |
| 681 | 681 | //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n"; |
| 682 | 682 | if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) { |
| 683 | 683 | if (isset($this->all_flights[$id]['over_country']) && $this->all_flights[$id]['over_country'] != '' && isset($this->all_flights[$id]['altitude_previous']) && $this->all_flights[$id]['altitude_previous'] != '' && $this->all_flights[$id]['altitude_previous'] < $this->all_flights[$id]['altitude_real'] && isset($this->all_flights[$id]['lastupdate']) && $this->all_flights[$id]['lastupdate'] < time() - 1600) { |
| 684 | 684 | if ($globalDebug) echo '--- Reset because of altitude'."\n"; |
| 685 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
|
| 686 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1)); |
|
| 687 | - if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
| 688 | - elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 689 | - elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 685 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0)); |
|
| 686 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 1)); |
|
| 687 | + if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $id.'-'.date('YmdHi'))); |
|
| 688 | + elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id'])); |
|
| 689 | + elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 690 | 690 | } |
| 691 | 691 | } |
| 692 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude'])); |
|
| 692 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude_previous' => $line['altitude'])); |
|
| 693 | 693 | } |
| 694 | 694 | |
| 695 | 695 | if (isset($line['noarchive']) && $line['noarchive'] === true) { |
| 696 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true)); |
|
| 696 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('noarchive' => true)); |
|
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | if (isset($line['heading']) && $line['heading'] != '') { |
| 700 | - if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true; |
|
| 701 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading']))); |
|
| 702 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true)); |
|
| 700 | + if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading'] - round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true; |
|
| 701 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => round($line['heading']))); |
|
| 702 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading_fromsrc' => true)); |
|
| 703 | 703 | //$dataFound = true; |
| 704 | 704 | } elseif (!isset($this->all_flights[$id]['heading_fromsrc']) && isset($this->all_flights[$id]['archive_latitude']) && $this->all_flights[$id]['archive_latitude'] != $this->all_flights[$id]['latitude'] && isset($this->all_flights[$id]['archive_longitude']) && $this->all_flights[$id]['archive_longitude'] != $this->all_flights[$id]['longitude']) { |
| 705 | - $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']); |
|
| 706 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading))); |
|
| 707 | - if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true; |
|
| 705 | + $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'], $this->all_flights[$id]['archive_longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']); |
|
| 706 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => round($heading))); |
|
| 707 | + if (abs($this->all_flights[$id]['heading'] - round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true; |
|
| 708 | 708 | if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['id']." : ".$heading."\n"; |
| 709 | 709 | } elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') { |
| 710 | 710 | // If not enough messages and ACARS set heading to 0 |
| 711 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0)); |
|
| 711 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => 0)); |
|
| 712 | 712 | } |
| 713 | - if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
|
| 714 | - elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false; |
|
| 715 | - elseif ($globalDaemon === TRUE && isset($globalAircraftMinUpdate) && $globalAircraftMinUpdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalMinupdate) $dataFound = false; |
|
| 713 | + if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
|
| 714 | + elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false; |
|
| 715 | + elseif ($globalDaemon === TRUE && isset($globalAircraftMinUpdate) && $globalAircraftMinUpdate != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalMinupdate) $dataFound = false; |
|
| 716 | 716 | |
| 717 | 717 | // print_r($this->all_flights[$id]); |
| 718 | 718 | //gets the callsign from the last hour |
@@ -723,7 +723,7 @@ discard block |
||
| 723 | 723 | if ($dataFound === true && isset($this->all_flights[$id]['id'])) { |
| 724 | 724 | $this->all_flights[$id]['lastupdate'] = time(); |
| 725 | 725 | if ((!isset($globalNoImport) || $globalNoImport === FALSE) && $this->all_flights[$id]['addedSpotter'] == 0) { |
| 726 | - if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == '' || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
|
| 726 | + if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == '' || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
|
| 727 | 727 | //print_r($this->all_flights); |
| 728 | 728 | //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n"; |
| 729 | 729 | //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']); |
@@ -734,61 +734,61 @@ discard block |
||
| 734 | 734 | $SpotterLive = new SpotterLive($this->db); |
| 735 | 735 | if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) { |
| 736 | 736 | $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']); |
| 737 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 737 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 738 | 738 | } elseif (isset($line['id'])) { |
| 739 | 739 | $recent_ident = $SpotterLive->checkIdRecent($line['id']); |
| 740 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 740 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 741 | 741 | } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') { |
| 742 | 742 | $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']); |
| 743 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 743 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 744 | 744 | } else $recent_ident = ''; |
| 745 | - $SpotterLive->db=null; |
|
| 745 | + $SpotterLive->db = null; |
|
| 746 | 746 | if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
| 747 | 747 | elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
| 748 | 748 | } else $recent_ident = ''; |
| 749 | 749 | } else { |
| 750 | 750 | $recent_ident = ''; |
| 751 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0)); |
|
| 751 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 0)); |
|
| 752 | 752 | } |
| 753 | 753 | //if there was no aircraft with the same callsign within the last hour and go post it into the archive |
| 754 | - if($recent_ident == "") |
|
| 754 | + if ($recent_ident == "") |
|
| 755 | 755 | { |
| 756 | 756 | if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : "; |
| 757 | 757 | if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; } |
| 758 | 758 | if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; } |
| 759 | 759 | //adds the spotter data for the archive |
| 760 | 760 | $ignoreImport = false; |
| 761 | - foreach($globalAirportIgnore as $airportIgnore) { |
|
| 761 | + foreach ($globalAirportIgnore as $airportIgnore) { |
|
| 762 | 762 | if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
| 763 | 763 | $ignoreImport = true; |
| 764 | 764 | } |
| 765 | 765 | } |
| 766 | 766 | if (count($globalAirportAccept) > 0) { |
| 767 | 767 | $ignoreImport = true; |
| 768 | - foreach($globalAirportIgnore as $airportIgnore) { |
|
| 768 | + foreach ($globalAirportIgnore as $airportIgnore) { |
|
| 769 | 769 | if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
| 770 | 770 | $ignoreImport = false; |
| 771 | 771 | } |
| 772 | 772 | } |
| 773 | 773 | } |
| 774 | 774 | if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) { |
| 775 | - foreach($globalAirlineIgnore as $airlineIgnore) { |
|
| 776 | - if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) { |
|
| 775 | + foreach ($globalAirlineIgnore as $airlineIgnore) { |
|
| 776 | + if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineIgnore)) { |
|
| 777 | 777 | $ignoreImport = true; |
| 778 | 778 | } |
| 779 | 779 | } |
| 780 | 780 | } |
| 781 | 781 | if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) { |
| 782 | 782 | $ignoreImport = true; |
| 783 | - foreach($globalAirlineAccept as $airlineAccept) { |
|
| 784 | - if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) { |
|
| 783 | + foreach ($globalAirlineAccept as $airlineAccept) { |
|
| 784 | + if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineAccept)) { |
|
| 785 | 785 | $ignoreImport = false; |
| 786 | 786 | } |
| 787 | 787 | } |
| 788 | 788 | } |
| 789 | 789 | if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) { |
| 790 | 790 | $ignoreImport = true; |
| 791 | - foreach($globalPilotIdAccept as $pilotIdAccept) { |
|
| 791 | + foreach ($globalPilotIdAccept as $pilotIdAccept) { |
|
| 792 | 792 | if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) { |
| 793 | 793 | $ignoreImport = false; |
| 794 | 794 | } |
@@ -800,32 +800,32 @@ discard block |
||
| 800 | 800 | if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack'; |
| 801 | 801 | if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)'; |
| 802 | 802 | if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency'; |
| 803 | - if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
|
| 803 | + if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
|
| 804 | 804 | $timeelapsed = microtime(true); |
| 805 | 805 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
| 806 | 806 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 807 | 807 | $Spotter = new Spotter($this->db); |
| 808 | - $result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['source_type']); |
|
| 808 | + $result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'], $this->all_flights[$id]['route_stop'], $highlight, $this->all_flights[$id]['hex'], $this->all_flights[$id]['registration'], $this->all_flights[$id]['pilot_id'], $this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['format_source'], $this->all_flights[$id]['source_name'], $this->all_flights[$id]['source_type']); |
|
| 809 | 809 | $Spotter->db = null; |
| 810 | 810 | if ($globalDebug && isset($result)) echo $result."\n"; |
| 811 | 811 | } |
| 812 | 812 | } |
| 813 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 813 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 814 | 814 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 815 | 815 | |
| 816 | 816 | // Add source stat in DB |
| 817 | 817 | $Stats = new Stats($this->db); |
| 818 | 818 | if (!empty($this->stats)) { |
| 819 | 819 | if ($globalDebug) echo 'Add source stats : '; |
| 820 | - foreach($this->stats as $date => $data) { |
|
| 821 | - foreach($data as $source => $sourced) { |
|
| 820 | + foreach ($this->stats as $date => $data) { |
|
| 821 | + foreach ($data as $source => $sourced) { |
|
| 822 | 822 | //print_r($sourced); |
| 823 | - if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date); |
|
| 824 | - if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date); |
|
| 823 | + if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']), $source, 'polar', $date); |
|
| 824 | + if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']), $source, 'hist', $date); |
|
| 825 | 825 | if (isset($sourced['msg'])) { |
| 826 | 826 | if (time() - $sourced['msg']['date'] > 10) { |
| 827 | 827 | $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date'])); |
| 828 | - echo $Stats->addStatSource($nbmsg,$source,'msg',$date); |
|
| 828 | + echo $Stats->addStatSource($nbmsg, $source, 'msg', $date); |
|
| 829 | 829 | unset($this->stats[$date][$source]['msg']); |
| 830 | 830 | } |
| 831 | 831 | } |
@@ -863,14 +863,14 @@ discard block |
||
| 863 | 863 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 864 | 864 | $SpotterLive = new SpotterLive($this->db); |
| 865 | 865 | $SpotterLive->deleteLiveSpotterData(); |
| 866 | - $SpotterLive->db=null; |
|
| 866 | + $SpotterLive->db = null; |
|
| 867 | 867 | } |
| 868 | 868 | } |
| 869 | 869 | if ($globalDebug) echo " Done\n"; |
| 870 | 870 | $this->last_delete = time(); |
| 871 | 871 | } |
| 872 | 872 | } else { |
| 873 | - if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt'|| $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'famaprs' || $line['format_source'] === 'airwhere')) { |
|
| 873 | + if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'famaprs' || $line['format_source'] === 'airwhere')) { |
|
| 874 | 874 | $this->all_flights[$id]['id'] = $recent_ident; |
| 875 | 875 | $this->all_flights[$id]['addedSpotter'] = 1; |
| 876 | 876 | } |
@@ -878,7 +878,7 @@ discard block |
||
| 878 | 878 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
| 879 | 879 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 880 | 880 | $Spotter = new Spotter($this->db); |
| 881 | - $Spotter->updateLatestSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time']); |
|
| 881 | + $Spotter->updateLatestSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['arrival_airport_time']); |
|
| 882 | 882 | $Spotter->db = null; |
| 883 | 883 | } |
| 884 | 884 | } |
@@ -904,37 +904,37 @@ discard block |
||
| 904 | 904 | if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; } |
| 905 | 905 | if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; } |
| 906 | 906 | |
| 907 | - foreach($globalAirportIgnore as $airportIgnore) { |
|
| 907 | + foreach ($globalAirportIgnore as $airportIgnore) { |
|
| 908 | 908 | if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
| 909 | 909 | $ignoreImport = true; |
| 910 | 910 | } |
| 911 | 911 | } |
| 912 | 912 | if (count($globalAirportAccept) > 0) { |
| 913 | 913 | $ignoreImport = true; |
| 914 | - foreach($globalAirportIgnore as $airportIgnore) { |
|
| 914 | + foreach ($globalAirportIgnore as $airportIgnore) { |
|
| 915 | 915 | if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
| 916 | 916 | $ignoreImport = false; |
| 917 | 917 | } |
| 918 | 918 | } |
| 919 | 919 | } |
| 920 | 920 | if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) { |
| 921 | - foreach($globalAirlineIgnore as $airlineIgnore) { |
|
| 922 | - if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) { |
|
| 921 | + foreach ($globalAirlineIgnore as $airlineIgnore) { |
|
| 922 | + if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineIgnore)) { |
|
| 923 | 923 | $ignoreImport = true; |
| 924 | 924 | } |
| 925 | 925 | } |
| 926 | 926 | } |
| 927 | 927 | if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) { |
| 928 | 928 | $ignoreImport = true; |
| 929 | - foreach($globalAirlineAccept as $airlineAccept) { |
|
| 930 | - if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) { |
|
| 929 | + foreach ($globalAirlineAccept as $airlineAccept) { |
|
| 930 | + if ((is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 4), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'], 0, 3), -1, 1)) && substr($this->all_flights[$id]['ident'], 0, 2) == $airlineAccept)) { |
|
| 931 | 931 | $ignoreImport = false; |
| 932 | 932 | } |
| 933 | 933 | } |
| 934 | 934 | } |
| 935 | 935 | if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) { |
| 936 | 936 | $ignoreImport = true; |
| 937 | - foreach($globalPilotIdAccept as $pilotIdAccept) { |
|
| 937 | + foreach ($globalPilotIdAccept as $pilotIdAccept) { |
|
| 938 | 938 | if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) { |
| 939 | 939 | $ignoreImport = false; |
| 940 | 940 | } |
@@ -942,23 +942,23 @@ discard block |
||
| 942 | 942 | } |
| 943 | 943 | |
| 944 | 944 | if (!$ignoreImport) { |
| 945 | - if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
|
| 946 | - if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
|
| 945 | + if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
|
| 946 | + if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
|
| 947 | 947 | $timeelapsed = microtime(true); |
| 948 | 948 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
| 949 | 949 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 950 | 950 | if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : "; |
| 951 | 951 | $SpotterLive = new SpotterLive($this->db); |
| 952 | - $result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']); |
|
| 952 | + $result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'], $this->all_flights[$id]['route_stop'], $this->all_flights[$id]['hex'], $this->all_flights[$id]['putinarchive'], $this->all_flights[$id]['registration'], $this->all_flights[$id]['pilot_id'], $this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['format_source'], $this->all_flights[$id]['source_name'], $this->all_flights[$id]['over_country']); |
|
| 953 | 953 | $SpotterLive->db = null; |
| 954 | 954 | if ($globalDebug) echo $result."\n"; |
| 955 | 955 | } |
| 956 | 956 | } |
| 957 | 957 | if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_flights[$id]['putinarchive']) { |
| 958 | - $APRSSpotter->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']); |
|
| 958 | + $APRSSpotter->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'], $this->all_flights[$id]['route_stop'], $this->all_flights[$id]['hex'], $this->all_flights[$id]['putinarchive'], $this->all_flights[$id]['registration'], $this->all_flights[$id]['pilot_id'], $this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['format_source'], $this->all_flights[$id]['source_name'], $this->all_flights[$id]['over_country']); |
|
| 959 | 959 | } |
| 960 | 960 | $this->all_flights[$id]['putinarchive'] = false; |
| 961 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 961 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 962 | 962 | |
| 963 | 963 | // Put statistics in $this->stats variable |
| 964 | 964 | //if ($line['format_source'] != 'aprs') { |
@@ -977,19 +977,19 @@ discard block |
||
| 977 | 977 | $latitude = $globalCenterLatitude; |
| 978 | 978 | $longitude = $globalCenterLongitude; |
| 979 | 979 | } |
| 980 | - $this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude); |
|
| 980 | + $this->source_location[$source] = array('latitude' => $latitude, 'longitude' => $longitude); |
|
| 981 | 981 | } else { |
| 982 | 982 | $latitude = $this->source_location[$source]['latitude']; |
| 983 | 983 | $longitude = $this->source_location[$source]['longitude']; |
| 984 | 984 | } |
| 985 | - $stats_heading = $Common->getHeading($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']); |
|
| 985 | + $stats_heading = $Common->getHeading($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']); |
|
| 986 | 986 | //$stats_heading = $stats_heading%22.5; |
| 987 | 987 | $stats_heading = round($stats_heading/22.5); |
| 988 | - $stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']); |
|
| 988 | + $stats_distance = $Common->distance($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']); |
|
| 989 | 989 | $current_date = date('Y-m-d'); |
| 990 | 990 | if ($stats_heading == 16) $stats_heading = 0; |
| 991 | 991 | if (!isset($this->stats[$current_date][$source]['polar'][1])) { |
| 992 | - for ($i=0;$i<=15;$i++) { |
|
| 992 | + for ($i = 0; $i <= 15; $i++) { |
|
| 993 | 993 | $this->stats[$current_date][$source]['polar'][$i] = 0; |
| 994 | 994 | } |
| 995 | 995 | $this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance; |
@@ -1004,9 +1004,9 @@ discard block |
||
| 1004 | 1004 | if (!isset($this->stats[$current_date][$source]['hist'][$distance])) { |
| 1005 | 1005 | if (isset($this->stats[$current_date][$source]['hist'][0])) { |
| 1006 | 1006 | end($this->stats[$current_date][$source]['hist']); |
| 1007 | - $mini = key($this->stats[$current_date][$source]['hist'])+10; |
|
| 1007 | + $mini = key($this->stats[$current_date][$source]['hist']) + 10; |
|
| 1008 | 1008 | } else $mini = 0; |
| 1009 | - for ($i=$mini;$i<=$distance;$i+=10) { |
|
| 1009 | + for ($i = $mini; $i <= $distance; $i += 10) { |
|
| 1010 | 1010 | $this->stats[$current_date][$source]['hist'][$i] = 0; |
| 1011 | 1011 | } |
| 1012 | 1012 | $this->stats[$current_date][$source]['hist'][$distance] = 1; |
@@ -1019,7 +1019,7 @@ discard block |
||
| 1019 | 1019 | $this->all_flights[$id]['lastupdate'] = time(); |
| 1020 | 1020 | if ($this->all_flights[$id]['putinarchive']) $send = true; |
| 1021 | 1021 | //if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
| 1022 | - } elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
|
| 1022 | + } elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude'])."\n"; |
|
| 1023 | 1023 | //$this->del(); |
| 1024 | 1024 | |
| 1025 | 1025 | if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) { |
@@ -63,7 +63,9 @@ discard block |
||
| 63 | 63 | $dbc = $this->db; |
| 64 | 64 | $this->all_flights[$id]['schedule_check'] = true; |
| 65 | 65 | if ($globalSchedulesFetch) { |
| 66 | - if ($globalDebug) echo 'Getting schedule info...'."\n"; |
|
| 66 | + if ($globalDebug) { |
|
| 67 | + echo 'Getting schedule info...'."\n"; |
|
| 68 | + } |
|
| 67 | 69 | $Spotter = new Spotter($dbc); |
| 68 | 70 | $Schedule = new Schedule($dbc); |
| 69 | 71 | $Translation = new Translation($dbc); |
@@ -74,7 +76,9 @@ discard block |
||
| 74 | 76 | if ($Schedule->checkSchedule($operator) == 0) { |
| 75 | 77 | $schedule = $Schedule->fetchSchedule($operator); |
| 76 | 78 | if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) { |
| 77 | - if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n"; |
|
| 79 | + if ($globalDebug) { |
|
| 80 | + echo "-> Schedule info for ".$operator." (".$ident.")\n"; |
|
| 81 | + } |
|
| 78 | 82 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime'])); |
| 79 | 83 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime'])); |
| 80 | 84 | // Should also check if route schedule = route from DB |
@@ -83,7 +87,9 @@ discard block |
||
| 83 | 87 | $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']); |
| 84 | 88 | if (trim($airport_icao) != '') { |
| 85 | 89 | $this->all_flights[$id]['departure_airport'] = $airport_icao; |
| 86 | - if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n"; |
|
| 90 | + if ($globalDebug) { |
|
| 91 | + echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n"; |
|
| 92 | + } |
|
| 87 | 93 | } |
| 88 | 94 | } |
| 89 | 95 | } |
@@ -92,17 +98,25 @@ discard block |
||
| 92 | 98 | $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']); |
| 93 | 99 | if (trim($airport_icao) != '') { |
| 94 | 100 | $this->all_flights[$id]['arrival_airport'] = $airport_icao; |
| 95 | - if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n"; |
|
| 101 | + if ($globalDebug) { |
|
| 102 | + echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n"; |
|
| 103 | + } |
|
| 96 | 104 | } |
| 97 | 105 | } |
| 98 | 106 | } |
| 99 | 107 | $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']); |
| 100 | 108 | } |
| 101 | - } else $scheduleexist = true; |
|
| 102 | - } else $scheduleexist = true; |
|
| 109 | + } else { |
|
| 110 | + $scheduleexist = true; |
|
| 111 | + } |
|
| 112 | + } else { |
|
| 113 | + $scheduleexist = true; |
|
| 114 | + } |
|
| 103 | 115 | // close connection, at least one way will work ? |
| 104 | 116 | if ($scheduleexist) { |
| 105 | - if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n"; |
|
| 117 | + if ($globalDebug) { |
|
| 118 | + echo "-> get arrival/departure airport info for ".$ident."\n"; |
|
| 119 | + } |
|
| 106 | 120 | $sch = $Schedule->getSchedule($operator); |
| 107 | 121 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time'])); |
| 108 | 122 | } |
@@ -124,14 +138,18 @@ discard block |
||
| 124 | 138 | |
| 125 | 139 | public function checkAll() { |
| 126 | 140 | global $globalDebug, $globalNoImport; |
| 127 | - if ($globalDebug) echo "Update last seen flights data...\n"; |
|
| 141 | + if ($globalDebug) { |
|
| 142 | + echo "Update last seen flights data...\n"; |
|
| 143 | + } |
|
| 128 | 144 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
| 129 | 145 | foreach ($this->all_flights as $key => $flight) { |
| 130 | 146 | if (isset($this->all_flights[$key]['id'])) { |
| 131 | 147 | //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].' '.$this->all_flights[$key]['longitude']."\n"; |
| 132 | 148 | $Spotter = new Spotter($this->db); |
| 133 | 149 | $real_arrival = $this->arrival($key); |
| 134 | - if (isset($this->all_flights[$key]['altitude'])) $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']); |
|
| 150 | + if (isset($this->all_flights[$key]['altitude'])) { |
|
| 151 | + $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']); |
|
| 152 | + } |
|
| 135 | 153 | } |
| 136 | 154 | } |
| 137 | 155 | } |
@@ -139,24 +157,32 @@ discard block |
||
| 139 | 157 | |
| 140 | 158 | public function arrival($key) { |
| 141 | 159 | global $globalClosestMinDist, $globalDebug; |
| 142 | - if ($globalDebug) echo 'Update arrival...'."\n"; |
|
| 160 | + if ($globalDebug) { |
|
| 161 | + echo 'Update arrival...'."\n"; |
|
| 162 | + } |
|
| 143 | 163 | $Spotter = new Spotter($this->db); |
| 144 | 164 | $airport_icao = ''; |
| 145 | 165 | $airport_time = ''; |
| 146 | - if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50; |
|
| 166 | + if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') { |
|
| 167 | + $globalClosestMinDist = 50; |
|
| 168 | + } |
|
| 147 | 169 | if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') { |
| 148 | 170 | $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist); |
| 149 | 171 | if (isset($closestAirports[0])) { |
| 150 | 172 | if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) { |
| 151 | 173 | $airport_icao = $closestAirports[0]['icao']; |
| 152 | 174 | $airport_time = $this->all_flights[$key]['datetime']; |
| 153 | - if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
| 175 | + if ($globalDebug) { |
|
| 176 | + echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
| 177 | + } |
|
| 154 | 178 | } elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') { |
| 155 | 179 | foreach ($closestAirports as $airport) { |
| 156 | 180 | if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) { |
| 157 | 181 | $airport_icao = $airport['icao']; |
| 158 | 182 | $airport_time = $this->all_flights[$key]['datetime']; |
| 159 | - if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
| 183 | + if ($globalDebug) { |
|
| 184 | + echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
| 185 | + } |
|
| 160 | 186 | break; |
| 161 | 187 | } |
| 162 | 188 | } |
@@ -164,14 +190,20 @@ discard block |
||
| 164 | 190 | $airport_icao = $closestAirports[0]['icao']; |
| 165 | 191 | $airport_time = $this->all_flights[$key]['datetime']; |
| 166 | 192 | } else { |
| 167 | - if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n"; |
|
| 193 | + if ($globalDebug) { |
|
| 194 | + echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n"; |
|
| 195 | + } |
|
| 168 | 196 | } |
| 169 | 197 | } else { |
| 170 | - if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n"; |
|
| 198 | + if ($globalDebug) { |
|
| 199 | + echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n"; |
|
| 200 | + } |
|
| 171 | 201 | } |
| 172 | 202 | |
| 173 | 203 | } else { |
| 174 | - if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n"; |
|
| 204 | + if ($globalDebug) { |
|
| 205 | + echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n"; |
|
| 206 | + } |
|
| 175 | 207 | } |
| 176 | 208 | return array('airport_icao' => $airport_icao,'airport_time' => $airport_time); |
| 177 | 209 | } |
@@ -181,7 +213,9 @@ discard block |
||
| 181 | 213 | public function del() { |
| 182 | 214 | global $globalDebug, $globalNoImport, $globalNoDB; |
| 183 | 215 | // Delete old infos |
| 184 | - if ($globalDebug) echo 'Delete old values and update latest data...'."\n"; |
|
| 216 | + if ($globalDebug) { |
|
| 217 | + echo 'Delete old values and update latest data...'."\n"; |
|
| 218 | + } |
|
| 185 | 219 | foreach ($this->all_flights as $key => $flight) { |
| 186 | 220 | if (isset($flight['lastupdate'])) { |
| 187 | 221 | if ($flight['lastupdate'] < (time()-5900)) { |
@@ -195,13 +229,17 @@ discard block |
||
| 195 | 229 | global $globalDebug, $globalNoImport, $globalNoDB; |
| 196 | 230 | // Delete old infos |
| 197 | 231 | if (isset($this->all_flights[$key]['id'])) { |
| 198 | - if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n"; |
|
| 232 | + if ($globalDebug) { |
|
| 233 | + echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n"; |
|
| 234 | + } |
|
| 199 | 235 | if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) { |
| 200 | 236 | $real_arrival = $this->arrival($key); |
| 201 | 237 | $Spotter = new Spotter($this->db); |
| 202 | 238 | if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') { |
| 203 | 239 | $result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']); |
| 204 | - if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
|
| 240 | + if ($globalDebug && $result != 'success') { |
|
| 241 | + echo '!!! ERROR : '.$result."\n"; |
|
| 242 | + } |
|
| 205 | 243 | } |
| 206 | 244 | } |
| 207 | 245 | } |
@@ -211,9 +249,13 @@ discard block |
||
| 211 | 249 | public function add($line) { |
| 212 | 250 | global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights, $globalServerAPRS, $APRSSpotter, $globalNoImport, $globalNoDB, $globalVA, $globalAircraftMaxUpdate, $globalAircraftMinUpdate, $globalLiveInterval; |
| 213 | 251 | //if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE; |
| 214 | - if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02'; |
|
| 215 | - if (!isset($globalAircraftMaxUpdate) || $globalAircraftMaxUpdate == '') $globalAircraftMaxUpdate = 3000; |
|
| 216 | -/* |
|
| 252 | + if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') { |
|
| 253 | + $globalCoordMinChange = '0.02'; |
|
| 254 | + } |
|
| 255 | + if (!isset($globalAircraftMaxUpdate) || $globalAircraftMaxUpdate == '') { |
|
| 256 | + $globalAircraftMaxUpdate = 3000; |
|
| 257 | + } |
|
| 258 | + /* |
|
| 217 | 259 | $Spotter = new Spotter(); |
| 218 | 260 | $dbc = $Spotter->db; |
| 219 | 261 | $SpotterLive = new SpotterLive($dbc); |
@@ -235,19 +277,28 @@ discard block |
||
| 235 | 277 | // SBS format is CSV format |
| 236 | 278 | if(is_array($line) && (isset($line['hex']) || isset($line['id']))) { |
| 237 | 279 | //print_r($line); |
| 238 | - if (isset($line['hex'])) $line['hex'] = strtoupper($line['hex']); |
|
| 280 | + if (isset($line['hex'])) { |
|
| 281 | + $line['hex'] = strtoupper($line['hex']); |
|
| 282 | + } |
|
| 239 | 283 | if (isset($line['id']) || (isset($line['hex']) && $line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6)) { |
| 240 | 284 | |
| 241 | 285 | // Increment message number |
| 242 | 286 | if (isset($line['sourcestats']) && $line['sourcestats'] === TRUE) { |
| 243 | 287 | $current_date = date('Y-m-d'); |
| 244 | - if (isset($line['source_name'])) $source = $line['source_name']; |
|
| 245 | - else $source = ''; |
|
| 246 | - if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source']; |
|
| 288 | + if (isset($line['source_name'])) { |
|
| 289 | + $source = $line['source_name']; |
|
| 290 | + } else { |
|
| 291 | + $source = ''; |
|
| 292 | + } |
|
| 293 | + if ($source == '' || $line['format_source'] == 'aprs') { |
|
| 294 | + $source = $line['format_source']; |
|
| 295 | + } |
|
| 247 | 296 | if (!isset($this->stats[$current_date][$source]['msg'])) { |
| 248 | 297 | $this->stats[$current_date][$source]['msg']['date'] = time(); |
| 249 | 298 | $this->stats[$current_date][$source]['msg']['nb'] = 1; |
| 250 | - } else $this->stats[$current_date][$source]['msg']['nb'] += 1; |
|
| 299 | + } else { |
|
| 300 | + $this->stats[$current_date][$source]['msg']['nb'] += 1; |
|
| 301 | + } |
|
| 251 | 302 | } |
| 252 | 303 | |
| 253 | 304 | /* |
@@ -263,23 +314,38 @@ discard block |
||
| 263 | 314 | //$this->db = $dbc; |
| 264 | 315 | |
| 265 | 316 | //$hex = trim($line['hex']); |
| 266 | - if (!isset($line['id'])) $id = trim($line['hex']); |
|
| 267 | - else $id = trim($line['id']); |
|
| 317 | + if (!isset($line['id'])) { |
|
| 318 | + $id = trim($line['hex']); |
|
| 319 | + } else { |
|
| 320 | + $id = trim($line['id']); |
|
| 321 | + } |
|
| 268 | 322 | |
| 269 | 323 | if (!isset($this->all_flights[$id])) { |
| 270 | - if ($globalDebug) echo 'New flight...'."\n"; |
|
| 324 | + if ($globalDebug) { |
|
| 325 | + echo 'New flight...'."\n"; |
|
| 326 | + } |
|
| 271 | 327 | $this->all_flights[$id] = array(); |
| 272 | 328 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
| 273 | 329 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '','altitude_previous' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true,'source_type' => '')); |
| 274 | - if (isset($globalDaemon) && $globalDaemon === FALSE) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time())); |
|
| 330 | + if (isset($globalDaemon) && $globalDaemon === FALSE) { |
|
| 331 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time())); |
|
| 332 | + } |
|
| 275 | 333 | if (!isset($line['id'])) { |
| 276 | - if (!isset($globalDaemon)) $globalDaemon = TRUE; |
|
| 277 | -// if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi'))); |
|
| 334 | + if (!isset($globalDaemon)) { |
|
| 335 | + $globalDaemon = TRUE; |
|
| 336 | + } |
|
| 337 | + // if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi'))); |
|
| 278 | 338 | // if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
| 279 | - if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
| 339 | + if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) { |
|
| 340 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
| 341 | + } |
|
| 280 | 342 | //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
| 281 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 282 | - if ($globalAllFlights !== FALSE) $dataFound = true; |
|
| 343 | + } else { |
|
| 344 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 345 | + } |
|
| 346 | + if ($globalAllFlights !== FALSE) { |
|
| 347 | + $dataFound = true; |
|
| 348 | + } |
|
| 283 | 349 | } |
| 284 | 350 | if (isset($line['source_type']) && $line['source_type'] != '') { |
| 285 | 351 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_type' => $line['source_type'])); |
@@ -301,12 +367,20 @@ discard block |
||
| 301 | 367 | $aircraft_icao = $Spotter->getAllAircraftType(trim($line['hex'])); |
| 302 | 368 | } |
| 303 | 369 | $Spotter->db = null; |
| 304 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 305 | - if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
| 370 | + if ($globalDebugTimeElapsed) { |
|
| 371 | + echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 372 | + } |
|
| 373 | + if ($aircraft_icao != '') { |
|
| 374 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
| 375 | + } |
|
| 306 | 376 | } |
| 307 | 377 | } |
| 308 | - if ($globalAllFlights !== FALSE) $dataFound = true; |
|
| 309 | - if ($globalDebug) echo "*********** New aircraft hex : ".$line['hex']." ***********\n"; |
|
| 378 | + if ($globalAllFlights !== FALSE) { |
|
| 379 | + $dataFound = true; |
|
| 380 | + } |
|
| 381 | + if ($globalDebug) { |
|
| 382 | + echo "*********** New aircraft hex : ".$line['hex']." ***********\n"; |
|
| 383 | + } |
|
| 310 | 384 | } |
| 311 | 385 | if (isset($line['id']) && !isset($line['hex'])) { |
| 312 | 386 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('hex' => '')); |
@@ -314,7 +388,9 @@ discard block |
||
| 314 | 388 | if (isset($line['aircraft_icao']) && $line['aircraft_icao'] != '') { |
| 315 | 389 | $icao = $line['aircraft_icao']; |
| 316 | 390 | $Spotter = new Spotter($this->db); |
| 317 | - if (isset($Spotter->aircraft_correct_icaotype[$icao])) $icao = $Spotter->aircraft_correct_icaotype[$icao]; |
|
| 391 | + if (isset($Spotter->aircraft_correct_icaotype[$icao])) { |
|
| 392 | + $icao = $Spotter->aircraft_correct_icaotype[$icao]; |
|
| 393 | + } |
|
| 318 | 394 | $Spotter->db = null; |
| 319 | 395 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $icao)); |
| 320 | 396 | } |
@@ -324,15 +400,24 @@ discard block |
||
| 324 | 400 | $Spotter = new Spotter($this->db); |
| 325 | 401 | $aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']); |
| 326 | 402 | $Spotter->db = null; |
| 327 | - if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
| 403 | + if ($aircraft_icao != '') { |
|
| 404 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
| 405 | + } |
|
| 328 | 406 | } |
| 329 | 407 | } |
| 330 | 408 | if (!isset($this->all_flights[$id]['aircraft_icao']) && isset($line['aircraft_type'])) { |
| 331 | - if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID'; |
|
| 332 | - elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL'; |
|
| 333 | - elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE'; |
|
| 334 | - elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC'; |
|
| 335 | - if (isset($aircraft_icao)) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
| 409 | + if ($line['aircraft_type'] == 'PARA_GLIDER') { |
|
| 410 | + $aircraft_icao = 'GLID'; |
|
| 411 | + } elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') { |
|
| 412 | + $aircraft_icao = 'UHEL'; |
|
| 413 | + } elseif ($line['aircraft_type'] == 'TOW_PLANE') { |
|
| 414 | + $aircraft_icao = 'TOWPLANE'; |
|
| 415 | + } elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') { |
|
| 416 | + $aircraft_icao = 'POWAIRC'; |
|
| 417 | + } |
|
| 418 | + if (isset($aircraft_icao)) { |
|
| 419 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
| 420 | + } |
|
| 336 | 421 | } |
| 337 | 422 | if (!isset($this->all_flights[$id]['aircraft_icao'])) { |
| 338 | 423 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA')); |
@@ -342,8 +427,11 @@ discard block |
||
| 342 | 427 | if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) { |
| 343 | 428 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime'])); |
| 344 | 429 | } else { |
| 345 | - if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n"; |
|
| 346 | - elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n"; |
|
| 430 | + if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) { |
|
| 431 | + echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n"; |
|
| 432 | + } elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) { |
|
| 433 | + echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n"; |
|
| 434 | + } |
|
| 347 | 435 | /* |
| 348 | 436 | echo strtotime($line['datetime']).' > '.strtotime($this->all_flights[$id]['datetime']); |
| 349 | 437 | print_r($this->all_flights[$id]); |
@@ -352,17 +440,23 @@ discard block |
||
| 352 | 440 | return ''; |
| 353 | 441 | } |
| 354 | 442 | } elseif (isset($line['datetime']) && strtotime($line['datetime']) < time()-20*60) { |
| 355 | - if ($globalDebug) echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n"; |
|
| 443 | + if ($globalDebug) { |
|
| 444 | + echo "!!! Date is too old ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n"; |
|
| 445 | + } |
|
| 356 | 446 | return ''; |
| 357 | 447 | } elseif (isset($line['datetime']) && strtotime($line['datetime']) > time()+20*60) { |
| 358 | - if ($globalDebug) echo "!!! Date is in the future ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n |
|
| 448 | + if ($globalDebug) { |
|
| 449 | + echo "!!! Date is in the future ".$line['datetime']." for ".$this->all_flights[$id]['id']." - format : ".$line['format_source']."!!!\n |
|
| 359 | 450 | "; |
| 451 | + } |
|
| 360 | 452 | return ''; |
| 361 | 453 | } elseif (!isset($line['datetime'])) { |
| 362 | 454 | date_default_timezone_set('UTC'); |
| 363 | 455 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s'))); |
| 364 | 456 | } else { |
| 365 | - if ($globalDebug) echo "!!! Unknow date error ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!"; |
|
| 457 | + if ($globalDebug) { |
|
| 458 | + echo "!!! Unknow date error ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."!!!"; |
|
| 459 | + } |
|
| 366 | 460 | return ''; |
| 367 | 461 | } |
| 368 | 462 | |
@@ -383,30 +477,48 @@ discard block |
||
| 383 | 477 | |
| 384 | 478 | if ($this->all_flights[$id]['addedSpotter'] == 1) { |
| 385 | 479 | if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE && $this->all_flights[$id]['lastupdate'] < time() - 1600) { |
| 386 | - if ($globalDebug) echo '---!!!! New ident, reset aircraft data...'."\n"; |
|
| 480 | + if ($globalDebug) { |
|
| 481 | + echo '---!!!! New ident, reset aircraft data...'."\n"; |
|
| 482 | + } |
|
| 387 | 483 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
| 388 | 484 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1)); |
| 389 | - if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
| 390 | - elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 391 | - elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 485 | + if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) { |
|
| 486 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
| 487 | + } elseif (isset($line['id'])) { |
|
| 488 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 489 | + } elseif (isset($this->all_flights[$id]['ident'])) { |
|
| 490 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 491 | + } |
|
| 392 | 492 | } else { |
| 393 | 493 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident']))); |
| 394 | 494 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 395 | 495 | $timeelapsed = microtime(true); |
| 396 | 496 | $Spotter = new Spotter($this->db); |
| 397 | 497 | $fromsource = NULL; |
| 398 | - if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource; |
|
| 399 | - elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim'; |
|
| 400 | - elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao'; |
|
| 401 | - elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim'; |
|
| 402 | - elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao'; |
|
| 498 | + if (isset($globalAirlinesSource) && $globalAirlinesSource != '') { |
|
| 499 | + $fromsource = $globalAirlinesSource; |
|
| 500 | + } elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') { |
|
| 501 | + $fromsource = 'vatsim'; |
|
| 502 | + } elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') { |
|
| 503 | + $fromsource = 'ivao'; |
|
| 504 | + } elseif (isset($globalVATSIM) && $globalVATSIM) { |
|
| 505 | + $fromsource = 'vatsim'; |
|
| 506 | + } elseif (isset($globalIVAO) && $globalIVAO) { |
|
| 507 | + $fromsource = 'ivao'; |
|
| 508 | + } |
|
| 403 | 509 | $result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource); |
| 404 | - if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
|
| 510 | + if ($globalDebug && $result != 'success') { |
|
| 511 | + echo '!!! ERROR : '.$result."\n"; |
|
| 512 | + } |
|
| 405 | 513 | $Spotter->db = null; |
| 406 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 514 | + if ($globalDebugTimeElapsed) { |
|
| 515 | + echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 516 | + } |
|
| 407 | 517 | } |
| 408 | 518 | } |
| 409 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident']))); |
|
| 519 | + } else { |
|
| 520 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident']))); |
|
| 521 | + } |
|
| 410 | 522 | |
| 411 | 523 | /* |
| 412 | 524 | if (!isset($line['id'])) { |
@@ -416,7 +528,9 @@ discard block |
||
| 416 | 528 | else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
| 417 | 529 | } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
| 418 | 530 | */ |
| 419 | - if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 531 | + if (!isset($this->all_flights[$id]['id'])) { |
|
| 532 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 533 | + } |
|
| 420 | 534 | |
| 421 | 535 | //$putinarchive = true; |
| 422 | 536 | if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) { |
@@ -434,7 +548,9 @@ discard block |
||
| 434 | 548 | $line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']); |
| 435 | 549 | $line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']); |
| 436 | 550 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => '')); |
| 437 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 551 | + if ($globalDebugTimeElapsed) { |
|
| 552 | + echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 553 | + } |
|
| 438 | 554 | } |
| 439 | 555 | } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') { |
| 440 | 556 | $timeelapsed = microtime(true); |
@@ -448,7 +564,9 @@ discard block |
||
| 448 | 564 | $Translation->db = null; |
| 449 | 565 | } |
| 450 | 566 | $Spotter->db = null; |
| 451 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 567 | + if ($globalDebugTimeElapsed) { |
|
| 568 | + echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 569 | + } |
|
| 452 | 570 | } |
| 453 | 571 | if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) { |
| 454 | 572 | //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) { |
@@ -457,9 +575,13 @@ discard block |
||
| 457 | 575 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop'])); |
| 458 | 576 | } |
| 459 | 577 | } |
| 460 | - if (!isset($globalFork)) $globalFork = TRUE; |
|
| 578 | + if (!isset($globalFork)) { |
|
| 579 | + $globalFork = TRUE; |
|
| 580 | + } |
|
| 461 | 581 | if (!$globalVA && !$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) { |
| 462 | - if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident'])); |
|
| 582 | + if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) { |
|
| 583 | + $this->get_Schedule($id,trim($line['ident'])); |
|
| 584 | + } |
|
| 463 | 585 | } |
| 464 | 586 | } |
| 465 | 587 | } |
@@ -475,8 +597,12 @@ discard block |
||
| 475 | 597 | // use datetime |
| 476 | 598 | $speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']); |
| 477 | 599 | $speed = $speed*3.6; |
| 478 | - if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed))); |
|
| 479 | - if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n"; |
|
| 600 | + if ($speed < 1000) { |
|
| 601 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed))); |
|
| 602 | + } |
|
| 603 | + if ($globalDebug) { |
|
| 604 | + echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".round($speed)." - distance : ".$distance."\n"; |
|
| 605 | + } |
|
| 480 | 606 | } |
| 481 | 607 | } |
| 482 | 608 | |
@@ -484,13 +610,21 @@ discard block |
||
| 484 | 610 | |
| 485 | 611 | if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
| 486 | 612 | if (ctype_digit(strval($line['latitude'])) || ctype_digit(strval($line['longitude']))) { |
| 487 | - if ($globalDebug) echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n"; |
|
| 613 | + if ($globalDebug) { |
|
| 614 | + echo "/!\ Invalid latitude or/and longitude data : lat: ".$line['latitude']." - lng: ".$line['longitude']."\n"; |
|
| 615 | + } |
|
| 488 | 616 | return false; |
| 489 | 617 | } |
| 490 | - if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']); |
|
| 491 | - else unset($timediff); |
|
| 492 | - if (isset($this->all_flights[$id]['time_last_archive_coord'])) $timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']); |
|
| 493 | - else unset($timediff_archive); |
|
| 618 | + if (isset($this->all_flights[$id]['time_last_coord'])) { |
|
| 619 | + $timediff = round(time()-$this->all_flights[$id]['time_last_coord']); |
|
| 620 | + } else { |
|
| 621 | + unset($timediff); |
|
| 622 | + } |
|
| 623 | + if (isset($this->all_flights[$id]['time_last_archive_coord'])) { |
|
| 624 | + $timediff_archive = round(time()-$this->all_flights[$id]['time_last_archive_coord']); |
|
| 625 | + } else { |
|
| 626 | + unset($timediff_archive); |
|
| 627 | + } |
|
| 494 | 628 | if ($this->tmd > 5 |
| 495 | 629 | || (isset($line['format_source']) |
| 496 | 630 | && $line['format_source'] == 'airwhere' |
@@ -526,16 +660,25 @@ discard block |
||
| 526 | 660 | $this->all_flights[$id]['putinarchive'] = true; |
| 527 | 661 | $this->tmd = 0; |
| 528 | 662 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
| 529 | - if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
|
| 663 | + if ($globalDebug) { |
|
| 664 | + echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
|
| 665 | + } |
|
| 530 | 666 | $timeelapsed = microtime(true); |
| 531 | 667 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 532 | 668 | $Spotter = new Spotter($this->db); |
| 533 | 669 | $all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
| 534 | - if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2']; |
|
| 535 | - else $this->all_flights[$id]['over_country'] = ''; |
|
| 670 | + if (!empty($all_country)) { |
|
| 671 | + $this->all_flights[$id]['over_country'] = $all_country['iso2']; |
|
| 672 | + } else { |
|
| 673 | + $this->all_flights[$id]['over_country'] = ''; |
|
| 674 | + } |
|
| 536 | 675 | $Spotter->db = null; |
| 537 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 538 | - if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n"; |
|
| 676 | + if ($globalDebugTimeElapsed) { |
|
| 677 | + echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 678 | + } |
|
| 679 | + if ($globalDebug) { |
|
| 680 | + echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n"; |
|
| 681 | + } |
|
| 539 | 682 | } |
| 540 | 683 | } |
| 541 | 684 | $this->all_flights[$id]['time_last_archive_coord'] = time(); |
@@ -581,7 +724,9 @@ discard block |
||
| 581 | 724 | */ |
| 582 | 725 | } |
| 583 | 726 | if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) { |
| 584 | - if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
|
| 727 | + if ($line['longitude'] > 180) { |
|
| 728 | + $line['longitude'] = $line['longitude'] - 360; |
|
| 729 | + } |
|
| 585 | 730 | //if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == '' || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) { |
| 586 | 731 | if (!isset($this->all_flights[$id]['archive_longitude'])) { |
| 587 | 732 | $this->all_flights[$id]['archive_longitude'] = $line['longitude']; |
@@ -618,7 +763,9 @@ discard block |
||
| 618 | 763 | } |
| 619 | 764 | } |
| 620 | 765 | if (isset($line['last_update']) && $line['last_update'] != '') { |
| 621 | - if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true; |
|
| 766 | + if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) { |
|
| 767 | + $dataFound = true; |
|
| 768 | + } |
|
| 622 | 769 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update'])); |
| 623 | 770 | } |
| 624 | 771 | if (isset($line['verticalrate']) && $line['verticalrate'] != '') { |
@@ -640,53 +787,79 @@ discard block |
||
| 640 | 787 | // Here we force archive of flight because after ground it's a new one (or should be) |
| 641 | 788 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
| 642 | 789 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1)); |
| 643 | - if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
| 644 | - elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 645 | - elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 790 | + if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) { |
|
| 791 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
| 792 | + } elseif (isset($line['id'])) { |
|
| 793 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 794 | + } elseif (isset($this->all_flights[$id]['ident'])) { |
|
| 795 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 796 | + } |
|
| 797 | + } |
|
| 798 | + if ($line['ground'] != 1) { |
|
| 799 | + $line['ground'] = 0; |
|
| 646 | 800 | } |
| 647 | - if ($line['ground'] != 1) $line['ground'] = 0; |
|
| 648 | 801 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground'])); |
| 649 | 802 | //$dataFound = true; |
| 650 | 803 | } |
| 651 | 804 | if (isset($line['squawk']) && $line['squawk'] != '') { |
| 652 | 805 | if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) { |
| 653 | - if ($this->all_flights[$id]['squawk'] != $line['squawk']) $this->all_flights[$id]['putinarchive'] = true; |
|
| 806 | + if ($this->all_flights[$id]['squawk'] != $line['squawk']) { |
|
| 807 | + $this->all_flights[$id]['putinarchive'] = true; |
|
| 808 | + } |
|
| 654 | 809 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
| 655 | 810 | $highlight = ''; |
| 656 | - if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC'; |
|
| 657 | - if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC'; |
|
| 658 | - if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC'; |
|
| 811 | + if ($this->all_flights[$id]['squawk'] == '7500') { |
|
| 812 | + $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC'; |
|
| 813 | + } |
|
| 814 | + if ($this->all_flights[$id]['squawk'] == '7600') { |
|
| 815 | + $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC'; |
|
| 816 | + } |
|
| 817 | + if ($this->all_flights[$id]['squawk'] == '7700') { |
|
| 818 | + $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC'; |
|
| 819 | + } |
|
| 659 | 820 | if ($highlight != '') { |
| 660 | 821 | $timeelapsed = microtime(true); |
| 661 | 822 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 662 | 823 | $Spotter = new Spotter($this->db); |
| 663 | 824 | $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight); |
| 664 | 825 | $Spotter->db = null; |
| 665 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 826 | + if ($globalDebugTimeElapsed) { |
|
| 827 | + echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 828 | + } |
|
| 666 | 829 | } |
| 667 | 830 | //$putinarchive = true; |
| 668 | 831 | //$highlight = ''; |
| 669 | 832 | } |
| 670 | 833 | |
| 671 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
|
| 834 | + } else { |
|
| 835 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
|
| 836 | + } |
|
| 672 | 837 | //$dataFound = true; |
| 673 | 838 | } |
| 674 | 839 | |
| 675 | 840 | if (isset($line['altitude']) && $line['altitude'] != '') { |
| 676 | 841 | //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) { |
| 677 | - if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) $this->all_flights[$id]['putinarchive'] = true; |
|
| 842 | + if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 3) { |
|
| 843 | + $this->all_flights[$id]['putinarchive'] = true; |
|
| 844 | + } |
|
| 678 | 845 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100))); |
| 679 | 846 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude'])); |
| 680 | 847 | //$dataFound = true; |
| 681 | 848 | //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n"; |
| 682 | 849 | if ($globalVA !== TRUE && $globalIVAO !== TRUE && $globalVATSIM !== TRUE && $globalphpVMS !== TRUE && $globalVAM !== TRUE) { |
| 683 | 850 | if (isset($this->all_flights[$id]['over_country']) && $this->all_flights[$id]['over_country'] != '' && isset($this->all_flights[$id]['altitude_previous']) && $this->all_flights[$id]['altitude_previous'] != '' && $this->all_flights[$id]['altitude_previous'] < $this->all_flights[$id]['altitude_real'] && isset($this->all_flights[$id]['lastupdate']) && $this->all_flights[$id]['lastupdate'] < time() - 1600) { |
| 684 | - if ($globalDebug) echo '--- Reset because of altitude'."\n"; |
|
| 851 | + if ($globalDebug) { |
|
| 852 | + echo '--- Reset because of altitude'."\n"; |
|
| 853 | + } |
|
| 685 | 854 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
| 686 | 855 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1)); |
| 687 | - if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
| 688 | - elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 689 | - elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 856 | + if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) { |
|
| 857 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
| 858 | + } elseif (isset($line['id'])) { |
|
| 859 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 860 | + } elseif (isset($this->all_flights[$id]['ident'])) { |
|
| 861 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 862 | + } |
|
| 690 | 863 | } |
| 691 | 864 | } |
| 692 | 865 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_previous' => $line['altitude'])); |
@@ -697,22 +870,32 @@ discard block |
||
| 697 | 870 | } |
| 698 | 871 | |
| 699 | 872 | if (isset($line['heading']) && $line['heading'] != '') { |
| 700 | - if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) $this->all_flights[$id]['putinarchive'] = true; |
|
| 873 | + if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 10) { |
|
| 874 | + $this->all_flights[$id]['putinarchive'] = true; |
|
| 875 | + } |
|
| 701 | 876 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading']))); |
| 702 | 877 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true)); |
| 703 | 878 | //$dataFound = true; |
| 704 | 879 | } elseif (!isset($this->all_flights[$id]['heading_fromsrc']) && isset($this->all_flights[$id]['archive_latitude']) && $this->all_flights[$id]['archive_latitude'] != $this->all_flights[$id]['latitude'] && isset($this->all_flights[$id]['archive_longitude']) && $this->all_flights[$id]['archive_longitude'] != $this->all_flights[$id]['longitude']) { |
| 705 | 880 | $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']); |
| 706 | 881 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading))); |
| 707 | - if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) $this->all_flights[$id]['putinarchive'] = true; |
|
| 708 | - if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['id']." : ".$heading."\n"; |
|
| 882 | + if (abs($this->all_flights[$id]['heading']-round($heading)) > 10) { |
|
| 883 | + $this->all_flights[$id]['putinarchive'] = true; |
|
| 884 | + } |
|
| 885 | + if ($globalDebug) { |
|
| 886 | + echo "ø Calculated Heading for ".$this->all_flights[$id]['id']." : ".$heading."\n"; |
|
| 887 | + } |
|
| 709 | 888 | } elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') { |
| 710 | 889 | // If not enough messages and ACARS set heading to 0 |
| 711 | 890 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0)); |
| 712 | 891 | } |
| 713 | - if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
|
| 714 | - elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false; |
|
| 715 | - elseif ($globalDaemon === TRUE && isset($globalAircraftMinUpdate) && $globalAircraftMinUpdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalMinupdate) $dataFound = false; |
|
| 892 | + if ($globalDaemon === TRUE && isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) { |
|
| 893 | + $dataFound = false; |
|
| 894 | + } elseif ($globalDaemon === TRUE && isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) { |
|
| 895 | + $dataFound = false; |
|
| 896 | + } elseif ($globalDaemon === TRUE && isset($globalAircraftMinUpdate) && $globalAircraftMinUpdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalMinupdate) { |
|
| 897 | + $dataFound = false; |
|
| 898 | + } |
|
| 716 | 899 | |
| 717 | 900 | // print_r($this->all_flights[$id]); |
| 718 | 901 | //gets the callsign from the last hour |
@@ -729,23 +912,38 @@ discard block |
||
| 729 | 912 | //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']); |
| 730 | 913 | if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) { |
| 731 | 914 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 732 | - if ($globalDebug) echo "Check if aircraft is already in DB..."; |
|
| 915 | + if ($globalDebug) { |
|
| 916 | + echo "Check if aircraft is already in DB..."; |
|
| 917 | + } |
|
| 733 | 918 | $timeelapsed = microtime(true); |
| 734 | 919 | $SpotterLive = new SpotterLive($this->db); |
| 735 | 920 | if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson' || $line['format_source'] === 'famaprs')) { |
| 736 | 921 | $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']); |
| 737 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 922 | + if ($globalDebugTimeElapsed) { |
|
| 923 | + echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 924 | + } |
|
| 738 | 925 | } elseif (isset($line['id'])) { |
| 739 | 926 | $recent_ident = $SpotterLive->checkIdRecent($line['id']); |
| 740 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 927 | + if ($globalDebugTimeElapsed) { |
|
| 928 | + echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 929 | + } |
|
| 741 | 930 | } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') { |
| 742 | 931 | $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']); |
| 743 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 744 | - } else $recent_ident = ''; |
|
| 932 | + if ($globalDebugTimeElapsed) { |
|
| 933 | + echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 934 | + } |
|
| 935 | + } else { |
|
| 936 | + $recent_ident = ''; |
|
| 937 | + } |
|
| 745 | 938 | $SpotterLive->db=null; |
| 746 | - if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
|
| 747 | - elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
|
| 748 | - } else $recent_ident = ''; |
|
| 939 | + if ($globalDebug && $recent_ident == '') { |
|
| 940 | + echo " Not in DB.\n"; |
|
| 941 | + } elseif ($globalDebug && $recent_ident != '') { |
|
| 942 | + echo " Already in DB.\n"; |
|
| 943 | + } |
|
| 944 | + } else { |
|
| 945 | + $recent_ident = ''; |
|
| 946 | + } |
|
| 749 | 947 | } else { |
| 750 | 948 | $recent_ident = ''; |
| 751 | 949 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0)); |
@@ -753,7 +951,9 @@ discard block |
||
| 753 | 951 | //if there was no aircraft with the same callsign within the last hour and go post it into the archive |
| 754 | 952 | if($recent_ident == "") |
| 755 | 953 | { |
| 756 | - if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : "; |
|
| 954 | + if ($globalDebug) { |
|
| 955 | + echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : "; |
|
| 956 | + } |
|
| 757 | 957 | if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; } |
| 758 | 958 | if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; } |
| 759 | 959 | //adds the spotter data for the archive |
@@ -797,31 +997,49 @@ discard block |
||
| 797 | 997 | |
| 798 | 998 | if (!$ignoreImport) { |
| 799 | 999 | $highlight = ''; |
| 800 | - if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack'; |
|
| 801 | - if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)'; |
|
| 802 | - if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency'; |
|
| 803 | - if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
|
| 1000 | + if ($this->all_flights[$id]['squawk'] == '7500') { |
|
| 1001 | + $highlight = 'Squawk 7500 : Hijack'; |
|
| 1002 | + } |
|
| 1003 | + if ($this->all_flights[$id]['squawk'] == '7600') { |
|
| 1004 | + $highlight = 'Squawk 7600 : Lost Comm (radio failure)'; |
|
| 1005 | + } |
|
| 1006 | + if ($this->all_flights[$id]['squawk'] == '7700') { |
|
| 1007 | + $highlight = 'Squawk 7700 : Emergency'; |
|
| 1008 | + } |
|
| 1009 | + if (!isset($this->all_flights[$id]['id'])) { |
|
| 1010 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
|
| 1011 | + } |
|
| 804 | 1012 | $timeelapsed = microtime(true); |
| 805 | 1013 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
| 806 | 1014 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 807 | 1015 | $Spotter = new Spotter($this->db); |
| 808 | 1016 | $result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['source_type']); |
| 809 | 1017 | $Spotter->db = null; |
| 810 | - if ($globalDebug && isset($result)) echo $result."\n"; |
|
| 1018 | + if ($globalDebug && isset($result)) { |
|
| 1019 | + echo $result."\n"; |
|
| 1020 | + } |
|
| 811 | 1021 | } |
| 812 | 1022 | } |
| 813 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 1023 | + if ($globalDebugTimeElapsed) { |
|
| 1024 | + echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 1025 | + } |
|
| 814 | 1026 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 815 | 1027 | |
| 816 | 1028 | // Add source stat in DB |
| 817 | 1029 | $Stats = new Stats($this->db); |
| 818 | 1030 | if (!empty($this->stats)) { |
| 819 | - if ($globalDebug) echo 'Add source stats : '; |
|
| 1031 | + if ($globalDebug) { |
|
| 1032 | + echo 'Add source stats : '; |
|
| 1033 | + } |
|
| 820 | 1034 | foreach($this->stats as $date => $data) { |
| 821 | 1035 | foreach($data as $source => $sourced) { |
| 822 | 1036 | //print_r($sourced); |
| 823 | - if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date); |
|
| 824 | - if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date); |
|
| 1037 | + if (isset($sourced['polar'])) { |
|
| 1038 | + echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date); |
|
| 1039 | + } |
|
| 1040 | + if (isset($sourced['hist'])) { |
|
| 1041 | + echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date); |
|
| 1042 | + } |
|
| 825 | 1043 | if (isset($sourced['msg'])) { |
| 826 | 1044 | if (time() - $sourced['msg']['date'] > 10) { |
| 827 | 1045 | $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date'])); |
@@ -834,13 +1052,17 @@ discard block |
||
| 834 | 1052 | unset($this->stats[$date]); |
| 835 | 1053 | } |
| 836 | 1054 | } |
| 837 | - if ($globalDebug) echo 'Done'."\n"; |
|
| 1055 | + if ($globalDebug) { |
|
| 1056 | + echo 'Done'."\n"; |
|
| 1057 | + } |
|
| 838 | 1058 | |
| 839 | 1059 | } |
| 840 | 1060 | $Stats->db = null; |
| 841 | 1061 | } |
| 842 | 1062 | $this->del(); |
| 843 | - } elseif ($globalDebug) echo 'Ignore data'."\n"; |
|
| 1063 | + } elseif ($globalDebug) { |
|
| 1064 | + echo 'Ignore data'."\n"; |
|
| 1065 | + } |
|
| 844 | 1066 | //$ignoreImport = false; |
| 845 | 1067 | $this->all_flights[$id]['addedSpotter'] = 1; |
| 846 | 1068 | //print_r($this->all_flights[$id]); |
@@ -857,7 +1079,9 @@ discard block |
||
| 857 | 1079 | */ |
| 858 | 1080 | //SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']); |
| 859 | 1081 | if ($this->last_delete == 0 || time() - $this->last_delete > 1800) { |
| 860 | - if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours..."; |
|
| 1082 | + if ($globalDebug) { |
|
| 1083 | + echo "---- Deleting Live Spotter data older than 9 hours..."; |
|
| 1084 | + } |
|
| 861 | 1085 | //SpotterLive->deleteLiveSpotterDataNotUpdated(); |
| 862 | 1086 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
| 863 | 1087 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
@@ -866,7 +1090,9 @@ discard block |
||
| 866 | 1090 | $SpotterLive->db=null; |
| 867 | 1091 | } |
| 868 | 1092 | } |
| 869 | - if ($globalDebug) echo " Done\n"; |
|
| 1093 | + if ($globalDebug) { |
|
| 1094 | + echo " Done\n"; |
|
| 1095 | + } |
|
| 870 | 1096 | $this->last_delete = time(); |
| 871 | 1097 | } |
| 872 | 1098 | } else { |
@@ -893,11 +1119,17 @@ discard block |
||
| 893 | 1119 | //echo "{$line[8]} {$line[7]} - MODES:{$line[4]} CALLSIGN:{$line[10]} ALT:{$line[11]} VEL:{$line[12]} HDG:{$line[13]} LAT:{$line[14]} LON:{$line[15]} VR:{$line[16]} SQUAWK:{$line[17]}\n"; |
| 894 | 1120 | if ($globalDebug) { |
| 895 | 1121 | if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) { |
| 896 | - if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n"; |
|
| 897 | - else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n"; |
|
| 1122 | + if (isset($this->all_flights[$id]['source_name'])) { |
|
| 1123 | + echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n"; |
|
| 1124 | + } else { |
|
| 1125 | + echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n"; |
|
| 1126 | + } |
|
| 898 | 1127 | } else { |
| 899 | - if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n"; |
|
| 900 | - else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n"; |
|
| 1128 | + if (isset($this->all_flights[$id]['source_name'])) { |
|
| 1129 | + echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n"; |
|
| 1130 | + } else { |
|
| 1131 | + echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n"; |
|
| 1132 | + } |
|
| 901 | 1133 | } |
| 902 | 1134 | } |
| 903 | 1135 | $ignoreImport = false; |
@@ -943,22 +1175,30 @@ discard block |
||
| 943 | 1175 | |
| 944 | 1176 | if (!$ignoreImport) { |
| 945 | 1177 | if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
| 946 | - if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
|
| 1178 | + if (!isset($this->all_flights[$id]['id'])) { |
|
| 1179 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
|
| 1180 | + } |
|
| 947 | 1181 | $timeelapsed = microtime(true); |
| 948 | 1182 | if (!isset($globalNoImport) || $globalNoImport === FALSE) { |
| 949 | 1183 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 950 | - if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : "; |
|
| 1184 | + if ($globalDebug) { |
|
| 1185 | + echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : "; |
|
| 1186 | + } |
|
| 951 | 1187 | $SpotterLive = new SpotterLive($this->db); |
| 952 | 1188 | $result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'],$this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']); |
| 953 | 1189 | $SpotterLive->db = null; |
| 954 | - if ($globalDebug) echo $result."\n"; |
|
| 1190 | + if ($globalDebug) { |
|
| 1191 | + echo $result."\n"; |
|
| 1192 | + } |
|
| 955 | 1193 | } |
| 956 | 1194 | } |
| 957 | 1195 | if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_flights[$id]['putinarchive']) { |
| 958 | 1196 | $APRSSpotter->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['altitude_real'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']); |
| 959 | 1197 | } |
| 960 | 1198 | $this->all_flights[$id]['putinarchive'] = false; |
| 961 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 1199 | + if ($globalDebugTimeElapsed) { |
|
| 1200 | + echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 1201 | + } |
|
| 962 | 1202 | |
| 963 | 1203 | // Put statistics in $this->stats variable |
| 964 | 1204 | //if ($line['format_source'] != 'aprs') { |
@@ -966,7 +1206,9 @@ discard block |
||
| 966 | 1206 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
| 967 | 1207 | if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') { |
| 968 | 1208 | $source = $this->all_flights[$id]['source_name']; |
| 969 | - if ($source == '') $source = $this->all_flights[$id]['format_source']; |
|
| 1209 | + if ($source == '') { |
|
| 1210 | + $source = $this->all_flights[$id]['format_source']; |
|
| 1211 | + } |
|
| 970 | 1212 | if (!isset($this->source_location[$source])) { |
| 971 | 1213 | $Location = new Source(); |
| 972 | 1214 | $coord = $Location->getLocationInfobySourceName($source); |
@@ -987,7 +1229,9 @@ discard block |
||
| 987 | 1229 | $stats_heading = round($stats_heading/22.5); |
| 988 | 1230 | $stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']); |
| 989 | 1231 | $current_date = date('Y-m-d'); |
| 990 | - if ($stats_heading == 16) $stats_heading = 0; |
|
| 1232 | + if ($stats_heading == 16) { |
|
| 1233 | + $stats_heading = 0; |
|
| 1234 | + } |
|
| 991 | 1235 | if (!isset($this->stats[$current_date][$source]['polar'][1])) { |
| 992 | 1236 | for ($i=0;$i<=15;$i++) { |
| 993 | 1237 | $this->stats[$current_date][$source]['polar'][$i] = 0; |
@@ -1005,7 +1249,9 @@ discard block |
||
| 1005 | 1249 | if (isset($this->stats[$current_date][$source]['hist'][0])) { |
| 1006 | 1250 | end($this->stats[$current_date][$source]['hist']); |
| 1007 | 1251 | $mini = key($this->stats[$current_date][$source]['hist'])+10; |
| 1008 | - } else $mini = 0; |
|
| 1252 | + } else { |
|
| 1253 | + $mini = 0; |
|
| 1254 | + } |
|
| 1009 | 1255 | for ($i=$mini;$i<=$distance;$i+=10) { |
| 1010 | 1256 | $this->stats[$current_date][$source]['hist'][$i] = 0; |
| 1011 | 1257 | } |
@@ -1017,19 +1263,27 @@ discard block |
||
| 1017 | 1263 | } |
| 1018 | 1264 | |
| 1019 | 1265 | $this->all_flights[$id]['lastupdate'] = time(); |
| 1020 | - if ($this->all_flights[$id]['putinarchive']) $send = true; |
|
| 1266 | + if ($this->all_flights[$id]['putinarchive']) { |
|
| 1267 | + $send = true; |
|
| 1268 | + } |
|
| 1021 | 1269 | //if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
| 1022 | - } elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
|
| 1270 | + } elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) { |
|
| 1271 | + echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
|
| 1272 | + } |
|
| 1023 | 1273 | //$this->del(); |
| 1024 | 1274 | |
| 1025 | 1275 | if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) { |
| 1026 | 1276 | if ((!isset($globalNoImport) || $globalNoImport === FALSE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) { |
| 1027 | - if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour..."; |
|
| 1277 | + if ($globalDebug) { |
|
| 1278 | + echo "---- Deleting Live Spotter data Not updated since 2 hour..."; |
|
| 1279 | + } |
|
| 1028 | 1280 | $SpotterLive = new SpotterLive($this->db); |
| 1029 | 1281 | $SpotterLive->deleteLiveSpotterDataNotUpdated(); |
| 1030 | 1282 | $SpotterLive->db = null; |
| 1031 | 1283 | //SpotterLive->deleteLiveSpotterData(); |
| 1032 | - if ($globalDebug) echo " Done\n"; |
|
| 1284 | + if ($globalDebug) { |
|
| 1285 | + echo " Done\n"; |
|
| 1286 | + } |
|
| 1033 | 1287 | $this->last_delete_hourly = time(); |
| 1034 | 1288 | } else { |
| 1035 | 1289 | $this->del(); |
@@ -1041,7 +1295,9 @@ discard block |
||
| 1041 | 1295 | //$ignoreImport = false; |
| 1042 | 1296 | } |
| 1043 | 1297 | //if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN); |
| 1044 | - if ($send) return $this->all_flights[$id]; |
|
| 1298 | + if ($send) { |
|
| 1299 | + return $this->all_flights[$id]; |
|
| 1300 | + } |
|
| 1045 | 1301 | } |
| 1046 | 1302 | } |
| 1047 | 1303 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | require_once(dirname(__FILE__).'/require/settings.php'); |
| 3 | -$date = filter_input(INPUT_POST,'date',FILTER_SANITIZE_STRING); |
|
| 3 | +$date = filter_input(INPUT_POST, 'date', FILTER_SANITIZE_STRING); |
|
| 4 | 4 | if ($date == '') $date = date('Y-m-d'); |
| 5 | 5 | header('Location: '.$globalURL.'/accident/'.$date); |
| 6 | 6 | ?> |
| 7 | 7 | \ No newline at end of file |
@@ -1,6 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | require_once(dirname(__FILE__).'/require/settings.php'); |
| 3 | 3 | $date = filter_input(INPUT_POST,'date',FILTER_SANITIZE_STRING); |
| 4 | -if ($date == '') $date = date('Y-m-d'); |
|
| 4 | +if ($date == '') { |
|
| 5 | + $date = date('Y-m-d'); |
|
| 6 | +} |
|
| 5 | 7 | header('Location: '.$globalURL.'/accident/'.$date); |
| 6 | 8 | ?> |
| 7 | 9 | \ No newline at end of file |
@@ -19,13 +19,13 @@ discard block |
||
| 19 | 19 | print '<div id="chart" class="chart" width="100%"></div><script>'; |
| 20 | 20 | $year_data = ''; |
| 21 | 21 | $year_cnt = ''; |
| 22 | -foreach($date_array as $year_item) |
|
| 22 | +foreach ($date_array as $year_item) |
|
| 23 | 23 | { |
| 24 | 24 | $year_data .= '"'.$year_item['year'].'-01-01",'; |
| 25 | 25 | $year_cnt .= $year_item['count'].','; |
| 26 | 26 | } |
| 27 | 27 | $year_data = "['x',".substr($year_data, 0, -1)."]"; |
| 28 | -$year_cnt = "['flights',".substr($year_cnt,0,-1)."]"; |
|
| 28 | +$year_cnt = "['flights',".substr($year_cnt, 0, -1)."]"; |
|
| 29 | 29 | print 'c3.generate({ |
| 30 | 30 | bindto: "#chart", |
| 31 | 31 | data: { x: "x", |
@@ -35,12 +35,12 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | if (!empty($date_array)) |
| 37 | 37 | { |
| 38 | - foreach($date_array as $key => $row) { |
|
| 38 | + foreach ($date_array as $key => $row) { |
|
| 39 | 39 | $years[$key] = $row['year']; |
| 40 | 40 | $counts[$key] = $row['count']; |
| 41 | 41 | } |
| 42 | 42 | //array_multisort($years,SORT_DESC,$date_array); |
| 43 | - array_multisort($counts,SORT_DESC,$date_array); |
|
| 43 | + array_multisort($counts, SORT_DESC, $date_array); |
|
| 44 | 44 | print '<div class="table-responsive">'; |
| 45 | 45 | print '<table class="common-date table-striped">'; |
| 46 | 46 | print '<thead>'; |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | print '</thead>'; |
| 51 | 51 | print '<tbody>'; |
| 52 | 52 | $i = 1; |
| 53 | - foreach($date_array as $date_item) |
|
| 53 | + foreach ($date_array as $date_item) |
|
| 54 | 54 | { |
| 55 | 55 | print '<tr>'; |
| 56 | 56 | print '<td><strong>'.$i.'</strong></td>'; |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | $route_array = $Spotter->countAllRoutes(); |
| 19 | 19 | print '<div id="chart" class="chart" width="100%"></div><script>'; |
| 20 | 20 | $route_data = ''; |
| 21 | -foreach($route_array as $route_item) |
|
| 21 | +foreach ($route_array as $route_item) |
|
| 22 | 22 | { |
| 23 | 23 | $route_data .= '[ "'.$route_item['airport_departure_icao'].' - '.$route_item['airport_arrival_icao'].'",'.$route_item['route_count'].'],'; |
| 24 | 24 | } |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | print '</thead>'; |
| 47 | 47 | print '<tbody>'; |
| 48 | 48 | $i = 1; |
| 49 | - foreach($route_array as $route_item) |
|
| 49 | + foreach ($route_array as $route_item) |
|
| 50 | 50 | { |
| 51 | 51 | print '<tr>'; |
| 52 | 52 | print '<td><strong>'.$i.'</strong></td>'; |
@@ -5,7 +5,9 @@ |
||
| 5 | 5 | $Spotter = new Spotter(); |
| 6 | 6 | $title = _("Statistics").' - '._("Most common Route by Airport"); |
| 7 | 7 | require_once('header.php'); |
| 8 | -if (!isset($filter_name)) $filter_name = ''; |
|
| 8 | +if (!isset($filter_name)) { |
|
| 9 | + $filter_name = ''; |
|
| 10 | +} |
|
| 9 | 11 | include('statistics-sub-menu.php'); |
| 10 | 12 | |
| 11 | 13 | print '<script type="text/javascript" src="'.$globalURL.'/js/d3.min.js"></script>'; |
@@ -72,8 +72,11 @@ discard block |
||
| 72 | 72 | $globalDBSname = $globalDBname; |
| 73 | 73 | $globalDBSuser = $globalDBuser; |
| 74 | 74 | $globalDBSpass = $globalDBpass; |
| 75 | - if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport == '') $globalDBSport = 3306; |
|
| 76 | - else $globalDBSport = $globalDBport; |
|
| 75 | + if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport == '') { |
|
| 76 | + $globalDBSport = 3306; |
|
| 77 | + } else { |
|
| 78 | + $globalDBSport = $globalDBport; |
|
| 79 | + } |
|
| 77 | 80 | } else { |
| 78 | 81 | $DBname = 'default'; |
| 79 | 82 | $globalDBSdriver = $globalDBdriver; |
@@ -81,8 +84,11 @@ discard block |
||
| 81 | 84 | $globalDBSname = $globalDBname; |
| 82 | 85 | $globalDBSuser = $user; |
| 83 | 86 | $globalDBSpass = $pass; |
| 84 | - if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport == '') $globalDBSport = 3306; |
|
| 85 | - else $globalDBSport = $globalDBport; |
|
| 87 | + if (!isset($globalDBport) || $globalDBport === NULL || $globalDBport == '') { |
|
| 88 | + $globalDBSport = 3306; |
|
| 89 | + } else { |
|
| 90 | + $globalDBSport = $globalDBport; |
|
| 91 | + } |
|
| 86 | 92 | } |
| 87 | 93 | } else { |
| 88 | 94 | $globalDBSdriver = $globalDB[$DBname]['driver']; |
@@ -90,11 +96,16 @@ discard block |
||
| 90 | 96 | $globalDBSname = $globalDB[$DBname]['name']; |
| 91 | 97 | $globalDBSuser = $globalDB[$DBname]['user']; |
| 92 | 98 | $globalDBSpass = $globalDB[$DBname]['pass']; |
| 93 | - if (isset($globalDB[$DBname]['port'])) $globalDBSport = $globalDB[$DBname]['port']; |
|
| 94 | - else $globalDBSport = 3306; |
|
| 99 | + if (isset($globalDB[$DBname]['port'])) { |
|
| 100 | + $globalDBSport = $globalDB[$DBname]['port']; |
|
| 101 | + } else { |
|
| 102 | + $globalDBSport = 3306; |
|
| 103 | + } |
|
| 95 | 104 | } |
| 96 | 105 | // Set number of try to connect to DB |
| 97 | - if (!isset($globalDBretry) || $globalDBretry == '' || $globalDBretry === NULL) $globalDBretry = 5; |
|
| 106 | + if (!isset($globalDBretry) || $globalDBretry == '' || $globalDBretry === NULL) { |
|
| 107 | + $globalDBretry = 5; |
|
| 108 | + } |
|
| 98 | 109 | $i = 0; |
| 99 | 110 | while (true) { |
| 100 | 111 | try { |
@@ -103,10 +114,16 @@ discard block |
||
| 103 | 114 | $this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'"); |
| 104 | 115 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 105 | 116 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER); |
| 106 | - if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,500); |
|
| 107 | - else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut); |
|
| 108 | - if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true); |
|
| 109 | - else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent); |
|
| 117 | + if (!isset($globalDBTimeOut)) { |
|
| 118 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,500); |
|
| 119 | + } else { |
|
| 120 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut); |
|
| 121 | + } |
|
| 122 | + if (!isset($globalDBPersistent)) { |
|
| 123 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true); |
|
| 124 | + } else { |
|
| 125 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent); |
|
| 126 | + } |
|
| 110 | 127 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); |
| 111 | 128 | $this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); |
| 112 | 129 | // Workaround against "ONLY_FULL_GROUP_BY" mode |
@@ -120,23 +137,35 @@ discard block |
||
| 120 | 137 | //$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'"); |
| 121 | 138 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 122 | 139 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER); |
| 123 | - if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,200); |
|
| 124 | - else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut); |
|
| 125 | - if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true); |
|
| 126 | - else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent); |
|
| 140 | + if (!isset($globalDBTimeOut)) { |
|
| 141 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,200); |
|
| 142 | + } else { |
|
| 143 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut); |
|
| 144 | + } |
|
| 145 | + if (!isset($globalDBPersistent)) { |
|
| 146 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true); |
|
| 147 | + } else { |
|
| 148 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent); |
|
| 149 | + } |
|
| 127 | 150 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); |
| 128 | 151 | $this->dbs[$DBname]->exec('SET timezone="UTC"'); |
| 129 | 152 | } |
| 130 | 153 | break; |
| 131 | 154 | } catch(PDOException $e) { |
| 132 | 155 | $i++; |
| 133 | - if (isset($globalDebug) && $globalDebug) echo 'Error connecting to DB: '.$globalDBSname.' - Error: '.$e->getMessage()."\n"; |
|
| 156 | + if (isset($globalDebug) && $globalDebug) { |
|
| 157 | + echo 'Error connecting to DB: '.$globalDBSname.' - Error: '.$e->getMessage()."\n"; |
|
| 158 | + } |
|
| 134 | 159 | //exit; |
| 135 | - if ($i > $globalDBretry) return false; |
|
| 160 | + if ($i > $globalDBretry) { |
|
| 161 | + return false; |
|
| 162 | + } |
|
| 136 | 163 | //return false; |
| 137 | 164 | } |
| 138 | 165 | } |
| 139 | - if ($DBname === 'default') $this->db = $this->dbs['default']; |
|
| 166 | + if ($DBname === 'default') { |
|
| 167 | + $this->db = $this->dbs['default']; |
|
| 168 | + } |
|
| 140 | 169 | return true; |
| 141 | 170 | } |
| 142 | 171 | |
@@ -148,7 +177,9 @@ discard block |
||
| 148 | 177 | } else { |
| 149 | 178 | $query = "SELECT * FROM pg_catalog.pg_tables WHERE tablename = '".$table."'"; |
| 150 | 179 | } |
| 151 | - if ($this->db == NULL) return false; |
|
| 180 | + if ($this->db == NULL) { |
|
| 181 | + return false; |
|
| 182 | + } |
|
| 152 | 183 | try { |
| 153 | 184 | //$Connection = new Connection(); |
| 154 | 185 | $results = $this->db->query($query); |
@@ -157,21 +188,28 @@ discard block |
||
| 157 | 188 | } |
| 158 | 189 | if($results->rowCount()>0) { |
| 159 | 190 | return true; |
| 191 | + } else { |
|
| 192 | + return false; |
|
| 160 | 193 | } |
| 161 | - else return false; |
|
| 162 | 194 | } |
| 163 | 195 | |
| 164 | 196 | public function connectionExists() |
| 165 | 197 | { |
| 166 | 198 | global $globalDBdriver, $globalDBCheckConnection; |
| 167 | - if (isset($globalDBCheckConnection) && $globalDBCheckConnection === FALSE) return true; |
|
| 199 | + if (isset($globalDBCheckConnection) && $globalDBCheckConnection === FALSE) { |
|
| 200 | + return true; |
|
| 201 | + } |
|
| 168 | 202 | $query = "SELECT 1 + 1"; |
| 169 | - if ($this->db === null) return false; |
|
| 203 | + if ($this->db === null) { |
|
| 204 | + return false; |
|
| 205 | + } |
|
| 170 | 206 | try { |
| 171 | 207 | $sum = @$this->db->query($query); |
| 172 | 208 | if ($sum instanceof \PDOStatement) { |
| 173 | 209 | $sum = $sum->fetchColumn(0); |
| 174 | - } else $sum = 0; |
|
| 210 | + } else { |
|
| 211 | + $sum = 0; |
|
| 212 | + } |
|
| 175 | 213 | if (intval($sum) !== 2) { |
| 176 | 214 | return false; |
| 177 | 215 | } |
@@ -206,8 +244,9 @@ discard block |
||
| 206 | 244 | $nb = $results->fetchAll(PDO::FETCH_ASSOC); |
| 207 | 245 | if($nb[0]['nb'] > 0) { |
| 208 | 246 | return true; |
| 247 | + } else { |
|
| 248 | + return false; |
|
| 209 | 249 | } |
| 210 | - else return false; |
|
| 211 | 250 | } |
| 212 | 251 | |
| 213 | 252 | /* |
@@ -257,9 +296,12 @@ discard block |
||
| 257 | 296 | } |
| 258 | 297 | $result = $sth->fetch(PDO::FETCH_ASSOC); |
| 259 | 298 | $sth->closeCursor(); |
| 260 | - if ($result['nb'] > 0) return true; |
|
| 261 | - else return false; |
|
| 262 | -/* } else { |
|
| 299 | + if ($result['nb'] > 0) { |
|
| 300 | + return true; |
|
| 301 | + } else { |
|
| 302 | + return false; |
|
| 303 | + } |
|
| 304 | + /* } else { |
|
| 263 | 305 | $query = "SELECT * FROM ".$table." LIMIT 0"; |
| 264 | 306 | try { |
| 265 | 307 | $results = $this->db->query($query); |
@@ -298,7 +340,9 @@ discard block |
||
| 298 | 340 | $sth->closeCursor(); |
| 299 | 341 | return $result['value']; |
| 300 | 342 | } |
| 301 | - } else return $version; |
|
| 343 | + } else { |
|
| 344 | + return $version; |
|
| 345 | + } |
|
| 302 | 346 | } |
| 303 | 347 | |
| 304 | 348 | /* |
@@ -307,9 +351,14 @@ discard block |
||
| 307 | 351 | */ |
| 308 | 352 | public function latest() { |
| 309 | 353 | global $globalNoDB; |
| 310 | - if (isset($globalNoDB) && $globalNoDB === TRUE) return true; |
|
| 311 | - if ($this->check_schema_version() == $this->latest_schema) return true; |
|
| 312 | - else return false; |
|
| 354 | + if (isset($globalNoDB) && $globalNoDB === TRUE) { |
|
| 355 | + return true; |
|
| 356 | + } |
|
| 357 | + if ($this->check_schema_version() == $this->latest_schema) { |
|
| 358 | + return true; |
|
| 359 | + } else { |
|
| 360 | + return false; |
|
| 361 | + } |
|
| 313 | 362 | } |
| 314 | 363 | |
| 315 | 364 | } |
@@ -6,6 +6,9 @@ discard block |
||
| 6 | 6 | public $dbs = array(); |
| 7 | 7 | public $latest_schema = 43; |
| 8 | 8 | |
| 9 | + /** |
|
| 10 | + * @param string $dbname |
|
| 11 | + */ |
|
| 9 | 12 | public function __construct($dbc = null,$dbname = null,$user = null,$pass = null) { |
| 10 | 13 | global $globalDBdriver, $globalNoDB; |
| 11 | 14 | if (isset($globalNoDB) && $globalNoDB === TRUE) { |
@@ -141,6 +144,9 @@ discard block |
||
| 141 | 144 | return true; |
| 142 | 145 | } |
| 143 | 146 | |
| 147 | + /** |
|
| 148 | + * @param string $table |
|
| 149 | + */ |
|
| 144 | 150 | public function tableExists($table) |
| 145 | 151 | { |
| 146 | 152 | global $globalDBdriver, $globalDBname; |
@@ -190,6 +196,11 @@ discard block |
||
| 190 | 196 | /* |
| 191 | 197 | * Check if index exist |
| 192 | 198 | */ |
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * @param string $table |
|
| 202 | + * @param string $index |
|
| 203 | + */ |
|
| 193 | 204 | public function indexExists($table,$index) |
| 194 | 205 | { |
| 195 | 206 | global $globalDBdriver, $globalDBname; |
@@ -232,6 +243,10 @@ discard block |
||
| 232 | 243 | return $columns; |
| 233 | 244 | } |
| 234 | 245 | |
| 246 | + /** |
|
| 247 | + * @param string $table |
|
| 248 | + * @param string $column |
|
| 249 | + */ |
|
| 235 | 250 | public function getColumnType($table,$column) { |
| 236 | 251 | $select = $this->db->query('SELECT '.$column.' FROM '.$table); |
| 237 | 252 | $tomet = $select->getColumnMeta(0); |
@@ -242,6 +257,11 @@ discard block |
||
| 242 | 257 | * Check if a column name exist in a table |
| 243 | 258 | * @return Boolean column exist or not |
| 244 | 259 | */ |
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * @param string $table |
|
| 263 | + * @param string $name |
|
| 264 | + */ |
|
| 245 | 265 | public function checkColumnName($table,$name) |
| 246 | 266 | { |
| 247 | 267 | global $globalDBdriver, $globalDBname; |
@@ -7,35 +7,35 @@ discard block |
||
| 7 | 7 | public $latest_schema = 43; |
| 8 | 8 | |
| 9 | 9 | public function __construct($dbc = null,$dbname = null,$user = null,$pass = null) { |
| 10 | - global $globalDBdriver, $globalNoDB; |
|
| 11 | - if (isset($globalNoDB) && $globalNoDB === TRUE) { |
|
| 10 | + global $globalDBdriver, $globalNoDB; |
|
| 11 | + if (isset($globalNoDB) && $globalNoDB === TRUE) { |
|
| 12 | 12 | $this->db = null; |
| 13 | - } else { |
|
| 13 | + } else { |
|
| 14 | 14 | if ($dbc === null) { |
| 15 | - if ($this->db === null && $dbname === null) { |
|
| 15 | + if ($this->db === null && $dbname === null) { |
|
| 16 | 16 | if ($user === null && $pass === null) { |
| 17 | - $this->createDBConnection(); |
|
| 17 | + $this->createDBConnection(); |
|
| 18 | 18 | } else { |
| 19 | - $this->createDBConnection(null,$user,$pass); |
|
| 19 | + $this->createDBConnection(null,$user,$pass); |
|
| 20 | 20 | } |
| 21 | - } else { |
|
| 21 | + } else { |
|
| 22 | 22 | $this->createDBConnection($dbname); |
| 23 | - } |
|
| 23 | + } |
|
| 24 | 24 | } elseif ($dbname === null || $dbname === 'default') { |
| 25 | - $this->db = $dbc; |
|
| 26 | - if ($this->connectionExists() === false) { |
|
| 25 | + $this->db = $dbc; |
|
| 26 | + if ($this->connectionExists() === false) { |
|
| 27 | 27 | /* |
| 28 | 28 | echo 'Restart Connection !!!'."\n"; |
| 29 | 29 | $e = new \Exception; |
| 30 | 30 | var_dump($e->getTraceAsString()); |
| 31 | 31 | */ |
| 32 | 32 | $this->createDBConnection(); |
| 33 | - } |
|
| 33 | + } |
|
| 34 | 34 | } else { |
| 35 | - //$this->connectionExists(); |
|
| 36 | - $this->dbs[$dbname] = $dbc; |
|
| 35 | + //$this->connectionExists(); |
|
| 36 | + $this->dbs[$dbname] = $dbc; |
|
| 37 | + } |
|
| 37 | 38 | } |
| 38 | - } |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | public function db() { |
@@ -56,11 +56,11 @@ discard block |
||
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | - * Creates the database connection |
|
| 60 | - * |
|
| 61 | - * @return Boolean of the database connection |
|
| 62 | - * |
|
| 63 | - */ |
|
| 59 | + * Creates the database connection |
|
| 60 | + * |
|
| 61 | + * @return Boolean of the database connection |
|
| 62 | + * |
|
| 63 | + */ |
|
| 64 | 64 | |
| 65 | 65 | public function createDBConnection($DBname = null, $user = null, $pass = null) |
| 66 | 66 | { |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | return false; |
| 158 | 158 | } |
| 159 | 159 | if($results->rowCount()>0) { |
| 160 | - return true; |
|
| 160 | + return true; |
|
| 161 | 161 | } |
| 162 | 162 | else return false; |
| 163 | 163 | } |
@@ -174,14 +174,14 @@ discard block |
||
| 174 | 174 | $sum = $sum->fetchColumn(0); |
| 175 | 175 | } else $sum = 0; |
| 176 | 176 | if (intval($sum) !== 2) { |
| 177 | - return false; |
|
| 177 | + return false; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | } catch(PDOException $e) { |
| 181 | 181 | if($e->getCode() != 'HY000' || !stristr($e->getMessage(), 'server has gone away')) { |
| 182 | - throw $e; |
|
| 183 | - } |
|
| 184 | - //echo 'error ! '.$e->getMessage(); |
|
| 182 | + throw $e; |
|
| 183 | + } |
|
| 184 | + //echo 'error ! '.$e->getMessage(); |
|
| 185 | 185 | return false; |
| 186 | 186 | } |
| 187 | 187 | return true; |
@@ -285,8 +285,8 @@ discard block |
||
| 285 | 285 | $version = 0; |
| 286 | 286 | if ($this->tableExists('aircraft')) { |
| 287 | 287 | if (!$this->tableExists('config')) { |
| 288 | - $version = '1'; |
|
| 289 | - return $version; |
|
| 288 | + $version = '1'; |
|
| 289 | + return $version; |
|
| 290 | 290 | } else { |
| 291 | 291 | $query = "SELECT value FROM config WHERE name = 'schema_version' LIMIT 1"; |
| 292 | 292 | try { |
@@ -307,10 +307,10 @@ discard block |
||
| 307 | 307 | * @return Boolean if latest version or not |
| 308 | 308 | */ |
| 309 | 309 | public function latest() { |
| 310 | - global $globalNoDB; |
|
| 311 | - if (isset($globalNoDB) && $globalNoDB === TRUE) return true; |
|
| 312 | - if ($this->check_schema_version() == $this->latest_schema) return true; |
|
| 313 | - else return false; |
|
| 310 | + global $globalNoDB; |
|
| 311 | + if (isset($globalNoDB) && $globalNoDB === TRUE) return true; |
|
| 312 | + if ($this->check_schema_version() == $this->latest_schema) return true; |
|
| 313 | + else return false; |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | } |
@@ -1,12 +1,12 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | require_once(dirname(__FILE__).'/settings.php'); |
| 3 | 3 | |
| 4 | -class Connection{ |
|
| 4 | +class Connection { |
|
| 5 | 5 | public $db = null; |
| 6 | 6 | public $dbs = array(); |
| 7 | 7 | public $latest_schema = 43; |
| 8 | 8 | |
| 9 | - public function __construct($dbc = null,$dbname = null,$user = null,$pass = null) { |
|
| 9 | + public function __construct($dbc = null, $dbname = null, $user = null, $pass = null) { |
|
| 10 | 10 | global $globalDBdriver, $globalNoDB; |
| 11 | 11 | if (isset($globalNoDB) && $globalNoDB === TRUE) { |
| 12 | 12 | $this->db = null; |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | if ($user === null && $pass === null) { |
| 17 | 17 | $this->createDBConnection(); |
| 18 | 18 | } else { |
| 19 | - $this->createDBConnection(null,$user,$pass); |
|
| 19 | + $this->createDBConnection(null, $user, $pass); |
|
| 20 | 20 | } |
| 21 | 21 | } else { |
| 22 | 22 | $this->createDBConnection($dbname); |
@@ -100,14 +100,14 @@ discard block |
||
| 100 | 100 | while (true) { |
| 101 | 101 | try { |
| 102 | 102 | if ($globalDBSdriver == 'mysql') { |
| 103 | - $this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;charset=utf8", $globalDBSuser, $globalDBSpass); |
|
| 103 | + $this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;charset=utf8", $globalDBSuser, $globalDBSpass); |
|
| 104 | 104 | $this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'"); |
| 105 | 105 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 106 | - $this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER); |
|
| 107 | - if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,500); |
|
| 108 | - else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut); |
|
| 109 | - if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true); |
|
| 110 | - else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent); |
|
| 106 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); |
|
| 107 | + if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, 500); |
|
| 108 | + else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, $globalDBTimeOut); |
|
| 109 | + if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, true); |
|
| 110 | + else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, $globalDBPersistent); |
|
| 111 | 111 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); |
| 112 | 112 | $this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); |
| 113 | 113 | // Workaround against "ONLY_FULL_GROUP_BY" mode |
@@ -117,19 +117,19 @@ discard block |
||
| 117 | 117 | $this->dbs[$DBname]->exec('SET SESSION time_zone = "+00:00"'); |
| 118 | 118 | //$this->dbs[$DBname]->exec('SET @@session.time_zone = "+00:00"'); |
| 119 | 119 | } else { |
| 120 | - $this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;options='--client_encoding=utf8'", $globalDBSuser, $globalDBSpass); |
|
| 120 | + $this->dbs[$DBname] = new PDO("$globalDBSdriver:host=$globalDBShost;port=$globalDBSport;dbname=$globalDBSname;options='--client_encoding=utf8'", $globalDBSuser, $globalDBSpass); |
|
| 121 | 121 | //$this->dbs[$DBname]->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'"); |
| 122 | 122 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 123 | - $this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE,PDO::CASE_LOWER); |
|
| 124 | - if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,200); |
|
| 125 | - else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT,$globalDBTimeOut); |
|
| 126 | - if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,true); |
|
| 127 | - else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT,$globalDBPersistent); |
|
| 123 | + $this->dbs[$DBname]->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); |
|
| 124 | + if (!isset($globalDBTimeOut)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, 200); |
|
| 125 | + else $this->dbs[$DBname]->setAttribute(PDO::ATTR_TIMEOUT, $globalDBTimeOut); |
|
| 126 | + if (!isset($globalDBPersistent)) $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, true); |
|
| 127 | + else $this->dbs[$DBname]->setAttribute(PDO::ATTR_PERSISTENT, $globalDBPersistent); |
|
| 128 | 128 | $this->dbs[$DBname]->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); |
| 129 | 129 | $this->dbs[$DBname]->exec('SET timezone="UTC"'); |
| 130 | 130 | } |
| 131 | 131 | break; |
| 132 | - } catch(PDOException $e) { |
|
| 132 | + } catch (PDOException $e) { |
|
| 133 | 133 | $i++; |
| 134 | 134 | if (isset($globalDebug) && $globalDebug) echo 'Error connecting to DB: '.$globalDBSname.' - Error: '.$e->getMessage()."\n"; |
| 135 | 135 | //exit; |
@@ -153,10 +153,10 @@ discard block |
||
| 153 | 153 | try { |
| 154 | 154 | //$Connection = new Connection(); |
| 155 | 155 | $results = $this->db->query($query); |
| 156 | - } catch(PDOException $e) { |
|
| 156 | + } catch (PDOException $e) { |
|
| 157 | 157 | return false; |
| 158 | 158 | } |
| 159 | - if($results->rowCount()>0) { |
|
| 159 | + if ($results->rowCount() > 0) { |
|
| 160 | 160 | return true; |
| 161 | 161 | } |
| 162 | 162 | else return false; |
@@ -177,8 +177,8 @@ discard block |
||
| 177 | 177 | return false; |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - } catch(PDOException $e) { |
|
| 181 | - if($e->getCode() != 'HY000' || !stristr($e->getMessage(), 'server has gone away')) { |
|
| 180 | + } catch (PDOException $e) { |
|
| 181 | + if ($e->getCode() != 'HY000' || !stristr($e->getMessage(), 'server has gone away')) { |
|
| 182 | 182 | throw $e; |
| 183 | 183 | } |
| 184 | 184 | //echo 'error ! '.$e->getMessage(); |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | /* |
| 191 | 191 | * Check if index exist |
| 192 | 192 | */ |
| 193 | - public function indexExists($table,$index) |
|
| 193 | + public function indexExists($table, $index) |
|
| 194 | 194 | { |
| 195 | 195 | global $globalDBdriver, $globalDBname; |
| 196 | 196 | if ($globalDBdriver == 'mysql') { |
@@ -201,11 +201,11 @@ discard block |
||
| 201 | 201 | try { |
| 202 | 202 | //$Connection = new Connection(); |
| 203 | 203 | $results = $this->db->query($query); |
| 204 | - } catch(PDOException $e) { |
|
| 204 | + } catch (PDOException $e) { |
|
| 205 | 205 | return false; |
| 206 | 206 | } |
| 207 | 207 | $nb = $results->fetchAll(PDO::FETCH_ASSOC); |
| 208 | - if($nb[0]['nb'] > 0) { |
|
| 208 | + if ($nb[0]['nb'] > 0) { |
|
| 209 | 209 | return true; |
| 210 | 210 | } |
| 211 | 211 | else return false; |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | $query = "SELECT * FROM ".$table." LIMIT 0"; |
| 221 | 221 | try { |
| 222 | 222 | $results = $this->db->query($query); |
| 223 | - } catch(PDOException $e) { |
|
| 223 | + } catch (PDOException $e) { |
|
| 224 | 224 | return "error : ".$e->getMessage()."\n"; |
| 225 | 225 | } |
| 226 | 226 | $columns = array(); |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | return $columns; |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - public function getColumnType($table,$column) { |
|
| 235 | + public function getColumnType($table, $column) { |
|
| 236 | 236 | $select = $this->db->query('SELECT '.$column.' FROM '.$table); |
| 237 | 237 | $tomet = $select->getColumnMeta(0); |
| 238 | 238 | return $tomet['native_type']; |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | * Check if a column name exist in a table |
| 243 | 243 | * @return Boolean column exist or not |
| 244 | 244 | */ |
| 245 | - public function checkColumnName($table,$name) |
|
| 245 | + public function checkColumnName($table, $name) |
|
| 246 | 246 | { |
| 247 | 247 | global $globalDBdriver, $globalDBname; |
| 248 | 248 | if ($globalDBdriver == 'mysql') { |
@@ -252,8 +252,8 @@ discard block |
||
| 252 | 252 | } |
| 253 | 253 | try { |
| 254 | 254 | $sth = $this->db()->prepare($query); |
| 255 | - $sth->execute(array(':database' => $globalDBname,':table' => $table,':name' => $name)); |
|
| 256 | - } catch(PDOException $e) { |
|
| 255 | + $sth->execute(array(':database' => $globalDBname, ':table' => $table, ':name' => $name)); |
|
| 256 | + } catch (PDOException $e) { |
|
| 257 | 257 | echo "error : ".$e->getMessage()."\n"; |
| 258 | 258 | } |
| 259 | 259 | $result = $sth->fetch(PDO::FETCH_ASSOC); |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | try { |
| 293 | 293 | $sth = $this->db->prepare($query); |
| 294 | 294 | $sth->execute(); |
| 295 | - } catch(PDOException $e) { |
|
| 295 | + } catch (PDOException $e) { |
|
| 296 | 296 | return "error : ".$e->getMessage()."\n"; |
| 297 | 297 | } |
| 298 | 298 | $result = $sth->fetch(PDO::FETCH_ASSOC); |