source: sandbox/webservice/api/rest/core/Expresso.php @ 6110

Revision 6110, 3.6 KB checked in by niltonneto, 12 years ago (diff)

Ticket #2507 - Alterado contactID para user DN.Adicionado array de aplicações.

  • Property svn:executable set to *
Line 
1<?php
2class Expresso extends Resource {
3
4        protected $expressoVersion;
5        protected $ldapCatalog;
6        private $request;
7        private $params;
8        private $result;
9        private $error;
10        private $id;
11       
12        function __construct($id){
13                $GLOBALS['phpgw_info'] = array(
14                                'flags' => array(
15                                                'currentapp'            => 'login',
16                                                'noheader'              => True,
17                                                'disable_Template_class' => True
18                                )
19                );
20               
21                include_once('../../header.inc.php');
22                $this->expressoVersion = substr($GLOBALS['phpgw_info']['server']['versions']['phpgwapi'],0,3);                 
23        }
24       
25        protected function setRequest($request){
26                $this->request = $request;
27        }
28       
29        public function getRequest(){
30                return $this->request;
31        }
32       
33        protected function setResult($result){
34                $this->result = $result;
35        }
36       
37        public function getResult(){
38                return $this->result;
39        }
40       
41        protected function setId($id){
42                $this->id = $id;
43        }
44       
45        public function getId(){
46                return $this->id;
47        }
48       
49        protected function setParams($params){         
50                $this->params = $params;
51        }
52       
53        public function getParams(){   
54                return $this->params;
55        }
56       
57        public function getParam($param){
58                return $this->params->$param;
59        }
60       
61        public function setError($error) {
62                $this-> error = $error;
63        }
64       
65        protected function getError() {
66                return $this-> error;
67        }
68       
69        public function post($request){
70                $this->setRequest($request);           
71                parse_str($request->data, &$array);             
72                $data = (object)$array;         
73                if($data){
74                        if($data->params){                                                             
75                                $this->setParams(json_decode($data->params));
76                        }
77                        if($data->id)
78                                $this->setId($data->id);
79                }
80        }       
81       
82        public function get($request){
83                $response = new Response($request);
84                $response->code = Response::OK;
85                $response->addHeader('content-type', 'text/html');             
86                $response->body = "<H4>Metodo GET nao permitido para este recurso.</H4>";               
87                return $response;
88        }
89       
90        public function getResponse(){
91                $response = new Response($this->getRequest());
92                $response->code = Response::OK;
93                $response->addHeader('content-type', 'application/json');
94
95                if($this->getId())
96                        $body['id']     = $this->getId();
97                if($this->getResult())
98                        $body['result'] = $this->getResult();
99                else
100                        throw new ResponseException("",Errors::E_UNKNOWN_ERROR);
101               
102                $response->body = json_encode($body);
103               
104                return $response;
105        }
106               
107        protected function getUserProfile(){
108                $user_id = $GLOBALS['phpgw_info']['user']['account_id']['acl'];         
109                $acl = CreateObject('phpgwapi.acl');
110                $apps = $acl->get_user_applications($user_id);
111                $contactApps = array();
112                foreach($apps as $app => $isEnabled){
113                        if($isEnabled)
114                                $contactApps[] = $app;
115                }
116
117                return array(
118                        'contactID'                     => $GLOBALS['phpgw_info']['user']['account_dn'],
119                        'contactMails'          => array($GLOBALS['phpgw_info']['user']['email']),
120                        'contactPhones'         => array($GLOBALS['phpgw_info']['user']['telephonenumber']),
121                        'contactFullName'       => $GLOBALS['phpgw_info']['user']['fullname'],
122                        'contactApps'           => $contactApps
123                );
124        }
125        protected function getLdapCatalog(){
126                if(!$this->ldapCatalog) {
127                        $catalog_config = CreateObject("contactcenter.bo_ldap_manager");
128                        $_SESSION['phpgw_info']['expressomail']['ldap_server'] = $catalog_config ? $catalog_config->srcs[1] : null;
129                        $this->ldapCatalog = CreateObject("expressoMail1_2.ldap_functions");
130                }
131       
132                return $this->ldapCatalog;
133        }
134       
135        protected function getDb(){
136                return $GLOBALS['phpgw']->db;
137        }
138       
139        protected function isLoggedIn(){
140                if($this->getParam('auth') != null) {
141                        list($sessionid, $kp3) = explode(":", $this->getParam('auth'));
142                        if($GLOBALS['phpgw']->session->verify($sessionid, $kp3)){                                                                       
143                                return $sessionid;
144                        }
145                        else{
146                                throw new ResponseException("",Errors::LOGIN_AUTH_INVALID);
147                        }
148                }
149                else{
150                        throw new ResponseException("",Errors::LOGIN_NOT_LOGGED_IN);
151                }               
152        }       
153                       
154}
Note: See TracBrowser for help on using the repository browser.