<?php
session_start();
include("header.php");
$dayAdd=0;
$prv = "";
$nxt = "";
if(trim($_GET["da"])!="")
	$dayAdd = $_GET["da"];

if($dayAdd > 0)
{
	$ddayAdd=$dayAdd-1;
	$prv = "<a href='studentsLabel.php?da=".$ddayAdd."'>prev</a>";
}
if($dayAdd<= 28)
{
	$ddayAdd=$dayAdd+1;
	$nxt = "<a href='studentsLabel.php?da=".$ddayAdd."'>next</a>";
}

	$fdate=strtotime(date('Y-m-d'));

	$odate=strtotime("+".$dayAdd." day",$fdate);
	$OrderDate=date("Y-m-d",$odate);
	
	$dayn=date("l",strtotime($OrderDate));

	$ccdate=explode("-",$OrderDate);

	$monthNum = $ccdate[1];
	$monthName = date("F", mktime(0, 0, 0, $monthNum, 10));

	$sDate =$dayn.", ". $monthName ." ". $ccdate[2].", ".$ccdate[0];

	//$OrderDate = FormatDateTime(DateAdd("d",dayAdd,Date()),1) 

?>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr><td></td><td align="center" class="fs14 black"><u><b>Student's Label</b></u></td></tr>
	<tr><td rowspan="3" width="200" class="fs12" valign="top">
	<?php
			include("sidemenu.php");
		?>
	</td>
		<td align="center" class="fs12"><b>Order Date: <?=$sDate?></b></td></tr>
	<tr><td align="center" class="fs12"><?=$prv?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?=$nxt?></td></tr>
	<tr><td width="700" class="fs12" valign="top">
			<table width="680" cellpadding="1" cellspacing="1" border="0">
				<tr valign="top"><td width="50%" height="10"></td><td width="50%"></td></tr>
				<tr valign="top"><td colspan="2"><hr /></td></tr>
				<tr><td colspan="2" align="center"><i><b>STUDENTS</b></i></td></tr>
				<tr><td colspan="2"><hr /></td></tr>
				<?php
			//set rs = server.createobject("adodb.recordset")
			
			$ordate1=$OrderDate." 00:01:01";

			$strSql =@mysql_query("SELECT e.student_id,concat(e.student_fname,' ',e.student_lname) full_name, h.school_name, g.teacher_name, f.grade_name, a.service_date,a.item_snack,a.item_drink, b.menu_name, b.menu_code, c.itemcode, e.alergy_desc FROM tr_orderdetails a join tr_menu b on b.menu_id=a.item_ordered join ma_itemtype c on c.itemtype_id=a.item_type join tr_orders d on d.order_id=a.order_id join tr_student e on e.student_id = d.student_id join ma_grades f on f.grade_id=e.grade join tr_teachers g on g.teacher_id=e.teacher join tr_schools h on h.school_id=e.school_id where service_date ='".$ordate1."'  order by h.school_name, f.orderBy, g.teacher_name, e.student_lname");
			
		
//			DATE_ADD(CURDATE(), INTERVAL '".$dayAdd."' DAY)

			//set rs = con.Execute(strSql)
			$cnt=@mysql_num_rows($strSql);	
			//If not rs.EOF then
			if($cnt>0)
			{
				$tCnt = 0;
				echo "<tr valign='top'>";
				//while not rs.EOF 	
				while($rs=@mysql_fetch_array($strSql))
				{
						if($tCnt==2)
						{
							$tCnt = 0;
							echo "</tr><tr><td colspan='2'><hr /></td></tr><tr>";
						}
						//end if
						$menuName = " - " .trim($rs['menu_name']);
						$menuItem = trim(($rs['menu_code']));  
						if(trim(strtoupper($rs["itemcode"]))!= "R")
							$menuItem = $menuItem . trim(strtoupper($rs["itemcode"]));
						$menuItem = $menuItem .$menuName;
						$bDayTD="<td>";
						//set rs1 = server.createobject("adodb.recordset")
						
						$birthd="%-".$ccdate[1]."-".$ccdate[2]." 00:00:00";
						$strSql1 =@mysql_query("SELECT * FROM tr_student where student_id='".$rs["student_id"]."' and date_birth='".$birthd."'");

					/*	$strSql1 =@mysql_query("SELECT * FROM tr_student where student_id=".$rs["student_id"]." and month(date_birth)=month(DATE_ADD(CURDATE(),INTERVAL ".$dayAdd." DAY)) and day(date_birth)=day(DATE_ADD(CURDATE(),INTERVAL ".$dayAdd." DAY))");
					*/
						//set rs1 = con.Execute(strSql1)
						
						$cnt1=@mysql_num_rows($strSql1);
						//if not rs1.EOF 
						if($cnt1>0)
							$bDayTD="<td style='background-image:url('../images/bdaybg.gif')'>";
						//rs1.Close
						//set rs1=nothing
						echo $bDayTD."<b>STUDENT NAME:</b>&nbsp;".$rs["full_name"]."<br/><b>Alergy info: </b>&nbsp;".$rs["alergy_desc"]."<br/><b>GRADE:</b>&nbsp;".$rs["grade_name"]."<br/>";
						echo "<b>TEACHER'S NAME:</b>&nbsp;".$rs["teacher_name"]."<br/><b>SCHOOL NAME:</b>&nbsp;".$rs["school_name"]."<br/>";
						echo "<b>ORDER DATE:</b>&nbsp;".$sDate."<br/><b>ITEM ORDERED:</b>&nbsp;".$menuItem."<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
						echo "<b>Snack:</b> ".getSD($rs["item_snack"])."<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
						echo "<b>Drink:</b>".getSD($rs["item_drink"])."</td>";
						$tCnt=$tCnt+1;
						//rs.moveNext
					//wend
				}
				echo "</tr>";
				echo "<tr><td colspan='2'><hr /></td></tr>";

				//echo "<tr><td></td><td><a href='#' onclick='openLunhwindow('studentsLabelReport.php?da=".$dayAdd."');'>View Print Report</a></td></tr>";

				echo "<tr><td></td><td><a href='#' onClick='javascript:window.open(\"studentsLabelReport.php?da=".$dayAdd."\",\"Print Report\",\"menubar=1,resizable=1,width=800,height=800,scrollbars=1\");' >View Print Report</a>&nbsp;&nbsp;</td>";
			
			//end if
			}
			else
			{
				echo "<tr><td colspan='2' align='center' height='100'>There are no orders for this Date!</td></tr>";
				echo "<tr><td colspan='2'><hr /></td></tr>";
				echo "<tr><td></td></tr>";
			}
			//rs.Close
			//set rs=nothing 
			?>
			</table></td></tr>
</table>
<?php
include("footer.php");
?>