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