[2] | 1 | <?php |
---|
| 2 | class Functions{ |
---|
[72] | 3 | function CallVoipConnect($params){ |
---|
| 4 | $fromNumber = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['telephone_number']; |
---|
| 5 | if(!$fromNumber) |
---|
| 6 | return false; |
---|
| 7 | $fromNumber = substr($fromNumber,strlen($fromNumber) - 4, strlen($fromNumber) - 1); |
---|
| 8 | $toNumber = $params['to'] ? substr($params['to'],strlen($params['to']) - 4, strlen($params['to']) - 1) : 0; |
---|
| 9 | |
---|
| 10 | $voipServer = $_SESSION['phpgw_info']['expressomail']['server']['voip_server']; |
---|
| 11 | $voipUrl = $_SESSION['phpgw_info']['expressomail']['server']['voip_url']; |
---|
| 12 | $voipPort = $_SESSION['phpgw_info']['expressomail']['server']['voip_port']; |
---|
| 13 | |
---|
| 14 | // Se for celular, passa os digitos do número e conecta com outro VoIP Server..... |
---|
| 15 | if($params['typePhone'] == 'mob'){ |
---|
| 16 | $toNumber = $params['to']; |
---|
| 17 | $voipServer = $_SESSION['phpgw_info']['expressomail']['server']['voip_server']; |
---|
| 18 | $voipUrl = $_SESSION['phpgw_info']['expressomail']['server']['voip_url']; |
---|
| 19 | $voipPort = $_SESSION['phpgw_info']['expressomail']['server']['voip_port']; |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | if(!$voipServer || !$voipUrl || !$voipPort) |
---|
| 23 | return false; |
---|
| 24 | $url = "http://".$voipServer.":".$voipPort.$voipUrl."?magic=1333&acao=liga&ramal=".$fromNumber."&numero=".$toNumber; |
---|
| 25 | $sMethod = 'GET '; |
---|
| 26 | $crlf = "\r\n"; |
---|
| 27 | $sRequest = " HTTP/1.1" . $crlf; |
---|
| 28 | $sRequest .= "Host: localhost" . $crlf; |
---|
| 29 | $sRequest .= "Accept: */* " . $crlf; |
---|
| 30 | $sRequest .= "Connection: Close" . $crlf . $crlf; |
---|
| 31 | $sRequest = $sMethod . $url . $sRequest; |
---|
| 32 | $sockHttp = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); |
---|
| 33 | if (!$sockHttp) { |
---|
| 34 | return false; |
---|
| 35 | } |
---|
| 36 | $resSocketConnect = socket_connect($sockHttp, $voipServer, $voipPort); |
---|
| 37 | if (!$resSocketConnect) { |
---|
| 38 | return false; |
---|
| 39 | } |
---|
| 40 | $resSocketWrite = socket_write($sockHttp, $sRequest, strlen($sRequest)); |
---|
| 41 | if (!$resSocketWrite) { |
---|
| 42 | return false; |
---|
| 43 | } |
---|
| 44 | $sResponse = ''; |
---|
| 45 | while ($sRead = socket_read($sockHttp, 512)) { |
---|
| 46 | $sResponse .= $sRead; |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | socket_close($sockHttp); |
---|
| 50 | $pos = strpos($sResponse, $crlf . $crlf); |
---|
| 51 | return substr($sResponse, $pos + 2 * strlen($crlf)); |
---|
| 52 | } |
---|
| 53 | |
---|
[2] | 54 | function getDirContents($dir){ |
---|
| 55 | //$dir = dirname($dir); |
---|
| 56 | |
---|
| 57 | if (!is_dir($dir)) { |
---|
| 58 | return 'Error: Cannot load files in :'. $dir.' !'; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | if ($root=@opendir($dir)) { |
---|
| 62 | |
---|
| 63 | while ($file=readdir($root)) { |
---|
| 64 | if($file!="." && $file!="..") |
---|
| 65 | $files[]=$dir."/".$file; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | return $files; |
---|
| 71 | } |
---|
| 72 | |
---|
[56] | 73 | function getFilesJs($includeFiles = '', $update_version = ''){ |
---|
[2] | 74 | |
---|
| 75 | $files = $this -> getDirContents('js'); |
---|
| 76 | $str_files = ''; |
---|
| 77 | |
---|
[56] | 78 | if($includeFiles) { |
---|
| 79 | $includeFiles = explode(",",trim($includeFiles)); |
---|
[2] | 80 | // Bug fixed for array_search function |
---|
[56] | 81 | $includeFiles[count($includeFiles)] = $includeFiles[0]; |
---|
| 82 | $includeFiles[0] = null; |
---|
| 83 | // End Bug fixed. |
---|
[2] | 84 | } |
---|
[56] | 85 | for($i = 0; $i < count($files); $i++) { |
---|
[2] | 86 | if(count(explode('.js',$files[$i])) > 1) { |
---|
[56] | 87 | if($includeFiles && array_search(trim($files[$i]),$includeFiles)){ |
---|
[2] | 88 | $str_files .= "<script src='".$files[$i]."?".$update_version."' type='text/javascript'></script>"; |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | return $str_files; |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | function getReturnExecuteForm(){ |
---|
| 97 | $response = $_SESSION['response']; |
---|
| 98 | $_SESSION['response'] = null; |
---|
| 99 | return $response; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | function getLang($key){ |
---|
[94] | 103 | if ($_SESSION['phpgw_info']['expressomail']['lang'][$key]) |
---|
[72] | 104 | return $_SESSION['phpgw_info']['expressomail']['lang'][$key]; |
---|
[94] | 105 | else |
---|
| 106 | return ($key . '*'); |
---|
[2] | 107 | } |
---|
[51] | 108 | |
---|
| 109 | function get_preferences() { |
---|
| 110 | return $_SESSION['phpgw_info']['user']['preferences']['expressoMail']; |
---|
| 111 | } |
---|
[1384] | 112 | // Unicode Conversor: convert everything from UTF-8 into an NCR[Numeric Character Reference] |
---|
| 113 | function utf8_to_ncr($content) { |
---|
| 114 | $result = ""; |
---|
| 115 | while ($strlen = mb_strlen($content)) { |
---|
| 116 | $c = mb_substr($content, 0, 1, "UTF-8"); |
---|
| 117 | $h = ord($c{0}); |
---|
| 118 | if ($h <= 0x7F || $h < 0xC2) { |
---|
[2089] | 119 | // fixing curly brackets |
---|
| 120 | if($h == 0x7B || $h == 0x7D) |
---|
| 121 | $result .= "&#" . $h . ";"; |
---|
| 122 | else |
---|
| 123 | $result .= $c; |
---|
[1384] | 124 | } |
---|
| 125 | else if ($h <= 0xDF) { |
---|
| 126 | $h = ($h & 0x1F) << 6 | (ord($c{1}) & 0x3F); |
---|
| 127 | $result .= "&#" . $h . ";"; |
---|
| 128 | } else if ($h <= 0xEF) { |
---|
| 129 | $h = ($h & 0x0F) << 12 | (ord($c{1}) & 0x3F) << 6 | (ord($c{2}) & 0x3F); |
---|
| 130 | $result .= "&#" . $h . ";"; |
---|
| 131 | } else if ($h <= 0xF4) { |
---|
| 132 | $h = ($h & 0x0F) << 18 | (ord($c{1}) & 0x3F) << 12 | (ord($c{2}) & 0x3F) << 6 | (ord($c{3}) & 0x3F); |
---|
| 133 | $result .= "&#" . $h . ";"; |
---|
| 134 | } |
---|
| 135 | $content = mb_substr( $content, 1, $strlen, "UTF-8"); |
---|
| 136 | } |
---|
| 137 | return mb_convert_encoding($result,"UTF-8"); |
---|
| 138 | } |
---|
| 139 | } |
---|
[1037] | 140 | ?> |
---|