<?php
include("../../include/session.php");
if(!$session->isAdmin()){
	header("Location: ../storeMenu.php");
}else{
	include("../../include/db.php");
	$productName = $_POST['productName'];
	$productId = $_POST['productId'];
	$cat = mysql_real_escape_string($_POST['cat']);
	$comingFrom = mysql_real_escape_string($_GET['comingFrom']);
	$comingFrom2 = mysql_real_escape_string($_GET['comingFrom2']);
	
	$date = isset ($_REQUEST["date"]) ? $_REQUEST["date"] : "";
	
	
	$columns ="";
	$values = "";
	foreach($_POST as $key => $value){
		if($key != "productName" && $key != "submitok" && $key != "productId" && $key != "cat" && !preg_match("/date/i",$key)){
			$columns .= "$key = '$value',";
		}
	}  echo $columns;
	
	$q = "UPDATE products SET $columns productName = '$productName', date = '$date' WHERE productId = $productId";
	$result = execsql($q);
	
	if($result){
		$return = mysql_real_escape_string($_POST['submitok']);
		
		if ($return == "Save and New") {
			   header("Location: ../modifyProduct.php?cat=$cat");
		}
		else{
		  
		   if ($return=="Save and Go to ".$comingFrom."/".$comingFrom2." stock list") {
		            header("Location: ../showAllProductsAll.php?searchText=All&CategorySelect=$comingFrom&subCatSelect=$comingFrom2&MinimumRadiobutton=yes");
					}
				else{
					header("Location: ../findDisplay.php?productId=$productId");
					}
			
		}

	}
}
?>