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

Revision 1040, 4.1 KB checked in by amuller, 15 years ago (diff)

Ticket #559 - Atualização de download de arquivos e sessão

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