source: sandbox/2.3-MailArchiver/expressoMail1_2/inc/class.functions.inc.php @ 6779

Revision 6779, 6.3 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2946 - Liberado Expresso(branch 2.3) integrado ao MailArchiver?.

Line 
1<?php
2        class Functions{
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
34                function CallVoipConnect($params){
35                        $fromNumber = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['telephone_number'];
36                        if(!$fromNumber)
37                                return false;
38                        $fromNumber = substr($fromNumber,strlen($fromNumber) - 4, strlen($fromNumber) - 1);
39                        $toNumber       = $params['to'] ? substr($params['to'],strlen($params['to']) - 4, strlen($params['to']) - 1) : 0;
40                       
41                        $voipServer     = $_SESSION['phpgw_info']['expressomail']['server']['voip_server'];
42                        $voipUrl        = $_SESSION['phpgw_info']['expressomail']['server']['voip_url'];
43                        $voipPort       = $_SESSION['phpgw_info']['expressomail']['server']['voip_port'];
44                       
45                        // Se for celular, passa os digitos do número e conecta com outro VoIP Server.....
46                        if($params['typePhone'] == 'mob'){
47                                $toNumber       = $params['to'];
48                                $voipServer     = $_SESSION['phpgw_info']['expressomail']['server']['voip_server'];
49                                $voipUrl        = $_SESSION['phpgw_info']['expressomail']['server']['voip_url'];
50                                $voipPort       = $_SESSION['phpgw_info']['expressomail']['server']['voip_port'];                               
51                        }       
52                               
53                        if(!$voipServer || !$voipUrl || !$voipPort)
54                                return false;
55                        $url            = "http://".$voipServer.":".$voipPort.$voipUrl."?magic=1333&acao=liga&ramal=".$fromNumber."&numero=".$toNumber;                 
56                        $sMethod = 'GET ';
57            $crlf = "\r\n";
58            $sRequest = " HTTP/1.1" . $crlf;
59            $sRequest .= "Host: localhost" . $crlf;
60            $sRequest .= "Accept: */* " . $crlf;
61            $sRequest .= "Connection: Close" . $crlf . $crlf;           
62            $sRequest = $sMethod . $url . $sRequest;   
63            $sockHttp = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);           
64            if (!$sockHttp)  {
65                return false;
66            }
67            $resSocketConnect = socket_connect($sockHttp, $voipServer, $voipPort);
68            if (!$resSocketConnect) {
69                return false;
70            }
71            $resSocketWrite = socket_write($sockHttp, $sRequest, strlen($sRequest));
72            if (!$resSocketWrite) {
73                return false;
74            }   
75            $sResponse = '';   
76            while ($sRead = socket_read($sockHttp, 512)) {
77                $sResponse .= $sRead;
78            }           
79           
80            socket_close($sockHttp);           
81            $pos = strpos($sResponse, $crlf . $crlf);
82            return substr($sResponse, $pos + 2 * strlen($crlf));                                                                       
83                }
84
85                function getDirContents($dir){
86                        //$dir = dirname($dir);
87       
88                        if (!is_dir($dir))      {
89                                        return 'Error: Cannot load files in :'. $dir.' !';
90                        }
91                       
92                        if ($root=@opendir($dir))       {
93                       
94                       while ($file=readdir($root))     {                 
95                           if($file!="." && $file!="..")
96                                   $files[]=$dir."/".$file;           
97                       }
98                       
99                        }
100                       
101                   return $files;
102                }
103                               
104                function getFilesJs($includeFiles = '', $update_version = ''){
105                       
106                        $files = $this -> getDirContents('js');
107                        $str_files = '';
108                       
109                        if($includeFiles) {
110                                $includeFiles = explode(",",trim($includeFiles));
111                                // Bug fixed for array_search function
112                                $includeFiles[count($includeFiles)] = $includeFiles[0];
113                                $includeFiles[0] = null;
114                                // End Bug fixed.
115                        }                                                                                                               
116                        for($i = 0; $i < count($files); $i++) {                         
117                                if(count(explode('.js',$files[$i])) > 1) {
118                                        if($includeFiles  && array_search(trim($files[$i]),$includeFiles)){     
119                                                $str_files .= "<script src='".$files[$i]."?".$update_version."' type='text/javascript'></script>";                                             
120                                        }
121                                }
122                        }
123                       
124                        return $str_files;
125                }                                                               
126
127                function getReturnExecuteForm(){
128                        $response = $_SESSION['response'];
129                        $_SESSION['response'] = null;
130                        return $response;
131                }
132                function getLang($key){
133                        if ($_SESSION['phpgw_info']['expressomail']['lang'][$key])
134                                return $_SESSION['phpgw_info']['expressomail']['lang'][$key];                   
135                        else
136                                return ($key . '*');
137                }
138
139                function get_preferences()      {
140                        return $_SESSION['phpgw_info']['user']['preferences']['expressoMail'];
141                }
142                // Unicode Conversor: convert everything from UTF-8 into an NCR[Numeric Character Reference]
143                function utf8_to_ncr($content)  {
144            $result = "";           
145            while ($strlen = mb_strlen($content)) {
146                $c = mb_substr($content, 0, 1, "UTF-8");
147                $h = ord($c{0});   
148                    if ($h <= 0x7F || $h < 0xC2) {
149                            // fixing curly brackets
150                            if($h == 0x7B || $h == 0x7D)
151                                    $result .= "&#" . $h . ";";
152                            else
153                                    $result .= $c;
154                    }
155                        else if ($h <= 0xDF) {
156                        $h = ($h & 0x1F) << 6 | (ord($c{1}) & 0x3F);
157                        $result .= "&#" . $h . ";";
158                    } else if ($h <= 0xEF) {
159                        $h = ($h & 0x0F) << 12 | (ord($c{1}) & 0x3F) << 6 | (ord($c{2}) & 0x3F);
160                        $result .= "&#" . $h . ";";
161                    } else if ($h <= 0xF4) {
162                        $h = ($h & 0x0F) << 18 | (ord($c{1}) & 0x3F) << 12 | (ord($c{2}) & 0x3F) << 6 | (ord($c{3}) & 0x3F);
163                        $result .= "&#" . $h . ";";
164                    }               
165                $content = mb_substr( $content, 1, $strlen, "UTF-8");
166            }
167            return mb_convert_encoding($result,"UTF-8");
168        }
169    }   
170?>
Note: See TracBrowser for help on using the repository browser.