<?php
  $Seccion      = 'Configuracion';
  $SubSeccion   = 'Sitios';
  $NameSec      = 'Sitios';
  $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');

  $SecLine      = array('Configuración', $NameSec);

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

  //Sitios
  $Query = "
    SELECT
      sit.Id,
      sit.Nombre, sit.Url, sit.Activo
    FROM CMS_Sitios sit
  ";
  $Sitios = $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">

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

            <!-- Botones -->
            <div class="col-md-7 align-self-center text-right">
              <div class="btn-group" role="group" aria-label="Basic example">
                <?php if( $Perms[6] ){ ?>
                  <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">
                    <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>
                            <?php if( $Perms[7] ){ ?>
                              <th width="20"></th>
                            <?php } ?>
                            <?php if( $Perms[8] ){ ?>
                              <th width="20"></th>
                            <?php } ?>
                          </tr>
                        </thead>
                        <tbody>
                            <?php
                              mysqli_data_seek($Sitios, 0);
                              while($Sit = mysqli_fetch_array($Sitios)) {
                            ?>
                              <tr>

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

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

                                <!-- Status -->
                                <td>
                                  <?php if( $Sit[Activo] == 1 ){ ?>
                                    <span class="label label-success">
                                      Activo
                                    </span>
                                  <?php } ?>
                                </td>
                                <!-- End Status -->

                                <?php if( $Perms[7] ){ ?>
                                  <!-- Editar -->
                                  <td>
                                    <?php if( $Perms[3] ){ ?>
                                      <a href="edit.php?Id=<?php echo $Sit['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 -->
                                <?php } ?>

                                <?php if( $Perms[8] ){ ?>
                                  <!-- Eliminar -->
                                  <td>
                                    <?php if( $Perms[4] ){ ?>
                                      <a data-toggle="modal" href="#Borrar<?php echo $Sit[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 $Sit[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 $Sit['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 $Sit['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 $Sit[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 -->
                                <?php } ?>

                              </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>
