<?php
session_start();
include("dbconnect.php");
include("globalfunctions.php");

if(trim($_SESSION['accountName'])=="" &&  trim($_SESSION['accountID'])=="" && trim($_SESSION['pgid'])!="i3g3e3nious7")
{
	echo '<script>';
	echo 'location.replace("index.php");';
	echo '</script>';
}
else
{

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

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

$myPageSize = 30;
if($_GET["currPage"] == "")
	$currPage = 1;
else
	$currPage = $_GET["currPage"];

//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>
	<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="800" align="center">
	<tr><td class="fs10 black" colspan="3">
		<table width="100%" cellpadding="1" cellspacing="1" border="0">
			<tr class="fs10 blue"><td><a href='javascript:void(0);' onclick="window.open('dwnldStdntOrdr.php?da=<?=$dayAdd?>', '_blank', 'width=800,height=800,scrollbars=no,status=yes,resizable=yes,screenx=0,screeny=0');">download data</a></td><td align="center"><b>Order Date: <?=$sDate?></b></td><td><a href="javascript:window.print()" title="print">print</a></td></tr>
			<tr valign="top"><td width="34%" height="10"></td><td width="35%"></td><td width="31%" height="10"></td></tr>
			<?php
			$ordate1=$OrderDate." 00:01:01";

			$strSql1 =@mysql_query("select count(*) totalproducts from tr_orderdetails  a join tr_orders d on d.order_id=a.order_id where service_date ='".$ordate1."' and d.paid_status='1'");
			$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);
			}
			if($totalProducts%$myPageSize > 0 && $totalProducts % $myPageSize <= 5)
			{
				$myPageCount = $myPageCount + 1;
			}
		
		$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."' and d.paid_status='1' 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 valign='top'>";
			while($rs=@mysql_fetch_array($strSql))
				{
					$linecount = $linecount + 1;
					if(($linecount >= ($currPage * $myPageSize) - $myPageSize + 1) && ($linecount <= ($currPage * $myPageSize)))
					{
						if($tCnt==3)
						{
							$tCnt = 0;
							echo "</tr><tr><td colspan='3' height='25'></td></tr><tr>";
						}
						$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>";

						$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."<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;
					}
			}
			echo "</tr>";

			if($myPageCount > 1)
			{
				if($currPage> 1 )
				{
					$acurrpage=$currPage - 1;
					$pagenavbar = $pagenavbar."<a href='studentsLabelReport.php?da=".$dayAdd."&currPage=".$acurrpage."'>previous</a>&nbsp;&nbsp;&nbsp;";
				}

				for($linecount = 1;$linecount<=$myPageCount;$linecount++)
				{
					if($linecount = $currPage)
						$pagenavbar = $pagenavbar.$linecount."&nbsp;&nbsp;&nbsp;";
					else
						$pagenavbar = $pagenavbar."<a href='studentsLabelReport.php?da=".$dayAdd."&currPage=".$linecount."'>".$linecount."</a>&nbsp;&nbsp;&nbsp;";
					
					if($linecount = 10 || $linecount = 20 || $linecount = 30 || $linecount = 40)
						$pagenavbar = $pagenavbar."<br/>";
				}
				if($currPage< $myPageCount)
				{
					$acurrpage=$currPage+ 1;
					$pagenavbar = $pagenavbar."<a href='studentsLabelReport.php?da=".$dayAdd."&currPage=".$acurrpage."'>next</a>&nbsp;&nbsp;&nbsp;";
				}
			}
			else
			{
				$pagenavbar = "";
				$linecount = 0;
			}
			if(trim($pagenavbar)!="")
				echo "<tr><td colspan='3' align='center'><br/><br/>".$pagenavbar."</td></tr>";
		}
		else
		{
			echo "<tr><td colspan='3' align='center' height='100'>There are no orders for this Date!</td></tr>";
		}
		?>
		</table></td></tr>
	<tr><td height="9" colspan="2"></td><td width="8"></td></tr>

</table>
</body>
</html>
<?php
}
?>
