3 require_once('init.php');
4 require_once('ParameterParser.php');
5 require_once(CONST_Debug ? 'DebugHtml.php' : 'DebugNone.php');
7 /***************************************************************************
9 * Error handling functions
13 function userError($sMsg)
15 throw new Exception($sMsg, 400);
19 function exception_handler_html($exception)
21 http_response_code($exception->getCode());
22 header('Content-type: text/html; charset=UTF-8');
23 include(CONST_BasePath.'/lib/template/error-html.php');
26 function exception_handler_json($exception)
28 http_response_code($exception->getCode());
29 header('Content-type: application/json; charset=utf-8');
30 include(CONST_BasePath.'/lib/template/error-json.php');
33 function exception_handler_xml($exception)
35 http_response_code($exception->getCode());
36 header('Content-type: text/xml; charset=utf-8');
37 echo '<?xml version="1.0" encoding="UTF-8" ?>'."\n";
38 include(CONST_BasePath.'/lib/template/error-xml.php');
42 function set_exception_handler_by_format($sFormat = 'html')
44 if ($sFormat == 'html') {
45 set_exception_handler('exception_handler_html');
46 } elseif ($sFormat == 'xml') {
47 set_exception_handler('exception_handler_xml');
49 set_exception_handler('exception_handler_json');
53 set_exception_handler_by_format();
56 /***************************************************************************
57 * HTTP Reply header setup
60 if (CONST_NoAccessControl) {
61 header('Access-Control-Allow-Origin: *');
62 header('Access-Control-Allow-Methods: OPTIONS,GET');
63 if (!empty($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) {
64 header('Access-Control-Allow-Headers: '.$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']);
67 if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'OPTIONS') exit;
69 if (CONST_Debug) header('Content-type: text/html; charset=utf-8');