
<?php 
$page_name = "Mix-design";
include ("../navigation/access.php");

if ($permission_num==1) {
	 
	?>
    
<script language="javascript" src="../jscript/chainedselects.js"></script>

<?php
$table_name = $_SESSION['db_prefix']."_product_store";
$store_item_query = "SELECT product_item_id, item_name, unit FROM $table_name WHERE subCategory = 'Sales product' AND mix_design_id IS NULL ORDER BY item_name ASC";
	$store_item_result = $con->query($store_item_query);
	$store_item_num = mysqli_num_rows($store_item_result);
	$w = 0;
	$arrId2 = array ();
	$arrName2 = array ();
	while ($w < $store_item_num) {
		$row = mysqli_fetch_assoc($store_item_result);
		$arrId2[$w] = $row['product_item_id'];
		$arrName2[$w] = $row['item_name'];
		$w++;
	}

	
$table_name = $_SESSION['db_prefix']."_product_store";
$store_item_query = "SELECT product_item_id, item_name, unit FROM $table_name WHERE subCategory = 'Other' AND mix_design_id IS NULL AND packing_design_no IS NULL   ORDER BY item_name ASC";
	$store_item_result = $con->query($store_item_query);
	$store_item_num = mysqli_num_rows($store_item_result);
	$w = 0;
	$arrId3 = array ();
	$arrName3 = array ();
	while ($w < $store_item_num) {
		$row = mysqli_fetch_assoc($store_item_result);
		$arrId3[$w] = $row['product_item_id'];
		$arrName3[$w] = $row['item_name'];
		$w++;
	}

?> 
<link rel="stylesheet" type="text/css" href="../css/main.css" />


<script>
addListGroup("Direct materials", "category", "product_item_id_select", "items");
//addOption("category0", "", "", "", 1); //Empty starter option
addList("category", "", "", "");
addList("category", "Product", "Product", "Product");
addList("category", "Other", "Other", "Other");


addList("Product", "", "", "");
		<?php 
    	for ($w = 0; $w < count($arrId2); $w++) { ?>
			addList("Product", "<?php echo $arrName2[$w]?> ", "<?php echo $arrId2[$w]?> ", "");
		<?php
	    }
     ?>
addList("Other", "", "", "");
		<?php 
        for ($w = 0; $w < count($arrId3); $w++) { ?>
			addList("Other", "<?php echo $arrName3[$w]?> ", "<?php echo $arrId3[$w]?> ", "");
		<?php
	    }
	?>
</script>   

<script language="javascript">
initListGroup("Direct materials", form1.category, form1.product_item_id_select); 

function initLists() {
  form1.category.onchange();
  category.fireEvent("onchange");
</script>

<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]+"'");
}
function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}
function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
</script>
</head>

<?php include('../include/wait.php') ?>

<body onLoad=" initListGroup('Direct materials', document.forms[0].category, document.forms[0].product_item_id_select); MM_showHideLayers('wait','','hide');" onFocus="MM_showHideLayers('wait','','hide');"  onBlur="MM_showHideLayers('wait','','hide');">

<div class="page_middle_frame">
  <form id="form1" name="form1" method="get" action="new_mix_designWizbase.php">
    <table width=595 border="0" align="left" cellpadding="10" cellspacing="0" bordercolor="#0066FF" border-collapse="collapse">
    <tr>
      <td width="525" align="left" valign="top" >
      Select product to make mix recipe for: 
     </td> 
	 <td>&nbsp; </td>
     </tr>
      <tr>
        <td width="111">
          <select name="category" id="category"  class="select160"  >
            <option value="<?php echo $_SESSION['sub_category'] ?>" selected><?php echo $_SESSION['mix_design'] ?></option>
            </select>
            <input type="hidden" name="index" id="index" />
            <select name="product_item_id_select" id="product_item_id_select" class="select250" >
              <option value="<?php echo $_SESSION['product_item_id'] ?>" selected="selected"><?php echo $_SESSION['mix_design'] ?></option>
            </select>
          </td>
        <td width="252"><input name="store_item_id" id="store_item_id" type="hidden" value="" /></td>
      </tr>
    
    <tr>
      <td><table width="590" height="50" align="left" id="table_button_bar">
          <tr>
            <td width="117">&nbsp;</td>
            <td width="115"></td>
            <td width="99"><input name="p" type="hidden" id="p" value="1" />
              <input name="error" type="hidden" id="error" value="0" />
              <input name="s" type="hidden" id="s" value="1" /></td>
            <td width="125" align="left"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="needToConfirm = false; cancel_confirmation(1, '../production/production_main.php?date=0&subCatSelect=Tiles');" value="Cancel"  tabindex="-1"/></td>
            <td width="110" align="left"><input type="submit" name="next_button" id="next_button" class="imagebutton" value="Next" onClick="needToConfirm = false; MM_showHideLayers('wait','','show'); validate();  " tabindex="5" /></td>
          </tr>
      </table></td>
    </tr>
  </table>
</form>

<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("product_item_id_select","req","Please select a product. If no product is available, you need to create the product first in the stores.");
  </script>

</body>
<?php } else { ?>
<script> needToConfirm = false; </script>
<?php
    $_SESSION['denied_return'] = "store/store_main.php?date=0&subCatSelect=Tiles";	?>
<body onLoad="accessdenied(); return false">
</body>
<?php }
?>
