<?php

session_start();

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

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

 if ($mainaction=='insert'){
	$query_items="insert into warehouseqty (item_id,warehouse_code,minqty,maxqty,warehouse_percentage)
				values('".$item_id."','".$warehouse_code."','".$min_qty."','".$max_qty."','".$item_percentage."')";
	//echo$query_items;exit;
	$result_items=mysql_query($query_items,$connection);
	
	if($result_items)
		$warehouseqty_id=mysql_insert_id();
}

if($mainaction=='edit'){

	$query_items="update warehouseqty set   warehouse_code='".$warehouse_code."',
											minqty='".$min_qty."',
											maxqty='".$max_qty."',
											warehouse_percentage='".$item_percentage."'
											where warehouseqty_id='".$warehouseqty_id."'";
				
	$result_items=mysql_query($query_items,$connection);
	$message= mysql_error();
}

$message = ereg_replace(" ", "%20", $message);

header ("Location: ./Form_Items_Warehouses.php?mainaction=insert&warehouseqty_id=".$warehouseqty_id."&item_id=".$item_id."&message=".$message);
	
mysql_close($connection);

?>