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

include("include/dbcommon.php");

##if @BUILDER.m_bCreateLoginPage##
if(!@$_SESSION["UserID"])
{
	header("Location: login.php");
	return;
}
##endif##


include('include/xtempl.php');
$xt = new Xtempl();


//	Before Process event
if(function_exists("BeforeProcessMenu"))
	BeforeProcessMenu($conn);
$xt->assign("body",true);
$body=array();
$body["begin"] = "<script type=\"text/javascript\" src=\"include/jquery.js\"></script>".
"<script type=\"text/javascript\" src=\"include/jsfunctions.js\"></script>";
$xt->assignbyref("body",$body);

##if @BUILDER.m_bCreateLoginPage##
$xt->assign("username",$_SESSION["UserID"]);
$xt->assign("changepwd_link",$_SESSION["AccessLevel"] != ACCESS_LEVEL_GUEST);
$xt->assign("changepwdlink_attrs","onclick=\"window.location.href='changepwd.##@ext##';return false;\"");
$xt->assign("logoutlink_attrs","onclick=\"window.location.href='login.##@ext##?a=logout';\"");

$xt->assign("loggedas_block",true);
$xt->assign("logout_link",true);
##endif##
$createmenu = false;
##foreach @BUILDER.Tables as @t filter @t.bMenuItem order @t.nMenuOrder##
##if GroupSecurity##
$strPerm = GetUserPermissions("##@t.strDataSourceTable s##");
$allow_##@t.strShortTableName##= (strpos($strPerm, "A")!==false || strpos($strPerm, "S")!==false);
##else##
$allow_##@t.strShortTableName##=true;
##endif##
if($allow_##@t.strShortTableName##)
{
	$createmenu=true;
	$xt->assign("##@t.strShortTableName##_tablelink",true);
	$page="";
	##if @t.bList##
	$page="list";
	##if @t.bAdd##
	$strPerm = GetUserPermissions("##@t.strDataSourceTable s##");
	if(strpos($strPerm, "A")!==false && strpos($strPerm, "S")===false)
		$page="add";
	##endif##
	##elseif @t.bAdd##
	$page="add";
	##elseif @t.nType==titREPORT##
	$page="report";
	##elseif @t.nType==titCHART##
	$page="chart";
	##endif##
	$xt->assign("##@t.strShortTableName##_tablelink_attrs","href=\"##@t.strShortTableName##_".$page.".##@ext##\"");
}
##endfor##

if($createmenu)
	$xt->assign("menustyle_block",true);


##if @BUILDER.bDynamicPermissions##
if(@$_SESSION["IsAdmin"])
	$xt->assign("adminarea_link",true);
$xt->assign("adminarealink_attrs","onclick=\"window.location.href='admin_rights_list.##@ext##';return false;\"");
##endif##

##if @BUILDER.bWebReports##
$xt->assign("webreports_link",true);
##endif##

$templatefile="menu.htm";
if(function_exists("BeforeShowMenu"))
	BeforeShowMenu($xt,$templatefile);

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