<?php 
if(!isset($_SESSION)) { 
  session_start(); 
  include('../includes/dbcon.php');
}
if(empty($_SESSION['rm_id'])):
header('Location:../index.php');
endif;

if(isset($_REQUEST['emp_id']))

  {
 
    $rid=$_GET['emp_id'];

    $stringParts = explode("*", $rid);

    $emp_id  = $stringParts[0];

    $loc_status= $stringParts[1];

   
    if ($loc_status=="Yes"){
      $cval=0;
    }
    else {
      $cval=1;
    }
    mysqli_query($con,"update employee_master set emp_Active=$cval where emp_id=$emp_id ")or die(mysqli_error());





}


?>
<!DOCTYPE html>
<html lang="en">


<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <title>saleshub |Employee Management </title>
  <!-- plugins:css -->
  <?php include('../includes/commonheader.php');?>



</head>
<body>
 <?php include('../includes/header.php');?>
 <?php include('../includes/leftsidebar.php');?>
           <!-- partial -->
 <div class="main-panel">        
        <div class="content-wrapper">

          <div class="page-header">
            <h3 class="page-title">
                Employee Registration
            </h3>
           
          </div>
          <div class="col-12 grid-margin">
              <div class="card">
                <div class="card-body">

              
         
                 
    <form class="needs-validation" novalidate method="post" action="admin_emp_add.php" enctype="multipart/form-data" onsubmit="return validateForm()"> 
                  
                    <div class="row">
                      <div class="col-md-6">
                        <div class="form-group row">
                          <label class="col-sm-3 col-form-label">Employee Name <span style="color:red;font-size: 15px;font-weight:bold;">*</span> </label>
                          <div class="col-sm-9">
                             <input type="text" class="form-control" id="emp" name="emp" placeholder="Employee Name">
                          </div>
                        </div>
                      </div>
                      <div class="col-md-6">
                        <div class="form-group row">
                          <label class="col-sm-3 col-form-label">Emp Address <span style="color:red;font-size: 15px;font-weight:bold;">*</span></label>
                          <div class="col-sm-9">
                            <input type="text" class="form-control" id="address" name="address" placeholder="User Name">
                          </div>
                        </div>
                      </div>
                    </div>
                    <div class="row">
                      <div class="col-md-6">
                        <div class="form-group row">
                          <label class="col-sm-3 col-form-label">Telephone</label>
                          <div class="col-sm-9">
                            <input type="text" class="form-control" id="tel" name="tel" placeholder="Contact Detail">
                          </div>
                        </div>
                      </div>
                      <div class="col-md-6">
                        <div class="form-group row">
                          <label class="col-sm-3 col-form-label">Email</label>
                          <div class="col-sm-9">
                            <input type="text" class="form-control" id="email" name="email" placeholder="Email">
                          </div>
                        </div>
                      </div>
                    </div>
                    <div class="row">
                    
                        
            <div class="col-md-6">
                        <div class="form-group row">
                          <label class="col-sm-3 col-form-label">Employee Type</label>
                          <div class="col-sm-9">
                           <select class="form-control select2" style="width: 100%;" name="e_id" id="e_id" required >
           <option value="0">~~~Select ~~~~</option>  
          <?php            
          $querydoc=mysqli_query($con,"select * from employee_types  ")or die(mysqli_error());
          
          while($rowd=mysqli_fetch_array($querydoc)){
          ?>
          <option value="<?php echo $rowd['e_id'];?>"><?php echo $rowd['e_des'];?></option>        
          <?php }?>
          </select> 
                          </div>
                        </div>
                      </div>

</div>



    <div class="row">
                  






                    </div>                                     
                 
                     <button type="submit" class="btn btn-primary">Save</button>
                    <button class="btn btn-light">Cancel</button>
                  </form>
                </div>
              </div>
            </div>


    <div class="col-12 grid-margin">
              <div class="card">
                <div class="card-body">

                  <h4 >Employee Listing</h4>
                  <p class="card-description">
                    <button type="button" onclick="document.location='home.php'" class="btn btn-warning "><i class="fas fa-arrow-left"></i> Go Back
                    
                  </button>
                  </p>
                  <div class="table-responsive">
                    <table class="table table-hover">
                      <thead>
                        <tr>
                          <th>#</th>
                          <th>Employee</th>
                          <th>Address</th>
                          <th>Mobile</th>
                           <th>Email</th>                      
                          
                          <th>Type</th>
                          <th>Active</th>
                          <th>Edit</th> 
                        </tr>
                      </thead>
                      <tbody>
<?php
$rcount=0;
$query=mysqli_query($con,"SELECT * FROM employee_master
LEFT JOIN employee_types ON employee_master.e_id=employee_types.e_id;
")or die(mysqli_error()); 
 while($row=mysqli_fetch_array($query)){   $rcount=$rcount+1;
             
                $emp_id=$row['emp_id'];
                $emp_name=$row['emp_name']; 
                $emp_active=$row['emp_Active'];
                //$loc_id=$row['loc_id'];
                $e_des=$row['e_des'];

                if ($emp_active==1) {
                    $empactive="Yes";
                }
             
                if ($emp_active==0) {
                    $empactive="No";
                }

 ?>
   <tr>
                         <td><?php echo $rcount;  ?></td>
                         <td><?php echo $row['emp_name'];?></td>
                         <td><?php echo $row['Address1'];?></td>
                         <td><?php echo $row['mobile'];?></td>
                         <td><?php echo $row['email'];?></td>
                       
                            <td><?php echo $row['e_des'];?></td>

                         <td><?php if ($row['emp_Active']>0) { ?> &#10004;<?php } else { ?> &#10006; <?php } ?><a href="admin_emp.php?emp_id=<?php echo $row['emp_id'];echo "*";echo $empactive;?>"> Change</a></td>


                 
</td>  

<td>
       <a href="#addvoucher<?php echo $row['emp_id'];?>" data-target="#addvoucher<?php echo $row['emp_id'];?>"data-toggle="modal"     </div> <i class="fas fa-edit "></i>  </i> </a> </td>
              

</td>
<!----------------------Model ------------------------------->
     <div id="addvoucher<?php echo $row['emp_id'];?>" class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
          <div class="modal-dialog" style="width:80%; aria-hidden="true>
          <div class="modal-content" style="height:auto">        
          <div class="modal-body">
  
             <form class="form-horizontal" method="post" action="admin_employee_edit.php" enctype='multipart/form-data'>
      <div class="form-group">
                     <label for="exampleInputPassword1">Employee Name</label>
                <input type="text" class="form-control" id="empname_edit" name="empname_edit" value="<?php echo $emp_name; ?>">
              <input type="hidden" class="form-control" id="emp_id_edit" name="emp_id_edit" value="<?php echo $row['emp_id'];?>">

                </div>  
 <div class="form-group">
                     <label for="exampleInputPassword1">Address</label>
                <input type="text" class="form-control" id="Address1_edit" name="Address1_edit" value="<?php echo $row['Address1']; ?>">
      

                </div>  



               <div class="form-group">
              <label for="exampleInputEmail1">Employee Type </label>
         

               <select class="form-control select2" style="width: 100%;" name="e_edit" id="e_edit" required >           
          <?php            
          $querydoc=mysqli_query($con,"select * from employee_types"
)or die(mysqli_error());          
          while($rowr=mysqli_fetch_array($querydoc)){
            if ($row['e_id']==$rowr['e_id']){ ?>            
            <option value="<?php echo $rowr['e_id'];?>" selected><?php echo $rowr['e_des'];?></option>
            <?php } else {
          ?>
          <option value="<?php echo $rowr['e_id'];?>"><?php echo $rowr['e_des'];?></option>        
          <?php } }?>
          </select> 



               </div>


                <div class="form-group">
                     <label for="exampleInputPassword1">Telephone</label>
                <input type="text" class="form-control" id="tel_edit" name="tel_edit" value="<?php echo $row['mobile']; ?>">    
                </div> 

                <div class="form-group">
                     <label for="exampleInputPassword1">Email</label>
                <input type="text" class="form-control" id="email_edit" name="email_edit" value="<?php echo $row['email']; ?>">    
                </div> 

                




                   <div class="modal-footer">
                   <button type="submit" class="btn btn-primary">Save changes</button>
                   <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                   </div>                   
          </form>

   


          </div>
        </div>
      </div>
    </div>
<!--------------- End of Model ------------------------------------>


 <?php }  ?>
</tr>
                      </tbody>
                    </table>



        </div>  <!----- <div class="content-wrapper">------>
                </div>
              </div>
    </div>



        </div>  <!----- <div class="content-wrapper">------>
  </div> 
</div>


</div>  <!----- <div class="content-wrapper">------>
  

 </div><!-----End of main panel--~~~~~~~~~~~~~~~~~~~~~~~--------------->
 </div><!-----Dont Delete this DIV--~~~~~~~~~~~~~~~~~~~~~~~--------------->
  <!-- container-scroller -->
<?php include('../includes/footer.php');?>
<?php include('../includes/commonjs.php');?>
 
</body>


</html>

<script>
    $( document ).ready(function() {
         // alert("Please Select Order Type");

    });

function validateForm() { 

    //````````route````````````````````````````````````
    if($('#emp').val().trim().length == 0) {
           alert("Please enter the Employee Name !!!");               
            return false;
    } ////``````````````````````````````````````````

     //````````start mileage````````````````````````````````````
   if ($('#e_id').val() === "0") {
        alert("Please select a valid  Type!");
        return false;
    }



 } ///validateForm() { 

</script>

 <!-- End custom js for this page-->
  <script>
  $(function () {
    //Initialize Select2 Elements
    $('.select2').select2()

    //Initialize Select2 Elements
    $('.select2bs4').select2({
      theme: 'bootstrap4'
    })
  })

</script>



