<?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 = "";
$grdID=0;

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


$action=$_POST['action'];

$gradeName=$_POST['gradeName'];
$orderBy=$_POST['orderBy'];

if(strtoupper($action) == "UPDATE")
{
	if(trim($gradeName)=="")
		$errmsg = $errmsg."Menu Name field is empty<br/>";
	
	if(trim($orderBy)=="")
		$errmsg = $errmsg."Order By field is empty<br/>";
	
	if(trim($errmsg)=="")
	{
		$strSql = mysql_query("update ma_grades set grade_name='".$gradeName."',orderBy='".$orderBy."' where grade_id='".$grdID."'");
		
		$errmsg = "You have successfully updated your Grade.";
	}
}
else
{
	$strSql = mysql_query("select * from ma_grades where grade_id='".$grdID."'");
	$rcnt=@mysql_num_rows($strSql);
	If($rcnt>0)
	{
		$rs=@mysql_fetch_array($strSql);
		$grdID=$rs['grade_id'];
		$gradeName=$rs['grade_name'];
		$orderBy=$rs['orderBy'];
	}
}
?>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr><td></td><td align="center" class="fs14"><u><b>Update Grade <?=$gradeName?></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=grades.php"><br/><br/><br/><br/><br/>
		<?php
		}	
		else
		{
		?>
				<form action="gradeUpdate.php?id=<?=$grdID?>" method="POST" name="frm">
				<input type="hidden" name="grdID" value="<?=$grdID?>" />
				<tr><td height="10" width="17%"></td><td width="33%" class="fs10"><i>* required fields</i></td><td height="10" width="15%"></td><td width="35%"></td></tr>
				<tr><td align="right"><b>* </b>GRADE NAME:&nbsp;</td><td><input class="formInput" type="text" name="gradeName" value="<?=$gradeName?>" /></td>
				<td align="right"><b>* </b>ORDER BY:&nbsp;</td><td><input class="formInputS" type="text" name="orderBy" value="<?=$orderBy?>"/></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");
}
?>