<?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'); ?>
</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['inside'])) {
                ?>

                    <div class="alert alert-warning alert-dismissible fade show" role="alert">
                        <strong>No puedes reservar!</strong> Ya has Reservado en esta u otra área, pirmero debes realizar la salida o cancelar la reserva.
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>

                <?php
                } 


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

                    <div class="alert alert-success alert-dismissible fade show" role="alert">
                        <strong>Área reservada!</strong> Ha reservado de forma exitosa. Ésta se hará efectiva al momento del ingreso ó usted podrá cancelarla en cualquier momento, si la reserva no ha sido confirmada en un lapso de 2 horas el sistema la cancelará de forma automática.
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>

                <?php
                } 



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

                    <div class="alert alert-success alert-dismissible fade show" role="alert">
                        <strong>Usuario verificado de forma exitosa!</strong>
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>

                <?php
                } 



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

                    <div class="alert alert-danger alert-dismissible fade show" role="alert">
                        <strong>Error! Usuario no pudo ser verificado.</strong>
                        <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("%a %d de %B del %Y");
              ?>
            </h1>            
          </div>


            <div class="row ">


            <?php
 


                $result_areas = mysqli_query($conexion, 'SELECT id_area_matriz as id_del_area, nombre_area, url, width_img FROM area_matriz where area_activa = 1 order by nombre_area asc');
                while($row_areas = mysqli_fetch_array($result_areas)){

                   $image = " <img src='assets/img/banner/".$row_areas['url']."' alt='' width='".$row_areas['width_img']."px' height='100px'>";
                   $label = 'Verificar';
 

                 echo "
                    <div class='col-xl-3 col-lg-6 col-md-6 col-sm-6 col-xs-12'>
                      <div class='card'>
                        <div class='card-statistic-4'>
                          <div class='align-items-center justify-content-between'>
                            <div class='row '>
                              <div class='col-lg-6 col-md-6 col-sm-6 col-xs-6 pr-0 pt-3'>
                                <div class='card-content'>
                                  <h5 class='font-15'>".$row_areas['nombre_area']."</h5>
                                  <input type='hidden' value='".$row_areas['nombre_area']."' id='name_area_".$row_areas['id_del_area']."'>
                                  <h2 class='mb-3 font-14'>";
                                  // if ($row['id_del_area'] == 6){
                                  //   echo "Capacidad: ".$row['capacidad'];
                                  // }
                                  
                                  echo "</h2>
                                  <p class='mb-0'><span class='col-blue'>
                                     
                                  </span></p> 



                                  <a href='make_checkout.php?ida=".$row_areas['id_del_area']."&na=".$row_areas['nombre_area']."' class='btn btn-info btn-sm  btnrsv'>$label </a>
                                  <input type='hidden' id='area_".$row_areas['id_del_area']."' value='".$row_areas['id_del_area'].$row_areas['nombre_area']."'> 
                                   
                                </div>
                              </div>
                              <div class='col-lg-6 col-md-6 col-sm-6 col-xs-6 pl-0'>
                                <div class='banner-img'>
                                 $image
                                </div>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>";

                }

            ?>
          </div> 
    
 
 
         


        

        </section>
 

        <!-- moadal para ingreso -->
        <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="formModal"
          aria-hidden="true">
          <div class="modal-dialog" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <h5 class="modal-title" id="formModal">Apartamento</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 action='validation/inbooking.php' method='post'>
                <input type="hidden" id='input_area' name="input_area">

                  <div class="form-group">
                    <label>Apartamento Húesped</label>
                    <div class="input-group">
                      <div class="input-group-prepend">
                        <div class="input-group-text">
                          <i class="fas fa-home"></i>
                        </div>
                      </div>
                      <div class="col-xs-6">
                        <select class="custom-select" name="apto_from" style="width:175px"> 

                          <?php 
                            $result_apto = mysqli_query($conexion, 'SELECT * FROM apartamento order by id asc');
                            while($row_apto = mysqli_fetch_array($result_apto)){
                              echo "<option value='".$row_apto['num_apto']."'>".$row_apto['num_apto']."</option>";
                            }
                          ?>

                        </select>
                      </div>
                    </div>
                  </div>  

                  <button type="submit" class="btn btn-success m-t-15 waves-effect">Reservar</button>
                </form>

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

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

    $('.btnrsv').click(function(){
      // alert($(this).val());
      $("#input_area").val($(this).val())
    })

    // input_area
    
  </script>

</body>

</html>

<?php
  }
?>