<?php
ini_set("display_errors","1");
ini_set("display_startup_errors","1");
set_magic_quotes_runtime(0);
include("include/dbcommon.php");
header("Expires: Thu, 01 Jan 1970 00:00:01 GMT");
header("Pragma: no-cache");
header("Cache-Control: no-cache");

include("include/##@TABLE.strShortTableName s##_variables.php");

##if @BUILDER.bCreateLoginPage##
if(!@$_SESSION["UserID"])
{ 
	$_SESSION["MyURL"]=$_SERVER["SCRIPT_NAME"]."?".$_SERVER["QUERY_STRING"];
	header("Location: login.php?message=expired"); 
	return;
}
if(!CheckSecurity(@$_SESSION["_".$strTableName."_OwnerID"],"Search"))
{
	echo "<p>".##message NO_PERMISSIONS##." <a href=\"login.php\">".##message BACK_TO_LOGIN##."</a></p>";
	return;
}
##endif##

$pageName = "chart.php";


//	Before Process event
if(function_exists("BeforeProcessChart"))
	BeforeProcessChart($conn);


//	process request data, fill session variables

if(!count($_POST) && !count($_GET))
{
	$sess_unset = array();
	foreach($_SESSION as $key=>$value)
		if(substr($key,0,strlen($strTableName)+1)==$strTableName."_" &&
			strpos(substr($key,strlen($strTableName)+1),"_")===false)
			$sess_unset[] = $key;
	foreach($sess_unset as $key)
		unset($_SESSION[$key]);
}

if(@$_REQUEST["a"]=="advsearch")
{
	$_SESSION[$strTableName."_asearchnot"]=array();
	$_SESSION[$strTableName."_asearchopt"]=array();
	$_SESSION[$strTableName."_asearchfor"]=array();
	$_SESSION[$strTableName."_asearchfor2"]=array();
	$tosearch=0;
	$asearchfield = postvalue("asearchfield");
	$_SESSION[$strTableName."_asearchtype"] = postvalue("type");
	if(!$_SESSION[$strTableName."_asearchtype"])
		$_SESSION[$strTableName."_asearchtype"]="and";
	foreach($asearchfield as $field)
	{
		$gfield=GoodFieldName($field);
		$asopt=postvalue("asearchopt_".$gfield);
		$value1=postvalue("value_".$gfield);
		$type=postvalue("type_".$gfield);
		$value2=postvalue("value1_".$gfield);
		$not=postvalue("not_".$gfield);
		if($value1 || $asopt=='Empty')
		{
			$tosearch=1;
			$_SESSION[$strTableName."_asearchopt"][$field]=$asopt;
			if(!is_array($value1))
				$_SESSION[$strTableName."_asearchfor"][$field]=$value1;
			else
				$_SESSION[$strTableName."_asearchfor"][$field]=combinevalues($value1);
			$_SESSION[$strTableName."_asearchfortype"][$field]=$type;
			if($value2)
				$_SESSION[$strTableName."_asearchfor2"][$field]=$value2;
			$_SESSION[$strTableName."_asearchnot"][$field]=($not=="on");
		}
	}
	if($tosearch)
		$_SESSION[$strTableName."_search"]=2;
	else
		$_SESSION[$strTableName."_search"]=0;
	$_SESSION[$strTableName."_pagenumber"]=1;
}


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

##if @BUILDER.arrLanguages.len>1##
if(@$_REQUEST["language"])
	$_SESSION["language"]=@$_REQUEST["language"];

$var=GoodFieldName(mlang_getcurrentlang())."_langattrs";
$xt->assign($var,"selected");
$xt->assign("langselector_attrs","name=lang onchange=\"javascript: window.location='##@TABLE.strShortTableName hs##_chart.##@ext##?language='+this.options[this.selectedIndex].value\"");
$xt->assign("languages_block",true);
##endif##



//	table selector
##foreach @BUILDER.Tables as @t filter (@t.bMenuItem || @t.arrMasterTables[strMasterTable==@TABLE.strDataSourceTable].len)##
##if GroupSecurity##
$strPerm = GetUserPermissions("##@t.strDataSourceTable s##");
$allow_##@t.strShortTableName##= (strpos($strPerm, "A")!==false || strpos($strPerm, "S")!==false);
##else##
$allow_##@t.strShortTableName##=true;
##endif##
##endfor##

$createmenu=false;
##foreach @BUILDER.Tables as @t filter @t.bMenuItem order @t.nMenuOrder##
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##\"");
	$xt->assign("##@t.strShortTableName##_optionattrs","value=\"##@t.strShortTableName##_".$page.".##@ext##\"");
}
##endfor##
if($createmenu)
{
	$xt->assign("menu_block",true);
	$xt->assign("menustyle_block",true);
}
$body=array();
$body["begin"]="<script type=\"text/javascript\" src=\"include/jquery.js\"></script>".
"<script language=\"JavaScript\" src=\"include/customlabels.js\"></script>\r\n".
"<script type=\"text/javascript\" src=\"include/jsfunctions.js\"></script>";
$xt->assignbyref("body",$body);

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

##if CreateMenu || IsAdminTable(@TABLE)##
$xt->assign("quickjump_attrs","onchange=\"window.location.href=this.options[this.selectedIndex].value;\"");
##endif##

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

##if @BUILDER.bCreateLoginPage##
$xt->assign("login_block",true);
$xt->assign("username",htmlspecialchars($_SESSION["UserID"]));
$xt->assign("logoutlink_attrs","onclick=\"window.location.href='login.##@ext##?a=logout';\"");
##endif##

$xt->assign("chart_block",true);
$xt->assign("toplinks_block",true);
$xt->assign("asearch_link",true);
$xt->assign("asearchlink_attrs","onclick=\"window.location.href='##@TABLE.strShortTableName h##_search.##@ext##';return false;\"");
$xt->assign("search_records_block",true);
$xt->assign("recordcontrols_block",true);

$templatefile = "##@TABLE.strShortTableName##_chart.htm";
if(function_exists("BeforeShowChart"))
	BeforeShowChart($xt,$templatefile);

$xt->display($templatefile);



?>