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


if($_POST)
{
	$_SESSION['form']=$_POST;
	//$section=$_POST["section"];unset($_POST["section"]);
		
	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($flgEr!=TRUE && $pgAct=="add")
	{
		$_POST["school_id"]=$_SESSION["admin"]["school_id"];
        $_POST["added_by"]=$_SESSION["admin"]["uid"];
		$flgIn=$db->insertAry("enquiry",$_POST);
		if(!is_null($flgIn))
		{
			$_SESSION['msg']='Saved Successfully';
			unset($_SESSION['form']);
			sms($_POST["mobile"],"Dear Parent Your admission enquiry is successfully submitted 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'])!='')
	{		
		$flgUp=$db->updateAry("enquiry",$_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']);
			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("enquiry","where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."' and session='".$_SESSION["admin"]["session"]."'");
	$where="where rid=".$_GET["id"]." and session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."'";
		$res=$db->delete("transaction","$where");
	if(!is_null($flgUp)) { $_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("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 enquiry 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='?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 enquiry where school_id='".$_SESSION["admin"]["school_id"]."' ")+1);	
								}
								?>">
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="class">Admission Class</label>
							<div class="controls">
								<select class="span12" name="class"  id="class" <?php /*if($pgAct=="edit")echo 'disabled="disabled"';*/ ?> required>
									<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["class"])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 Enquiry</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" onchange="getsibling(this.value)" name="sibling" id="sibling">
                                	<option value="">none</option>
									<?php 
										$student=$db->getRows("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
										foreach($student as $st){
											?>
											<option <?php if($st["idno"]==$aryForm["sibling"])echo 'selected';?> value="<?php echo $st["idno"] ?>">
												 <?php echo $st["name"]." - class ".$st["class"] ?> - idno <?php echo $st["idno"] ?>
                                            </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"){
									$newAddno=$db->getVal("select max(admissionno) from student");
									echo $newAddno+1;
								}
								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="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">Rashan 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="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 -->
                        <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="test_date">Date of Test</label>
                            <div class="controls">
                                    <input type="date" id="test_date" name="test_date"  class="input-block-level" value="<?php echo $aryForm["test_date"]; ?>">
                                </div>
                        </div>
                        <div class="control-group">
							<label class="control-label" for="test_time">Time of Test</label>
                            <div class="controls">
                                    <input type="time" id="test_time" name="test_time"  class="input-block-level" value="<?php echo $aryForm["test_time"]; ?>">
                                </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">Remarks</label>
							<div class="controls">
								<select class="span12" name="discount_mode" id="discount_mode">
                                	<option value="">none</option>
									<?php 
										$location=$db->getRows("select * from remarks 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="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>
                       
						<!-- / 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 enquiry where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 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>
            
         </div>
        <input type="hidden" id="tabletype" value="enquiry_data" />
        <table class="table" id="ajaxtable">
            <thead>
                <tr>
                    <!--<th>Serial No</th>-->
                   <th width="10%">S.no</th>
                    <th width="20%">Name</th>
                    <th>Class</th>
                    <th>Father</th>
                    <th>Mobile</th>
                    <th>remarks</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": 'Enquiry/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='?page_id=make_admission&action=add';
				}else{
					window.location='?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>