<?php
/*
  ===============================================================

  inGenio X
  http://ingenio.area421.com

  Created by 
  Julian Moreno Hidalgo (Software developer)
  Jesus Moreno Hidalgo (Communication's tree)

  inGenio X is a free software licensed under CC-GNU GPL

  ===============================================================
*/
?>
<?php
	if (!defined("IGNX")) { die("Attempt..."); }

	// definir modo
	if (INGENIO_X_MODO == "web")
	{	
		// skin
		$qcomp = myquery("SELECT * FROM ".COMPOSICION." WHERE enabled=1 ORDER BY skinID ASC limit 0, 1","[tpl_cuerpo=1]");
		$row_comp = myfetch($qcomp);

		// test
		if (!$row_comp) { die ("ERROR: !enabled"); }
	
	} else if (INGENIO_X_MODO == "prev")
	{
		// skin previo
		$qcomp = myquery("SELECT * FROM ".COMPOSICION." WHERE previo=1 ORDER BY skinID ASC limit 0, 1","[tpl_cuerpo=2]");
		$row_comp = myfetch($qcomp);
	
		// test
		if (!$row_comp) { die ("ERROR: !previo"); }
	
	}

	// definir composicion
	define("TPL_COMPOSICION",$row_comp["composicion"]);
	
	// definir skin
	define("TPL_SKIN",substr($row_comp['skin_css'],0,-4));
					
	// definir imagen cabecera
	if ($row_comp["imagen_cabecera"] != "")
	{
		if ($row_comp["imagen_cabecera"] && file_exists_url("./ftps/".$row_comp["imagen_cabecera"]))
		{
			$size = getimagesize("./ftps/".$row_comp["imagen_cabecera"]);
		} else {
			$size = array("","0");
		}
					
		define("TPL_IMAGEN_CABECERA","style=\"height:".$size[1]."px;background-image:url(".RUTA_INICIO_IMG."ftps/".$row_comp['imagen_cabecera'].");background-repeat:no-repeat;\"");
	
	} else {
		
		define ("TPL_IMAGEN_CABECERA","class=\"div_principal_alto\"");
	}
	
	// elementos elegidos de menus
	$ids_menu_alto = explode(",",$row_comp["menu_alto"]);
	$ids_menu_principal = explode(",",$row_comp["menu_principal"]);
	$ids_menu_secundario = explode(",",$row_comp["menu_secundario"]);
	$ids_menu_bajo = explode(",",$row_comp["menu_pie"]);		

	// menus
	include("./ints/menus/menu_add_item.php");
	include("./ints/menus/menu_add_traduccion.php");
	include("./ints/menus/menu_buscar.php");
	include("./ints/menus/menu_cabecera.php");
	include("./ints/menus/menu_canales.php");
	include("./ints/menus/menu_categorias_priv.php");
	include("./ints/menus/menu_categorias.php");
	include("./ints/menus/menu_copy.php");
	include("./ints/menus/menu_email.php");
	include("./ints/menus/menu_extra_1.php");
	include("./ints/menus/menu_extra_2.php");
	include("./ints/menus/menu_extra_3.php");
	include("./ints/menus/menu_idiomas.php");
	include("./ints/menus/menu_items_leidos.php");
	include("./ints/menus/menu_items_portada.php");
	include("./ints/menus/menu_items_ultimos.php");
	include("./ints/menus/menu_items_votados.php");
	include("./ints/menus/menu_links.php");
	include("./ints/menus/menu_paginas.php");
	include("./ints/menus/menu_portada.php");
	include("./ints/menus/menu_reloj.php");
	include("./ints/menus/menu_rss_feeds.php");
	include("./ints/menus/menu_rss.php");
	include("./ints/menus/menu_secciones.php");
	include("./ints/menus/menu_tags_2.php");
	include("./ints/menus/menu_tags_3.php");
	include("./ints/menus/menu_tags.php");
	include("./ints/menus/menu_tienda.php");

?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

<?php
	include("./ints/tpls/tpl_head.php");
?>

<body>

<?php
	
	// Smarty -> template_dir
	$smarty->template_dir = "./skins/".substr($row_comp['skin_css'],0,-4)."/templates/";	
	
	// Smarty -> compile_dir
	if (INGENIO_X_MODO == "web")
	{	
		$smarty->compile_dir = "./templates_c/";
		
	} else if (INGENIO_X_MODO == "prev")
	{
		$smarty->compile_dir = "./templates_cp/";
	}

	// Smarty -> elementos elegidos de menus
	$smarty->assign("ids_menu_alto", $ids_menu_alto);
	$smarty->assign("ids_menu_principal", $ids_menu_principal);
	$smarty->assign("ids_menu_secundario", $ids_menu_secundario);
	$smarty->assign("ids_menu_bajo", $ids_menu_bajo);
	

	// Smarty -> template principal
	$smarty->display($row_comp["composicion"]);

	
	// powered link
	echo '
	<div style="font-size: x-small;font-family: verdana,sans-serif;margin: 3px 0 2px 0;text-align: center;">'.INGENIO_POWERED.'</div>';

?>


</body>
</html>