<?php
session_start();
error_reporting(E_ALL ^ E_NOTICE);
set_time_limit (3600);
$fname="lunchpails_".date('dmy');
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=".$fname.".xls");
header("Pragma: no-cache");
header("Expires: 0"); 

include("dbconnect.php");
include("globalfunctions.php");

$dayAdd=0;
$prv = "";
$nxt = "";

if(trim($_GET["da"])!="")
	$dayAdd = $_GET["da"];

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

	$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];

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>:: Lunch Pails ::</title>
	</head>
<body >
<table border="1" cellpadding="2" cellspacing="2" width="800" align="center"style="border-collapse:collapse;">
			
			<?php
			$ordate1=$OrderDate." 00:01:01";

			$strSql1 =@mysql_query("select count(*) totalproducts from tr_orderdetails where service_date ='".$ordate1."'");
			$cunt=@mysql_num_rows($strSql1);
			$rs1=@mysql_fetch_array($strSql1);
			if($cunt>0)
			{
				$myPageCount = 1;
			}
			else
			{
				$totalProducts = trim($rs1["totalproducts"]);
				$myPageCount = round($totalProducts / $myPageSize, 0);
			}
			
		
		$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");
		$cnt=@mysql_num_rows($strSql);
		if($cnt>0)
		{
			$tCnt = 0;
			echo "<tr><td nowrap>Student Name</td><td nowrap>Alergy Info</td><td nowrap>Grade</td><td nowrap>Teacher's Name</td><td nowrap>School Name</td><td nowrap>Order Date</td>";
			echo "<td nowrap>Item Ordered</td><td nowrap>Snack</td><td nowrap>Drink</td></tr>";

			while($rs=@mysql_fetch_array($strSql))
				{
					
						$menuName = " - ".trim($rs["menu_name"]);
						$menuItem = trim(strtoupper($rs["menu_code"]));
						if(trim(strtoupper($rs["itemcode"]))!="R")
							$menuItem = $menuItem.trim(strtoupper($rs["itemcode"]));
						$menuItem = $menuItem.$menuName;

					//	$bDayTD="<td>";

						echo "<tr valign='top'>";

						$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."'");

						$cnt1=@mysql_num_rows($strSql1);
						//if($cnt1>0)


						//	$bDayTD="<td style='background-image:url('../images/bdaybg.gif')'>";
						echo $bDayTD."<td>&nbsp;".$rs["full_name"]."</td><td>&nbsp;".$rs["alergy_desc"]."</td><td nowrap>&nbsp;".$rs["grade_name"]."</td><td>&nbsp;".$rs["teacher_name"]."</td><td>&nbsp;".$rs["school_name"]."</td><td nowrap>&nbsp;".$sDate."</td><td>&nbsp;".$menuItem."</td><td>&nbsp;".getSD($rs["item_snack"])."</td><td>&nbsp;".getSD($rs["item_drink"])."</td>";

						//$tCnt=$tCnt+1;
						echo "</tr>";

				
			}

		
		}
		else
		{
			echo "<tr><td colspan='9' align='center' height='100'>There are no orders for this Date!</td></tr>";
		}
		?>

</table>
</body>
</html>
