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