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

Revision 5681, 2.6 KB checked in by niltonneto, 12 years ago (diff)

Ticket #2507 - Implementada primeira parte do método Catalog.getUserContacts().

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