Exemplo n.º 1
0
 function trav_ajax_acc_get_available_rooms()
 {
     //validation and initiate variables
     $result_json = array('success' => 0, 'result' => '');
     if (!isset($_POST['_wpnonce']) || !isset($_POST['accommodation_id']) || !wp_verify_nonce($_POST['_wpnonce'], 'post-' . sanitize_text_field($_POST['accommodation_id']))) {
         $result_json['success'] = 0;
         $result_json['result'] = __('Sorry, your nonce did not verify.', 'trav');
         wp_send_json($result_json);
     }
     $rooms = isset($_POST['rooms']) && is_numeric($_POST['rooms']) ? sanitize_text_field($_POST['rooms']) : 1;
     $adults = isset($_POST['adults']) && is_numeric($_POST['adults']) ? sanitize_text_field($_POST['adults']) : 1;
     $kids = isset($_POST['kids']) && is_numeric($_POST['kids']) ? sanitize_text_field($_POST['kids']) : 0;
     $child_ages = isset($_POST['child_ages']) ? $_POST['child_ages'] : '';
     if (isset($_POST['accommodation_id']) && isset($_POST['date_from']) && trav_strtotime($_POST['date_from']) && isset($_POST['date_to']) && trav_strtotime($_POST['date_to']) && time() - 60 * 60 * 24 < trav_strtotime($_POST['date_from'])) {
         $acc_id = (int) $_POST['accommodation_id'];
         $except_booking_no = 0;
         $pin_code = 0;
         if (isset($_POST['edit_booking_no'])) {
             $except_booking_no = sanitize_text_field($_POST['edit_booking_no']);
         }
         if (isset($_POST['pin_code'])) {
             $pin_code = sanitize_text_field($_POST['pin_code']);
         }
         $return_value = trav_acc_get_available_rooms($acc_id, $_POST['date_from'], $_POST['date_to'], $rooms, $adults, $kids, $child_ages, $except_booking_no, $pin_code);
         if (!empty($return_value) && is_array($return_value)) {
             $number_of_days = count($return_value['check_dates']);
             ob_start();
             $available_room_type_ids = $return_value['bookable_room_type_ids'];
             if (!empty($available_room_type_ids)) {
                 foreach ($available_room_type_ids as $room_type_id) {
                     $room_price = 0;
                     foreach ($return_value['check_dates'] as $check_date) {
                         $room_price += (double) $return_value['prices'][$room_type_id][$check_date]['total'];
                     }
                     trav_acc_get_room_detail_html($room_type_id, 'available', $room_price, $number_of_days, $rooms);
                 }
             }
             $not_available_room_type_ids = array_diff($return_value['matched_room_type_ids'], $return_value['bookable_room_type_ids']);
             if (!empty($not_available_room_type_ids)) {
                 foreach ($not_available_room_type_ids as $room_type_id) {
                     trav_acc_get_room_detail_html($room_type_id, 'not_available');
                 }
             }
             $not_match_room_type_ids = array_diff($return_value['all_room_type_ids'], $return_value['matched_room_type_ids']);
             if (!empty($not_match_room_type_ids)) {
                 foreach ($not_match_room_type_ids as $room_type_id) {
                     trav_acc_get_room_detail_html($room_type_id, 'not_match');
                 }
             }
             $output = ob_get_contents();
             ob_end_clean();
             $result_json['success'] = 1;
             $result_json['result'] = $output;
         } else {
             $result_json['success'] = 1;
             $result_json['result'] = $return_value;
         }
     } else {
         $result_json['success'] = 0;
         $result_json['result'] = __('Invalid input data', 'trav');
     }
     wp_send_json($result_json);
 }
Exemplo n.º 2
0
                            trav_acc_get_room_detail_html($room_type_id, 'not_available');
                        }
                    }
                    $not_match_room_type_ids = array_diff($return_value['all_room_type_ids'], $return_value['matched_room_type_ids']);
                    if (!empty($not_match_room_type_ids)) {
                        foreach ($not_match_room_type_ids as $room_type_id) {
                            trav_acc_get_room_detail_html($room_type_id, 'not_match');
                        }
                    }
                } else {
                    echo wp_kses_post($return_value);
                }
            } else {
                echo '<input type="hidden" name="pre_searched" value="0">';
                foreach ($room_types as $room_type) {
                    trav_acc_get_room_detail_html($room_type->ID, 'all');
                }
            }
        } else {
            echo __('No Rooms Found', 'trav');
        }
        ?>

									</div>
								</div>
								<div class="tab-pane fade<?php 
        echo $def_tab == 'desc' ? ' in active' : '';
        ?>
" id="hotel-description">
									<div class="intro table-wrapper full-width hidden-table-sms">
										<div class="col-sm-4 features table-cell">