<?php 
include "config.php";
error_reporting(0);
?>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="datatable/data.css">
<script src="datatable/data.js" type="text/javascript"></script>
<script src="datatable/table.js" type="text/javascript"></script>
<script src="datatable/datatable.js"></script>
<link rel="stylesheet" href="datatable/data-boot.css">
<style>
    
    #navbar
    {
        flex:15%;
        height:100%; 
        flex-direction:row;
        overflow:auto;
        
    }
    #content
    {
        flex:90%;
        overflow:auto;
        padding-left:10px;
        padding-right:10px;
    }
    #fullbody
    {
        display:flex;
        
         height:100%;         
    }
    label
    {
      font-size:20px;
    }
    .edit
    {
        font-size:18px;
        color:green;
        cursor:pointer;
    }
    .dele
    {
        font-size:18px;
        color:red;
        cursor:pointer;
    }
    .edit:hover
    {
        font-size:20px;
        
    }
    .dele:hover
    {
        font-size:20px;
        color:red;
        cursor:pointer;
        
    }
    td
    {
      text-align:center;
    }
    th
    {
      text-align:center;
    }
    @media (max-width: 800px) {
        #fullbody
    {
        display:flex;
        flex-wrap: wrap;
                 
    }
        #navbar,#content {
    flex: 100%;
  }
}
</style>
<script>
$(document).ready( function () {
    $('#protable').DataTable();
} );
</script>

</head>
<body>
    <div ><?php include "navbar.php"?></div>
    <div id="fullbody"> 

<div id="content">
<br>
<h3>Employee-Master</h3>
<?php 
        $userall=$_SESSION['log'];
        $usper = mysqli_query($connect,"select * from userpermission where username = '$userall'  && filename='employeemaster'");
while($per=mysqli_fetch_array($usper))
{
          ?>
<br>
<?php if($per['dataadd'] =='1'){ ?>
<input type="button" class="btn btn-info" data-toggle="modal" data-target="#myModal" style="float:right;margin-right:10px;" value="+ Add"><?php }?>
<br><br>
<!-- table -->
<div>
<table class="table table-bordered table-hover " style="border:1px solid lightgrey" id="protable">
    <thead >
<tr>
  <th>S.no</th>
    <th>Code</th>
    <th>Name</th>
    <th>Mobile</th>
    <th>Employee-Type</th>
    <th>Status</th>
    <?php if($per['dataedit'] =='1'){ ?><th>Edit</th><?php }?>
   <!-- <?php if($per['datadelete'] =='1'){ ?><th>Delete</th><?php }?>-->
</tr>

    </thead>
    <tbody>
<?php 
$pro=mysqli_query($connect,"select * from employeedetails where status !='deleted' order by id desc");
while($proshow = mysqli_fetch_array($pro))
{
?>
        <tr>
          
            <td><?php echo $proshow['id'] ?></td>
            <td><?php echo $proshow['employeecode'] ?></td>
            <td><?php echo $proshow['employeename'] ?></td>
            <td><?php echo $proshow['mobile'] ?></td>
            <td><?php echo $proshow['usertype'] ?></td>
            <td><?php if($proshow['statuslive'] == 1){echo 'Active';}else{echo 'Deleted';} ?></td>
            
            <?php if($per['dataedit'] =='1'){ ?>  <td><a data-toggle="modal" data-target="#edit<?php echo $proshow['employeecode']?>"><i class="fas fa-edit edit"></i></a></td><?php }?>
          <!--  <?php if($per['datadelete'] =='1'){ ?>  <td><a data-toggle="modal" data-target="#delete<?php echo $proshow['employeecode']?>"><i  class="fas fa-trash-alt dele"></a></i></td><?php }?>-->
        </tr>
        <?php
      } }
      
      ?>
    </tbody>



</table>
</div>
<!-- modal -->
<div class="modal fade" id="myModal">
    <div class="modal-dialog modal-dialog-centered modal-lg">
      <div class="modal-content">
      
        <!-- Modal Header -->
        <div class="modal-header">
          <h4 class="modal-title">Add employee</h4>
          <button type="button" class="close" data-dismiss="modal">&times;</button>
        </div>
        
        <!-- Modal body -->
        <div class="modal-body">
            <!--  -->
            <form action="insertemployee.php" method="post" name="masteremployee">
              <?php 
              $code = mysqli_query($connect,"select max(id)as count from employeedetails ");
              while($row=mysqli_fetch_array($code))
              {
                $code = $row['count'];
                $codeco = sprintf("%04d",$code + 1);
              }
              ?>
              <input type="text" class="form-control" autocomplete="off" value="EMP-<?php echo $codeco ?>" name="employeecode" placeholder="Name">
              <!-- userrefer -->
              <?php 

$display=mysqli_query($connect,"SELECT  * from user_refer");
while($dis=mysqli_fetch_array($display))
{
  
?>
    
<input type="hidden" name="filename[]"  value="<?php echo $dis['filename']?>">
<?php 
}
?>
              <!-- userrefer -->
              <!--  -->
            
            <div class="row">
              <div class="col-sm-3"><label>Employee Type</label></div>:
              <div class="col-sm-3"><input type="radio" class="emptype "autocomplete="off" name="usertype" placeholder="Name" value="admin"><label>Administrator</label></div>
              <div class="col-sm-3"><input type="radio" class="emptype" autocomplete="off" name="usertype" placeholder="Name" value="general"><label>General</label></div>
            </div><br>
            <!--  -->
          <div class="row">
              <div class="col-sm-3"><label>Employee Name</label></div>:
              <div class="col-sm-6"><input type="text" class="form-control" autocomplete="off" name="employeename" id="employeenameadd"placeholder="Name"></div>
              
            </div><br>
            <!--  -->
            <div class="row">
              <div class="col-sm-3"><label>Username</label></div>:
              <div class="col-sm-6"><input type="text" class="form-control" autocomplete="off" id="usernameadd"name="username" placeholder="User"></div>
            </div><br>
            <div class="row">
              <div class="col-sm-3"><label>Mobile</label></div>:
              <div class="col-sm-6"><input type="text" class="form-control" autocomplete="off" name="mobile" placeholder="Mobile Number"></div>
            </div><br>
            <?php 
$username_val=mysqli_query($connect,"select * from employeedetails order by id desc");
while($username_val_show = mysqli_fetch_array($username_val))
{
?>
<input type="hidden" class="usernameValue" value="<?php echo $username_val_show['username'] ?>">
<?php
}
?>
<script>
  var userName = document.querySelectorAll(".usernameValue");
  var userAdd = document.getElementById("usernameadd");
  userAdd.addEventListener("keyup",function(e){
   var user = e.target.value.toLowerCase();
   userName.forEach((list)=>{
    if(user.replace(/ /g,"") == list.value.toLowerCase().replace(/ /g,"")){
      document.getElementById("alertUser").click();
     userAdd.value="";
   }
   });
     
  });
  console.log(userName);
</script>
            <!--  -->
            <div class="row">
              <div class="col-sm-3"><label>Password</label></div>:
              <div class="col-sm-6"><input type="password" class="form-control" autocomplete="off" id="passwordadd"name="password" placeholder="password"></div>
            </div><br>
            <!--  -->
            <div class="row">
              <div class="col-sm-3"><label>Status</label></div>:
              <div class="col-sm-6"><select class="form-control selectpro" autocomplete="off" name="statuslive" id="statusadd"placeholder="Tax">
<option value="">--select Status --</option>
              <option value="1">Active</option>
              <option value="0">delete</option>
              
</select></div>
            </div><br>
            <!--  -->
        </div>
        
        <!-- Modal footer -->
        <div class="modal-footer">
          <input type="button" class="btn btn-success" data-toggle="modal" data-target="#addpro" value="ADD" id="submitadd" onMouseOver="sub()" onKeyUp="sub()">
        </div>
        <!-- modal for add -->
<div class="modal fade" id="addpro">
    <div class="modal-dialog modal-sm">
      <div class="modal-content" style="background-color:rgba(77, 219, 106,0.9)">
      
        <!-- Modal Header -->
        
        
        <!-- Modal body -->
        <div class="modal-body">
          <span style="color:white"><i class="fas fa-check" style="font-size:24px"></i> Employee Have Been Created Successfully</span>
        </div>
        
        <!-- Modal footer -->
        <div class="modal-footer">
          <button type="submit" type="button" class="btn btn-warning" >Ok</button>
        </div>
</form>
      </div>
    </div>
  </div>
  
<!-- modal for add -->
      </div>
    </div>
  </div>
<!-- modal -->
<!-- modal for edit -->
<?php 
$proedit=mysqli_query($connect,"select * from employeedetails order by id desc");
while($proshowedi = mysqli_fetch_array($proedit))
{
?>
<form action="updateemployee.php" method="post">
<div class="modal fade" id="edit<?php echo $proshowedi['employeecode']?>">
    <div class="modal-dialog modal-dialog-centered modal-lg">
      <div class="modal-content">
      
        <!-- Modal Header -->
        <div class="modal-header">
          <h4 class="modal-title">Edit Employee</h4>
          <button type="button" class="close" data-dismiss="modal">&times;</button>
        </div>
        
        <!-- Modal body -->
        <div class="modal-body">
            <!--  -->
            <div class="row">
              <div class="col-sm-3"><label>Employeetype</label></div>:
              <div class="col-sm-3"><input type="radio" class="tonnedit" autocomplete="off" name="employeetypeedit<?php echo$proshowedi['employeecode'] ?>" placeholder="Name" value="admin"<?php echo ($proshowedi['usertype']== 'admin') ?  "checked" : "" ;  ?>><label>Administrator</label></div>
              <div class="col-sm-3"><input type="radio" class="kgedit" autocomplete="off" name="employeetypeedit<?php echo$proshowedi['employeecode'] ?>" placeholder="Name" value="general"<?php echo ($proshowedi['usertype']== 'general') ?  "checked" : "" ;  ?>><label>General</label></div>
            </div><br>
            <!--  -->
          <div class="row">
              <div class="col-sm-3"><label>Employee Name</label></div>:
              <div class="col-sm-6"><input type="text" class="form-control" autocomplete="off" name="employeenameedit" value="<?php echo $proshowedi['employeename'] ?>" placeholder="Name">
              <input type="hidden" class="form-control" autocomplete="off" name="employeecodeedit" value="<?php echo $proshowedi['employeecode'] ?>" placeholder="Code">
            </div>
              
            </div><br>
            <!--  -->
            <div class="row">
              <div class="col-sm-3"><label>Username</label></div>:
              <div class="col-sm-6"><input type="text" class="form-control" autocomplete="off" name="useredit" value="<?php echo $proshowedi['username'] ?>" placeholder="HSN"></div>
            </div><br>
            <div class="row">
              <div class="col-sm-3"><label>Mobile</label></div>:
              <div class="col-sm-6"><input type="text" class="form-control" autocomplete="off" name="mobileedit" value="<?php echo $proshowedi['mobile'] ?>" placeholder="Mobile Number"></div>
            </div><br>
            <!--  -->
           
            
            <div class="row">
              <div class="col-sm-3"><label>Password</label></div>:
              <div class="col-sm-6"><input type="password" class="form-control" value="<?php echo $proshowedi['password'] ?>" autocomplete="off" name="passwordedit" placeholder="Price"></div>
            </div><br>
            <!--  -->
            
            <div class="row">
              <div class="col-sm-3"><label>Status</label></div>:
              <div class="col-sm-6"><select class="form-control selectpro" autocomplete="off" name="statusliveedit" placeholder="Tax">
<?php if( $proshowedi['statuslive'] == 1){echo '<option value="1">Active</option><option value="0">Deleted</option>';}else{echo '<option value="0">Deleted</option><option value="1">Active</option>';} ?>
              
</select></div>
            </div><br>
            <!--  -->
        </div>
        
        <!-- Modal footer -->
        <div class="modal-footer">
          <button type="submit" class="btn btn-success">Update</button>
        </div>
</form>
      </div>
    </div>
    
  </div>
  <?php
}
  ?>
  <!--  -->
<!-- modal for edit -->
<!-- modal for delete -->
<!-- The Modal -->
<?php 
$prodele=mysqli_query($connect,"select * from employeedetail order by id desc");
while($proshowdele = mysqli_fetch_array($prodele))
{
?>
<div class="modal fade" id="delete<?php echo $proshowdele['employeecode']?>">

    <div class="modal-dialog modal-sm">
      <div class="modal-content" style="background-color:rgba(247, 2, 80,0.9)">
      
        <!-- Modal Header -->
        <form action="deleteemployee.php" method="post">
        <input type="hidden" value="<?php echo $proshowdele['employeecode']?>" name="delete">
        <!-- Modal body -->
        <div class="modal-body" >
         Are You Sure Want To Delete !.

        </div>
        
        <!-- Modal footer -->
        <div class="modal-footer">
        <button type="submit" class="btn btn-success">Yes</button>
          <button type="button" class="btn btn-warning" data-dismiss="modal">No</button>
</form>
        </div>
        
      </div>
    </div>
  </div>
  <?php 
}
  ?> 
<!-- ,odal for delete -->
<!-- table -->


<!-- main-content-div -->
</div>
<!-- modal to blockdate -->
<button type="button" class="btn btn-primary" id="alertUser" data-toggle="modal" data-target="#advanceLimit" style="display:none">
      </button>

  <!-- The Modal -->
  <div class="modal fade" id="advanceLimit">
    <div class="modal-dialog modal-lg">
     <div class="alert alert-danger alert-dismissible fade show">
    <button type="button" class="close"  data-dismiss="alert">&times;</button>
    <strong>User Already Exist</strong>
  </div>
  </div>
  </div>
        
<!-- alert -->
<!-- alert producttype-->
<button type="button" class="btn btn-primary alertunit" data-toggle="modal" data-target="#myunit" style="display:none">
      </button>

  <!-- The Modal -->
  <div class="modal fade" id="myunit">
    <div class="modal-dialog modal-lg">
     <div class="alert alert-danger alert-dismissible fade show">
    <button type="button" class="close" data-dismiss="alert">&times;</button>
    <strong>Please Select Employee Type</strong>
  </div>
  </div>
        </div>
<!-- alert -->
<!-- main-content-div -->
</div>

</body>
