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