<?php
session_start();
include("dbconnect.php");
include("globalfunctions.php");
//<!-- #include file="include\globalfunctions.inc"-->

// dim con,rs,strSql
//set con = server.createobject("adodb.connection")
//con.ConnectionString = "DSN=lunchpails;UID=admin;PWD=ohY9ielae"
//con.CursorLocation = 3
//con.Open

$dayAdd=1;
$prv = "";
$nxt = "";
$school=0;
$grade=0;
$teacher=0;

if(trim($_GET["schl"])!="") 
	$school=$_GET["schl"];
if(trim($_GET["da"])!="") 
	$dayAdd = $_GET["da"];
if(trim($_GET["grd"])!="") 
	$grade=$_GET["grd"];
if(trim($_GET["tchr"])!="") 
{
	$teacher=$_GET["tchr"];
	//$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];

 $xdt=date('Y-m-d');

?>
<!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>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<meta name="description" content="Lunch Pails">
	<meta name="hidden" content="school, snack, healthy, catering, class, peanut-free">
	<meta name="keywords" content="school, snack, healthy, catering, class, peanut-free">
    <link rel="stylesheet" href="../css/general.css" type="text/css" />
</head>
<body style="background-color:#FFF; background-image:url(../../images/space.gif)">
<table border="0" cellpadding="0" cellspacing="0" width="750" align="center">
	<tr><td valign="middle" width="300"><img src="../images/lunchpails_logo.gif" border="0" alt=""/></td><td align="right" class="fs12" valign="middle"><?=date('F',strtotime($xdt))?>&nbsp;<?=date('d',strtotime($xdt))?>,&nbsp;<?=date('Y',strtotime($xdt))?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td width="8" valign="middle"><a href="javascript:window.print()"><img src="../images/print.jpg" border="0" alt="print"/></a></td></tr>
	<tr><td colspan="3"><hr /></td></tr>
	<tr><td colspan="3" height="25"></td></tr>
	<tr><td colspan="3">
		<table width="100%" cellpadding="1" cellspacing="1" border="0">
			<tr><td colspan="4" align="center" class="fs14 black"><u><b>Class Packing List</b></u></td></tr>
			<tr valign="top"><td width="25%" height="10"></td><td width="10%"></td><td width="40%"></td><td width="25%" height="10"></td></tr>
		<?php
		$ordate1=$OrderDate." 00:01:01";
		$strSql =@mysql_query("SELECT concat(e.student_fname,' ',e.student_lname) full_name,e.grade,f.grade_name,e.teacher,g.teacher_name,a.service_date,a.item_snack,a.item_drink,b.menu_name,b.menu_code,c.itemcode 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 where service_date = '".$ordate1."' and e.school_id=".$school." order by f.orderby,f.grade_name,e.teacher");
			if($teacher!=0)
			{
				$strSql = $strSql." and e.teacher=".$teacher;
			}
		$cntr=@mysql_num_rows($strSql);
			if($cntr>0)
			{
				$tCnt = 0;
				$sTest = 0;
				$rTest = 0;
				$sTech = 0;
				$rTech = 0;
				$jun=0;
				while($rs=@mysql_fetch_array($strSql))
				{
					$tCnt=$tCnt+1;
					$rTest = $rs["grade"];
					$rTech = $rs["teacher"];
					if($rTest!=$sTest)
						$jun=1;
					if($sTech!=$rTech)
						$jun=1;
					if($jun==1)
					{
						$jun=0;
						echo "<tr><td colspan='4' height='15'></td></tr>";
						echo "<tr><td colspan='4'><hr/></td></tr>";
						echo "<tr><td colspan='4' height='15'></td></tr>";
						echo "<tr><td colspan='4' class='fs12'>School Name:&nbsp;&nbsp;<b>".getSchool($school)."</b></td></tr>";
						echo "<tr><td colspan='4' class='fs12'>Order Date:&nbsp;&nbsp;<b>".$sDate."</b></td></tr>";
						echo "<tr><td colspan='4' class='fs19'><b>".$rs["grade_name"]."</b></td></tr>";
						echo "<tr><td colspan='4' class='fs19'><b>".$rs["teacher_name"]."</b></td></tr>";
					}
					$iNote = getIType(trim($rs["itemcode"]));
					$menuItem = trim(strtoupper($rs["menu_code"]));
					if(trim(strtoupper($rs["itemcode"]))!="R")
					{
						$menuItem = $menuItem.trim(strtoupper($rs["itemcode"]));
					}
					echo "<tr class='fs12' valign='top'><td>".$rs["full_name"]."</td><td>".$menuItem."</td><td>".trim($rs["menu_name"])."<br/><i><u>Snack:</u> ".getSD($rs["item_snack"])."</i><br/><i><u>Drink:</u> ".getSD($rs["item_drink"])."</i></td><td>".$iNote."</td></tr>";
					$sTest = $rTest;
					$sTech = $rTech;
					
				}
				echo "<tr><td colspan='4'><hr /></td></tr>";
				echo "<tr class='fs12'><td colspan='2' align='center'></td><td align='right'><b>Total Orders:</b>&nbsp;&nbsp;</td><td align='center'><b>".$tCnt."</b></td></tr>";
			}
			else
			{
				echo "<tr><td colspan='4'><hr /></td></tr>";
				echo "<tr><td colspan='4' align='center' height='100'>There's no Order for this Class!</td></tr>";
				echo "<tr><td colspan='4'><hr /></td></tr>";
			}
	?>
		</table></td></tr>
	<tr><td height="9" colspan="2"></td><td width="5"></td></tr>

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