<?php

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

}


include("config.inc.php");



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


while($row=mysql_fetch_array($result)){
	extract($row);
}

$InsMode = '';
if ($FA_warehouseApp == 0)
	$InsMode = ' disabled ';

if(!isset($mode))
$mode='';

if($mode=='edit' or $mode=='view'){


$query="select warehouse_code,warehouse_name from warehouse
where warehouse_code='".$warehouse_code."'";
echo $query;
$result=mysql_query($query, $connection);
while($row=mysql_fetch_array($result)){

$warehouse_code=$row[0];
$warehouse_name=$row[1];
}
}

print <<<HERE

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="default.css" type="text/css" />
<script type="text/javascript" language="javascript">

function editmode() {

	document.warehouse.mode.value='edit';
	document.warehouse.action="Form_warehouse1.php";
	document.warehouse.submit();
}


function Addwarehouse() {

			document.warehouse.mode.value='insert';
			document.warehouse.action="Form_warehouse1.php";
				document.warehouse.submit();
}

function CancelRecord () {


if (confirm ( "Are you sure you want to Cancel Page?")){
	ClearForm('All');
document.warehouse.action="Form_warehouse1.php?mode=";
document.warehouse.submit();
}
}


function SubmitRecord() {

if (document.warehouse.warehouse_code.value=='' )
		{
		alert("your warehouse_code is empty");
		document.getElementById("warehouse_code").focus();
		}
		
else  if (document.warehouse.warehouse_name.value=='' )
		{alert("your warehouse_name is empty");
		document.getElementById("warehouse_name").focus();
		}
		
		else {
		
		document.warehouse.action="Form_warehouse1_Actions.php";
				document.warehouse.submit();
		
		}
}
    function ClearPage(){
	if (confirm ( "Are you sure you want to Clear Page?"))
	{
		ClearForm('All');
		
		x.mode.value='';
		x.action='Form_warehouse1.php';
		x.submit();
	}	
}
function ClearForm(Option){
    x = document.warehouse;
	
	x.warehouse_code.value='';
	x.warehouse_name.value='';
	
	}


function SearchForwarehouse(){
ClearForm('All');
    x= document.warehouse;
    win = window.open('Form_warehousesearch1.php', 'Form_warehousesearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=775,height=450,top=100,left=100');		
	win.creator = self;
	win.focus();		
			
}

</script>
<body >
<form name='warehouse' method='post'>

<input type=text name='mode' value='$mode'>
<input type=hidden name='message' value='$message'>


HERE;

if($mode==''){
$status='disabled';
$dis='disabled';
}

if($mode=='view'){

$status='readonly';
$dis='disabled';

}


if($mode=='insert')
$status='';





$style= "style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'";

echo"<table border=0 width='100%'>";
echo '<tr><td colspan="9" align="left" valign="top">';

include_once("MenuBar.php");

print <<< HERE
       </td>
      </tr>
HERE;

echo" <table border='1' style='table-layout:fixed' align='center' valign='top'>
      <col width=120>";
		
	echo"<tr><td>Code <font color=red>*</font></td>
	
	<td><input type=text name='warehouse_code'  value='$warehouse_code' maxlength=15 $status></td></tr>";
	
	echo"<tr><td>name <font color=red>*</font></td>
	
	<td><input type=text name='warehouse_name'  value='$warehouse_name' maxlength=40 $status></td></tr>";
		
		
		
			echo"</table>";		
			
			
			
			


			echo"<table border=0 align=center width=100%> <tr bgcolor=#D8D8D8 height='35'>

			 ";
			
	
			echo"	<td align=center><input type='button'  value='Add warehouse'";  	
			
			if($mode=='insert' or $mode=='edit')
			echo "disabled ";
			
			echo"onclick='Addwarehouse()' $style title='Addwarehouse'>";
				
echo"           <input type='button' id='btnClear' name='BtnClear' value='Clear Page'   onclick='ClearPage();' $style title='Clear Page'>";

				
echo"           <input type='button' name='btnCancel' id='btnCancel' value='Cancel' ";//cancel
				if ($mode=='' )
					echo " disabled ";
				echo" onclick='CancelRecord();' $style title='Cancel Changes'>";
				
				
		if($mode=='view'){
echo"           <input type='button' name='btnEdit' id='btnEdit' value='Edit' ";//Edit
				
				
				echo" onclick='editmode();' $style	title='Edit warehouse' />";
	}
else	{
echo"           <input type='button' name='btnPost' id='btnPost' value='Save' ";//post
				if ($mode=='')
						echo " disabled ";
				
				echo" onclick='SubmitRecord();' $style	title='Save Changes' />";}

echo"           <input name='btnSearch' type='button' id='btnSearch' value='Search' onclick='SearchForwarehouse();' $style title='Search warehouse' ";
                if ($mode=='edit' or $mode=='insert') 
				    echo " disabled ";
		        
				

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

print <<< HERE
       </td>
      </tr>
	  </table>
HERE;


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

HERE;





?>
















