<?php
session_start();

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

$Pusercode = $_POST['Pusercode']; if($Pusercode == '') $Pusercode = $_GET['Pusercode'];
$Pusername = $_POST['Pusername']; if($Pusername == '') $Pusername = $_GET['Pusername'];
$lusername = $_GET['lusername']; echo $lusername;
$frm = $_GET['frm'];

if($_GET['lusername']!=""){
	$_GET['post']="1";

}
	

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>List of Usernames</title>
<script type="text/javascript" language="javascript">
function clearform(){
  document.form1.Pusercode.value='';
  document.form1.Pusername.value='';
  document.form1.action='List_RequestedByUsers.php';
  document.form1.submit();
}
</script>
<style type="text/css">
<!--
body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 14px;
}
.style1 {
	color: #333333;
	font-weight: bold;
}
.style2 {
	color: #999999;
	font-weight: bold;
}
.style3 {color: #999999}
-->
</style></head>

<body>
<form id="form1" name="form1" method="post" action="">
 <table width="800" border="0" align="center">
    <tr>
      <th colspan="5" bgcolor="#DDDDDD"><span class="style1"> List Of Users </span></th>
    </tr>
    <tr>
      <td bgcolor="#DDDDDD"> <span style="font-size: 11px; color: #999999; font-weight: bold;">Search for Users  <br> Code / Name</span></td>
      <td bgcolor="#DDDDDD"><input type="text" name="Pusercode" value="<?php echo $Pusercode; ?>"  />
        <input name="code1" type="hidden" id="code1"  value="">
      <td bgcolor="#DDDDDD"><input type="text" name="Pusername"  value="<?php echo $Pusername; ?>" size='35'/>
        		
	    <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="cancelbtn" value="Cancel" onclick='clearform();'style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/></td>
      <td bgcolor="#DDDDDD">
	
	  <input name="frm" type="hidden" id="frm" value="<?php echo $frm; ?>" />
	  <input name="lusername" type="hidden" id="lusername" value="<?php echo $lusername; ?>" /></td>
    </tr>
	<?php if($_GET['post']=="1") { ?>
<script type="text/javascript" language="javascript">
 var FormOption = document.form1.frm.value;


if (FormOption == 1){
	
opener.document.search.PRequestedBy.value=document.form1.lusername.value;
}
self.close();

</script>
<?php } ?>
	<tr bgcolor="#E5E5E5">
      <td width="136"><span class="style2">User Code </span></td>
      <td width="411" colspan="2"><span class="style2">User Name </span></td>
      <td width="57"><span class="style3"></span></td>
	  
<?php   //Costcenter List
$query_username=" select distinct users.user_account, users.user_name 
				from ".$_SESSION['dbLabel'].".users as users
				inner join prequest on prqst_requestBy= users.user_name 
				where 1=1 ";
if($Pusercode != '') $query_username = $query_username." and users.user_account like '%$Pusercode%' ";

if($Pusername != '') $query_username = $query_username." and users.user_name like '%$Pusername%' ";
				
	//echo $query_username;		  
$result_username = mysql_query($query_username,$connection);

while($rows_username=mysql_fetch_row($result_username)){

$usercode = $rows_username[0];
$username = $rows_username[1];

$ct+=1;

if($ct%2==0)
{
	$Color="style='color:#0000FF;background-color:".$grid_color1."'";
	
	}else{
		
	$Color="style='color:#0000FF;background-color:".$grid_color2."'";	
}
?>
<tr <?php echo $Color; ?>>
      <td align="left"><a href="List_RequestedByUsers.php?lusername=<?php echo $username; ?>&frm=<?php echo $frm; ?>"><?php echo $usercode; ?></a></td>
      <td colspan="2"><a href="List_RequestedByUsers.php?lusername=<?php echo $username; ?>&frm=<?php echo $frm; ?>"><?php echo $username; ?></a></td>
      <td>&nbsp;</td>
    </tr>

<?php } ?>
    </tr>
	
</table>	

</form>
</body>
</html>
