source: sandbox/webservice/api/json-rpc/Expresso.php @ 5954

Revision 5954, 3.2 KB checked in by niltonneto, 12 years ago (diff)

Ticket #2507 - Corrigido método getUserId(). Renomeado classe http_request.

Line 
1<?php
2
3class Expresso {
4
5        protected $expressoVersion;
6        protected $ldapCatalog;
7        var $result;
8        var $error;
9        var $id;
10
11       
12        function __construct($id){             
13                $this->expressoVersion = substr($GLOBALS['phpgw_info']['server']['versions']['phpgwapi'],0,3);
14                $this->result   = array();
15                $this->error    = null;                                         
16                $this-> id              = $id;
17        }
18
19        protected function getResponse(){       
20                return  array(
21                                'result'        => $this->result,
22                                'error'         => $this->error,
23                                'id'            => $this->id
24                );
25        }       
26               
27        protected function getUserProfile(){
28                return array(
29                        'contactID'                     => $GLOBALS['phpgw_info']['user']['account_id'],
30                        'contactMails'          => array($GLOBALS['phpgw_info']['user']['email']),
31                        'contactPhones'         => array($GLOBALS['phpgw_info']['user']['telephonenumber']),
32                        'contactFullName'       => $GLOBALS['phpgw_info']['user']['fullname']
33                );
34        }
35        protected function getLdapCatalog(){
36                if(!$this->ldapCatalog) {
37                        $catalog_config = CreateObject("contactcenter.bo_ldap_manager");
38                        $_SESSION['phpgw_info']['expressomail']['ldap_server'] = $catalog_config ? $catalog_config->srcs[1] : null;
39                        $this->ldapCatalog = CreateObject("expressoMail1_2.ldap_functions");
40                }
41       
42                return $this->ldapCatalog;
43        }
44       
45        protected function getDb(){
46                return $GLOBALS['phpgw']->db;
47        }
48       
49       
50        protected function isLoggedIn($params){
51                if($params['auth'] != null) {
52                        list($sessionid, $kp3) = explode(":", $params['auth']);
53                        if($GLOBALS['phpgw']->session->verify($sessionid, $kp3)){                                                                       
54                                return true;
55                        }
56                        else{
57                                $this-> error = Errors::get(Errors::LOGIN_AUTH_INVALID);
58                                return false;
59                        }
60                }
61                else{
62                        $this-> error = Errors::get(Errors::LOGIN_NOT_LOGGED_IN);
63                        return false;
64                }               
65        }       
66       
67        public function getExpressoVersion(){           
68                $this->result = array('expressoVersion' =>  $this->expressoVersion);
69                return $this->getResponse();
70        }
71       
72        public function login($params){
73                if(!$this-> isLoggedIn($params))
74                {                               
75                        if($sessionid = $GLOBALS['phpgw']->session->create($params['user'], $params['password']))                                       
76                        {
77                                $this->error  = null;
78                                $this->result = array(
79                                                'auth'                  => $sessionid.":".$GLOBALS['phpgw']->session->kp3,
80                                                'profile'               => array($this->getUserProfile())
81                                        );
82                        }
83                        else
84                        {                               
85                                $this-> error = Errors::get($GLOBALS['phpgw']->session->cd_reason);
86                        }                       
87                }
88                else
89                {
90                        $this->result = array('auth' =>  $params['auth']);
91                }
92               
93                return $this->getResponse();   
94        }       
95       
96        public function logout($params){                       
97               
98                if($this->isLoggedIn($params))
99                {
100                        if (file_exists($GLOBALS['phpgw_info']['server']['temp_dir'].SEP.$_SESSION['phpgw_session']['session_id']))     
101                        {
102                                $dh = opendir($GLOBALS['phpgw_info']['server']['temp_dir']. SEP . $_SESSION['phpgw_session']['session_id']);
103                                while ($file = readdir($dh))
104                                {
105                                        if ($file != '.' && $file != '..')
106                                        {
107                                                unlink($GLOBALS['phpgw_info']['server']['temp_dir'].SEP.$_SESSION['phpgw_session']['session_id'].SEP.$file);
108                                        }
109                                }
110                                rmdir($GLOBALS['phpgw_info']['server']['temp_dir'].SEP.$_SESSION['phpgw_session']['session_id']);
111                        }
112                        $GLOBALS['phpgw']->hooks->process('logout');
113                        $GLOBALS['phpgw']->session->destroy($_SESSION['phpgw_session']['session_id'], $GLOBALS['kp3']);
114                        $this->result = true;
115                }
116               
117                return $this->getResponse();
118        }       
119}
Note: See TracBrowser for help on using the repository browser.