source: trunk/expressoMail1_2/inc/class.functions.inc.php @ 5509

Revision 5509, 7.0 KB checked in by gustavo, 12 years ago (diff)

Ticket #2488 - Adicionar cabecalho de licenca em arquivos que nao o possuem

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