<?php
class document extends design{
	var $title = 'Заголовок';
	protected  $err = array();
	protected $msg = array();
	protected $outputed = false;
	protected $actions = array();
	protected $returns = array();

	function __construct($group=0)
	{
		parent::__construct();
		global $user,$dcms;
		$this->title = $dcms->title;
		if ($group > $user->group)$this->access_denied('Доступ к данной странице запрещен');
		ob_start();
	}

	// добавление в список ошибок
	function err($err,$help=false){$this->err[]=array('text'=>$err,'help'=>$help);}
	// добавление в список сообщений
	function msg($msg,$help=false){$this->msg[]=array('text'=>$msg,'help'=>$help);}
	//
	function ret($name,$link){$this->returns[]=array($name,$link);}
	//
	function act($name,$link){$this->actions[]=array($name,$link);}

	function access_denied($err)
	{


		if (isset($_GET['return']))
		{
			header('refresh:2;url='.$_GET['return']);
		}
		elseif (isset($_SERVER['HTTP_REFERER']) && preg_match('#^http://'.preg_quote($_SERVER['HTTP_HOST']).'#ui',$_SERVER['HTTP_REFERER']) && $_SERVER['REQUEST_URI']!=$_SERVER['HTTP_REFERER'])
		{
			header('refresh:2;url='.$_SERVER['HTTP_REFERER']);
		}


		$this->err($err);
		$this->output();
		exit;
	}




	private function output()
	{
		if ($this->outputed) return false; $this->outputed = true;

		global $dcms,$user;


		header('Cache-Control: no-store, no-cache, must-revalidate');
		header('Expires: ' . date('r'));

if ($dcms -> browser == 'Microsoft Internet Explorer')
header('Content-Type: text/html; charset=utf-8');
else
{
		switch ($this->theme_obj->content) {
			case 'wml':header('Content-Type: text/vnd.wap.wml; charset=utf-8');break;
			case 'xhtml':header('Content-Type: application/xhtml+xml; charset=utf-8');break;
			default:header('Content-Type: text/html; charset=utf-8');break;
		}
}



		$this->assignByRef('adt',new adt());


		$this->assign('actions',$this->actions);
		$this->assign('returns',$this->returns);
		$this->assign('err',$this->err);
		$this->assign('msg',$this->msg);
		$this->assign('title',$this->title);

		$this->assign('content',@ob_get_clean());

		list($msec, $sec) = explode(chr(32), microtime());
		$this->assign('document_generation_time',round($msec + $sec - TIME_START , 3));

		$this->display('document.tpl');
	//	exit;
	}

	function clean()
	{
		$this->outputed = true;
		@ob_clean();
	}

	function __destruct(){
		$this->output();
	}


}
?>