source: companies/celepar/expressoMail1_2/inc/class.functions.inc.php @ 763

Revision 763, 3.9 KB checked in by niltonneto, 15 years ago (diff)

Importação inicial do Expresso da Celepar

Line 
1<?php
2        class Functions{
3               
4               
5                function CallVoipConnect($params){
6                        $fromNumber = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['telephone_number'];
7                        if(!$fromNumber)
8                                return false;
9                        $fromNumber = substr($fromNumber,strlen($fromNumber) - 4, strlen($fromNumber) - 1);
10                        $toNumber       = $params['to'] ? substr($params['to'],strlen($params['to']) - 4, strlen($params['to']) - 1) : 0;
11                       
12                        $voipServer     = $_SESSION['phpgw_info']['expressomail']['server']['voip_server'];
13                        $voipUrl        = $_SESSION['phpgw_info']['expressomail']['server']['voip_url'];
14                        $voipPort       = $_SESSION['phpgw_info']['expressomail']['server']['voip_port'];
15                       
16                        // Se for celular, passa os digitos do número e conecta com outro VoIP Server.....
17                        if($params['typePhone'] == 'mob'){
18                                $toNumber       = $params['to'];
19                                $voipServer     = $_SESSION['phpgw_info']['expressomail']['server']['voip_server'];
20                                $voipUrl        = $_SESSION['phpgw_info']['expressomail']['server']['voip_url'];
21                                $voipPort       = $_SESSION['phpgw_info']['expressomail']['server']['voip_port'];                               
22                        }       
23                               
24                        if(!$voipServer || !$voipUrl || !$voipPort)
25                                return false;
26                        $url            = "http://".$voipServer.":".$voipPort.$voipUrl."?magic=1333&acao=liga&ramal=".$fromNumber."&numero=".$toNumber;                 
27                        $sMethod = 'GET ';
28            $crlf = "\r\n";
29            $sRequest = " HTTP/1.1" . $crlf;
30            $sRequest .= "Host: localhost" . $crlf;
31            $sRequest .= "Accept: */* " . $crlf;
32            $sRequest .= "Connection: Close" . $crlf . $crlf;           
33            $sRequest = $sMethod . $url . $sRequest;   
34            $sockHttp = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);           
35            if (!$sockHttp)  {
36                return false;
37            }
38            $resSocketConnect = socket_connect($sockHttp, $voipServer, $voipPort);
39            if (!$resSocketConnect) {
40                return false;
41            }
42            $resSocketWrite = socket_write($sockHttp, $sRequest, strlen($sRequest));
43            if (!$resSocketWrite) {
44                return false;
45            }   
46            $sResponse = '';   
47            while ($sRead = socket_read($sockHttp, 512)) {
48                $sResponse .= $sRead;
49            }           
50           
51            socket_close($sockHttp);           
52            $pos = strpos($sResponse, $crlf . $crlf);
53            return substr($sResponse, $pos + 2 * strlen($crlf));                                                                       
54                }
55
56                function getDirContents($dir){
57                        //$dir = dirname($dir);
58       
59                        if (!is_dir($dir))      {
60                                        return 'Error: Cannot load files in :'. $dir.' !';
61                        }
62                       
63                        if ($root=@opendir($dir))       {
64                       
65                       while ($file=readdir($root))     {                 
66                           if($file!="." && $file!="..")
67                                   $files[]=$dir."/".$file;           
68                       }
69                       
70                        }
71                       
72                   return $files;
73                }
74                               
75                function getFilesJs($includeFiles = '', $update_version = ''){
76                       
77                        $files = $this -> getDirContents('js');
78                        $str_files = '';
79                       
80                        if($includeFiles) {
81                                $includeFiles = explode(",",trim($includeFiles));
82                                // Bug fixed for array_search function
83                                $includeFiles[count($includeFiles)] = $includeFiles[0];
84                                $includeFiles[0] = null;
85                                // End Bug fixed.
86                        }                                                                                                               
87                        for($i = 0; $i < count($files); $i++) {                         
88                                if(count(explode('.js',$files[$i])) > 1) {
89                                        if($includeFiles  && array_search(trim($files[$i]),$includeFiles)){     
90                                                $str_files .= "<script src='".$files[$i]."?".$update_version."' type='text/javascript'></script>";                                             
91                                        }
92                                }
93                        }
94                       
95                        return $str_files;
96                }                                                               
97
98                function getReturnExecuteForm(){
99                        $response = $_SESSION['response'];
100                        $_SESSION['response'] = null;
101                        return $response;
102                }
103               
104                function getLang($key){
105                        if ($_SESSION['phpgw_info']['expressomail']['lang'][$key])
106                        return $_SESSION['phpgw_info']['expressomail']['lang'][$key];                   
107                        else
108                                return ($key . '*');
109                }
110
111                function get_preferences()      {
112                        return $_SESSION['phpgw_info']['user']['preferences']['expressoMail'];
113                }
114        }
115?>
Note: See TracBrowser for help on using the repository browser.