<?php
  $page_title = 'Lista de usuarios';
  require_once('../../includes/load.php');
?>
<?php
// Checkin What level user has permission to view this page
 page_require_level(1);
//pull out all user form database
 $all_users = find_all_user();
?>
<?php include_once('../../layouts/header.php'); ?>
<div class="row">
   <div class="col-md-12">
     <?php echo display_msg($msg); ?>
   </div>
</div>
<div class="row">
  <div class="col-md-12">
    <div class="panel panel-default">
      <div class="panel-heading clearfix">
        <div class="pull">
        <strong>
          <span class="glyphicon glyphicon-th"></span>
          <span>Usuarios</span>
       </strong>
       </div> 
         <a href="add_user.php" class="btn btn-info pull-right">Agregar usuario</a>
      </div>
     <div class="panel-body">
      <table class="table table-bordered table-striped" id="mytable">
        <thead>
          <tr>
            <th>NOMBRE </th>
            <th>USUARIO</th>
            <th style="width: 15%;">ROL DE USUARIO</th>
            <th style="width: 10%;">ESTADO</th>
            <th style="width: 20%;">INICIO LOGIN</th>
            <th style="width: 20%;">ULTIMO LOGIN</th>
            <th style="width: 100px;">ACCIONES</th>
          </tr>
        </thead>
        <tbody>
        <?php foreach($all_users as $a_user): ?>
          <tr>
           <td><?php echo remove_junk(ucwords($a_user['name']))?></td>
           <td><?php echo remove_junk(ucwords($a_user['username']))?></td>
           <td ><?php echo remove_junk(ucwords($a_user['group_name']))?></td>
           <td class="text-center">
           <?php if($a_user['status'] === '1'): ?>
            <span class="label label-success"><?php echo "Activo"; ?></span>
          <?php else: ?>
            <span class="label label-danger"><?php echo "Inactivo"; ?></span>
          <?php endif;?>
           </td>
           <td><?php echo read_date($a_user['op_login'])?></td>
           <td><?php echo read_date($a_user['last_login'])?></td>
           <td class="text-center">
             <div class="btn-group">
                <a style="margin-right: 3pt" href="edit_user.php?id=<?php echo (int)$a_user['id'];?>" class="btn btn-xs btn-primary confirmEditar"  title="Editar">
                <span class="glyphicon glyphicon-pencil"></span>
                </a>
                 <a href="delete_user.php?id=<?php echo (int)$a_user['id'];?>" class="btn btn-xs btn-danger confirmUser"  title="Eliminar" >
                  <span class="glyphicon glyphicon-remove" ></span>
                </a>
                </div>
           </td>
          </tr>
        <?php endforeach;?>
       </tbody>
     </table>
     </div>
    </div>
  </div>
</div>
  <?php include_once('../../layouts/footer.php'); ?>

<script type="text/javascript">
table = $('#mytable').DataTable({
  responsive: true,
  deferRender: true, 
  "autoWidth": false,     
  "search": {
    "regex": true,
    "caseInsensitive": false,
  },
"aLengthMenu": [[7, 10, 25, 50, -1], [7, 10, 25, 50, "All"]],
"order": [[1, "ASC"]],
"language":{
    "lengthMenu": "Mostrar _MENU_ registros por pagina",
    "info": "Mostrando pagina _PAGE_ de _PAGES_",
    "infoEmpty": "No hay registros disponibles",
    "infoFiltered": "(filtrada de _MAX_ registros)",
    "loadingRecords": "Cargando...",
    "processing":     "Procesando...",
    "search": "Buscar:",
    "zeroRecords":    "No se encontraron registros coincidentes",
    "paginate": {
        "next":       "Siguiente",
        "previous":   "Anterior"
    },  


}
});
</script>