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