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