function output_error($type, $message, $file, $line)
    {
        global $mybb, $parser;
        if (!$mybb->settings['bbname']) {
            $mybb->settings['bbname'] = "MyBB";
        }
        if ($type == MYBB_SQL) {
            $title = "MyBB SQL Error";
            $error_message = "<p>MyBB has experienced an internal SQL error and cannot continue.</p>";
            if ($mybb->settings['errortypemedium'] == "both" || $mybb->settings['errortypemedium'] == "error" || defined("IN_INSTALL") || defined("IN_UPGRADE")) {
                $error_message .= "<dl>\n";
                $error_message .= "<dt>SQL Error:</dt>\n<dd>{$message['error_no']} - {$message['error']}</dd>\n";
                if ($message['query'] != "") {
                    $error_message .= "<dt>Query:</dt>\n<dd>{$message['query']}</dd>\n";
                }
                $error_message .= "</dl>\n";
            }
        } else {
            $title = "MyBB Internal Error";
            $error_message = "<p>MyBB has experienced an internal error and cannot continue.</p>";
            if ($mybb->settings['errortypemedium'] == "both" || $mybb->settings['errortypemedium'] == "error" || defined("IN_INSTALL") || defined("IN_UPGRADE")) {
                $error_message .= "<dl>\n";
                $error_message .= "<dt>Error Type:</dt>\n<dd>{$this->error_types[$type]} ({$type})</dd>\n";
                $error_message .= "<dt>Error Message:</dt>\n<dd>{$message}</dd>\n";
                if (!empty($file)) {
                    $error_message .= "<dt>Location:</dt><dd>File: {$file}<br />Line: {$line}</dd>\n";
                    if (!@preg_match('#config\\.php|settings\\.php#', $file) && @file_exists($file)) {
                        $code_pre = @file($file);
                        $code = "";
                        if (isset($code_pre[$line - 4])) {
                            $code .= $line - 3 . ". " . $code_pre[$line - 4];
                        }
                        if (isset($code_pre[$line - 3])) {
                            $code .= $line - 2 . ". " . $code_pre[$line - 3];
                        }
                        if (isset($code_pre[$line - 2])) {
                            $code .= $line - 1 . ". " . $code_pre[$line - 2];
                        }
                        $code .= $line . ". " . $code_pre[$line - 1];
                        // The actual line.
                        if (isset($code_pre[$line])) {
                            $code .= $line + 1 . ". " . $code_pre[$line];
                        }
                        if (isset($code_pre[$line + 1])) {
                            $code .= $line + 2 . ". " . $code_pre[$line + 1];
                        }
                        if (isset($code_pre[$line + 2])) {
                            $code .= $line + 3 . ". " . $code_pre[$line + 2];
                        }
                        unset($code_pre);
                        $parser_exists = false;
                        if (!is_object($parser) || !method_exists($parser, 'mycode_parse_php')) {
                            if (@file_exists(MYBB_ROOT . "inc/class_parser.php")) {
                                @(require_once MYBB_ROOT . "inc/class_parser.php");
                                $parser = new postParser();
                                $parser_exists = true;
                            }
                        } else {
                            $parser_exists = true;
                        }
                        if ($parser_exists) {
                            $code = $parser->mycode_parse_php($code, true);
                        } else {
                            $code = @nl2br($code);
                        }
                        $error_message .= "<dt>Code:</dt><dd>{$code}</dd>\n";
                    }
                }
                $backtrace = $this->generate_backtrace();
                if ($backtrace && !in_array($type, $this->mybb_error_types)) {
                    $error_message .= "<dt>Backtrace:</dt><dd>{$backtrace}</dd>\n";
                }
                $error_message .= "</dl>\n";
            }
        }
        if (isset($lang->settings['charset'])) {
            $charset = $lang->settings['charset'];
        } else {
            $charset = 'UTF-8';
        }
        if (!headers_sent() && !defined("IN_INSTALL") && !defined("IN_UPGRADE")) {
            @header('HTTP/1.1 503 Service Temporarily Unavailable');
            @header('Status: 503 Service Temporarily Unavailable');
            @header('Retry-After: 1800');
            @header("Content-type: text/html; charset={$charset}");
            $_SERVER['PHP_SELF'] = htmlspecialchars_uni($_SERVER['PHP_SELF']);
            echo <<<EOF
\t<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head profile="http://gmpg.org/xfn/11">
\t<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\t<title>{$mybb->settings['bbname']} - Internal Error</title>
\t<style type="text/css">
\t\tbody { background: #efefef; color: #000; font-family: Verdana; font-size: 12px; text-align: center; line-height: 1.4; }
\t\ta:link { color: #026CB1; text-decoration: none;\t}
\t\ta:visited {\tcolor: #026CB1;\ttext-decoration: none; }
\t\ta:hover, a:active {\tcolor: #000; text-decoration: underline; }
\t\t#container { width: 600px; padding: 20px; background: #fff;\tborder: 1px solid #e4e4e4; margin: 100px auto; text-align: left; }
\t\th1 { margin: 0; background: url({$_SERVER['PHP_SELF']}?action=mybb_logo) no-repeat;\theight: 82px; width: 248px; }
\t\t#content { border: 1px solid #B60101; background: #fff; }
\t\th2 { font-size: 12px; padding: 4px; background: #B60101; color: #fff; margin: 0; }
\t\t.invisible { display: none; }
\t\t#error { padding: 6px; }
\t\t#footer { font-size: 11px; border-top: 1px solid #ccc; padding-top: 10px; }
\t\tdt { font-weight: bold; }
\t</style>
</head>
<body>
\t<div id="container">
\t\t<div id="logo">
\t\t\t<h1><a href="http://mybb.com/" title="MyBulletinBoard"><span class="invisible">MyBB</span></a></h1>
\t\t</div>

\t\t<div id="content">
\t\t\t<h2>{$title}</h2>

\t\t\t<div id="error">
\t\t\t\t{$error_message}
\t\t\t\t<p id="footer">Please contact the <a href="http://mybb.com">MyBB Group</a> for support.</p>
\t\t\t</div>
\t\t</div>
\t</div>
</body>
</html>
EOF;
        } else {
            echo <<<EOF
\t<style type="text/css">
\t\t#mybb_error_content { border: 1px solid #B60101; background: #fff; }
\t\t#mybb_error_content h2 { font-size: 12px; padding: 4px; background: #B60101; color: #fff; margin: 0; }
\t\t#mybb_error_error { padding: 6px; }
\t\t#mybb_error_footer { font-size: 11px; border-top: 1px solid #ccc; padding-top: 10px; }
\t\t#mybb_error_content dt { font-weight: bold; }
\t</style>
\t<div id="mybb_error_content">
\t\t<h2>{$title}</h2>
\t\t<div id="mybb_error_error">
\t\t{$error_message}
\t\t\t<p id="mybb_error_footer">Please contact the <a href="http://mybb.com">MyBB Group</a> for support.</p>
\t\t</div>
\t</div>
EOF;
        }
        exit(1);
    }