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

Revision 5889, 3.7 KB checked in by niltonneto, 12 years ago (diff)

Ticket #2507 - Implementado métodos getUserProfile() e getUserPreferences().

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