<?php
session_start();
include("header.php");
if(trim($_SESSION['accountName'])=="" &&  trim($_SESSION['accountID'])=="" && trim($_SESSION['pgid'])!="i3g3e3nious7")
{
	echo '<script>';
	echo 'location.replace("index.php");';
	echo '</script>';
}
else
{
?>
<!-- #include file="include\header.inc"-->
<!-- #include file="include\globalfunctions.inc"-->
<!-- #include file="include\ckSess.inc"-->
<script type="text/javascript"> 
function confirmdelete(DestURL) {
	var ok = confirm("Are you sure you want to delete this?");
	if (ok) {location.href = DestURL;}
	return ok;
} 
function geteStudentInfo(){	
	var el;
	var id="eStudentInfo";
	if (document.getElementById){
		el = document.getElementById(id);
	}else if (document.all){
		el = document.all[id];
	}else if (document.layers){
		el = document.layers( id )
	}
	if ( el.style ){
		el.style.visibility = ('visible' == el.style.visibility)? 'hidden':'visible';
	}
}
</script>
<?php 
$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;
	}
}
if(trim($_POST['ckNewStud'])!="")
{
	$ckNewStudVal = 1;
	$ckNewStud = "checked";
	$ckNewStudStat="visible";
}


$studentfName = $_POST['studentfName'];
$studentlName = $_POST['studentlName'];
$guardianName = $_POST['guardianName'];
$emailAdd = $_POST['emailAdd'];
$contactNo = $_POST['contactNo'];
$pType = $_POST['pType'];
$checkNum = $_POST['checkNum'];
$amount = $_POST['amount'];

if(trim($_POST['sy'])!="") $sy=$_POST['sy'];
if(trim($_GET['oID'])!="") $oID=$_GET['oID'];
if(trim($_POST['byear'])!="") $byear = $_POST['byear'];
if(trim($_POST['bdmonth'])!="") $bdmonth = $_POST['bdmonth'];
if(trim($_POST['bdday'])!="") $bdday = $_POST['bdday'];
if(trim($_POST['tchrID'])!="") $tchrID = $_POST['tchrID'];
if(trim($_POST['school'])!="") $school=$_POST['school'];
if(trim($_POST['grade'])!="") $grade=$_POST['grade'];
if(trim($_POST['student'])!="") $student=$_POST['student'];
if($school== 1000)
{
	echo "<script>";
	echo "location.replace('schoolNew.php');";
	echo "</script>";

}

if(strtoupper($action) == "SUBMIT ORDER")
{
	$nowDate =date("Y-m-d");
	$bDate = $byear. "-" . $bdmonth . "-" . $bdday;

	if($school==0) $errmsg = $errmsg."Select School Name.<br/>";
	if($grade==0) $errmsg = $errmsg."Select Grade Name.<br/>";
	if($ckNewStudVal==0)
	{
		if($student==0)
			$errmsg = $errmsg."Select Student Name.<br/>";
	}
	else
	{
		if(trim($studentfName)=="") $errmsg=$errmsg."Student First Name field is empty.<br/>";
		if(trim($studentlName)=="") $errmsg=$errmsg."Student Last Name field is empty.<br/>";
		if(trim($guardianName)=="") $errmsg=$errmsg."Guardian Name field is empty.<br/>";
		if(trim($contactNo)=="") $errmsg=$errmsg."Contact Number field is empty.<br/>";
		if($tchrID == 0) $errmsg=$errmsg."Select Teacher Name.<br/>";
		if(strtotime($bDate) >= strtotime($nowDate))
			$errmsg=$errmsg."Birth Date is greater or is the current Date!.<br/>";
	}

	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(trim($pType)=="")
	{
		$errmsg = $errmsg."Select Payment Type(Cash/Check).<br/>";
	}
	else
	{
		if(trim(strtoupper($pType)) == "CHECK")
		{
			if(trim($checkNum) =="") $errmsg=$errmsg."Check No. field is empty.<br/>";
			if(trim($amount) =="") $errmsg=$errmsg."Order Amount field is empty.<br/>";
			$pTypeVal=1;
		}
	}
}
if(strtoupper($action) == "SUBMIT ORDER" && trim($errmsg) == "")
{
	if($ckNewStudVal==1)
	{
		/*
		'set rs = server.createobject("adodb.recordset")
		'strSql = "select student_fname,student_lname,school_id from tr_student where student_fname='"& CleanStrForSQL(trim(studentfName)) &"' and student_lname='"& CleanStrForSQL(trim(studentlName)) &"' and school_id="& school
		'set rs = con.Execute(strSql)
		'If not rs.EOF then
		'	errmsg = "Student "& studentfName &" "& studentlName &" is already exist!<br/>"
		'else
		*/
			$bDate = $bDate ." 00:01:01";
			$strSql1 = "insert into tr_student(school_id,student_fname,student_lname,date_birth,teacher,grade,parent_guardian,contact_no,email,sy)";
			$strSql1 = $strSql1 . " values('".$school."','".$studentfName."','".$studentlName."','".$bDate."','".$tchrID."','".$grade."','".$guardianName."','".$contactNo."','".$emailAdd."','".$sy."')";
			mysql_query($strSql1);

			$errmsg = "You have successfully created your student.<br/>";

			
			$strSql1 = mysql_query("select student_id from tr_student order by student_id desc limit 1");
			$rcn=mysql_num_rows($strSql1);

			if($rcn>0)
			{
				$rs1=@mysql_fetch_array($strSql);
				$student=$rs1['student_id'];
			}
			
		/*
		'end if
		'rs.Close
		'set rs=nothing
		*/
	}
	if($student!=0)
	{
		$orderID=0;
		$nowDate = $nowDate . " 00:01:01";
		$strSql = "insert into tr_orders(student_id,order_date,ptype,check_no,total)";
		$strSql = $strSql . " values('".$student."','".$nowDate."','".$pTypeVal."','".$checkNum."','".$amount."')";
		mysql_query($strSql);

		$strSql22 = mysql_query("select order_id from tr_orders order by order_id desc limit 1");
		$rcn22=mysql_num_rows($strSql22);

			if($rcn22>0)
			{
				$rs22=@mysql_fetch_array($strSql22);
				$orderID=$rs22['order_id'];
			}
		
		for($j=1;$j<=$addMform;$j++)
		{

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

		//	$orDate = $_POST[$xrDate];
			$menuSels=$_POST[$xmenuSel];
			$itemSels=$_POST[$xitemSel];
			$snakSels=$_POST[$xsnakSel];
			$drinkSels=$_POST[$xdrinkSel];
			$orDate = $_POST[$xrDate] . " 00:01:01";

			$strSql = "insert into tr_orderdetails(order_id,service_date,item_ordered,item_type,item_snack,item_drink)";
			$strSql = $strSql . " values('".$orderID."','".$orDate."','".$menuSels."','".$itemSels."','".$snakSels."','".$drinkSels."')";

			mysql_query($strSql);
		}
		$errmsg = $errmsg ."You have successfully created your student Order.<br/>";
	}
} 
?>
<table border="0" cellpadding="0" cellspacing="0" width="100%" align="center">
    <tr><td></td><td align="center"><u><b>Student Orders</b></u></td></tr>
    <tr class="fs12"><td width="200" valign="top"><?php include("sidemenu.php");?></td>
        <td width="700" valign="top">
            <table width="100%" cellpadding="1" cellspacing="1" border="0">
                <tr><td height="5" width="30%"></td><td height="5" width="70%"></td></tr>
			<?php
            $strSql33 = mysql_query("SELECT syID FROM ma_schoolyear where sStatus=1 order by syID desc limit 1");
            $rsc33=@mysql_num_rows($strSql33);
            
			if($rsc33>0)
			{
				$rs33=@mysql_fetch_array($strSql33);
				$yearRef=$rs33['syID'];
			}
           
			if(strtoupper(substr(trim($errmsg),0,8)) == "YOU HAVE")
			{
                echo "<tr><td colspan='4'><hr/></td></tr>";
                echo "<tr valign='top' align='center'><td colspan='4'><br/>".$errmsg."<br/></td></tr>";
                echo "<tr valign='top' align='center'><td colspan='4'><a href='studentOrder.php'>Create another order?</a><br/><br/></td></tr>";
			}
			else 
			{
				?>
                <tr><td colspan="4" class="errmsg"><hr/><?=$errmsg?></td></tr>
                <form action="studentOrder.php" method="POST" name="frm">
                <tr><td align="right">Select School:&nbsp;</td>
                    <td><select name="school" class="formSelect" onChange="javascript:{if(this.value!='') submit();}">
					<?php
					 $strSqlss = mysql_query("select school_id,school_name from tr_schools where status=1 order by school_name");
                     $rscss=@mysql_num_rows($strSqlss);
            
					if($rscss>0)
					{
                        echo "<option value='0'>--Select--</option>";

                        while($rsss=@mysql_fetch_array($strSqlss))
						{
						  if($school==$rsss['school_id'])
							 echo "<option value='".$rsss['school_id']."' selected>".$rsss['school_name']."</option>";
						  else
							 echo "<option value='".$rsss['school_id']."' >".$rsss['school_name']."</option>";                            
                        }
                        echo "<option value='1000'>Others (Create New School)</option>";
                    }
					else
					{
                        $school=0;
                    }
                    ?>
					</select></td></tr>
					<tr><td align="right">Select Grade:&nbsp;</td>
                    <td><select name="grade" class="formSelect" onChange="javascript:{if(this.value!='') submit();}">
					<?php
                    $strSqlg = mysql_query("select grade_id,grade_name from ma_grades where status=1");
					$rscg=@mysql_num_rows($strSqlg);
            
					if($rscg>0)
					{
                        echo "<option value='0'>--Select--</option>";

                        while($rsg=@mysql_fetch_array($strSqlg))
						{
						  if($grade==$rsg['grade_id'])
							 echo "<option value='".$rsg['grade_id']."' selected>".$rsg['grade_name']."</option>";
						  else
							 echo "<option value='".$rsg['grade_id']."' >".$rsg['grade_name']."</option>";                            
                        }

                    }
					else
					{
                        $grade=0;
                    }
                     
					?>
					</select></td></tr>
                <tr><td align="right">Select Student:&nbsp;</td>
				
                    <td><select name="student" class="formSelect" onChange="javascript:{if(this.value!='') submit();}">
					<?php
                    $strSqlstu = mysql_query("select student_id,student_fname,student_lname from tr_student where status=1 and school_id='".$school."' and grade='".$grade."' and sy='".$yearRef."' order by grade,student_lname");
					

				  
					$rscstu=@mysql_num_rows($strSqlstu);
            
					if($rscstu>0)
					{
                        echo "<option value='0'>--Select--</option>";

                        while($rsstu=@mysql_fetch_array($strSqlstu))
						{
						  if($student==$rsstu['student_id'])
							 echo "<option value='".$rsstu['student_id']."' selected>".$rsstu['student_lname'].", ".$rsstu['student_fname']."</option>";
						  else
							 echo "<option value='".$rsstu['student_id']."' >".$rsstu['student_lname'].", ".$rsstu['student_fname']."</option>";
                        }

					
                    }
					else
					{
                        $student=0;
                    }
                    
					?>
					</select></td></tr>
					<?php
					if($student!=0)
					{

						$strSqla = mysql_query("select a.student_id,a.date_birth,b.teacher_name,a.parent_guardian,a.contact_no,a.email from tr_student a left join tr_teachers b on b.teacher_id=a.teacher where a.status=1 and a.school_id='".$school."' and a.student_id='".$student."'");

						$rsca=@mysql_num_rows($strSqla);
            
						if($rsca>0)
						{
							$semail= "--none-- &nbsp; &nbsp; ";
							$rsa=@mysql_fetch_array($strSqla);

							if(trim($rsa['email'])!="") 
							{
								$semail= trim($rsa['email']);
							}
							?>
								<tr><td align="right">Date of Birth:&nbsp;</td><td><b><?=$rsa['date_birth']?></b></td></tr>
								<tr><td align="right">Teacher:&nbsp;</td><td><b><?=$rsa['teacher_name']?></b></td></tr>
								<tr><td align="right">Guardian Name:&nbsp;</td><td><b><?=$rsa['parent_guardian']?></b></td></tr>
								<tr><td align="right">Contact Number:&nbsp;</td><td><b><?=$rsa['contact_no']?></b></td></tr>
								<tr><td align="right">Email:&nbsp;</td><td><b><?=$semail?></b>&nbsp;&nbsp;&nbsp;<a href="studentUpdate.php?id=<?=$rsa['student_id']?>">edit student details?</a></td></tr>
						
							<?php 
								
							$ckNewStud = "";
							$ckNewStudVal=0;
							$ckNewStudStat="hidden";
						}
					}
					else
					{
						$chkst='ckNewStud'.$chNewStud;

							echo "<tr><td></td><td><input type='checkbox' name='".$chkst."' onclick='javascript:geteStudentInfo();' />&nbsp;New Student</td></tr>";
					}
						?>
                <tr><td colspan="2">
                <span id="eStudentInfo" style="visibility: <?=$ckNewStudStat?>;">
                    <table width="100%" cellpadding="1" cellspacing="1" border="0">
                        <tr><td height="10" width="20%"></td><td width="30%" class="reqmsg"><i>* required fields</i></td><td height="10" width="15%"></td><td width="35%"></td></tr>
                        <tr><td align="right"><b>* </b>FIRST NAME:&nbsp;</td><td><input class="formInput" type="text" name="studentfName" value="<?=$studentfName?>" /></td>
                            <td align="right"><b>* </b>CONTACT#:&nbsp;</td><td><input class="formInputL" type="text" name="contactNo" value="<?=$contactNo?>" /></td></tr>
                        <tr><td align="right"><b>* </b>LAST NAME:&nbsp;</td><td><input class="formInput" type="text" name="studentlName" value="<?=$studentlName?>" /></td>
                            <td align="right">BIRTH DATE:&nbsp;</td><td>

                            <select name="byear" class="formYear">
							<?php
                            for($i=$frDate;$i<$toDate;$i++)
							{
                               if($byear==$i)
							    echo "<option value='".$i."' selected>".$i."</option>";
							   else
								echo "<option value='".$i."' >".$i."</option>";								
                            }
							?></select>&nbsp;
                            
								<select name="bdmonth" class="formDDMM">
								<?php
								for($i=1;$i<=12;$i++)
								{
								   if($bdmonth==$i)
									echo "<option value='".$i."' selected>".$i."</option>";
								   else
									echo "<option value='".$i."' >".$i."</option>";								
								}
								?>
								</select>&nbsp;

                                <select name="bdday" class="formDDMM">
								<?php
								for($i=1;$i<=31;$i++)
								{
								   if($bdday==$i)
									echo "<option value='".$i."' selected>".$i."</option>";
								   else
									echo "<option value='".$i."' >".$i."</option>";								
								}
								?>
								</select></td></tr>
							<tr><td align="right"><b>* </b>GUARDIAN NAME:&nbsp;</td><td><input class="formInput" type="text" name="guardianName" value="<?=$guardianName?>" /></td>
                            <td align="right">TEACHER:&nbsp;</td><td>
                            <select name="tchrID" class="formSelect">
							<?php
                            $strSqlt = mysql_query("select teacher_id,teacher_name from tr_teachers where status=1 and school_id='".$school."' and sy='".$yearRef."' order by teacher_name");
							
							$rsct=@mysql_num_rows($strSqlt);
            
							if($rsct>0)
							{
								echo "<option value='0'>--Select--</option>";

								while($rst=@mysql_fetch_array($strSqlt))
								{
								  if($tchrID==$rst['tecaher_id'])
									 echo "<option value='".$rst['teacher_id']."' selected>".$rst['teacher_name']."</option>";
								  else
									 echo "<option value='".$rst['teacher_id']."' >".$rst['teacher_name']."</option>";
								}
							}
                            ?>
							</select></td></tr>
                        <tr><td align="right">EMAIL ADDRESS:&nbsp;</td><td><input class="formInput" type="text" name="emailAdd" value="<?=$emailAdd?>" /></td>
                            <td align="right">SCHOOL YR:&nbsp;</td>
                            <td><select name="sy" class="formYear">
							<?php
                            $strSqlyr = mysql_query("select syID,syName from ma_schoolyear where sstatus=1 order by syID desc");
							$rscyr=@mysql_num_rows($strSqlyr);
            
							if($rscyr>0)
							{
								echo "<option value='0'>--Select--</option>";

								while($rsyr=@mysql_fetch_array($strSqlyr))
								{
								  if($sy==$rsyr['syID'])
									 echo "<option value='".$rsyr['syID']."' selected>".$rsyr['syName']."</option>";
								  else
									 echo "<option value='".$rsyr['syID']."' >".$rsyr['syName']."</option>";
								}
							}
                          
							?>
							</select></td></tr>
                    </table>
                </span></td></tr>
                    <tr><td colspan="2"><hr/></td></tr>
                    <tr><td colspan="2">
                        <table border="0" width="100%" cellpadding="1" cellspacing="1">
                            <tr align="center"><td width="30%"><b>Day of Service</b></td><td width="35%"><b>Item Ordered</b></td><td width="35%"><b>Item Type</b></td></tr>
							<?php
							for($j=1;$j<=$addMform;$j++)
							{
							?>
                            <tr align="center">
                             <td><?=$j?>.&nbsp;<select name="orDate<?=$j?>" class="formYear">
							 <?php
                            $strSqlo = mysql_query("select orderDate from tr_school_dates where school_id = '".$school."' order by orderDate");
							$rsco=@mysql_num_rows($strSqlo);
							
                            if($rsco>0)
							{
                                while($rso=@mysql_fetch_array($strSqlo))
								{
								    //tDate = Year(cDate(rs("orderDate"))) & "-" & Month(cDate(rs("orderDate"))) & "-" & Day(cDate(rs("orderDate")))
									$tDate=$rso['orderDate'];
                                    
									$orDatee='orDate'.$j;

									if($_POST[$orDatee]==$tDate)
										echo "<option value='".$tDate."' selected>".$tDate."</option>";
									else
										echo "<option value='".$tDate."' >".$tDate."</option>";

                                    
								}
                            }
                            ?></select>
                                </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'>--Select--</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='".$school."'");
								$rowcnt=@mysql_num_rows($sel);
								$row=@mysql_fetch_array($sel);

								if($rowcnt>0)
								{
								
									?>

									<tr align="center">
										<td align="right"><b>Snack &amp; Drink:&nbsp;</b></td>
									<?php
									if($row['snacks']=='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($row['drinks']=='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
						?>
                            <tr align="right"><td><input type="radio" name="pType" value="Cash" <?php if($_POST['pType']=="Cash") echo "checked";?> />Cash&nbsp;<input type="radio" name="pType" value="Check" <?php if($_POST['pType']=="Check") echo "checked";?> />Check</td>
                                <td>Check No.:&nbsp;<input class="formInputS" type="text" name="checkNum" value="<?=$checkNum?>" /></td>
                                <td><b>* </b>Amount:&nbsp;<input class="formInputS" type="text" name="amount" value="<?=$amount?>" /></td></tr>
                                <input type="hidden" name="addMform" value="<?=$addMform?>" />
                            <tr align="right"><td></td><td><input type="submit" name="action" value="add more order" /></td><td><input type="submit" name="action" value="Submit Order" /></td></tr>
                        </table></td></tr>
                </form>
			<?php
			}
			?>
                <tr><td colspan="2"><hr/></td></tr>
				<?php
				$crdate=date('Y-m-d')." 00:00:00";
                $strSql = mysql_query("SELECT a.detail_id,a.service_date,c.menu_name,d.item_type,b.student_id,b.paid_status 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=".$student." and  a.service_date >='".$crdate."' order by service_date");

				
				$resc=@mysql_num_rows($strSql);
                if($resc>0)
				{
				?>

                <tr><td colspan="2" height="20"></td></tr>
                <tr><td colspan="2">&nbsp;<b>CURRENT ORDERS:</b></td></tr>
                <tr><td colspan="2">
                        <table width="608" cellpadding="1" cellspacing="1" border="0">
                            <tr valign="top"><td width="20%" height="1"></td><td width="43%"></td><td width="23%"></td><td width="7%" height="1"></td><td width="7%" height="1"></td></tr>
                            <tr valign="top"><td colspan="5"><hr /></td></tr>
                            <tr><td>&nbsp;<b>Date Ordered</b></td><td><b>Lunch Ordered</b></td><td><b>Payment </b></td><td><b>Description</b></td><td colspan="2"></td></tr>
                            <tr><td colspan="5"><hr /></td></tr>
							<?php
							while($rss=@mysql_fetch_array($strSql))
							{
								$cdate=explode(" ",$rss['service_date']);
								$ccdate=explode("-",$cdate[0]);

								$monthNum = $ccdate[1];
								$monthName = date("F", mktime(0, 0, 0, $monthNum, 10));

	                            $sDate = $monthName ." ". $ccdate[2].", ".$ccdate[0];
							?>
                            <tr><td>&nbsp;<?=$sDate?></td>
                                <td><?=$rss['menu_name']?></td>
								<td><?php
									if($rs1['paid_status']=='1')
									 echo "&nbsp;&nbsp;Done";
									else
									 echo "&nbsp;&nbsp;Not Done&nbsp;&nbsp;";
									?></td>
                                <td><?=$rss['item_type']?></td>
								
                                <td align="center"><a href="orderStudent.php?oID=<?=$rss['detail_id']?>&sID=<?=$rss['student_id']?>">edit</a></td>
                                <td align="center"><a href="#" onClick="confirmdelete('<?="student.php?oID=".$rss['detail_id']."&sID=".$rss['student_id']?>&action=rmvd'); return false;">delete</a></td></tr>
							<?php
							}
							?>
                            <tr><td colspan="5"><hr /></td></tr></table>
				<?php
				}
				?></td></tr>
            </table></td></tr>
</table>
<?php
include("footer.php");
}
?>