<?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/Contact_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=="Pending Customers")
{
	$where ="";
		$where.= GetFullFieldName("Company Name")."=".make_db_value("Company Name",$_SESSION[$strTableName."_masterkey1"]);
}
if($mastertable=="List Management")
{
	$where ="";
		$where.= GetFullFieldName("Company Name")."=".make_db_value("Company Name",$_SESSION[$strTableName."_masterkey1"]);
}
if($mastertable=="Review List")
{
	$where ="";
		$where.= GetFullFieldName("Company Name")."=".make_db_value("Company Name",$_SESSION[$strTableName."_masterkey1"]);
}
if($mastertable=="Inactive customer_list")
{
	$where ="";
		$where.= GetFullFieldName("Company Name")."=".make_db_value("Company Name",$_SESSION[$strTableName."_masterkey1"]);
}
if($mastertable=="Short-Listed Customers")
{
	$where ="";
		$where.= GetFullFieldName("Company Name")."=".make_db_value("Company Name",$_SESSION[$strTableName."_masterkey1"]);
}
if($mastertable=="Active Customers")
{
	$where ="";
		$where.= GetFullFieldName("Company Name")."=".make_db_value("Company Name",$_SESSION[$strTableName."_masterkey1"]);
}
if($mastertable=="Potential Customer List")
{
	$where ="";
		$where.= GetFullFieldName("Company Name")."=".make_db_value("Company Name",$_SESSION[$strTableName."_masterkey1"]);
}
if($mastertable=="Vendor Details")
{
	$where ="";
		$where.= GetFullFieldName("Company Name")."=".make_db_value("Company 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["idCLCP"]));

	
	//	idCLCP - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"idCLCP", ""),"field=idCLCP".$keylink,"",MODE_PRINT);
			$row["idCLCP_value"]=$value;
	//	Name - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"Name", ""),"field=Name".$keylink,"",MODE_PRINT);
			$row["Name_value"]=$value;
	//	Job Title - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"Job Title", ""),"field=Job+Title".$keylink,"",MODE_PRINT);
			$row["Job_Title_value"]=$value;
	//	Phone- Direct - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"Phone- Direct", ""),"field=Phone%2D+Direct".$keylink,"",MODE_PRINT);
			$row["Phone__Direct_value"]=$value;
	//	Phone Extn - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"Phone Extn", ""),"field=Phone+Extn".$keylink,"",MODE_PRINT);
			$row["Phone_Extn_value"]=$value;
	//	Mobile - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"Mobile", ""),"field=Mobile".$keylink,"",MODE_PRINT);
			$row["Mobile_value"]=$value;
	//	E-Mail - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"E-Mail", ""),"field=E%2DMail".$keylink,"",MODE_PRINT);
			$row["E_Mail_value"]=$value;
	//	Notes - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"Notes", ""),"field=Notes".$keylink,"",MODE_PRINT);
			$row["Notes_value"]=$value;
	//	Company Name - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"Company Name", ""),"field=Company+Name".$keylink,"",MODE_PRINT);
			$row["Company_Name_value"]=$value;
	$rowinfo[]=$row;
	}
	$xt->assign_loopsection("details_row",$rowinfo);
} else {
}
$xt->display("Contact_Details_detailspreview.htm");
if($mode!="inline")
	echo "counterSeparator".postvalue("counter");
?>