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