1 | <?php |
---|
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 | \**************************************************************************/ |
---|
12 | class Functions{ |
---|
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 | |
---|
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 | |
---|
83 | function getFilesJs($includeFiles = '', $update_version = ''){ |
---|
84 | |
---|
85 | $files = $this -> getDirContents('js'); |
---|
86 | $str_files = ''; |
---|
87 | |
---|
88 | if($includeFiles) { |
---|
89 | $includeFiles = explode(",",trim($includeFiles)); |
---|
90 | // Bug fixed for array_search function |
---|
91 | $includeFiles[count($includeFiles)] = $includeFiles[0]; |
---|
92 | $includeFiles[0] = null; |
---|
93 | // End Bug fixed. |
---|
94 | } |
---|
95 | for($i = 0; $i < count($files); $i++) { |
---|
96 | if(count(explode('.js',$files[$i])) > 1) { |
---|
97 | if($includeFiles && array_search(trim($files[$i]),$includeFiles)){ |
---|
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 | } |
---|
111 | function getLang($key){ |
---|
112 | if ($_SESSION['phpgw_info']['expressomail']['lang'][$key]) |
---|
113 | return $_SESSION['phpgw_info']['expressomail']['lang'][$key]; |
---|
114 | else |
---|
115 | return ($key . '*'); |
---|
116 | } |
---|
117 | |
---|
118 | function get_preferences() { |
---|
119 | return $_SESSION['phpgw_info']['user']['preferences']['expressoMail']; |
---|
120 | } |
---|
121 | // Unicode Conversor: convert everything from UTF-8 into an NCR[Numeric Character Reference] |
---|
122 | function utf8_to_ncr($content) { |
---|
123 | $result = ""; |
---|
124 | while ($strlen = mb_strlen($content)) { |
---|
125 | $c = mb_substr($content, 0, 1, "UTF-8"); |
---|
126 | $h = ord($c{0}); |
---|
127 | if ($h <= 0x7F || $h < 0xC2) { |
---|
128 | // fixing curly brackets |
---|
129 | if($h == 0x7B || $h == 0x7D) |
---|
130 | $result .= "&#" . $h . ";"; |
---|
131 | else |
---|
132 | $result .= $c; |
---|
133 | } |
---|
134 | else if ($h <= 0xDF) { |
---|
135 | $h = ($h & 0x1F) << 6 | (ord($c{1}) & 0x3F); |
---|
136 | $result .= "&#" . $h . ";"; |
---|
137 | } else if ($h <= 0xEF) { |
---|
138 | $h = ($h & 0x0F) << 12 | (ord($c{1}) & 0x3F) << 6 | (ord($c{2}) & 0x3F); |
---|
139 | $result .= "&#" . $h . ";"; |
---|
140 | } else if ($h <= 0xF4) { |
---|
141 | $h = ($h & 0x0F) << 18 | (ord($c{1}) & 0x3F) << 12 | (ord($c{2}) & 0x3F) << 6 | (ord($c{3}) & 0x3F); |
---|
142 | $result .= "&#" . $h . ";"; |
---|
143 | } |
---|
144 | $content = mb_substr( $content, 1, $strlen, "UTF-8"); |
---|
145 | } |
---|
146 | return mb_convert_encoding($result,"UTF-8"); |
---|
147 | } |
---|
148 | } |
---|
149 | ?> |
---|