<?php $r="../../";
require_once($r."inc/funciones.php");
$titlepage = "Usuarios Sistema";
validNotSession($r);
$mysqli = connectDB($r);
$spe=$_SESSION['perfil'];
roleaccess(2510);
$actionnew = viewroleaccess(2501);
$actioneditar = viewroleaccess(2511);
$actionactivar = viewroleaccess(2512);
$actioneliminar = viewroleaccess(2513);
$actionexcel = viewroleaccess(2515);

$row1 = $mysqli->query("SELECT * FROM z_proveedores WHERE eliminado=0");
?>

  <?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> LISTA DE PROVEEDORES
          <? 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>ID</th>
                  <th>Proveedor</th>
                  <th>Correo</th>
                  <th>Nombre</th>
                  <th># Contacto</th>
                  <?php if($actioneditar || $actionactivar  || $actioneliminar){ ?><th></th><? } ?>
                </tr>
              </thead>
              <tfoot>
                <tr>
                  <th>ID</th>
                  <th>Proveedor</th>
                  <th>Correo</th>
                  <th>Nombre</th>
                  <th># Contacto</th>
                  <?php if($actioneditar || $actionactivar  || $actioneliminar){ ?><th></th><? } ?>
                </tr>
              </tfoot>
              <tbody>
                     <?php
                    while($row2 = $row1->fetch_assoc()) {
                    ?>
                      <tr <? if ($row2["estado"]=="0"){echo 'class="text-danger"';} ?>>
                        <td><?= $row2["id"] ?></td>
                        <td class="text-uppercase"><?= $row2["nombre"] ?></td>
                        <td><?= $row2["correo"] ?></td>
                        <td><?= $row2["contacto1"] ?></td>
                        <td><?= $row2["celular1"] ?></td>
                        <?php if($actioneditar || $actionactivar  || $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($actionactivar){ ?>
                                <? if ($row2["estado"]!="0"){ ?><a class="text-secondary d-inline activar" title="Activar <?= $row2["nombre"] ?>" href="acciones.php?desactivar=1&id=<?= $row2["id"] ?>"><i class="fa fa-minus-circle"></i></a>
                                <? } else{?><a class="text-success 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>    
    