
<?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);
}


?>


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

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

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

                    <br><br>

                     <!-- 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">Formulario de Registro</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">



         <?php
        
        
   $nomb =$profiless;

      ?>

  
    <input style="visibility:hidden" type="text"  class="form-control" name="prop" id="prop" value="<?php echo $nomb?>">
                            <div class="form-group">

                                <label for="nombre">NOMBRE ARRENDATARIO</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>ARRENDATARIO</option>
        <option>PROPIETARIO</option>
        <option>FAMILIAR</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"  ><a href="http://192.168.100.254/datatables/datatables/administrador.php">Cerrar</button></a>




                        <button type="submit"  onclick="onSubmitForm()"><a href="http://192.168.100.254/datatables/datatables/administrador.php">Registrar</button></a>


                    </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>

     
    <!--Ejemplo tabla con DataTables-->
    <div class="container">
        <div class="row">
                <div class="col-lg-20">
                    <div class="table-responsive">        
                        <table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
                        <thead>
                            <tr>
                                <th>#</th>
                                 <th>Registrado por</th>
                                <th>Nombre Arrendatario</th>
                                <th>Rut</th>                               
                                <th>Depto</th>
                                <th>Patente</th>                                
                                <th>Fono</th>
                                 <th>Tipo</th>
                                <th>Fecha de Ingreso</th>
                                <th>Fecha de Salida</th>
                                <th>Dias Arriendo</th>
                                <th>Termina en</th>
                                <th>Estado</th>
                                <th>Ficha</th>
                                <th>Editar</th>
                                <th>Borrar</th>
                                   <th>Correo</th>
                                
                                
                            </tr>
                        </thead>
                       <tbody>

 <?php     


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

                             foreach ($res as $val) { ?>       

                                <tr>
                                     
              <th scope="row"><?php echo $i++; ?></th>  
                                
                                  <td><?php echo $val['prop'] ?></td>
                                    <td><?php echo $val['nombre'] ?></td>
                                    <td><?php echo $val['rut'] ?></td>
                                    <td><h5><center><?php echo $val['dpto'] ?></h5></center></td>
                                    <td><h5><center><?php echo $val['ppu'] ?></h5></center></td>
                                  
                                    <td><?php echo $val['fono'] ?></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['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>    <h5><center>   <?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
        ;

}


?>
                              </center>  </h5>   </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> <center> 


                                    <?php  if ($val['url'] <> '') {
                                       
                                     ?>
                                        <a class="btn btn-info" target="_black"  href="<?php echo 'http://' . $_SERVER['HTTP_HOST'] . '/uploadfile/' . $val['url']; ?>" ><span class="glyphicon glyphicon-file"></span>  </a>
                                    <?php   }else{  echo 'NO REGISTRA';
                                        } ?>

                               </center>    </td>

                    <td>               <center>  
<a href="updatecde.php?variable1=<?= $val['id'] ?>" class="btn btn-success " name="submit" type="submit"/a>
          <span class=" glyphicon glyphicon-pencil"></span> </center></td>
              <td>                 <center> 
<a href="delete_ruc.php?variable1=<?= $val['id'] ?>" class="btn btn-danger " name="submit" type="submit"/a>
          <span class="glyphicon glyphicon-trash"></span> </center></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>-->

            <td> <center> <a href="javascript:window.open('http://192.168.100.254/datatables/datatables/mail/index.php?page=new_email&email=<?= $val['nombre'] ?>&folder=email&name=<?= $nomb?>&asunto=<?= $val['dpto'] ?>&last_name=<?= $val['fono'] ?>&fecin=<?= $val['fecin'] ?>&fecout=<?= $val['fecout'] ?>&url=<?= $val['url'] ?>','','width=1500,height=700,left=100,top=100,toolbar=yes');void 0"class="btn btn-warning " name="submit" type="submit"/a>
          <span class="glyphicon glyphicon-envelope"></span> </td> </center>

                         
                            </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>
