<?php
session_start();
include("config.php");
error_reporting(0);
include('funciones.php');
validacion_usuario($con);
include "include/head.php" ?>; 
<link type="text/css" rel="stylesheet" href="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 Noticias</h3>
        </div>
        <div class="panel-body">
          <form id="formulario" name="formulario" method="post" action="noticiasGrabar.php">
              <div class="row">
                <div class="col-md-12">
                  <a class="btn btn-default" href="noticiasNue.php" role="button">Nuevo Registro</a>
                  <button class="btn btn-default" type="submit">Grabar</button>    
                </div>
                <br><br>
                <br><br>
              </div>
              <div id="div_tabla">
                <div class="row">
                <div class="col-md-12">
                  <?php
                    $sql =  "SELECT * FROM noticias WHERE id ORDER BY id DESC LIMIT 0,100";
                    $result=mysqli_query($con,$sql);
                     if($result){
                    $filas=mysqli_num_rows($result);                  
                  ?>
                  <div class="table-responsive">                       
                    <table class="paginacion table table-hover" >
                        <thead>
                            <tr>
                              <th>N°</th>
                              <th>Categoría</th>
                              <th>Título</th>
                              <th>Fecha</th>
                              <th>Publicación</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']; ?>" />
                                    <input name="imagen_cabecera<?php echo $fila['id']; ?>" type="hidden"  id="imagen_cabecera<?php echo $fila['id']; ?>" value="<?php echo $fila['imagen_cabecera']; ?>" />
                                    <input name="imagen_interna<?php echo $fila['id']; ?>" type="hidden"  id="imagen_interna<?php echo $fila['id']; ?>" value="<?php echo $fila['imagen_interna']; ?>" />
                                    <input name="imagen_redes<?php echo $fila['id']; ?>" type="hidden"  id="imagen_redes<?php echo $fila['id']; ?>" value="<?php echo $fila['imagen_redes']; ?>" />                           
                                    <?php echo $fila['id']; ?>
                                  </td>
                                  <td>
                                    <?php
                                      if($fila['categoria'] == 1){
                                        echo "Noticia";
                                      }else if($fila['categoria'] == 2){
                                        echo "Evento";  
                                      }else{
                                        echo "Casos de Éxito"; 
                                      }
                                    ?>
                                  </td>
                                  <td><?php echo $fila['titulo']; ?></td>
                                  <td style="width:100px"><?php 
                                  echo  $fila['fecha_creacion'];?></td>
                                  <td width="98">
                                      <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="0" <?php if (!(strcmp(0, $fila['estado']))) {echo "selected=\"selected\"";} ?>>No</option>
                                      </select>
                                  </td>
                                  <td width="82">                                    
                                    <a class="btn btn-default btn-sm"  onclick="ver(<?php echo $fila['id'];?>);">
                                      <span class="glyphicon glyphicon-search"></span> Ver
                                    </a>
                                  </td>
                                  <td width="82">
                                    <a class="editar btn btn-default btn-sm" onClick="edi(<?php echo $fila['id'];?>);">
                                      <span class="glyphicon glyphicon-edit"></span> Editar
                                    </a>                                  
                                  </td>
                                  <td width="82">
                                    <a class="delete 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 "<div class='text-center'>No hay noticias recientes, por favor agregue nuevos noticias</div>";?></b></td> </tr><?php }// fin del bucle de ordenes  
                                 }else{
                                   echo 'Error al ejecutar la consulta';
                               }
                               ?>
                          </tbody>
                            </table>
                  </div>
                </div>
                </div>
              </div>
          </form>


          <form id="noticiaseditar" action="noticiasEdi.php"  method="post"> 
            <input type="hidden" id="noticiaseditar_id" name="noticiaseditar_id" value=""/>
          </form>

           <form id="noticiasver" action="noticiasVer.php"  method="post"> 
            <input type="hidden" id="noticiasver_id" name="noticiasver_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>
