<?php
	namespace Mocha\UI\MasterPages;
	
	use Phast\CancelEventArgs;
	use Phast\RenderedEventArgs;
	use Phast\RenderingEventArgs;
	use Phast\RenderMode;
	use Phast\System;
	use Phast\WebPage;

	class BlankMasterPage extends WebPage
	{
		public $RequireLogin;

		public function __construct()
		{
			parent::__construct();
			
			$this->RequireLogin = true;
		}

		protected function OnPreRender(CancelEventArgs $e)
		{
			/**
			 * @var \Mocha\Oms\MySQLDatabaseOms
			 */
			$oms = mocha_get_oms();

			$path = System::GetVirtualPath();
			$currentUser = mocha_get_current_user();
		
			$page = null;
			$pathVars = null;
			System::ParsePathVariablesIntoPage($page, $pathVars);
			if ($currentUser === null)
			{
				if ($page != null)
				{
					if ($page->MasterPage->ClassReference->RequireLogin) // requiresLogin($page->FileName))
					{
						// echo($page->FileName);
						$_SESSION["login_return"] = $path;
						System::RedirectToLoginPage(true);
						$e->Cancel = true;
					}
				}
			}
			return true;
		}

		protected function OnRendering(RenderingEventArgs $re)
		{
			if ($re->RenderMode === RenderMode::Complete)
			{
				echo("<!DOCTYPE html>");
				echo("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
			}
		}

		protected function OnRendered(RenderedEventArgs $e)
		{
			if ($e->RenderMode === RenderMode::Complete)
			{
				echo("</html>");
			}
		}

	}
?>