<?php

session_start();
if($_SESSION['dbName']==""){
header("location:../index.php");
}


include("config.inc.php");
include("function.inc.php");
include("Functions_Trans.php");

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");

$fromdate   =$_POST["fromdate"];
$todate     =$_POST["todate"];

if ($fromdate == '')
	$fromdate = date('01/m/Y');

if ($todate == '')
	$todate =  date('d/m/Y');

if ($perpage == '' ) $perpage = $config['trowlimit'][0];

$querylog=" select ifNull(FA_PaymentRqstDel,0) As FA_PaymentRqstDel, ifNull(FA_PaymentRqstMod,0) As FA_PaymentRqstMod, ".
          " ifNull(login_belongstogrp,0) As FI_BelongsToGrp, ifNull(ShowTransaction,0) As ShowTransaction ".
          " from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')  ";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

//Read From Module Table
$querymodule=" Select ifNull(Module_Project,0) As Module_Project, ifNull(Module_Costcenter,0) As Module_CostCenter, ".
			 " ifNull(Module_ProjectParent,0) As Module_ProjectParent, ifNull(Module_CostCenterParent,0) As Module_CostCenterParent, ".
			 " ifNull(Module_BelongsToGroup,0) As Module_BelongsToGroup From Module";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}


//Access Mode On Insert/Edit/Delete
$DelMode  =1;
$EditMode =1;
$PrevMode =1;

$PrevHint   = '';
$EditHint   = '';
$DelHint    = '';



$querysetup="select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2 from setup";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
extract($rowsetup);
}

$MainCompanyName=explode('_',$_SESSION['dbName']);

$queryperiod= " Select ifNull(LockViewPeriod,0) As LockViewPeriod, ViewPeriodDate, ifNull(ViewLockDaily,0) As ViewLockDaily, ViewNumberOfDays ".
              " From ".$_SESSION['dbLabel'].".ListUserDir  ".
			  " Where Usercode='".$_SESSION['useraccount']."' ".
			  " And Upper(CompanyName) = Upper('".$MainCompanyName[0]."') ".
			  " And Upper(Diryear) = Upper('".$MainCompanyName[1]."') ";
			  
$resultperiod = mysql_query($queryperiod,$connection) or die(mysql_error());
$rowsperiod   = mysql_num_rows($resultperiod);

while($rows=mysql_fetch_array($resultperiod)){
	extract($rows);
}	
			  
//echo $queryperiod;	

$queryproject=" select distinct project.project_code, project_name ".
              " from project left join ".$_SESSION['dbLabel'].".loginstk on (($Module_ProjectParent=1 and project.project_code like concat(ifnull(loginstk.project_code,project.project_code),'%')) or ($Module_ProjectParent=0 and project.project_code = loginstk.project_code )) ".
			  " where user_account='".$_SESSION['useraccount']."' ".
			  " and (loginstk.project_code is not null and loginstk.project_code != '') ".
			  " order by project.project_code";
$projectresult = mysql_query($queryproject,$connection) or die(mysql_error());
$projectexist  = mysql_num_rows($projectresult);		  

$querycostcent=" select distinct costcent.costcent_code, costcent_name ".
               " from costcent left join ".$_SESSION['dbLabel'].".loginstk on (($Module_CostCenterParent=1 and costcent.costcent_code like concat(ifnull(loginstk.costcent_code,costcent.costcent_code),'%')) or ($Module_CostCenterParent=0 and costcent.costcent_code = loginstk.costcent_code )) ".
			   " where user_account='".$_SESSION['useraccount']."' ".
			   " and (loginstk.costcent_code is not null and loginstk.costcent_code != '') ".
			   " order by costcent.costcent_code";
$costcentresult = mysql_query($querycostcent,$connection) or die(mysql_error());
$costcentexist  = mysql_num_rows($costcentresult);		  

$queryledger= " select distinct ledger_number, ledger_include ".
              " from ".$_SESSION['dbLabel'].".ledgerstk  ".
			  " where user_account='".$_SESSION['useraccount']."' ".
			  " order by ledger_number";
$ledgerresult = mysql_query($queryledger,$connection) or die(mysql_error());
$ledgerexist  = mysql_num_rows($ledgerresult);	
$rows=mysql_fetch_array($ledgerresult) ;
$ledgerinclude = $rows[1];


//Get Default Project
$querydflproject="select project_code as defaultproject from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and default_project=1 ";
$resultdflproject=mysql_query($querydflproject,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflproject)){
	extract($rows);
}
	
//Get Default Coscenter
$querydflcostcent="select costcent_code as defaultcostcent from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and default_costcenter=1 ";
$resultdflcostcent=mysql_query($querydflcostcent,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflcostcent)){
	extract($rows);
}


$querymodule=" Select ifNull(paymentrqstNoDt,0) As paymentrqstNoDt, ifnull(toBeApprovedByHOD,0) as toBeApprovedByHOD ".
			 " From paymentsetup";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}



if ((!isset($PProjectCode)) && $Module_Project == 1)
	$PProjectCode = $defaultproject;
if ((!isset($PCostCentCode)) && $Module_CostCenter == 1)	
	$PCostCentCode = $defaultcostcent;	

if (empty($orderby))  $orderby = 1;
if (empty($searchby)) $searchby = 2;

if ($startrange=='')  $startrange = 0;
if ($perpage=='')	  $perpage = 20;

print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" media="all" href="css/style.css">

<title>Search Payment Request</title>
<script type="text/javascript" language="javascript">

function ClearForm()
{
	document.search.keyword.value='';
	document.search.PProjectCode.value='';
	document.search.PCostCentCode.value='';
	
	document.search.action='Form_PaymentRqstUnconfirmed.php';
	document.search.submit();

}

function LoadForm() 
{
	x=document.search;
	x.keyword.focus();
	
	ChangeLocation();
}

function SetNextPage(startrange,perpage){ 
  
	document.search.action='Form_PaymentRqstUnconfirmed.php?keyword=&startrange='+startrange+'&perpage='+perpage;
	document.search.submit();
}

function SetPrvPage(startrange,perpage){
	
	document.search.action='Form_PaymentRqstUnconfirmed.php?keyword=&startrange='+startrange+'&perpage='+perpage;
	document.search.submit();
}

function SetFirstPage(startrange,perpage){
	document.search.action='Form_PaymentRqstUnconfirmed.php?startrange=0&perpage='+perpage;
	document.search.submit();
}

function SetLastPage(perpage,totalrows){
	var result=totalrows % perpage;
	if (result == 0) result = perpage;
	startrange=totalrows-result;
	document.search.action='Form_PaymentRqstUnconfirmed.php?startrange='+startrange+'&perpage='+perpage;
	document.search.submit();
}

function UpdateRecord(PaymentRqstId){
	document.search.action="Form_PaymentRqst_Actions.php?mainmode=search2&STransId="+PaymentRqstId;
	document.search.submit();
	
	document.search.PMode.value=1;
	
	opener.document.paymentrqst.txtTransId.value=PaymentRqstId;
	opener.document.paymentrqst.mainaction.value='edit';
	opener.document.paymentrqst.actionmode.value='';
	
	//opener.document.paymentrqst.action='Form_PaymentRqst.php';
	//opener.document.paymentrqst.submit();
	
	
	//self.close();
	

}

function ConfirmRecord(PaymentRqstId){
	document.search.action="Form_PaymentRqst_Actions.php?mainmode=approveConfirm&STransId="+PaymentRqstId;
	document.search.submit();
}

function PrintPreview(PaymentRqstId)
{
	var str = '';
	
	str = 'Form_PaymentRqstPreview.php?PaymentRqstId='+PaymentRqstId;
	window.open(str);
	
	//self.close();

}

function ChangeLocation()
{
    if (document.search.PMode.value == 1) {
		opener.document.paymentrqst.action='Form_PaymentRqst.php';
		opener.document.paymentrqst.submit();
		self.close();
	} else {
		opener.document.paymentrqst.txtTransId.value='';
		opener.document.paymentrqst.mainaction.value='';
		opener.document.paymentrqst.actionmode.value='';
	}
	
}

function showlistProject(str){

  window.open('List_SorProject.php?frm=6&item='+str,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistCostcenter(str){

  window.open('List_SorCostcenter.php?frm=6&item='+str,'mywindow','width=850,height=550,,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function RefreshPage()
{
	document.search.action='Form_PaymentRqstUnconfirmed.php?startrange=0';
	document.search.submit();
}


function SelectSearchBy()
{	
 
  //document.search.keyword.value='';
  document.search.action='Form_PaymentRqstUnconfirmed.php?startrange=0';
  document.search.submit();

}

function SubmitForm()
{	
 
  //document.search.keyword.value='';
  document.search.action='Form_PaymentRqstSearch.php?startrange=0';
  document.search.submit();

}

function kd(e)
{
	x=document.search;
    var intKey = (window.Event) ? e.which : e.keyCode;
	
    if (intKey == 13) { //enter key
        x.btnSubmit.click();
		return false;
    }
    return true;
}


</script>

<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
body {
	margin-top: 2px;
	margin-left: 1px;
}
a:link {
	text-decoration: none;
	color: #0000FF;
}
a:visited {
	text-decoration: none;
	color: #0000FF;
}
a:hover {
	text-decoration: none;
	color: #0000FF;
}
a:active {
	text-decoration: none;
	color: #0000FF;
}

.style12 {
	font-size: 9px;
	color: #999999;
	font-weight: bold;
}
.style15 {color: #5151FF; }
.style16 {
	font-size: 16px;
	color: #FF0000;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
.style17 {font-size: 9px}
.style25 {color: #999999; font-weight: bold; font-size: 10px; }
.style26 {color: #FF0000}
.style27 {color: #999999 ;font-size: 10px;}
.style28 {color: #000000 ;font-size: 10px;}

</style>
<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="dhtmlgoodies_calendar.js?random=20060118"></script>
</head>
<body onLoad='LoadForm();' class='bodybackground'>
<form name='search' method='post' action="">

HERE;



if (empty($ViewPeriodDate))
   $ViewPeriodDate = 'Null';
if (empty($ViewNumberOfDays))   
   $ViewNumberOfDays = 1;
			 
$PRef = GetSQLValueString($keyword, 'text');
		 
$querysearch=" Select PaymentRqst.PaymentRqst_ID, PaymentRqst.PaymentRqst_RefGovernment, Date_Format(PaymentRqst.PaymentRqst_Date,'%d-%m-%Y') As PaymentRqst_Date, ".
             " PaymentRqst.PaymentRqst_Remark, PaymentRqst.PaymentRqst_Name, PaymentRqst.Touser_account, PaymentRqst.User_Confirmed, ".
			 " PaymentRqst.PaymentRqst_ManualNo, PaymentRqst.PaymentRqst_Desc, Project.Project_Name As ProjectName, Costcent.Costcent_name As CostcentName, ".
			 " Round(ifNull(PaymentRqst.PaymentRqst_AmountD1,0), ".$DecimalBase.") as PaymentRqst_AmountD1 , Round(ifNull(PaymentRqst.PaymentRqst_AmountD2,0), ".$DecimalBase.") as PaymentRqst_AmountD2, ".
			 " Round(ifNull(PaymentRqst.PaymentRqst_AmountC1,0), ".$DecimalBase.") as PaymentRqst_AmountC1, Round(ifNull(PaymentRqst.PaymentRqst_AmountC2,0), ".$DecimalBase.") as PaymentRqst_AmountC2, ".
			 " ifNull(Temp_PaymentRqst.PaymentRqst_Id, -1) As TempPaymentRqstId, PaymentRqst.CURRENCY_CODE as  CURRENCY_CODE, PaymentRqst.user_account as user_account, PaymentRqst.PaymentRqst_App as PaymentRqst_App ".
			 " From PaymentRqst ".
			 " Left Join Project on PaymentRqst.Project_Code = Project.Project_Code ".
			 " Left Join Costcent on PaymentRqst.Costcent_code = Costcent.Costcent_code ".
			 " Left Join Temp_PaymentRqst on Temp_PaymentRqst.PaymentRqst_ID = PaymentRqst.PaymentRqst_ID ";
			 
if ($projectexist >	0)
  $querysearch= $querysearch." Inner join ( select distinct project_code from ".$_SESSION['dbLabel'].".loginstk ".
							 "			   where loginstk.user_account='".$_SESSION['useraccount']."' ".
							 "             and (project_code is not null and project_code != '') ".
							 "			 ) Q1 on (($Module_ProjectParent=1 and PaymentRqst.project_code like concat(Q1.project_code,'%')) or ($Module_ProjectParent=0 and PaymentRqst.project_code = Q1.project_code )) ";
							 
if ($costcentexist > 0)
  $querysearch= $querysearch." Inner join ( select distinct costcent_code from ".$_SESSION['dbLabel'].".loginstk ".
							 "			   where loginstk.user_account='".$_SESSION['useraccount']."' ".
							 "             and (costcent_code is not null and costcent_code != '') ".
							 "			 ) Q2 on (($Module_CostCenterParent=1 and PaymentRqst.costcent_code like concat(Q2.costcent_code,'%')) or ($Module_CostCenterParent=0 and PaymentRqst.costcent_code = Q2.costcent_code )) ";

$querysearch= $querysearch.											 
			 " Where (($searchby = 2 and ifNull(PaymentRqst.PaymentRqst_RefGovernment,-1) Like Concat(ifNull($PRef, ifNull(PaymentRqst.PaymentRqst_RefGovernment,-1)),'%')) Or ".
			 "        ($searchby = 1 and Date_Format(PaymentRqst.PaymentRqst_Date,'%Y-%m-%d') = ifNull(Date_Format($PRef,'%Y-%m-%d'), Date_Format(PaymentRqst.PaymentRqst_Date,'%Y-%m-%d'))) Or  ".
			 "        ($searchby = 3 and PaymentRqst.Touser_account Like Concat('%', ifNull($PRef, PaymentRqst.Touser_account),'%')) Or ".
			 "        ($searchby = 4 and PaymentRqst.PaymentRqst_Name Like Concat('%', ifNull($PRef, PaymentRqst.PaymentRqst_Name),'%')) ) ".
			 " And (($rowsperiod = 0 and 1 = 1) Or ($rowsperiod > 0 and (($LockViewPeriod = 1 and  Date_Format(PaymentRqst.PaymentRqst_Date,'%Y-%m-%d') >= Date_Format(ifNull('".$ViewPeriodDate."',PaymentRqst.PaymentRqst_Date),'%Y-%m-%d')) Or ($LockViewPeriod = 0 and 1=1 ))   ".
             "                                                      and (($ViewLockDaily = 1 and DateDiff(Date_Format(Now(),'%Y-%m-%d'),Date_Format(PaymentRqst.PaymentRqst_Date,'%Y-%m-%d')) <= $ViewNumberOfDays) Or ($ViewLockDaily = 0 and  1 = 1 ))) ) ";
			 
if ($Module_BelongsToGroup == 1)
	$querysearch= $querysearch." And ifNull(PaymentRqst.PaymentRqst_BelongsToGrp,0) >= ifNull($FI_BelongsToGrp,0) ";
	
	$querysearch= $querysearch." And ((Upper(PaymentRqst.Touser_account) = Upper('".$_SESSION['useraccount']."') and ifnull(PaymentRqst.PaymentRqst_App,0) = 0)  
										or (upper(PaymentRqst.user_confirmed) = Upper('".$_SESSION['useraccount']."') and ifnull(PaymentRqst.PaymentRqst_Confirmed,0) = 0 
											and ifnull(PaymentRqst.PaymentRqst_App,0) = 1)) ";
				 
if ($PProjectCode != '')
	$querysearch= $querysearch." And PaymentRqst.project_code like concat('".$PProjectCode."','%') ";
if ($PCostCentCode != '')
	$querysearch= $querysearch." And PaymentRqst.costcent_code like concat('".$PCostCentCode."','%') ";	

if ($orderby == 1)
	$querysearch= $querysearch." Order By PaymentRqst.PaymentRqst_Date Desc, PaymentRqst.PaymentRqst_RefGovernment Desc ";
else if ($orderby == 2)
	$querysearch= $querysearch." Order By PaymentRqst.PaymentRqst_RefGovernment Desc ";	
	
$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());
$totalrows = mysql_num_rows($resultsearch);
	
	
$querysearch = $querysearch." limit ".$startrange.",".$perpage;

$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());	

echo"<table cellpadding='0' cellspacing='0' border='0'  align='left' style='table-layout:fixed' width='1350px;'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; width:908px' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>List of Unconfirmed Payment Request</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";

echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";
		 
echo"<table border='0' cellspacing='1'  style='table-layout:fixed'>
	  <col width=20><col width=20><col width=20>
	  <col width=80><col width=80>
	  <col width=200><col width=200><col width=250>
	  <col width=120><col width=150><col width=150>
		     	
	  <tr class='Search-header-bg'>";
	  
if ($Module_Project == 1) {
	echo" <td align='left' colspan='4'><span class='style4'>Project</span></td>
	      <td align='left' colspan='2'><span class='style4'>
		    <input type='text' name='PProjectCode' id='PProjectCode' value='$PProjectCode' size='15' maxlength='20' /></span>
		    <label><span class='style4'><img src='img/btnopen.jpg' title=' Select Project ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistProject(1); '  /></span></label></td>";
} else {
	echo" <td align='left' colspan='6'><input type='hidden' name='PProjectCode' id='PProjectCode' value='$PProjectCode' /></td>";

}			

if ($Module_CostCenter == 1) {		  
	echo" <td align='right' ><span class='style4'>Costcenter</span></td>		
		  <td align='left' ><span class='style4'>
		    <input type='text' name='PCostCentCode' id='PCostCentCode' value='$PCostCentCode' size='15' maxlength='20' /></span>
		    <label><span class='style4'><img src='img/btnopen.jpg' title=' Select Costcenter ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistCostcenter(1); ' /></span></label></td>";
} else {
	echo" <td align='left' colspan='2'><input type='hidden' name='PCostCentCode' id='PCostCentCode' value='$PCostCentCode' /></td>";

}	  


echo" 	<td align='right' ><span class='style4'>Order By</span></td>		
		<td align='left' colspan=2><span class='style4'><select name='orderby' id='orderby' value='$orderby' onchange='RefreshPage();'>";
		
		if ($orderby==1)
			$s11 = 'selected';
		else if ($orderby==2)
			$s12 = 'selected';
			
		echo"<option ".$s11." value='1'>Date</option>
			 <option ".$s12." value='2'>Reference</option>
			 </select></span></td>";
		  
echo" <td></td></tr>";
echo" <tr class='Search-header-bg'>	  
	    <td align='left' colspan='4'><span class='style4'>Search By</span></td>
		<td align='left' colspan='7'><span class='style4'><input type='text' name='keyword' id='keyword' value='$keyword' style='width:200px;' /><input type='hidden' name='PMode' id='PMode' value='$PMode' size='15' maxlength='30'/></span>
			
			<select name='searchby' id='searchby' value='$searchby' onchange='SelectSearchBy();'>";
		
			if ($searchby==1)
				$s21 = 'selected';
			else if ($searchby==2)
				$s22 = 'selected';
			else if ($searchby==3)
				$s23 = 'selected';
			else if ($searchby==4)
				$s24 = 'selected';		
				
			echo"<option ".$s21." value='1'>Date (yyyy-mm-dd)</option>
				 <option ".$s22." value='2'>Reference</option>
				 <option ".$s23." value='3'>Approved By</option>
				 <option ".$s24." value='4'>Representative</option>
				 </select>";	
				 
echo"     		<button type='button' id='btnFind' name='btnFind' onclick='SubmitForm(); return false;' title='Find'><span><span>Find</span></span></button>
					<button type='button' id='btnCancel' name='btnCancel' onclick='ClearForm(); return false;' title='Cancel'><span><span>Cancel</span></span></button>
				
		</td>";	
			echo"	<td></td></tr>
					</table>
		</td>
		<td id='search-content3' style='width:31px;'>&nbsp;</td>"; 
echo" </tr>";

echo"<tr>
		<td  id='search-content1' style='height:34px;width:31px;'>&nbsp;</td>
		<td  id='search-content2' style='height:34px;width:908px;'>
		<table width='100%' border=0>
		<tr>
			<td align='right' style='width:380px;'><span class='style4'>Per Page </span><span class='style4'><select name='perpage' id='perpage' value='$perpage' onchange='RefreshPage();'>";
              
            $perpages = $config['trowlimit'];
			foreach ($perpages as $val){
			echo" <option value = '$val' "; if ($perpage ==$val) echo "selected"; 
			echo" >$val</option> ";
			}
	echo'	
				 </select></span></td>
			<td  style="width:74px;border-right:1px solid #000000;text-align:right;">';
			
			if($startrange > 0)
				echo"<img src='img/firstpage.png' title='First Page' onMouseOver=\"style.cursor='hand'\" onclick=SetFirstPage('".$startrange."','".$perpage."')>";

			$diff= $startrange - $perpage;
				
			if (($diff) >= 0 ){
				$prvstartrange = $startrange - $perpage;
				echo"&nbsp;&nbsp;<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."')>";
			}
			else
				echo "&nbsp;";
		
echo"		</td><td  align='left' style='width:74px;'>";
		
		
			if ($startrange <= $totalrows){
				$startrange1 = $startrange + $perpage;
				if  ($startrange1 < $totalrows){
					echo"<img src='img/arrowright.png' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange1."','".$perpage."')>";
					echo"&nbsp;&nbsp;<img src='img/lastpage.png' title='Last Page' onMouseOver=\"style.cursor='hand'\" onclick=SetLastPage('".$perpage."','".$totalrows."')>";	
				}
			} else
				echo "&nbsp;";
				
			
echo"		</td><td style='width:380px;'>&nbsp;</td>
		</tr>";
echo"	</table></td>
		<td id='search-content3' style='width:31px;'>&nbsp;</td>";
echo"</tr>";

echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		<td id='search-content2'>
			<div style='overflow:scroll;height:400px;width:1270px;'>
			<table border='0'  cellpadding='0' cellspacing='1' >
			  <col width=20>
			  <col width=20>
			  <col width=20>";

echo "		  <col width=80>
			  <col width=80>
			  <col width=120>
			  <col width=150>
			  <col width=150>
			  <col width=140>
			  <col width=110><col width=90>
			  <col width=100><col width=100><col width=90>";
	if($message!=''){
	echo"	  <tr class='Search-header-bg'>
				<td height='15' align='center' colspan='14' class='searchmessage'>".$message."</td>
			  </tr>";
}
	  echo"<tr class='Search-Label-bg'>
		<td  height='25' align='center'><span class='style4'>&nbsp;</span></td>
		<td  height='25' align='center'><span class='style4'>&nbsp;</span></td>
		<td  height='25' align='center'><span class='style4'>&nbsp;</span></td>";
	
	echo "<td  height='25' align='center'><span class='style4'>Reference </span></td>
		<td  height='25' align='center'><span class='style4'>Date </span></td>
		<td  height='25' align='center'><span class='style4'>Name </span></td>
		<td  height='25' align='center'><span class='style4'>Approved By </span></td>
		<td  height='25' align='center'><span class='style4'>Confirmed By </span></td>
		<td  height='25' align='center'><span class='style4'>Project</span></td>
		<td  height='25' align='center'><span class='style4'>CostCenter</span></td>
		<td  height='25' align='center'><span class='style4'>Currency</span></td>
		<td  height='25' align='center'><span class='style4'>$base1</span></td>
		<td  height='25' align='center'><span class='style4'>$base2</span></td>
		<td  height='25' align='center'><span class='style4'>User</span></td>
	  </tr>";
		
$i = 0;
while($rows=mysql_fetch_array($resultsearch)){
		
	extract($rows);
	$ct+=1;

	if($ct%2==0)
		$Color="style='background-color:".$grid_color1."'";
	else			
		$Color="style='background-color:".$grid_color2."'";	
		
		

	$PrevHint   = 'Preview';
	$EditHint   = 'Edit Record';
	$ConfHint   = 'Confirm Record';
	
	if ($TempPaymentRqstId != -1) {$PrevHint=$EditHint=$ConfHint = 'Exists in Pending';}
	
    if ($FA_PaymentRqstMod == 0)	$EditMode =0; 
	else if ($FA_PaymentRqstMod == 1 && $TempPaymentRqstId != -1) $EditMode =0;
	else if ($FA_PaymentRqstMod == 1 && $TempPaymentRqstId == -1) $EditMode =1;
	
	if ($TempPaymentRqstId != -1) $ConfMode =0;
	else $ConfMode =1;
	
	if ($TempPaymentRqstId != -1) $PrevMode =0; else $PrevMode =1;		
			
		   
	echo'<tr '.$Color.'>';
	
		if($PrevMode==1)
	        echo'<td align="center"><span class="style5"><img src="img/mag.jpg" onMouseOver="style.cursor=\'hand\'"  onclick="PrintPreview('.$PaymentRqst_ID.');"  title="'.$PrevHint.'" ></span></td>';
		else echo'<td align="center">&nbsp;</td>';		
		
		if($EditMode==1)	
			echo'<td align="center"><span class="style5"><img src="img/edit.png" onMouseOver="style.cursor=\'hand\'" onclick="UpdateRecord('.$PaymentRqst_ID.');" title="'.$EditHint.'"  style="width:20px; height:20px;"></span></td>';
		else echo'<td align="center">&nbsp;</td>';			
		
		if($ConfMode==1)	
		echo'<td align="center"><span class="style5"><img src="img/confirmorder.png" onMouseOver="style.cursor=\'hand\'" onclick="ConfirmRecord('.$PaymentRqst_ID.');" title="'.$ConfHint.'" style="width:16px; height:16px; "></span></td>';
		else echo'<td align="center">&nbsp;</td>';				
		
		echo'<td align="left"><span class="style5">'.$PaymentRqst_RefGovernment.'</span></td>
			<td align="center"><span class="style5">'.$PaymentRqst_Date.'</span></td>
			<td align="left"><span class="style5">'.$PaymentRqst_Name.'</span></td>
			<td align="left"><span class="style5">'.$Touser_account.'</span></td>
			<td align="left"><span class="style5">'.$User_Confirmed.'</span></td>
			<td align="left"><span class="style5">'.$ProjectName.'</span></td>
			<td align="left"><span class="style5">'.$CostcentName.'</span></td>
			<td align="left"><span class="style5">'.$CURRENCY_CODE.'</span></td>
			<td align="left"><span class="style5">'.$PaymentRqst_AmountD1.'</span></td>
			<td align="left"><span class="style5">'.$PaymentRqst_AmountD2.'</span></td>
			<td align="left"><span class="style5">'.$user_account.'</span></td>
		</tr>';
}
							

			
		
echo"   <tr><td colspan='10'>&nbsp;</td></tr>";


echo"</table></div></td><td id='search-content3' style='width:31px;'>&nbsp;</td></tr>";
echo"   <tr ><td id='search-content1'>&nbsp;</td><td id='search-content2'>&nbsp;</td><td id='search-content3'>&nbsp;</td></tr>";
echo"	<tr >
		<td id='search-bottom1' style='height:34px; width:31px;'>&nbsp;</td>
		<td id='search-bottom2' style='height:34px; width:908px;' valign='top'><table width='100%' border=0 height=28px>
		<tr><td style='width:380px;'>&nbsp;</td><td align='right' style='width:74px;border-right:1px solid #000000;'>";

		
		if($startrange>0)
			echo"<img src='img/firstpage.png' title='First Page' onMouseOver=\"style.cursor='hand'\" onclick=SetFirstPage('".$startrange."','".$perpage."')>";

		//$diff= $startrange - $perpage;
		
		if (($diff) >= 0 ){
			//$prvstartrange = $startrange - $perpage;
			echo"&nbsp;&nbsp;<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."')>";
		}
		else
			echo "&nbsp;";
		
		echo"</td><td  align='left' style='width:74px;'>";
		
		
		if ($startrange <= $totalrows){
			//$startrange = $startrange + $perpage;
			if  ($startrange1 < $totalrows){
				echo"<img src='img/arrowright.png' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange1."','".$perpage."')>";
				echo"&nbsp;&nbsp;<img src='img/lastpage.png' title='Last Page' onMouseOver=\"style.cursor='hand'\" onclick=SetLastPage('".$perpage."','".$totalrows."')>";	
			}
		} else
			echo "&nbsp;";
	
			
		echo"</td><td style='width:380px;'>&nbsp;</td></tr>";
		echo"</table></td><td id='search-bottom3' style='height:34px; width:31px;'>&nbsp;</td>";

	 
echo"</tr>";
echo"</table>";
	


          

		  

print <<<HERE

</form>
</body>

HERE;
function explodeword($date)
{

$trim = explode('/',$date);
$trim = "$trim[2]"."-"."$trim[1]"."-"."$trim[0]";
return $trim;
}

?>