1 | <?php |
---|
2 | class Functions{ |
---|
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 | |
---|
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 | |
---|
73 | function getFilesJs($includeFiles = '', $update_version = ''){ |
---|
74 | |
---|
75 | $files = $this -> getDirContents('js'); |
---|
76 | $str_files = ''; |
---|
77 | |
---|
78 | if($includeFiles) { |
---|
79 | $includeFiles = explode(",",trim($includeFiles)); |
---|
80 | // Bug fixed for array_search function |
---|
81 | $includeFiles[count($includeFiles)] = $includeFiles[0]; |
---|
82 | $includeFiles[0] = null; |
---|
83 | // End Bug fixed. |
---|
84 | } |
---|
85 | for($i = 0; $i < count($files); $i++) { |
---|
86 | if(count(explode('.js',$files[$i])) > 1) { |
---|
87 | if($includeFiles && array_search(trim($files[$i]),$includeFiles)){ |
---|
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 | function getLang($key){ |
---|
102 | if ($_SESSION['phpgw_info']['expressomail']['lang'][$key]) |
---|
103 | return $_SESSION['phpgw_info']['expressomail']['lang'][$key]; |
---|
104 | else |
---|
105 | return ($key . '*'); |
---|
106 | } |
---|
107 | |
---|
108 | function get_preferences() { |
---|
109 | return $_SESSION['phpgw_info']['user']['preferences']['expressoMail']; |
---|
110 | } |
---|
111 | // Unicode Conversor: convert everything from UTF-8 into an NCR[Numeric Character Reference] |
---|
112 | function utf8_to_ncr($content) { |
---|
113 | $result = ""; |
---|
114 | while ($strlen = mb_strlen($content)) { |
---|
115 | $c = mb_substr($content, 0, 1, "UTF-8"); |
---|
116 | $h = ord($c{0}); |
---|
117 | if ($h <= 0x7F || $h < 0xC2) { |
---|
118 | $result .= $c; |
---|
119 | } |
---|
120 | else if ($h <= 0xDF) { |
---|
121 | $h = ($h & 0x1F) << 6 | (ord($c{1}) & 0x3F); |
---|
122 | $result .= "&#" . $h . ";"; |
---|
123 | } else if ($h <= 0xEF) { |
---|
124 | $h = ($h & 0x0F) << 12 | (ord($c{1}) & 0x3F) << 6 | (ord($c{2}) & 0x3F); |
---|
125 | $result .= "&#" . $h . ";"; |
---|
126 | } else if ($h <= 0xF4) { |
---|
127 | $h = ($h & 0x0F) << 18 | (ord($c{1}) & 0x3F) << 12 | (ord($c{2}) & 0x3F) << 6 | (ord($c{3}) & 0x3F); |
---|
128 | $result .= "&#" . $h . ";"; |
---|
129 | } |
---|
130 | $content = mb_substr( $content, 1, $strlen, "UTF-8"); |
---|
131 | } |
---|
132 | return mb_convert_encoding($result,"UTF-8"); |
---|
133 | } |
---|
134 | } |
---|
135 | ?> |
---|