]> git.openstreetmap.org Git - nominatim.git/blob - lib/init-website.php
clean up docs for lookup call
[nominatim.git] / lib / init-website.php
1 <?php
2
3 require_once('init.php');
4 require_once('ParameterParser.php');
5 require_once(CONST_Debug ? 'DebugHtml.php' : 'DebugNone.php');
6
7 /***************************************************************************
8  *
9  * Error handling functions
10  *
11  */
12
13
14 function chksql($oSql, $sMsg = 'Database request failed')
15 {
16     if (!PEAR::isError($oSql)) return $oSql;
17
18     header('HTTP/1.0 500 Internal Server Error');
19     header('Content-type: text/html; charset=utf-8');
20
21     $sSqlError = $oSql->getMessage();
22
23     echo <<<INTERNALFAIL
24 <html>
25   <head><title>Internal Server Error</title></head>
26   <body>
27     <h1>Internal Server Error</h1>
28     <p>Nominatim has encountered an internal error while accessing the database.
29        This may happen because the database is broken or because of a bug in
30        the software. If you think it is a bug, feel free to report
31        it over on <a href="https://github.com/openstreetmap/Nominatim/issues">
32        Github</a>. Please include the URL that caused the problem and the
33        complete error details below.</p>
34     <p><b>Message:</b> $sMsg</p>
35     <p><b>SQL Error:</b> $sSqlError</p>
36     <p><b>Details:</b> <pre>
37 INTERNALFAIL;
38
39     if (CONST_Debug) {
40         var_dump($oSql);
41     } else {
42         echo "<pre>\n".$oSql->getUserInfo().'</pre>';
43     }
44
45     echo '</pre></p></body></html>';
46     exit;
47 }
48
49 function failInternalError($sError, $sSQL = false, $vDumpVar = false)
50 {
51     header('HTTP/1.0 500 Internal Server Error');
52     header('Content-type: text/html; charset=utf-8');
53     echo '<html><body><h1>Internal Server Error</h1>';
54     echo '<p>Nominatim has encountered an internal error while processing your request. This is most likely because of a bug in the software.</p>';
55     echo '<p><b>Details:</b> '.$sError,'</p>';
56     echo '<p>Feel free to file an issue on <a href="https://github.com/openstreetmap/Nominatim/issues">Github</a>. ';
57     echo 'Please include the error message above and the URL you used.</p>';
58     if (CONST_Debug) {
59         echo '<hr><h2>Debugging Information</h2><br>';
60         if ($sSQL) {
61             echo '<h3>SQL query</h3><code>'.$sSQL.'</code>';
62         }
63         if ($vDumpVar) {
64             echo '<h3>Result</h3> <code>';
65             var_dump($vDumpVar);
66             echo '</code>';
67         }
68     }
69     echo "\n</body></html>\n";
70     exit;
71 }
72
73
74 function userError($sError)
75 {
76     header('HTTP/1.0 400 Bad Request');
77     header('Content-type: text/html; charset=utf-8');
78     echo '<html><body><h1>Bad Request</h1>';
79     echo '<p>Nominatim has encountered an error with your request.</p>';
80     echo '<p><b>Details:</b> '.$sError.'</p>';
81     echo '<p>If you feel this error is incorrect feel file an issue on <a href="https://github.com/openstreetmap/Nominatim/issues">Github</a>. ';
82     echo 'Please include the error message above and the URL you used.</p>';
83     echo "\n</body></html>\n";
84     exit;
85 }
86
87
88 /***************************************************************************
89  * HTTP Reply header setup
90  */
91
92 if (CONST_NoAccessControl) {
93     header('Access-Control-Allow-Origin: *');
94     header('Access-Control-Allow-Methods: OPTIONS,GET');
95     if (!empty($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) {
96         header('Access-Control-Allow-Headers: '.$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']);
97     }
98 }
99 if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') exit;
100
101 if (CONST_Debug) header('Content-type: text/html; charset=utf-8');