<?php
session_start();
require_once('../conexion.php');
require_once('../include/sesiones.php');
?>
<table class="table table-striped table-bordered">
    <thead>
        <tr>
            <th>NOMBRE</th>
            <th width="20%"></th>
        </tr>
    </thead>
    <?php
        $registros=mysqli_query($con,"SELECT * from rol where empresa='$empresa'") or die(mysqli_error($con));
        while ($reg=mysqli_fetch_array($registros)){
        $id=$reg["rol_id"];
    ?>
        <tr>
            <td><?php  echo $reg['rol_nombre']; ?></td>
            <td >
                <?php 
                if($reg['rol_nombre']<>'Administrador' && $reg['rol_nombre']<>'Cajero' && $reg['rol_nombre']<>'Vendedor') {?>
                  <a data-id="<?php echo $id;?>" class="btn btn-edit btn-xs btn-warning"> <i class="btn-icon-only icon-edit"></i></a>
                  <a href="#" id="del-<?php echo $reg["rol_id"];?>"  title="Eliminar" class="btn btn-xs btn-danger"> <i class="btn-icon-only icon-remove"></i></a>
               <?php }?>
            </td>
            <script>
            $("#del-"+<?php echo $reg["rol_id"];?>).click(function(e){
              e.preventDefault();
              p = confirm("Estas seguro?");
              if(p){
                $.get("./php_configuraciones/eliminar_rol.php","rol_id="+<?php echo $reg["rol_id"];?>,function(data){
                  loadTabla();
                });
              }
            });
            </script>
        </tr>
    <?php }?>
</table>

<script>
    $(".btn-edit").click(function(){
      id = $(this).data("id");
      $.get("./php_configuraciones/form_editar_rol.php","id="+id,function(data){
        $("#form-edit").html(data);
      });
      $('#editModal').modal('show');
    });
</script>
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Actualizar Rol</h4>
            </div>
            <div class="modal-body">
                <div id="form-edit"></div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->