source: sandbox/webservice/api/adapters/ExpressoAdapter.php @ 6493

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

Ticket #2507 - Implementação modificada para permitir envio de anexos

  • Property svn:executable set to *
Line 
1<?php
2class ExpressoAdapter extends Resource {
3
4        private $cannotModifyHeader;
5        private $expressoVersion;
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(__DIR__.'/../../header.inc.php');
22                $this->expressoVersion = substr($GLOBALS['phpgw_info']['server']['versions']['phpgwapi'],0,3);
23                $this->setCannotModifyHeader(false);
24        }
25       
26        protected function setRequest($request){
27                $this->request = $request;
28        }
29       
30        public function getRequest(){
31                return $this->request;
32        }
33       
34        protected function getExpressoVersion(){
35                return $this->expressoVersion;
36        }
37       
38        protected function setResult($result){
39                $this->result = $result;
40        }
41       
42        public function getResult(){
43                return $this->result;
44        }
45       
46        protected function setId($id){
47                $this->id = $id;
48        }
49       
50        public function getId(){
51                return $this->id;
52        }
53       
54        protected function setParams($params){         
55                $this->params = $params;
56        }
57       
58        public function getParams(){   
59                return $this->params;
60        }
61       
62        public function getParam($param){
63                return $this->params->$param;
64        }
65       
66        public function setError($error) {
67                $this-> error = $error;
68        }
69       
70        protected function getError() {
71                return $this-> error;
72        }
73       
74        protected function setCannotModifyHeader($boolean){
75                $this-> cannotModifyHeader = $boolean;
76        }
77        protected function getCannotModifyHeader(){
78                return $this-> cannotModifyHeader;
79        }
80
81        public function post($request){
82                if(!$request->data)
83                        $request->data = $_POST;
84                $this->setRequest($request);           
85                if(!is_array($request->data))
86                        parse_str(urldecode($request->data), &$request->data);
87                $data = (object)$request->data;         
88                if($data){
89                        if($data->params){                                                             
90                                $this->setParams(json_decode($data->params));
91                        }
92                        if($data->id)
93                                $this->setId($data->id);
94                }
95        }       
96       
97        public function get($request){
98                $response = new Response($request);
99                $response->code = Response::OK;
100                $response->addHeader('content-type', 'text/html');             
101                $response->body = "<H4>Metodo GET nao permitido para este recurso.</H4>";               
102                return $response;
103        }
104       
105        public function getResponse(){
106                $response = new Response($this->getRequest());
107               
108                if($this->getCannotModifyHeader())
109                        return $response;
110               
111                $response->code = Response::OK;
112                $response->addHeader('content-type', 'application/json');
113
114                if($this->getId())
115                        $body['id']     = $this->getId();
116                if($this->getResult())
117                        $body['result'] = $this->getResult();
118                else {
119                        Errors::runException("E_UNKNOWN_ERROR");                       
120                }
121               
122               
123                $response->body = json_encode($body);
124               
125                return $response;
126        }
127       
128        protected function isLoggedIn(){
129                if($this->getParam('auth') != null) {
130                        list($sessionid, $kp3) = explode(":", $this->getParam('auth'));
131                        if($GLOBALS['phpgw']->session->verify($sessionid, $kp3)){                                                                       
132                                return $sessionid;
133                        }
134                        else{
135                                Errors::runException("LOGIN_AUTH_INVALID");                                                     
136                        }
137                }
138                elseif($sessionid = $GLOBALS['_COOKIE']['sessionid']) {
139                        if($GLOBALS['phpgw']->session->verify($sessionid)) {
140                                return $sessionid;
141                        }
142                        else{
143                                Errors::runException("LOGIN_NOT_LOGGED_IN");
144                        }
145                }
146                else{
147                        Errors::runException("LOGIN_NOT_LOGGED_IN");                   
148                }               
149        }       
150                       
151}
Note: See TracBrowser for help on using the repository browser.