<?php
session_start();
include("header.php");

$stat=1;
$menuID=0;


if(trim($_POST['mtyp'])!="")
{
	$mtyp=$_POST['mtyp'];
}
elseif(trim($_GET['mt'])!="")
{
	$mtyp=$_GET['mt'];
}
else
	$mtyp=1;
	

if($_POST['action']!="")
	$action =$_POST['action'];
elseif($_GET['action']!="")
	$action =$_GET['action'];

if(trim($_GET['stat'])!="")
	$stat=$_GET['stat'];


if(trim($_GET['id'])!="")
	$menuID=$_GET['id'];

if(trim(strtoupper($action))=="UPDATE")
{
	$strSql = mysql_query("update tr_menu set status='".$stat."' where menu_id='".$menuID."'");

}

?>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr><td></td><td align="center" class="fs14 black"><u><b>School Menus</b></u></td></tr>
	<tr><td rowspan="2" width="140" class="fs12" valign="top"><?php include("sidemenu.php");?></td>
		<form action="menus.php" method="POST" name="frm">
		<td align="center" class="fs12">Select Menu for:&nbsp;
		<select name="mtyp" class="formSelect" onChange="this.form.submit();">
	<?php
		
		$strSql = mysql_query("select mtype_id,menu_type from ma_menutype where status=1");
		$rccnt=@mysql_num_rows($strSql);

		echo "<option value='0'>--Select--</option>";
		
		if($rccnt>0)
		{
			while($rs=@mysql_fetch_array($strSql))
			{
			  	if($mtyp==$rs['mtype_id'])
					echo "<option value='".trim($rs['mtype_id'])."' selected >".$rs['menu_type']."</option>";
				else
					echo "<option value='".trim($rs['mtype_id'])."'>".$rs['menu_type']."</option>";
			}
		}
		
		?>
		</select></td>
		</form>
	<tr><td width="700" class="fs12" valign="top">
			<table width="680" cellpadding="1" cellspacing="1" border="0">
				<tr align="center"><td width="80%"></td>
					<td width="10%"></td><td width="10%"></td></tr>
<?php
			$strSql2 = mysql_query("SELECT * FROM tr_menu where menu_type='".$mtyp."' order by orderby");
			$scnt=@mysql_num_rows($strSql2);
			if($scnt>0)
			{
				while($rs2=@mysql_fetch_array($strSql2))
				{
					$sStatus="In-active";
					$statVal=1;
					if($rs2['status'] == '1')
					{
						$sStatus="Active";
						$statVal=0;
					}
					echo "<tr><td colspan='3'><hr /></td></tr>";

				echo "<tr><td>&nbsp;".$rs2['orderby'].".)&nbsp;".trim($rs2['menu_name'])."&nbsp;(".trim($rs2['menu_code']).")<br/>&nbsp;".trim($rs2['menu_details'])."</td>";
					echo "<td><a href='menuUpdate.php?id=".$rs2['menu_id']."'>Update</a></td><td><a href='menus.php?mt=".$mtyp."&action=update&stat=".$statVal."&id=".$rs2['menu_id']."'>".$sStatus."</a></td></tr>";
					
				}
			}
			echo "<tr><td colspan='3'><hr /></td></tr>";
			echo "<tr><td></td><td colspan='2'><a href='menuNew.php?mt=".$mtyp."'>Create New Menu</a></td></tr>";
			?>
			</table>
		</td>
	</tr>
</table>
<?php
include("footer.php");
?>