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

Revision 5714, 2.8 KB checked in by niltonneto, 12 years ago (diff)

Ticket #2507 - Corrigido problema do id_contact no método getImagePicture().

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 getUserId(){
28                return $GLOBALS['phpgw_info']['user']['account_id'];
29        }
30       
31        protected function getLdapCatalog(){
32                if(!$this->ldapCatalog) {
33                        $catalog_config = CreateObject("contactcenter.bo_ldap_manager");
34                        $_SESSION['phpgw_info']['expressomail']['ldap_server'] = $catalog_config ? $catalog_config->srcs[1] : null;
35                        $this->ldapCatalog = CreateObject("expressoMail1_2.ldap_functions");
36                }
37       
38                return $this->ldapCatalog;
39        }
40       
41        protected function getDb(){
42                return $GLOBALS['phpgw']->db;
43        }
44       
45       
46        protected function isLoggedIn($params){
47                list($sessionid, $kp3) = explode(":", $params['auth']);
48                if($GLOBALS['phpgw']->session->verify($sessionid, $kp3)){                                                                       
49                        return true;
50                }
51                else{
52                        $this-> error = "You are not logged in";
53                        return false;
54                }               
55        }       
56       
57        public function getExpressoVersion(){           
58                $this->result = array('expressoVersion' =>  $this->expressoVersion);
59                return $this->getResponse();
60        }
61       
62        public function login($params){
63                if(!$this-> isLoggedIn($params))
64                {                               
65                        if($params['auth'] != "")
66                        {       
67                                $this->error  = "Your auth is invalid";
68                               
69                        }
70                        elseif($sessionid = $GLOBALS['phpgw']->session->create($params['user'], $params['password']))                                   
71                        {
72                                $this->error  = null;
73                                $this->result = array('auth' =>  $sessionid.":".$GLOBALS['phpgw']->session->kp3);
74                        }
75                        else
76                        {                               
77                                $this-> error = $GLOBALS['phpgw']->session->reason;
78                        }                       
79                }
80                else
81                {
82                        $this->result = array('auth' =>  $params['auth']);
83                }
84               
85                return $this->getResponse();   
86        }       
87       
88        public function logout($params){                       
89               
90                if($this->isLoggedIn($params))
91                {
92                        if (file_exists($GLOBALS['phpgw_info']['server']['temp_dir'].SEP.$_SESSION['phpgw_session']['session_id']))     
93                        {
94                                $dh = opendir($GLOBALS['phpgw_info']['server']['temp_dir']. SEP . $_SESSION['phpgw_session']['session_id']);
95                                while ($file = readdir($dh))
96                                {
97                                        if ($file != '.' && $file != '..')
98                                        {
99                                                unlink($GLOBALS['phpgw_info']['server']['temp_dir'].SEP.$_SESSION['phpgw_session']['session_id'].SEP.$file);
100                                        }
101                                }
102                                rmdir($GLOBALS['phpgw_info']['server']['temp_dir'].SEP.$_SESSION['phpgw_session']['session_id']);
103                        }
104                        $GLOBALS['phpgw']->hooks->process('logout');
105                        $GLOBALS['phpgw']->session->destroy($_SESSION['phpgw_session']['session_id'], $GLOBALS['kp3']);
106                        $this->result = true;
107                }
108               
109                return $this->getResponse();
110        }       
111}
Note: See TracBrowser for help on using the repository browser.