<!DOCTYPE html>
<html>
<head>
	<?php include('include/head.php'); ?>
</head>
<body>
	<?php include('include/header.php'); ?>
	<?php include('include/sidebar.php'); ?>
	<div class="main-container">
		<div class="pd-ltr-20 xs-pd-20-10">
			<div class="min-height-200px">
				<div class="page-header">
					<div class="row">
						<div class="col-md-6 col-sm-12">
							<div class="title">
								<h4>Student Registraion</h4>
							</div>
							<nav aria-label="breadcrumb" role="navigation">
								<ol class="breadcrumb">
									<li class="breadcrumb-item"><a href="dashboard.php">Dashboard</a></li>
									<li class="breadcrumb-item active" aria-current="page">Add Student Registraion</li>
								</ol>
							</nav>
						</div>
						<div class="col-md-6 col-sm-12 text-right">
							<div class="dropdown">
								<a class="btn btn-primary" href="view_student_reg.php" role="button">
									View Student Registration
								</a>
							</div>
						</div>
					</div>
				</div>
				<!-- Default Basic Forms Start -->
				<div class="pd-20 bg-white border-radius-4 box-shadow mb-30">
					<form method="post">
			<?php 
              $select1=mysqli_query($connect,"select fld_stud_reg_id from tbl_student_reg order by fld_stud_reg_id desc limit 1") or die(mysqli_error($connect));
              $fetch1=mysqli_fetch_array($select1);
              $stud_reg_id=$fetch1['fld_stud_reg_id'];

            ?>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Registraion No<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<input class="form-control" type="text" name="stud_reg_id" value="<?php echo "GBS" . ++$stud_reg_id;?>" readonly>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">First Name<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<input class="form-control" placeholder="First Name" type="text" required="" oninput="this.value = this.value.replace(/[^a-zA-Z\s.]/g, '').replace(/(\..*)\./g, '$1');" name="fname">
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Middle Name<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<input class="form-control" placeholder="Middle Name" type="text" required="" oninput="this.value = this.value.replace(/[^a-zA-Z\s.]/g, '').replace(/(\..*)\./g, '$1');" name="mname">
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Last Name<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<input class="form-control" placeholder="Last Name" type="text" required="" oninput="this.value = this.value.replace(/[^a-zA-Z\s.]/g, '').replace(/(\..*)\./g, '$1');" name="lname">
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Date of Birth<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<input class="form-control date-picker" placeholder="Select DOB" type="text" name="dob">
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Email<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<input class="form-control" placeholder="Email" type="email" required  name="email">
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Mobile<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<input class="form-control" type="tel" placeholder="Mobile No" required="" pattern="[789]{1}[0-9]{9}" maxlength="10" minlength="10" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');" name="mobile">
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">State<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<select name="state" class="form-control" id="state" required="">
                    				<option value="">Select State</option>
                                    <?php
                                        
                                        $query1=mysqli_query($connect,"select distinct fld_state_name,fld_state_id from tbl_state where fld_state_delete='0' order by fld_state_id desc");
                                        while($row=mysqli_fetch_assoc($query1)){
                                          extract($row);

                                      ?>
                                    <option value="<?php echo $row['fld_state_id'];?>"><?php echo $row['fld_state_name'];?></option>
                                    <?php  }?>
                				</select>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">City<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<select name="city" class="form-control" id="city" required="">
                   					<option value="">Select City</option>
                				</select>
							</div>
						</div>
						<div class="form-group row">
							<label for="example-datetime-local-input" class="col-sm-12 col-md-2 col-form-label">Taluka<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<select name="taluka" class="form-control" id="taluka" required="">
                   					<option value="">Select Taluka</option>
                				</select>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Aadhar Card Number<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<input type="text" class="form-control" placeholder="Aadhar Card Number" name="aadhar_card_number" required="" maxlength="12" minlength="12" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');">
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Student Qualification<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<select name="quali" class="form-control" id="quali" required="">
                    				<option value="">Select Student Qualification</option>
                                    <?php
                                        
                                      $query1=mysqli_query($connect,"select distinct fld_stud_qualification,fld_stud_id from tbl_student_qualification where fld_stud_qualification_delete='0' order by fld_stud_id desc");
                                        while($row=mysqli_fetch_assoc($query1)){
                                          extract($row);
                                      ?>
                                    <option value="<?php echo $row['fld_stud_id'];?>"><?php echo $row['fld_stud_qualification'];?></option>
                                    <?php  }?>
                				</select>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Student Occupation<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<select name="occ" class="form-control" id="occ" required="">
                    				<option value="">Select Student Occupation</option>
                                    <?php
                                        
                                      $query1=mysqli_query($connect,"select distinct fld_occupation,fld_occ_id from tbl_student_occupation where fld_occupation_delete='0' order by fld_occ_id desc");
                                        while($row=mysqli_fetch_assoc($query1)){
                                          extract($row);
                                      ?>
                                    <option value="<?php echo $row['fld_occ_id'];?>"><?php echo $row['fld_occupation'];?></option>
                                    <?php  }?>
                				</select>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Course<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<select name="course" class="form-control" id="course" required="">
                    				<option value="">Select Course</option>
                                    <?php
                                        
                                      $query1=mysqli_query($connect,"select c.*,cd.* from tbl_course_details cd, tbl_course c where c.fld_course_id=cd.fld_course_id and cd.fld_course_details_delete='0' order by fld_course_details_id desc");

                                        while($row=mysqli_fetch_array($query1)){
                                          extract($row);
                                      ?>
                                    <option value="<?php echo $row['fld_course_id'];?>"><?php echo $row['fld_course_name'];?></option>
                                    <?php  }?>
                				</select>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Batch Time From<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<select name="fld_batch_time_from" class="form-control" id="fld_batch_time_from" required="">
                    				<option value="">Select Batch Time From</option>
                                    
                				</select>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Batch Time To<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<select name="fld_batch_time_to" class="form-control" id="fld_batch_time_to" required="">
                    				<option value="">Select Batch Time To</option>
                                   
                				</select>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Session Date<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<select name="session_date" class="form-control" id="session_date" required="">
                    				<option value="">Select Session Date</option>
                                    
                				</select>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Course Fees<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<select name="course_fees" class="form-control" id="course_fees" required="">
                    				<option value="">Course Fees</option>
                                    
                				</select>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Discount<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<input type="text" name="discount" id="discount" class="form-control" required="" placeholder="Discount" onkeyup="fn1()" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');">
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Final Fees<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<input type="text" name="final_fees" id="final_fees" class="form-control" required="" placeholder="Final Fees" readonly>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Media(reference)<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<select name="media" class="form-control" id="media" required="">
                    				<option value="">Select Media</option>
                                    <?php
                                        
                                      $query1=mysqli_query($connect,"select distinct fld_media_name,fld_media_id from tbl_media where fld_media_delete='0' order by fld_media_id desc");
                                        while($row=mysqli_fetch_assoc($query1)){
                                          extract($row);
                                      ?>
                                    <option value="<?php echo $row['fld_media_id'];?>"><?php echo $row['fld_media_name'];?></option>
                                    <?php  }?>
                				</select>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Registration Date<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<input class="form-control date-picker" placeholder="Select Date" type="text" name="reg_date">
							</div>
						</div>
						<div class="form-group row">
							<div class="col-sm-12 col-md-10">
							<center><input class="btn btn-success" value="Submit" type="submit" name="submit">&nbsp;
								<input class="btn btn-danger" value="Reset" type="reset">&nbsp;
								<a href="view_student_reg.php" class="btn btn-warning">Back</a></center>
							</div>
						</div>
						
						
					</form>

			</div>
			<?php include('include/footer.php'); ?>
		</div>
	</div>
	<?php include('include/script.php'); ?>
	<script type="text/javascript">
  $(document).ready(function(){
    $("select#state").change(function(){
          var u = $("#state option:selected").val();
      
          $.ajax({
              type: "POST",
              url: "city.php", 
              data: { state : u  } 
          }).done(function(data){
              $("#city").html(data);
          });
      });
  });
</script>
<script type="text/javascript">
  $(document).ready(function(){
    $("select#city").change(function(){
          var u = $("#city option:selected").val();
      
          $.ajax({
              type: "POST",
              url: "taluka.php", 
              data: { city : u  } 
          }).done(function(data){
              $("#taluka").html(data);
          });
      });
  });
</script>
<script type="text/javascript">
  $(document).ready(function(){
    $("select#course").change(function(){
          var u = $("#course option:selected").val();
      
          $.ajax({
              type: "POST",
              url: "batch_time_from.php", 
              data: { course : u  } 
          }).done(function(data){
              $("#fld_batch_time_from").html(data);
          });
      });
  });
</script>
<script type="text/javascript">
  $(document).ready(function(){
    $("select#course").change(function(){
          var u = $("#course option:selected").val();
      
          $.ajax({
              type: "POST",
              url: "batch_time_to.php", 
              data: { course : u  } 
          }).done(function(data){
              $("#fld_batch_time_to").html(data);
          });
      });
  });
</script>
<script type="text/javascript">
  $(document).ready(function(){
    $("select#course").change(function(){
          var u = $("#course option:selected").val();
      
          $.ajax({
              type: "POST",
              url: "session_date.php", 
              data: { course : u  } 
          }).done(function(data){
              $("#session_date").html(data);
          });
      });
  });
</script>
<script type="text/javascript">
  $(document).ready(function(){
    $("select#course").change(function(){
          var u = $("#course option:selected").val();
      
          $.ajax({
              type: "POST",
              url: "course_fees.php", 
              data: { course : u  } 
          }).done(function(data){
              $("#course_fees").html(data);
          });
      });
  });
</script>
<script type="text/javascript">
		function fn1()
{
	 var pri=parseInt(document.getElementById('course_fees').value);
	var qui=parseInt(document.getElementById('discount').value);

	var result=parseInt(pri) - (parseInt(pri)*parseInt(qui)/100);
	
	document.getElementById('final_fees').value=result;
}
</script>
</body>

<?php 
	if (isset($_POST['submit'])) 
	{

	extract($_POST);

	$dob=$_POST['dob'];
	$new_dob= date("Y-m-d",strtotime($dob));

	$reg_date=$_POST['reg_date'];
	$new_reg_date= date("Y-m-d",strtotime($reg_date));

	 date_default_timezone_set('Asia/Kolkata');
      $current_date=Date("Y-m-d");


	$abc=mysqli_query($connect,"select * from tbl_student_reg where 
			fld_reg_no='".$stud_reg_id."'");

	if(mysqli_num_rows($abc)==1)
	{
	    echo "<script>";
	    echo "alert('Student Registration Number Alrady Exist');";
	    //echo "window.location.href='view_course_details.php';";
	    echo "</script>";
	}
	else
	{
	 $query="INSERT INTO tbl_student_reg(fld_reg_no,fld_first_name,fld_middle_name,fld_last_name,fld_dob,fld_email,fld_mobile,fld_state_id,fld_city_id,fld_taluka_id,fld_aadhar_no,fld_stud_id,fld_occ_id,fld_course_id,fld_batch_time_from,fld_batch_time_to,fld_session_date,fld_fee_of_course,fld_discount,fld_final_fees,fld_media_id,fld_reg_date,fld_invoice_current_date) VALUES ('$stud_reg_id','$fname','$mname','$lname','$new_dob','$email','$mobile','$state','$city','$taluka','$aadhar_card_number','$quali','$occ','$course','$fld_batch_time_from','$fld_batch_time_to','$session_date','$course_fees','$discount','$final_fees','$media','$new_reg_date','$current_date')";
	//echo $query."<br>";
	$row=mysqli_query($connect,$query) or die(mysqli_error($connect));
	if ($row) 
	{
	    echo "<script>";
	    echo "alert('Student Registration Details Added Successfully');";
	    echo "window.location.href='view_student_reg.php';";
	    echo "</script>";                 
	}
	else
	{
	    echo "<script>";
	    echo "alert('Error');";
	    echo "</script>";
	}
	}
	 }




 ?>
