<?php if (!defined('VB_ENTRY')) die('Access denied.');
/*======================================================================*\
|| #################################################################### ||
|| # vBulletin 4.0.0 Alpha 5
|| # ---------------------------------------------------------------- # ||
|| # Copyright ©2000-2009 Jelsoft Enterprises Ltd. All Rights Reserved. ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
|| #################################################################### ||
\*======================================================================*/

/**
 * Default error controller.
 * Error controller with default implementations for providing error responses for
 * 403 (Access Denied), 404 (File not Found) and 500 (Internal Server Error)
 * responses.
 *
 * @author vBulletin Development Team
 * @version $Revision: 29533 $
 * @since $Date: 2009-02-12 16:00:09 +0000 (Thu, 12 Feb 2009) $
 * @copyright Jelsoft Enterprises Ltd.
 */
class vB_Controller_Error extends vB_Controller
{
	/*Properties====================================================================*/

	/**
	 * The package that the controller belongs to.
	 *
	 * @var string
	 */
	protected $package = 'vB';

	/**
	 * The class string id that identifies the controller.
	 *
	 * @var string
	 */
	protected $class = 'Error';



	/*Initialization================================================================*/

	/**
	 * Main entry point for the controller.
	 *
	 * @return string							- The final page output
	 */
	public function getResponse()
	{
		$error = vB_Router::getSegment('error');

		// Resolve rerouted error
		$error = in_array($error, array('403', '404', '409', '500')) ? $error : '404';

		if ('403' == $error)
		{
			@header("HTTP/1.0 403 Forbidden");
			print_no_permission();
		}
		else if ('409' == $error)
		{
			$message = ($message = vB_Router::getRerouteMessage()) ? $message : new vB_Phrase('error', 'error_409_description', vB_Router::getInitialURL(), vB_Router::getBaseURL(), vB::$vbulletin->options['contactuslink']);
			 
			@header("HTTP/1.0 409 Conflict");
			standard_error($message);
		}
		else if ('500' == $error)
		{
			@header("HTTP/1.0 500 Internal Server Error");
			standard_error(new vB_Phrase('error', 'error_500_description', vB_Router::getInitialURL(), vB_Router::getBaseURL(), vB::$vbulletin->options['contactuslink']));
		}
		else
		{
			@header("HTTP/1.0 404 Not Found");
		}

		// Create the standard vB templater
		$templater = new vB_Templater_vB();

		// TODO: Check what happens to style when undefined.

		// Register the templater to be used for XHTML
		vB_View::registerTemplater(vB_View::OT_XHTML, new vB_Templater_vB());

		// Create the page view
		$page_view = new vB_View_Page('page');
		$title = new vB_Phrase('error', 'error_404');
		$page_view->setPageTitle($title);

		// Create the body view
		$error_view = new vB_View('error_message');

		$subtitle = ($title != ($subtitle = vB_Router::getRerouteMessage())) ? $subtitle : false;
		$error_view->title = $title;
		$error_view->subtitle = $subtitle;
		$error_view->message = new vB_Phrase('error', 'error_404_description', vB_Router::getBaseURL(), vB::$vbulletin->options['contactuslink']);

		$page_view->setBodyView($error_view);

		// Add general page info
		$page_view->setPageTitle($title);

		return $page_view->render();
	}
}

/*======================================================================*\
|| ####################################################################

|| # SVN: $Revision: 29533 $
|| ####################################################################
\*======================================================================*/