<?php
session_start();
$errmsg="";
$ingrID=0;

if(trim($_GET['id'])!="")
	$ingrID=$_GET['id'];
elseif(trim($_POST['ingrID']!="")
	$ingrID=$_POSt['ingrID'];

$action=$_POST['action'];
$details=$_POST['details'];

if(strtoupper($action) == "UPDATE")
{
	if(trim($details)=="")
		 $errmsg = "Ingredient Details field is empty<br/>";
	if(trim($errmsg)=="")
	{
		$strSql = mysql_query("update tr_ingredient set ingredient_desc='".$details."' where ingredient_id='".$ingrID."'");		
		$errmsg = "You have successfully updated your Ingredient.";
	}
}
else
{
	$strSql2 = mysql_query("SELECT b.menu_code,b.menu_name,a.* FROM tr_ingredient a join tr_menu b on b.menu_id=a.menu_id where ingredient_id='".$ingrID."'");
	
	$strcnt2=@mysql_num_rows($strSql2);
	if($strcnt2>0)
	{
		$rs2=@mysql_fetch_array($strcnt2);

		$ingrID=$rs2['ingredient_id'];
		$menuName=$rs2['menu_name'];
		$mCode=$rs2['menu_code'];
		$details=$rs2['ingredient_desc'];
	}
}
?>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr><td></td><td align="center" class="fs14"><u><b>Update Menu Ingredient <?=$menuName?></b></u></td></tr>
	<tr><td width="200" class="fs12" valign="top"><?php include("sidemenu.php");?>
		<td width="700" class="fs12">
			<table width="680" cellpadding="1" cellspacing="1" border="0">
				<tr><td colspan="4"><hr /></td></tr>
				<?php
				if(strtoupper(substr(trim($errmsg),1,8)) == "YOU HAVE")
				{
					echo "<tr valign='top' align='center'><td colspan='4'>".$errmsg."</td></tr>";
				?>
					<meta http-equiv="Refresh" content="3;url=menus.asp"><br/><br/><br/><br/><br/>

				<?php
				}
				else
				{
				?>
					<form action="ingredientUpdate.php?id=<?=$ingrID?>" method="POST" name="frm">
					<input type="hidden" name="ingrID" value="<?=$ingrID?>" />
					<tr><td height="10" width="17%"></td>
					<td width="30%" class="reqmsg"><i>* required fields</i></td><td height="10" width="15%"></td><td width="38%"></td></tr>
					<tr valign="top"><td colspan="2">MENU NAME:&nbsp;<b><?=$menuName?></b><br/>MENU CODE:&nbsp;<b><?=$mCode?></b></td>
						<td align="right"><b style="color:#FF0000; font-size:15px">* </b>DETAILS:&nbsp;</td>
						<td><textarea name="details" class="formtextarea"><?=$details?></textarea></td></tr>
					<tr valign="top"><td></td><td class="errmsg" colspan="2"><?=$errmsg?></td>
					<td><input class="fs12" type="submit" name="action" value="UPDATE" /></td></tr>
					</form>
					<?php
				}
				?>
				<tr><td colspan="4"><hr /></td></tr>
			</table></td></tr>
</table>
<?php
include("footer.php");
?>