<?php
/*
	Stempora Web Framework
	Copyright (c) 2002-2016 Stempora. 
	All rights reserved.
		web:  www.stempora.com
		mail: support@stempora.com				
*/


if (is_array($_GET["config"])) {
		$isvisible = true;

		if (
			($_GET["config"]["menu"] == "right") ||
			($_GET["config"]["layout"] == "right") ||
			($_GET["config"]["sh:btt"])

			){
				//$isvisible = false;
				$mainclass = "to-left";
		}				
	}

	foreach ($options["backgrounds"] as $key => $val) {
		foreach ($val as $k => $v) {
			$options["backgrounds"][$key][$k]["class"] = $_SESS["configurator"]["tmp_bg"] == $key . "_" . $v["id"] ? "active" : "";
		}		
	}

	foreach ($options["titlebackgrounds"] as $key => $val) {
		foreach ($val as $k => $v) {
			$options["titlebackgrounds"][$key][$k]["class"] = $_SESS["configurator"]["tmp_tbg"] == $key . "_" . $v["id"] ? "active" : "";
		}		
	}
	
	foreach ($options["menu"] as $key => $val) {
		foreach ($val as $k => $v) {
			$options["menu"][$key][$k]["class"] = $_SESS["configurator"]["tmp_mbg"] == $key . "_" . $v["id"] ? "active" : "";
		}		
	}


	foreach ($options["skins"] as $key => $val) {
		$options["skins"][$key]["class"] = $val["id"] == $_SESS["configurator"]["set_skin"] ? "active" : "";
	}
	

	if ($_GET["config"]["tbg"]) {
		$tab = ".tab-2-2";
	} elseif ($_GET["config"]["cbg:color"] || $_GET["config"]["cbg:type"] || $_GET["config"]["cbg:inverted"]){
		$tab = ".tab-3-3";		
	}


	$tpl = new CTemplateDynamic("assets/configurator/tpl/main.htm");
	$_MODULES["seo"]->PrependToBody(
		$tpl->blockReplace(
			"Main",
			array(			

				"reset"					=> is_array($_SESS["configurator"]) && count($_SESS["configurator"]) ? $tpl->blockReplace("Reset") : $tpl->blockReplace("New") ,

				"posclass"				=> $mainclass,

				"tab:default"			=> $tab,

				"cbg:color"				=> $site->vars->data["set_cbg_color"] ? $site->vars->data["set_cbg_color"]  : "",
				"cbg:alpha"				=> $site->vars->data["set_cbg_alpha"] ? $site->vars->data["set_cbg_alpha"]  : "1",
				"cbg:type"				=> $site->vars->data["set_cbg_type"] ? "active"  : "",

				"menu:left"				=> $site->vars->data["set_menu_style"] == "r" ? "active" : "",
				"menu:top"				=> $site->vars->data["set_menu_style"] == "c" ? "active" : "",
				"menu:right"			=> $site->vars->data["set_menu_style"] == "l" ? "active" : "",
				"menu:split"			=> $site->vars->data["set_menu_style"] == "lr" ? "active" : "",


				"layout:wide"			=> $site->vars->data["set_style_boxed"] == "" ? "active" : "",
				"layout:boxed"			=> $site->vars->data["set_style_boxed"] == "boxed" ? "active" : "",
				"layout:left"			=> $site->vars->data["set_style_boxed"] == "boxed boxed-left" ? "active" : "",
				"layout:right"			=> $site->vars->data["set_style_boxed"] == "boxed boxed-right" ? "active" : "",


				"cbg:inverted"		=> $site->vars->data["set_cbg_inverted"] == "1" ? "active" : "",

				"sh:sticky"			=> in_array(1, $site->vars->data["set_menu_sticky"]) ? "active" : "",
				"sh:btt"			=> in_array(1, $site->vars->data["set_back_top"]) ? "active" : "",
				"sh:pp"				=> in_array(1, $site->vars->data["set_preloader"]) ? "active" : "",

				"sh:ptb"			=> $site->vars->data["set_page_title_block"] ? "" : "active",


				"skins"					=> $base->html->table(
					$tpl , 
					"Skins" , 
					$options["skins"]
				),


				"visible"			=> $isvisible ? "active" : "",

				"bgs"					=> $tpl->blockReplace(
					"Bgs",
					array(
						"solid"		=> $base->html->table(
							$tpl,
							"Solid",
							$options["backgrounds"]["solid"]
						),

						"Image"		=> $base->html->table(
							$tpl,
							"Image",
							$options["backgrounds"]["img"]
						),

						"kb"		=> $base->html->table(
							$tpl,
							"KB",
							$options["backgrounds"]["kb"]
						),

						"video"		=> $base->html->table(
							$tpl,
							"Video",
							$options["backgrounds"]["video"]
						),

						"youtube"	=> $base->html->table(
							$tpl,
							"Youtube",
							$options["backgrounds"]["youtube"]
						)

					),
					array(
						"type"	=> "bg"
					)
				),


				"titlebgs"			=> $tpl->blockReplace(
					"TitleBgs",
					array(
						"solid"		=> $base->html->table(
							$tpl,
							"Solid",
							$options["titlebackgrounds"]["solid"]
						),

						"Image"		=> $base->html->table(
							$tpl,
							"Image",
							$options["titlebackgrounds"]["img"]
						),

						"kb"		=> $base->html->table(
							$tpl,
							"KB",
							$options["titlebackgrounds"]["kb"]
						),

						"video"		=> $base->html->table(
							$tpl,
							"Video",
							$options["titlebackgrounds"]["video"]
						),

						"youtube"	=> $base->html->table(
							$tpl,
							"Youtube",
							$options["titlebackgrounds"]["youtube"]
						)

					),
					array(
						"type"	=> "tbg"
					)
				),

				"menubgs"			=> $tpl->blockReplace(
					"MenuBgs",
					array(
						"solid"		=> $base->html->table(
							$tpl,
							"Solid",
							$options["menu"]["solid"]
						),

						"Image"		=> $base->html->table(
							$tpl,
							"Image",
							$options["menu"]["img"]
						),

						"kb"		=> $base->html->table(
							$tpl,
							"KB",
							$options["menu"]["kb"]
						),

					),
					array(
						"type"	=> "mbg"
					)
				)


			),
			array(
				"url"					=> $_SERVER["REDIRECT_URL"],
			),

			$options["product"]
		)
	);

	$bg = explode("_" , $site->vars->data["tmp_bg"]);
	global $_TSM;

	switch ($bg[0]) {
		case "video":
		case "kb":
		case "img":
		case "solid":
		case "youtube":

			$bg = $_MODULES["backgrounds"]->GetBg($options["backgrounds"][$bg[0]][$bg[1]]);

			$_TSM["PUB:PAGE_BG_HTML"] = $bg["html"];
			$_TSM["PUB:PAGE_BG_CLASS"] = $bg["class"];

		break;
	}



	$mbg = explode("_" , $site->vars->data["tmp_mbg"]);
	global $_TSM;

	switch ($mbg[0]) {
		case "video":
		case "kb":
		case "img":
		case "solid":
		case "youtube":

			$bg = $_MODULES["backgrounds"]->GetBg($options["menu"][$mbg[0]][$mbg[1]]);

			$_TSM["PUB:MENU_BG_HTML"] = $bg["html"];
			$_TSM["PUB:MENU_BG_CLASS"] = $bg["class"];

		break;
	}
	
	$tbg = explode("_" , $site->vars->data["tmp_tbg"]);


	switch ($tbg[0]) {
		case "video":
		case "kb":
		case "img":
		case "solid":
		case "youtube":

			$bg = $_MODULES["backgrounds"]->GetBg($options["titlebackgrounds"][$tbg[0]][$tbg[1]]);

			$_TSM["PUB:PAGETITLE_BG_HTML"] = $bg["html"];
			$_TSM["PUB:PAGETITLE_BG_CLASS"] = $bg["class"];

		break;
	}

	if ($site->vars->data["set_cbg_color"]) {	
		if ($site->vars->data["set_cbg_type"]) {
			$extra = $tpl->blockReplace("SectionWide" , $this->vars->data);
		} else {
			$extra = $tpl->blockReplace("Section" , $this->vars->data);
		}
	}

	if ($site->vars->data["set_cbg_inverted"]) {
		$extra .= $tpl->blockReplace("SectionInverted" , $this->vars->data);
	}

	if ($site->vars->data["set_page_title_block"]) {
		$extra .= $tpl->blockReplace("PageTitleBlock" );
	}

	$_MODULES["seo"]->AppendToHead(
		$tpl->blockReplace(
			"Head",
			array(

				"extra"		=> $extra
			)
		)
	);

?>