array( 'currentapp' => 'login', 'noheader' => True, 'disable_Template_class' => True, 'public_functions' => $public_functions ) ); include_once('../header.inc.php'); // NO COOKIES!!!! unset($_COOKIE); switch ($_SERVER['REQUEST_METHOD']) { case 'GET': case 'POST': execute($_REQUEST); break; default: exit(); } function execute($request){ if(empty($request)) { $request = array(); $http_request = new http_request(); $content_type = $http_request->header('Content-Type'); $accept = $http_request->header('Accept'); $content = $http_request->body(); if (($content_type == 'application/x-www-form-urlencoded') && ($accept == 'application/json') && $content != null) { $req_obj = json_decode($content); $request['params'] = (array)$req_obj->params; $request['method'] = $req_obj->method; $request ['format'] = "json-rpc"; $request['id'] = $req_obj->id; } } list($params, $method, $format, $id) = array_values($request); if(verifyMethod($method)){ $method = explode(".", $method); include_once("./".$format."/".$method[0].".php"); $obj = new $method[0]($id); $response = $obj->$method[1]($params); } else{ $response = array( 'result' => null, 'error' => "Available Resources: ". implode(", ", $GLOBALS['phpgw_info']['flags']['public_functions']), 'id' => $id ); } dispatch($response, $format); } function verifyMethod($method) { if(array_search( $method, $GLOBALS['phpgw_info']['flags']['public_functions']) !== FALSE){ return true; } else { return false; } } function dispatch($response, $format){ $e_response = false; switch($format){ case 'json-rpc': $e_response = @json_encode($response); break; case 'xml-rpc': $e_response = @xmlrpc_encode($response); break; default: $e_response = false; break; } echo $e_response; }