<?php 
@session_start();
include("include/header.php");
include("admin/globalfunctions.php");

$dtitle = "Mississauga Area School Lunch Catering Service – Catering to Kids lunches"; 
$dtags = "catering for schools, school lunch lady, school lunches delivered, school hot lunch, elementary school lunch, school lunches, hot lunch program, lunch program, public school lunches, lunch programs, school meal program, school food programs, school food program,kids";
$ddesc = "Lunch Pails provides delicious, nutritious, and reliable hot or cold lunches for school children, delivered right to the school - servicing Mississauga, Brampton, West Toronto, Milton, Oakville, Georgetown and Caledon.";

if(trim($_SESSION['pName'])== "" || trim($_SESSION['pID'])=="")
{
	echo "<script>";
	echo "location.replace('parentLogin.php');";
	echo "</script>";

}



?>
<script language="JavaScript" type="text/javascript">
<!--
function getsupport ( selectedtype )
{
  document.frm.sid.value = selectedtype ;
  document.frm.submit() ;
}
-->
</script>
<tr>
	<td width="900" class="fs15 blue">
	<?php
		if($_GET['ord']!="")
			$nid=$_GET['ord'];
		else
			$nid=$_POST['pord'];
		
	?>
	 <form action="parentAccount.php?ord=nord" method="POST" name="frm">
		 <table border="0" cellpadding="0" cellspacing="0" width="100%" align="center">
			<tr>
				<input type='hidden' name='pord' value='<?=$nid?>'/><input type='hidden' name='sid' value="<?=$_POST['sid']?>" />
				<td width="25"><img src="images/space.gif" width="25" height="1" alt=""></td>
				<td width="850">
      				<table border="0" cellpadding="0" cellspacing="0" width="100%">
            			<tr>
							<td colspan="2">&nbsp;</td>
						</tr>
						<tr>
							<td width="50%" class="homet black"><div id="paAccount">Welcome <b><?=$_SESSION['pName']?></b></div></td>
							<td width="50%" align="right" class="fs12 onlines">
							<?php
							echo "<a class='deco' href='edit_parent.php'>EDIT ACCOUNT</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
							echo "<a class='deco' href='add_newstudent.php'>ADD STUDENT</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
							?>
							<a class="deco" href="parentLogin.php?action=LOGOUT" title="Logout">LOGOUT</a>
							</td>
						</tr>
		                <tr>
							<td colspan="2"><hr/></td>
						</tr>
						<tr>
							<td colspan="2" class="fs10">&nbsp;</td>
						</tr>
						<tr>
							<td class="fs12">Student(s):</td>
							<!-- <td class='fs12 onlines' align='right' style='padding-right:25px'><a class='deco' href='parentAccount.php?ord=nord'>NEW ORDER</a></td> -->
						</tr>
						<tr>
							<td colspan="2"><hr/></td>
						</tr>
						<?php
						$strSql = mysql_query("select c.school_name,a.student_id,a.student_fname,a.student_lname,b.teacher_name,d.grade_name,c.school_id,d.grade_id from tr_student a left join tr_teachers b on b.teacher_id=a.teacher left join tr_schools c on c.school_id=a.school_id left join ma_grades d on d.grade_id=a.grade where a.status=1 and a.parent_id='".$_SESSION['pID']."'");
						$rsc=@mysql_num_rows($strSql);		
						if($rsc>0)
						{
							$x=0;
							while($rs=@mysql_fetch_array($strSql))
							{
								$x=$x+1; 
								?>
								<tr><td width="50%" class="fs12 black"><?=$x?>.) <?=trim($rs['student_fname'])." ". trim($rs['student_lname'])?></b></td><td width="50%" align="right" class="fs12 onlines">

								<?php

								$stid=$rs['student_id'];

								echo "<a class='deco' href='javascript:getsupport($stid);'>NEW ORDER</a>&nbsp;&nbsp;&nbsp;&nbsp;";

								//echo "<a class='deco' href='parentAccount.php?ord=nord&pid=".$stid."'>NEW ORDER&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>";

								echo "<a class='deco' href='edit_student.php?id=".$stid."'>EDIT STUDENT</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

								echo "<a class='deco' href='parentAccount.php?typ=v&id=".$stid."'>VIEW ORDERS</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

								echo "<a class='deco' href='parentAccount.php?typ=pd&id=".$stid."'>PAYMENT PENDING ORDERS</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

								

								
								?>
								</td></tr>
								<tr><td colspan="2" class="fs12">Teacher Name: <?=trim($rs['teacher_name'])?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?=trim($rs['grade_name'])?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?=trim($rs['school_name'])?></td></tr>
								<tr><td colspan="2"><hr/></td></tr>
							<?php
							}
						}
						

						// neworder coding start
		
						if($_GET['ord']=='nord')
						{
					
								$errmsg = "";
								$sy=0;
								$oID=0;
								$byear = date('Y');
								$bmonth = date('m');
								$bdmonth = 1;
								$bday = date('d');
								$bdday = 1;
								$toDate = $byear + 1;
								$frDate = $toDate-20;


								$snakSel1=0;$snakSel2=0;$snakSel3=0;$snakSel4=0;$snakSel5=0;$snakSel6=0;$snakSel7=0;$snakSel8=0;$snakSel9=0;$snakSel10=0;$snakSel11=0;$snakSel12=0;$snakSel13=0;$snakSel14=0;$snakSel15=0;$snakSel16=0;$snakSel17=0;$snakSel18=0;$snakSel19=0;$snakSel20=0;$snakSel21=0;$snakSel22=0;$snakSel23=0;$snakSel24=0;$snakSel25=0;

								$drinkSel1=0;$drinkSel2=0;$drinkSel3=0;$drinkSel4=0;$drinkSel5=0;$drinkSel6=0;$drinkSel7=0;$drinkSel8=0;$drinkSel9=0;$drinkSel10=0;$drinkSel11=0;$drinkSel12=0;$drinkSel13=0;$drinkSel14=0;$drinkSel15=0;$drinkSel16=0;$drinkSel17=0;$drinkSel18=0;$drinkSel19=0;$drinkSel20=0;$drinkSel21=0;$drinkSel22=0;$drinkSel23=0;$drinkSel24=0;$drinkSel25=0;

								$menuSel1=0;$menuSel2=0;$menuSel3=0;$menuSel4=0;$menuSel5=0;$menuSel6=0;$menuSel7=0;$menuSel8=0;$menuSel9=0;$menuSel10=0;$menuSel11=0;$menuSel12=0;$menuSel13=0;$menuSel14=0;$menuSel15=0;$menuSel16=0;$menuSel17=0;$menuSel18=0;$menuSel19=0;$menuSel20=0;$menuSel21=0;$menuSel22=0;$menuSel23=0;$menuSel24=0;$menuSel25=0;

								$itemSel1=0;$itemSel2=0;$itemSel3=0;$itemSel4=0;$itemSel5=0;$itemSel6=0;$itemSel7=0;$itemSel8=0;$itemSel9=0;$itemSel10=0;$itemSel11=0;$itemSel12=0;$itemSel13=0;$itemSel14=0;$itemSel15=0;$itemSel16=0;$itemSel17=0;$itemSel18=0;$itemSel19=0;$itemSel20=0;$itemSel21=0;$itemSel22=0;$itemSel23=0;$itemSel24=0;$itemSel25=0;
								$byear1=$byear;$byear2=$byear;$byear3=$byear;$byear4=$byear;$byear5=$byear;$byear6=$byear;$byear7=$byear;$byear8=$byear;$byear9=$byear;$byear1byear=$byear;$byear11=$byear;$byear12=$byear;$byear13=$byear;$byear14=$byear;$byear15=$byear;$byear16=$byear;$byear17=$byear;$byear18=$byear;$byear19=$byear;$byear2byear=$byear;$byear21=$byear;$byear22=$byear;$byear23=$byear;$byear24=$byear;$byear25=$byear;

								$bmonth1=$bmonth;$bmonth2=$bmonth;$bmonth3=$bmonth;$bmonth4=$bmonth;$bmonth5=$bmonth;$bmonth6=$bmonth;$bmonth7=$bmonth;$bmonth8=$bmonth;$bmonth9=$bmonth;$bmonth1bmonth=$bmonth;$bmonth11=$bmonth;$bmonth12=$bmonth;$bmonth13=$bmonth;$bmonth14=$bmonth;$bmonth15=$bmonth;$bmonth16=$bmonth;$bmonth17=$bmonth;$bmonth18=$bmonth;$bmonth19=$bmonth;$bmonth2bmonth=$bmonth;$bmonth21=$bmonth;$bmonth22=$bmonth;$bmonth23=$bmonth;$bmonth24=$bmonth;$bmonth25=$bmonth;

								$bday1=$bday;$bday2=$bday;$bday3=$bday;$bday4=$bday;$bday5=$bday;$bday6=$bday;$bday7=$bday;$bday8=$bday;$bday9=$bday;$bday1bday=$bday;$bday11=$bday;$bday12=$bday;$bday13=$bday;$bday14=$bday;$bday15=$bday;$bday16=$bday;$bday17=$bday;$bday18=$bday;$bday19=$bday;$bday2bday=$bday;$bday21=$bday;$bday22=$bday;$bday23=$bday;$bday24=$bday;$bday25=$bday;

								$addMform=1;
								$school=0;
								$tchrID=0;
								$grade=0;
								$student=0;
								$yearRef=0;
								$ckNewStud = "";
								$ckNewStudVal=0;
								$ckNewStudStat="hidden";

								if(trim($_POST['addMform'])!="")
								$addMform=$_POST['addMform'];

								$action = trim($_POST['action']);



								if(strtolower($action)== "add more order")
								{
									if($addMform<25)
									{ 
										$addMform=$addMform + 1;
									}
								}


								//-----------------------
								

								$_SESSION['sid']=$_POST['sid'];


								if($_SESSION['xsid']=="")
								{
									$_SESSION['xsid']=$_SESSION['sid'];
								}
								else
								{
									$xchkid=explode("_",$_SESSION['xsid']);
									$icc=0;
									for($ic=0;$ic<count($xchkid);$ic++)
									{
										if($xchkid[$ic]==$_SESSION['sid'])
											$icc=1;
									}
									if($icc=='0')
										$_SESSION['xsid'] .="_".$_SESSION['sid'];
								}

								$xpldid=explode("_",$_SESSION['xsid']);
								$i=1;
								$xstrcont=0;

								for($jc=0;$jc<count($xpldid);$jc++)
								{

								//	$selp=@mysql_query("select * from tr_student where status='1' and student_id='".$_GET['pid']."'");
									$selp=@mysql_query("select * from tr_student where status='1' and student_id='".$xpldid[$jc]."'");
									$rowp=@mysql_fetch_array($selp);

								
									$strSqldt =@mysql_query("select orderDate from tr_school_dates where school_id = '".$rowp['school_id']."' and  orderDate>'".date('Y-m-d')."'order by orderDate");
									$strcont=@mysql_num_rows($strSqldt);

									$snkdrk=@mysql_query("select * from tr_snak_drink where status='1' and	school_id='".$rowp['school_id']."'");
									$ressnkdrk=@mysql_fetch_array($snkdrk);

									$snk[$jc]=$ressnkdrk['snacks'];
									$dnk[$jc]=$ressnkdrk['drinks'];
									$stid[$jc]=$xpldid[$jc];
									
									$xstrcont +=$strcont;
									
									while($rowdt=@mysql_fetch_array($strSqldt))
									{
										$newodt[$i]=$rowdt[0];
										$newcnt[$jc]=$i;
										
										$i++;
																
									}
								}

// -----------------------------------------------------------------------------------------------------

								if(strtoupper($action) == "CHECK OUT")
								{
									$nowDate =date("Y-m-d");
									

									for($j=1;$j<$addMform;$j++)
									{
										$xrDate="orDate".$j;
										$xmenusel="menuSel".$j;
										$orDate = $_POST[$xrDate];

									//	if($_POST[$xmenusel]==0)
									//	  $errmsg=$errmsg ."Order # " . $j . " Date:" .  date('d-m-Y',strtotime($orDate)) . " Item Order is Required!<br/>";


										if(strtotime($orDate) <= strtotime($nowDate))
											$errmsg=$errmsg ."Order # " .$j." Date:" .  date('d-m-Y',strtotime($orDate)) . " is lesser or is the current Date!<br/>";
										$orDate = "";
									}

									$pTypeVal=0;
									
								
								}
								if(strtoupper($action) == "CHECK OUT" && trim($errmsg) == "")
								{
									
										$nowDate = $nowDate . " 00:01:01";
										
										$sid[0]=0;
										$jj=0;
										$amount=0;
										for($j=1;$j<$addMform;$j++)
										{											

											$xstudntid="studnt".$j;
											$xrDate="orDate".$j;
											$xmenuSel="menuSel".$j;
											$xitemSel="itemSel".$j;
											$xsnakSel="snakSel".$j;
											$xdrinkSel="drinkSel".$j;

										 //$orDate = $_POST[$xrDate];
											$studentid=$_POST[$xstudntid];
											$menuSels=$_POST[$xmenuSel];
											$itemSels=$_POST[$xitemSel];
											$snakSels=$_POST[$xsnakSel];
											$drinkSels=$_POST[$xdrinkSel];
											$orDate = $_POST[$xrDate] . " 00:01:01";											
											
											if($studentid!=0)
											{
												
												//$sid[$j]=$studentid;
												$orderID=0;
												$flag=0;

												for($ii=0;$ii<=count($sid);$ii++)
												{

													if($sid[$ii]==$studentid)
													{		
														$flag=1;
														$mm=$ii;
														break;
													}
												}
												if($flag==0)
												{
													$amount=0;
													
													$strSql = "insert into tr_orders(student_id,order_date,ptype,check_no,total)";
													$strSql = $strSql . " values('".$studentid."','".$nowDate."','".$pTypeVal."','".$checkNum."','".$amount."')";
									
													mysql_query($strSql);

													$orderID=@mysql_insert_id();
													
													$sid[$jj]=$studentid;
													$rid[$jj]=$orderID;
													

													//$xstudid=$studentid;
													$xordid=$orderID;
													$jj++;
												}
												else
												{
													//$xstudid=$sid[$mm];
													$xordid=$rid[$mm];

												}
												
											//echo "+".$menuSels."+";
												if($menuSels!="0")
												{
													$strSql = "insert into tr_orderdetails(order_id,service_date,item_ordered,item_type,item_snack,item_drink)";
													$strSql = $strSql . " values('".$xordid."','".$orDate."','".$menuSels."','".$itemSels."','".$snakSels."','".$drinkSels."')";

												//	echo $strSql."<br />";

													@mysql_query($strSql);

													
													$itmc=@mysql_query("select pprice from ma_itemtype where status='1' and itemtype_id='".$itemSels."'");
													$xitmc=@mysql_fetch_array($itmc);

													$amount +=$xitmc[0];

													//echo "amt:".$amount."<br />";

													mysql_query("update tr_orders set total='".$amount."' where order_id='".$xordid."'");

												
													$txxamt +=$amount;



												}

												

											}
											
														

										}
											$errmsg = "You have successfully created your Order... Please wait this page is redirecting to Paypal.<br/>";

											
										/*	echo "<script>";
											echo "window.open(\"paypalpay.php?Oid=".base64_encode($orderID)."&b=".base64_encode($txxamt)."\",\"PAYPAL \",\"menubar=1,resizable=1,width=690,height=600,scrollbars=1\")";
											echo "</script>";
										*/
											if(strtoupper(substr(trim($errmsg),0,8))== "YOU HAVE")
											{
											?>

											<meta http-equiv="Refresh" target="_blank" content="3;url=paypalpay.php?sessid=<?=base64_encode($xordid)?>&b=<?=base64_encode($txxamt)?>" ><br/><br/><br/><br/><br/>
											<?php
											}
								
									} 

// -----------------------------------------------------------------------------
							?>
							<div id="stAdAccount" style="background-color:#bcbbbb;" class="sAdAccount">
							<table border="0" cellpadding="0" cellspacing="0" width="100%" align="center" style="font-size: 12px;">
							<tr>
								<td align="center" style="font-size: 18px;"><u><b>Student Orders</b></u></td>
							</tr>
							
							<tr>
								<td>
									

										<table width="100%" cellpadding="1" cellspacing="1" border="0">
											<tr>
												<td height="5" width="30%"></td>
												<td height="5" width="70%"></td>
											</tr>
											<tr>
												<td colspan="4" class="errmsg" align='center'><hr/><?=$errmsg?></td>
											</tr>
												<tr>
													<td colspan="2">
														  <table border="0" width="100%" cellpadding="1" cellspacing="1" style="font-size:12px;">
															
															<?php
															//for($j=1;$j<=$addMform;$j++)
																$pp=0;
																$sndnk=0;
															for($j=1;$j<=$xstrcont;$j++)
															{
																$nordt=$newodt[$j];
																$jj=$j-1;

																if($pp==0 && $j==1)
																{
																	$stnam=mysql_query("select * from tr_student where student_id='".$xpldid[$pp]."'");
																	$resstnam=@mysql_fetch_array($stnam);
																	
																	echo "<tr><td colspan='5' height='10'>&nbsp;</td></tr>";
																	echo "<tr><td colspan='5' align='center' height='20px'>".$resstnam['student_fname']."  ".$resstnam['student_lname']."</td><tr>";
																	$sstdid=$xpldid[$pp];
																
																?>
																	<tr>
																		<td colspan="5" class="errmsg" align='center'><hr/></td>
																	</tr>
																	<tr align="center">
																	<td width="20%" nowrap>&nbsp;&nbsp;&nbsp;<b>Day of Service</b></td>
																	<td width="25%" nowrap><b>Item Ordered</b></td>
																	<td width="25%" nowrap><b>Item Type</b></td>
																	<!-- <td width="25%" nowrap><b>Snack</b></td>
																	<td width="25%" nowrap><b>Drink</b></td> -->
																	<?php
																		if($snk[$sndnk]=='y')
																	{
																		?>
																			<td width="25%" nowrap><b>Snack</b></td>
																	<?php
																	}
																		if($dnk[$sndnk]=='y')
																	{
																	?>
																	<td width="25%" nowrap><b>Drink</b></td>
																	<?php
																	}
																	?>
																	</tr>

																	
																<?php

																//	$sndnk++;

																}
																else if($newcnt[$pp]==$jj && $j >1)
																{
																	$ppp=$pp+1;
																	$sndnk++;
																	$stnam=mysql_query("select * from tr_student where student_id='".$xpldid[$ppp]."'");
																	$resstnam=@mysql_fetch_array($stnam);
																	$pp++;

																	echo "<tr><td colspan='5' height='10'>&nbsp;</td></tr>";
																	echo "<tr><td colspan='5' align='center' height='20px'>".$resstnam['student_fname']."  ".$resstnam['student_lname']."</td><tr>";

																	$sstdid=$xpldid[$ppp];
																	?>

																	<tr>
																		<td colspan="5" class="errmsg" align='center'><hr/></td>
																	</tr>

																	<tr align="center">
																	<td width="20%" nowrap>&nbsp;&nbsp;&nbsp;<b>Day of Service</b></td>
																	<td width="25%" nowrap><b>Item Ordered</b></td>
																	<td width="25%" nowrap><b>Item Type</b></td>
																	<?php
																		if($snk[$sndnk]=='y')
																	{
																		?>
																			<td width="25%" nowrap><b>Snack</b></td>
																	<?php
																	}
																		if($dnk[$sndnk]=='y')
																	{
																	?>
																	<td width="25%" nowrap><b>Drink</b></td>
																	<?php
																	}
																	?>
																	</tr>

																	
																<?php
																	
																}

															?>
																 <tr align="center">
																	 <td><?=$j?>.&nbsp;&nbsp;&nbsp;<?=$nordt?>
																	 <input type="hidden" name="orDate<?=$j?>" value="<?=$nordt?>" />
																	<input type="hidden" name="studnt<?=$j?>" value="<?=$sstdid?>" />
																	
																	</td>
																	<td>
																		<select name="menuSel<?=$j?>" class="formSelect">
																		<?php
																		
																		$strSqlm = mysql_query("select menu_id,menu_code,menu_name from tr_menu where status=1 and menu_type=1 order by menu_name");
																		$rscm=@mysql_num_rows($strSqlm);                            
																		echo "<option value='0'>--No Lunch this day--</option>";
														
																		if($rscm>0)
																		{							
																			while($rsm=@mysql_fetch_array($strSqlm))
																			{
																				$menuSela='menuSel'.$j;
																			  if($_POST[$menuSela]==$rsm['menu_id'])
																				 echo "<option value='".$rsm['menu_id']."' selected>".$rsm['menu_name']." (".$rsm['menu_code'].")</option>";
																			  else
																				 echo "<option value='".$rsm['menu_id']."' >".$rsm['menu_name']." (".$rsm['menu_code'].")</option>";
																			}

																		}

																	   ?>
																</select></td>
																<td><select name="itemSel<?=$j?>" class="formSelect">
																	<?php
																	
																	$strSqlmt=mysql_query("select itemtype_id,item_type from ma_itemtype where status=1 order by orderby");
																	$rscmt=@mysql_num_rows($strSqlmt);                            
																	echo "<option value='0'>--Select--</option>";
													
																	if($rscmt>0)
																	{							
																		while($rsmt=@mysql_fetch_array($strSqlmt))
																		{
																			$itemSela='itemSel'.$j;
																		  if($_POST[$itemSela]==$rsmt['itemtype_id'])
																			 echo "<option value='".$rsmt['itemtype_id']."' selected>".$rsmt['item_type']."</option>";
																		  else
																			 echo "<option value='".$rsmt['itemtype_id']."' >".$rsmt['item_type']."</option>";
																		}

																	}
																	?>
															</select></td>
														<!-- </tr> -->
														<?php
														/*$sel=@mysql_query("select * from tr_snak_drink where status='1' and school_id='".$rowid[0]."'");
														$rowcnt=@mysql_num_rows($sel);
														$row=@mysql_fetch_array($sel);

														if($rowcnt>0)
														{*/
														?>
								
														 <!--  <tr align="center">  -->
															<!-- <td align="right" nowrap><b>Snack &amp; Drink:&nbsp;</b></td> -->
															<?php
															if($snk[$sndnk]=='y')
															{
															?>
															<td><select name="snakSel<?=$j?>" class="formSelect">
																<?php
																$strSqls = mysql_query("select menu_id,menu_code,menu_name from tr_menu where status=1 and menu_type=2 order by menu_name");
																$rscs=@mysql_num_rows($strSqls);                            
																echo "<option value='0'>--Any Snack--</option>";
												
																if($rscs>0)
																{							
																	while($rssd=@mysql_fetch_array($strSqls))
																	{
																		$snakSela='snakSel'.$j;
																	  if($_POST[$snakSela]==$rssd['menu_id'])
																		 echo "<option value='".$rssd['menu_id']."' selected>".$rssd['menu_name']." (".$rssd['menu_code'].")</option>";
																	  else
																		 echo "<option value='".$rssd['menu_id']."' >".$rssd['menu_name']." (".$rssd['menu_code'].")</option>";
																	}

																}
																?></select></td>
																<?php
																}
																if($dnk[$sndnk]=='y')
																{
																?>
																<td><select name="drinkSel<?=$j?>" class="formSelect">
																<?php
																$strSqld = mysql_query("select menu_id,menu_code,menu_name from tr_menu where status=1 and menu_type=3 order by menu_name");
																$rscd=@mysql_num_rows($strSqld);                            
																echo "<option value='0'>--Any Drink--</option>";
												
																if($rscd>0)
																{							
																	while($rssd=@mysql_fetch_array($strSqld))
																	{
																	  $drinkSela='drinkSel'.$j;
																	  if($_POST[$drinkSela]==$rssd['menu_id'])
																		 echo "<option value='".$rssd['menu_id']."' selected>".$rssd['menu_name']." (".$rssd['menu_code'].")</option>";
																	  else
																		 echo "<option value='".$rssd['menu_id']."' >".$rssd['menu_name']." (".$rssd['menu_code'].")</option>";
																	}

																}

																
																?></select></td>
															<!--  </tr>  -->
													<?php
																}
														//}
													} // for close
													?>
										
												<input type="hidden" name="addMform" value="<?=$j?>" />
												
											<tr align="right">
												<td></td>
												<td><!-- <input type="submit" name="action" value="add more order" /> --></td>
												<td align="right" colspan="3"><input type="submit" name="action" value="Check Out" /></td>
											</tr>
										</table>
									   </tr>
									</td>
								  </form>
							 </td>
						  </tr>
				 </table>
				 </div>
				<?php
				}//neworder close
				if($_GET['typ']=='v')
				{
					
					if($_GET['id']!="")
						$studentID=$_GET['id'];

					$strSqls =@mysql_query("select c.school_name,a.student_id,a.student_fname,a.student_lname,b.teacher_name,d.grade_name,c.school_id,d.grade_id from tr_student a left join tr_teachers b on b.teacher_id=a.teacher left join tr_schools c on c.school_id=a.school_id left join ma_grades d on d.grade_id=a.grade where a.status=1 and a.student_id='".$studentID."'");
					$rowrec=@mysql_fetch_array($strSqls);
				?>
					<tr>
						<td align='center' colspan='2'>
							<table width="550" cellpadding="1" cellspacing="3" border="0" class='fs12'>
								<tr>
									<td><B>Student Name:</B></td><td><?=$rowrec['student_fname']." ".$rowrec['student_lname']?></td>
									<td><B>Grade:</B></td><td><?=trim($rowrec['grade_name'])?></td>
									
								</tr>
								<tr>
									<td><B>Teacher Name:</B></td><td><?=trim($rowrec['teacher_name'])?></td>
									<td><B>School Name:</B></td><td><?=trim($rowrec['school_name'])?></td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<td align='center' colspan='2'>
								<table width="550" cellpadding="1" cellspacing="3" border="0" class='fs12'>
									<tr bgcolor="#C6E7F9" align='center'>
										<!-- <td><b>Order No.</b></td> -->
										<td><b>Date Ordered</b></td>
										<td><b>Lunch Ordered</b></td>
										<td><b>Description</b></td>
										<td><b>Payment</b></td>
										<!-- <td><b>Paypal<b></td> -->
									</tr>
									
									<?php
									$ddate=date('Y-m-d');
									$sdate=$ddate." 00:00:00";

									$strSql2 =@mysql_query("SELECT a.detail_id,a.service_date,a.item_snack,a.item_drink,c.menu_name,d.item_type,b.paid_status,b.order_id FROM tr_orderdetails a left join tr_orders b on b.order_id=a.order_id left join tr_menu c on c.menu_id=a.item_ordered left join ma_itemtype d on d.itemtype_id=a.item_type where b.student_id='".$studentID."' and a.service_date>'".$sdate."' and b.paid_status='1' order by service_date");
									

									$cntr2=@mysql_num_rows($strSql2);
									if($cntr2>0)
									{
										$col="#F2FAFD";

										while($rs1=@mysql_fetch_array($strSql2))
										{
												
												if($col=="#F2FAFD")
													   $col="#EBF5FC";													   
													else
													  $col="#F2FAFD";

																						
											$sDate=	date('F',strtotime($rs1["service_date"]))." ".date('d',strtotime($rs1["service_date"]))." ".date('Y',strtotime($rs1["service_date"]));

										?>
											<tr valign="top" bgcolor="<?=$col?>">
											
											
												<td nowrap>&nbsp;<?=$sDate?></td>
												<td>&nbsp;&nbsp;<?=$rs1["menu_name"]?><br/>&nbsp;&nbsp;<i><u>Snack:</u> <?=getSD($rs1["item_snack"])?></i><br/>&nbsp;&nbsp;<i><u>Drink:</u> <?=getSD($rs1["item_drink"])?></i></td>
												<td>&nbsp;&nbsp;<?=$rs1["item_type"]?></td>
												<td>
												<?php
												if($rs1['paid_status']=='1')
												 echo "&nbsp;&nbsp;Done";
												else
												 echo "&nbsp;&nbsp;Not Done&nbsp;&nbsp;";
												?>
												</td>
												
												</tr>
												
											<?php
										}
									}
									else
									{
										echo "<tr><td colspan='4'><hr /></td></tr>";
										echo "<tr><td colspan='4' align='center'>There are no orders for this Student</td></tr>";
										echo "<tr><td colspan='4'><hr /></td></tr>"; 
									}
														
									?>
								</table>
					</td></tr>
				<?php
				}
				
				if($_GET['typ']=='pd')  // payment pending orders
				{
					
					if($_GET['id']!="")
						$studentID=$_GET['id'];

					$strSqls =@mysql_query("select c.school_name,a.student_id,a.student_fname,a.student_lname,b.teacher_name,d.grade_name,c.school_id,d.grade_id from tr_student a left join tr_teachers b on b.teacher_id=a.teacher left join tr_schools c on c.school_id=a.school_id left join ma_grades d on d.grade_id=a.grade where a.status=1 and a.student_id='".$studentID."'");
					$rowrec=@mysql_fetch_array($strSqls);
				?>
				    <tr>
					  <td colspan='4' class='fs12' style="font-color:#000099;" align="center">PAYMENT PENDING ORDERS</td>
					</tr>
					<tr>
						<td align='center' colspan='2'>
							<table width="550" cellpadding="1" cellspacing="3" border="0" class='fs12'>
								<tr>
									<td><B>Student Name:</B></td><td><?=$rowrec['student_fname']." ".$rowrec['student_lname']?></td>
									<td><B>Grade:</B></td><td><?=trim($rowrec['grade_name'])?></td>
									
								</tr>
								<tr>
									<td><B>Teacher Name:</B></td><td><?=trim($rowrec['teacher_name'])?></td>
									<td><B>School Name:</B></td><td><?=trim($rowrec['school_name'])?></td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<td align='center' colspan='2'>
								<table width="550" cellpadding="1" cellspacing="1" border="0" class='fs12'>
									<tr bgcolor="#C6E7F9" align='center'>
										
										<td><b>Date Ordered</b></td>
										<td><b>Lunch Ordered</b></td>
										<td><b>Description</b></td>
										<td><b>Order No.</b></td>
										<td><b>Payment</b></td>
										
									</tr>
									
									<?php
									$ddate=date('Y-m-d');
									$sdate=$ddate." 00:00:00";

									$strSql2 =@mysql_query("SELECT a.detail_id,a.service_date,a.item_snack,a.item_drink,c.menu_name,d.item_type,b.paid_status,b.order_id,b.total FROM tr_orderdetails a left join tr_orders b on b.order_id=a.order_id left join tr_menu c on c.menu_id=a.item_ordered left join ma_itemtype d on d.itemtype_id=a.item_type where b.student_id='".$studentID."' and a.service_date>'".$sdate."' and b.paid_status='0' order by service_date");
									

									$cntr2=@mysql_num_rows($strSql2);
									if($cntr2>0)
									{
										$col="#F2FAFD";

										while($rs1=@mysql_fetch_array($strSql2))
										{
												
												if($col=="#F2FAFD")
													   $col="#EBF5FC";													   
													else
													  $col="#F2FAFD";

																						
											$sDate=	date('F',strtotime($rs1["service_date"]))." ".date('d',strtotime($rs1["service_date"]))." ".date('Y',strtotime($rs1["service_date"]));

										?>
											<tr valign="top" bgcolor="<?=$col?>">
												<td nowrap>&nbsp;<?=$sDate?></td>
												<td>&nbsp;&nbsp;<?=$rs1["menu_name"]?><br/>&nbsp;&nbsp;<i><u>Snack:</u> <?=getSD($rs1["item_snack"])?></i><br/>&nbsp;&nbsp;<i><u>Drink:</u> <?=getSD($rs1["item_drink"])?></i></td>
												<td>&nbsp;&nbsp;<?=$rs1["item_type"]?></td>
												<td align="center"><?=$rs1['order_id']?></td>
												<?php
												if($xorid!=$rs1['order_id'])
												{
													$xorid=$rs1['order_id'];
													 echo "<td align='center'><a  href='paypalpay.php?sessid=".base64_encode($xorid)."&b=".base64_encode($rs1['total'])."'>PAY LINK</a></td>";
												}
												else
													echo '<td>&nbsp;</td>';
												?>
										   </tr>
												
											<?php
										}
									}
									else
									{
										echo "<tr><td colspan='4'><hr /></td></tr>";
										echo "<tr><td colspan='4' align='center'>There are no orders for this Student</td></tr>";
										echo "<tr><td colspan='4'><hr /></td></tr>"; 
									}
														
									?>
								</table>
					</td></tr>
				<?php
				}

			?>
             <tr><td colspan="2" height="100"></td></tr>
            </table></td>
		<td width="25"><img src="images/space.gif" width="25" height="1" alt=""></td></tr>
		<tr>
		 <td colspan="2" height="40" style="font-family:verdana;font-size:12px;color:#FF3300;font-weight:bold;line-height:17px;" align='center'>NOTE:&nbsp;&nbsp;Regular Meals include entrée only.<div style='padding-left:140px;'>Complete Meals include entrée, drink and snack.</div><div style='padding-left:210px;'>Extra Large Meals include a large entrée, drink and snack.</div></td>
		</tr>
		 <tr><td colspan="2" height="15"></td></tr>
 	</table></td></tr>
	<?php
	$school=0;
	$grade=0;
	$tchrID=0;
	$paName="";
	$paEmail="";
	$paPassword="";
	$paPhone="";
	$paCell="";

	$strSql2 = mysql_query("SELECT name,email,password,contact_no,cell_no FROM tr_parent where parent_id='".$_SESSION['pID']."'");
	$rsc2=@mysql_num_rows($strSql2);		
	if($rsc2>0)
	{
		$rs2=@mysql_fetch_array($strSql2);

		$paName=trim($rs2['name']);
		$paEmail=trim($rs2['email']);
		$paPassword=trim($rs2['password']);
		$paPhone=trim($rs2['contact_no']);
		$paCell=trim($rs2['cell_no']);
	}
	

	$strSql3 = mysql_query("SELECT syID FROM ma_schoolyear where sStatus=1 order by syID desc limit 1");
	$rsc3=@mysql_num_rows($strSql3);		
	if($rsc3>0)
	{
		$rsc3=@mysql_fetch_array($strSql3);
		 $yearRef=$rsc3['syID'];
	}

include("include/footer.php");
?>
