<?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/Open_Leads_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=="Vendor Details")
{
	$where ="";
		$where.= GetFullFieldName("Alligned Vendor")."=".make_db_value("Alligned Vendor",$_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["Leadid"]));

	
	//	Leadid - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"Leadid", ""),"field=Leadid".$keylink,"",MODE_PRINT);
			$row["Leadid_value"]=$value;
	//	Region - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"Region", ""),"field=Region".$keylink,"",MODE_PRINT);
			$row["Region_value"]=$value;
	//	Customer Name - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"Customer Name", ""),"field=Customer+Name".$keylink,"",MODE_PRINT);
			$row["Customer_Name_value"]=$value;
	//	Contact Person - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"Contact Person", ""),"field=Contact+Person".$keylink,"",MODE_PRINT);
			$row["Contact_Person_value"]=$value;
	//	Lead Details - HTML
		    $value="";
				$value = GetData($data,"Lead Details", "HTML");
			$row["Lead_Details_value"]=$value;
	//	Employee Name - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"Employee Name", ""),"field=Employee+Name".$keylink,"",MODE_PRINT);
			$row["Employee_Name_value"]=$value;
	//	Approx Closure Date - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"Approx Closure Date", ""),"field=Approx+Closure+Date".$keylink,"",MODE_PRINT);
			$row["Approx_Closure_Date_value"]=$value;
	//	Lead Status - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"Lead Status", ""),"field=Lead+Status".$keylink,"",MODE_PRINT);
			$row["Lead_Status_value"]=$value;
	//	Requirement Details - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"Requirement Details", ""),"field=Requirement+Details".$keylink,"",MODE_PRINT);
			$row["Requirement_Details_value"]=$value;
	//	Approx Value - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"Approx Value", ""),"field=Approx+Value".$keylink,"",MODE_PRINT);
			$row["Approx_Value_value"]=$value;
	//	First Quote Remarks - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"First Quote Remarks", ""),"field=First+Quote+Remarks".$keylink,"",MODE_PRINT);
			$row["First_Quote_Remarks_value"]=$value;
	//	Proposed Closure Date - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"Proposed Closure Date", ""),"field=Proposed+Closure+Date".$keylink,"",MODE_PRINT);
			$row["Proposed_Closure_Date_value"]=$value;
	//	Projected Closure QTR - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"Projected Closure QTR", ""),"field=Projected+Closure+QTR".$keylink,"",MODE_PRINT);
			$row["Projected_Closure_QTR_value"]=$value;
	//	Proposed Solution Details - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"Proposed Solution Details", ""),"field=Proposed+Solution+Details".$keylink,"",MODE_PRINT);
			$row["Proposed_Solution_Details_value"]=$value;
	//	Quoted Price - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"Quoted Price", ""),"field=Quoted+Price".$keylink,"",MODE_PRINT);
			$row["Quoted_Price_value"]=$value;
	//	Final Quote Remarks - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"Final Quote Remarks", ""),"field=Final+Quote+Remarks".$keylink,"",MODE_PRINT);
			$row["Final_Quote_Remarks_value"]=$value;
	//	Discussion Highlights - HTML
		    $value="";
				$value = GetData($data,"Discussion Highlights", "HTML");
			$row["Discussion_Highlights_value"]=$value;
	//	WIN / Lost Analysis - HTML
		    $value="";
				$value = GetData($data,"WIN / Lost Analysis", "HTML");
			$row["WIN___Lost_Analysis_value"]=$value;
	//	Alligned Vendor - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"Alligned Vendor", ""),"field=Alligned+Vendor".$keylink,"",MODE_PRINT);
			$row["Alligned_Vendor_value"]=$value;
	$rowinfo[]=$row;
	}
	$xt->assign_loopsection("details_row",$rowinfo);
} else {
}
$xt->display("Open_Leads_detailspreview.htm");
if($mode!="inline")
	echo "counterSeparator".postvalue("counter");
?>