<?php
session_start();
include("header.php");
$stat=1;
$teacherID=0;
$schoolID=0;
$yearRef=0;
$action = $_GET["action"];
if(trim($_GET["stat"])!="")
	$stat=$_GET["stat"];
if(trim($_GET["id"])!="")
	$teacherID=$_GET["id"];
if(trim($_GET["schlID"])!="")
	$schoolID=$_GET["schlID"];
if(trim(strtoupper($action)) == "UPDATE")
	$strSql =@mysql_query("update tr_teachers set status=".$stat." where teacher_id=".$teacherID);
	 
?>
<table width="748" cellpadding="0" cellspacing="0" border="0">
	<tr><td></td><td align="center" class="fs14 black"><u><b>Teachers</b></u></td></tr>
	<tr><td width="200" class="fs12" valign="top">
	<?php
	include("sidemenu.php");
	?>
	</td>
		<td width="700" class="fs12" valign="top">
			<table width="680" cellpadding="1" cellspacing="1" border="0">
			<tr align="center"><td width="80%"></td>
					<td width="10%"></td><td width="10%"></td></tr>
					<?php
			
			$strSql =@mysql_query("SELECT syID FROM ma_schoolyear order by syID desc limit 1");
			$cnt=@mysql_num_rows($strSql);
			$rs=@mysql_fetch_array($strSql);
			if($cnt>0)
			{
				$yearRef=$rs["syID"];
				
				$strSql1 = @mysql_query("select a.*,b.school_name from tr_teachers a left join tr_schools b on b.school_id=a.school_id where a.school_id=".$schoolID." and a.sy=".$yearRef);
				$cntr=@mysql_num_rows($strSql1);
				
				if($cntr>0)
				{
					while($rs1=@mysql_fetch_array($strSql1))
					{
						$sStatus="In-active";
						$statVal=1;
						if($rs1["status"]== 1)
						{
							$sStatus="Active";
							$statVal=0;
						}
						echo "<tr><td colspan='3'><hr /></td></tr>";
						echo "<tr><td>&nbsp;".$rs1["teacher_name"]."<br/>&nbsp;".$rs1["school_name"]."</td>";
						echo "<td><a href='teacherUpdate.php?id=".$rs1["teacher_id"]."'>Update</a></td><td><a href='teachers.php?action=update&stat=".$statVal."&schlID=".$schoolID."&id=".$rs1["teacher_id"]."'>".$sStatus."</a></td></tr>";
						
					}
				}
				else
				{
					echo "<tr><td colspan='3'><hr /></td></tr>";
					echo "<tr><td colspan='3'>There's no new Teacher found on this School.</td></tr>";
				}
				
			}
			echo "<tr><td colspan='3'><hr /></td></tr>";
			
			?>
				<tr><td align="center" colspan="3"><a href="teacherNew.php?schlID=<?=$schoolID?>"><b>Create New Teacher</b></a></td></tr>
				<tr><td colspan="3"><hr /></td></tr>
				<tr><td colspan="3"><b class="fs14 black">Previous Teachers</b></td></tr>
				<tr align="center"><td width="80%"></td>
					<td width="10%"></td><td width="10%"></td></tr>
					<?php
			
			$strSql2 = @mysql_query("select a.*,b.school_name from tr_teachers a left join tr_schools b on b.school_id=a.school_id where a.school_id=".$schoolID." and a.sy!=".$yearRef);
			$cntr2=@mysql_num_rows($strSql2);
		
				if($cntr2>0)
				{
					while($rs2=@mysql_fetch_array($strSql2))
					{
						
						$sStatus="In-active";
						$statVal=1;
						if($rs2["status"]== 1)
						{
							$sStatus="Active";
							$statVal=0;
						}
						
						echo "<tr><td colspan='3'><hr /></td></tr>";
						echo "<tr><td>&nbsp;".$rs2["teacher_name"]."<br/>&nbsp;".$rs2["school_name"]."</td>";
						echo "<td><a href='teacherUpdate.php?id=".$rs2["teacher_id"]."'>Update</a></td><td><a href='teachers.php?action=update&stat=".$statVal."&schlID=".$schoolID."&id=".$rs["teacher_id"]."'>".$sStatus."</a></td></tr>";
						
					}
				}
				else
				{
					echo "<tr><td colspan='3'><hr /></td></tr>";
					echo "<tr><td colspan='3'>There's no Teacher found on this School.</td></tr>";
				}
				
			echo "<tr><td colspan='3'><hr /></td></tr>";
			 ?>
			</table></td></tr>
</table>
<?php
include("footer.php");
?>