<?php
  $Seccion    = 'Expositores';
  $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');
  require_once($Position.'funciones/paginador1.php');

  //Filtrar
  $Where = "
    WHERE exp.Id != '0'
  ";
  if( $_GET[Filtrar] == 'Ok' ){

    //Variables
    $Filtrar     = 'Ok';
    $Bus = "&Filtrar=Ok";

    //Nombre
    $FilNom = $_GET[Nom];
    if( $FilNom ){
      $Where .= "AND cli.Nombre LIKE '%$FilNom%' ";
      $Bus .= "&Nom=".$FilNom;
    }

    //Cliente
    $FilCli = $_GET[Cli];
    if( $FilCli ){
      $Where .= "AND cli.Id = '$FilCli' ";
      $Bus .= "&Cli=".$FilCli;
    }

    //Rfc
    $FilRfc      = $_GET[Rfc];
    if( $FilRfc ){
      $Where .= "AND cli.Rfc LIKE '%$FilRfc%' ";
      $Bus .= "&Rfc=".$FilRfc;
    }

    //Email
    $FilEmail    = $_GET[Email];
    if( $FilEmail ){
      $Where .= "AND cli.Email LIKE '%$FilEmail%' ";
      $Bus .= "&Email=".$FilEmail;
    }

    //Eje
    $FilEje    = $_GET[Eje];
    if( $FilEje ){
      $Where .= "AND cli.Fk_Administrador = '$FilEje' ";
      $Bus .= "&Eje=".$FilEje;
    }

    //Status
    $FilSta      = $_GET[Sta];
    if( $FilSta ){
      $Where .= "AND cli.Fk_ProspectoStatus = '$FilSta' ";
      $Bus .= '&Sta='.$FilSta;
    }

    // $FilPai      = $_POST[Pai];
    // $FilEst      = $_POST[Est];
    // if( $FilPai ){ $Where .= "AND cli.Fk_Pais LIKE '$FilPai' "; }
    // if( $FilEst ){ $Where .= "AND cli.Fk_Estado LIKE '$FilEst' "; }



  }

  if (isset($_GET['pgn'])){
    $pgn =  $_GET['pgn']; // $pg es la pagina actual
  }else{
    $pgn = 0;
  }
  $cantidad = 20; // cantidad de resultados por página
  $PagerLap = $cantidad / 10;
  $inicial  = $pgn * $cantidad;

  //Total Usuarios
  $Query = "
    SELECT
      COUNT(usr.Id) AS Total
    FROM CMS_Expositores usr
    $Where
  ";
  $Result = mysqli_query($mysqli, $Query);
  $ArtTotal = mysqli_fetch_assoc($Result);
  $total_records = $ArtTotal[Total];
  $pages = intval($total_records / $cantidad);

  //Expositores
  $Query = "
    SELECT
      exp.Id,
      exp.Nombre, exp.Apellidos,
      exp.Titulo,
      exp.Email, exp.Celular,
      exp.Activo
    FROM CMS_Expositores exp
    $Where
    ORDER BY exp.Nombre ASC, exp.Apellidos ASC
    LIMIT $inicial, $cantidad
  ";
  $Exps = $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">Expositores</h3>
              <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="javascript:void(0)">Lista de Expositores</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="item">
                    <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">

                <!-- Buscador -->
                <div id="Filtrar">

                  <div class="card">
                    <div class="card-body">
                      <form method="get">
                        <div class="row">

                          <!-- <div class="col-sm-12">
                            <h4>Filtar</h4>
                            <hr />
                          </div> -->

                          <!-- Usuarios -->
                          <div class="col-sm-6">
                            <div class="form-group">
                              <label class="control-label">Nombre</label>
                              <div class="controls">
                                <select name="Exp" class="form-control form-condtrol-sm chosen-select">
                                  <option value="">Todos</option>
                                  <?php
                                    //Sucursales
                                    $Query = "
                                      SELECT
                                        exp.Id, exp.Nombre, exp.Apellidos
                                      FROM CMS_Expositores exp
                                      ORDER BY exp.Nombre ASC, exp.Apellidos ASC
                                    ";
                                    $UsrsFil = $mysqli->query($Query);
                                    mysqli_data_seek($UsrsFil, 0);
                                    while($UsrFil = mysqli_fetch_array($UsrsFil)) {
                                  ?>
                                    <option
                                      <?php if( $UsrFil['Id'] == $FilUsr ){ echo 'selected="selected"'; } ?>
                                      value="<?php echo $UsrFil['Id']; ?>"
                                    >
                                      <?php echo $UsrFil['Nombre'].' '.$UsrFil['Apellidos']; ?>
                                    </option>
                                  <?php } ?>
                                </select>
                              </div>
                            </div>
                          </div>
                          <!-- End Usuarios -->

                          <!-- Email -->
                          <div class="col-sm-6">
                            <div class="form-group">
                              <label class="control-label">Email</label>
                              <input
                                name="Ema"
                                type="text"
                                class="form-control form-control-sm"
                                autocomplete="off"
                                placeholder=""
                                value="<?php echo $FilEma; ?>"
                              >
                            </div>
                          </div>
                          <!-- End Email -->

                          <!-- Filtrar -->
                          <div class="col-sm-3">
                            <div class="form-group">
                              <label class="control-label">.</label>
                              <button class="btn btn-success btn-block" type="submit" name="button">Filtrar <i class="fa fa-search mar-l-5"></i></button>
                              <input type="hidden" name="Filtrar" value="Ok" />
                            </div>
                          </div>
                          <!-- End Filtrar -->

                          <!-- Btn Descargar Excel -->
                          <div class="col-sm-3">
                            <div class="form-group">
                              <label class="control-label">.</label>
                              <a href="excel.php?pgn=0<?php echo $Bus; ?>" target="_blank">
                                <button class="btn btn-secondary btn-block" type="button">
                                  Exportar Excel
                                  <i class="fa fa-file mar-l-5"></i>
                                </button>
                              </a>
                            </div>
                          </div>
                          <!-- End Btn Descargar Excel -->

                          <!-- Total -->
                          <div class="col-sm-3">
                            <div class="form-group">
                              <label class="control-label">Expositores Registrados</label>
                              <input
                                readonly
                                type="text"
                                class="form-control form-control-sm"
                                autocomplete="off"
                                placeholder=""
                                value="<?php echo $total_records; ?>"
                              >
                            </div>
                          </div>
                          <!-- End Total -->

                        </div>
                      </form>
                    </div>
                  </div>

                </div>
                <!-- End Buscador -->

                <!-- Card -->
                <div class="card">
                  <div class="card-body">

                    <!-- Table -->
                    <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>Id</th> -->
                            <th>Nombre</th>
                            <th>Contacto</th>
                            <th width="20">Status</th>
                            <th width="20"></th>
                            <th width="20"></th>
                          </tr>
                        </thead>
                        <tbody>
                            <?php
                              mysqli_data_seek($Exps, 0);
                              while($Exp = mysqli_fetch_array($Exps)) {
                            ?>
                              <tr>
                                <!-- Id --
                                <td width="10">
                                  <?php echo $Exp['Id'];?>
                                </td>
                                <!-- End Id -->

                                <!-- Nombre -->
                                <td>
                                  <div><?php echo $Exp['Titulo']; ?></div>
                                  <div><?php echo $Exp['Nombre'].' '.$Exp['Apellidos']; ?></div>
                                </td>
                                <!-- End Nombre -->

                                <!-- Contacto -->
                                <td>
                                  <div>
                                    <i class="fa fa-envelope m-r-5"></i>
                                    <a href="mailto:<?php echo $Exp['Email']; ?>" style="color:#244887;" target:"_top"><?php echo $Exp['Email']; ?></a>
                                  </div>
                                  <div>
                                    <i class="fa fa-phone m-r-5"></i>
                                    <?php echo $Exp['Celular']; ?>
                                  </div>
                                </td>
                                <!-- End Contacto -->

                                <!-- Status -->
                                <td>
                                  <span
                                    class="
                                      label
                                      <?php
                                        if( $Exp[Activo] == '1' ){
                                          echo "label-success";
                                        }elseif( $Exp[Activo] == '0' ){
                                          echo "label-warning";
                                        }
                                      ?>
                                    "
                                  >
                                    <?php
                                      if( $Exp[Activo] == '1' ){
                                        echo "Activo";
                                      }elseif( $Exp[Activo] == '0' ){
                                        echo "Inactivo";
                                      }
                                    ?>
                                  </span>
                                </td>
                                <!-- End Status -->

                                <!-- Editar Btn -->
                                <td>
                                  <?php //if( $Perms[3] ){ ?>
                                    <a href="item?Id=<?php echo $Exp['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>
                                <!-- End Editar Btn -->

                                <!-- Btn Eliminar -->
                                <td width="20">
                                  <?php //if( $Perms[4] ){ ?>

                                    <!-- Btn Eliminar -->
                                    <a data-toggle="modal" href="#Borrar<?php echo $Exp[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>
                                    <!-- End Btn Eliminar -->

                                    <!--Modal Eliminar-->
                                    <form method="POST">
                                      <div id="Borrar<?php echo $Exp[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</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é usuario?</p>
                                                  <p>
                                                    <?php echo $Exp['Nombre'].' '.$Exp['Apellidos'];?><br>
                                                    <?php echo $Exp['Email']; ?><br>
                                                    <?php echo $Exp['Celular']; ?>
                                                  </p>
                                                </div>
                                              </div>
                                            </div>
                                            <div class="modal-footer">
                                                <input name="Borrar"   type="hidden" value="Ok">
                                                <input name="Id" type="hidden" value="<?php echo $Exp[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 Btn Eliminar -->

                              </tr>
                            <?php } ?>
                          </tbody>
                      </table>
                    </div>
                    <!-- End Table -->

                    <!-- Paginador -->
                    <div class="m-t-40 text-right">
                      <!-- <button class="btn btn-secondary">< Primera</button> -->

                      <?php
                        $cantRegistros  = $total_records / $PagerLap;
                        $pgnActual      = $_GET['pgn'];
                        $pag            = new Paginador();
                        $datos          = $pag->paginar($pgnActual, $cantRegistros);
                        if ($datos) {
                          'Pagina: ' . ($_GET['pgn'] + 1) . ' de ' . $pag->getCantidadPaginas() . '<br />';
                      ?>
                        <?php
                          foreach( $datos as $enlace ) {
                        ?>
                          <a
                            href="?pgn=<?php
                              echo $enlace['numero'];
                              echo $Bus;
                            ?>"
                          >
                            <button type="button" class="btn btn-secondary"><?php echo $enlace['vista']; ?></button>
                          </a>
                        <?php } ?>
                      <?php } ?>

                    </div>
                    <!-- End Paginador -->

                  </div>
                </div>
                <!-- End Card -->
              </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>
