<?php
session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
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");

if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
	mysql_query("SET NAMES 'utf8'"); 
	mysql_query('SET CHARACTER SET utf8'); 
	mysql_set_charset('utf8', $connection);
}


$query1="select ifnull(Login_location,0) as  Login_location from ".$_SESSION['dbLabel'].".login";
$result1=mysql_query($query1,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($result1)){
extract($rows);

}


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

}


$str    	= $_GET['str']; 		if ($str == ""){			$str 		= $_POST["str"];}
$vtext1 	= $_GET['vtext1']; 		if ($vtext1 == ""){			$vtext1 	= $_POST["vtext1"];}
$text1value = $_GET['text1value']; 	if ($text1value == ""){		$text1value = $_POST["text1value"];}


$PRef  = $_POST["PRef"]; if ($PRef == ""){$PRef = $_GET["PRef"];}


?>

<!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=windows-1256" />
<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()
{
  document.form1.PRef.value='';
  document.form1.action='List_warehouses.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="2" 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 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="str" type="hidden"   value="<?php echo $str; ?>">
		<input name="vtext1" type="hidden" id="vtext1" value="<?php echo $vtext1; ?>" />
		<input name="text1value" type="hidden" id="text1value" value="<?php echo $text1value; ?>" /> 
        <input name="desc1" type="hidden" id="desc1" value="<?php echo $_GET['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();'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.vtext1.value;

	var parentText = window.opener.document.getElementById(vtext1);
	parentText.value =  document.form1.code1.value;
}
else if(document.form1.str.value=='6'){
	opener.document.items.warehouse_code.value=document.form1.code1.value;
	opener.document.items.warehouse_desc.value=document.form1.desc1.value;
}
else if(document.form1.str.value=='7'){
	opener.document.useraccess.towarehouse_code.value=document.form1.code1.value;
	opener.document.useraccess.towarehouse_name.value=document.form1.desc1.value;
}
else if(document.form1.str.value=='8'){
	opener.document.salesman.warehouse_code.value=document.form1.code1.value;
	opener.document.salesman.warehouse_desc.value=document.form1.desc1.value;
}
else if(document.form1.str.value=='9'){
	opener.document.Warehouse.Pwarehouse_code.value=document.form1.code1.value;
}
else if(document.form1.str.value=='10'){
	opener.document.getElementById('fromwarehouse_code').value=document.form1.code1.value;
	opener.document.getElementById('fromwarehouse_name').value=document.form1.desc1.value;
	if (opener.document.getElementById('towarehouse_code').value == ''){
		opener.document.getElementById('towarehouse_code').value=document.form1.code1.value;
		opener.document.getElementById('towarehouse_name').value=document.form1.desc1.value;
	}
}
else if(document.form1.str.value=='11'){
	opener.document.getElementById('towarehouse_code').value=document.form1.code1.value;
	opener.document.getElementById('towarehouse_name').value=document.form1.desc1.value;
}
else if(document.form1.str.value=='12'){
	//alert("test");
	opener.document.getElementById('warehouse_code').value=document.form1.code1.value;
	//opener.document.transForm.towarehouse_name.value=document.form1.desc1.value;
}
else if(document.form1.str.value=='13'){
	//alert("test");
	opener.document.getElementById('warehouse_code_<?php echo $_GET['rmadtrpc_id']; ?>').value=document.form1.code1.value;
	//opener.document.transForm.towarehouse_name.value=document.form1.desc1.value;
}
else if(document.form1.str.value=='14'){
	opener.document.form1.fromwarehouse.value=document.form1.code1.value;
	opener.document.form1.fromwarehouse_name.value=document.form1.desc1.value;
}
else if(document.form1.str.value=='15'){
	opener.document.form1.towarehouse.value=document.form1.code1.value;
	opener.document.form1.towarehouse_name.value=document.form1.desc1.value;
}
else if(document.form1.str.value=='16'){
	opener.document.purchase.txtprjtwh.value=document.form1.code1.value;
	opener.document.purchase.txtprjtwh.onchange();
}
else if(document.form1.str.value=='22'){
	opener.document.form1.fromwarehouse.value=document.form1.code1.value;
	opener.document.form1.fromwarehouse_name.value=document.form1.desc1.value;
	opener.document.form1.towarehouse.value=document.form1.code1.value;
	opener.document.form1.towarehouse_name.value=document.form1.desc1.value;
} 
else if(document.form1.str.value=='23'){ 
	opener.document.form1.towarehouse.value=document.form1.code1.value;
	opener.document.form1.towarehouse_name.value=document.form1.desc1.value;
} 
else if(document.form1.str.value=='24'){
	opener.document.form1.fromtranswh.value=document.form1.code1.value;
	opener.document.form1.fromtranswh_name.value=document.form1.desc1.value;
	opener.document.form1.totranswh.value=document.form1.code1.value;
	opener.document.form1.totranswh_name.value=document.form1.desc1.value;
} 
else if(document.form1.str.value=='25'){ 
	opener.document.form1.totranswh.value=document.form1.code1.value;
	opener.document.form1.totranswh_name.value=document.form1.desc1.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>
  
    </tr>
<?php

if ($str == '16'){
	$querywarehouse= " select distinct warehouseProject.warehouse_code, warehouse_name ".
					" from warehouseProject ".
					" inner join warehouse on warehouse.warehouse_code = warehouseProject.warehouse_code".
					" where project_code = '$text1value' ";	 
	$result1 = mysql_query($querywarehouse,$connection);
} else {
	$querywarehouse= " select distinct warehouse.warehouse_code, warehouse_name ".
					  " from warehouse where warehouse_code in (select warehouse_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."') 
					   and warehouse_code not in (select warehouse_excluded from ".$_SESSION['dbLabel'].".login where warehouse_excluded is not null and user_account='".$_SESSION['useraccount']."')
					   and (warehouse.warehouse_code like ('%".$PRef."%') or Warehouse_name like"."('%".$PRef."%'))
					   order by Warehouse_code";

			//echo 	$querywarehouse;	 
	$result1 = mysql_query($querywarehouse,$connection);		
	$rwwarehouse = mysql_num_rows($result1); 
	if($rwwarehouse == 0){
	$query1=" select Warehouse_code,Warehouse_name ".
			" from Warehouse";
		if($Login_location == 1)	
	$query1=$query1." where warehouse_type = 'WAREHOUSE' and (Warehouse_code like"."('%".$PRef."%') or Warehouse_name like"."('%".$PRef."%')) ";
	$query1=$query1." order by Warehouse_code";
				
	//echo$query1;
	$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_warehouses.php?str=<?php echo $str; ?>&post=1&lcode=<?php echo $rows[0]; ?>&desc1=<?php echo $desc; ?>&vtext1=<?php echo $vtext1;?>&text1value=<?php echo $text1value; ?>&rmadtrpc_id=<?php echo $_GET['rmadtrpc_id']; ?>"><?php echo $rows[0]; ?></a></td>
      <td colspan="1"><a href="List_warehouses.php?str=<?php echo $str; ?>&post=1&lcode=<?php echo $rows[0]; ?>&desc1=<?php echo $desc; ?>&vtext1=<?php echo $vtext1;?>&text1value=<?php echo $text1value; ?>&rmadtrpc_id=<?php echo $_GET['rmadtrpc_id']; ?>"><?php echo $rows[1]; ?></a></td>

    </tr>
	
<?php }?>
  </table>
</form>
</body>
</html>
