<!DOCTYPE html>
<html lang="en">

<head>
  <meta http-equiv="content-type" content="text/html; charset=iso8859-1"/>
  <!--<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta charset="utf-8">-->
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="">
  <meta name="author" content="">

  <title>Recursos Humanos Puerto Villarroel</title>

  <!-- Bootstrap core CSS -->
  <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

  <!-- Custom fonts for this template -->
  <link href="https://fonts.googleapis.com/css?family=Raleway:100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css?family=Lora:400,400i,700,700i" rel="stylesheet">

  <!-- Custom styles for this template -->
  <link href="css/business-casual.min.css" rel="stylesheet">

  <!--imagen en la ventana-->
  <link href='sistem/img/logo_pestana.png' rel='shortcut icon' type='image/png' />

  <script type="text/javascript" src="sistem/dist/js/funciones.js"></script>
  <!-------funciones personales------->
   
   <style>
      .fancy-button{
        background-color:#c6711b;
        color:#ffffff;
        border:none;
        padding:4px;
        font-size:10px;
        font-weight:bold;
        border-radius:8px;
        cursor:pointer;
        box-shadow: 0 4px 8px rgba(0,0,0,0,3);
        transition: background-color 0.3s ease, transform 0.2s ease;    
      }
      .fancy-button:hover{
        background-color: #ffc00c; 
        transform: scale(1.05);
      }
      .text-uppercase:hover{
        color: #f4fb00; 
        transform: scale(1.05);
      }
      
  </style>

</head>

<body>

  <?php

  $ci = isset($_POST['ci']) ? $_POST['ci'] : "";
  $vermas = isset($_POST['item']) ? $_POST['item'] : 0;
  $id_per = '';
  $accion = isset($_POST['accion']) ? $_POST['accion'] : "";
  $viajes = [];

  include('database/conexion.php');

  switch ($accion) {
    case "change":

      $sentenciasSQL = $conexion->prepare("SELECT * FROM t_personales WHERE numDoc_per=:ci");
      $sentenciasSQL->bindParam(':ci', $ci);
      $sentenciasSQL->execute();
      $user = $sentenciasSQL->fetch(PDO::FETCH_LAZY);
      if ($user) {
        $id_per = $user['id_per'];
        $sentenciasSQL2 = $conexion->prepare("SELECT * FROM t_comision_info WHERE id_per=:id_per");
        $sentenciasSQL2->bindParam(':id_per', $id_per);
        $sentenciasSQL2->execute();
        $viajes = $sentenciasSQL2->fetchAll(PDO::FETCH_ASSOC);
      } else {
        header("Location: lista_no_existe.php");
        sleep(3);
        exit();
      }

      break;
    case "save":

      break;
  }
  ?>

  <!-- Navigation -->
  <nav class="navbar navbar-expand-lg navbar-dark py-lg-4" id="mainNav">
    <div class="container">
      <a class="navbar-brand text-uppercase text-expanded font-weight-bold d-lg-none" href="#">MENÚ</a>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="navbarResponsive">
        <ul class="navbar-nav mx-auto">
          <li class="nav-item active px-lg-4">
            <a class="nav-link text-uppercase text-expanded" href="index.php">GENERAR COMISION
              <span class="sr-only">(current)</span>
            </a>
          </li>
          
          <li class="nav-item active px-lg-4">
            <a class="nav-link text-uppercase text-expanded" href="viajeImprimir.php">Imprimir Viajes Anteriores</a>
          </li>
    
          <li class="nav-item active px-lg-4">
            <a class="nav-link text-uppercase text-expanded" href="informe.php">Generar Informe</a>
          </li>
          
		  <li class="nav-item active px-lg-4">
            <a class="nav-link text-uppercase text-expanded" href="lista_viajes.php">Imprimir Informes anteriores</a>
          </li>
		  
		  <li class="nav-item active px-lg-4">
            <a class="nav-link text-uppercase text-expanded" href="login.php"><button class="fancy-button">L O G I N</button></a>
          </li>
        </ul>
      </div>
    </div>
  </nav>
  <h1 class="site-heading text-center text-white d-none d-lg-block" style="margin-top: 1%;color: #3fda98;">
    <span class="site-heading-upper text-primary mb-3">IMPRIMIR INFORMES GENERADOS</span>
  </h1>
  <section class="page-section about-heading">
    <div class="container">
      <div class="about-heading-content">
        <div class="row">
          <div class="col-xl-9 col-lg-10 mx-auto mx-auto">
            <div class="bg-faded rounded p-3">
              <div class="row">
                <div class="col-md-5">
                  <label> <strong> Buscar por Nº de documentación (C.I.)</strong></label>
                </div>
                <div class="col-md-5">
                  <form name="" action="" method="POST" autocomplete="off">
                    <div class="input-group form"> 
                        <input type="number" name="ci" id="filtrar" value="<?php echo $ci?>" class="form-control" placeholder=" Nº de Carnet Identidad " required>
                        <span class="input-group-btn">
                            <button type="submit" class="btn btn-primary" name="accion" value="change"> Buscar </button>
                        </span>
                    </div>
                  </form>
                </div>

                <div class="col-md-2">
                  <div class="input-group from">
                    <a href="viajeImprimir.php" class="btn btn-info">Cerrar</a>
                  </div>
                </div>
              </div>

             
              <hr>
              <!--......................js para imprimir..................................-->
              <script type="text/javascript">
                function imprimir() {
                  var objeto = document.getElementById('reporteImprimir'); //obtenemos el objeto a imprimir
                  var ventana = window.open('', '_blank'); //abrimos una ventana vacía nueva
                  ventana.document.write(objeto.innerHTML); //imprimimos el HTML del objeto en la nueva ventana
                  ventana.document.close(); //cerramos el documento
                  ventana.print(); //imprimimos la ventana
                  ventana.close(); //cerramos la ventana
                }
              </script>

              <div class="row">
                <div class="col-md-12">
                  

                  <?php
                    if(count($viajes) > 0):
                  ?>

                  <div class="row" style="font-size: 12px">
                    <table class="table table-striped">
                      <thead>
                        <tr>
                          <th scope="col">Intem</th>
                          <th scope="col">Fecha de Solicitud</th>
                          <th scope="col">Destino</th>
                          <th scope="col">Inicio de Viaje</th>
                          <th scope="col">Fin de Viaje</th>
                          <th scope="col">Acciones</th>
                        </tr>
                      </thead>
                      <tbody>
                        <?php foreach ($viajes as $viaje) : ?>

                          <tr>
                            <th scope="row"><?php echo $viaje['id_viaj'] ?></th>
                            <td><?php echo $viaje['fechaReg_viaj'] ?></td>
                            <td><?php
                                $butom = 0;
                                if ($vermas == $viaje['id_viaj']) {
                                  echo  $viaje['motivo_viaj'];
                                  $butom = 1;
                                } else {
                                  echo  substr($viaje['motivo_viaj'], 0, 300);
                                }
                                ?><form name="" action="" method="POST" style="display: inline;" autocomplete="off">
                                <input type="text" name="ci" id="filtrar" style="display: none;" value="<?php echo $ci ?>">
                                <input type="text" name="item" id="item" style="display: none;" value="<?php
                                                                                                        if ($butom == 1) {
                                                                                                          echo 0;
                                                                                                        } else {
                                                                                                          echo $viaje['id_viaj'];
                                                                                                        }
                                                                                                        ?>">
                                <button type="submit" class="btn btn-primary" name="accion" value="change" style="padding: 2px;opacity: 0.6;"> <?php echo $butom ? "Ver menos" : "Ver más"; ?></button>
                              </form>
                            </td>
                            <td><?php echo $viaje['fecha_inc'] ?></td>
                            <td><?php echo $viaje['fecha_fin'] ?></td>
                            <td>
                              <div>
                              <form  action="report.php" method="POST" target="_blank">
                                  <input type="hidden" name="item" value="<?php echo $viaje['id_viaj'] ?>">
                                  <button type="submit" class="btn btn-success "  style="font-size: 8px;">Imprimir</button>
                              </form>
                              </div>
                            </td>
                          </tr>

                        <?php endforeach ?>
                      </tbody>
                    </table>
                  </div>
                  <?php
                    else:
                  ?>
                  <div class="row">
                    <div class="col-md-12">
                      <center> <img src="img/img_generar_informe.jpg" width="80%" ></center>  
                    </div>
                  </div>

                  <?php
                    endif
                  ?>  

                  <hr>
                </div>
              </div>


            </div>
          </div>
        </div>
      </div>
    </div>
  </section>

  <footer class="footer text-faded text-center py-5">
    <div class="container">
      <p class="m-0 small"> Desarrollado por <a href="https://www.facebook.com/profile.php?id=100063951547418" target="_blank">Unidad de Redes y Sistemas</U.R.S.> </a> Gestión 2024 </p>
    </div>
  </footer>

  <!-- Bootstrap core JavaScript -->
  <script src="vendor/jquery/jquery.min.js"></script>
  <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

</body>

</html>