<?php $r="../../";
require_once($r."inc/funciones.php");
$titlepage = "Usuarios Sistema";
validNotSession($r);
$mysqli = connectDB($r);
$spe=$_SESSION['perfil'];
roleaccess(1220);
$actionnew = viewroleaccess(1210);
$actioneditar = viewroleaccess(1221);
$actionactivar = viewroleaccess(1222);
$actioneliminar = viewroleaccess(1223);
$actionreset = viewroleaccess(1224);
$actionexcel = viewroleaccess(1225);

$row1 = $mysqli->query("SELECT * FROM z_usuarios WHERE eliminado=0 AND tipo!=99");
?>

  <?php include $r."inc/head.php"; ?>
<body class="fixed-nav sticky-footer sidenav-toggled bg-dark" id="page-top">
  <?php include $r."inc/nav.php"; ?>
 
  <div class="content-wrapper">
    <div class="container-fluid">
      <!-- Example DataTables Card-->
      <div class="card mb-3">
        <div class="h3 card-header">
          <i class="fa fa-table"></i> USUARIOS SISTEMA
          <? if($actionnew){ ?><a href="nuevo.php" class="text-primary fa fa-user-plus float-right" ></a><? } ?>
        </div>
        <div class="card-body">
          <div class="table-responsive">
            <table class="table table-bordered table-striped" id="dataTable" width="100%" cellspacing="0">
              <thead>
                <tr>
                  <th>Usuario</th>
                  <th>Correo</th>
                  <th>Perfil</th>
                  <th># Contacto</th>
                  <?php if($actioneditar || $actionactivar || $actionreset || $actioneliminar){ ?><th></th><? } ?>
                </tr>
              </thead>
              <tfoot>
                <tr>
                  <th>Usuario</th>
                  <th>Correo</th>
                  <th>Perfil</th>
                  <th># Contacto</th>
                  <?php if($actioneditar || $actionactivar || $actionreset || $actioneliminar){ ?><th></th><? } ?>
                </tr>
              </tfoot>
              <tbody>
                     <?php
                    while($row2 = $row1->fetch_assoc()) {
                    ?>
                      <tr <? if ($row2["estado"]!="0"){echo 'class="text-danger"';} ?>>
                        <td class="text-uppercase"><?= $row2["nombre"] ?></td>
                        <td><?= $row2["correo"] ?></td>
                        <? $infoperfil = sinfo('z_perfiles',$row2["tipo"]); ?><td><?= $infoperfil["nombre"] ?></td>
                        <td><?= $row2["telefono"] ?></td>
                        <?php if($actioneditar || $actionactivar || $actionreset || $actioneliminar){ ?>
                        <td width="100px" class="text-center h5 p-05">
                            <?php if($actioneditar){ ?><a class="text-primary fa fa-pencil d-inline" title="Editar <?= $row2["nombre"] ?>" href="editar.php?id=<?= $row2["id"] ?>"></a><? } ?>
                            <?php if($actionreset){ ?><a class="text-warning fa fa-key d-inline" title="Resetear Clave <?= $row2["nombre"] ?>" href="acciones.php?reset=1&id=<?= $row2["id"] ?>"></a><? } ?>
                            <?php if($actionactivar){ ?>
                                <? if ($row2["estado"]!="0"){ ?><a class="text-success d-inline activar" title="Activar <?= $row2["nombre"] ?>" href="acciones.php?desactivar=1&id=<?= $row2["id"] ?>"><i class="fa fa-check"></i></a>
                                <? } else{?><a class="text-secondary d-inline desactivar" title="Desactivar <?= $row2["nombre"] ?>" href="acciones.php?activar=1&id=<?= $row2["id"] ?>"><i class="fa fa-minus-circle"></i></a><? } ?>
                            <? } ?>
                            <?php if($actioneliminar){ ?><a class="text-danger d-inline eliminar" title="Eliminar <?= $row2["nombre"] ?>" href="acciones.php?eliminar=1&id=<?= $row2['id']; ?>"><i class="fa fa-trash"></i></a><? } ?>
                        </td>
                        <? } ?>
                        </tr>
                    <?php
                    }
                    ?>
              <tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
  <?php include $r."inc/foot.php"; ?>
  <script>
      $('#dataTable').DataTable( {
        "stateSave": true,
        "lengthMenu": [[25, 50, 100, 500, -1], [25, 50, 100, 500, "Todos" ]],
        <?php if($actionexcel){?>"dom": '<"top"lfB>rt<"bottom"ip><"clear">', // Agrega B para los botones
        "buttons": [
            'copy', 'csv', 'excel', 'pdf', 'print'
        // Puedes agregar más botones según tus necesidades
        ],
        <? } ?>
    } );
  </script>
</body>
</html>    
    