static function _handle_form_submit() { if (!st_is_ajax()) { $result = self::booking_form_submit(); if (isset($result['status']) and !$result['status']) { STTemplate::set_message($result['message'], 'danger'); } if (isset($result['redirect']) and $result['redirect']) { wp_redirect($result['redirect']); die; } } }
function search_room($param = array()) { $default = array('room_parent' => FALSE, 'adult_number' => FALSE, 'child_number' => FALSE, 'room_type' => 0, 'room_num_search' => 1, 'room_num_config' => array()); $page = STInput::request('paged'); if (!$page) { $page = get_query_var('paged'); } extract(wp_parse_args($param, $default)); $arg = array('post_type' => 'hotel_room', 'posts_per_page' => '10', 'paged' => $page); $max_adult = 1; $max_child = 0; if ($room_num_search == 1) { $max_adult = $adult_number; $max_child = $child_number; } if ($room_num_search) { $arg['meta_query'][] = array('key' => 'number_room', 'compare' => '>=', 'value' => $room_num_search, 'type' => 'DECIMAL'); } if ($room_num_search > 1) { if (!empty($room_num_config) and is_array($room_num_config)) { foreach ($room_num_config as $key => $value) { if ($value['adults'] > $max_adult) { $max_adult = $value['adults']; } if ($value['children'] > $max_child) { $max_child = $value['children']; } } } } if (st_is_ajax()) { // for ajax $arg['meta_query'][] = array('key' => 'children_number', 'compare' => '>=', 'value' => $child_number, 'type' => 'NUMERIC'); $arg['meta_query'][] = array('key' => 'adult_number', 'compare' => '>=', 'value' => $adult_number, 'type' => 'NUMERIC'); } else { $arg['meta_query'][] = array('key' => 'children_number', 'compare' => '>=', 'value' => $max_child, 'type' => 'NUMERIC'); $arg['meta_query'][] = array('key' => 'adult_number', 'compare' => '>=', 'value' => $max_adult, 'type' => 'NUMERIC'); } if ($room_parent) { $arg['meta_key'] = 'room_parent'; $arg['meta_value'] = $room_parent; } if ($room_type) { $arg['tax_query'][] = array('taxonomy' => 'room_type', 'terms' => $room_type); } return $arg; }
function ajax_search_room() { if (st_is_ajax() and STInput::post('room_search')) { if (!wp_verify_nonce(STInput::post('room_search'), 'room_search')) { $result = array('status' => 0, 'data' => ""); echo json_encode($result); die; } $result = array('status' => 1, 'data' => ""); $hotel_id = get_the_ID(); $post = STInput::request(); $post['room_parent'] = $hotel_id; //Check Date $today = date('m/d/Y'); $check_in = strtotime(TravelHelper::convertDateFormat($post['start'])); $check_out = strtotime(TravelHelper::convertDateFormat($post['end'])); $date_diff = STDate::date_diff($check_in, $check_out); $booking_period = $this->is_booking_period($hotel_id, $today, $post['start']); if ($booking_period) { $result = array('status' => 0, 'data' => st()->load_template('hotel/elements/loop-room-none'), 'message' => sprintf(__('Booking is only accepted %d day(s) before today.', ST_TEXTDOMAIN), $booking_period)); echo json_encode($result); die; } if ($date_diff < 1) { $result = array('status' => 0, 'data' => "", 'message' => __('Make sure your check-out date is at least 1 day after check-in.', ST_TEXTDOMAIN), 'more-data' => $date_diff); echo json_encode($result); die; } query_posts($this->search_room($post)); $post['check_in'] = date('d-m-Y', strtotime($post['start'])); $post['check_out'] = date('d-m-Y', strtotime($post['end'])); global $wp_query; if (have_posts()) { while (have_posts()) { the_post(); $result['data'] .= st()->load_template('hotel/elements/loop-room-item'); } } else { $result['data'] .= st()->load_template('hotel/elements/loop-room-none'); } wp_reset_query(); echo json_encode($result); die; } }