<?php
include("dbconnect.php");
?>
<link rel="stylesheet" href="css/general.css" type="text/css" />

<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";
}*/

$pType = $_POST['pType'];
$checkNum = $_POST['checkNum'];
$amount = $_POST['amount'];
if(trim($_GET['sID'])!="")
	$student=$_GET['sID'];
else
	$student=$_POST['sid'];

if(trim($_GET['schID'])!="")
	$schoolid=$_GET['schID'];
else
	$schoolid=$_POST['schid'];

if(trim($_GET['gID'])!="")
	$gid=$_GET['gID'];
else
	$gid=$_POST['gid'];
/*
if(trim($_POST['snakSel1'])!="") $snakSel1=$_POST['snakSel1'];
if(trim($_POST['snakSel2'])!="") $snakSel2=$_POST['snakSel2'];
if(trim($_POST['snakSel3'])!="") $snakSel3=$_POST['snakSel3'];
if(trim($_POST['snakSel4'])!="") $snakSel4=$_POST['snakSel4'];
if(trim($_POST['snakSel5'])!="") $snakSel5=$_POST['snakSel5'];
if(trim($_POST['snakSel6'])!="") $snakSel6=$_POST['snakSel6'];
if(trim($_POST['snakSel7'])!="") $snakSel7=$_POST['snakSel7'];
if(trim($_POST['snakSel8'])!="") $snakSel8=$_POST['snakSel8'];
if(trim($_POST['snakSel9'])!="") $snakSel9=$_POST['snakSel9'];
if(trim($_POST['snakSel10'])!="") $snakSel10=$_POST['snakSel10'];
if(trim($_POST['snakSel11'])!="") $snakSel11=$_POST['snakSel11'];
if(trim($_POST['snakSel12'])!="") $snakSel12=$_POST['snakSel12'];
if(trim($_POST['snakSel13'])!="") $snakSel13=$_POST['snakSel13'];
if(trim($_POST['snakSel14'])!="") $snakSel14=$_POST['snakSel14'];
if(trim($_POST['snakSel15'])!="") $snakSel15=$_POST['snakSel15'];
if(trim($_POST['snakSel16'])!="") $snakSel16=$_POST['snakSel16'];
if(trim($_POST['snakSel17'])!="") $snakSel17=$_POST['snakSel17'];
if(trim($_POST['snakSel18'])!="") $snakSel18=$_POST['snakSel18'];
if(trim($_POST['snakSel19'])!="") $snakSel19=$_POST['snakSel19'];
if(trim($_POST['snakSel20'])!="") $snakSel20=$_POST['snakSel20'];
if(trim($_POST['snakSel21'])!="") $snakSel21=$_POST['snakSel21'];
if(trim($_POST['snakSel22'])!="") $snakSel22=$_POST['snakSel22'];
if(trim($_POST['snakSel23'])!="") $snakSel23=$_POST['snakSel23'];
if(trim($_POST['snakSel24'])!="") $snakSel24=$_POST['snakSel24'];
if(trim($_POST['snakSel25'])!="") $snakSel25=$_POST['snakSel25'];
if(trim($_POST['drinkSel1'])!="") $drinkSel1=$_POST['drinkSel1'];
if(trim($_POST['drinkSel2'])!="") $drinkSel2=$_POST['drinkSel2'];
if(trim($_POST['drinkSel3'])!="") $drinkSel3=$_POST['drinkSel3'];
if(trim($_POST['drinkSel4'])!="") $drinkSel4=$_POST['drinkSel4'];
if(trim($_POST['drinkSel5'])!="") $drinkSel5=$_POST['drinkSel5'];
if(trim($_POST['drinkSel6'])!="") $drinkSel6=$_POST['drinkSel6'];
if(trim($_POST['drinkSel7'])!="") $drinkSel7=$_POST['drinkSel7'];
if(trim($_POST['drinkSel8'])!="") $drinkSel8=$_POST['drinkSel8'];
if(trim($_POST['drinkSel9'])!="") $drinkSel9=$_POST['drinkSel9'];
if(trim($_POST['drinkSel10'])!="") $drinkSel10=$_POST['drinkSel10'];
if(trim($_POST['drinkSel11'])!="") $drinkSel11=$_POST['drinkSel11'];
if(trim($_POST['drinkSel12'])!="") $drinkSel12=$_POST['drinkSel12'];
if(trim($_POST['drinkSel13'])!="") $drinkSel13=$_POST['drinkSel13'];
if(trim($_POST['drinkSel14'])!="") $drinkSel14=$_POST['drinkSel14'];
if(trim($_POST['drinkSel15'])!="") $drinkSel15=$_POST['drinkSel15'];
if(trim($_POST['drinkSel16'])!="") $drinkSel16=$_POST['drinkSel16'];
if(trim($_POST['drinkSel17'])!="") $drinkSel17=$_POST['drinkSel17'];
if(trim($_POST['drinkSel18'])!="") $drinkSel18=$_POST['drinkSel18'];
if(trim($_POST['drinkSel19'])!="") $drinkSel19=$_POST['drinkSel19'];
if(trim($_POST['drinkSel20'])!="") $drinkSel20=$_POST['drinkSel20'];
if(trim($_POST['drinkSel21'])!="") $drinkSel21=$_POST['drinkSel21'];
if(trim($_POST['drinkSel22'])!="") $drinkSel22=$_POST['drinkSel22'];
if(trim($_POST['drinkSel23'])!="") $drinkSel23=$_POST['drinkSel23'];
if(trim($_POST['drinkSel24'])!="") $drinkSel24=$_POST['drinkSel24'];
if(trim($_POST['drinkSel25'])!="") $drinkSel25=$_POST['drinkSel25'];
if(trim($_POST['menuSel1'])!="") $menuSel1=$_POST['menuSel1'];
if(trim($_POST['menuSel2'])!="") $menuSel2=$_POST['menuSel2'];
if(trim($_POST['menuSel3'])!="") $menuSel3=$_POST['menuSel3'];
if(trim($_POST['menuSel4'])!="") $menuSel4=$_POST['menuSel4'];
if(trim($_POST['menuSel5'])!="") $menuSel5=$_POST['menuSel5'];
if(trim($_POST['menuSel6'])!="") $menuSel6=$_POST['menuSel6'];
if(trim($_POST['menuSel7'])!="") $menuSel7=$_POST['menuSel7'];
if(trim($_POST['menuSel8'])!="") $menuSel8=$_POST['menuSel8'];
if(trim($_POST['menuSel9'])!="") $menuSel9=$_POST['menuSel9'];
if(trim($_POST['menuSel10'])!="") $menuSel10=$_POST['menuSel10'];
if(trim($_POST['menuSel11'])!="") $menuSel11=$_POST['menuSel11'];
if(trim($_POST['menuSel12'])!="") $menuSel12=$_POST['menuSel12'];
if(trim($_POST['menuSel13'])!="") $menuSel13=$_POST['menuSel13'];
if(trim($_POST['menuSel14'])!="") $menuSel14=$_POST['menuSel14'];
if(trim($_POST['menuSel15'])!="") $menuSel15=$_POST['menuSel15'];
if(trim($_POST['menuSel16'])!="") $menuSel16=$_POST['menuSel16'];
if(trim($_POST['menuSel17'])!="") $menuSel17=$_POST['menuSel17'];
if(trim($_POST['menuSel18'])!="") $menuSel18=$_POST['menuSel18'];
if(trim($_POST['menuSel19'])!="") $menuSel19=$_POST['menuSel19'];
if(trim($_POST['menuSel20'])!="") $menuSel20=$_POST['menuSel20'];
if(trim($_POST['menuSel21'])!="") $menuSel21=$_POST['menuSel21'];
if(trim($_POST['menuSel22'])!="") $menuSel22=$_POST['menuSel22'];
if(trim($_POST['menuSel23'])!="") $menuSel23=$_POST['menuSel23'];
if(trim($_POST['menuSel24'])!="") $menuSel24=$_POST['menuSel24'];
if(trim($_POST['menuSel25'])!="") $menuSel25=$_POST['menuSel25'];
if(trim($_POST['itemSel1'])!="") $itemSel1=$_POST['itemSel1'];
if(trim($_POST['itemSel2'])!="") $itemSel2=$_POST['itemSel2'];
if(trim($_POST['itemSel3'])!="") $itemSel3=$_POST['itemSel3'];
if(trim($_POST['itemSel4'])!="") $itemSel4=$_POST['itemSel4'];
if(trim($_POST['itemSel5'])!="") $itemSel5=$_POST['itemSel5'];
if(trim($_POST['itemSel6'])!="") $itemSel6=$_POST['itemSel6'];
if(trim($_POST['itemSel7'])!="") $itemSel7=$_POST['itemSel7'];
if(trim($_POST['itemSel8'])!="") $itemSel8=$_POST['itemSel8'];
if(trim($_POST['itemSel9'])!="") $itemSel9=$_POST['itemSel9'];
if(trim($_POST['itemSel10'])!="") $itemSel10=$_POST['itemSel10'];
if(trim($_POST['itemSel11'])!="") $itemSel11=$_POST['itemSel11'];
if(trim($_POST['itemSel12'])!="") $itemSel12=$_POST['itemSel12'];
if(trim($_POST['itemSel13'])!="") $itemSel13=$_POST['itemSel13'];
if(trim($_POST['itemSel14'])!="") $itemSel14=$_POST['itemSel14'];
if(trim($_POST['itemSel15'])!="") $itemSel15=$_POST['itemSel15'];
if(trim($_POST['itemSel16'])!="") $itemSel16=$_POST['itemSel16'];
if(trim($_POST['itemSel17'])!="") $itemSel17=$_POST['itemSel17'];
if(trim($_POST['itemSel18'])!="") $itemSel18=$_POST['itemSel18'];
if(trim($_POST['itemSel19'])!="") $itemSel19=$_POST['itemSel19'];
if(trim($_POST['itemSel20'])!="") $itemSel20=$_POST['itemSel20'];
if(trim($_POST['itemSel21'])!="") $itemSel21=$_POST['itemSel21'];
if(trim($_POST['itemSel22'])!="") $itemSel22=$_POST['itemSel22'];
if(trim($_POST['itemSel23'])!="") $itemSel23=$_POST['itemSel23'];
if(trim($_POST['itemSel24'])!="") $itemSel24=$_POST['itemSel24'];
if(trim($_POST['itemSel25'])!="") $itemSel25=$_POST['itemSel25'];
if(trim($_POST['byear1'])!="") $byear1=$_POST['byear1'];
if(trim($_POST['byear2'])!="") $byear2=$_POST['byear2'];
if(trim($_POST['byear3'])!="") $byear3=$_POST['byear3'];
if(trim($_POST['byear4'])!="") $byear4=$_POST['byear4'];
if(trim($_POST['byear5'])!="") $byear5=$_POST['byear5'];
if(trim($_POST['byear6'])!="") $byear6=$_POST['byear6'];
if(trim($_POST['byear7'])!="") $byear7=$_POST['byear7'];
if(trim($_POST['byear8'])!="") $byear8=$_POST['byear8'];
if(trim($_POST['byear9'])!="") $byear9=$_POST['byear9'];
if(trim($_POST['byear10'])!="") $byear10=$_POST['byear10'];
if(trim($_POST['byear11'])!="") $byear11=$_POST['byear11'];
if(trim($_POST['byear12'])!="") $byear12=$_POST['byear12'];
if(trim($_POST['byear13'])!="") $byear13=$_POST['byear13'];
if(trim($_POST['byear14'])!="") $byear14=$_POST['byear14'];
if(trim($_POST['byear15'])!="") $byear15=$_POST['byear15'];
if(trim($_POST['byear16'])!="") $byear16=$_POST['byear16'];
if(trim($_POST['byear17'])!="") $byear17=$_POST['byear17'];
if(trim($_POST['byear18'])!="") $byear18=$_POST['byear18'];
if(trim($_POST['byear19'])!="") $byear19=$_POST['byear19'];
if(trim($_POST['byear20'])!="") $byear20=$_POST['byear20'];
if(trim($_POST['byear21'])!="") $byear21=$_POST['byear21'];
if(trim($_POST['byear22'])!="") $byear22=$_POST['byear22'];
if(trim($_POST['byear23'])!="") $byear23=$_POST['byear23'];
if(trim($_POST['byear24'])!="") $byear24=$_POST['byear24'];
if(trim($_POST['byear25'])!="") $byear25=$_POST['byear25'];
if(trim($_POST['bmonth1'])!="") $bmonth1=$_POST['bmonth1'];
if(trim($_POST['bmonth2'])!="") $bmonth2=$_POST['bmonth2'];
if(trim($_POST['bmonth3'])!="") $bmonth3=$_POST['bmonth3'];
if(trim($_POST['bmonth4'])!="") $bmonth4=$_POST['bmonth4'];
if(trim($_POST['bmonth5'])!="") $bmonth5=$_POST['bmonth5'];
if(trim($_POST['bmonth6'])!="") $bmonth6=$_POST['bmonth6'];
if(trim($_POST['bmonth7'])!="") $bmonth7=$_POST['bmonth7'];
if(trim($_POST['bmonth8'])!="") $bmonth8=$_POST['bmonth8'];
if(trim($_POST['bmonth9'])!="") $bmonth9=$_POST['bmonth9'];
if(trim($_POST['bmonth10'])!="") $bmonth10=$_POST['bmonth10'];
if(trim($_POST['bmonth11'])!="") $bmonth11=$_POST['bmonth11'];
if(trim($_POST['bmonth12'])!="") $bmonth12=$_POST['bmonth12'];
if(trim($_POST['bmonth13'])!="") $bmonth13=$_POST['bmonth13'];
if(trim($_POST['bmonth14'])!="") $bmonth14=$_POST['bmonth14'];
if(trim($_POST['bmonth15'])!="") $bmonth15=$_POST['bmonth15'];
if(trim($_POST['bmonth16'])!="") $bmonth16=$_POST['bmonth16'];
if(trim($_POST['bmonth17'])!="") $bmonth17=$_POST['bmonth17'];
if(trim($_POST['bmonth18'])!="") $bmonth18=$_POST['bmonth18'];
if(trim($_POST['bmonth19'])!="") $bmonth19=$_POST['bmonth19'];
if(trim($_POST['bmonth20'])!="") $bmonth20=$_POST['bmonth20'];
if(trim($_POST['bmonth21'])!="") $bmonth21=$_POST['bmonth21'];
if(trim($_POST['bmonth22'])!="") $bmonth22=$_POST['bmonth22'];
if(trim($_POST['bmonth23'])!="") $bmonth23=$_POST['bmonth23'];
if(trim($_POST['bmonth24'])!="") $bmonth24=$_POST['bmonth24'];
if(trim($_POST['bmonth25'])!="") $bmonth25=$_POST['bmonth25'];
if(trim($_POST['bday1'])!="") $bday1=$_POST['bday1'];
if(trim($_POST['bday2'])!="") $bday2=$_POST['bday2'];
if(trim($_POST['bday3'])!="") $bday3=$_POST['bday3'];
if(trim($_POST['bday4'])!="") $bday4=$_POST['bday4'];
if(trim($_POST['bday5'])!="") $bday5=$_POST['bday5'];
if(trim($_POST['bday6'])!="") $bday6=$_POST['bday6'];
if(trim($_POST['bday7'])!="") $bday7=$_POST['bday7'];
if(trim($_POST['bday8'])!="") $bday8=$_POST['bday8'];
if(trim($_POST['bday9'])!="") $bday9=$_POST['bday9'];
if(trim($_POST['bday10'])!="") $bday10=$_POST['bday10'];
if(trim($_POST['bday11'])!="") $bday11=$_POST['bday11'];
if(trim($_POST['bday12'])!="") $bday12=$_POST['bday12'];
if(trim($_POST['bday13'])!="") $bday13=$_POST['bday13'];
if(trim($_POST['bday14'])!="") $bday14=$_POST['bday14'];
if(trim($_POST['bday15'])!="") $bday15=$_POST['bday15'];
if(trim($_POST['bday16'])!="") $bday16=$_POST['bday16'];
if(trim($_POST['bday17'])!="") $bday17=$_POST['bday17'];
if(trim($_POST['bday18'])!="") $bday18=$_POST['bday18'];
if(trim($_POST['bday19'])!="") $bday19=$_POST['bday19'];
if(trim($_POST['bday20'])!="") $bday20=$_POST['bday20'];
if(trim($_POST['bday21'])!="") $bday21=$_POST['bday21'];
if(trim($_POST['bday22'])!="") $bday22=$_POST['bday22'];
if(trim($_POST['bday23'])!="") $bday23=$_POST['bday23'];
if(trim($_POST['bday24'])!="") $bday24=$_POST['bday24'];
if(trim($_POST['bday25'])!="") $bday25=$_POST['bday25'];
*/
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)
	{
			$bDate = $bDate ." 00:00:00";
			$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'];
			}
			
	
	}*/
	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($strSql122);

			if($rcn22>0)
			{
				$rs22=@mysql_fetch_array($strSql22);
				$orderID=$rs22['order_id'];
			}*/
			$orderID=@mysql_insert_id();
			$amount=0;
		
		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);

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

			$amount +=$xitmc[0];

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

		
			//$amount=7;

			echo "<script>";
			echo "location.replace('paypalpay.php?Oid=".base64_encode($orderID)."&b=".base64_encode($amount)."');";
			echo "</script>";



		
	}
} 

?>
<link rel="stylesheet" href="css/general.css" type="text/css" />
<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>
            <form action="new_order.php?schID=<?=$schoolid?>&sID=<?=$student?>&gID=<?=$gid?>" method="POST" name="frm">
				  <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;">
									<tr align="center">
										<td width="30%" nowrap><b>Day of Service</b></td>
										<td width="35%" nowrap><b>Item Ordered</b></td>
										<td width="35%" nowrap><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 = '".$schoolid."' 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>
								 <tr align="center">
									<td align="right" nowrap><b>Snack &amp; Drink:&nbsp;</b></td>
									<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>
										<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 nowrap>
								<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
								<input type="radio" name="pType" value="Paypal" <?php if($_POST['pType']=="Paypal") echo "checked";?> />Paypal&nbsp;
								</td>
                                <td>Check No.:&nbsp;<input class="formInputSS" type="text" name="checkNum" value="<?=$checkNum?>" /></td>
                                <td><b>* </b>Amount:&nbsp;<input class="formInputSS" type="text" name="amount" value="<?=$amount?>" readonly/></td>
							</tr> -->
                                <input type="hidden" name="addMform" value="<?=$addMform?>" /><input type='hidden' name='sid' value='<?=$_GET['sID']?>'/>
								<input type='hidden' name='schid' value='<?=$_GET['schID']?>'/><input type='hidden' name='gid' value='<?=$_GET['gID']?>'/>
                            <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>
			</table>
          </form>
 </table>

