<script>
    $(document).ready(function() {
      if($('#usertype').val() == 'admin'){
        $('#mytable').DataTable({
          dom: 'Bfrtip',
          aaSorting: [[0, 'desc']],
        buttons: [
        //  { extend: 'pdf', className: 'btn-primary',exportOptions: {columns: [ 0, 1, 2, 3, 4]}, },
          //{ extend: 'excel', className: 'btn-primary',exportOptions: {columns: [ 0, 1, 2, 3, 4]}, },
         // { extend: 'csv', className: 'btn-primary',exportOptions: {columns: [ 0, 1, 2, 3, 4]}, },
        ]
        });
      }else{
        $('#mytable').DataTable({
          aaSorting: [[0, 'desc']],
        });
      }
        if($('#usertype').val() == 'staff')
        {
            $('.edit-btn').remove();
            $('.add-btn').remove();
        }
    } );
</script>
<table class="table table-striped table-hover" id="mytable">
    <thead>
      <tr>
        <th scope="col">S.No.</th>
        <th scope="col">Fullname</th>
        <th scope="col">Department</th>
        <th scope="col">Email</th>
        <th scope="col">Mobile</th>
        <th scope="col">Date</th>
        <th scope="col">Action</th>
      </tr>
    </thead>
    <tbody>
      <?php $i=1; foreach($list as $val) { ?>
        <tr>
          <th scope="row"><?= $val['id']; ?></th>
          <td><?= $val['fullname']; ?></td>
          <td><?= $val['department']; ?></td>
          <td><?= $val['emailid']; ?></td>
          <td><?= $val['mobile']; ?></td>
          <td><?= date('d-m-Y',strtotime($val['created']));?></td>
          <td>
                      <a href="staff-detail/<?= $val['id']; ?>" class="btn btn-primary btn-sm" target="_blank">View</a>  

            <a href="javascript:void(0)" class="btn btn-info btn-sm edit-btn" onclick="editData(<?= $val['id']; ?>)" data-bs-toggle="modal" data-bs-target="#editModal">Edit</a>
            <?php if($this->session->userdata('usertype') == 'admin'){ ?>
          <?php if($val['is_suspended'] == '0'){ ?>
                <a href="javascript:void(0)" class="btn btn-danger btn-sm disable-btn" onclick="changeStatus(<?= $val['id']; ?>,'1')">Suspend</a>
            <?php } else{ ?>
                <a href="javascript:void(0)" class="btn btn-success btn-sm disable-btn" onclick="changeStatus(<?= $val['id']; ?>,'0')">Unsuspend</a>
            <?php } ?>
            <a href="javascript:void(0)" class="text-primary forgot-password" onclick="changePassword(<?= $val['id']; ?>)">Forgot Password</a>
            <?php } ?>
          </td>
        </tr>
      <?php } ?>
    </tbody>
</table>
<script>
function changeStatus(id,type)
{
  if (confirm('Are you sure?') == true) {
    var table = 'staff';
    var column = 'is_suspended';
    $.ajax({
        url: "<?= base_url('Dashboard/Status'); ?>",
        method: "POST",
        data: {
            id:id,
            type:type,
            table:table,
            column:column,
            module:'staff'
        },
        dataType:'json',
        success:function(res){
          if(res.return)
          {
            $("#tb").load("<?= base_url('staff/viewStaff/') ?>")
            toastr.success(res.msg);
          }
          else
          {          
            toastr.error(res.msg);
          }
        }
    });
  }
};
</script>