<?php
include_once('inc.function.php');
?>

    <style>
        .img-responsive {
           height:100%;
           width:100%;
        }

      .image-container
      {
        width:268px;
        height:260px;
      }
    </style>


<div class="container">
    <div class="row">
        <div class="row">
            <div class="col-md-9">
                <h3>Available Hall For Booking</h3>
            </div>
            <div class="col-md-3">
            </div>
        </div>
        <div id="carousel-example" class="carousel slide hidden-xs" data-ride="carousel">
            <!-- Wrapper for slides -->
            <div class="carousel-inner">
                <div class="item active">
                    <div class="row">

                        <?php
                            $result_check = DB::query("SELECT * FROM bookings WHERE START_DATE <= %s AND END_DATE >= %s AND `FACILITY_REF` NOT IN ('70','71') AND BOOKING_STATUS_REF = 'SSM'",$END_DATE,$START_DATE);
                            foreach ($result_check as $row_check) 
                            {
                                    $row_double_check=DB::queryFirstRow("SELECT * FROM `config_hall` WHERE FAC_ID = %s",$row_check['FACILITY_REF']);
                                    $FACILITY_REF[] = $row_double_check['FAC_AVAILABILITY'];
                                    $f1[] = "SELECT * FROM `config_hall` WHERE FAC_ID = $row_check[FACILITY_REF]";
                            }

                            $f1 = join('||',$f1); 

                            $FAC_AVAILABILITY = join(',',$FACILITY_REF); 

                            $FAC_AVAILABILITY = rtrim($FAC_AVAILABILITY, ",");

                            $SELECTED_HALL = join(',',$FAC_SELECTED);

                            $SELECTED_HALL = rtrim($SELECTED_HALL, ",");

                            $NEW_ARRAY = $FAC_AVAILABILITY.','.$SELECTED_HALL;
                            

                    if( !empty($FAC_AVAILABILITY) ) {
                        if(!empty($_SESSION['ITEM_SELECTED'])) { 
                            $combined = $FAC_AVAILABILITY.",".$SELECTED_HALL;
                            $result_display = DB::query("SELECT * FROM `config_hall` WHERE UPDATE_ILA = 'y' AND FAC_CAPACITY >= $PAX AND FAC_ID NOT IN (".rtrim($combined, ",").")");
                            $f = "SELECT * FROM bookings WHERE START_DATE <= $END_DATE AND END_DATE >= $START_DATE AND `FACILITY_REF` NOT IN ('70','71') AND  BOOKING_STATUS_REF != 'SSM'";
                            $t = '$result_display = DB::query("SELECT * FROM `config_hall` WHERE UPDATE_ILA = y AND FAC_CAPACITY >= $PAX AND FAC_ID NOT IN (".rtrim($combined, ",").")");';
                            $s = "SELECT * FROM `config_hall` WHERE UPDATE_ILA = 'y' AND FAC_CAPACITY >= $PAX AND FAC_ID NOT IN (".rtrim($combined, ",").")";
                        } else {
                            $combined = $FAC_AVAILABILITY;
                            $result_display = DB::query("SELECT * FROM `config_hall` WHERE UPDATE_ILA = 'y' AND FAC_CAPACITY >= $PAX AND FAC_ID NOT IN (".rtrim($combined, ",").")");
                            $f = "SELECT * FROM bookings WHERE START_DATE <= $END_DATE AND END_DATE >= $START_DATE AND `FACILITY_REF` NOT IN ('70','71') AND BOOKING_STATUS_REF != 'SSM'";
                            $t = '$result_display = DB::query("SELECT * FROM `config_hall` WHERE UPDATE_ILA = y AND FAC_CAPACITY >= $PAX AND FAC_ID NOT IN (".rtrim($combined, ",").")");';
                            $s = "SELECT * FROM `config_hall` WHERE UPDATE_ILA = 'y' AND FAC_CAPACITY >= $PAX AND FAC_ID NOT IN (".rtrim($combined, ",").")";
                        }
                    } else {
                        if(!empty($_SESSION['ITEM_SELECTED'])) { 
                            $combined =$SELECTED_HALL;
                            $result_display = DB::query("SELECT * FROM `config_hall` WHERE UPDATE_ILA = 'y' AND FAC_CAPACITY >= $PAX AND FAC_ID NOT IN (".rtrim($combined, ",").")");
                            $f = "SELECT * FROM bookings WHERE START_DATE <= $END_DATE AND END_DATE >= $START_DATE AND `FACILITY_REF` NOT IN ('70','71') AND BOOKING_STATUS_REF != 'SSM'";
                            $t = '$result_display = DB::query("SELECT * FROM `config_hall` WHERE UPDATE_ILA = y AND FAC_CAPACITY >= $PAX AND FAC_ID NOT IN (".rtrim($combined, ",").")");';
                            $s = "SELECT * FROM `config_hall` WHERE UPDATE_ILA = 'y' AND FAC_CAPACITY >= $PAX AND FAC_ID NOT IN (".rtrim($combined, ",").")";
                        } else {
                            $result_display = DB::query("SELECT * FROM `config_hall` WHERE UPDATE_ILA = 'y' AND FAC_CAPACITY >= $PAX");
                            $f = "SELECT * FROM bookings WHERE START_DATE <= $END_DATE AND END_DATE >= $START_DATE AND `FACILITY_REF` NOT IN ('70','71') AND BOOKING_STATUS_REF != 'SSM'";
                            $t = '$result_display = DB::query("SELECT * FROM `config_hall` WHERE UPDATE_ILA = y AND FAC_CAPACITY >= $PAX");';
                            $s = "SELECT * FROM `config_hall` WHERE UPDATE_ILA = 'y' AND FAC_CAPACITY >= $PAX";
                        }
                    }

                            
                            foreach ($result_display as $row_display)
                            {
                                $FAC_ID = $row_display['FAC_ID'];
                                $FAC_MODAL[] = $row_display['FAC_ID'];
                                $FAC_NAME = $row_display['FAC_NAME'];
                                $FAC_FILENAME = $row_display['FAC_FILENAME'];
                                $FAC_CAPACITY = $row_display['FAC_CAPACITY'];

                        ?>


                        <div class="col-sm-3">
                            <div class="col-item">
                                <div class="image-container">
                                    <img src="img/<?php echo $FAC_FILENAME; ?>" class="img-responsive img-thumbnail" />
                                </div>
                                <div class="info">
                                    <div class="row">
                                        <div class="price col-md-10">
                                            <h5>
                                                <?php echo $FAC_NAME; ?> 
                                            </h5>
                                            <h5 class="price-text-color">
                                                Capacity: <?php echo $FAC_CAPACITY; ?>
                                            </h5>
                                        </div>
                                        <div class="rating hidden-sm col-md-2">
                                        </div>
                                    </div>
                                    <div class="separator clear-left">
                                        <p class="btn-add">
                                            <i class="glyphicon glyphicon-shopping-cart"></i><a href="#myModal<?php echo $FAC_ID; ?>" class="hidden-sm" data-toggle="modal">Select Venue</a></p>
                                        <p class="btn-details">
                                            <i class="glyphicon glyphicon-tasks"></i><a href="#myDetail<?php echo $FAC_ID; ?>" class="hidden-sm" data-toggle="modal">More details</a></p>
                                    </div>
                                    <div class="clearfix">
                                    </div>
                                </div>
                            </div>
                        </div>

                        <?php
                                }
                        ?>


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

                        <?php
                            foreach ($FAC_MODAL as $key => $val) {
                            $row_detail = DB::queryFirstRow("SELECT * FROM config_hall WHERE FAC_ID = %i",$val);
                            $ITEM_ID = $row_detail['FAC_ID'];
                            $ITEM_DESCRIPTION = $row_detail['FAC_NAME'];
                            $ITEM_AVAILABILITY = $row_detail['FAC_AVAILABILITY'];
                            $ITEM_UNIT_COST = $row_detail['CORPORATE_RATE'];
                        ?>
                        <!-- Modal Add Layout -->
                        <div id="myModal<?php echo $val; ?>" class="modal fade">
                            <div class="modal-dialog">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                        <h4 class="modal-title">Layout for <?php echo $ITEM_DESCRIPTION; ?></h4>
                                    </div>
                                    <div class="modal-body">
                                        <p class="text-warning"><small>Select Layout For Appropriate Occasion</small></p>
                                        <table class="table table-striped table-bordered table-hover">
                                        <thead>
                                            <tr>
                                                <th class="center">Type</th>
                                                <th class="center">Capacity</th>
                                                <th class="center">Choose</th>
                                            </tr>
                                        </thead>
                                        <form method="POST" action="update_cart.php">
                                        <tbody>
                                            <?php
                                            $result_capacity = DB::query("SELECT * FROM `config_hall_capacity` WHERE FAC_ID = %i",$val);
                                            foreach ($result_capacity as $row_capacity)
                                            {
                                                $SETUP_ID = $row_capacity['ID'];
                                                $SETUP_LAYOUT = $row_capacity['LAYOUT'];
                                                $SETUP_CAPACITY = $row_capacity['FAC_CAPACITY'];
                                            ?>
                                            <tr>
                                                <input type="hidden" name="ITEM_ID" id="ITEM_ID" value="<?php echo $ITEM_ID; ?>">
                                                <input type="hidden" name="ITEM_DESCRIPTION" id="ITEM_DESCRIPTION" value="<?php echo $ITEM_DESCRIPTION; ?>">
                                                <input type="hidden" name="ITEM_AVAILABILITY" id="ITEM_AVAILABILITY" value="<?php echo $ITEM_AVAILABILITY; ?>">
                                                <input type="hidden" name="ITEM_UNIT_COST" id="ITEM_UNIT_COST" value="<?php echo $ITEM_UNIT_COST; ?>">
                                                    <?php
                                                        if($row_capacity['FAC_CAPACITY'] != 0) {
                                                            echo '
                                                            <td class="center">'.$SETUP_LAYOUT.'</td>
                                                            <td class="center">'.$SETUP_CAPACITY.'</td>
                                                            <td class="center"><input type="radio" name="check_list[]" value="'.$SETUP_ID.'"></td>
                                                            ';
                                                        } else {
                                                            echo '';
                                                        }
                                                    ?>
                                            </tr>
                                            <?php } ?>
                                        </tbody>
                                    </table>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-default btn-lg" data-dismiss="modal">Close</button>
                                        <input type="submit" class="btn btn-primary btn-lg" value="Select venue" />
                                    </div>
                                </div>
                            </div>
                        </div>
                        </form>
                        

                        <?php
                                }
                        ?>

                        <?php
                            foreach ($FAC_MODAL as $key => $val) {
                                //$result_detail = mysqli_query($con,"SELECT * FROM config_hall WHERE FAC_ID = '$val'");
                                //$row_detail = mysqli_fetch_assoc($result_detail);
                                $row_detail = DB::queryFirstRow("SELECT * FROM config_hall WHERE FAC_ID = %i",$val);
                        ?>
                        <!-- Modal Add Layout -->
                        <div id="myDetail<?php echo $val; ?>" class="modal fade">
                            <div class="modal-dialog">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                        <h4 class="modal-title">Detail for <?php echo $row_detail['FAC_NAME']; ?></h4>
                                    </div>
                                    <div class="modal-body">
                                        <p class="text-warning"><small>Dimensions & Capacities.</small></p>
                                        <blockquote><p><?php echo $row_detail['FAC_DESCRIPTION']; ?></p></blockquote>
                                    <table class="table table-striped table-bordered table-hover">
                                        <thead>
                                            <tr>
                                                <th class="center">Gross Area</th>
                                                <th class="center">Dimension</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <tr>
                                                <td class="center">Dimension Lenght (m)</td>
                                                <td class="center"><?php echo $row_detail['FAC_DIM_LENGTH']; ?></td>
                                            </tr>
                                             <tr>
                                                <td class="center">Dimension Width (m)</td>
                                                <td class="center"><?php echo $row_detail['FAC_DIM_WIDTH']; ?></td>
                                            </tr>
                                            <tr>
                                                <td class="center">Area Square (m)</td>
                                                <td class="center"><?php echo $row_detail['FAC_AREA_METER']; ?></td>
                                            </tr>
                                            <tr>
                                                <td class="center">Area Square (feet)</td>
                                                <td class="center"><?php echo $row_detail['FAC_AREA_FEET']; ?></td>
                                            </tr>
                                            <tr>
                                                <td class="center">Ceiling Height</td>
                                                <td class="center"><?php echo $row_detail['FAC_CEILING_HEIGHT']; ?></td>
                                            </tr>
                                            <tr>
                                                <td class="center">Wifi</td>
                                                <td class="center"><?php if($row_detail['FAC_WIFI'] == 'Y') { echo 'Yes'; } else { echo 'No'; } ?></td>
                                            </tr>
                                            <tr>
                                                <td class="center">Division</td>
                                                <td class="center"><?php if($row_detail['FAC_DIVISIBLE']== 'Y') { echo 'Yes'; } else { echo 'No'; } ?></td>
                                            </tr>
                                        </tbody>
                                    </table>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-success" data-dismiss="modal">Close</button>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <?php
                                }
                        ?>

