<?php 
session_start();
include("header.php");
if(trim($_SESSION['accountName'])=="" &&  trim($_SESSION['accountID'])=="" && trim($_SESSION['pgid'])!="i3g3e3nious7")
{
	echo '<script>';
	echo 'location.replace("index.php");';
	echo '</script>';
}
else
{

$errmsg = "";
$mtyp=1;

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

$action=$_POST['action'];
$menuName=$_POST['menuName'];
$details=$_POST['details'];
$mCode=$_POST['mCode'];
$orderBy=$_POST['orderBy'];
$mtyp=$_POST['mtyp'];


if(strtoupper($action) == "CREATE")
{
	if(trim($menuName)=="")
		$errmsg = $errmsg."Menu Name field is empty<br/>";

	if(trim($mCode)=="")
		$errmsg = $errmsg."Menu Code field is empty<br/>";
	
	if(trim($orderBy)=="")
		$errmsg = $errmsg."Order By field is empty<br/>";
	

	if(trim($errmsg)=="")
	{
		$strSql = mysql_query("insert into tr_menu(menu_code,menu_name,menu_details,menu_type,orderby) values('".$mCode."','".$menuName."','".$details."','".$mtyp."','".$orderBy."');");

		$errmsg = "You have successfully created your menu.";
	}
}
?>

<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr><td></td><td align="center" class="fs14"><u><b>Create New Menu</b></u></td></tr>
	<tr><td width="200" class="fs12" valign="top"><?php include("sidemenu.php");?></td>
		<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),0,8)) == "YOU HAVE")
				{
				echo "<tr valign='top' align='center'><td colspan='4'>".$errmsg."</td></tr>";
			?>
				<meta http-equiv="Refresh" content="3;url=menus.php?mt=<?=$mtyp?>"><br/><br/><br/><br/><br/>
		<?php
			}
			else
			{
		?>
				<form action="menuNew.php" method="POST" name="frm">
				<tr><td height="10" width="17%"></td><td width="33%" class="reqmsg"><i>* required fields</i></td><td height="10" width="15%"></td><td width="35%"></td></tr>
				<tr><td align="right"><b>* </b>MENU NAME:&nbsp;</td><td><input class="formInput" type="text" name="menuName" value="<?=$menuName?>" /></td>
					<td align="right">DETAILS:&nbsp;</td><td rowspan="4"><textarea name="details" class="formtextarea"><?=$details?></textarea></td></tr>
				<tr><td align="right"><b>* </b>MENU CODE:&nbsp;</td><td><input class="formInputS" size="1" type="text" name="mCode" value="<?=$mCode?>"/></td><td></td></tr>
				<tr><td align="right"><b>* </b>ORDER BY:&nbsp;</td><td><input class="formInputS" type="text" name="orderBy" value="<?=$orderBy?>"/></td><td></td></tr>
				<tr><td align="right">MENU TYPE:&nbsp;</td>
					<td><select name="mtyp" class="formYear">
				<?php	
					$strSql = mysql_query("select mtype_id,menu_type from ma_menutype where status=1");
					$rcnnt=mysql_num_rows($strSql);
					if($rcnnt>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>";
						
						}
					}
					else
					{
						echo "<option value='0'>--Select--</option>";
					}
					?>
						</select></td><td></td></tr>
				<tr valign="top"><td></td><td class="errmsg" colspan="2"><?=$errmsg?></td><td><input class="fs12" type="submit" name="action" value="CREATE" /></td></tr>
				</form>
		<?php
			}
		?>
				<tr><td colspan="4"><hr /></td></tr>
			</table></td></tr>
</table>
<?php
include("footer.php");
}
?>