<?php
  session_start();
  if(!(isset($_SESSION["k_name"]))){
        header("location:index.php");
        }
        else{  
 include("includes/conect.php");
 include("includes/timezone.php");

?>
<!DOCTYPE html>
<html lang="es">


<head>
<?php include('head.php'); ?>

<style type="text/css">
  .feather-16{
    width: 20px;
    height: 20px;
}

.feather-24{
    width: 24px;
    height: 24px;
}

.feather-32{
    width: 32px;
    height: 32px;
}
</style>


</head>

<body>
  <div class="loader"></div>
  <div id="app">
    <div class="main-wrapper main-wrapper-1">
      <div class="navbar-bg"></div>
      
      <?php include('navbar.php')?>

      <?php include('sidebar.php')?>
      <!-- Main Content -->

          <div class="main-content">
            <section class="section">


               <div class="col-xl-12 col-lg-12 col-md-12">
                <?php
                if (isset($_GET['full'])) {
                ?>

                    <div class="alert alert-danger alert-dismissible fade show" role="alert">
                        <strong>No disponible!</strong> Capacidad llena para esta Área.
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>

                <?php
                }
 


                if (isset($_GET['succ'])) {
                ?>

                    <div class="alert alert-success alert-dismissible fade show" role="alert">
                        <strong>Reservada cancelada!</strong> Has cancelado tu reserva de forma exitosa.
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>

                <?php
                } 



                if (isset($_GET['succx'])) {
                ?>

                    <div class="alert alert-danger alert-dismissible fade show" role="alert">
                        <strong>Reserva cancelada!</strong>.
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>

                <?php
                } 


                if (isset($_GET['error'])) {
                ?>

                    <div class="alert alert-danger alert-dismissible fade show" role="alert">
                        <strong>Accion no ralizada!</strong> acción no realizada.
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>

                <?php
                } 


                ?>
            </div>

          <div class="d-sm-flex align-items-center justify-content-between mb-4">
            <h1 class="h6 mb-0 text-gray-800">
              <?php
                echo strftime("%d de %B del %Y");
              ?>
            </h1>            
          </div>

          <div class="row">
            <div class="col-12">
              <div class="card">
                <div class="card-header">
                  <h4>Mis reservas</h4> 
                </div>
                <div class="card-body p-0">

                  <div class="table-responsive">
                    <table class="table table-striped">
                      <tr> 
                        <th class='p-0 text-center'>Cancelar</th>
                        <th>Apartamento</th>
                        <th>Área</th>
                        <!-- <th>Id Reservante</th> -->
                        <th>Fecha reserva</th>
                        <th>Hora Inicial</th>
                        <th>Hora Final</th>  
                        <th class='p-0 text-center'>Reservados</th>
                      </tr>

                      <?php

                      $id_ocupante = $_SESSION['k_id'];

                      $contador = 1;

                      $consecutivo = $_SESSION['k_code'];

                        // $result = mysqli_query($conexion, 'SELECT *, COUNT(*) as count_rsv FROM ocupante_reserva inner join area on ocupante_reserva.idarea = area.id inner join turno on ocupante_reserva.jornada = turno.id_tabla_turno where consecutivo =\''.$consecutivo.'\' and ocupante_reserva.fecha_in >= \''.$fecha_hoy.'\' GROUP BY fecha_in order by estado asc, fecha_in asc');
                        // ocupante_reserva.fecha_in >=\''.$fecha_hoy.'\' and 
                        // ocupante_reserva.estado = 0 and


                        $result = mysqli_query($conexion, 'SELECT *, COUNT(*) as cant_rsv FROM ocupante_reserva inner join area on ocupante_reserva.idarea = area.id inner join turno on ocupante_reserva.jornada = turno.id_tabla_turno where consecutivo =\''.$consecutivo.'\' and ocupante_reserva.fecha_in >= \''.$fecha_hoy.'\' GROUP BY ocupante_reserva.consecutivo, ocupante_reserva.fecha_in, ocupante_reserva.hora_in, ocupante_reserva.idarea ORDER BY ocupante_reserva.estado asc, ocupante_reserva.fecha_in asc, ocupante_reserva.hora_in asc');



                        while($row = mysqli_fetch_array($result)){     

                          $fecha_in_search = $row['fecha_in'];
                          $hora_in_search = $row['hora_in'];
                          $area_in_search = $row['idarea'];
                          $apto_in_search = $row['apto_from']; 
 

                           if($row['estado'] == 1){
                            $disabled='#';
                              $btn_cancelar = "<a href='#' style='text-decoration:none; ' class='btn btn-default btn-sm btn-xs m-t-15 waves-effect'>".$contador++." <i class='fas fa-trash'></i> </a>";
                            }else{

                            $disabled="validation/salida_by_area.php?id=".$row['id_tabla']."";
                              $btn_cancelar = "<a href='".$disabled."' style='text-decoration:none; ' class='btn btn-danger btn-sm btn-xs m-t-15 waves-effect'>".$contador++." <i class='fas fa-trash'></i> </a>

                              <i class='feather-16'  data-toggle='tooltip' title='La reserva solo podrá ser cancelada por la persona que la creó.' data-placement='right' data-feather='info'></i>
                              ";
                            } 
                           
                          echo "
                            <tr>
                              <td class='p-0 text-center'>".$btn_cancelar."</td>
                              <td>".$row['apto_from']."</td>                              
                              <td >".$row['nombre']."</td>                              
                              <td >".$row['fecha_in']."</td>
                              <td >".$row['hora_in']."</td>
                              <td >".$row['hora_out']."</td> 
                              <td class='p-0 text-center'>".$row['cant_rsv']."</td>
                            
                            </tr>
                          ";
 
                        } 

                      ?>

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


        <section class="section">
          <a href='bookings.php' style='text-decoration:none; ' class='btn btn-success btn-sm btn-xs m-t-15 waves-effect'><i class='fas fa-calendar'></i> Ver todas mis reservas</a>
        </section>

        
      </div>

      <?php include('footer.php'); ?>

    </div>
  </div>
  <!-- General JS Scripts -->
  <script src="assets/js/app.min.js"></script>
  <!-- JS Libraies -->
  <script src="assets/bundles/apexcharts/apexcharts.min.js"></script>
  <!-- Page Specific JS File -->
  <script src="assets/js/page/index.js"></script>
  <!-- Template JS File -->
  <script src="assets/js/scripts.js"></script>
  <!-- Custom JS File -->
  <script src="assets/js/custom.js"></script>


<script type="text/javascript">
  $(document).ready(function(){
    $('[data-toggle="tooltip"]').tooltip();   
  });
</script>


</body>



</html>
<?php
  }
?>