<?php

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


include("config.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");

$query1="select grid_color1,grid_color2 from setup";
$result1=mysql_query($query1,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($result1)){
extract($rows);

}

		
		
print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />


<title>List of Staff</title>
<script type="text/javascript" language="javascript">


function fillfield(value1,value2,str){
if(str=='1')
{
	opener.document.formstaffreport.staff_Cdname1.value=value1;
	
	opener.document.formstaffreport.staff_namefrom.value=value2;
}
else{
	opener.document.formstaffreport.staff_nameto.value=value2;
	opener.document.formstaffreport.staff_Cdname2.value=value1;
}
	//opener.document.formhouse.submit();
	self.close();

	
}

function clearform()
{
  document.search.PRef.value='';
  document.search.action='List_Staff_ft.php';
  document.search.submit();

}

function LoadForm() 
{
	x=document.search;
	x.PRef.focus();
	

}

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

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




</script>

<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
}
body {
	margin-top: 2px;
	margin-left: 1px;
}

a:visited {
	text-decoration: none;
	color: #0000FF;
}


.style11 {color: #999999; font-weight: bold; }
.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>

</head>
<body >
<form name='search' method='post' action=''>
<input type='hidden' name='str'  value='$str'>

HERE;

echo"<table border='0' style='table-layout:fixed'>

	  <col width=3%>
	  <col width=15%>
	  <col width=76%>
	
		     
	  <tr bgcolor='#DDDDDD'>
	    <td align='center' colspan='3'><span class='style16'>$label</span></td></tr>
	  <tr bgcolor='#DDDDDD' height=30px>
	    <td align='left' colspan='2'><span class='style11'>Search by Code/Name</span></td>
		<td align='left' colspan='1'><span class='style11'><input type='text' name='PRef' id='PRef' value='$PRef' size='15' maxlength='30'/><input type='hidden' name='PMode' id='PMode' value='$PMode' size='15' maxlength='30'/></span>
		    <input type='submit' name='Submit' value='Find' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/>
			<input type='button' name='btnCancel' value='Cancel' onclick='clearform();'style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/></td>
		";
echo" </tr>
	  <tr bgcolor='#DDDDDD'>
		<td height='15' align='center' colspan='3'><font size='1' color='#FF0000' face='Verdana'><b>".$message."</b></font></td>
	  </tr>	
	  <tr bgcolor='#CCD8E6'>
	  
	
		<td  height='25' align='left' width=50% colspan=2><span class='style25'>Code </span></td>
		<td  height='25' align='center'><span class='style25'>Name </span></td>
		
	  </tr>";
		

$querysearch="select  staff_code,staff_fullname from staff ";

	if($PRef!='')
	{$querysearch=$querysearch." where (staff_code like"."('".$PRef."%') or staff_fullname like"."('%".$PRef."%')) ";
	}
	$querysearch.="order by staff_code";
	
	///echo $querysearch;
//echo $querysearch;
$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());
$totalrows = mysql_num_rows($resultsearch);
	
if ($startrange=='')
	$startrange = 0;
if ($perpage=='')
	$perpage = 20;
		
$querysearch = $querysearch." limit ".$startrange.",".$perpage;
$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());		


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."'";	
			
	echo"<tr $Color>";
	$str=$_GET['str'];
	echo "
      <td align='left' colspan=2><a onclick=\"fillfield('$staff_code','$staff_fullname',$str);\" href=''>$staff_code</a></td>
	  
      <td ><a onclick=\"fillfield('$staff_code','$staff_fullname','$str');\" href=''>$staff_fullname</a></td>
    </tr>";

}
							
	
		
echo"   <tr><td colspan='3'>&nbsp;</td></tr>
		<tr><td colspan=3><table width='100%' border=0><tr><td width='260'>&nbsp;</td><td width='150' align='center'>";
		
		$diff= $startrange - $perpage;
		
		if (($diff) >= 0 ){
			$prvstartrange = $startrange - $perpage;
			echo"<img src='img/arrowleft.jpg' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."')>";
		}
		else
			echo "&nbsp;";
		
		echo"</td><td width='150' align='center'>";
		
		
		if ($startrange <= $totalrows){
			$startrange = $startrange + $perpage;
			if  ($startrange <= $totalrows)
				echo"<img src='img/arrowright.jpg' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange."','".$perpage."')>";
		} else
			echo "&nbsp;";
			
		echo"</td><td width='170'>&nbsp;</td></tr>";
		echo"<table>";

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


          

		  

print <<<HERE
</form>
</body>

HERE;

?>