[2] | 1 | <?php |
---|
[1036] | 2 | $GLOBALS['phpgw_info']['flags'] = array( |
---|
| 3 | 'currentapp' => 'expressoMail1_2', |
---|
| 4 | 'nonavbar' => true, |
---|
| 5 | 'noheader' => true |
---|
| 6 | ); |
---|
| 7 | |
---|
| 8 | require_once $_SERVER[ 'DOCUMENT_ROOT' ] . '/header.inc.php'; |
---|
[2] | 9 | class Functions{ |
---|
| 10 | |
---|
| 11 | |
---|
[72] | 12 | function CallVoipConnect($params){ |
---|
| 13 | $fromNumber = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['telephone_number']; |
---|
| 14 | if(!$fromNumber) |
---|
| 15 | return false; |
---|
| 16 | $fromNumber = substr($fromNumber,strlen($fromNumber) - 4, strlen($fromNumber) - 1); |
---|
| 17 | $toNumber = $params['to'] ? substr($params['to'],strlen($params['to']) - 4, strlen($params['to']) - 1) : 0; |
---|
| 18 | |
---|
| 19 | $voipServer = $_SESSION['phpgw_info']['expressomail']['server']['voip_server']; |
---|
| 20 | $voipUrl = $_SESSION['phpgw_info']['expressomail']['server']['voip_url']; |
---|
| 21 | $voipPort = $_SESSION['phpgw_info']['expressomail']['server']['voip_port']; |
---|
| 22 | |
---|
| 23 | // Se for celular, passa os digitos do número e conecta com outro VoIP Server..... |
---|
| 24 | if($params['typePhone'] == 'mob'){ |
---|
| 25 | $toNumber = $params['to']; |
---|
| 26 | $voipServer = $_SESSION['phpgw_info']['expressomail']['server']['voip_server']; |
---|
| 27 | $voipUrl = $_SESSION['phpgw_info']['expressomail']['server']['voip_url']; |
---|
| 28 | $voipPort = $_SESSION['phpgw_info']['expressomail']['server']['voip_port']; |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | if(!$voipServer || !$voipUrl || !$voipPort) |
---|
| 32 | return false; |
---|
| 33 | $url = "http://".$voipServer.":".$voipPort.$voipUrl."?magic=1333&acao=liga&ramal=".$fromNumber."&numero=".$toNumber; |
---|
| 34 | $sMethod = 'GET '; |
---|
| 35 | $crlf = "\r\n"; |
---|
| 36 | $sRequest = " HTTP/1.1" . $crlf; |
---|
| 37 | $sRequest .= "Host: localhost" . $crlf; |
---|
| 38 | $sRequest .= "Accept: */* " . $crlf; |
---|
| 39 | $sRequest .= "Connection: Close" . $crlf . $crlf; |
---|
| 40 | $sRequest = $sMethod . $url . $sRequest; |
---|
| 41 | $sockHttp = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); |
---|
| 42 | if (!$sockHttp) { |
---|
| 43 | return false; |
---|
| 44 | } |
---|
| 45 | $resSocketConnect = socket_connect($sockHttp, $voipServer, $voipPort); |
---|
| 46 | if (!$resSocketConnect) { |
---|
| 47 | return false; |
---|
| 48 | } |
---|
| 49 | $resSocketWrite = socket_write($sockHttp, $sRequest, strlen($sRequest)); |
---|
| 50 | if (!$resSocketWrite) { |
---|
| 51 | return false; |
---|
| 52 | } |
---|
| 53 | $sResponse = ''; |
---|
| 54 | while ($sRead = socket_read($sockHttp, 512)) { |
---|
| 55 | $sResponse .= $sRead; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | socket_close($sockHttp); |
---|
| 59 | $pos = strpos($sResponse, $crlf . $crlf); |
---|
| 60 | return substr($sResponse, $pos + 2 * strlen($crlf)); |
---|
| 61 | } |
---|
| 62 | |
---|
[2] | 63 | function getDirContents($dir){ |
---|
| 64 | //$dir = dirname($dir); |
---|
| 65 | |
---|
| 66 | if (!is_dir($dir)) { |
---|
| 67 | return 'Error: Cannot load files in :'. $dir.' !'; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | if ($root=@opendir($dir)) { |
---|
| 71 | |
---|
| 72 | while ($file=readdir($root)) { |
---|
| 73 | if($file!="." && $file!="..") |
---|
| 74 | $files[]=$dir."/".$file; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | return $files; |
---|
| 80 | } |
---|
| 81 | |
---|
[56] | 82 | function getFilesJs($includeFiles = '', $update_version = ''){ |
---|
[2] | 83 | |
---|
| 84 | $files = $this -> getDirContents('js'); |
---|
| 85 | $str_files = ''; |
---|
| 86 | |
---|
[56] | 87 | if($includeFiles) { |
---|
| 88 | $includeFiles = explode(",",trim($includeFiles)); |
---|
[2] | 89 | // Bug fixed for array_search function |
---|
[56] | 90 | $includeFiles[count($includeFiles)] = $includeFiles[0]; |
---|
| 91 | $includeFiles[0] = null; |
---|
| 92 | // End Bug fixed. |
---|
[2] | 93 | } |
---|
[56] | 94 | for($i = 0; $i < count($files); $i++) { |
---|
[2] | 95 | if(count(explode('.js',$files[$i])) > 1) { |
---|
[56] | 96 | if($includeFiles && array_search(trim($files[$i]),$includeFiles)){ |
---|
[2] | 97 | $str_files .= "<script src='".$files[$i]."?".$update_version."' type='text/javascript'></script>"; |
---|
| 98 | } |
---|
| 99 | } |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | return $str_files; |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | function getReturnExecuteForm(){ |
---|
| 106 | $response = $_SESSION['response']; |
---|
| 107 | $_SESSION['response'] = null; |
---|
| 108 | return $response; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | function getLang($key){ |
---|
[94] | 112 | if ($_SESSION['phpgw_info']['expressomail']['lang'][$key]) |
---|
[72] | 113 | return $_SESSION['phpgw_info']['expressomail']['lang'][$key]; |
---|
[94] | 114 | else |
---|
| 115 | return ($key . '*'); |
---|
[2] | 116 | } |
---|
[51] | 117 | |
---|
| 118 | function get_preferences() { |
---|
| 119 | return $_SESSION['phpgw_info']['user']['preferences']['expressoMail']; |
---|
| 120 | } |
---|
[2] | 121 | } |
---|
| 122 | ?> |
---|