<?php
include("../include/session.php");
if(!$session->isRadstoneStoreUser() && !$session->isAdmin() && !$session->isRadstoneReceptionUser()){
	header("Location: ../Store/storeMenu.php");
}else{
	
	include("../storeHeader.php");
//	include("../include/db.php");
	?>



<?php
$productId = $_GET['productId'];


$edit = $_GET['edit'];
	
	if ($edit=="1") {
		$field = $_GET['field'];
		$editText = $_GET['editText'];
		
		$editQuery = "UPDATE products SET $field = '".  $editText ."' WHERE productId = '$productId' ";
		
        $editResult = mySQL_query($editQuery);
	}
	
	if ($edit=="2") {
		$productId = $_GET['productId'];
		$category = $_GET['category'];
		$sub_category = $_GET['sub_category'];
		
		$editQuery = "UPDATE products SET category = '".  $category ."', subCategory = '".  $sub_category ."' WHERE productId = '$productId' ";
		
        $editResult = mySQL_query($editQuery);
	}



$query = "SELECT * FROM products WHERE productId ='".$productId."'";
$result = execsql($query);


	$f1=mysql_result($result,0,"productName");
	$f2=mysql_result($result,0,"suppliersName");
	$f3=mysql_result($result,0,"category");
	$f4=mysql_result($result,0,"subCategory");
	$f5=mysql_result($result,0,"unit");
	$f6=mysql_result($result,0,"returnable");
	if($f6 < 1){$returnable = "No";}else{$returnable="Yes";}
	$f7=mysql_result($result,0,"quantity");
	$f8=mysql_result($result,0,"price");
	$f9=mysql_result($result,0,"depreciation");
	$f10=mysql_result($result,0,"date");
	$f11=mysql_result($result, 0, "productId");
	$f12=mysql_result($result, 0, "shelf");
	$f13=mysql_result($result, 0, "minimumStock");
	$f14=mysql_result($result, 0, "productSpecs");
	
	$w=1;
	while ($w < 15) {
	$f = 'f';	
	   if (${$f.$w} == '') { ${$f.$w}="?"; }
	   $w++;
	}
$link="";
if ($f3=="Tiles and Accessories") { 
	$link="showAllProducts.php?cat=Tiles and Accessories&productSelect=All&colorSelect=All&date=0"; }
if ($f3=="Direct Materials") { 
	$link="showAllProductsAll.php?searchText=All&CategorySelect=Direct Materials&subCatSelect=&date=0"; }
if ($f3=="Store Item") {
	$link="showAllProductsAll.php?searchText=All&CategorySelect=Store Item&subCatSelect=$f4&date=0"; }


if ($f3=="Tiles and Accessories") {
    $link2="stockMovement.php?monthdisplay=0&cat=Store Item&productIdSelect=$productId&date=0" ; }
else {
	$link2="stockMovement.php?productIdSelect=$productId&date=0" ;
	
}
?>

<link rel="stylesheet" href="../css/dhtmlwindow.css" type="text/css" />
<script type="text/javascript" src="../css/dhtmlwindow.js"></script>
<link rel="stylesheet" href="../css/modal.css" type="text/css" />
<script type="text/javascript" src="../css/modal.js"></script>
 
<link href="../css/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
<!--
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->
</script>
<div class="pageheading">
	Edit Stock Item 
	</div>
<table id="tableMain" width="595"> <!--begin of tableMain-->
    <tr>
      <td valign="top" ><p class="edit">
        <label class="std"><span class="main"><font size="3">
        <?php echo $f1?>
&nbsp;&nbsp; </font></span>Click on the line you want to edit.</label> </p><br /><br />



<table width="590" align="center"  id="tablePlain">
      <tr>
        <td width="121">Product Id:</td>
        <td width="94">
          <?php echo $f11?>
        </td>
        <td width="81">Product Name:</td>
        <td width="165">
		<a href="" onClick="editwindow=dhtmlmodal.open('editBox', 'iframe', 'editStockItemLine.php?productId=<?php echo $f11?>&field=<?php echo 'productName' ?>&Type=T ', 'Edit stock item', 'width=330px,height=170px,center=1,resize=0,scrolling=0')
needToConfirm = false;
editwindow.onclose=function(){return window}; return false"><?php echo $f1; ?></a></td>
      </tr>
      <tr>
        <td>Location:</td>
        <td>
          <a href="" onClick="editwindow=dhtmlmodal.open('editBox', 'iframe', 'editStockItemLine.php?productId=<?php echo $f11?>&field=<?php echo 'shelf' ?>&Type=T ', 'Edit stock item', 'width=330px,height=170px,center=1,resize=0,scrolling=0')
needToConfirm = false;
editwindow.onclose=function(){return window}; return false">  <?php echo $f12?></a>
          </td>
        <td>Suppliers Name:</td>
        <td>
          <a href="" onClick="editwindow=dhtmlmodal.open('editBox', 'iframe', 'editStockItemLine.php?productId=<?php echo $f11?>&field=<?php echo 'suppliersName' ?>&Type=T ', 'Edit stock item', 'width=330px,height=170px,center=1,resize=0,scrolling=0')
needToConfirm = false;
editwindow.onclose=function(){return window}; return false"><?php echo $f2; ?></a></td>
      </tr>
      <tr>
        <td>Category:</td>
        <td><a href="" onclick="editwindow=dhtmlmodal.open('editBox', 'iframe', 'editStockItemLine.php?productId=<?php echo $f11?>&field=<?php echo 'Category' ?>&Type=D6', 'Edit stock item', 'width=330px,height=170px,center=1,resize=0,scrolling=0')
needToConfirm = false;
editwindow.onclose=function(){return window}; return false"></a><a href="" onclick="editwindow=dhtmlmodal.open('editBox', 'iframe', 'editStockItemLine.php?productId=<?php echo $f11?>&field=<?php echo 'Category' ?>&Type=D6', 'Edit stock item', 'width=330px,height=170px,center=1,resize=0,scrolling=0')
needToConfirm = false;
editwindow.onclose=function(){return window}; return false"></a><a href="" onclick="editwindow=dhtmlmodal.open('editBox', 'iframe', 'editStockItemCategory.php?productId=<?php echo $f11?>', 'Edit stock item category', 'width=330px,height=170px,center=1,resize=0,scrolling=0')
needToConfirm = false;
editwindow.onclose=function(){return window}; return false"><?php echo $f3; ?></a></td>
        <td>Sub-Category:</td>
        <td>
        

<?php if ($f3!="Tiles and Accessories") { echo $f4; }?>
        </td>
      </tr>
      <tr>
        <td>Unit:</td>
        <td>
		<a href="" onClick="editwindow=dhtmlmodal.open('editBox', 'iframe', 'editStockItemLine.php?productId=<?php echo $f11?>&field=<?php echo 'unit' ?>&Type=D4 ', 'Edit stock item', 'width=330px,height=170px,center=1,resize=0,scrolling=0')
needToConfirm = false;
editwindow.onclose=function(){return window}; return false"><?php echo $f5; ?></a></td>
        <td>Returnable:</td>
        <td>
		<a href="" onClick="editwindow=dhtmlmodal.open('editBox', 'iframe', 'editStockItemLine.php?productId=<?php echo $f11?>&field=<?php echo 'returnable' ?>&Type=D ', 'Edit stock item', 'width=330px,height=170px,center=1,resize=0,scrolling=0')
needToConfirm = false;
editwindow.onclose=function(){return window}; return false"><?php echo $returnable; ?></a></td>
      </tr>
      <tr>
        <td>Quantity in stock: </td>
        <td>
		<?php echo number_format($f7); ?></td>
        <td>Minimum Stock:</td>
        <td>
		<a href="" onClick="editwindow=dhtmlmodal.open('editBox', 'iframe', 'editStockItemLine.php?productId=<?php echo $f11?>&field=<?php echo 'minimumStock' ?>&Type=N ', 'Edit stock item', 'width=330px,height=170px,center=1,resize=0,scrolling=0')
needToConfirm = false;
editwindow.onclose=function(){return window}; return false"><?php echo number_format($f13)?></a></td>
      </tr>
      <tr>
        <td>Price per:</td>
        <td>
		<a href="" onClick="editwindow=dhtmlmodal.open('editBox', 'iframe', 'editStockItemLine.php?productId=<?php echo $f11?>&field=<?php echo 'price' ?>&Type=N ', 'Edit stock item', 'width=330px,height=170px,center=1,resize=0,scrolling=0')
needToConfirm = false;
editwindow.onclose=function(){return window}; return false"><?php echo $f8; ?></a></td>
        <td>Depreciation over years:</td>
        <td>
		<?php echo $f9; ?></td>
      </tr>
      <tr>
        <td>Date:</td>
        <td>
		<?php echo date("d-m-Y", strtotime($f10 )); ?></td>
        <td>&nbsp;</td>
        <td></td>
      </tr>
      <tr>
        <td>Product specifications</td>
        <td colspan="3">
		<a href="" onClick="editwindow=dhtmlmodal.open('editBox', 'iframe', 'editStockItemLine.php?productId=<?php echo $f11?>&field=<?php echo 'productSpecs' ?>&Type=D5 ', 'Edit stock item', 'width=330px,height=170px,center=1,resize=0,scrolling=0')
needToConfirm = false;
editwindow.onclose=function(){return window}; return false"><?php echo $f14; ?></a></td>
        </tr>
    </table>
	</td>
</tr>
<tr>
  <td><p class="main">
    <label class="std">&nbsp;&nbsp;&nbsp;&nbsp;</label>
    <input name="button" type="button" class="imagebutton" id="button" onclick="MM_goToURL('parent','showAllProducts.php?cat=Tiles and Accessories&amp;productSelect=All&amp;colorSelect=All');return document.MM_returnValue" value="Done" />
  </p>
  </p></td>
  </tr>
</table><!--end of tableMain-->
<?php 
include("../footer.php");
}
?>
