public function getTpl() { javascript('jquery'); $tpl = $this->tplFormatTime(); if ($this->show_busy && !$this->_schedule->checkPermissions()) { $tpl['SUMMARY'] = dgettext('calendar', 'Busy'); $tpl['DESCRIPTION'] = null; } else { $tpl['SUMMARY'] = $this->getSummary(); $tpl['DESCRIPTION'] = $this->getDescription(); } if ($this->_schedule->checkPermissions()) { $link[] = $this->editLink('icon'); $link[] = $this->deleteLink('icon'); if (PHPWS_Core::moduleExists('blog')) { if (Current_User::allow('blog', 'edit_blog', null, null, true)) { $link[] = $this->blogLink('icon'); } } $tpl['LINKS'] = implode(' ', $link); } if (!empty($this->location)) { $tpl['LOCATION_LABEL'] = dgettext('calendar', 'Location'); $tpl['LOCATION'] = $this->getLocation(); } $tpl['BACK_LINK'] = PHPWS_Text::backLink(); return $tpl; }
/** * This function handle a request binding it to a given object * * @param Request $request * @param object $object * @return array|null * @throws \Exception */ public static function handle(Request $request, $object) { // user-defined error handler to catch annoying php errors and throw them as exceptions set_error_handler(function ($errno, $errstr, $errfile, $errline) { throw new ErrorHandler($errstr, 0, $errno, $errfile, $errline); }, E_ALL); // checks if a JSON-RPC request has been received if ($_SERVER['REQUEST_METHOD'] != 'POST' || empty($_SERVER['CONTENT_TYPE']) || strrpos($_SERVER['CONTENT_TYPE'], "application/json") === false && strrpos($_SERVER['CONTENT_TYPE'], "application/xml") === false) { throw new \Exception("Not a JSON-RPC request: ct: '" . @$_SERVER['CONTENT_TYPE'] . "'"); } // executes the task on local object try { // TODO: refactor to use an error dto $object->checkPermissions($request->request->get('method'), $request->request->get('params')); if (method_exists($object, $request->request->get('method'))) { $result = call_user_func_array(array($object, $request->request->get('method')), $request->request->get('params')); $response = array('jsonrpc' => '2.0', 'id' => $request->request->get('id'), 'result' => $result, 'error' => NULL); } else { $response = array('jsonrpc' => '2.0', 'id' => $request->request->get('id'), 'result' => NULL, 'error' => array('type' => 'UnknownMethod', 'message' => sprintf("unknown method '%s' on class '%s'", $request->request->get('method'), get_class($object)))); } } catch (\Exception $e) { $response = array('id' => $request->request->get('id'), 'result' => NULL, 'error' => array('type' => get_class($e), 'message' => $e->getMessage() . " line " . $e->getLine() . " " . $e->getFile() . " " . CodeGuard::getStackTrace($e->getTrace()))); if ($e instanceof ResourceNotAvailableException) { $response['error']['type'] = 'ResourceNotAvailableException'; $response['error']['message'] = $e->getMessage(); } elseif ($e instanceof UserNotAuthenticatedException) { $response['error']['type'] = 'UserNotAuthenticatedException'; $response['error']['message'] = $e->getMessage(); } elseif ($e instanceof UserUnauthorizedException) { $response['error']['type'] = 'UserUnauthorizedException'; $response['error']['message'] = $e->getMessage(); } $message = ''; $message .= $e->getMessage() . "\n"; $message .= $e->getTraceAsString() . "\n"; error_log($message); } if (!$request->request->get('id')) { // notifications don't want response return null; } return $response; }