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

if($_POST)
{
    // echo "Select amount from transaction where detail like 'Enquiryfee%' and rid=".$_POST["idno"]." and session='".$_POST["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and tid='".$_POST["detail"]."'";
    // print_r($_POST); 
    // die();

	$_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")
	{
	    if($_POST["discount_mode"]!="Purchased Application"){
	       $_POST["application_no"] = "";
	       $_POST["detail"] = "";
	    }

		$_POST["school_id"]=$_SESSION["admin"]["school_id"];
        $_POST["added_by"]=$_SESSION["admin"]["uid"];
		$flgIn=$db->insertAry("enquiry",$_POST);
		if(!is_null($flgIn))
		{
	    if($_POST["discount_mode"] == "Purchased Application"){
		   $trn=$db->getVal("Select amount from transaction where detail like 'Enquiryfee%' and rid=".$_POST["idno"]." and session='".$_POST["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and tid='".$_POST["detail"]."'");
			if(!$trn) {
                $data = array(
                     'rid'      =>  $_POST["idno"],
					 'tid'      =>  $_POST["detail"],
					 'tfor'     =>  "cash",
					 'type'     =>  "deposit",
					 'amount'   =>  $_POST["amount"],
					 'status'   =>  1,
					 "school_id"=>  $_SESSION["admin"]["school_id"],
					 "added_by" =>  $_SESSION["admin"]["uid"],
					 'session'  =>  $_POST["session"],
					 'detail'   =>  "Enquiryfee ".$_POST["detail"]
					 );
        	$did = $db->insertAry('transaction',$data);

			if($did > 0){ ?>

    	    <script>
        	    var name = "0"; var bus = "0"; var hostel = "0"; var hostelFine = "0"; var busFine = "0"; var nameFine = "0"; var msg = "Enquiry";
    	        var given  = '<?php echo $_POST["amount"]; ?>';
    	        var data = '<?php echo $did; ?>';
    	        var reasion = '<?php echo $_POST["detail"]; ?>';
        		getPopup("<?php echo URL_ROOT ?>print/?page_id=enquiry_recepitNew&idno=<?php echo $_POST["idno"]."&udate=".date("Y-m-d")."&amount="; ?>"+given+"&type=fee&fee-Tution%20Fees="+name+"&fee-Bus%20Fees="+bus+"&fee-Hostel%20Fees="+hostel+"&fee-Hostel%20Fine="+hostelFine+"&fee-Bus%20Fine="+busFine+"&fee-Tution%20Fine="+nameFine+"&rrid=rrid-"+data+"&fee-"+reasion+"="+given+"&paytype=classfee&detail=pay fee for "+reasion+"&class=<?php echo $_POST["apply_class"]; ?>&install=1&total="+given,"1","recepit");
            	$(".close").click(function() {
            		$(this).parent().remove();
            	    // location.reload();
            	    window.location.href = '?src=Enquiry&page_id=enquiry';
            	});
            	$(".outer").click(function() {
            		$(this).remove();
                    // location.reload();
                    window.location.href = '?src=Enquiry&page_id=enquiry';
            	});
    	    </script>
			    
			    <?php
			}

			}
			else { echo " You Can not pay with same name..! Please try again"; }
			
		}
		    else {
    			$_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"=>"Enquiry","page_id"=>$pgMod)));
    			}
            }
		}
		else
		{
			array_push($alert_err,$db->getErMsg());
		}
	}
	elseif($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id'])!='')
	{		

	    if($_POST['discount_mode'] == "Admitted"){

    //             $years=explode("-",$_POST["session"]);
			 //   $year = $years[0];
			 //   $newstring = substr($year, -2);
				// $s = $db->getVal("SELECT admissionno from student order by idno DESC");
				// $noo = strstr($s, '-', true);
				// $noo=$noo+1;
				// $admissionno = "$noo-$newstring";

					$admno = $db->getVal("SELECT admissionno from student ORDER by idno DESC LIMIT 1");
                    $session = explode("-",$_SESSION["admin"]["session"]);
                    
                    $newadm = explode("/",$admno);
                    $newAdmission = $newadm[0]+1;
                    
                    $sess = str_replace("20","",$session[0]);
                    $admissionno = trim($newAdmission."/".$sess);
				

                    $a = $_SERVER['HTTP_HOST'];
                    $school = "";
                    if (strpos($a, '.savarnacloud.com') !== false) {
                        $school = str_replace(".savarnacloud.com","",$a);
                    }
                    elseif (strpos($a, '.savarna.in') !== false) {
                        $school = str_replace(".savarna.in","",$a);
                    }

                    $randompwd = $school.rand(1000,9999);

        $idno = (int)($db->getVal("select max(idno) from student where school_id='".$_SESSION["admin"]["school_id"]."' ")+1);
	        $studata = array(
	                "idno"              => $idno,
	                "name"              => $_POST['name'],
	                "admissionclass"    => $_POST['apply_class'],
	                "admissionno"       => $admissionno,
	                "class"             => $_POST['apply_class'],
	                "section"           => "",
	                "gender"            => $_POST['gender'],
	                "medium"            => $_POST['medium'],
	                "email"             => $_POST['email'],
	                "old_school"        => $_POST['old_school'],
	                "dob"               => $_POST['dob'],
	                "fname"             => $_POST['fname'],
	                "foccupation"       => $_POST['foccupation'],
	                "moccupation"       => $_POST['moccupation'],
	                "mname"             => $_POST['mname'],
	                "mobile"            => $_POST['mobile'],
	                "address"           => $_POST['address'],
	                "stype"             => "new",
	                "mincome"           => $_POST['reg_no'],
	                "password"          => $randompwd,
	                "session"           => $_POST["session"],
	                "school_id"         => $_SESSION["admin"]["school_id"],
	                "added_by"          => $_SESSION["admin"]["uid"]
	            );
	            
	            $flgIn = $db->insertAry("student", $studata);
	            
				$instalmentAry=array("idno"     =>  $idno,
									 "class"    =>  $_POST['apply_class'],
									 'session'  =>  $_POST["session"],
									 "status"   =>  1,
									 "school_id"=>  $_SESSION["admin"]["school_id"],
									 "added_by" =>  $_SESSION["admin"]["uid"],
				);
				$i=0;$j=0;
				$installmentClass=$db->getRow("select installment,fee from class where class='".$_POST['apply_class']."'");
				$classins=($installmentClass["fee"]/$installmentClass["installment"]);
				for($i=1;$i<=$installmentClass["installment"];$i++){
					$list="i".$i;
					$instalmentAry[$list]=$classins;	
				}

				$instalmentAry["total"]=$installmentClass["fee"];

				$db->insertAry("installment",$instalmentAry);
	        
	    }
		$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))
		{
    	    if($_POST["discount_mode"] == "Purchased Application"){
		   $trn=$db->getVal("Select amount from transaction where detail like 'Enquiryfee%' and rid=".$_POST["idno"]." and session='".$_POST["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and tid='".$_POST["detail"]."'");
			if(!$trn) {
                $data = array(
                     'rid'      =>  $_POST["idno"],
					 'tid'      =>  $_POST["detail"],
					 'tfor'     =>  "cash",
					 'type'     =>  "deposit",
					 'amount'   =>  $_POST["amount"],
					 'status'   =>  1,
					 "school_id"=>  $_SESSION["admin"]["school_id"],
					 "added_by" =>  $_SESSION["admin"]["uid"],
					 'session'  =>  $_POST["session"],
					 'detail'   =>  "Enquiryfee ".$_POST["detail"]
					 );
        	$did = $db->insertAry('transaction',$data);

			if($did > 0){ ?>

    	    <script>
        	    var name = "0"; var bus = "0"; var hostel = "0"; var hostelFine = "0"; var busFine = "0"; var nameFine = "0"; var msg = "Enquiry";
    	        var given  = '<?php echo $_POST["amount"]; ?>';
    	        var data = '<?php echo $did; ?>';
    	        var reasion = '<?php echo $_POST["detail"]; ?>';
        		getPopup("<?php echo URL_ROOT ?>print/?page_id=enquiry_recepitNew&idno=<?php echo $_POST["idno"]."&udate=".date("Y-m-d")."&amount="; ?>"+given+"&type=fee&fee-Tution%20Fees="+name+"&fee-Bus%20Fees="+bus+"&fee-Hostel%20Fees="+hostel+"&fee-Hostel%20Fine="+hostelFine+"&fee-Bus%20Fine="+busFine+"&fee-Tution%20Fine="+nameFine+"&rrid=rrid-"+data+"&fee-"+reasion+"="+given+"&paytype=classfee&detail=pay fee for "+reasion+"&class=<?php echo $_POST["apply_class"]; ?>&install=1&total="+given,"1","recepit");
            	$(".close").click(function() {
            		$(this).parent().remove();
            	    // location.reload();
            	    window.location.href = '?src=Enquiry&page_id=enquiry';
            	});
            	$(".outer").click(function() {
            		$(this).remove();
                    // location.reload();
                    window.location.href = '?src=Enquiry&page_id=enquiry';
            	});
    	    </script>
			    
			    <?php
			}

			}
			else { echo " You Can not pay with same name..! Please try again"; }
			
		}
		    else {
			$_SESSION['msg']='update Successfully';
			unset($_SESSION['form']);
			redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"Enquiry","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");
    $db->delete("enquiry_receipt","where idno='".$_GET['id']."' and session='".$_SESSION["admin"]["session"]."'");

	if(!is_null($flgUp)) { $_SESSION['msg']='Deleted Successfully'; }
	else { array_push($alert_err,$db->getErMsg()); }
	redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"Enquiry","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>

<style>
.recepit {
	width: 750px !important;
	height: 400px !important;
}
.outer, .inner{ 
  max-height: 800px;
  min-height: 405px;
 }
 .outer .undefined{
  background-color: #DADADA !important;
  border: 5px inset #181616 !important;
  min-height: 440px;
  min-width:675px;
}

</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=Enquiry&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">

                        <label style="text-align:center;border-bottom:solid 2px;padding:8px;">Basic Details</label>

						<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">Student Name</label>
							<div class="controls">
								<input type="text" id="name" name="name" class="input-block-level" value="<?php echo $aryForm["name"]; ?>" required>
							</div>
						</div>

	 					<div class="control-group">
							<label class="control-label">Father's Name</label>
							<div class="controls">
								<input type="text" id="fname" name="fname" class="input-block-level" value="<?php echo $aryForm["fname"]; ?>" required>
							</div>
						</div>

                        <div class="control-group">
							<label class="control-label" for="mname">Mother's 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">Family Annual <br> Income</label>
							<div class="controls">
								<input type="text" name="annual_income" class="input-block-level" value="<?php echo $aryForm["annual_income"]; ?>" >
							</div>
						</div>

                        <div class="control-group">
							<label class="control-label">Legal Guardian <br> Name</label>
							<div class="controls">
								<input type="text" name="guardian" class="input-block-level" value="<?php echo $aryForm["guardian"]; ?>" >
							</div>
						</div>

                        <div class="control-group">
							<label class="control-label">Religion</label>
							<div class="controls">
								<input type="text" name="religion" class="input-block-level" value="<?php echo $aryForm["religion"]; ?>" >
							</div>
						</div>

                        <div class="control-group">
							<label class="control-label">Nationality</label>
							<div class="controls">
								<input type="text" name="nationality" class="input-block-level" value="<?php echo $aryForm["nationality"]; ?>" >
							</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="address">Correspondence <br> 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">Permanent <br> Address</label>
							<div class="controls">
							<textarea rows="3" class="span12" name="permanent_address"><?php echo $aryForm["permanent_address"]; ?></textarea>
							</div>
						</div>

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

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

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

					<!-- Forms: Form -->
                    <label style="text-align:center;border-bottom:solid 2px;padding:8px;">Basic Details</label>
                        <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="foccupation">Father's 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">Mother's Occupation</label>
							<div class="controls">
								<input type="text" name="moccupation" class="input-block-level" value="<?php echo $aryForm["moccupation"]; ?>" >
							</div>
						</div>

						<div class="control-group">
							<label class="control-label" for="email">Email Id.</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">Alternate <br>Contact No.</label>
							<div class="controls">
								<input type="text" name="mobile_alt" class="input-block-level" value="<?php echo $aryForm["mobile_alt"]; ?>" >
							</div>
						</div>
						
						<div class="control-group">
							<label class="control-label">Account Detail</label>
							<div class="controls">
							<textarea rows="3" class="span12" name="account"><?php echo $aryForm["account"]; ?></textarea>
							</div>
						</div>

                        <div class="control-group">
							<label class="control-label">Blood Group</label>
							<div class="controls">
								<input type="text" name="blood_group" class="input-block-level" value="<?php echo $aryForm["blood_group"]; ?>" >
							</div>
						</div>

                        <div class="control-group">
							<label class="control-label">Caste</label>
							<div class="controls">
								<input type="text" name="cast" class="input-block-level" value="<?php echo $aryForm["cast"]; ?>" >
							</div>
						</div>

                        <div class="control-group">
							<label class="control-label">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">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">Mobile No.</label>
							<div class="controls">
								<input type="text" id="mobile" name="mobile" class="input-block-level" value="<?php echo $aryForm["mobile"]; ?>" required>
							</div>
						</div>

						<div class="control-group">
							<label class="control-label">Enrollment No.</label>
							<div class="controls">
							    <?php if($pgAct=="add"){ ?><input type="text" id="enrollment" name="reg_no" class="input-block-level"/><?php } else { ?>
							    <input type="text" name="reg_no" value="<?php echo $aryForm["reg_no"]; ?>" class="input-block-level" readonly/>
								<?php } ?>
							</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 -->
						<!-- Forms: Normal input field -->
						<label style="text-align:center;border-bottom:solid 2px;padding:8px;">Academic Details</label>
						<div class="control-group">
							<label class="control-label">Last School</label>
							<div class="controls">
								<input type="text" name="old_school" class="input-block-level" value="<?php echo $aryForm["old_school"]; ?>" >
							</div>
						</div>
						
						<div class="control-group">
							<label class="control-label">Last Class</label>
							<div class="controls">
									<select class="span12" name="last_class" >
    									<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["last_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">Reason for Leaving</label>
							<div class="controls">
								<input type="text" name="leave_reason" class="input-block-level" value="<?php echo $aryForm["leave_reason"]; ?>" >
							</div>
						</div>

						<div class="control-group">
							<label class="control-label">Apply Class</label>
							<div class="controls">
								
								<select class="span12" id="apply_class" name="apply_class" onchange="getRollNo(this.value)">
									<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["apply_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">Batch</label>
							<div class="controls">
								<select class="span12" id="batch" name="session" onchange="getenrollment()">
									<?php 
										$class=$db->getRows("select * from session");
										foreach($class as $cla){
											?>
											<option <?php if($cla["session"]==$aryForm["session"])echo 'selected';?> value="<?php echo $cla["session"] ?>">
												<?php echo $cla["session"] ?>
                                            </option>
											<?php
										}
									?>
								</select>
							</div>
						</div>

						<div class="control-group">
							<label class="control-label">Enquiry Type</label>
							<div class="controls">
								<select class="span12" name="enquiry_type">
									<option value="Online">Online</option>
									<option value="Telephonic">Telephonic</option>
									<option value="Walkin">Walkin</option>
								</select>
								
							</div>
						</div>

                        <div class="control-group">
							<label class="control-label" for="discount_mode">Enquiry Status</label>
							<div class="controls">
								<select class="span12" name="discount_mode" id="discount_mode" onchange="getregno(this.value)" <?php if($aryForm["discount_mode"]=="Admitted"){echo "disabled";} ?>>
                                	<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>

                    <?php $display = "none"; 
                            $clist = $receipt = $db->getRow("select * from enquiry_receipt where idno='".$_GET["id"]."' order by id limit 1 "); 
                            if(count($receipt)>1){
                                $display = "block";
                            }
                    ?>

                        <div id="feediv" style="display:<?php echo $display ?>;">

    						<div class="control-group">
    							<label class="control-label">Registration No.</label>
    							<div class="controls">
							    <?php if($aryForm["application_no"]==""){ ?>
    							    <input type="text" id="application" name="application_no" class="input-block-level" readonly/>
							    <?php } else { ?>
	    						    <input type="text" name="application_no" value="<?php echo $aryForm["application_no"]; ?>" class="input-block-level" readonly/>
								<?php } ?>
    							</div>
    						</div>


                            <div class="control-group">
    							<label class="control-label">Detail</label>
    							<div class="controls">
    								<textarea rows="4" name="detail" class="input-block-level" <?php if(count($receipt)>1){ echo "readonly"; } ?>><?php if($aryForm["detail"]!=""){echo $aryForm["detail"];}else {echo "Registration";} ?></textarea>
    							</div>
                            </div>

                            <div class="control-group">
    							<label class="control-label">Amount</label>
    							<div class="controls">
    							    <input type="text" name="amount" class="input-block-level" value="<?php echo $aryForm["amount"]; ?>" <?php if(count($receipt)>1){ echo "readonly"; } ?> />
    							</div>
                            </div>

                            <div class="control-group" style="text-align:center;">
                                <?php if(count($receipt)>1){
                                    $detail=""; ?>
                                    <a class="fancybox" data-class="recepit" href="./print/?page_id=enquiry_recepitNew&idno=<?php echo $clist["idno"] ?>&udate=<?php echo $clist["udate"] ?>&udate=<?php echo $clist["udate"] ?>&amount=<?php echo $clist["amount"] ?>&total=<?php echo $clist["total"] ?>&Months=<?php echo $clist["Months"] ?>&type=<?php echo $clist["type"] ?><?php $allDetail=array();
                    					$detail=json_decode($clist["detail"], true);
                    					foreach($detail as $dList=>$val){
                    						echo "&fee-$dList=$val";
                    					}
                    					?>&paytype=<?php echo $clist["paytype"] ?>&detail=pay-fee&class=<?php echo $clist["class"] ?>&install=<?php echo $clist["install"] ?>&receiptid=<?php echo $clist["id"] ?>&rrid=rrid-<?php echo $clist["rrid"]; ?>&save=record">
                                        <button type="button" class="btn btn-info">Print</button>
                                    </a>
                                <?php } else { ?>
                                <button type="submit" class="btn btn-primary">Pay Now</button>
                                <?php } ?>
                            </div>
 
                        </div>

						<div class="control-group">
							<label class="control-label">Other Ward <br> Studying</label>
							<div class="controls">
								<select class="span12" name="other_ward">
									<option value="Yes">Yes</option>
									<option value="No">No</option>
								</select>
							</div>
						</div>

                        <div class="control-group">
							<label class="control-label">Remarks</label>
							<div class="controls">
								<textarea rows="4" name="summary" class="input-block-level"><?php echo $aryForm["summary"]; ?></textarea>
							</div>
                        </div>

                        <div class="control-group"> 
							<label class="control-label">Lead Source</label>
							<div class="controls">
								<select class="span12" name="lead_source" >
								    <option value="NA">NA</option>
                                    <option value="Event Organized Locally" <?php if($aryForm["lead_source"]=="Event Organized Locally")echo 'selected';?>>Event Organized Locally</option>
                                    <option value="Hoarding" <?php if($aryForm["lead_source"]=="Hoarding")echo 'selected';?>>Hoarding</option>
                                    <option value="Leaflet / Flyers" <?php if($aryForm["lead_source"]=="Leaflet / Flyers")echo 'selected';?>>Leaflet / Flyers</option>
                                    <option value="Newspaper Ads" <?php if($aryForm["lead_source"]=="Newspaper Ads")echo 'selected';?>>Newspaper Ads</option>
                                    <option value="Just Dial" <?php if($aryForm["lead_source"]=="Just Dial")echo 'selected';?>>Just Dial</option>
                                    <option value="Recommendation from Family/Relative/Others" <?php if($aryForm["lead_source"]=="Recommendation from Family/Relative/Others")echo 'selected';?>>Recommendation from Family/Relative/Others</option>
                                    <option value="Social Media" <?php if($aryForm["lead_source"]=="Social Media")echo 'selected';?>>Social Media</option>
                                    <option value="TV Ads" <?php if($aryForm["lead_source"]=="TV Ads")echo 'selected';?>>TV Ads</option>
                                    <option value="Website" <?php if($aryForm["lead_source"]=="Website")echo 'selected';?>>Website</option>
                                    <option value="Field Staff" <?php if($aryForm["lead_source"]=="Field Staff")echo 'selected';?>>Field Staff</option>
								</select>
							</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" >Follow Date</label>
                            <div class="controls">
                                    <input type="date" name="follow_date"  class="input-block-level" value="<?php echo $aryForm["follow_date"]; ?>">
                                </div>
                        </div>
                        
                        <div class="control-group">
							<label class="control-label">Follow Staff</label>
							<div class="controls">
								<select class="span12" name="follow_staff" >
								    <option value="">--Select--</option>
									<?php 
										$location=$db->getRows("select * from staff where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 order by name ");
										if(is_array($location) && count($location)>0){
											foreach($location as $loc){
												?>
												<option <?php if($loc["idno"]==$aryForm["follow_staff"])echo 'selected';?> value="<?php echo $loc["idno"] ?>">
													<?php echo $loc["name"] ?>
												</option>
												<?php
											}
										}
									?>
								</select>
							</div>
						</div>

                        <div class="control-group">
							<label class="control-label">Follow Status</label>
							<div class="controls">
								<select name="follow_status" class="input-block-level">
                                    <option value="1" <?php if($aryForm["follow_status"]=="1")echo "selected"; ?>>Open</option>
                                    <option value="0" <?php if($aryForm["follow_status"]=="0")echo "selected"; ?>>Closed</option>
                                </select>
							</div>
                        </div>

                        <div class="control-group">
							<label class="control-label">Admission Agent</label>
							<div class="controls">
								<select name="agent" class="input-block-level">
                                    <option value="">Select Agent</option>
                                    <?php $aryList = $db->getRows("SELECT * FROM admission_agent "); 
                                            foreach($aryList as $clist){ ?>
                                        <option value="<?php echo $clist["id"]; ?>" <?php if($aryForm["agent"]==$clist["id"])echo "selected"; ?>><?php echo $clist["name"]; ?></option>
                                    <?php } ?>
                                </select>
							</div>
                        </div>

                        <div id="ins">
                            
                        </div>
                        <div id="busins">
                        
                        </div>
                        <div id="hostelins">
                        
                        </div>

				</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=Enquiry&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"=>"Enquiry","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:"
		}
	});
	
	getAdmissionNo();
    getenrollment();	
});
function fetchByClass(){
	var name=$("#class").val();
	var section=$("#section").val();
	if(name!=""){
		var url='Enquiry/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": 'Enquiry/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=Enquiry&page_id=make_admission&action=add';
				}else{
					window.location='?src=Enquiry&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($("#apply_class").val()==""){
		alert("Please select apply class")
	}
	else if($("#batch").val()==""){
		alert("Please select batch")
	}
	else if($("#mobile").val()==""){
		alert("Please enter mobile no.")
	}
	else
	{
		$("#saveformbutton").hide();
		$("#saveme").click();
	}
}

function getRollNo(cls){
	$.post( "Enquiry/ajax.php", { type: "getrollno", cls: cls } , function( data ) {
	  	$("#roll_no").val(data);
	});
} 

function getAdmissionNo(){
	$.post( "Enquiry/ajax.php", { type: "getadmissionno" } , function( data ) {
	  	$("#admissionno").val(data);
	});
}

function getregno(val){
    if(val=="Purchased Application"){
        $("#feediv").show();
    } else {
        $("#feediv").hide();
    }
}


function getenrollment(){
    var session = $('#batch').val();
	$.post( "Enquiry/ajax.php", { type: "getenrollment", session: session } , function(data) {
	  	$("#enrollment").val(data);
	});
	getapplication();
}

function getapplication(){
    var session = $('#batch').val();
	$.post( "Enquiry/ajax.php", { type: "getapplication", session: session } , function(data) {
	  	$("#application").val(data);
	});
}

</script>

