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

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

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

if($_POST['orderBy']!="")
{
	$orderBy=$_POST['orderBy'];
}
if($_GET['orderBy']!="")
{
	$orderBy=$_GET['orderBy'];
}

if(strtoupper($action)== "CREATE")
{
	if(trim($gradeName)=="")
	{
		$errmsg = $errmsg."Grade Name field is empty<br/>";
	}
	if(trim($orderBy)=="")
	{
		$errmsg = $errmsg."Order By field is empty<br/>";
	}	
	if(trim($errmsg)=="")
	{
		$strSql = mysql_query("insert into ma_grades(grade_name,orderBy) values('".$gradeName."',".$orderBy.");");
		$errmsg = "You have successfully created your Grade.";
	}
}
?>

<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr><td></td><td align="center" class="fs14"><u><b>Create New Grade</b></u></td></tr>
	<tr><td width="200" class="fs12" valign="top">
		<?php
		include("sidemenu.php");
		?>
		</td>
		<td width="680" class="fs12">
		<table width="608" 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=grades.asp"><br/><br/><br/><br/><br/>
		<?php
		}
		else
		{
		?>
				<form action="gradeNew.php" method="POST" name="frm">
				<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="CREATE" /></td></tr>
				</form>
		<?php
		}
		?>
				<tr><td colspan="4"><hr /></td></tr>
			</table>
		</td>
	</tr>
</table>
<?php
include("footer.php");
}
?>