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

include("include/dbcommon.php");
add_nocache_headers();

include("include/Customer_Summary_variables.php");

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>"."You don't have permissions to access this table"." <a href=\"login.php\">"."Back to login page"."</a></p>";
	return;
}

//	Before Process event
if($eventObj->exists("BeforeProcessChart"))
	$eventObj->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]);
}

include('include/xtempl.php');
include('classes/runnerpage.php');
include('classes/searchclause.php');
include("classes/searchpanel.php");
include("classes/searchpanelsimple.php");	
include("classes/searchcontrol.php");
include("classes/panelsearchcontrol.php");	

$xt = new Xtempl();

$sessionPrefix = $strTableName;

if(postvalue("id"))
	$id = postvalue("id");
else
	$id = 1;
// assign an id			
$xt->assign("id",$id);	

//array of params for, most of them used by searchPanel class
$params = array("id" =>$id, 
				"tName"=>$strTableName,
				"pageType" => PAGE_CHART,
				"shortTableName"=>"Customer_Summary",
				"isDisplayLoading"=>GetTableData($strTableName,".isDisplayLoading",false),
				"menuTablesArr"=> $menuTablesArr,
				"isGroupSecurity"=>$isGroupSecurity);
$params["xt"]=&$xt;
$pageObject = new RunnerPage($params);

// SearchClause class stuff
$pageObject->searchClauseObj->parseRequest();
$_SESSION[$sessionPrefix.'_advsearch'] = serialize($pageObject->searchClauseObj);

// add button events if exist
$pageObject->addButtonHandlers();

// add onload event
$onLoadJsCode = GetTableData($pageObject->tName, ".jsOnloadChart", '');
$pageObject->addOnLoadJsEvent($onLoadJsCode);


$pageObject->addCommonJs();

$pageObject->createOldMenu();

if($pageObject->isCreateMenu())
{
	$xt->assign("menu_block",true);
	$xt->assign("menustyle_block",true);
}





$xt->assign("quickjump_attrs","onchange=\"window.location.href=this.options[this.selectedIndex].value;\"");


$xt->assign("security_block", true);
$xt->assign("username",htmlspecialchars($_SESSION["UserID"]));
$xt->assign("logoutlink_attrs","onclick=\"window.location.href='login.php?a=logout';return false;\"");

$xt->assign("chart_block",true);
$xt->assign("toplinks_block",true);
$xt->assign("asearch_link",true);
$xt->assign("asearchlink_attrs","id=\"asearch_".$id."\" name=\"asearch_".$id."\" onclick=\"window.location.href='Customer_Summary_search.php';return false;\"");
$xt->assign("search_records_block",true);
//$xt->assign("recordcontrols_block",true);

$xt->assign("searchform_showall",true);
$xt->assign("showallbutton_attrs","onclick=\"window.location.href='Customer_Summary_chart.php?a=showall';\"");

if(!GetChartXML("Customer_Summary"))
	$xt->assign("chart_block",false);

	
// assign for lheader

// create searchPanel
$args = array();
$args['pageObj'] = &$pageObject;
$searchPanelObj = new SearchPanelSimple($args);
$searchPanelObj->buildSearchPanel('adv_search_panel');

$pageObject->body['begin'] .= "<script type=\"text/javascript\" src=\"include/jquery.js\"></script>\r\n";
if ($pageObject->debugJSMode === true)
{
	/*$pageObject->body['begin'] .= "<script type=\"text/javascript\" src=\"include/runnerJS/Runner.js\"></script>\r\n".
		"<script type=\"text/javascript\" src=\"include/runnerJS/Util.js\"></script>\r\n".
		"<script type=\"text/javascript\" src=\"include/runnerJS/Observer.js\"></script>\r\n";*/
	$pageObject->body['begin'] .= "<script language=\"JavaScript\" src=\"include/runnerJS/RunnerBase.js\"></script>\r\n";
}
else
{
	$pageObject->body['begin'] .= "<script language=\"JavaScript\" src=\"include/runnerJS/RunnerBase.js\"></script>\r\n";
}
				
				
$pageObject->body['begin'] .= "<script language=\"JavaScript\" src=\"include/jsfunctions.js\"></script>\r\n".
				($pageObject->isDisplayLoading ? "<script type=\"text/javascript\">runLoading(".$id.",document.body,0);</script>" : "").				
				"<div id=\"search_suggest\" class=\"search_suggest\"></div>";

				
				
// assign body end in such way, to prevent collisions with flyId increment 

$pageObject->body["end"] .= "<script>".$pageObject->PrepareJs()."</script>";

// assign body end
$pageObject->body['end'] = array();
$pageObject->body['end']["method"] = "assignBodyEnd";		
$pageObject->body['end']["object"] = &$pageObject;	

$xt->assignbyref('body', $pageObject->body);

$xt->assign("left_block", true);

$xt->assign("style_block",true);
$xt->assign("shiftstyle_block", true);
// end assign for lheader
	
$templatefile = "Customer_Summary_chart.htm";
if($eventObj->exists("BeforeShowChart"))
	$eventObj->BeforeShowChart($xt,$templatefile);

$xt->display($templatefile);



?>
