<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">
<link href="javascript/select2.css" rel="stylesheet" >
<script src="javascript/selectt2.js"></script>
<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;
    }
    li a 
    {
      color:black;
    }
    .page-item.active .page-link {
    
    background-color:yellow;
    border-color: #007bff;
}
    @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>Userpermission Edit</h3>
<br>
<!-- edit -->
<?php 
include "config.php";

error_reporting(0);
?>
<html>
<head>
<script src="javascript/min.js" type="text/javascript"></script>
<link href="javascript/select2.css" rel="stylesheet" >
<script src="javascript/selectt2.js"></script>
<style>
td
{
	padding:40px;
    text-align:center;
}
th
{
    text-align:center;
}
td:first-child { text-align: left }
</style>
</head>
<body>
 <form action="userpermissioninsert.php" method="post">

<script>
$(document).ready(function(){       
        
        $("#usernameselect").on('change',function() {
          var usersel = $("#usernameselect").val();
         $("#usernamedis").html(usersel);
          
                  }); 
              
          });

</script>


<div class="row">
<div class="col-sm-12">    
<!-- <button type="button" class="btn btn-primary alertbutton" data-toggle="modal" data-target="#mypermission">
  +Add Permission    </button> -->
</div></div><br><br>
<?php 
$edi = $_GET['code'];
$disemp=mysqli_query($connect,"select distinct * from employeedetails where employeecode='$edi' && status !='deleted' && statuslive !='0'");
while($emp=mysqli_fetch_array($disemp))
{
?>
<h4 ><span style="text-transform:uppercase" id="usernamedis"><?php echo $emp['username'] ?></span>'s&nbsp Permissions</h4>
<input type="hidden" value="<?php echo $edi ?>" class="userselect">
<?php 
}
?>

<script>
$(document).ready(function(){
    
  
        $(".all").click(function () {
          //alert('hai');
            if ($(this).is(":checked")) {
              $(".userview").attr('checked');
               
      //alert(filename);
    
        }
       
      });
});
</script>

<!-- <input type="text"  value="<?php echo $dis['USERNAME']?>" name="username"> -->
<table class="table  table-hover">
<thead >
<th>Contents</th>
<th>View</th>
<th>Add</th>
<th>Edit</th>
<th>Delete</th>
<th>Print</th>
<th>Excel</th>



</thead>
<tbody>

<?php 
$edi = $_GET['code'];
$display=mysqli_query($connect,"SELECT distinct * from userpermission where employeecode='$edi'");
while($dis=mysqli_fetch_array($display))
{
  
?>
    <tr>
<td> <input type="hidden" value="<?php echo $dis['filename'] ?> " class="oldname"><input type="text" name="filename[]" style="outline:none;border:none"  class=" form-control filename" value="<?php echo $dis['filename'] ?>"></td>
<td><input type="checkbox" value="datashow"<?php if ($dis['datashow'] == 1) { echo "checked='checked'"; } ?> class="userview" name="view[]"></td>
<td><input type="checkbox" value="dataadd" <?php if ($dis['dataadd'] == 1) { echo "checked='checked'"; } ?> class="userview" name="add[]"></td>
<td><input type="checkbox"  value="dataedit" <?php if ($dis['dataedit'] == 1) { echo "checked='checked'"; } ?>class="userview" name="edit[]"></td>
<td><input type="checkbox" value="datadelete" <?php if ($dis['datadelete'] == 1) { echo "checked='checked'"; } ?> class="userview" name="delete[]"></td>
<td><input type="checkbox" value="dataprint"  <?php if ($dis['dataprint'] == 1) { echo "checked='checked'"; } ?>class="userview" name="print[]"></td>
<td><input type="checkbox" value="dataexcel"  <?php if ($dis['dataexcel'] == 1) { echo "checked='checked'"; } ?>class="userview" name="excel[]"></td>
</tr>

<tbody>
<?php 
}

?>
<script>

</script>
<script type="text/javascript">
$(document).ready(function(){
  $('.filename').attr("disabled","disabled");
  
    $('.filename').keyup(function(){
      var oldname=$(this).closest('tr').find(".oldname").val();
      var newone=$(".filename").closest('tr').find(this).val();
      //alert(oldname);
      $.ajax({
                type:'POST',
                url:'ajaxuserperedit.php',
                data:{oldname:oldname,newone:newone},
                   success:function(a){
                   // alert(a);
                    location.reload();
                  //$("#report").html(a);
                  
                    //$('#city').html('<option value="">Select state first</option>'); 
                }
            }); 
      
    });
    
   
});
</script>
<script>
$(document).ready(function(){
    
  
        $(".userview").click(function () {
          //alert('hai');
            if ($(this).is(":checked")) {
              var usercode =$(".userselect").val();
      var colname= $(this).closest('tr').find(this).val();
    var filename=$(this).closest('tr').find('.filename').val();
      //alert(filename);
    $.ajax({
                type:'POST',
                url:'userpermission/userajax.php',
                data:{usercode:usercode,filename:filename,colname:colname},
               success:function(a){
                location.reload();
               // $("#hello").html(a);
               //alert(a);
               }
            });
        }
        else
        {
          var usercode =$(".userselect").val();
      var colname= $(this).closest('tr').find(this).val();
    var filename=$(this).closest('tr').find('.filename').val();
    var unchk='no';
     // alert(filename);
    $.ajax({
                type:'POST',
                url:'userpermission/userajax.php',
                data:{usercode:usercode,filename:filename,colname:colname,unchk:unchk},
               success:function(a){
                location.reload();
               // $("#hello").html(a);
              // alert(a);
               }
            });
        }
       
      });
});
</script>









</table>
<!-- <input type="submit" class="btn btn-info"> -->
</form>
<!-- The Modal -->
<div class="modal fade" id="myModal">
    <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>
    <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Add Permission</h4>
        </div>
        <div class="modal-body">
         <form action="insertuserpermissionedit.php" method="post">
         <table class="addcustomer">
         <?php 
$sql = mysqli_query($connect,"SELECT distinct usercode,username  FROM userpermission");
while($take=mysqli_fetch_array($sql))
{
?>
                 
         
        <input type="hidden" name="usercode[]" class="form-control" style="width:400px;" placeholder="Enter Your Product Name"  value="<?php echo $take['usercode'] ?>" >
        <input type="hidden" name="username[]" class="form-control" style="width:400px;" placeholder="Enter Your Product Name"  value="<?php echo $take['username'] ?>" ><?php }?>
      <tr>
         <th>Permission<span style=" color:red" > *</span></th>
         <td><input type="text" id="chk"  name="permission" class="form-control" autocomplete="off"></td>
         </tr>
                  <tr>
         <td><button type="submit" id="show" class="btn btn-success"  >Save permission</button></td>
         </tr>
         </table>
         </form>
        </div>
  </div>
  </div>
        </div>
<!-- alert -->
<script src="javascript/select2.js"></script>
<div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog ">
      <div class="modal-content" style="height:300px; overflow:scroll">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Add Permission</h4>
        </div>
        <div class="modal-body">
         <form action="insertuserpermissionedit.php" method="post">
         <table class="addcustomer">
         <?php 
$sql = mysqli_query($connect,"SELECT distinct usercode,username  FROM userpermission");
while($take=mysqli_fetch_array($sql))
{
?>
                 
         
        <input type="hidden" name="usercode[]" class="form-control" style="width:400px;" placeholder="Enter Your Product Name"  value="<?php echo $take['usercode'] ?>" >
        <input type="hidden" name="username[]" class="form-control" style="width:400px;" placeholder="Enter Your Product Name"  value="<?php echo $take['username'] ?>" ><?php }?>
      <tr>
         <th>Permission<span style=" color:red" > *</span></th>
         <td><input type="text" id="chk"  name="permission" class="form-control" autocomplete="off"></td>
         </tr>
                  <tr>
         <td><button type="submit" id="show" class="btn btn-success"  >Save permission</button></td>
         </tr>
         </table>
         </form>
        </div>
              </div>
    </div>
   <
</body>

<!-- edit -->
</div>
<script>
    $('.selectpro').select2({ width: '100%',height:'420px;' });
    
</script>
</body>
</html>