<?php
session_start();
include("header.php");
$stat=1;
$studentID=0;
$schoolID=0;
$yearRef=0;
$action =$_GET["action"];

if(trim($_GET["stat"])!="")
	$stat=$_GET["stat"];
if(trim($_GET["id"])!="")
	$studentID=$_GET["id"];
if(trim($_GET["schlID"])!="")
	$schoolID=$_GET["schlID"];

if(trim(strtoupper($action)) == "UPDATE")
	$strSql =@mysql_query("update tr_student set status=".$stat." where student_id=".$studentID);

	?>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr><td></td><td align="center" class="fs14 black"><u><b>Students</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);
			$rs1=@mysql_fetch_array($strSql);
			if($cnt>0)
			{
				$yearRef=$rs1["syID"];
				
				$strSql =@mysql_query("select a.*,b.school_name,c.grade_name from tr_student a left join tr_schools b on b.school_id=a.school_id left join ma_grades c on c.grade_id=a.grade where a.school_id=".$schoolID." and a.sy=".$yearRef." order by c.orderby,a.student_lname");
				$cnt1=@mysql_num_rows($strSql);
				
				if($cnt1>0)
				{
					while($rs=@mysql_fetch_array($strSql))
					{
						$sStatus="In-active";
						$statVal=1;
						if($rs["status"]== 1)
						{
							$sStatus="Active";
							$statVal=0;
						}
						//$bDate = MonthName(Month(cDate($rs["date_birth"])),true)." ".Day(cDate($rs["date_birth"])).", ".Year(Date);
						$bDate=$rs['date_birth'];
						echo "<tr><td colspan='3'><hr /></td></tr>";
						echo "<tr><td>&nbsp;<a href='student.php?sID=".$rs["student_id"]."'>".$rs["student_fname"]." ".$rs["student_lname"]."</a><br/>&nbsp;".$rs["grade_name"].", Birth Day: ".$bDate."<br/>&nbsp;".$rs["school_name"]."</td>";
						echo "<td><a href='studentUpdate.php?id=".$rs["student_id"]."&schlID=".$schoolID."'>Update</a></td><td><a href='students.php?action=update&stat=".$statVal."&schlID=".$schoolID."&id=".$rs["student_id"]."'>".$sStatus."</a></td></tr>";
					}
				}
				else
				{
					echo "<tr><td colspan='3'><hr /></td></tr>";
					echo "<tr><td colspan='3'>There's no Student found on this School.</td></tr>";
				}
			
			}
			echo "<tr><td colspan='3'><hr /></td></tr>";
			echo "<tr><td></td><td colspan='2'><a href='studentNew.php?schlID=".$schoolID."'>Create New Student</a></td></tr>";

			?>
			</table></td></tr>
</table>
<?php
include("footer.php");
?>