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

include("include/dbcommon.php");
header("Expires: Thu, 01 Jan 1970 00:00:01 GMT"); 

include("include/Visit_Details_variables.php");

$mode=postvalue("mode");

if(!@$_SESSION["UserID"])
{ 
	return;
}
if(!CheckSecurity(@$_SESSION["_".$strTableName."_OwnerID"],"Search"))
{
	return;
}

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


$recordsCounter = 0;

//	process masterkey value
$mastertable=postvalue("mastertable");
if($mastertable!="")
{
	$_SESSION[$strTableName."_mastertable"]=$mastertable;
//	copy keys to session
	$i=1;
	while(isset($_REQUEST["masterkey".$i]))
	{
		$_SESSION[$strTableName."_masterkey".$i]=$_REQUEST["masterkey".$i];
		$i++;
	}
	if(isset($_SESSION[$strTableName."_masterkey".$i]))
		unset($_SESSION[$strTableName."_masterkey".$i]);
}
else
	$mastertable=$_SESSION[$strTableName."_mastertable"];

//$strSQL = $gstrSQL;

if($mastertable=="Active Customers")
{
	$where ="";
		$where.= GetFullFieldName("Customer Name")."=".make_db_value("Customer Name",$_SESSION[$strTableName."_masterkey1"]);
}
if($mastertable=="Short-Listed Customers")
{
	$where ="";
		$where.= GetFullFieldName("Customer Name")."=".make_db_value("Customer Name",$_SESSION[$strTableName."_masterkey1"]);
}
if($mastertable=="Potential Customer List")
{
	$where ="";
		$where.= GetFullFieldName("Customer Name")."=".make_db_value("Customer Name",$_SESSION[$strTableName."_masterkey1"]);
}


$str = SecuritySQL("Search");
if(strlen($str))
	$where.=" and ".$str;
$strSQL = gSQLWhere($where);

$strSQL.=" ".$gstrOrderBy;

$rowcount=gSQLRowCount($where);

$xt->assign("row_count",$rowcount);
if ( $rowcount ) {
	$xt->assign("details_data",true);
	$rs=db_query($strSQL,$conn);

	$display_count=10;
	if($mode=="inline")
		$display_count*=2;
	if($rowcount>$display_count+2)
	{
		$xt->assign("display_first",true);
		$xt->assign("display_count",$display_count);
	}
	else
		$display_count = $rowcount;

	$rowinfo=array();
		
	while (($data = db_fetch_array($rs)) && $recordsCounter<$display_count) {
		$recordsCounter++;
		$row=array();
		$keylink="";
		$keylink.="&key1=".htmlspecialchars(rawurlencode(@$data["idvisit_register"]));

	
	//	idvisit_register - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"idvisit_register", ""),"field=idvisit%5Fregister".$keylink,"",MODE_PRINT);
			$row["idvisit_register_value"]=$value;
	//	Employee Name - 
		    $value="";
				$value=DisplayLookupWizard("Employee Name",$data["Employee Name"],$data,$keylink,MODE_PRINT);
			$row["Employee_Name_value"]=$value;
	//	Contact Person - 
		    $value="";
				$value=DisplayLookupWizard("Contact Person",$data["Contact Person"],$data,$keylink,MODE_PRINT);
			$row["Contact_Person_value"]=$value;
	//	Purpose Of Visit - 
		    $value="";
				$value=DisplayLookupWizard("Purpose Of Visit",$data["Purpose Of Visit"],$data,$keylink,MODE_PRINT);
			$row["Purpose_Of_Visit_value"]=$value;
	//	MOM Summary - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"MOM Summary", ""),"field=MOM+Summary".$keylink,"",MODE_PRINT);
			$row["MOM_Summary_value"]=$value;
	//	Date Of Visit - Short Date
		    $value="";
				$value = ProcessLargeText(GetData($data,"Date Of Visit", "Short Date"),"field=Date+Of+Visit".$keylink,"",MODE_PRINT);
			$row["Date_Of_Visit_value"]=$value;
	//	Visit Status - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"Visit Status", ""),"field=Visit+Status".$keylink,"",MODE_PRINT);
			$row["Visit_Status_value"]=$value;
	//	Customer Name - 
		    $value="";
				$value=DisplayLookupWizard("Customer Name",$data["Customer Name"],$data,$keylink,MODE_PRINT);
			$row["Customer_Name_value"]=$value;
	$rowinfo[]=$row;
	}
	$xt->assign_loopsection("details_row",$rowinfo);
} else {
}
$xt->display("Visit_Details_detailspreview.htm");
if($mode!="inline")
	echo "counterSeparator".postvalue("counter");
?>