[6149] | 1 | <?php |
---|
| 2 | class ExpressoAdapter extends Resource { |
---|
| 3 | |
---|
[6307] | 4 | private $cannotModifyHeader; |
---|
[6149] | 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 | |
---|
[6227] | 21 | include_once(__DIR__.'/../../header.inc.php'); |
---|
[6307] | 22 | $this->expressoVersion = substr($GLOBALS['phpgw_info']['server']['versions']['phpgwapi'],0,3); |
---|
| 23 | $this->setCannotModifyHeader(false); |
---|
[6149] | 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){ |
---|
[6601] | 63 | return mb_convert_encoding($this->params->$param, "ISO_8859-1", "UTF8"); |
---|
[6149] | 64 | } |
---|
| 65 | |
---|
| 66 | public function setError($error) { |
---|
| 67 | $this-> error = $error; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | protected function getError() { |
---|
| 71 | return $this-> error; |
---|
| 72 | } |
---|
| 73 | |
---|
[6307] | 74 | protected function setCannotModifyHeader($boolean){ |
---|
| 75 | $this-> cannotModifyHeader = $boolean; |
---|
| 76 | } |
---|
| 77 | protected function getCannotModifyHeader(){ |
---|
| 78 | return $this-> cannotModifyHeader; |
---|
| 79 | } |
---|
| 80 | |
---|
[6149] | 81 | public function post($request){ |
---|
[6493] | 82 | if(!$request->data) |
---|
| 83 | $request->data = $_POST; |
---|
[6149] | 84 | $this->setRequest($request); |
---|
[6493] | 85 | if(!is_array($request->data)) |
---|
| 86 | parse_str(urldecode($request->data), &$request->data); |
---|
| 87 | $data = (object)$request->data; |
---|
[6149] | 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()); |
---|
[6307] | 107 | |
---|
| 108 | if($this->getCannotModifyHeader()) |
---|
| 109 | return $response; |
---|
| 110 | |
---|
[6149] | 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(); |
---|
[6165] | 118 | else { |
---|
| 119 | Errors::runException("E_UNKNOWN_ERROR"); |
---|
| 120 | } |
---|
[6149] | 121 | |
---|
[6165] | 122 | |
---|
[6149] | 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{ |
---|
[6165] | 135 | Errors::runException("LOGIN_AUTH_INVALID"); |
---|
[6149] | 136 | } |
---|
| 137 | } |
---|
[6273] | 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 | } |
---|
[6149] | 146 | else{ |
---|
[6165] | 147 | Errors::runException("LOGIN_NOT_LOGGED_IN"); |
---|
[6149] | 148 | } |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | } |
---|