<?php
$pgMod="make_admission";
$pgAct="view";
if(isset($_GET['action']) && trim($_GET['action'])!='')
		$pgAct=strtolower($_GET['action']);


if($_POST)
{
	$_SESSION['form']=$_POST;
	//$section=$_POST["section"];unset($_POST["section"]);
	$flgEr=FALSE;$hostel=$_POST["hostel"];//echo "<pre>".$hostel;print_r($_POST);exit;
	$busfee=$_POST["busfee"];$classfee=$_POST["classfee"];$installment=$_POST["noInstallment"];
	$installmentAry=$_POST["fee"];$installmentbusAry=$_POST["busfee"];$installmenthostelAry=$_POST["hostelfee"];
	$discount=$_POST["discount"];$feetotal=$_POST["feetotal"];
	$busdiscount=$_POST["busdiscount"];$busfeetotal=$_POST["busfeetotal"];
	$hosteldiscount=$_POST["hosteldiscount"];$hostelfeetotal=$_POST["hostelfeetotal"];
	
	unset($_POST["hostel"]);
	unset($_POST["fee"]);unset($_POST["discount"]);unset($_POST["feetotal"]);unset($_POST["classfee"]);unset($_POST["noInstallment"]);
	unset($_POST["busfee"]);unset($_POST["busdiscount"]);unset($_POST["busfeetotal"]);
	unset($_POST["hostelfee"]);unset($_POST["hosteldiscount"]);unset($_POST["hostelfeetotal"]);
	
	$instalmentAry=array("idno"=>$_POST["idno"],
						 "class"=>$_POST["class"],
						 "bus"=>$busfeetotal,
						 "total"=>$feetotal,
						 "discount"=>$discount,
						 "busdiscount"=>$busdiscount,
						 'session'=>$_SESSION["admin"]["session"],
						 "status"=>1
	);
	$instalmenthostelAry=array("idno"=>$_POST["idno"],
						 "class"=>$_POST["class"],
						 "hid"=>$hostel,
						 "total"=>$hostelfeetotal,
						 "discount"=>$hosteldiscount,
						 'session'=>$_SESSION["admin"]["session"],
						 'school_id'=>$_SESSION["admin"]["school_id"],
						 'added_by'=>$_SESSION["admin"]["uid"],
						 "status"=>1
	);
	//print_r($instalmentAry);exit;
	$ij=0;$ih=0;$ik=0;
	if(isset($_POST["bpl"]) && $_POST["bpl"]==1){
		$instalmentAry["total"]=0;
		foreach($installmentAry as $value){$ij++;
			$list="i".$ij;
			$instalmentAry[$list]=0;
				
		}
	}else{			
		foreach($installmentAry as $value){$ij++;
			$list="i".$ij;
			$instalmentAry[$list]=$value;	
		}
	}
	foreach($installmentbusAry as $value){$ik++;
		$list="b".$ik;
		$instalmentAry[$list]=$value;	
	}
	foreach($installmenthostelAry as $value){$ih++;
		$list="i".$ih;
		$instalmenthostelAry[$list]=$value;	
	}
	if(isset($_FILES["photo"]["name"]) && !empty($_FILES["photo"]["name"])){
		$lfilename = basename($_FILES['photo']['name']);
		$lext = strtolower(substr($lfilename, strrpos($lfilename, '.')+1));
		$lnewfile=md5(microtime()).".".$lext;
		if(move_uploaded_file($_FILES['photo']['tmp_name'],"media/photo/".$lnewfile))
		{
			$_POST["photo"]=$lnewfile;
		}
	}
	if(isset($_FILES["TC"]["name"]) && !empty($_FILES["TC"]["name"])){
		$lfilename = basename($_FILES['TC']['name']);
		$lext = strtolower(substr($lfilename, strrpos($lfilename, '.')+1));
		$lnewfile=md5(microtime()).".".$lext;
		if(move_uploaded_file($_FILES['TC']['tmp_name'],"media/TC/".$lnewfile))
		{
			$_POST["TC"]=$lnewfile;
		}
	}
	if($flgEr!=TRUE && $pgAct=="add")
	{
		$_POST["school_id"]=$_SESSION["admin"]["school_id"];
        $_POST["added_by"]=$_SESSION["admin"]["uid"];				if (in_array($_GET['id'], $_POST['sibling']))		{		$_POST['sibling'];			}		/*else		{			array_push($_POST['sibling'],$_GET['id']);		}*/				  $_POST["sibling"]=implode(",", $_POST['sibling']);		
		$flgIn=$db->insertAry("student",$_POST);
		if(!is_null($flgIn))
		{
			$instalmentAry["school_id"]=$_SESSION["admin"]["school_id"];
            $instalmentAry["added_by"]=$_SESSION["admin"]["uid"];
			
			$flgInstall=$db->insertAry("installment",$instalmentAry);
			if($hostel!=""){
				$flgInstall=$db->insertAry("hostelinstallment",$instalmenthostelAry);
				$hostelName=$db->getVal("select name from hostel where id='".$hostel."'");
				$checkRoom=$db->getRow("select id,seat from hostelroom where hostel='".$hostelName."'");
				$roomid=$checkRoom["id"];
				if(is_array($checkRoom) && count($checkRoom)>0){
					$db->updateAry("hostelroom",array("seat"=>($checkRoom["seat"]+1))," where id='".$roomid."'");
				}else{
					
					$roomid=$db->insertAry("hostelroom",array("seat"=>1,"hostel"=>$hostelName,"noofroom"=>100,"status"=>1,"school_id"=>$_SESSION["admin"]["school_id"],"added_by"=>$_SESSION["admin"]["uid"]));
				}
				$roomAryD=array("roomid"=>$roomid,"idno"=>$_POST["idno"],"status"=>1,"school_id"=>$_SESSION["admin"]["school_id"],"added_by"=>$_SESSION["admin"]["uid"]);
				$db->insertAry("roomallocation",$roomAryD);
			}
			if(isset($_POST["bpl"]) && $_POST["bpl"]==1){
			
			}
			else{
				$extrafee_type=$db->getRows("select * from extrafee_type where class='".$_POST["class"]."' and session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."'");
			if(is_array($extrafee_type) && count($extrafee_type)>0){
				foreach($extrafee_type as $extrafee){
					if($_POST["stype"]==$extrafee["otype"]){
						$saveAry=array(
									"session"	=>	$_SESSION["admin"]["session"],
									"school_id"	=>	$_SESSION["admin"]["school_id"],
									"added_by"	=>	$_SESSION["admin"]["uid"],
									"type"	=>	$extrafee["id"],
									"idno"	=>	$flgIn,
									"pay"	=> 	0,
									"status"	=>	1
						);
						for($i=1; $i<=12;$i++){
							if($extrafee["p".$i]>"0"){
								$saveAry["pid"]="p".$i;
								$saveAry["fee"]=$extrafee["p".$i];
								$db->insertAry("extrafee",$saveAry);
							}
						}
					}elseif($extrafee["otype"]==""){
						$saveAry=array(
									"session"	=>	$_SESSION["admin"]["session"],
									"school_id"	=>	$_SESSION["admin"]["school_id"],
									"added_by"	=>	$_SESSION["admin"]["uid"],
									"type"	=>	$extrafee["id"],
									"idno"	=>	$flgIn,
									"pay"	=> 	0,
									"status"	=>	1
						);
						for($i=1; $i<=12;$i++){
							if($extrafee["p".$i]>"0"){
								$saveAry["pid"]="p".$i;
								$saveAry["fee"]=$extrafee["p".$i];
								$db->insertAry("extrafee",$saveAry);
							}
						}
					}
				}
			}
			}///echo $db->getLasyQuery();exit;
			if($db->getErMsg()!=""){
				echo $db->getErMsg();exit;
			}
			$db->insertAry("session_idno",array("session"=>$_SESSION["admin"]["session"],"idno"=>$flgIn,"is_root"=>$flgIn ,
            "school_id"=>$_SESSION["admin"]["school_id"],"added_by"=>$_SESSION["admin"]["uid"]));
			$message="Happy Birth Day Alert<hr/>To send sms <a style='color:#FF0000; font-weight:bold' href='javascript:;' onclick='sendSMS(\"".$flgIn."\",\"".$_POST["mobile"]."\")'>click here</a>";
			$dataAry=array( "alert_date"=>date("Y-m-d",strtotime($_POST["dob"])),"idno"=>$flgIn,"msg"=>$message);
			$dataAry["school_id"]=$_SESSION["admin"]["school_id"];
            $dataAry["added_by"]=$_SESSION["admin"]["uid"];
			$db->insertAry("alert",$dataAry);
			$_SESSION['msg']='Saved Successfully';
			unset($_SESSION['form']);
			sms($_POST["mobile"],"Dear Parent Your child is successfully register in ".$LinksDetails["site_name"],"student_enrollment");
			if($db->getErMsg()!=""){
				array_push($alert_err,$db->getErMsg());
			}else{
				redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"Promote", "page_id"=>$pgMod)));
			}
		}
		else
		{
			array_push($alert_err,$db->getErMsg());
			
		}
	}
	elseif($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id'])!='')
	{
		$editBus="0";
		if(isset($_POST["editbus"]) && $_POST["editbus"]=="yes"){
			$editBus="1";unset($_POST["editbus"]);
		}
		$editClass="0";
		if(isset($_POST["editclass"]) && $_POST["editclass"]=="yes"){
			$editClass="1";unset($_POST["editclass"]);
		}
		$editHostel="0";
		if(isset($_POST["edithostel"]) && $_POST["edithostel"]=="yes"){
			$editHostel="1";unset($_POST["edithostel"]);
		}
		if($_POST['bpl']==0){
			$_POST['bpl']=0;
		}				/if (in_array($_GET['id'], $_POST['sibling']))		{		$_POST['sibling'];			}		/*else		{			array_push($_POST['sibling'],$_GET['id']);		}*/		//echo $c= count($_POST["sibling"]);		print_r($_POST['sibling']);		die;		 $_POST["sibling"]=implode(",", $_POST['sibling']);		 //print_r($_POST["sibling"]);		
		$flgUp=$db->updateAry("student",$_POST,"where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."' and session='".$_SESSION["admin"]["session"]."'");
		//echo $db->getLastQuery();exit;
		if(!is_null($flgUp))
		{
			$_SESSION['msg']='update Successfully';
			unset($_SESSION['form']);
			if($editBus=="1"){
				$dataBus=array();
				for($ii=1;$ii<=15;$ii++)
				{
					$dataBus["b".$ii]="";
				}
				$flgInstall=$db->updateAry("installment",$dataBus,"where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."'");
				//echo "<pre>".$db->getLastQuery().$db->getErMsg()."</pre>";exit;
				$flgInstall=$db->updateAry("installment",$instalmentAry,"where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."'");
			}
			if($editClass=="1"){
				$dataBus=array();
				for($ii=1;$ii<=15;$ii++)
				{
					$dataFee["i".$ii]="";
				}
				$flgInstall=$db->updateAry("installment",$dataFee,"where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."'");
				$flgInstall=$db->updateAry("installment",$instalmentAry,"where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."'");
			}
			if($editHostel=="1" && $hostel!=""){
				$checkHostelExistName=$db->getVal("select id from hostelinstallment where idno='".$_GET['id']."'");
				if($checkHostelExistName!=""){
					$dataHostel=array();
					for($ii=1;$ii<=15;$ii++)
					{
						$dataHostel["i".$ii]="";
					}
					$flgInstall=$db->updateAry("hostelinstallment",$dataHostel,"where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."'");
					$flgInstall=$db->updateAry("hostelinstallment",$instalmenthostelAry,"where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."'");
				}else{
					$flgInstall=$db->insertAry("hostelinstallment",$instalmenthostelAry);
				}
				$hostelName=$db->getVal("select name from hostel where id='".$hostel."'");
				$checkRoom=$db->getRow("select id,seat from hostelroom where hostel='".$hostelName."'");
				$roomid=$checkRoom["id"];
				if(is_array($checkRoom) && count($checkRoom)>0){
					$db->updateAry("hostelroom",array("seat"=>($checkRoom["seat"]+1))," where id='".$roomid."'");
				}else{
					
					$roomid=$db->insertAry("hostelroom",array("seat"=>1,"hostel"=>$hostelName,"noofroom"=>100,"status"=>1,"school_id"=>$_SESSION["admin"]["school_id"],"added_by"=>$_SESSION["admin"]["uid"]));
				}
				$checkHostelAllocationName=$db->getVal("select id from roomallocation where idno='".$_GET['id']."'");
				if($checkHostelAllocationName==""){
					$roomAryD=array("roomid"=>$roomid,"idno"=>$_POST["idno"],"status"=>1,"school_id"=>$_SESSION["admin"]["school_id"],"added_by"=>$_SESSION["admin"]["uid"]);
					$db->insertAry("roomallocation",$roomAryD);
				}
			}elseif(isset($hostel) && $hostel==""){
				$flgUp=$db->delete("hostelinstallment","where idno='".$_GET['id']."' and session='".$_SESSION["admin"]["session"]."'");
				$flgUp=$db->delete("roomallocation","where idno='".$_GET['id']."'");
			}
			$hasExtraFee=$db->getVal("select id from extrafee where idno='".$_GET['id']."' and type in (select id from extrafee_type where class='".$_POST["class"]."')");
			if($hasExtraFee==""){
				//$db->delete("extrafee"," where idno='".$_GET['id']."'");
				$extrafee_type=$db->getRows("select * from extrafee_type where class='".$_POST["class"]."' and session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."'");
				if(is_array($extrafee_type) && count($extrafee_type)>0){
					foreach($extrafee_type as $extrafee){
						if($_POST["stype"]==$extrafee["otype"]){
							$saveAry=array(
										"session"	=>	$_SESSION["admin"]["session"],
										"school_id"	=>	$_SESSION["admin"]["school_id"],
										"added_by"	=>	$_SESSION["admin"]["uid"],
										"type"	=>	$extrafee["id"],
										"idno"	=>	$_GET["id"],
										"pay"	=> 	0,
										"status"	=>	1
							);
							for($i=1; $i<=12;$i++){
								if($extrafee["p".$i]>"0"){
									$saveAry["pid"]="p".$i;
									$saveAry["fee"]=$extrafee["p".$i];
									$db->insertAry("extrafee",$saveAry);
								}
							}
						}elseif($extrafee["otype"]==""){
							$saveAry=array(
										"session"	=>	$_SESSION["admin"]["session"],
										"school_id"	=>	$_SESSION["admin"]["school_id"],
										"added_by"	=>	$_SESSION["admin"]["uid"],
										"type"	=>	$extrafee["id"],
										"idno"	=>	$_GET["id"],
										"pay"	=> 	0,
										"status"	=>	1
							);
							for($i=1; $i<=12;$i++){
								if($extrafee["p".$i]>"0"){
									$saveAry["pid"]="p".$i;
									$saveAry["fee"]=$extrafee["p".$i];
									$db->insertAry("extrafee",$saveAry);
								}
							}
						}
					}
				}
			}
			elseif($hasExtraFee!=""){
				if(isset($_POST["bpl"]) && $_POST["bpl"]==1){
					$flgIn1=$db->delete("extrafee", "where idno='".$_GET['id']."' and session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and type in (select id from extrafee_type where class='".$_POST["class"]."')");
				}
			
			}
			sms($_POST["mobile"],"Dear Parent Your child detail is updated successfully in ".$LinksDetails["site_name"],"student_enrollment");
			if($db->getErMsg()!=""){
				array_push($alert_err,$db->getErMsg());
			}else{
				redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"Promote", "page_id"=>$pgMod)));
			}
		}
		else
		{
			array_push($alert_err,$db->getErMsg());
		
		}
	} 
}		
elseif($pgAct=="delete" && isset($_GET['id']) && trim($_GET['id'])!='')
{
	//$flgUp=$db->updateAry("student",array("status"=>0),"where idno='".$_GET['id']."' and session='".$_SESSION["admin"]["session"]."'");
	//$flgUp=$db->updateAry("installment",array("status"=>0),"where idno='".$_GET['id']."' and session='".$_SESSION["admin"]["session"]."'");
	$flgUp=$db->delete("student","where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."' and session='".$_SESSION["admin"]["session"]."'");
	$flgUp=$db->delete("installment","where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."' and session='".$_SESSION["admin"]["session"]."'");
	
	$flgUp=$db->delete("transaction","where school_id='".$_SESSION["admin"]["school_id"]."' and rid='".$_GET['id']."' and session='".$_SESSION["admin"]["session"]."'");
	$flgUp=$db->delete("installment_time","where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."'");
	$flgUp=$db->delete("installment_fine","where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."'");
	$flgUp=$db->delete("alert","where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."'");
	$flgUp=$db->delete("notification","where school_id='".$_SESSION["admin"]["school_id"]."' and userid='".$_GET['id']."'");
	$flgUp=$db->delete("reff_receipt","where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."'");
	$flgUp=$db->delete("receipt","where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."' and session='".$_SESSION["admin"]["session"]."'");
	$flgUp=$db->delete("extrafee","where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."'");
	$flgUp=$db->delete("hostelinstallment","where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."' and session='".$_SESSION["admin"]["session"]."'");
	$flgUp=$db->delete("roomallocation","where idno='".$_GET['id']."'");
	if(!is_null($res)) { $_SESSION['msg']='Deleted Successfully'; }
	else { array_push($alert_err,$db->getErMsg()); }
	redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"Promote", "page_id"=>$pgMod)));
}
elseif($pgAct=="cancel" && isset($_GET['id']) && trim($_GET['id'])!='')
{	 $idate=date("Y-m-d");
	$flgUp=$db->updateAry("student",array("status"=>3, "added_by"=>$_SESSION["admin"]["uid"], "idate"=>$idate),"where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."' and session='".$_SESSION["admin"]["session"]."'");
	redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"Promote", "page_id"=>$pgMod)));
}
if(isset($_SESSION['msg']) && $_SESSION['msg']!="")
{
	?>
	<div class="alert alert-success">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-thumbs-up-alt"></i> <b>Notice</b><?php echo $_SESSION['msg'] ?></i>
	</div>
	<?php
	unset($_SESSION["msg"]);
}
if(is_array($alert_err) && count($alert_err)>0)
{
	?>
	<div class="alert alert-error">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-warning-sign"></i> <b>Notice</b> <?php echo $alert_err[0] ?></i>
	</div>
	<?php
}
if($pgAct=="edit" && $_GET["id"]!=""){   
	$aryForm=$db->getRow("SELECT * FROM student WHERE school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."'");
}
if($pgAct=="add" || ($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id']) !='')){
	 
	if(isset($_SESSION['form']))
	{
		$aryForm=$_SESSION['form'];
		unset($_SESSION['form']);
	}
?>
<!-- Forms --> 
<style>.top-bar-minimize{display:none;}
thead, tfoot {display: table-header-group;}
.top-bar+.well,.accordion .accordion-heading+.accordion-body{display: inline-block !important;width: 96.7% !important;overflow: inherit !important;} 
</style>
<form method="post" action="" id="printableDiv" enctype="multipart/form-data">
     <div class="row-fluid">
        <div class="span12">
            <div class="top-bar">
                <h3><i class="icon-cog"></i> Create New Admission</h3>
                 <?php if(isset($_GET["id"])){ ?><button type="button" onclick="window.location='?src=Promote&page_id=make_admission&action=cancel&id=<?php echo $_GET["id"] ?>';" class="btn btn-danger" style="margin:8px 0px 0px 600px;"> Inactive</button><?php } ?>
                <div style="float:right; margin-top:5px">
                    <button type="button" onclick="checkvalid(this)" class="btn btn-primary" id="saveformbutton"> Save</button>
                    <button type="submit" id="saveme" style="display:none" class="btn btn-primary"> Save</button>
                   
                </div>
            </div>
            <div class="well">
			<!-- Forms: Box -->
			<div class="span4">

				<!-- Forms: Top Bar -->
				
				<!-- / Forms: Top Bar -->

				<!-- Forms: Content -->
				<div class="well no-padding">

						<div class="control-group">
							<label class="control-label" for="idno">Id no</label>
							<div class="controls">
                            	<input type="hidden" name="session" value="<?php echo $_SESSION["admin"]["session"] ?>"	/> 
								<input type="text" id="idno" name="idno" readonly class="input-block-level" value="<?php
                                if($aryForm["idno"]!="")
								{
									echo $aryForm["idno"];
								}
								else{
									echo (int)($db->getVal("select max(idno) from student where school_id='".$_SESSION["admin"]["school_id"]."' ")+1);	
								}
								?>">
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="admissionclass">Admission Class</label>
							<div class="controls">
								<select class="span12" name="admissionclass"  id="admissionclass" <?php if($pgAct=="edit")echo 'disabled="disabled"'; ?> >
									<option value="">Admission Class</option>
									<?php 
										$class=$db->getRows("select * from class  where school_id='".$_SESSION["admin"]["school_id"]."'");
										foreach($class as $cla){
											?>
											<option <?php if($cla["class"]==$aryForm["admissionclass"])echo 'selected';?> value="<?php echo $cla["class"] ?>">
												<?php echo $cla["class"] ?>
                                            </option>
											<?php
										}
									?>
								</select>
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="class">Class</label>
							<div class="controls">
                            	<?php 
								$checkPay="0";
								for($i=1;$i<=12;$i++){
									$ipi="ip".$i;
									$checkFee=$db->getVal("select id from installment where school_id='".$_SESSION["admin"]["school_id"]."' and $ipi!='' and idno='".$_GET["id"]."'");	
									if($checkFee)$checkPay="1";
								}
								?>
								<select onchange="changeIns()" class="span12" name="class" id="class"  <?php if($checkPay!="0" && $pgAct=="edit")echo 'disabled="disabled"'; ?> >
									<option value="">Class</option>
                                    <?php 
										$class=$db->getRows("select * from class where  school_id='".$_SESSION["admin"]["school_id"]."'");
										foreach($class as $cla){
											?>
											<option <?php if($cla["class"]==$aryForm["class"])echo 'selected';?> value="<?php echo $cla["class"] ?>">
												<?php echo $cla["class"] ?>
                                            </option>
											<?php
										}
									?>
								</select>
                                <?php 
								if($checkPay=="0" && $pgAct=="edit"){
									?>
									<input type="hidden" name="editclass" value="yes" />
									<?php
								}
								?>
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="class">Section</label>
							<div class="controls">
								<select class="span12" name="section" id="section"  <?php /* if($checkPay!="0" && $pgAct=="edit")echo 'disabled="disabled"';*/ ?> >
									<option value="">Section</option>
                                    <?php 
										$class=$db->getRows("select * from section where  school_id='".$_SESSION["admin"]["school_id"]."'");
										foreach($class as $cla){
											?>
											<option <?php if($cla["name"]==$aryForm["section"])echo 'selected';?> value="<?php echo $cla["name"] ?>">
												<?php echo $cla["name"] ?>
                                            </option>
											<?php
										}
									?>
								</select>
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="bus">Bus Root</label>
							<div class="controls">
                            <?php 
							$checkBus="0";
							for($i=1;$i<=12;$i++){
								$bpi="bp".$i;
								$checkBusFee=$db->getVal("select id from installment where school_id='".$_SESSION["admin"]["school_id"]."' and $bpi!='' and idno='".$_GET["id"]."'");	
								//echo $db->getLastQuery()."(".$checkBusFee.")<br />";
								if($checkBusFee)$checkBus="1";
							}
							?>
								<select class="span12" onchange="buschangeIns()" name="bus" id="bus" <?php /*if($checkBus!="0" && $pgAct=="edit")echo 'disabled="disabled"';*/ ?>>
									<option value="">Bus</option>
									<?php 
										$class=$db->getRows("select * from bus where  school_id='".$_SESSION["admin"]["school_id"]."'");
										foreach($class as $cla){
											?>
											<option <?php if($cla["id"]==$aryForm["bus"])echo 'selected';?> value="<?php echo $cla["id"] ?>"><?php echo $cla["root"] ?></option>
											<?php
										}
									?>
								</select>
                                <?php 
								if($checkBus=="0" && $pgAct=="edit"){
									?>
									<input type="hidden" name="editbus" value="yes" />
									<?php
								}
								?>
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="hostel">Hostel </label>
							<div class="controls">
                            <?php 
							$checkhostel="0";
							for($i=1;$i<=12;$i++){
								$bpi="ip".$i;
								$checkhostelFee=$db->getVal("select id from hostelinstallment where school_id='".$_SESSION["admin"]["school_id"]."' and $bpi!='' and idno='".$_GET["id"]."'");	
								//echo $db->getLastQuery()."(".$checkBusFee.")<br />";
								if($checkhostelFee)$checkhostel="1";
							}
							$checkRoomHostel=$db->getVal("select hid from hostelinstallment where idno='".$_GET["id"]."' and  school_id='".$_SESSION["admin"]["school_id"]."'");
							?>
								<select class="span12" onchange="hostelchangeIns()" name="hostel" id="hostel" <?php if($checkhostel!="0" && $pgAct=="edit")echo 'disabled="disabled"'; ?>>
									<option value="">Hostel</option>
									<?php 
										$hostel=$db->getRows("select * from hostel where  school_id='".$_SESSION["admin"]["school_id"]."'");
										foreach($hostel as $hos){
											?>
											<option <?php if($hos["id"]==$checkRoomHostel)echo 'selected';?> value="<?php echo $hos["id"] ?>">
												<?php echo $hos["name"] ?>
                                            </option>
											<?php
										}
									?>
								</select>
                                <?php 
								//echo $db->getErMsg();
								if($checkhostel=="0" && $pgAct=="edit"){
									?>
									<input type="hidden" name="edithostel" value="yes" />
									<?php
								}
								?>
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="dateofadmission">Date of Admission</label>
                            <div class="controls">
                                    <input type="date" id="doa" name="doa"  class="input-block-level" value="<?php echo $aryForm["doa"]; ?>">
                                </div>
                        </div>
                       <div class="control-group">							<label class="control-label" for="sibling">Sibling</label>							<div class="controls">							<select class="span12" name="sibling[]" id="sibling" multiple="multiple">                                	<option value="">none</option>									<?php 										$student=$db->getRows("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");																				if($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id'])!='')										{									$ssid=$_GET['id'];							//	$sib_id=$db->getRows("select idno,name from student where sibling IN ('$ssid')");												//echo $ss="select idno,name from student where sibling IN ('$ssid')";										                                      $stu_sib=$db->getval("select sibling from student where idno='".$_GET['id']."'");									// print_r($stu_sib);									$csvString= "$stu_sib";									$options = explode(",", $csvString);//print_r($options);foreach($options as $val) {	//echo $val;    ${"opt".$val} = "selected=\"selected\"";		$sib_name=$db->getval("select name from student where idno='".$val."'");	?>		<option value="<?php echo $val; ?>" <?php echo $opt.$val ?> selected ><?php echo $sib_name=$db->getval("select name from student where idno='".$val."'"); ?>&nbsp;<?php echo $sib_name=$db->getval("select class from student where idno='".$val."'"); ?></option>	<?php}?>  <?php						 						 									}																			$stu_sib_arr=$db->getRows("select sibling from student where sibling!=''");												$id_sql = array();               $name_sql = array();                 foreach($stu_sib_arr as $arry)                     {                                      $name_sql[]    = $arry['sibling'];                        }                    $ids    = implode(',',$id_sql);                   $names  = implode(',',$name_sql);$sib_in_array= explode(",", $names);				                																				foreach($student as $st){																			if (in_array($st["idno"], $sib_in_array))								{								}                              else							  {																			?>											<option style="color:red;" <?php if($st["idno"]==$aryForm["sibling"])echo 'selected';?> value="<?php echo $st["idno"] ?>">												 <?php echo $st["name"]." - ".$st["class"] ?> -  <?php echo $st["mobile"] ?>                                            </option>											<?php										} }									?>								</select>							</div>						</div>
                        <div class="control-group hide">
							<label class="control-label" for="rollno">Roll no</label>
							<div class="controls">
								<input type="text" id="rollno" name="rollno" class="input-block-level" value="<?php echo $aryForm["rollno"]; ?>" >
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="rollno">Gender</label>
							<div class="controls">
								<input type="radio" id="male" name="gender"  value="male" <?php if($aryForm["gender"]=="male") echo 'checked="checked"'; ?>  >Male
                                <input type="radio" id="female" name="gender" value="female" <?php if($aryForm["gender"]=="female") echo 'checked="checked"'; ?> >FeMale
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="admissionno">Admission no</label>
							<div class="controls">
								<input type="text" id="admissionno" name="admissionno" class="input-block-level" value="<?php 
								if($pgAct=="add"){$addno=array();
									$newAddno=$db->getRows("select admissionno from student");
									foreach($newAddno as $new){
										$addno[]=$new["admissionno"];
									}
									$noo=max($addno);
									$noo=$noo+1;
									echo $noo;
								}
								else
								echo $aryForm["admissionno"]; ?>" >
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="medium">Medium</label>
							<div class="controls">
								<select class="span12" name="medium" id="medium">
									<option <?php if("english"==$aryForm["medium"])echo 'selected';?> value="english">English</option>
                                    <option <?php if("hindi"==$aryForm["medium"])echo 'selected';?> value="hindi">Hindi</option>
								</select>
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="stype">Student type</label>
							<div class="controls">
								<select class="span12" name="stype" id="stype">
                                <option <?php if("new"==$aryForm["stype"])echo 'selected';?> value="new">New</option>
									<option <?php if("old"==$aryForm["stype"])echo 'selected';?> value="old">Old</option>
									
								</select>
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="old_school">Bus Detail</label>
							<div class="controls">
								<select class="span12" name="old_school" id="old_school">
                                	<option value="">none</option>
									<?php 
										$location=$db->getRows("select * from bus_detail where school_id='".$_SESSION["admin"]["school_id"]."'");
										if(is_array($location) && count($location)>0){
											foreach($location as $loc){
												?>
												<option <?php if($loc["id"]==$aryForm["old_school"])echo 'selected';?> value="<?php echo $loc["id"] ?>">
													<?php echo $loc["name"] ?>
												</option>
												<?php
											}
										}
									?>
								</select>
							</div>
						</div>
                        <!--<div class="control-group">
							<label class="control-label" for="sssmid">SSSMID</label>
							<div class="controls">
								<input type="text" id="sssmid" name="sssmid" class="input-block-level" value="<?php echo $aryForm["sssmid"]; ?>" >
							</div>
						</div>-->
                         <div class="control-group">
							<label class="control-label" for="sssmid">House</label>
							<div class="controls">
								<select class="span12" name="sssmid" id="sssmid">
                                	<option value="">Select House</option>
									<option value"1" <?php if($aryForm["sssmid"]==1)echo 'selected';?>>Rig</option>
                                    <option value="2" <?php if($aryForm["sssmid"]==2)echo 'selected';?>>Atharva</option>
                                    <option value="3" <?php if($aryForm["sssmid"]==3)echo 'selected';?>>Sama</option>
                                    <option value="4" <?php if($aryForm["sssmid"]==4)echo 'selected';?>>Yajur</option>
								</select>
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="location">Location</label>
							<div class="controls">
								<select class="span12" name="location" id="location">
                                	<option value="">none</option>
									<?php 
										$location=$db->getRows("select * from location where school_id='".$_SESSION["admin"]["school_id"]."'");
										if(is_array($location) && count($location)>0){
											foreach($location as $loc){
												?>
												<option <?php if($loc["id"]==$aryForm["location"])echo 'selected';?> value="<?php echo $loc["id"] ?>">
													<?php echo $loc["name"] ?>
												</option>
												<?php
											}
										}
									?>
								</select>
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="height">Height</label>
							<div class="controls">
								<input type="text" id="height" name="height" class="input-block-level" value="<?php echo $aryForm["height"]; ?>" >
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="weight">Weight</label>
							<div class="controls">
								<input type="text" id="weight" name="weight" class="input-block-level" value="<?php echo $aryForm["weight"]; ?>" >
							</div>
						</div>
						
				</div>
				<!-- / Forms: Content -->

			</div>
			<!-- / Forms: Box -->
			<!-- Forms: Box -->
			<div class="span4">

				<!-- Forms: Top Bar -->
				
				<!-- / Forms: Top Bar -->

				<!-- Forms: Content -->
				<div class="well no-padding">

					<!-- Forms: Form -->
                    
						<div class="control-group">
							<label class="control-label" for="name">Student Name</label>
							<div class="controls">
								<input type="text" id="name" name="name" class="input-block-level" value="<?php echo $aryForm["name"]; ?>" >
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="rollno">Date of Birth</label>
                            <div class="controls">
                                    <input type="date" id="dob" name="dob"  class="input-block-level" value="<?php echo $aryForm["dob"]; ?>">
                                </div>
                        </div>
	 					<div class="control-group">
							<label class="control-label" for="fname">Father Name</label>
							<div class="controls">
								<input type="text" id="fname" name="fname" class="input-block-level" value="<?php echo $aryForm["fname"]; ?>" >
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="foccupation">Fathers Occupation</label>
							<div class="controls">
								<input type="text" id="foccupation" name="foccupation" class="input-block-level" value="<?php echo $aryForm["foccupation"]; ?>" >
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="feducation">Blood group</label>
							<div class="controls">
								<input type="text" id="feducation" name="feducation" class="input-block-level" value="<?php echo $aryForm["feducation"]; ?>" >
							</div>
						</div>
                        
                        <div class="control-group">
							<label class="control-label" for="mname">Mother Name</label>
							<div class="controls">
								<input type="text" id="mname" name="mname" class="input-block-level" value="<?php echo $aryForm["mname"]; ?>" >
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="meducation">Adhar no</label>
							<div class="controls">
								<input type="text" id="meducation" name="meducation" class="input-block-level" value="<?php echo $aryForm["meducation"]; ?>" >
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="fincome">Conatct no</label>
							<div class="controls">
								<input type="text" id="mincome" name="mincome" class="input-block-level" value="<?php echo $aryForm["mincome"]; ?>" >
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="fincome">Bank Account no</label>
							<div class="controls">
								<input type="text" id="fincome" name="fincome" class="input-block-level" value="<?php echo $aryForm["fincome"]; ?>" >
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="cast">Cast</label>
							<div class="controls">
								<input type="text" id="cast" name="cast" class="input-block-level" value="<?php echo $aryForm["cast"]; ?>" >
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="email">E-mail</label>
							<div class="controls">
								<input type="email" id="email" name="email" class="input-block-level" value="<?php echo $aryForm["email"]; ?>" >
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="mobile">Mobile</label>
							<div class="controls">
								<input type="text" id="mobile" name="mobile" class="input-block-level" value="<?php echo $aryForm["mobile"]; ?>" >
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="address">Address</label>
							<div class="controls">
							<textarea rows="3" class="span12" name="address" id="address"><?php echo $aryForm["address"]; ?></textarea>
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="hygiene">Dental hygiene</label>
							<div class="controls">
								<input type="text" id="hygiene" name="hygiene" class="input-block-level" value="<?php echo $aryForm["hygiene"]; ?>" >
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="discount_mode">Discount Mode</label>
							<div class="controls">
								<select class="span12" name="discount_mode" id="discount_mode">
                                	<option value="">none</option>
									<?php 
										$location=$db->getRows("select * from discount_mode where school_id='".$_SESSION["admin"]["school_id"]."'");
										if(is_array($location) && count($location)>0){
											foreach($location as $loc){
												?>
												<option <?php if($loc["name"]==$aryForm["discount_mode"])echo 'selected';?> value="<?php echo $loc["name"] ?>">
													<?php echo $loc["name"] ?>
												</option>
												<?php
											}
										}
									?>
								</select>
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="class">Is BPL student</label>
							<div class="controls">
                            	<input <?php if($aryForm["bpl"]==1)echo 'checked="checked"'; ?>  type="checkbox" <?php if($checkPay!="0" && $pgAct=="edit")echo 'disabled="disabled"'; ?> value="1" name="bpl" /> check if student is BPL
							</div>
						</div>
						<!-- Forms: Form Actions -->
						
						<!-- / Forms: Form Actions -->
	 
					<!-- / Forms: Form -->           

				</div>
				<!-- / Forms: Content -->

			</div>
			<!-- / Forms: Box -->
            <!-- Forms: Box -->
			<div class="span4">

				<!-- Forms: Top Bar -->
				
				<!-- / Forms: Top Bar -->

				<!-- Forms: Content -->
				<div class="well no-padding">

					<!-- Forms: Form -->
						<!-- Forms: Normal input field -->
                        <?php
						if($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id']) !=''){
							$aryInstall=$db->getRow("select * from installment where idno='".$aryForm["idno"]."'");
							?>
                            <div class="control-group">
                                <label class="control-label" for="photo">Photo</label>
                                <div class="controls">
                                	<?php if($aryForm["photo"]!=""){
										?><img src="media/photo/<?php echo $aryForm["photo"]; ?>" height="30px" /><?php
									}?>
                                    <a href="javascript:;" onclick="$('#photo').click()">Change Photo</a>
                                    <input type="file" name="photo" style="display:none" id="photo"/>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="TC">TC</label>
                                <div class="controls">
                                	<?php if($aryForm["TC"]!=""){
										?><a id="TC" href="media/TC/<?php echo $aryForm["TC"]; ?>">Download TC</a><?php
									}else{
										echo "No TC Found";
									}?>
                                </div>
                            </div>
							<div class="control-group">
                            	<?php 
								$insTall=$db->getRow("select * from installment where idno='".$_GET["id"]."'");
								if(is_array($insTall) && count($insTall)>0){
								?>
                                <div id="ins">
                                <table class="table">
                                	<tr>
                                		<th>Fee for</th>
                                        <th>Installmnt</th>
                                        <th>Payment</th>
                               		</tr>
                                    <?php
									for($i=1;$i<=12;$i++){
										$classfees="i".$i;
										$classpayfees="ip".$i;
										if($aryInstall[$classfees]!="" && $aryInstall[$classfees]!=0){
											if($checkPay=="0" && $pgAct=="edit"){
												?>
												<tr>
                                                    <td>Class fee <?php echo $i; ?></td>
                                                    <td colspan="2"><input readonly="readonly" class="input-block-level busfeeInsCharge" type="text" value="<?php echo $aryInstall[$classfees]; ?>" name="fee[]" id="fee<?php echo $i;?>" /></td>
                                                </tr>
                                            	<?php
											}else{
										?>
										<tr>
                                        	<td>Class fee <?php echo $i; ?></td>
                                            <td><?php echo $aryInstall[$classfees]; ?></td>
                                            <td><?php 	if(trim($aryInstall[$classpayfees])=="" || trim($aryInstall[$classpayfees])==0)
															echo "<font color='#FF0000'>Due</font>";
														else 
															echo $aryInstall[$classpayfees]; ?></td>
                                        </tr>
										<?php
											}
										}
									}
									?>
									<tr>
                                    	<td>Class Total Discount</td>
                                        <td><?php echo $aryInstall["discount"]; ?></td>
                                        <td></td>
                                    </tr>
                                    <tr style="border-bottom:2px solid #F00">
                                    	<td>Class Total Fee</td>
                                        <td><?php echo $aryInstall["total"]; ?></td>
                                        <td></td>
                                    </tr>
                                 </table>
                                 <input type="hidden" name="feetotal" value="<?php echo $aryInstall["total"] ?>" />
                                    <input value="<?php echo $aryInstall["discount"] ?>" type="hidden" name="discount" />
                                </div>
                                 <div id="busins">
                                 <table class="table">
									<?php
									for($i=1;$i<=12;$i++){
										$busfees="b".$i;
										$buspayfees="bp".$i;
										if($aryInstall[$busfees]!="" && $aryInstall[$busfees]!=0){											
											if($checkBus=="0" && $pgAct=="edit"){
												?>
												<tr>
                                                    <td>Bus fee <?php echo $i; ?></td>
                                                    <td colspan="span2"><input readonly="readonly" class="input-block-level busfeeInsCharge" type="text" value="<?php echo $aryInstall[$busfees]; ?>" name="busfee[]" id="busfee<?php echo $i;?>" /></td>
                                                </tr>
                                            <?php
											}else{
										?>
										<tr>
                                        	<td>Bus fee <?php echo $i; ?></td>
                                            <td><?php echo $aryInstall[$busfees]; ?></td>
                                            <td><?php 	if(trim($aryInstall[$buspayfees])=="" || trim($aryInstall[$buspayfees])==0)
															echo "<font color='#FF0000'>Due</font>";
														else 
															echo $aryInstall[$buspayfees]; ?></td>
                                        </tr>
										<?php
											}
										}
									}
									?>
                                    
                                    <tr>
                                    	<td>Bus Total Discount</td>
                                        <td><?php echo $aryInstall["busdiscount"]; ?></td>
                                        <td></td>
                                    </tr>
                                    <tr>
                                    	<td>Bus Total Fee</td>
                                        <td><?php echo $aryInstall["bus"]; ?></td>
                                        <td></td>
                                    </tr>
                                 </table>
                                 <input type="hidden" name="busfeetotal" value="<?php echo $aryInstall["bus"] ?>" />
                                    <input value="<?php echo $aryInstall["busdiscount"] ?>" type="hidden" name="busdiscount" />
                                 </div>
                                 <?php
								 }else{
									 echo "Due to Transfer this student from one session to another Payment setup is not completed yet
									 <br /> Please <a href='".URL_ROOT."?src=Promote&page_id=pay_fee&action=add&id=".$_GET["id"]."'>Click Here</a> to set fee stucture for this student ";
									 //redirect(URL_ROOT."?page_id=pay_fee&action=add&id=".$_GET["id"]);
								 }
								 ?>
                            </div>
							<div class="control-group">
                            <div id="hostelins">
                            	<?php 
								$hostelinsTall=$db->getRow("select * from hostelinstallment where idno='".$_GET["id"]."'");
								if(is_array($hostelinsTall) && count($hostelinsTall)>0){
								?>
                                
                                <table class="table">
                                	<tr>
                                		<th>Fee for</th>
                                        <th>Installmnt</th>
                                        <th>Payment</th>
                               		</tr>
                                    <?php
									for($i=1;$i<=12;$i++){
										$hostelfees="i".$i;
										$hostelpayfees="ip".$i;
										if($hostelinsTall[$hostelfees]!="" && $hostelinsTall[$hostelfees]!=0){
											if($checkhostel=="0" && $pgAct=="edit"){
												?>
												<tr>
                                                    <td>Hostel fee <?php echo $i; ?></td>
                                                    <td colspan="2"><input readonly="readonly" class="input-block-level hostelfeeInsCharge" type="text" value="<?php echo $hostelinsTall[$hostelfees]; ?>" name="hostelfee[]" id="hostelfee<?php echo $i;?>" /></td>
                                                </tr>
                                            	<?php
											}else{
										?>
										<tr>
                                        	<td>Hostel fee <?php echo $i; ?></td>
                                            <td><?php echo $hostelinsTall[$hostelfees]; ?></td>
                                            <td><?php 	if(trim($hostelinsTall[$hostelpayfees])=="" || trim($hostelinsTall[$hostelpayfees])==0)
															echo "<font color='#FF0000'>Due</font>";
														else 
															echo $hostelinsTall[$hostelpayfees]; ?></td>
                                        </tr>
										<?php
											}
										}
									}
									?>
									<tr>
                                    	<td>Hostel Total Discount</td>
                                        <td><?php echo $hostelinsTall["discount"]; ?></td>
                                        <td></td>
                                    </tr>
                                    <tr style="border-bottom:2px solid #F00">
                                    	<td>Hostel Total Fee</td>
                                        <td><?php echo $hostelinsTall["total"]; ?></td>
                                        <td></td>
                                    </tr>
                                 </table>
                                 <input type="hidden" name="hostelfeetotal" value="<?php echo $hostelinsTall["total"] ?>" />
                                    <input value="<?php echo $hostelinsTall["discount"] ?>" type="hidden" name="hosteldiscount" />
                                 <?php
								 }
								 ?>
                                 </div>
                            </div>
							<?php
						}else{?>
                        <div class="control-group">
							<label class="control-label" for="photo">Photo</label>
							<div class="controls">
								<input type="file" name="photo" id="photo"/>
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="TC">TC</label>
							<div class="controls">
								<input type="file" name="TC" id="TC"/>
							</div>
                        </div>
                        <div id="ins">
                            
                        </div>
                        <div id="busins">
                        
                        </div>
                        <div id="hostelins">
                        
                        </div>
                        <?php 
						}?>
						<!-- / Forms: Normal input field -->


						<!-- Forms: Form Actions -->
						
						<!-- / Forms: Form Actions -->
	 
					<!-- / Forms: Form -->           

				</div>
				<!-- / Forms: Content -->

			</div>
			<!-- / Forms: Box -->
            </div>
        </div>
        
	</div>
</form>
<!-- / Forms -->
<?php
}
else{
	?>
    <script>
    </script>
	<div class="row-fluid"><div class="span12"><div class="top-bar">
    <h3><i class="icon-eye-open"></i> <?php echo ucwords($pgAct." ".$pgMod); ?></h3>
    <button style="float:right; margin-top:5px" onclick="window.location='./?src=Promote&page_id=<?php echo $pgMod; ?>&action=add'" class="btn" type="button">Add <?php echo $pgMod; ?></button>
    </div>
    <div class="well no-padding">
	<?php
	$aryPgAct=array("src"=>"Promote", "page_id"=>$pgMod,"action"=>"add");
	$aryList=$db->getRows("select idno from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 order by name");
	if(is_array($aryList) && count($aryList)>0)
	{
		?>
        <div style="position: absolute;width:300px;z-index: 99999;margin: 30px;">
        	<select onchange="fetchByClass()" class="span6" name="class" id="class" >
                <option value="">Class</option>
                <?php 
                    $class=$db->getRows("select * from class where school_id='".$_SESSION["admin"]["school_id"]."'");
                    foreach($class as $cla){
                        ?>
                        <option value="<?php echo $cla["class"] ?>">
                            <?php echo $cla["class"] ?>
                        </option>
                        <?php
            
                    }
                ?>
            </select>
            <select onchange="fetchByClass()" class="span6" name="section" id="section" >
                <option value="">Section</option>
                <?php 
                    $class=$db->getRows("select * from section where school_id='".$_SESSION["admin"]["school_id"]."'");
                    foreach($class as $cla){
                        ?>
                        <option value="<?php echo $cla["name"] ?>">
                            <?php echo $cla["name"] ?>
                        </option>
                        <?php
            
                    }
                ?>
            </select>
         </div>
        <input type="hidden" id="tabletype" value="makeadmission_data" />
        <table class="table" id="ajaxtable">
            <thead>
                <tr>
                    <!--<th>Serial No</th>-->
                   <th width="10%">Admission no</th>
                    <th width="20%">Name</th>
                    <th>Class</th>
                    <th>Medium</th>
                    
                    <th>Bus Root</th>
                    <th>Cast</th>
                    <th>Father</th>
                    <!--<th>Mobile</th>-->
                    <th>Action</th>
                </tr>
            </thead>
            <tfoot>
            </tfoot>
            <tbody>
           
            </tbody>
        </table>
		<?php
	}
	else{
		?>
        <div class="alert alert-info">
          <a class="close" data-dismiss="alert">×</a>
          <i class="icon icon-warning-sign"></i> <b>Notice</b> Record not found </i>
        </div>
        <?php
	}
	?>
	</div></div></div>
	<?php
}
?>
<!-- / Forms -->
<script type="text/javascript">
$(document).ready(function(e) {
    var oTable = $('#ajaxtable').dataTable( {
		"bProcessing": true,
		'sPaginationType': 'full_numbers',
		"sAjaxSource": 'ajax.php?type='+$('#tabletype').val(),
		'iDisplayLength': 5,
		"oLanguage": {
			"sSearch": "Search by any columns:"
		}
	});
});
function fetchByClass(){
	var name=$("#class").val();
	var section=$("#section").val();
	if(name!=""){
		var url='ajax.php?class='+name+'&type='+$('#tabletype').val();
		if(section!=""){
			url+='&section='+section
		}
		 oTable = $('#ajaxtable').dataTable( {
			"bProcessing": true,
			'sPaginationType': 'full_numbers',
			"bServerSide": false,
			"bDestroy":true,
			"sAjaxSource": url,
			'iDisplayLength': 5,
			"oLanguage": {
				"sSearch": "Search by any columns:"
			}
		});
	}else{
		var oTable = $('#ajaxtable').dataTable( {
			"bProcessing": true,
			'sPaginationType': 'full_numbers',
			"bServerSide": false,
			"bDestroy":true,
			"sAjaxSource": 'ajax.php?type='+$('#tabletype').val(),
			'iDisplayLength': 5,
			"oLanguage": {
				"sSearch": "Search by any columns:"
			}
		});
	}
}
function checkform(){
	var data="name="+$("#name").val()+"&dob="+$("#dob").val()+"&fname="+$("#fname").val()+"&mname="+$("#mname").val()+"&cast="+$("#cast").val()+"&mobile="+$("#mobile").val();
	$.post( "ajax.php?"+data, { type: "PreCheckExist"} , function( data ) {
		//alert(data);
	  	if(data=="0"){
			$("#saveme").click();
		}else{
			alert(data);
			if(confirm("are you sureyou want to register a this student?")){
				$("#saveme").click();
			}else{
				if(confirm("You want to add new student?")){
					window.location='?src=Promote&page_id=make_admission&action=add';
				}else{
					window.location='?src=Promote&page_id=make_admission';
				}
			}
		}
	});
	return false;
}
function changeIns(){
	var cla=$("#class").val();
	$.post( "ajax.php", { type: "classinstallment" ,class: cla } , function( data ) {
	  	$("#ins").html(data);
		getTotal();
	});
}
function buschangeIns(){
	var bus=$("#bus").val();
	if(bus==""){
		$("#busins").html('');
	}else{
		$.post( "ajax.php", { type: "businstallment", bus: bus } , function( data ) {
			$("#busins").html(data);
			getbusTotal();
		});
	}
}
function hostelchangeIns(){
	var hostel=$("#hostel").val();
	if(hostel==""){
		$("#hostelins").html('');
	}else{
		$.post( "ajax.php", { type: "hostelinstallment", hostel: hostel } , function( data ) {
			$("#hostelins").html(data);
			gethostelTotal();
		});
	}
}
function getTotal(){
	var sum=0;var classfee=0;var busfee=0;
	var cost = document.getElementsByName('fee[]');
	classfee=$('#classfee').val();
	for(var i=0;i<cost.length;i++)
	{
		sum = parseFloat(sum) + parseFloat(cost[i].value);
	}
	$('#feetotal').val(parseInt(sum));
	$('#oldtotal').val(parseInt(sum));
}
function getbusTotal(){
	var sum=0;var classfee=0;var busfee=0;
	var cost = document.getElementsByName('busfee[]');
	classfee=$('#busclassfee').val();
	for(var i=0;i<cost.length;i++)
	{
		sum = parseFloat(sum) + parseFloat(cost[i].value);
	}
	$('#busfeetotal').val(parseInt(sum));
	$('#busoldtotal').val(parseInt(sum));
}
function gethostelTotal(){
	var sum=0;var hostelfee=0;
	var cost = document.getElementsByName('hostelfee[]');
	hostelfee=$('#hostelclassfee').val();
	for(var i=0;i<cost.length;i++)
	{
		sum = parseFloat(sum) + parseFloat(cost[i].value);
	}
	$('#hostelfeetotal').val(parseInt(sum));
	$('#hosteloldtotal').val(parseInt(sum));
}
function updateIns(){
	var sum=0;
	 var discountAmt=$("#discount").val();
	 var TotalAmt=$('#oldtotal').val();
	 var RestedAmt=TotalAmt-discountAmt;
	 var cost = document.getElementsByName('fee[]');
	 if(RestedAmt<=0){
		alert("Discount Cannot Greater Then Total Fees"+TotalAmt);
		$("#discount").val(0);
		var DevidedAmt = (TotalAmt/(cost.length));
		$('.feeInsCharge').val(DevidedAmt);
	}else{
		var DevidedAmt = (RestedAmt/(cost.length));
		$('.feeInsCharge').val(DevidedAmt);
	}
	for(var i=0;i<cost.length;i++)
	{
		sum = parseFloat(sum) + parseFloat(cost[i].value);
	}
	$('#feetotal').val(parseInt(sum));
}
function busupdateIns(){
	var sum=0;
	 var discountAmt=$("#busdiscount").val();
	 var TotalAmt=$('#busoldtotal').val();
	 var RestedAmt=TotalAmt-discountAmt;
	 var cost = document.getElementsByName('busfee[]');
	 if(RestedAmt<=0){
		alert("Discount Cannot Greater Then Total Fees"+TotalAmt);
		$("#busdiscount").val(0);
		var DevidedAmt = (TotalAmt/(cost.length));
		$('.busfeeInsCharge').val(DevidedAmt);
	}else{
		var DevidedAmt = (RestedAmt/(cost.length));
		$('.busfeeInsCharge').val(DevidedAmt);
	}
	for(var i=0;i<cost.length;i++)
	{
		sum = parseFloat(sum) + parseFloat(cost[i].value);
	}
	$('#busfeetotal').val(parseInt(sum));
}
function hostelupdateIns(){
	var sum=0;
	var discountAmt=$("#hosteldiscount").val();
	var TotalAmt=$('#hosteloldtotal').val();
	var RestedAmt=TotalAmt-discountAmt;
	var cost = document.getElementsByName('hostelfee[]');
	if(RestedAmt<=0){
		alert("Discount Cannot Greater Then Total Fees"+TotalAmt);
		$("#hosteldiscount").val(0);
		var DevidedAmt = (TotalAmt/(cost.length));
		$('.hostelfeeInsCharge').val(DevidedAmt);
	}else{
		var DevidedAmt = (RestedAmt/(cost.length));
		$('.hostelfeeInsCharge').val(DevidedAmt);
	}
	for(var i=0;i<cost.length;i++)
	{
		sum = parseFloat(sum) + parseFloat(cost[i].value);
	}
	$('#hostelfeetotal').val(parseInt(sum));
}
function getsibling(id){
	$.post( "ajax.php", { type: "getsibling", id: id } , function( data ) {
	  	alert(data);
	});
}
function checkvalid(id){
	if($("#name").val()=="")
		alert("student name cannot blank");
	else
	if($("#fname").val()=="")
		alert("student fathers name cannot blank")
	else
	if($("#class").val()=="")
		alert("please select student class")
	else
	{
		$("#saveformbutton").hide();
		$("#saveme").click();
	}
}
</script>