<?php
  $Seccion    = 'Administradores';
  $Position   = '../';
  require_once($Position.'config/config.php');
  require_once($Position.'config/conexion.php');
  require_once($Position.'config/user.php');
  require_once($Position.'funciones/acces.php');
  require_once($Position.'funciones/logout.php');
  require_once($Position.'funciones/funciones.php');
  require_once($Position.'funciones/extras.php');


  //Eliminar Administrador
  if( $_POST['Borrar']=='Ok' ){
    $Id = $_POST['Id'];
    $Query="DELETE FROM Administradores WHERE Id = '$Id'";
    $Result = mysqli_query($mysqli, $Query);
  }

  //Administradores
  $Query = "
    SELECT
      admi.Id, admi.Email,
      CONCAT(admi.Nombre,' ',admi.Apellidos) AS Nombre,
      admi.Activo,
      sta.Nombre AS Status, sta.ClassColorLabel
    FROM CMS_Admins admi
    LEFT JOIN CMS_AdminsStatus sta ON sta.Id = admi.Activo
    GROUP BY admi.Id
  ";
  $Administradores = $mysqli->query($Query);
?>

<!DOCTYPE html>
<html lang="en">

<?php require_once($Position.'head.php'); ?>

<body class="fix-sidebar fix-header card-no-border">
    <div class="preloader">
        <svg class="circular" viewBox="25 25 50 50">
            <circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="2" stroke-miterlimit="10" /> </svg>
    </div>
    <div id="main-wrapper">
      <?php require_once($Position.'header.php'); ?>
      <?php require_once($Position.'menu.php'); ?>
      <div class="page-wrapper">
        <div class="container-fluid">
          <div class="row page-titles">

            <!-- Titulo -->
            <div class="col-md-5 col-8 align-self-center">
              <h3 class="text-themecolor m-b-0 m-t-0">Administradores</h3>
              <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="javascript:void(0)">Lista de Administradores</a></li>
              </ol>
            </div>
            <!-- End Titulo -->

            <!-- Botones -->
            <div class="col-md-7 align-self-center text-right">
              <div class="btn-group" role="group" aria-label="Basic example">
                <?php if( $Perms[2] ){ ?>
                  <a href="edit.php">
                    <button type="button" class="btn btn-sm btn-secondary">Nuevo<i class="fa fa-plus mar-l-10"></i></button>
                  </a>
                <?php } ?>
              </div>
            </div>
            <!-- End Botones -->

          </div>
          <div class="row">
              <div class="col-12">
                <!-- Usuarios -->
                <div class="card">
                  <div class="card-body">
                    <h4 class="card-title">Listado de Administradores</h4>
                    <div class="table-responsive m-t-20">
                      <table id="example23" class="display nowrap table table-hover table-striped table-bordered" cellspacing="0" width="100%">
                        <thead>
                          <tr>
                            <!-- <th width="20">Id</th> -->
                            <th>Nombre</th>
                            <th width="20">Status</th>
                            <th width="20"></th>
                            <th width="20"></th>
                          </tr>
                        </thead>
                        <tbody>
                            <?php
                              mysqli_data_seek($Administradores, 0);
                              while($Admi = mysqli_fetch_array($Administradores)) {
                            ?>
                              <tr>

                                <!-- Id -->
                                <!-- <td>
                                  <?php echo $Admi['Id'];?>
                                </td> -->
                                <!-- End Id -->

                                <!-- Nombre -->
                                <td>
                                  <div><?php echo $Admi['Nombre']; ?></div>
                                  <div><a href="mailto:<?php echo $Admi['Email']; ?>" style="color:#244887;" target:"_top"><?php echo $Admi['Email']; ?></a></div>
                                </td>
                                <!-- End Nombre -->

                                <!-- Status -->
                                <td>
                                  <span class="label <?php echo $Admi[ClassColorLabel]; ?>"><?php echo $Admi[Status]; ?></span>
                                </td>
                                <!-- End Status -->

                                <!-- Editar -->
                                <td>
                                  <?php if( $Perms[3] ){ ?>
                                    <a href="edit.php?Id=<?php echo $Admi['Id']; ?>">
                                      <button class="btn btn-secondary btn-sm" data-toggle="tooltip" data-placement="top" title="" data-original-title="Editar">
                                        Editar<i class="fa fa-pencil m-l-10"></i>
                                      </button>
                                    </a>
                                  <?php } ?>
                                </td>
                                <!-- Ebd Editar -->

                                <!-- Eliminar -->
                                <td>
                                  <?php if( $Perms[4] ){ ?>
                                    <a data-toggle="modal" href="#Borrar<?php echo $Admi[Id];?>">
                                      <button class="btn btn-danger btn-sm ml-2" data-toggle="tooltip" data-placement="top"  title="Eliminar" data-original-title="Eliminar">
                                      <i class="fa fa-times"></i></button>
                                    </a>

                                    <!--Modal Eliminar-->
                                    <form method="POST">
                                      <div id="Borrar<?php echo $Admi[Id];?>" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
                                        <div class="modal-dialog">
                                          <div class="modal-content">
                                            <div class="modal-header">
                                              <h4 class="modal-title">Eliminar Administrador</h4>
                                              <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                            </div>
                                            <div class="modal-body p-4">
                                              <div class="row">
                                                <div class="col-md-12">
                                                  <p>¿Desea eliminar esté administrador?</p>
                                                </div>
                                                <div class="col-md-6">
                                                  <div class="form-group">
                                                    <label for="field-1" class="control-label">Nombre</label>
                                                    <input type="text" class="form-control" id="field-1" value="<?php echo $Admi['Nombre'];?>" disabled>
                                                  </div>
                                                </div>
                                                <div class="col-md-6">
                                                  <div class="form-group">
                                                    <label for="field-2" class="control-label">Email</label>
                                                    <input type="text" class="form-control" id="field-2" value="<?php echo $Admi['Email'];?>" disabled>
                                                  </div>
                                                </div>
                                              </div>
                                            </div>
                                            <div class="modal-footer">
                                                <input name="Borrar"   type="hidden" value="Ok">
                                                <input name="Id" type="hidden" value="<?php echo $Admi[Id];?>">
                                                <button type="button" class="btn btn-secondary waves-effect" data-dismiss="modal">Cancelar</button>
                                                <button type="submit" class="btn btn-danger waves-effect waves-light">Eliminar</button>
                                              </div>
                                          </div>
                                        </div>
                                      </div>
                                    </form>
                                    <!-- End Modal Eliminar-->
                                  <?php } ?>
                                </td>
                                <!-- End Eliminar -->

                              </tr>
                            <?php } ?>
                          </tbody>
                      </table>
                    </div>
                  </div>
                </div>
                <!-- End Usuarios -->
              </div>
            </div>
        </div>
        <?php require_once($Position.'footer.php'); ?>
      </div>
    </div>
    <?php require_once($Position.'scripts.php'); ?>
    <script>

    </script>
    <script src="<?php echo $Position; ?>assets/plugins/styleswitcher/jQuery.style.switcher.js"></script>

</body>
</html>
