
<?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
        
        
  include('conect.php');
  $sqlClientes = ("SELECT depto FROM users WHERE logUser = '$profiless'  ");
  $queryData   = mysqli_query($con, $sqlClientes);
  $dto = mysqli_fetch_array($queryData);

   $ndepto = $dto[0];

  ?>







<!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 dpto = '$ndepto' order by fecin asc");
while ($row = $sel->fetch_assoc()) {
    $tmp = $row;
    array_push($res, $tmp);
}
?>




<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" 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>

  <!-- 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">  

 <script type="text/javascript" language="javascript" class="init">
    

$(document).ready(function() {
    $('#example').DataTable();
} );



<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("#myInput").on("keyup", function() {
    var value = $(this).val().toLowerCase();
    $("#myTable tr").filter(function() {
      $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
    });
  });
});
</script>
<style>
table {
  font-family: arial, sans-serif;
  border-collapse: collapse;
  width: 100%;
}

td, th {
  border: 1px solid #dddddd;
  text-align: left;
  padding: 8px;
}

tr:nth-child(even) {
  background-color: #dddddd;
}
</style>

   
         <?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];

  ?>



<body style="height:100px">

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




<h2>Filtrar por palabra</h2>

<input id="myInput" type="text" placeholder="Search..">
<br><br>

    </head>
    <body>
        <div class="container">
            <div class="row justify-content-md-center">
                <div class="col-md-5">
                    <h1>MIS ARRIENDOS</h1>
                </div>
            </div>
            <div class="row justify-content-md-center">
                <div class="col-xl-20">
                    <button type="button" class="btn btn-danger" data-toggle="modal" data-target="#exampleModal">
                        REGISTRAR
                    </button>

                    <table class="table mt-2 table-hover">
                        <thead class="thead-dark">
                            <tr>
                               
                                   <tbody id="myTable">
                           <th class="centered">#</th>
                                <th class="centered">Nombre</th>
                     <th class="centered">Rut</th>
                         <th class="centered">Departamento</th>
                              <th class="centered">Patente</th>
                                  <th class="centered">Tipo</th>
                              <th class="centered">Fono</th>
                               <th class="centered">Fecha de ingreso</th>
                              <th class="centered">Fecha de Salida</th>
                                  <th class="centered">Días de arriendo</th>
                                <th class="centered">Días restantes</th>
                               <th class="centered">Estado</th>
                            <th class="centered">Ver Ficha</th>
                              

                            </tr>
                        </thead>
                        <tbody>

 <?php     


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

                             foreach ($res as $val) { ?>       

                                <tr>
                                     <tbody id="myTable">
              <th scope="row"><?php echo $i++; ?></th>  
                                
                                    <td><?php echo $val['nombre'] ?></td>
                                    <td><?php echo $val['rut'] ?></td>
                                    <td><?php echo $val['dpto'] ?></td>
                                    <td><?php echo $val['ppu'] ?></td>
                                    <td><?php  $val['tipo'];
if ($val['tipo'] == 'PROPIETARIO'){
echo ' <center><a href=""   class="btn btn-warning btn-block ">
          PROPIETARIO
        </a></center>';

}else if

         ($val['tipo'] == 'ARRENDATARIO'){
echo ' <center><a href=""   class="btn btn-primary btn-block">
          ARRENDATARIO
        </a></center>';
}else if

         ($val['tipo'] == 'VISITA'){
echo ' <center><a href=""   class="btn btn-success btn-block">
          VISITA
        </a></center>';
}else if

         ($val['tipo'] == 'INMOBILIARIA'){
echo ' <center><a href=""   class="btn btn-info btn-block">
          INMOBILIARIA
        </a></center>';

}

?></td>       





                                    <td><?php echo $val['fono'] ?></td>
                                    <td><?php echo $val['fecin'] ?></td>
                                    <td><?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>  <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>
        <!-- Modal -->
        <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalLabel">Nuevo archivoSS</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <form enctype="multipart/form-data" id="form1">
                            <div class="form-group">
                                <label for="nombre">NOMBRE PROPIETARIO</label>
                                <input type="text" class="form-control" id="nombre" name="nombre">
                            </div>
                            <div class="form-group">
                                <label for="rut">RUT</label>
                                <input type="text" class="form-control" id="rut" name="rut">
                            </div>
                              <div class="form-group">
                                <label for="fono">FONO</label>
                                <input type="text" class="form-control" id="fono" name="fono">
                            </div>
                              <div class="form-group">
                                <label for="fecin">FECHA DE INGRESO</label>
                                <input type="date" class="form-control" id="fecin" name=fecin>
                            </div>
                              <div class="form-group">
                                <label for="rut">FECHA DE SALIDA</label>
                                <input type="date" class="form-control" id="fecout" name="fecout">
                            </div>
                            <div class="form-group">
                                <label for="dpto">NUMERO DEPARTAMENTO</label>


         <?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];

      ?>

  
    <input type="text"  class="form-control" name="dpto" id="dpto" value="<?php echo $ndepto?>">
   


         
                            </div>
                            <div class="form-group">
                                <label for="ppu">PATENTE VEHICULO</label>
                                <input type="text" class="form-control" id="ppu" name="ppu">
                            </div>
                              <div class="form-group">
                                <label for="tipo">TIPO</label>
                               
      <select class="form-control" id="tipo" name="tipo">
        <option>PROPIETARIO</option>
        <option>ARRENDATARIO</option>
        <option>VISITA</option>
        <option>INMOBILIARIA</option>
      </select>
                           
                            </div>
                            <div class="form-group">
                                <label for="description">SUBIR FICHA</label>
                                <input type="file" class="form-control" id="file" name="file">
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Cerrar</button>




                        <button type="button" class="btn btn-primary" onclick="onSubmitForm()">Cuardar</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal fade" id="modalPdf" tabindex="-1" aria-labelledby="modalPdf" aria-hidden="true">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalLabel">Ver archivo</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <iframe id="iframePDF" frameborder="0" scrolling="no" width="100%" height="500px"></iframe>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Cerrar</button>

                    </div>
                </div>
            </div>
        </div>
        
<script src="js/jquery.min.js"></script>
<script src="'js/popper.min.js"></script>
<script src="js/bootstrap.min.js"></script>

<script type="text/javascript">
    $(document).ready(function() {
        $(window).load(function() {
            $(".cargando").fadeOut(10);
        });      
});
</script>
        <script>
                            function onSubmitForm() {
                                var frm = document.getElementById('form1');
                                var data = new FormData(frm);
                                var xhttp = new XMLHttpRequest();
                                xhttp.onreadystatechange = function () {
                                    if (this.readyState == 4) {
                                        var msg = xhttp.responseText;
                                        if (msg == 'success') {
                                            alert(msg);
                                            $('#exampleModal').modal('hide')
                                        } else {
                                            alert(msg);
                                        }

                                    }
                                };
                                xhttp.open("POST", "upload.php", true);
                                xhttp.send(data);
                                $('#form1').trigger('reset');
                            }
                            function openModelPDF(url) {
                                $('#modalPdf').modal('show');
                                $('#iframePDF').attr('src','<?php echo 'http://' . $_SERVER['HTTP_HOST'] . '/uploadfile/'; ?>'+url);
                            }
        </script>

    </body>
</html>
