<?php
	include("../include/session.php");
//	include("../include/db.php");
	if(!$session -> isAdmin()){
		header("Location: ../main.php");
	}else{
		include("../productionHeader.php");
		$recipieId = mysql_real_escape_string($_GET['recipieId']);
	$q = "SELECT productName, unit FROM nam_products WHERE category = 'Direct Materials' AND subCategory = 'Depalet' ORDER BY productName ASC";
	$result = execsql($q);
	$num = mysql_num_rows($result);
	$arrName = array();
	$i = 0;
	while($i < $num){
		$arrName[$i] = mysql_result($result, $i, "productName");
		$arrUnit[$i] = mysql_result($result, $i, "unit");
		$i++;
	}
	
	$q1 = "SELECT * FROM nam_perdepaletprice WHERE id = '$recipieId'";
	$r1 = execsql($q1);
	$price = mysql_fetch_array($r1, MYSQL_ASSOC);
//	echo $q1;
	
	
	$q2 = "SELECT * FROM nam_recipiedepalet WHERE id = '$recipieId'";
	$r2 = execsql($q2);
	$amount = mysql_fetch_array($r2, MYSQL_ASSOC);

//	print_r($amount);
?>                      
<h3>Add New Recipie (Packaging)</h3>

<form action="manipulation/inputDepalet.php" method="POST">
<table>
<tr><td>Recipie Name:<input name="recipieName" value="<?php echo $amount[recipieName]?>" type="text" /><td>Size Of Pallet<input name="size" value="<?php echo $amount[size]?>" type="text" />
<tr><td></td><td>Quantity per Tile</td><td>Cost Per Unit</td></tr>
<?php 

	for ($b = 0 ; $b < count($arrName) ; $b++) {
		$product = $arrName[$b];
		$product = str_replace(" ","_", $product);
//		echo $product;
        echo "<tr><td>$arrName[$b]($arrUnit[$b]):</td> <td><input name=\"$arrName[$b]\" value=\"$amount[$product]\" type=\"text\" /> </td><td><input name=\"$arrName[$b]Price\" value=\"$price[$product]\" type=\"text\" /></td></tr>";
    }
    if($r2){
    	echo "<input name=\"recipieId\" value=\"$recipieId\" type=\"hidden\" />";
    }

?></table>
<input type="reset" value="Reset Form" />
    	<input type="submit" name="submitok" value="   OK   " />
</form>

    	
 <?php 
 		include("../footer.html");
	}
 ?>