<?php
session_start();
include("header.php");

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

if(trim($_POST["school"])!="") 
	$school=$_POST["school"];
else if(trim($_GET["schl"])!="") 
		$school=$_GET["schl"];

if(trim($_POST["grade"])!="") 
	$grade=$_POST["grade"];
else if(trim($_GET["grd"])!="")
		$grade=$_GET["grd"];

if(trim($_POST["teacher"])!="") 
	$teacher=$_POST["teacher"];
else if(trim($_GET["tchr"])!="")
		$teacher=$_GET["tchr"];

if(trim($_GET["da"])!="")
{
	$dayAdd = $_GET['da'];
}
	
		//$OrderDate = FormatDateTime(DateAdd("d",$dayAdd,Date()),1);
if($dayAdd > 0)
{
	$Addday=$dayAdd-1;
	$prv = "<a href='classPlist.php?tchr=".$teacher."&grd=".$grade."&schl=".$school."&da=".$Addday."'>prev</a>";
}
if($dayAdd<= 30)
{
	$Addday=$dayAdd+1;
   $nxt = "<a href='classPlist.php?tchr=".$teacher."&grd=".$grade."&schl=".$school."&da=".$Addday."'>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];

  ?>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr><td></td><td colspan="2" align="center" class="fs14 black"><u><b>Class Packing List</b></u></td></tr>
	<form action="classPlist.php?tchr=<?=$teacher?>&grd=<?=$grade?>&schl=<?=$school?>&da=<?=$dayAdd?>" method="POST" name="frm">
	<tr><td rowspan="4" width="200" class="fs12" valign="top">
	
	<?php
	include("sidemenu.php");
	?>
	</td>
		<td width="350" align="right" class="fs12"><b>School Name:&nbsp;&nbsp;</b></td>
		<td width="350"><select name="school" class="formSelect" onChange="javascript:{if(this.value!='') submit();}">
	<?php
		
			$strSql=@mysql_query("select school_id,school_name from tr_schools where status=1");
			$cnt2=@mysql_num_rows($strSql);
			if($cnt2>0)
			{
				echo "<option value='0'>--Select--</option>";
				while($rs=@mysql_fetch_array($strSql))
				{
					if($school==$rs['school_id'])
						echo "<option value=".$rs['school_id']." selected>".$rs['school_name']."</option>";
					else
						echo "<option value=".$rs['school_id'].">".$rs['school_name']."</option>";

				}
			}
			else
				$school=0;
		 ?></select></td></tr>
	</form>
	<tr class="fs12"><td align="right"><b>Order Date:&nbsp;&nbsp;</b></td><td><b><?=$sDate?></b></td></tr>
	<tr class="fs12"><td colspan="2" align="center"><?=$prv?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?=$nxt?></td></tr>
	<tr><td width="700" class="fs12" colspan="2">
			<table width="680" cellpadding="1" cellspacing="1" border="0">
				<tr valign="top"><td width="25%" height="10"></td><td width="10%"></td><td width="40%"></td><td width="25%" height="10"></td></tr>
				<tr valign="top"><td colspan="4"><hr /></td></tr>
				<tr><td><b>Student Name</b></td><td><b>Item</b></td><td><b>Description</b></td><td><b>Notes</b></td></tr>
		<?php
			//set rs = server.createobject("adodb.recordset")
			$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;

			$cnt=@mysql_num_rows($strSql);
			//set rs = con.Execute(strSql)
			//If not rs.EOF then
			if($cnt>0)
			{
				$tCnt = 0;
				$sTest = 0;
				$rTest = 0;
				$sTech = 0;
				$rTech = 0;
				$jun=0;
				//while not rs.EOF 
				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'><b>".$rs["grade_name"]."</b></td></tr>";
						echo "<tr><td colspan='4'><b>".$rs["teacher_name"]."</b></td></tr>";
					}
					//end if
					$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 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;
					//rs.moveNext
				//wend
				}
				echo "<tr><td colspan='4'><hr /></td></tr>";
				echo "<tr><td colspan='2' align='center'>";

				//echo "<a href='#' onclick='openLunhwindow('classPlistReport.asp?tchr=".$teacher."&grd=".$grade ."&schl=".$school."&da=".$dayAdd."');'>View Print Report</a></td>";

				echo "<a href='#' onClick='javascript:window.open(\"classPlistReport.php?tchr=".$teacher."&grd=".$grade ."&schl=".$school."&da=".$dayAdd."\",\"Print Report\",\"menubar=1,resizable=1,width=800,height=800,scrollbars=1\");' >View Print Report</a>&nbsp;&nbsp;</td>";

				echo "<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>";
			}
			
			//rs.Close
			//set rs=nothing ?>
			</table></td></tr>
</table>
<?php
include("footer.php");
?>