<?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);

}


$PRef 	= $_POST["PRef"]; if ($PRef == ""){$PRef = $_GET["PRef"];}
$str 	= $_POST["str"]; if ($str == ""){$str = $_GET["str"];}
$text1 	= $_POST["vtext1"]; if ($text1 == ""){$text1 = $_GET["vtext1"];}
$text2 	= $_POST["vtext2"]; if ($text2 == ""){$text2 = $_GET["vtext2"];}
$vitem 	= $_POST["vitem"]; if ($vitem == ""){$vitem = $_GET["vitem"];}
$vdate 	= $_POST["vdate"]; if ($vdate == ""){$vdate = $_GET["vdate"];}

?>

<!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 Warehouses</title>
<script type="text/javascript" language="javascript">

function clearform(vstr,vtext1,vtext2,vitem,vdate)
{
  document.form1.PRef.value='';
  document.form1.action='List_warehousesQtyExists.php?str='+vstr+'&vtext1='+vtext1+'&vtext2='+vtext2+'&vitem='+vitem+'&vdate='+vdate;
  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="3" bgcolor="#DDDDDD"><span class="style1"> Warehouses</span></th>
    </tr>
    <tr>
      <td bgcolor="#DDDDDD"> <span style="font-size: 11px; color: #999999; font-weight: bold;">Search for Warehouse <br> Code / Name</span></td>
      <td colspan=3 bgcolor="#DDDDDD"><input type="text" name="PRef" value="<?php echo $PRef; ?>"  />
        <input name="code1" type="hidden" id="code1"  value="<?php echo $_GET['lcode']; ?>">
        <input name="code2" type="hidden" id="code2"  value="<?php echo $_GET['lcode1']; ?>">
	    <input name="str" type="hidden"   value="<?php echo $str; ?>">
		<input name="text1" type="hidden" id="text1" value="<?php echo $_GET['vtext1']; ?>" />
		<input name="text2" type="hidden" id="text2" value="<?php echo $_GET['vtext2']; ?>" />
		<input name="text1value" type="hidden" id="text1value" value="<?php echo $_GET['text1value']; ?>" /> 
        <input name="desc1" type="hidden" id="desc1" value="<?php echo $desc1; ?>" />
	    <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("<?php echo $str;?>","<?php echo $text1;?>","<?php echo $text2;?>","<?php echo $vitem;?>","<?php echo $vdate;?>");'style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/></td>
   
    </tr>
<?php if($_GET['post']=="1") { ?>
	
		
<script type="text/javascript" language="javascript">

if(document.form1.str.value=='1'){
	opener.document.warehouseqty.warehouse_code.value=document.form1.code1.value;
	opener.document.warehouseqty.warehouse_name.value=document.form1.desc1.value;
}
else if(document.form1.str.value=='2'){
	opener.document.clientdt.warehouse.value=document.form1.code1.value;

}
else if(document.form1.str.value=='3'){
	opener.document.items.item_warehousecode.value=document.form1.code1.value;
	opener.document.items.item_warehousedesc.value=document.form1.desc1.value;
}
else if(document.form1.str.value=='4'){
	opener.document.useraccess.warehouse_code.value=document.form1.code1.value;
	opener.document.useraccess.warehouse_name.value=document.form1.desc1.value;
}
else if(document.form1.str.value=='5'){
var vtext1 = document.form1.text1.value;


var parentText = window.opener.document.getElementById(vtext1);
parentText.value =  document.form1.code1.value;
			


}
else if(document.form1.str.value=='10'){

var vtext1 = document.form1.text1.value;
var vtext2 = document.form1.text2.value;

var parentText = window.opener.document.getElementById(vtext1);
var parentText1 = window.opener.document.getElementById(vtext2);
parentText.value =  document.form1.code1.value;
parentText1.value =  document.form1.code2.value;

}

self.close();

</script>

<?php } ?>
    <tr bgcolor="#E5E5E5">
      <td width="136"><span class="style2">Group Code </span></td>
      <td width="411" colspan="1"><span class="style2">Group Name </span></td>
      <td width="411" colspan="1"><span class="style2">Qty Exists </span></td>
  
    </tr>
<?php
$query1=" select Warehouse_code,Warehouse_name,ifnull(QtyExists('".$vitem."', Warehouse_code, '".explodewordrequest($vdate)."', 0, 'PQ', '', ''),0) ".
		" from Warehouse";
$query1=$query1." where Warehouse_code like"."('%".$PRef."%') or Warehouse_name like"."('%".$PRef."%')
		 order by Warehouse_code";
			
//echo$query1;
//exit;
$result1=mysql_query($query1,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($result1)){


$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; 
	
	
	?>>
	
	 <?php
		$desc=ereg_replace("'","%27",$rows[1]);
		?>
		
		
      <td align="left"><a href="List_warehousesQtyExists.php?str=<?php echo $str; ?>&post=1&lcode=<?php echo $rows[0]; ?>&lcode1=<?php echo $rows[2]; ?>&desc1=<?php echo $desc; ?>&vtext1=<?php echo $_GET['vtext1'];?>&vtext2=<?php echo $_GET['vtext2'];?>&text1value=<?php echo $_GET['text1value']; ?>"><?php echo $rows[0]; ?></a></td>
      <td colspan="1"><a href="List_warehousesQtyExists.php?str=<?php echo $str; ?>&post=1&lcode=<?php echo $rows[0]; ?>&lcode1=<?php echo $rows[2]; ?>&desc1=<?php echo $desc; ?>&vtext1=<?php echo $_GET['vtext1'];?>&vtext2=<?php echo $_GET['vtext2'];?>&text1value=<?php echo $_GET['text1value']; ?>"><?php echo $rows[1]; ?></a></td>
 	  <td colspan="1"><a href="List_warehousesQtyExists.php?str=<?php echo $str; ?>&post=1&lcode=<?php echo $rows[0]; ?>&lcode1=<?php echo $rows[2]; ?>&desc1=<?php echo $desc; ?>&vtext1=<?php echo $_GET['vtext1'];?>&vtext2=<?php echo $_GET['vtext2'];?>&text1value=<?php echo $_GET['text1value']; ?>"><?php echo $rows[2]; ?></a></td>
    </tr>
	
<?php }
function explodewordrequest($date)
	{

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

		return $trim;
	}

?>
  </table>
</form>
</body>
</html>
