<?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/Quote_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=="Leads-Management")
{
	$where ="";
		$where.= GetFullFieldName("Lead_ID")."=".make_db_value("Lead_ID",$_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["LBOMID"]));

	
	//	Material Code - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"Material Code", ""),"field=Material+Code".$keylink,"",MODE_PRINT);
			$row["Material_Code_value"]=$value;
	//	Quantity - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"Quantity", ""),"field=Quantity".$keylink,"",MODE_PRINT);
			$row["Quantity_value"]=$value;
	//	Unit_Price - Number
		    $value="";
				$value = ProcessLargeText(GetData($data,"Unit_Price", "Number"),"field=Unit%5FPrice".$keylink,"",MODE_PRINT);
			$row["Unit_Price_value"]=$value;
	//	Amonut - Number
		    $value="";
				$value = ProcessLargeText(GetData($data,"Amonut", "Number"),"field=Amonut".$keylink,"",MODE_PRINT);
			$row["Amonut_value"]=$value;
	//	Tax % - Number
		    $value="";
				$value = ProcessLargeText(GetData($data,"Tax %", "Number"),"field=Tax+%25".$keylink,"",MODE_PRINT);
			$row["Tax___value"]=$value;
	//	Ext. Amount - Number
		    $value="";
				$value = ProcessLargeText(GetData($data,"Ext. Amount", "Number"),"field=Ext%2E+Amount".$keylink,"",MODE_PRINT);
			$row["Ext__Amount_value"]=$value;
	//	Specification - HTML
		    $value="";
				$value = GetData($data,"Specification", "HTML");
			$row["Specification_value"]=$value;
	$rowinfo[]=$row;
	}
	$xt->assign_loopsection("details_row",$rowinfo);
} else {
}
$xt->display("Quote_detailspreview.htm");
if($mode!="inline")
	echo "counterSeparator".postvalue("counter");
?>