<?php
	include("../../include/session.php");
	include("../../include/db.php");
if(!$session->isRadstoneStoreUser() && !$session->isAdmin() && !$session->isRadstoneReceptionUser() ){
	header("Location: ../Store/storeMenu.php");
	}else{
			
		$productId = mysql_real_escape_string($_POST['productId']);
		$for = mysql_real_escape_string($_POST['for']);
		$quantity = mysql_real_escape_string($_POST['quantity']);
		$comments = mysql_real_escape_string($_POST['comments']);
		$date = isset($_REQUEST["date1"]) ? $_REQUEST["date1"] : "";
		$q2 = "SELECT quantity, price FROM products WHERE productId = '$productId'";
		$result2 = execsql($q2);
		$totalQuantity = mysql_result($result2, 0, "quantity") - $quantity;
		$price = mysql_result($result2, 0, "price");
		$q="";
		$q1 = "UPDATE products SET quantity = quantity - '$quantity' WHERE productId = '$productId'";
		$q3 = "";
		
	
			$q = "INSERT INTO radstoneusage (productId, reason, quantity, comments, date, costs) VALUES ('".$productId."', '".$for."', '".$quantity."', '$comments' ,      '".$date."','".$price."')";
			$q3 = "INSERT INTO itemhistory (productId, details, quantity, total, date) VALUES ('".$productId."','Used in: ".$for."</a>','".$quantity."', '".$totalQuantity."','".$date."')";
	
		$return = mysql_real_escape_string($_POST['submitok']);
		

	$result = execsql($q);
	$resultQ = execsql($q1);
	$resultH = execsql($q3);
	
	
		if ($return == "Save and New") {
			header("Location: ../giveToRadstone.php?cat=$cat");
		} else {
			header("Location: ../suppliedRadstone.php?forSelect=$for&date1=$date&date2=$date");
		}
	
}
?>
