<!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>Employee Details</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 Employee Details</li>
								</ol>
							</nav>
						</div>
						<div class="col-md-6 col-sm-12 text-right">
							<div class="dropdown">
								<a class="btn btn-primary" href="view_emp_details.php" role="button">
									View Employee Details
								</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_emp_details_id from tbl_empolyee_details order by fld_emp_details_id desc limit 1") or die(mysqli_error($connect));
              $fetch1=mysqli_fetch_array($select1);
              $emp_id=$fetch1['fld_emp_details_id'];

            ?>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Employee Id<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<input class="form-control" type="text" name="emp_id" value="<?php echo "GBE" . ++$emp_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">Employee 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 Qualification</option>
                                    <?php
                                        
                                      $query1=mysqli_query($connect,"select distinct fld_emp_qualification,fld_emp_id from tbl_employee_qualification where fld_emp_qualification_delete='0' order by fld_emp_id desc");
                                        while($row=mysqli_fetch_assoc($query1)){
                                          extract($row);
                                      ?>
                                    <option value="<?php echo $row['fld_emp_id'];?>"><?php echo $row['fld_emp_qualification'];?></option>
                                    <?php  }?>
                				</select>
							</div>
						</div>
						
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Empolyee Course(optional) :</label>
							<div class="col-sm-12 col-md-10">
								<input type="text" name="course" class="form-control" placeholder="Empolyee Course" oninput="this.value = this.value.replace(/[^a-zA-Z\s.]/g, '').replace(/(\..*)\./g, '$1');">
							</div>
						</div>
						
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Date of Joining<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="joining_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_emp_details.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>
</body>

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

	extract($_POST);

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

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

	$abc=mysqli_query($connect,"select * from tbl_empolyee_details where 
			fld_employee_id='".$emp_id."'");

	if(mysqli_num_rows($abc)==1)
	{
	    echo "<script>";
	    echo "alert('Employee Id Alrady Exist');";
	    //echo "window.location.href='view_course_details.php';";
	    echo "</script>";
	}
	else
	{
	 $query="INSERT INTO tbl_empolyee_details(fld_employee_id,fld_emp_fname,fld_emp_mname,fld_emp_lname,fld_emp_dob,fld_emp_email,fld_emp_mobile,fld_state_id,fld_city_id,fld_taluka_id,fld_emp_aadhar_no,fld_emp_id,fld_emp_course,fld_emp_date_of_joining) VALUES ('$emp_id','$fname','$mname','$lname','$new_dob','$email','$mobile','$state','$city','$taluka','$aadhar_card_number','$quali','$course','$new_joining_date')";
	//echo $query."<br>";
	$row=mysqli_query($connect,$query) or die(mysqli_error($connect));
	if ($row) 
	{
	    echo "<script>";
	    echo "alert('Employee Details Added Successfully');";
	    echo "window.location.href='view_emp_details.php';";
	    echo "</script>";                 
	}
	else
	{
	    echo "<script>";
	    echo "alert('Error');";
	    echo "</script>";
	}
	}
	 }




 ?>
