<?php
@ini_set("display_errors","1");
@ini_set("display_startup_errors","1");


include("include/dbcommon.php");

if(!isLogged())
{
	header("Location: login.php");
	return;
}

if(isLoggedAsGuest()){
	$_SESSION["MyURL"]=$_SERVER["SCRIPT_NAME"]."?".$_SERVER["QUERY_STRING"];
}


$layout = new TLayout("menu","BoldAqua","MobileAqua");
$layout->blocks["top"] = array();
$layout->containers["menu"] = array();

$layout->containers["menu"][] = array("name"=>"menulogas","block"=>"loggedas_block","substyle"=>1);


$layout->containers["menu"][] = array("name"=>"menulogout","block"=>"logout_link","substyle"=>1);


$layout->containers["menu"][] = array("name"=>"menuchangepwd","block"=>"changepwd_link","substyle"=>1);


$layout->containers["menu"][] = array("name"=>"vmenu","block"=>"menu_block","substyle"=>1);


$layout->skins["menu"] = "menu";
$layout->blocks["top"][] = "menu";$page_layouts["menu"] = $layout;


include('include/xtempl.php');
require_once(getabspath("classes/cipherer.php"));
include('classes/runnerpage.php');

include_once(getabspath("include/articulo_events.php"));
$tableEvents["articulo"] = new eventclass_articulo;
include_once(getabspath("include/cuenta_events.php"));
$tableEvents["cuenta"] = new eventclass_cuenta;
include_once(getabspath("include/ajuste_events.php"));
$tableEvents["ajuste"] = new eventclass_ajuste;
include_once(getabspath("include/v_articulo_events.php"));
$tableEvents["v_articulo"] = new eventclass_v_articulo;
include_once(getabspath("include/venta_events.php"));
$tableEvents["venta"] = new eventclass_venta;
include_once(getabspath("include/gasto_events.php"));
$tableEvents["gasto"] = new eventclass_gasto;
include_once(getabspath("include/det_venta_events.php"));
$tableEvents["det_venta"] = new eventclass_det_venta;
include_once(getabspath("include/det_movimiento_events.php"));
$tableEvents["det_movimiento"] = new eventclass_det_movimiento;
include_once(getabspath("include/movimiento_caja_events.php"));
$tableEvents["movimiento_caja"] = new eventclass_movimiento_caja;
include_once(getabspath("include/det_gasto_events.php"));
$tableEvents["det_gasto"] = new eventclass_det_gasto;
include_once(getabspath("include/reimprimir_mov_cajas_events.php"));
$tableEvents["reimprimir_mov_cajas"] = new eventclass_reimprimir_mov_cajas;
include_once(getabspath("include/v_det_movimiento_events.php"));
$tableEvents["v_det_movimiento"] = new eventclass_v_det_movimiento;
include_once(getabspath("include/inf_ventas_articulos_events.php"));
$tableEvents["inf_ventas_articulos"] = new eventclass_inf_ventas_articulos;
include_once(getabspath("include/inf_cobros_events.php"));
$tableEvents["inf_cobros"] = new eventclass_inf_cobros;
include_once(getabspath("include/inf_ventas_resumido_events.php"));
$tableEvents["inf_ventas_resumido"] = new eventclass_inf_ventas_resumido;
include_once(getabspath("include/inf_ventas_proveedores_events.php"));
$tableEvents["inf_ventas_proveedores"] = new eventclass_inf_ventas_proveedores;
include_once(getabspath("include/cobro_events.php"));
$tableEvents["cobro"] = new eventclass_cobro;
include_once(getabspath("include/inf_gastos_events.php"));
$tableEvents["inf_gastos"] = new eventclass_inf_gastos;
include_once(getabspath("include/inf_mov_cajas_events.php"));
$tableEvents["inf_mov_cajas"] = new eventclass_inf_mov_cajas;
include_once(getabspath("include/ranking_clientes_total_events.php"));
$tableEvents["ranking_clientes_total"] = new eventclass_ranking_clientes_total;
include_once(getabspath("include/ranking_clientes_cant_events.php"));
$tableEvents["ranking_clientes_cant"] = new eventclass_ranking_clientes_cant;
include_once(getabspath("include/inf_ventas_detallado_events.php"));
$tableEvents["inf_ventas_detallado"] = new eventclass_inf_ventas_detallado;
include_once(getabspath("include/inf_utilidad_events.php"));
$tableEvents["inf_utilidad"] = new eventclass_inf_utilidad;
include_once(getabspath("include/generar_barras_events.php"));
$tableEvents["generar_barras"] = new eventclass_generar_barras;
include_once(getabspath("include/registrar_venta_events.php"));
$tableEvents["registrar_venta"] = new eventclass_registrar_venta;
include_once(getabspath("include/inf_ingresos_vs_egresos_events.php"));
$tableEvents["inf_ingresos_vs_egresos"] = new eventclass_inf_ingresos_vs_egresos;

$xt = new Xtempl();

$id = postvalue("id")!=="" ? postvalue("id") : 1;

//array of params for classes
$params["id"] = $id; 
$params["xt"] = &$xt;
$params["tName"] = "global";
$params["pageType"] = PAGE_MENU;
$params["templatefile"] = "menu.htm";
$params["isGroupSecurity"] = $isGroupSecurity;
$params["needSearchClauseObj"] = false;
$pageObject = new RunnerPage($params);

// button handlers file names

//	Before Process event
if($globalEvents->exists("BeforeProcessMenu"))
	$globalEvents->BeforeProcessMenu($conn, $pageObject);

$pageObject->body["begin"] .= "<script type=\"text/javascript\" src=\"include/loadfirst.js\"></script>";
$pageObject->body["begin"] .= "<script type=\"text/javascript\" src=\"include/lang/".getLangFileName(mlang_getcurrentlang()).".js\"></script>";				

$pageObject->addCommonJs();

//fill jsSettings and ControlsHTMLMap
$pageObject->fillSetCntrlMaps();
$pageObject->body['end'] .= '<script>';
$pageObject->body['end'] .= "window.controlsMap = ".my_json_encode($pageObject->controlsHTMLMap).";";
$pageObject->body['end'] .= "window.viewControlsMap = ".my_json_encode($pageObject->viewControlsHTMLMap).";";
$pageObject->body['end'] .= "window.settings = ".my_json_encode($pageObject->jsSettings).";</script>";
$pageObject->body["end"] .= "<script type=\"text/javascript\" src=\"include/runnerJS/RunnerAll.js\"></script>";
$pageObject->body["end"] .= '<script>'.$pageObject->PrepareJS()."</script>";
$xt->assignbyref("body",$pageObject->body);

$xt->assign("username",$_SESSION["UserName"]);
$xt->assign("changepwd_link",$_SESSION["AccessLevel"] != ACCESS_LEVEL_GUEST);
$xt->assign("changepwdlink_attrs","onclick=\"window.location.href='changepwd.php';return false;\"");

$xt->assign("logoutlink_attrs","onclick=\"window.location.href='login.php?a=logout';return false;\"");

$xt->assign("guestloginlink_attrs","onclick=\"window.location.href='login.php';return false;\"");

$xt->assign("loggedas_block", !isLoggedAsGuest());
$xt->assign("logout_link", true);
$xt->assign("guestloginbutton", isLoggedAsGuest());
$xt->assign("logoutbutton", isSingleSign() && !isLoggedAsGuest());

// get redirect location for menu page
$redirect = $pageObject->getRedirectForMenuPage();
if($redirect)
{
	header("Location: ".$redirect); 
	exit();
}

$xt->assign("menu_block",true);
if($globalEvents->exists("BeforeShowMenu"))
	$globalEvents->BeforeShowMenu($xt, $pageObject->templatefile, $pageObject);

$xt->display($pageObject->templatefile);
?>