<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
include ("../navigation/header.php");
$page_name = "Stores-edit";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/store_sidebar.php");

$store_item_id = $_GET['store_item_id'];



$table_name = $_SESSION['db_prefix']."_list_stores_location";
    $location_query = "SELECT item_name FROM $table_name ORDER BY item_name ASC";
	$location_result = execsql($location_query);
	$location_num = mysql_num_rows($location_result);
	$arrId1 = array ();
	$arrName1 = array ();
	$k = 0;
	while ($k < $location_num) {
		$arrId1[$k] = mysql_result($location_result, $k, "item_name");
		$arrName1[$k] = mysql_result($location_result, $k, "item_name");
		$k++;
	}
	
	
$table_name = $_SESSION['db_prefix']."_suppliers";
$suppliersQuery = "SELECT supplier_id, account_name FROM $table_name  ORDER BY account_name ASC";
	$suppliersResult = execsql($suppliersQuery);
	$suppliersNum = mysql_num_rows($suppliersResult);
	$w = 0;
	$arrId2 = array ();
	$arrName2 = array ();
	while ($w < $suppliersNum) {
		$arrId2[$w] = mysql_result($suppliersResult, $w, "supplier_id");
		$arrName2[$w] = mysql_result($suppliersResult, $w, "account_name");
		$w++;
	}


$table_name = $_SESSION['db_prefix']."_store_items";
$item_query = "SELECT * FROM $table_name WHERE store_item_id = '".$store_item_id."' ";
$item_result = mySQL_query($item_query);
$item_num = mysql_num_rows($item_result);
$item_name = mysql_result($item_result, 0, "item_name");
$supplier_id = mysql_result($item_result, 0, "supplier_id");
$category = mysql_result($item_result, 0, "category");
$sub_category = mysql_result($item_result, 0, "subCategory");
$location = mysql_result($item_result, 0, "location");
$unit = mysql_result($item_result, 0, "unit");
$quantity = mysql_result($item_result, 0, "quantity");
$minimumStock = mysql_result($item_result, 0, "minimumStock");
$price = mysql_result($item_result, 0, "price");
$purchase_price = mysql_result($item_result, 0, "purchase_price");
$date = mysql_result($item_result, 0, "date");
$lastModDate = mysql_result($item_result, 0, "lastModDate");
$specs = mysql_result($item_result, 0, "productSpecs");


$table_name = $_SESSION['db_prefix']."_suppliers";
$supplier_query = "SELECT account_name FROM $table_name WHERE supplier_id = '".$supplier_id."' ";
$supplier_result = mySQL_query($supplier_query);
$supplier_num = mysql_num_rows($supplier_result);
if ($supplier_num != 0) {
$account_name = mysql_result($supplier_result, 0, "account_name");
}
else {
	$account_name='';
}


?>
 <!--style sheets-->
<link href="../css/main.css" rel="stylesheet" type="text/css">

<!--jscript-->
<script language="JavaScript" src="../jscript/cancel_confirmation.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/numbers_only_decimal.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/numbers_only.js"  type="text/javascript"></script>    
<script language="JavaScript" src="../jscript/confirm_exit.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/cancel_confirmation.js"  type="text/javascript"></script> 

<script language="JavaScript" src="../jscript/numbers_only_decimal.js"  type="text/javascript"></script>  
<script language="JavaScript" src="../jscript/numbers_only.js"  type="text/javascript"></script>  



</head>

<body>
<div class="main_frame">
<div class="page_head_frame">
	<label class="label_page_head">Edit store item</label>
    &nbsp;&nbsp;&nbsp;&nbsp;
<label class="label_page_head_2"></label>
  </div>
<div class="page_middle_frame">  
<form action="store_item_edit_save.php" method="get" name="form1">
        <table width="664" align="left"  id="table_display">
          <tr>
        <td width="132">Product Name:</td>
        <td colspan="2"><input name="item_text_display" type="text" class="text200" id="item_text_display" value="<?php echo $item_name?>" onBlur="capitalize(this)" onFocus = "this.select();" disabled>         (<?php echo $store_item_id ?>) <input name="item_text" type="hidden" value="<?php echo $item_name?>"></td>
      <td>&nbsp;</td>  
      </tr>
      <tr>
        <td>Location:</td>
        <td><label for="category_select"></label>
          
          <select name="location_select" class="select120"  tabindex="1" >
            <option value="<?php echo $location ?>" selected="selected"><?php echo $location ?></option>
            <?php
        	for ($k = 0; $k < count($arrId1); $k++) {
    		echo "<option value=" . "\"" . $arrId1[$k] . "\"" . ">" . $arrName1[$k] . "</option>";
	}
?>
          </select>
          </td>
        <td width="149">Suppliers Name:</td>
        <td><span class="wizard_frame">
          <select name="supplier_id_select" id="supplier_id_select" class="select160">
            <option value="<?php echo $supplier_id?>" <selected="selected"><?php echo $account_name?></option>
            <?php 
    	for ($w = 0; $w < count($arrId2); $w++) {
		echo "<option value=\"".$arrId2[$w] . "\"" . ">" . $arrName2[$w] . "</option>";	
	    }
     ?>
          </select>
        </span></td>
      </tr>
      <tr>
        <td>Category:</td>
        <td><label for="sub_category_select"></label>
          <select name="category_select" class="select160" id="category_select">
            <option value="Product">Product</option>
            <option value="Production">Production</option>
            <option value="Stores">Stores</option>
            <option value="Old">Old</option>
            <option value="<?php echo $category?>" selected><?php echo $category?></option>
          </select></td>
        <td>Sub category:</td>
        <td><select name="sub_category_select" class="select160" id="sub_category_select">
          <option value="Aggregates">Aggregates</option>
          <option value="Cleaning materials">Cleaning materials</option>
          <option value="Consumables">Consumables</option>
          <option value="Fuel">Fuel</option>
          <option value="Lubricants">Lubricants</option>
          <option value="Machine spares">Machine spares</option>
          <option value="Oils">Oils</option>
          <option value="Packaging">Packaging</option>
          <option value="Pigment">Pigment</option>
          <option value="PPE">PPE</option>
          <option value="Tools">Tools</option>
          <option value="Welding &amp; Engineering">Welding &amp; Engineering</option>
          <option value="Old">Old</option>
          <option value="<?php echo $sub_category?>" selected="selected"><?php echo $sub_category?></option>
        </select></td>
      </tr>
      <tr>
        <td>Unit:</td>
        <td>
		<select name="unit_select" class="select120" id="unit_select">
		  <option value="kg">kg</option>
		  <option value="ltr">ltr</option>
		  <option value="m">m</option>
		  <option value="m2">m2</option>
		  <option value="m3">m3</option>
		  <option value="no">no</option>
		  <option value="pair">pair</option>
		  <option value="<?php echo $unit?>" selected="selected"><?php echo $unit?></option>
        </select>
		</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>Quantity in stock: </td>
        <td><?php echo $quantity?></td>
        <td>Minimum Stock:</td>
        <td>
		<input name="minimum_stock_text" type="text" class="text100" id="minimum_stock_text" value="<?php echo $minimumStock?>" onfocus = "this.select();">
		</td>
      </tr>
      <tr>
        <td>Price:</td>
        <td>
        <input name="base_price_text" type="text" class="text100" id="base_price_text" value="<?php echo $price?> " onKeyPress="return isNumberKey(event)" onKeyUp=" this.value = this.value.replace (/(\...).*/, '$1')" onfocus = "this.select();" ></td>
        <td>Last purchase price:</td>
        <td><input name="purchase_price_text" type="text" class="text100" id="purchase_price_text" value="<?php echo $purchase_price?> " onKeyPress="return isNumberKey(event);" onKeyUp=" this.value = this.value.replace (/(\...).*/, '$1')" onfocus = "this.select();" ></td>
        </tr>
      <tr>
        <td>Product specifications:</td>
        <td colspan="3"><input name="specs_text" type="text" class="text300" id="specs_text" value="<?php echo $specs?>"> </td>
        </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>Date entered:</td>
        <td><?php echo date("d-m-Y", strtotime($date))?></td>
        <td>Last modification:</td>
        <td><?php echo date("d-m-Y", strtotime($lastModDate))?></td>
      </tr>
      
      <tr>
        <td>&nbsp;</td>
        <td colspan="3">&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="3">&nbsp;</td>
      </tr>
      
      <tr>
        <td>&nbsp;</td>
        <td colspan="3">&nbsp;</td>
      </tr>
  </table>
    <div class="page_inside_frame">
      <table width="600" border="0">
    <tr>
      <td width="20"></td>
      <td width="615" align="right"><input type="hidden" name="store_item_id" id="store_item_id" value="<?php echo $store_item_id ?>" />
        <input name="button2" type="button" class="imagebutton" id="button2" onClick="cancel_confirmation(3, '../store/store_main.php?date=0&subCatSelect=Tiles');" value="Close"/>
        <input name="save_button"  id="save_button" type="submit" class="imagebutton" value="Save" onClick="needToConfirm = false; confirmRefresh();" />
        <input name="save_close_button"  id="save_close_button" type="submit" class="imagebutton" value="Save &amp; Close" onClick="needToConfirm = false; confirmRefresh();" /></td>
    </tr>
  </table>
</div>
</form>
</div>
</div>
<?php include ('../navigation/side_bar.php'); ?>
</body>
<?php } else { ?>
<script> needToConfirm = false; </script>
<?php
$_SESSION['denied_return'] = $_SESSION['location'];	
include ("../navigation/store_sidebar.php");?>
	<body onLoad="accessdenied(); return false">
	</body>
<?php }
?>


