<?php
session_start();
include("header.php");
$sy=0;
$errmsg = "";
$tchID=0;
$schoolID=0;
if(trim($_GET["id"])!="")
{
	$tchID=$_GET["id"];
}
else if(trim($_POST["tchID"])!="")
{
	$tchID=$_POST["tchID"];
}
if(trim($_POST["sy"])!="")
	$sy=$_POST["sy"];

if(trim($_POST["schoolID"])!="")
	$schoolID=$_POST["schoolID"];

$action=$_POST["action"];
$teacherName=$_POST["teacherName"];
$school=$_POST["school"];

if(strtoupper($action)== "UPDATE")
{
	if(trim($teacherName)=="")
	{
		$errmsg = "Teacher Name field is empty";
	}
	else
	{
		$strSql = @mysql_query("update tr_teachers set teacher_name='".$teacherName."',school_id=".$school.",sy=".$sy." where teacher_id=".$tchID);
		$errmsg = "You have successfully updated your teacher.";
	}
	
}
else
{
	
	$strSql = @mysql_query("select * from tr_teachers where teacher_id=".$tchID);
	$cntr=@mysql_num_rows($strSql);
	$rs=@mysql_fetch_array($strSql);
	if($cntr>0)
	{
		$sy = $rs["sy"];
		$tchID = $rs["teacher_id"];
		$schoolID =$rs["school_id"];
		$teacherName = trim($rs["teacher_name"]);
	}
}
 ?>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr><td></td><td align="center" class="fs14 black"><u><b>Update Teacher (<?=$teacherName?>)</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.asp?schlID=<%=school%>"><br/><br/><br/><br/><br/>
			<?php
			}
			else
			{
			?>
				<form action="teacherUpdate.php?id=<?=$tchID?>" method="post" name="frm">
				<input type="hidden" name="tchID" value="<?=$tchID?>" />
				<input type="hidden" name="schoolID" value="<?=$schoolID?>" />
				<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="UPDATE" /></td></tr>
				<tr valign="top"><td></td><td class="errmsg" colspan="3"><?=$errmsg?></td></tr>
				</form>
				<?php
			}
				?>
				<tr><td colspan="4"><hr /></td></tr>
			</table></td></tr>
</table>
<?php
include("footer.php");
?>