<?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
{
$sy=0;
$errmsg = "";
$schoolID=0;
if(trim($_GET["schlID"])!="")
	$schoolID=$_GET["schlID"];

$action=$_POST["action"];
$teacherName=$_POST["teacherName"];
$school=$_POST["school"];
if(trim($_POST["sy"])!="")
	$sy=$_POST["sy"];

if(strtoupper($action)== "CREATE")
{
	if(trim($teacherName)=="") 
	{
		$errmsg = "Teacher Name field is empty";
	}
	else
	{
		$strSql =@mysql_query("insert into tr_teachers(school_id,teacher_name,sy) values(".$school.",'".$teacherName."',".$sy.")");
		//strSql = ""
		$errmsg = "You have successfully created your teacher.";
	}
	
}
?>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr><td></td><td align="center" class="fs14 black"><u><b>Create New Teacher</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),1,8))== "YOU HAVE")
				{
					echo "<tr valign='top' align='center'><td colspan='4'>".$errmsg."</td></tr>";
				?>
					<meta http-equiv="Refresh" content="3;url=teachers.php?schlID=<?=$schoolID?>"><br/><br/><br/><br/><br/>
				<?php
				}
				else 
				{
				?>
						<form action="teacherNew.php?schlID=<?=$schoolID?>" method="post" name="frm">
						<tr><td height="10" width="20%"></td><td width="30%" class="fs10"><i>* required fields</i></td><td height="10" width="15%"></td><td width="35%"></td></tr>
						<tr><td align="right"><b>* </b>TEACHER NAME:&nbsp;</td><td><input class="formInput" type="text" name="teacherName" value="<?=$teacherName?>" /></td><td align="right">SCHOOL:&nbsp;</td>
							<td><select name="school" class="formSelect">
							<?php
								echo "<option value='0'>--Select--</option>";
								$strSqls =@mysql_query("select school_id,school_name from tr_schools where status=1 order by school_name");
								$cnts=@mysql_num_rows($strSqls);
								if($cnts>0)
								{
									
									while($rs1=@mysql_fetch_array($strSqls))
									{
										
										if($schoolID==$rs1['school_id'])
											echo '<option value='.$rs1['school_id'].' selected>'.$rs1['school_name'].'</option>';
										else
											echo '<option value='.$rs1['school_id'].'>'.$rs1['school_name'].'</option>';
									}
									
								}
							
							?>
						
						</select></td></tr>
						<tr><td align="right">SCHOOL YEAR:&nbsp;</td>
							<td><select name="sy" class="formYear">
							<?php
							
							$strSql1 =@mysql_query("select syID,syName from ma_schoolyear where sstatus=1 order by syID desc");
							$cntr1=@mysql_num_rows($strSql1);
							if($cntr1>0)
							{
								while($rs1=@mysql_fetch_array($strSql1))
								{
									
									if($sy==$rs1['syID'])
										echo '<option value='.$rs1['syID'].' selected>'.$rs1['syName'].'</option>';
									else
										echo '<option value='.$rs1['syID'].'>'.$rs1['syName'].'</option>';
								}
							}
							
							?></select></td>
							<td></td><td><input class="fs12" type="submit" name="action" value="CREATE" /></td></tr>
						<tr><td></td><td class="errmsg fs12" colspan="3"><?=$errmsg?></td></tr>
						</form>
						<?php
				}
						?>
				<tr><td colspan="4"><hr /></td></tr>
			</table></td></tr>
</table>
<?php
include("footer.php");
}
?>