<?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/SPC_Approval_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=="SPC-Pending")
{
	$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"]));

	
	//	LBOMID - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"LBOMID", ""),"field=LBOMID".$keylink,"",MODE_PRINT);
			$row["LBOMID_value"]=$value;
	//	Material Category - 
		    $value="";
				$value=DisplayLookupWizard("Material Category",$data["Material Category"],$data,$keylink,MODE_PRINT);
			$row["Material_Category_value"]=$value;
	//	Material Code - HTML
		    $value="";
				$value=DisplayLookupWizard("Material Code",$data["Material Code"],$data,$keylink,MODE_PRINT);
			$row["Material_Code_value"]=$value;
	//	Quantity - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"Quantity", ""),"field=Quantity".$keylink,"",MODE_PRINT);
			$row["Quantity_value"]=$value;
	//	SPC_REQ_BY - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"SPC_REQ_BY", ""),"field=SPC%5FREQ%5FBY".$keylink,"",MODE_PRINT);
			$row["SPC_REQ_BY_value"]=$value;
	//	Target_Price - Number
		    $value="";
				$value = ProcessLargeText(GetData($data,"Target_Price", "Number"),"field=Target%5FPrice".$keylink,"",MODE_PRINT);
			$row["Target_Price_value"]=$value;
	//	SPC_Status - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"SPC_Status", ""),"field=SPC%5FStatus".$keylink,"",MODE_PRINT);
			$row["SPC_Status_value"]=$value;
	//	Special_Price - Number
		    $value="";
				$value = ProcessLargeText(GetData($data,"Special_Price", "Number"),"field=Special%5FPrice".$keylink,"",MODE_PRINT);
			$row["Special_Price_value"]=$value;
	//	SPC_Approved_By - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"SPC_Approved_By", ""),"field=SPC%5FApproved%5FBy".$keylink,"",MODE_PRINT);
			$row["SPC_Approved_By_value"]=$value;
	//	List_Price - Number
		    $value="";
				$value = ProcessLargeText(GetData($data,"List_Price", "Number"),"field=List%5FPrice".$keylink,"",MODE_PRINT);
			$row["List_Price_value"]=$value;
	//	MDP - Number
		    $value="";
				$value = ProcessLargeText(GetData($data,"MDP", "Number"),"field=MDP".$keylink,"",MODE_PRINT);
			$row["MDP_value"]=$value;
	//	Last Updated on - Short Date
		    $value="";
				$value = ProcessLargeText(GetData($data,"Last Updated on", "Short Date"),"field=Last+Updated+on".$keylink,"",MODE_PRINT);
			$row["Last_Updated_on_value"]=$value;
	//	Last Updated by - 
		    $value="";
				$value = ProcessLargeText(GetData($data,"Last Updated by", ""),"field=Last+Updated+by".$keylink,"",MODE_PRINT);
			$row["Last_Updated_by_value"]=$value;
	//	Target_Amt - Number
		    $value="";
				$value = ProcessLargeText(GetData($data,"Target_Amt", "Number"),"field=Target%5FAmt".$keylink,"",MODE_PRINT);
			$row["Target_Amt_value"]=$value;
	//	SPC_Amt - Number
		    $value="";
				$value = ProcessLargeText(GetData($data,"SPC_Amt", "Number"),"field=SPC%5FAmt".$keylink,"",MODE_PRINT);
			$row["SPC_Amt_value"]=$value;
	$rowinfo[]=$row;
	}
	$xt->assign_loopsection("details_row",$rowinfo);
} else {
}
$xt->display("SPC_Approval_detailspreview.htm");
if($mode!="inline")
	echo "counterSeparator".postvalue("counter");
?>