<?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
{
?>
<script type="text/javascript"> 
function confirmdelete(DestURL) {
	var ok = confirm("Are you sure you want to delete this?");
	if (ok) {location.href = DestURL;}
	return ok;
	} 
</script>
<?php 
$oID=0;
$errmsg="";
$studentID=0;
$action = trim($_GET["action"]);
if(trim($_GET["oID"])!="")
	$oID=$_GET["oID"];
if(trim($_GET["sID"])!="")
	$studentID=$_GET["sID"];
if($oID!=0 && strtoupper(trim($action)) == "RMVD")
{
	$strSql = @mysql_query("delete from tr_orderdetails where detail_id=".$oID);
	$strSql = "";
	$errmsg = "You have successfully deleted an Order.";
}
?>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr><td></td><td align="center" class="fs14 black"><u><b>Student</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><td width="17%" headers="10"></td>
					<td width="31%"></td>
					<td width="21%" height="10"></td>
					<td width="31%"></td></tr>
				<tr valign="top"><td colspan="4"><hr /></td></tr>
				<?php
			$strSql1 = @mysql_query("select concat(a.student_fname,' ',a.student_lname) full_name,b.school_name,a.date_birth,c.teacher_name,d.grade_name,a.parent_guardian,a.email,a.contact_no from tr_student a left join tr_schools b on b.school_id=a.school_id left join tr_teachers c on c.teacher_id=a.teacher left join ma_grades d on d.grade_id=a.grade where a.student_id=".$studentID);
			$cntr=@mysql_num_rows($strSql1);
			if($cntr>0)
			{
				$rs=@mysql_fetch_array($strSql1);

				//$bDay = Monthname(Month(rs("date_birth"))) &" "& Day(rs("date_birth")) &", "& Year(rs("date_birth"))
				$bDay=date('F',strtotime($rs["date_birth"]))." ".date('d',strtotime($rs["date_birth"]))." ".date('Y',strtotime($rs["date_birth"]));
				?>
				<tr><td align="right"><b>STUDENT NAME:</b>&nbsp;</td><td><?=$rs["full_name"]?></td><td align="right"><b>DATE OF BIRTH:</b>&nbsp;</td><td><?=$bDay?></td></tr>
				<tr><td align="right"><b>SCHOOL NAME:</b>&nbsp;</td><td><?=$rs["school_name"]?></td><td align="right"><b>PARENT/GUARDIAN:</b>&nbsp;</td><td><?=$rs["parent_guardian"]?></td></tr>
				<tr><td align="right"><b>GRADE:</b>&nbsp;</td><td><?=$rs["grade_name"]?></td><td align="right"><b>EMAIL:</b>&nbsp;</td><td><?=$rs["email"]?></td></tr>
				<tr><td align="right"><b>TEACHER:</b>&nbsp;</td><td><?=$rs["teacher_name"]?></td><td align="right"><b>CONTACT NUMBER:</b>&nbsp;</td><td><?=$rs["contact_no"]?></td></tr>
			<?php
			}
			else
			{
				echo "<tr><td colspan='4'>There's no Student found.</td></tr>";
			}
			?>
			<tr><td colspan="5"><hr /></td></tr>
			<tr><td colspan="5">&nbsp;</td></tr>
			<tr><td colspan="5">&nbsp;<b>CURRENT ORDERS:</b></td></tr>
			<tr><td colspan="5">
					<table width="608" cellpadding="1" cellspacing="1" border="0">
						<tr valign="top"><td width="20%" height="1"></td><td width="35%"></td><td width="20%"></td><td width="15%"></td><td width="7%" height="1"></td></tr>
						<tr valign="top"><td colspan="6"><hr /></td></tr>
						<tr><td>&nbsp;<b>Date Ordered</b></td><td><b>Lunch Ordered</b></td><td><b>Description</b></td><td><p>Payment</p></td><td></td></tr>
						<tr><td colspan="6"><hr /></td></tr>
						<?php
						$ddate=date('Y-m-d');
						$sdate=$ddate." 00:00:00";

					$strSql2 =@mysql_query("SELECT a.detail_id,a.service_date,a.item_snack,a.item_drink,c.menu_name,d.item_type,b.paid_status FROM tr_orderdetails a left join tr_orders b on b.order_id=a.order_id left join tr_menu c on c.menu_id=a.item_ordered left join ma_itemtype d on d.itemtype_id=a.item_type where b.student_id='".$studentID."' and a.service_date>'".$sdate."' order by service_date");
					
					$cntr2=@mysql_num_rows($strSql2);
					if($cntr2>0)
					{
						while($rs1=@mysql_fetch_array($strSql2))
						{
							//$sDate = Monthname(Month(rs("service_date"))) &" "& Day(rs("service_date")) &", "& Year(rs("service_date"))
							$sDate=	date('F',strtotime($rs1["service_date"]))." ".date('d',strtotime($rs1["service_date"]))." ".date('Y',strtotime($rs1["service_date"]));

						?>
							<tr valign="top">
								<td>&nbsp;<?=$sDate?></td>
								<td><?=$rs1["menu_name"]?><br/><i><u>Snack:</u> <?=getSD($rs1["item_snack"])?></i><br/><i><u>Drink:</u> <?=getSD($rs1["item_drink"])?></i></td>
								<td><?=$rs1["item_type"]?></td>
								<td>
								<?php
									if($rs1['paid_status']=='1')
									 echo "&nbsp;&nbsp;Done";
									else
									 echo "&nbsp;&nbsp;Not Done&nbsp;&nbsp;";
								?>
								</td>
								<td align="center"><a href="orderStudent.php?oID=<?=$rs1["detail_id"]?>&sID=<?=$studentID?>">edit</a></td>
								<td align="center">
								<a href="#" onclick="confirmdelete('student.php?oID=<?=$rs1["detail_id"]?>&sID=<?=$studentID?>&action=rmvd'); return false;">delete</a></td></tr>
							<?php
						}
					}
					else
					{
						echo "<tr><td colspan='5' align='center'>There's no Order for this Student!</td></tr>";
						echo "<tr><td colspan='5'><hr /></td></tr>"; 
					}
					?>
					</table></td></tr>
			</table></td></tr>
</table>
<?php
include("footer.php");
}
?>