verturnos.php 11.1 KB
<?php
  session_start();

  require './database.php';

  if (isset($_SESSION['user_id'])) {
    $records = $conn->prepare('SELECT id, email, password FROM users WHERE id = :id');
    $records->bindParam(':id', $_SESSION['user_id']);
    $records->execute();
    $results = $records->fetch(PDO::FETCH_ASSOC);

    $user = null;

    if (count($results) > 0) {
      $user = $results;
    }
  }
  if (isset($_POST['fecha'])){
    $fecha = date("Y-m-d", strtotime($_POST['fecha']));
  }
  $turnos = $conn->prepare("SELECT * FROM turnosv_turnos t, tipo_solicitantes s WHERE t.id_solicitante=s.id_solicitante AND t.fecha='".$fecha."' ORDER BY t.hora ASC");
  $turnos->execute();
  $turnosconfirm = $conn->prepare("SELECT * FROM turnosv_turnos t, tipo_solicitantes s WHERE t.id_solicitante=s.id_solicitante AND verificado IS NOT NULL AND t.fecha='".$fecha."' ORDER BY t.hora ASC");
  $turnosconfirm->execute();
  $turnosnoconfirm = $conn->prepare("SELECT * FROM turnosv_turnos t, tipo_solicitantes s WHERE t.id_solicitante=s.id_solicitante AND verificado IS NULL AND t.fecha='".$fecha."' ORDER BY t.hora ASC");
  $turnosnoconfirm->execute();
?>

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>Listado de turnos - <?php echo date("d/m/Y", strtotime($_POST['fecha']));?></title>
    <link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
     <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jszip-2.5.0/dt-1.10.21/b-1.6.2/b-html5-1.6.2/b-print-1.6.2/datatables.min.css"/>
    <link rel="stylesheet" href="assets/css/style.css">
  </head>
  <body>
    <?php if(!empty($user)): ?>
      <nav class="navbar navbar-light" style="background-image: url('img/fondoheader.png'); background-repeat: no-repeat; background-position: center; background-size: cover;">
        <div class="navbar-brand mx-auto" >
          <img src="img/logo.png" width="350px" height="75%">
        </div>  
      </nav>
      <br>
      <div class="container">
        <div class="row">
          <div class="col-lg-10 col-md-10 col-sm-12 col-xs-12">
            <h5><b>LISTADO DE TURNOS - <?php echo date("d/m/Y", strtotime($_POST['fecha']));?></b>  <h4>Turnos confirmados: <span class="badge badge-info"><?php echo $turnosconfirm->rowCount(); ?></span> Turnos no confirmados: <span class="badge badge-info"><?php echo $turnosnoconfirm->rowCount(); ?></span></h4></h5>
          </div>
          <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12 text-right">
            <a href="logout.php" class="btn btn-sm btn-warning"><b>Cerrar Sesión</b></a>
          </div>
        </div>
        <hr style="border-style: solid; border-width: 1px;">
        <div class="row">
          <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
            <nav>
                            <div class="nav nav-tabs nav-fill" id="nav-tab" role="tablist">
                                <a class="nav-item nav-link active" id="nav-home-tab" data-toggle="tab" href="#nav-home" role="tab" aria-controls="nav-home" aria-selected="true">Todos los turnos</a>
                                <a class="nav-item nav-link" id="nav-profile-tab" data-toggle="tab" href="#nav-profile" role="tab" aria-controls="nav-profile" aria-selected="false">Turnos Confirmados</a>
                            </div>
                        </nav>
                        <!-- Todos los turnos -->
                        <div class="tab-content" id="nav-tabContent">
                            <div class="tab-pane fade show active" id="nav-home" role="tabpanel" aria-labelledby="nav-home-tab">
                              <br>
                              <div class="table-responsive">
                                <table class="display tabladt" style="width:100%">
                                  <thead>
                                    <tr>
                                      <th>HORARIO</th>
                                      <th>DNI</th>
                                      <th>NOMBRE Y APELLIDO</th>
                                      <th>TIPO SOLICITANTE</th>
                                      <th>TELEFONO</th>
                                      <th>E-MAIL</th>
                                      <th>CONFIRMADO</th>
                                    </tr>
                                  </thead>
                                  <tbody>
                                    <?php
                                    while($row = $turnos->fetch(PDO::FETCH_ASSOC)) {
                                      if (!empty($row['verificado'])){
                                        $verificado = "SI";
                                      } else {
                                        $verificado = "NO";
                                      }
                                      echo "<tr><td>".substr($row['hora'],0,5)."</td><td>".$row["dni"]."</td><td>".$row["nombre_apellido"]."</td><td>".$row["descripcion"]."</td><td>".$row["telefono"]."</td><td>".$row["email"]."</td><td>".$verificado."</td></tr>";
                                    }
                                    ?>
                                  </tbody>
                                </table>
                              </div>
                            </div>
                            <!-- Fin todos los turnos -->
                            <!-- Solo turnos confirmados -->
                            <div class="tab-pane fade" id="nav-profile" role="tabpanel" aria-labelledby="nav-profile-tab">
                              <br>
                              <div class="table-responsive">
                                <table class="display tabladt" style="width:100%">
                                  <thead>
                                    <tr>
                                      <th>HORARIO</th>
                                      <th>DNI</th>
                                      <th>NOMBRE Y APELLIDO</th>
                                      <th>TIPO SOLICITANTE</th>
                                      <th>TELEFONO</th>
                                      <th>E-MAIL</th>
                                      <th>CONFIRMADO</th>
                                    </tr>
                                  </thead>
                                  <tbody>
                                    <?php
                                    while($row = $turnosconfirm->fetch(PDO::FETCH_ASSOC)) {
                                      if (!empty($row['verificado'])){
                                        $verificado = "SI";
                                      } else {
                                        $verificado = "NO";
                                      }
                                      echo "<tr><td>".substr($row['hora'],0,5)."</td><td>".$row["dni"]."</td><td>".$row["nombre_apellido"]."</td><td>".$row["descripcion"]."</td><td>".$row["telefono"]."</td><td>".$row["email"]."</td><td>".$verificado."</td></tr>";
                                    }
                                    ?>
                                  </tbody>
                                </table>
                              </div>
                            </div>
                            <!-- FIN Solo turnos confirmados -->
                        </div>
                        <br>
          </div>
        </div>
      </div>
      
    <?php else:
      header('Location: login.php');  
    endif; ?>
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
  <script type="text/javascript" src="https://cdn.datatables.net/v/dt/jszip-2.5.0/dt-1.10.21/b-1.6.2/b-html5-1.6.2/b-print-1.6.2/datatables.min.js"></script>
  <script type="text/javascript">
    $(document).ready(function() {
      $('.tabladt').DataTable( {
        columnDefs: [ { orderable: false, targets: [0,1,2,3,4,5] }],
        language: {
          "sProcessing":     "Procesando...",
          "sLengthMenu":     "Mostrar _MENU_ registros",
          "sZeroRecords":    "No se encontraron resultados",
          "sEmptyTable":     "Ningún dato disponible en esta tabla",
          "sInfo":           "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
          "sInfoEmpty":      "Mostrando registros del 0 al 0 de un total de 0 registros",
          "sInfoFiltered":   "(filtrado de un total de _MAX_ registros)",
          "sInfoPostFix":    "",
          "sSearch":         "Buscar:",
          "sUrl":            "",
          "sInfoThousands":  ",",
          "sLoadingRecords": "Cargando...",
          "oPaginate": {
            "sFirst":    "Primero",
            "sLast":     "Último",
            "sNext":     "Siguiente",
            "sPrevious": "Anterior"
          },
          "oAria": {
            "sSortAscending":  ": Activar para ordenar la columna de manera ascendente",
            "sSortDescending": ": Activar para ordenar la columna de manera descendente"
          },
          "buttons": {
            "copy": "Copiar",
            "colvis": "Visibilidad",
            "print": "Imprimir"
          }
        },
        dom: 'Bfrtip',
        buttons: [
        'excelHtml5',
          { 
            extend: 'print',
            customize: function(win)
            {
 
                var last = null;
                var current = null;
                var bod = [];
 
                var css = '@page { size: landscape; }',
                    head = win.document.head || win.document.getElementsByTagName('head')[0],
                    style = win.document.createElement('style');
 
                style.type = 'text/css';
                style.media = 'print';
 
                if (style.styleSheet)
                {
                  style.styleSheet.cssText = css;
                }
                else
                {
                  style.appendChild(win.document.createTextNode(css));
                }
 
                head.appendChild(style);
            },
            messageTop: 'Turnos confirmados: <?php echo $turnosconfirm->rowCount(); ?> - Turnos no confirmados: <?php echo $turnosnoconfirm->rowCount(); ?>'
          }
        // 'excelHtml5',
        // 'pdfHtml5',
        // 'print'
        ]
      } );
    } );
  </script>
  </body>
</html>