<?
class content
{
	var $VERSION=1.05;

	function content() {
		global $X;

		if($_POST['master_com']==true) require_once(LIBS_PATH_ADMIN.'/_admin/lib_sync.php');
		if(empty($_SESSION['backend']['user_id'])) {
			$X->ADMIN->prepare_interface();
			return require_once('classes/system/_login.php');
		}


		define('IS_ROOT', $_SESSION['backend']['is_root']==1 ? 1:0);
		define('IS_SU', $X->DB->fast(' SELECT is_su FROM _admin_users WHERE id="'.$_SESSION['backend']['user_id'].'" '));
		define('INC_SYS', ROOT.'/admin/includes/system');
		define('START_FORM', INC_SYS.'/start_form.php');
		define('START_SAVE', INC_SYS.'/start_save.php');
		define('START_DELETE', INC_SYS.'/start_delete.php');
		define('START_OTHER', INC_SYS.'/start_other.php');


		////////////////////////////////////////////////////////////////
		$X->LANGS = $X->DB->get_array(' SELECT kod, title FROM _front_lang WHERE active="1" ORDER BY pozycja,id ',true);
		$DEFAULT_LANG='PL';

		if(empty($_GET['lang'])) $_GET['lang']=$DEFAULT_LANG;
		$_GET['lang']=strtoupper(str_replace('/','',$_GET['lang']));
		$_SESSION['backend']['lang']=$_GET['lang'];
		define('LANG',$_GET['lang']);

		if($_GET['lang']!=$DEFAULT_LANG) {
			$_SESSION['backend']['PREFIX']=strtolower($_GET['lang'].'/');
			define('PREFIX',$_SESSION['backend']['PREFIX']);
			$_SESSION['backend']['PREFIX_VAR']=strtolower('&lang='.$_GET['lang']);
			define('PREFIX_VAR',$_SESSION['backend']['PREFIX_VAR']);
			$_SESSION['backend']['LANG_SUFFIX']=strtolower('_'.$_GET['lang']);
			define('LANG_SUFFIX',$_SESSION['backend']['LANG_SUFFIX']);
		} else {
			unset($_SESSION['backend']['PREFIX']);
			unset($_SESSION['backend']['PREFIX_VAR']);
			unset($_SESSION['backend']['LANG_SUFFIX']);
			define('PREFIX','');
			define('PREFIX_VAR','');
			define('LANG_SUFFIX','');
		}
		////////////////////////////////////////////////////////////////


		if(empty($_SESSION['backend']['css_color'])) $_SESSION['backend']['css_color']='68a7d4';
		if(!empty($_COOKIE['css_color']) && strlen($_COOKIE['css_color'])==6 && $_SESSION['backend']['css_color']!=$_COOKIE['css_color']) {
			$X->DB->q(' UPDATE _admin_users SET css_color="'.$X->STR->in($_COOKIE['css_color']).'" WHERE id="'.$_SESSION['backend']['user_id'].'" ');
			$_SESSION['backend']['css_color']=$_COOKIE['css_color'];
			setcookie('css_color','',-1);
		}


		$X->ADMIN->unoverride($this);
		$X->ADMIN->update_activity();


		$this->MENU=$X->ADMIN->generate_menu();
		$this->TOP_SHORTCUTS=$X->ADMIN->top_shortcuts();
		$this->BODY_COLOR=$_SESSION['backend']['css_color'];
		$this->BODY_COLOR_PICKER=$X->ADMIN->body_color_picker($this->BODY_COLOR);


		$this->ONLOAD_JS.=$X->ADMIN->get_onload_js();
		require_once('classes/system/_load_module.php');
		$this->HTML=$LOAD_MODULE->init();
		$this->ONLOAD_JS.=$X->ADMIN->get_onload_js();

		if(count($X->NAVI)>0) $this->TITLE=strip_tags($X->NAVI[0]).' | ';


		$X->ADMIN->prepare_interface();
		$this->generate_addons();
		$this->generate_html();
	}


	function generate_addons() {
		global $X;

		$X->CSS[] = './style.css?v='.$this->VERSION;
		$X->CSS['css_color'] = './color-'.$this->BODY_COLOR.'.css?v='.$this->VERSION;

		//////////////////////////////////////////////
		if(count($X->CSS)>0) foreach(@array_unique($X->CSS) as $css_id => $css) $this->CODE['HEAD'].="<link rel=\"stylesheet\"".(!empty($css_id) && !is_numeric($css_id) ? ' id="'.$css_id.'"':'')." href=\"".$css."\" type=\"text/css\" />\n";
		if(count($X->JS)>0) foreach(@array_unique($X->JS) as $js_id => $js) $this->CODE['HEAD'].="<script type=\"text/javascript\"".(!empty($js_id) && !is_numeric($js_id) ? ' id="'.$js_id.'"':'')." src=\"".$js."\"></script>\n";
		if(count($X->JS_BODY)>0) foreach(@array_unique($X->JS_BODY) as $js_id => $js) $this->CODE['BODY'].="<script type=\"text/javascript\"".(!empty($js_id) && !is_numeric($js_id) ? ' id="'.$js_id.'"':'')." src=\"".$js."\"></script>\n";

		if(!defined('ADDON_HEAD')) define('ADDON_HEAD','');
		if(!defined('ADDON_BODY')) define('ADDON_BODY','');
	}


	function generate_html() {
		global $X;


		echo '<!DOCTYPE html>
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>'.$this->TITLE.'CMS.Panel</title>
<meta name="SOFTWARE" content="DigiHex Systems Tomasz Kwaśny - digihex.pl" />
<meta name="viewport" content="width=960" />
<script type="text/javascript">var SID="'.session_id().'";</script>
<script type="text/javascript" id="js" src="./js.js?v='.$this->VERSION.'"></script>
'.$this->CODE['HEAD'].'
'.ADDON_HEAD.'
</head>

<body'.($_COOKIE['left_menu_hidden']==1 ? ' class="left_hidden"':'').'>
'.$this->CODE['BODY'].'

<div id="root">
	<table class="root"'.(!empty($_COOKIE['table_root_last_height']) ? ' style="height:'.(int)$_COOKIE['table_root_last_height'].'px"':'').'>
		<tr>
			<td class="left_col">
				'.$this->UNOVERRIDE.'
				'.(IS_ROOT==1 && $X->CONF->SHOW_DEV==1 ? '<div class="sys_info" style="position:absolute; top:2px; left:122px; width:100px; text-align:right; font:10px Tahoma; line-height:9px; color:#aaa;">DEV_MODE = '.($X->CONF->DEV_MODE==1 ? '<b>ON</b>':'<b style="color:#fff">OFF</b>').'</div>':'').'

				<div id="left">
					'.(!empty($_GET['module']) ? '<a href="#" onclick="left_menu_toggle(this); return false;" id="left_menu_toggle_link"'.($_COOKIE['left_menu_hidden']==1 ? ' class="hidden"':'').'><span class="ico w_left"></span></a>':'').'
					<a href="./" id="logo"'.($X->CONF->ASPAR==true ? ' style="background:url(images/logo_aspar.png) no-repeat;"':'').'></a>
					<div id="left_menu_cont">'.$this->MENU.'</div>
					<div id="links"><a href="index.php?module=change_password"><span class="ico i_key"></span><span>&nbsp; Zmień hasło</span></a> &nbsp;|&nbsp; <a href="" onclick="question(\'Chcesz się wylogować z panelu?\', \'index.php?module=logout\'); return false;"><span class="ico i_lock"></span><span>&nbsp; Wyloguj się</span></a></div>
				</div>
			</td>
			<td class="right_col">
				<div id="top_bg">
					<div class="bg">
						<div id="log"></div>
						'.$this->TOP_SHORTCUTS.'
						'.$X->SHORTCUT.'
					</div>
				</div>
				<div id="right">'.$this->HTML.'</div>
			</td>
		</tr>
		<tr class="foot">
			<td class="left_col">
				<div id="colors">'.$this->BODY_COLOR_PICKER.'</div>
				<div id="left_bottom">
					<div id="copyright"><a href="mailto:kontakt@digihex.pl">Tomasz Kwaśny</a> '.($X->CONF->ASPAR==true ? '&nbsp;<a href="http://aspar.pl/" target="_blank"><b>Aspar</b> s.c.</a>':'<a href="http://digihex.pl/" target="_blank"><b>DigiHex</b> Systems</a>').'</div>
				</div>
			</td>
			<td class="right_col">
				<div id="bottom_bg">
					<div class="bg">
						<a href="#" onclick="this.blur(); $.scrollTo(0); return false;" ondragstart="return false;" class="to_top"><span class="ico b_up" style="margin-top:-3px"></span><span>&nbsp; Do góry</span></a>
					</div>
				</div>
			</td>
		</tr>
	</table>
</div>


<div id="div_preload" style="display:none; width:1px; height:1px; overflow:hidden;">
	<img src="images/box/overlay.png" alt="" />
	<img src="images/box/controls.png" alt="" />
	<img src="images/box/header_gradient.png" alt="" />
	<img src="images/tip_arrows.png" alt="" />
	<img src="images/menu_sub_bg_sel.png" alt="" />
	<img src="images/form_warning.png" alt="" />
</div>

'.$this->ONLOAD_JS.'
'.ADDON_BODY.'
';
	}


}
$CONTENT=new content();
?>