

<?php



//llamamos la constante URL

//controlamos que se haya iniciado session.
require 'class/sessions.php';
$objSes = new Sessions();
$objSes->init();

$profiless = $objSes->get('login');
$profile = $objSes->get('profi');

if((!isset($profile))&&($profile != 'Stardard')){
    header('location: ' . URL);
}


?>

<?php

$variable1=($_GET['variable1']);

"$variable1";


?>




<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<?php
include('conexion.php');

$tmp = array();
$res = array();

$sel = $con->query("SELECT * FROM files where id = $variable1 order by fecin asc");
while ($row = $sel->fetch_assoc()) {
    $tmp = $row;
    array_push($res, $tmp);
}
?>

<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="shortcut icon" href="#" />  
    <title>Tutorial DataTables</title>
      
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <!-- CSS personalizado --> 
    <link rel="stylesheet" href="main.css">  
      
    <!--datables CSS básico
    <link rel="stylesheet" type="text/css" href="datatables/datatables.min.css"/>-->
    <!--datables estilo bootstrap 4 CSS-->  
    <link rel="stylesheet"  type="text/css" href="datatables/DataTables-1.10.18/css/dataTables.bootstrap4.min.css">
           
    <!--font awesome con CDN-->  
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css" integrity="sha384-oS3vJWv+0UjzBfQzYUhtDYW+Pj2yciDJxpsK1OYPAYjqT085Qq/1cq5FLXAZQ7Ay" crossorigin="anonymous">  


  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>

     <?php
        
        
  include('conect.php');
  $sqlClientes = ("SELECT depto FROM users WHERE logUser = '$profiless'");
  $queryData   = mysqli_query($con, $sqlClientes);
  $dto = mysqli_fetch_array($queryData);

   $ndepto = $dto[0];

  ?>

  </head>
    
 <body style="height:100px">

<nav class="navbar navbar-expand-sm bg-info navbar-dark">
 
    <div class="my-2 my-lg-0">
   <h1>Bienvenido(a): <?php echo $profiless ?> -  Departamento:  <?php echo $ndepto ?> </h1>
    </div>
</nav>

     
    <!--Ejemplo tabla con DataTables-->
    <form action="updates.php" method="POST">
    <div class="container">
        <div class="row">
                <div class="col-lg-12">
                    <div class="table-responsive">        
                        <table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
                        <thead>
                            <tr>
                                <th>#</th>
                                <th>Nombre</th>
                                <th>Rut</th>                               
                                <th>Depto</th>
                                <th>Patente</th>
                                <th>Tipo</th>
                                <th>Fono</th>
                                <th>Fecha de Ingreso</th>
                                <th>Fecha de Salida</th>
                                <th>Dias Arriendo</th>
                                <th>Restantes</th>
                                <th>Estado</th>
                                <th>Ficha</th>
                                  <th>Actualizar</th>
                            </tr>
                        </thead>
                       <tbody>



                 <!--            <input type="text"  style="visibility:hidden" class="form-control" name="id"  value="<?php echo $data['ID']?>">

              <th scope="row"><?php echo $i++; ?></th>  
              <td><strong><a href="http://frfamae010:270/carpeta_digital_v9/index.php?ruc=<?php echo $data['RUC'];?>&rut=<?php echo $rut;?>"><?php echo $data['RUC']; ?></strong></td> 
              
             <td> <input class="form-control input-lg" id="inputlg" type="text" name="observacion"  value="<?php echo $data['OBSERVACION']?>"> </td>
             
       
</tr>



  <center> <input class="btn btn-success" name="submit" type="submit" value="Grabar" /></center> -->
         

 <?php     


            
            $rut = '15844765-7';
            $i = 1;

                             foreach ($res as $val) { ?>       

                                <tr>
  <input type="text"   style="visibility:hidden" class="form-control" name="id"  value="<?php echo $val['id']?>">

                                     
  <th scope="row"><?php echo $i++; ?></th>  

                                
  <td> <input class="form-control input-lg" id="inputlg" type="text" name="nombre"  value="<?php echo $val['nombre'] ?>"> </td>
  <td> <input class="form-control input-lg" id="inputlg" type="text" name="rut"  value="<?php echo $val['rut'] ?>"> </td>
  <td> <input class="form-control input-lg" id="inputlg" type="text" name="dpto"  value="<?php echo $val['dpto'] ?>"> </td>
  <td> <input class="form-control input-lg" id="inputlg" type="text" name="ppu"  value="<?php echo $val['ppu'] ?>"> </td>
  <td> <input class="form-control input-lg" id="inputlg" type="text" name="tipo"  value="<?php echo $val['tipo']?>"> 

   
                               
      <select class="form-control" id="tipo" name="tipo">
        <option>PROPIETARIO</option>
        <option>ARRENDATARIO</option>
        <option>VISITA</option>
        <option>INMOBILIARIA</option>
      </select>
                           
                          


 </td>      
  <td> <input class="form-control input-lg" id="inputlg" type="text" name="fono"  value="<?php echo $val['fono']?>"> </td>
  <td> <input class="form-control input-lg" id="inputlg" type="date" name="fecin"  value="<?php echo $val['fecin'] ?>"> </td>
  <td> <input class="form-control input-lg" id="inputlg" type="date" name="fecout"  value="<?php echo $val['fecout'] ?>"> </td>




                       

                                   <td>        <?php 

$fechain =   $val['fecin'];
$fechaout =  $val['fecout'];


  $fechaActual = date('Y-m-d'); 
  $datetime1 = date_create($fechain);
  $datetime2 = date_create($fechaout);
  $contador2 = date_diff($datetime2, $datetime1);
  $differenceFormat = '%a';
  echo $contador2->format($differenceFormat);


?>
                                  </td>


                                   <td>        <?php 

                                   if (($fechaActual < $fechaout)) {
                                    


  $fechaActual = date('Y-m-d'); 
  $datetime = date_create($fechaActual);
  $datetime2 = date_create($fechaout);
  $contador = date_diff($datetime2, $datetime);
  $differenceFormat = '%a';
  echo $contador->format($differenceFormat) +1;

 }else{
 
 $cero = 0;
         
echo           $cero
        ;

}


?>
                                  </td>

                                    <td>        <?php 


                                    $fechain =   $val['fecin'];
                                    $fechaout =  $val['fecout'];
                                    $fechaActual = date('Y-m-d'); 

if (($fechaout > $fechain) && ($fechain > $fechaActual)){
                                    


  echo ' <center><a href=""   class="btn btn-warning btn-block">
          Pendiente
        </a></center>';

}else if (($fechaActual >= $fechain)  && ($fechaout >= $fechaActual)){
echo ' <center><a href=""   class="btn btn-success btn-block">
          Vigente
        </a></center>';

 }elseif (($fechaActual > $fechaout) && ($fechaout >=$fechain)){
echo ' <center><a href=""   class="btn btn-danger btn-block">
          Terminado
        </a></center>';
         


}


?>
                                  </td>




                        <!--       <td>
                                        <button onclick="openModelPDF('<?php echo $val['url'] ?>')" class="btn btn-primary" type="button">Ver FICHA Modal</button>
                                        <a class="btn btn-success" target="_black" href="<?php echo 'http://' . $_SERVER['HTTP_HOST'] . '/uploadfile/' . $val['url']; ?>" >Ver FICHA pagina</a>
                                    </td>-->

                                     <td>
                                     
                                        <a class="btn btn-info" target="_black"  href="<?php echo 'http://' . $_SERVER['HTTP_HOST'] . '/uploadfile/' . $val['url']; ?>" ><span class="glyphicon glyphicon-file"></span>  </a>
                                    </td>

                                     <td>  <center> <input class="btn btn-success" name="submit" type="submit" value="Grabar" /></center> 

        <!--    <td>  <a href="updatechek.php?variable1=<?= $data['FECHA_CARGA']?>&variable2=<?= $data['ID']?>" class="btn btn-warning btn-lg" name="submit" type="submit"/a>
          <span class="glyphicon glyphicon-floppy-saved"></span> </td>-->
                         
                            </tr> 
                            <?php } ?>                          
                        </tbody>        
                       </table>                  
                    </div>
                </div>
        </div>  
    </div>   
     
    <!-- jQuery, Popper.js, Bootstrap JS -->
    <script src="jquery/jquery-3.3.1.min.js"></script>
    <script src="popper/popper.min.js"></script>
    <script src="bootstrap/js/bootstrap.min.js"></script>
      
    <!-- datatables JS -->
    <script type="text/javascript" src="datatables/datatables.min.js"></script>    
     
    <!-- para usar botones en datatables JS -->  
    <script src="datatables/Buttons-1.5.6/js/dataTables.buttons.min.js"></script>  
    <script src="datatables/JSZip-2.5.0/jszip.min.js"></script>    
    <script src="datatables/pdfmake-0.1.36/pdfmake.min.js"></script>    
    <script src="datatables/pdfmake-0.1.36/vfs_fonts.js"></script>
    <script src="datatables/Buttons-1.5.6/js/buttons.html5.min.js"></script>
     
    <!-- código JS propìo-->    
    <script type="text/javascript" src="main.js"></script>  
    
    
  </body>
</html>
