<?php
  session_start();
  include("config.php");
  include('funciones.php');
  validacion_usuario($con);
  include "include/head.php" ?>; 
  <link type="text/css" rel="stylesheet" href="<?php echo $host;?>admin/css/jpagination/PaginateMyTable.min.css" />
</head>
<body>
<?php include("include/menu.php") ?>  
 <div class="container margin-top">
    <div class="panel panel-info">
          <div class="panel-heading">
             <h3 class="panel-title">Lista de Banner</h3>
          </div>
          <div class="panel-body">
            <form id="formulario" name="formulario" method="post" action="bannerGrabar.php">
              <div class="row">
                  <div class="col-md-12">
                    <a class="btn btn-default" href="bannerNue.php" role="button">Nuevo Registro</a>
                    <button class="btn btn-default" type="submit">Grabar</button>    
                  </div><br><br><br><br>
                </div>
                <div class="row">
                <div class="col-md-12">
                  <div id="div_tablabanner">
                   <?php
                      $sql =  "SELECT * FROM banner WHERE id ORDER BY id DESC LIMIT 0,100";
                      $result=mysqli_query($con,$sql);
                      if($result){
                        $filas=mysqli_num_rows($result);  
                        if($filas >0){                
                    ?>
                    <div class="table-responsive">
                    <table class="paginacion table table-hover">
                          <thead>
                            <tr>
                              <th>N°</th>
                              <th>Link</th>
                              <th>Orden</th>
                              <th>Publicación</th>
                              <th>Fecha</th>
                              <th>Ver</th>
                              <th>Editar</th>
                              <th>Eliminar</th>
                            </tr>
                          </thead>                                
                          <tbody>
                             <?php 

                             if($filas >0){

                                while ($fila =mysqli_fetch_assoc($result)) { ?>
                                <tr>
                                  <td scope="row">
                                    <input name="id[]" type="hidden"  id="id[]" value="<?php echo $fila['id']; ?>" /><?php echo $fila['id'];?>
                                    <input name="imagen_escritorio<?php echo $fila['id']; ?>" type="hidden"  id="imagen_escritorio<?php echo $fila['id']; ?>" value="<?php echo $fila['imagen_escritorio']; ?>" />
                                    <input name="imagen_mobile<?php echo $fila['id']; ?>" type="hidden"  id="imagen_mobile<?php echo $fila['id']; ?>" value="<?php echo $fila['imagen_mobile']; ?>" />                                 
                                  </td>
                                  <td><?php echo $fila['link']; ?></td>
                                  <td>
                                    <select style="width:100px" name="orden[]" id="orden[]" title="<?= $fila['id']; ?>" class="form-control" >
                                      <option value="0" <?php if (!(strcmp(0, $fila['orden']))) {echo "selected=\"selected\"";} ?>>Ninguno</option>
                                      <option value="1" <?php if (!(strcmp(1, $fila['orden']))) {echo "selected=\"selected\"";} ?>>1</option>
                                      <option value="2" <?php if (!(strcmp(2, $fila['orden']))) {echo "selected=\"selected\"";} ?>>2</option>
                                      <option value="3" <?php if (!(strcmp(3, $fila['orden']))) {echo "selected=\"selected\"";} ?>>3</option>
                                      <option value="4" <?php if (!(strcmp(4, $fila['orden']))) {echo "selected=\"selected\"";} ?>>4</option>
                                      <option value="5" <?php if (!(strcmp(5, $fila['orden']))) {echo "selected=\"selected\"";} ?>>5</option>
                                    </select>                                                
                                  </td>
                                  <td>
                                    <select name="estado[]" id="estado[]" title="<?= $fila['id']; ?>" class="form-control">
                                        <option value="1" <?php if (!(strcmp("1", $fila['estado']))) {echo "selected=\"selected\"";} ?>>Si</option>
                                        <option value="2" <?php if (!(strcmp("2", $fila['estado']))) {echo "selected=\"selected\"";} ?>>No</option>
                                    </select>
                                  </td> 
                                   <td style="width:100px"><?php 
                                     echo  $fila['fecha_creacion'];?></td>                                         
                                  <td width="82">                                    
                                    <a class="btn btn-default btn-sm" onClick="ver_banner(<?php echo $fila['id'];?>);">
                                      <span class="glyphicon glyphicon-search"></span>Ver
                                    </a>
                                  </td>
                                   <td width="82">
                                    <a class="btn btn-default btn-sm" onClick="edi_banner(<?php echo $fila['id'];?>);">
                                      <span class="glyphicon glyphicon-edit"></span> Editar
                                    </a> 
                                  </td>
                                  <td width="82">
                                    <a class="deletebanner btn btn-default btn-sm"><span class="glyphicon glyphicon-remove"></span>Eliminar</a>
                                  </td>
                                </tr>
                        <?php }
                      }else{ ?><tr><td colspan="10" align="center"><b><?php echo "No hay registros";?></b></td> </tr>
                      <?php }
                      }else{
                          echo "<div class='text-center'>No hay banner recientes, por favor agregue nuevos banner</div>";
                      }                    
                    }else{
                        echo 'Error al ejecutar la consulta';
                    }?>
                      </tbody>
                    </table>
                    </div>
                  </div>    
              </div>
            </div>
          </form>
          <form id="bannerEdi" action="bannerEdi.php"  method="post"> 
            <input type="hidden" id="bannereditar_id" name="bannereditar_id" value=""/>
          </form>
          <form id="bannerVer" action="bannerVer.php"  method="post"> 
            <input type="hidden" id="bannerver_id" name="bannerver_id" value=""/>
          </form>
        </div>     
    </div>
  </div>         
<?php include "include/footer.php"; ?>
    <script src="js/jpagination/PaginateMyTable.min.js"></script>
    <script>
    $(document).ready(function() {
      $(".paginacion").paginate();
    });
    </script>
</body>
</html>
