function trav_tour_get_search_result($search_data = array()) { //$search_data = array('s'=>$s, 'date_from'=>$date_from, 'date_to'=>$date_to, 'order_by'=>$order_by_array[$order_by], 'order'=>$order, 'last_no'=>( $page - 1 ) * $per_page, 'per_page'=>$per_page, 'min_price'=>$min_price, 'max_price'=>$max_price, 'tour_type'=>$tour_type ) // if wrong date return false if (!empty($search_data['date_from']) && !empty($search_data['date_to']) && trav_strtotime($search_data['date_from']) > trav_strtotime($search_data['date_to'])) { return false; } global $wpdb, $language_count; $tbl_posts = esc_sql($wpdb->posts); $tbl_postmeta = esc_sql($wpdb->postmeta); $tbl_terms = esc_sql($wpdb->prefix . 'terms'); $tbl_term_taxonomy = esc_sql($wpdb->prefix . 'term_taxonomy'); $tbl_term_relationships = esc_sql($wpdb->prefix . 'term_relationships'); $tbl_icl_translations = esc_sql($wpdb->prefix . 'icl_translations'); $temp_tbl_name = esc_sql('Search_' . session_id()); $order_by = esc_sql(empty($search_data['order_by']) ? 'tour_title' : $search_data['order_by']); $order = esc_sql(empty($search_data['order']) ? 'ASC' : $search_data['order']); $last_no = esc_sql(empty($search_data['last_no']) ? 0 : $search_data['last_no']); $per_page = esc_sql(empty($search_data['per_page']) ? 10 : $search_data['per_page']); $max_price = esc_sql(empty($search_data['max_price']) ? 'no_max' : $search_data['max_price']); $min_price = esc_sql(empty($search_data['min_price']) ? 0 : $search_data['min_price']); $tour_type = empty($search_data['tour_type']) || !is_array($search_data['tour_type']) ? array() : $search_data['tour_type']; foreach ($tour_type as $key => $value) { if (!is_numeric($value)) { unset($tour_type[$key]); } } $s = ''; if (floatval(get_bloginfo('version')) >= 4.0) { $s = esc_sql($wpdb->esc_like($search_data['s'])); } else { $s = esc_sql(like_escape($search_data['s'])); } $date_from = ''; $date_to = ''; if (!empty($search_data['date_from']) && trav_strtotime($search_data['date_from'])) { $date_from = trav_strtotime($search_data['date_from']); } else { $date_from = time(); } if (!empty($search_data['date_to']) && trav_strtotime($search_data['date_to'])) { $date_to = trav_strtotime($search_data['date_to']) + 86400; } else { $date_to = strtotime('+30 days'); } $from_date_obj = new DateTime(); $from_date_obj->setTimestamp($date_from); $to_date_obj = new DateTime(); $to_date_obj->setTimestamp($date_to); $sql = ''; $s_query = ''; // sql for search keyword if (!empty($s)) { $s_query = "SELECT DISTINCT post_s1.ID AS tour_id FROM {$tbl_posts} AS post_s1 \n\t\t\t\t\t\tLEFT JOIN {$tbl_postmeta} AS meta_s1 ON post_s1.ID = meta_s1.post_id\n\t\t\t\t\t\tLEFT JOIN {$tbl_terms} AS terms_s1 ON (meta_s1.meta_key IN('trav_tour_country','trav_tour_city')) AND (terms_s1.term_id = meta_s1.meta_value)\n\t\t\t\t\t\tWHERE (post_s1.post_status = 'publish') AND (post_s1.post_type = 'tour')\n\t\t\t\t\t\t AND ((post_s1.post_title LIKE '%{$s}%') \n\t\t\t\t\t\t\tOR (post_s1.post_content LIKE '%{$s}%')\n\t\t\t\t\t\t\tOR (meta_s1.meta_value LIKE '%{$s}%')\n\t\t\t\t\t\t\tOR (terms_s1.name LIKE '%{$s}%'))"; } else { $s_query = "SELECT post_s1.ID AS tour_id FROM {$tbl_posts} AS post_s1 \n\t\t\t\t\t\tWHERE (post_s1.post_status = 'publish') AND (post_s1.post_type = 'tour')"; } // if wpml is enabled do search by default language post if (defined('ICL_LANGUAGE_CODE') && $language_count > 1) { $s_query = "SELECT DISTINCT it2.element_id AS tour_id FROM ({$s_query}) AS t0\n\t\t\t\t\t\tINNER JOIN {$tbl_icl_translations} it1 ON (it1.element_type = 'post_tour') AND it1.element_id = t0.tour_id\n\t\t\t\t\t\tINNER JOIN {$tbl_icl_translations} it2 ON (it2.element_type = 'post_tour') AND it2.language_code='" . trav_get_default_language() . "' AND it2.trid = it1.trid "; } // if this searh has specified date then check schedule and booking data, but if it doesn't have specified date then only check other search factors if ($from_date_obj && $to_date_obj) { // has specified date $date_interval = DateInterval::createFromDateString('1 day'); $period = new DatePeriod($from_date_obj, $date_interval, $to_date_obj); $sql_check_date_parts = array(); $days = 0; foreach ($period as $dt) { $check_date = $dt->format("Y-m-d"); $sql_check_date_parts[] = "SELECT '{$check_date}' AS check_date"; $days++; } $sql_check_date = implode(' UNION ', $sql_check_date_parts); $sql = "SELECT available_schedules.tour_id, MIN(available_schedules.check_date) as min_date, MAX(available_schedules.check_date) as max_date\n\t\t\t\t\tFROM ( SELECT schedules.*, check_dates.check_date, schedules.max_people - SUM( IFNULL(bookings.adults,0) ) - SUM( IFNULL(bookings.kids,0) ) AS available_seat\n\t\t\t\t\t\tFROM ({$s_query}) AS tours\n\t\t\t\t\t\tINNER JOIN " . TRAV_TOUR_SCHEDULES_TABLE . " AS schedules\n\t\t\t\t\t\tON tours.tour_id = schedules.tour_id\n\t\t\t\t\t\tINNER JOIN ({$sql_check_date}) AS check_dates\n\t\t\t\t\t\tON ( schedules.is_daily = 0 AND check_dates.check_date = schedules.tour_date ) OR ( schedules.is_daily = 1 AND check_dates.check_date >= schedules.tour_date AND check_dates.check_date <= schedules.date_to )\n\t\t\t\t\t\tLEFT JOIN " . TRAV_TOUR_BOOKINGS_TABLE . " AS bookings\n\t\t\t\t\t\tON bookings.tour_id = schedules.tour_id AND bookings.st_id = schedules.st_id AND bookings.tour_date = check_dates.check_date AND bookings.status<>0\n\t\t\t\t\t\tGROUP BY schedules.tour_id, schedules.st_id, check_dates.check_date\n\t\t\t\t\t\tHAVING available_seat > 0\n\t\t\t\t\t\tORDER BY st_id ASC, tour_date ASC ) AS available_schedules\n\t\t\t\t\tGROUP BY available_schedules.tour_id"; } else { return false; } // if wpml is enabled return current language posts if (defined('ICL_LANGUAGE_CODE') && $language_count > 1 && trav_get_default_language() != ICL_LANGUAGE_CODE) { $sql = "SELECT it4.element_id AS tour_id, t5.min_date, t5.max_date FROM ({$sql}) AS t5\n\t\t\t\t\tINNER JOIN {$tbl_icl_translations} it3 ON (it3.element_type = 'post_tour') AND it3.element_id = t5.tour_id\n\t\t\t\t\tINNER JOIN {$tbl_icl_translations} it4 ON (it4.element_type = 'post_tour') AND it4.language_code='" . ICL_LANGUAGE_CODE . "' AND it4.trid = it3.trid"; } $sql = "CREATE TEMPORARY TABLE IF NOT EXISTS {$temp_tbl_name} AS " . $sql; $wpdb->query($sql); $sql = "SELECT DISTINCT t1.*, post_l1.post_title as tour_title, meta_price.meta_value as min_price FROM {$temp_tbl_name} as t1\n\t\t\t\tINNER JOIN {$tbl_posts} post_l1 ON (t1.tour_id = post_l1.ID) AND (post_l1.post_status = 'publish') AND (post_l1.post_type = 'tour')\n\t\t\t\tLEFT JOIN {$tbl_postmeta} AS meta_price ON (t1.tour_id = meta_price.post_id) AND (meta_price.meta_key = 'trav_tour_min_price')"; $where = ' 1=1'; if ($min_price != 0) { $where .= " AND cast(meta_price.meta_value as unsigned) >= {$min_price}"; } if ($max_price != 'no_max') { $where .= " AND cast(meta_price.meta_value as unsigned) <= {$max_price} "; } if (!empty($tour_type)) { $sql .= " INNER JOIN {$tbl_term_relationships} AS tr ON tr.object_id = t1.tour_id \n\t\t\t\t\tINNER JOIN {$tbl_term_taxonomy} AS tt ON tt.term_taxonomy_id = tr.term_taxonomy_id"; $where .= " AND tt.taxonomy = 'tour_type' AND tt.term_id IN (" . esc_sql(implode(',', $tour_type)) . ")"; } $sql .= " WHERE {$where} ORDER BY {$order_by} {$order} LIMIT {$last_no}, {$per_page};"; $results = $wpdb->get_results($sql); return $results; }
function trav_ajax_acc_update_booking_date() { if (!isset($_POST['_wpnonce']) || !isset($_POST['booking_no']) || !wp_verify_nonce($_POST['_wpnonce'], 'booking-' . $_POST['booking_no'])) { $result_json['success'] = 0; $result_json['result'] = __('Sorry, your nonce did not verify.', 'trav'); wp_send_json($result_json); } global $wpdb; $booking_no = sanitize_text_field($_POST['booking_no']); $pin_code = sanitize_text_field($_POST['pin_code']); if (!($booking_data = trav_acc_get_booking_data($booking_no, $pin_code))) { $result_json['success'] = 0; $result_json['result'] = __('Wrong booking number and pin code.', 'trav'); wp_send_json($result_json); } $booking_data['date_from'] = date('Y-m-d', trav_strtotime($_POST['date_from'])); $booking_data['date_to'] = date('Y-m-d', trav_strtotime($_POST['date_to'])); $booking_data['rooms'] = sanitize_text_field($_POST['rooms']); $booking_data['adults'] = sanitize_text_field($_POST['adults']); $booking_data['kids'] = sanitize_text_field($_POST['kids']); $booking_data['child_ages'] = serialize($_POST['child_ages']); $room_price_data = trav_acc_get_room_price_data($booking_data['accommodation_id'], $booking_data['room_type_id'], $booking_data['date_from'], $booking_data['date_to'], $booking_data['rooms'], $booking_data['adults'], $booking_data['kids'], $booking_data['child_ages'], $booking_no, $pin_code); if (!$room_price_data) { $result_json['success'] = 0; $result_json['result'] = __('The room is not available for the selected date, rooms and person. Please have another look at booking fields.', 'trav'); wp_send_json($result_json); } $tax_rate = get_post_meta($booking_data['accommodation_id'], 'trav_accommodation_tax_rate', true); $tax = 0; if (!empty($tax_rate)) { $tax = $tax_rate * $room_price_data['total_price'] / 100; } $total_price_incl_tax = $room_price_data['total_price'] + $tax; $booking_data['room_price'] = $room_price_data['total_price']; $booking_data['tax'] = $tax; $booking_data['total_price'] = $total_price_incl_tax; /*if ( ! isset( $_SESSION['exchange_rate'] ) ) trav_init_currency(); $booking_data['currency_code'] = trav_get_user_currency();*/ $booking_data['updated'] = date('Y-m-d H:i:s'); $result = trav_acc_update_booking($booking_no, $pin_code, $booking_data, 'update'); if (false === $result) { $result_json['success'] = 0; $result_json['result'] = __('Sorry, some error occurred on update.', 'trav'); } else { $result_json['success'] = 1; $result_json['result'] = __('Your booking is updated successfully.', 'trav'); } wp_send_json($result_json); }
function trav_tour_get_single_schedule_html($tour_id, $st_id, $schedule) { global $trav_options; // init variables $st_data = trav_tour_get_schedule_type_data($tour_id, $st_id); $st_title = !empty($st_data) && !empty($st_data['title']) ? $st_data['title'] : ''; $st_desc = !empty($st_data) && !empty($st_data['description']) ? $st_data['description'] : ''; $st_time = !empty($st_data) && !empty($st_data['time']) ? $st_data['time'] : ''; $repeated = get_post_meta($tour_id, 'trav_tour_repeated', true); $multi_book = get_post_meta($tour_id, 'trav_tour_multi_book', true); $tour_booking_page = ''; if (!empty($trav_options['tour_booking_page'])) { $tour_booking_page = trav_get_permalink_clang($trav_options['tour_booking_page']); } $location_arr = array(); $location_arr[] = trav_tour_get_city($tour_id); $location_arr[] = trav_tour_get_country($tour_id); $location = implode(', ', $location_arr); $discount = get_post_meta($tour_id, 'trav_tour_hot', true); $discount_rate = get_post_meta($tour_id, 'trav_tour_discount_rate', true); // init variables $def_date = key($schedule); $default_data = $schedule[$def_date]; foreach ($schedule as $key => $value) { if (!empty($value['available_seat'])) { $def_date = $key; $default_data = $value; break; } } $adults = 1; $kids = 0; ?> <div class="intro small-box table-wrapper full-width hidden-table-sms"> <div class="col-sm-4 table-cell features"> <table> <tr><td><label><?php _e('Location', 'trav'); ?> :</label></td><td><?php echo esc_html($location); ?> </td></tr> <?php if (empty($repeated)) { ?> <tr><td><label><?php _e('Tour Date', 'trav'); ?> :</label></td><td><?php echo date('l, F, j, Y', trav_strtotime($default_data['tour_date'])); ?> </td></tr> <?php } ?> <tr><td><label><?php _e('Duration', 'trav'); ?> :</label></td><td><?php echo esc_html($default_data['duration']); ?> </td></tr> <tr><td><label><?php _e('Available Seats', 'trav'); ?> :</label></td><td class="available-seats"><?php echo esc_html($default_data['available_seat']); ?> </td></tr> <?php if (!empty($multi_book)) { ?> <tr><td><label><?php _e('Price Per Adult', 'trav'); ?> :</label></td><td class="adult-price"><?php echo esc_html(trav_get_price_field($default_data['price'])); ?> </td></tr> <?php if (!empty($default_data['child_price']) && (double) $default_data['child_price'] != 0) { ?> <tr><td><label><?php _e('Price Per Child', 'trav'); ?> :</label></td><td class="child-price"><?php echo esc_html(trav_get_price_field($default_data['child_price'])); ?> </td></tr> <?php } ?> <?php } else { ?> <tr><td><label><?php _e('Price', 'trav'); ?> :</label></td><td class="adult-price"><?php echo esc_html(trav_get_price_field($default_data['price'])); ?> </td></tr> <?php } ?> <?php if (!empty($discount) && !empty($discount_rate)) { ?> <tr><td><label><?php _e('Discount', 'trav'); ?> :</label></td><td><?php echo sprintf(__('%d%% Off', 'trav'), $discount_rate); ?> </td></tr> <?php } ?> </table> </div> <div class="col-sm-8 table-cell"> <form method="get" action="<?php echo $tour_booking_page; ?> " class="tour-booking-form"> <input type="hidden" name="tour_id" value="<?php echo esc_attr($tour_id); ?> "> <input type="hidden" name="st_id" value="<?php echo esc_attr($st_id); ?> "> <?php wp_nonce_field('post-' . $tour_id, '_wpnonce', false); ?> <?php if (defined('ICL_LANGUAGE_CODE')) { ?> <input type="hidden" name="lang" value="<?php echo ICL_LANGUAGE_CODE; ?> "> <?php } ?> <?php if (empty($multi_book)) { ?> <input type="hidden" name="adults" value="1"> <?php } ?> <?php if (empty($repeated)) { ?> <input type="hidden" name="tour_date" value="<?php echo $default_data['tour_date']; ?> "> <?php } ?> <div class="detail-section-top row"> <div class="st-details col-md-9 col-sm-8"> <?php if (!empty($st_title)) { ?> <h4 class="box-title"><?php echo wp_kses_post($st_title); ?> </h4> <?php } ?> <?php if (!empty($st_desc)) { ?> <div class="st-description"><?php echo wp_kses_post($st_desc); ?> </div> <?php } ?> <?php if (!empty($st_time)) { ?> <div class="time"><i class="soap-icon-clock yellow-color"></i><span><?php echo wp_kses_post($st_time); ?> </span></div> <?php } ?> </div> <div class="price-details col-md-3 col-sm-4"> <h3 class="price"> <div class="adult-price"><?php echo trav_get_price_field($default_data['price']); ?> </div> <?php if (!empty($multi_book)) { ?> <small><?php _e('per adult', 'trav'); ?> </small> <?php } ?> </h3> <?php if (empty($multi_book) && empty($repeated)) { ?> <button title="book now" class="button btn-small full-width text-center btn-book-now <?php echo empty($default_data['available_seat']) ? 'no-display' : ''; ?> "><?php _e("BOOK NOW", "trav"); ?> </button> <h4 class="sold-out <?php echo empty($default_data['available_seat']) ? '' : 'no-display'; ?> "><?php echo __('Sold Out', 'trav'); ?> </h4> <h4 class="exceed-persons no-display"><?php echo __('Exceed Persons', 'trav'); ?> </h4> <?php } ?> </div> </div> <?php if (!empty($multi_book) || !empty($repeated)) { ?> <div class="detail-section-bottom"> <div class="row"> <?php if (!empty($repeated)) { ?> <div class="col-md-4 col-sm-6"> <label><?php _e('AVAILABLE ON', 'trav'); ?> </label> <div class="selector validation-field"> <select name="tour_date" class="full-width tour-date-select"> <?php foreach ($schedule as $key => $value) { $selected = $key == $def_date ? 'selected' : ''; echo '<option value="' . esc_attr($key) . '" ' . $selected . ' data-max-seat="' . esc_attr($value['available_seat']) . '" data-price="' . esc_attr($value['price']) . '" data-child-price="' . esc_attr($value['child_price']) . '" >' . esc_html(trav_tophptime($key)) . '</option>'; } ?> </select> </div> </div> <?php } else { ?> <div class="price-data no-display" data-max-seat="<?php echo esc_attr($default_data['available_seat']); ?> " data-price="<?php echo esc_attr($default_data['price']); ?> " data-child-price="<?php echo esc_attr($default_data['child_price']); ?> "></div> <?php } ?> <?php if (!empty($multi_book)) { ?> <div class="col-md-2 col-sm-3 col-xs-6"> <label><?php _e('ADULTS', 'trav'); ?> </label> <div class="selector validation-field"> <select name="adults" class="full-width"> <?php for ($i = 1; $i <= 10; $i++) { $selected = $i == $adults ? 'selected' : ''; echo '<option value="' . esc_attr($i) . '" ' . $selected . '>' . esc_html($i) . '</option>'; } ?> </select> </div> </div> <div class="col-md-2 col-sm-3 col-xs-6"> <label><?php _e('KIDS', 'trav'); ?> </label> <div class="selector validation-field"> <select name="kids" class="full-width"> <?php for ($i = 0; $i <= 10; $i++) { $selected = $i == $kids ? 'selected' : ''; echo '<option value="' . esc_attr($i) . '" ' . $selected . '>' . esc_html($i) . '</option>'; } ?> </select> </div> </div> <?php } ?> <div class="col-md-4 pull-right"> <label> <?php _e('Total', 'trav'); ?> : <span class="total-price"> <?php echo trav_get_price_field($default_data['price']); ?> </span> </label> <div class="row"> <div class="col-sm-12"> <button data-animation-duration="1" data-animation-type="bounce" class="btn-book-now full-width icon-check animated bounce <?php echo empty($default_data['available_seat']) ? 'no-display' : ''; ?> " type="submit"><?php _e("BOOK NOW", "trav"); ?> </button> <h4 class="sold-out <?php echo empty($default_data['available_seat']) ? '' : 'no-display'; ?> "><?php echo __('Sold Out', 'trav'); ?> </h4> <h4 class="exceed-persons no-display"><?php echo __('Exceed Persons', 'trav'); ?> </h4> </div> </div> </div> </div> </div> <?php } ?> </form> </div> </div> <?php }
get_header(); global $trav_options, $before_article, $after_article, $tour_list, $current_view, $date_from, $date_to, $language_count; $order_array = array('ASC', 'DESC'); $order_by_array = array('name' => 'tour_title', 'price' => 'cast(min_price as unsigned)'); $order_defaults = array('name' => 'ASC', 'price' => 'ASC'); $s = isset($_REQUEST['s']) ? sanitize_text_field($_REQUEST['s']) : ''; $min_price = isset($_REQUEST['min_price']) && is_numeric($_REQUEST['min_price']) ? sanitize_text_field($_REQUEST['min_price']) : 0; $max_price = isset($_REQUEST['max_price']) && (is_numeric($_REQUEST['max_price']) || $_REQUEST['max_price'] == 'no_max') ? sanitize_text_field($_REQUEST['max_price']) : 'no_max'; $order_by = isset($_REQUEST['order_by']) && array_key_exists($_REQUEST['order_by'], $order_by_array) ? sanitize_text_field($_REQUEST['order_by']) : 'name'; $order = isset($_REQUEST['order']) && in_array($_REQUEST['order'], $order_array) ? sanitize_text_field($_REQUEST['order']) : 'ASC'; $tour_type = isset($_REQUEST['tour_types']) ? is_array($_REQUEST['tour_types']) ? $_REQUEST['tour_types'] : array($_REQUEST['tour_types']) : array(); $current_view = isset($_REQUEST['view']) ? sanitize_text_field($_REQUEST['view']) : 'list'; $page = isset($_REQUEST['page']) && is_numeric($_REQUEST['page']) && $_REQUEST['page'] >= 1 ? sanitize_text_field($_REQUEST['page']) : 1; $per_page = isset($trav_options['tour_posts']) && is_numeric($trav_options['tour_posts']) ? $trav_options['tour_posts'] : 12; $date_from = empty($_REQUEST['date_from']) || trav_sanitize_date($_REQUEST['date_from']) == '' ? date(trav_get_date_format('php')) : $_REQUEST['date_from']; $date_to = empty($_REQUEST['date_to']) || trav_sanitize_date($_REQUEST['date_to']) == '' || trav_strtotime($date_from) > trav_strtotime($_REQUEST['date_to']) ? date(trav_get_date_format('php'), trav_strtotime($date_from) + 86400 * 30) : $_REQUEST['date_to']; if (is_tax()) { $queried_taxonomy = get_query_var('taxonomy'); $queried_term = get_query_var('term'); $queried_term_obj = get_term_by('slug', $queried_term, $queried_taxonomy); if ($queried_term_obj) { if ($queried_taxonomy == 'tour_type' && !in_array($queried_term_obj->term_id, $tour_type)) { $tour_type[] = $queried_term_obj->term_id; } } } $tour_list = trav_tour_get_search_result(array('s' => $s, 'date_from' => $date_from, 'date_to' => $date_to, 'order_by' => $order_by_array[$order_by], 'order' => $order, 'last_no' => ($page - 1) * $per_page, 'per_page' => $per_page, 'min_price' => $min_price, 'max_price' => $max_price, 'tour_type' => $tour_type)); $count = trav_tour_get_search_result_count(array('min_price' => $min_price, 'max_price' => $max_price, 'tour_type' => $tour_type)); $before_article = ''; $after_article = ''; ?>
?> </a> </div> </figure> <div class="details"> <div class="icon-box style12 style13 full-width"> <div class="icon-wrapper"> <i class="soap-icon-calendar"></i> </div> <dl class="details"> <dt class="skin-color"><?php _e('Date', 'trav'); ?> </dt> <dd><?php echo date("M j, Y", trav_strtotime($booking_data['tour_date'])); ?> </dd> </dl> </div> <div class="icon-box style12 style13 full-width"> <div class="icon-wrapper"> <i class="soap-icon-clock"></i> </div> <dl class="details"> <dt class="skin-color"><?php _e('Duration', 'trav'); ?> </dt> <dd><?php echo $price_data['duration'];
function trav_acc_booking_before() { global $trav_options, $def_currency; // prevent direct access if (!isset($_REQUEST['booking_data'])) { do_action('trav_acc_booking_wrong_data'); exit; } // init booking data : array( 'accommodation_id', 'room_type_id', 'date_from', 'date_to', 'rooms', 'adults', 'kids', 'child_ages' ); $raw_booking_data = ''; parse_str($_REQUEST['booking_data'], $raw_booking_data); //verify nonce if (!isset($raw_booking_data['_wpnonce']) || !wp_verify_nonce($raw_booking_data['_wpnonce'], 'post-' . $raw_booking_data['accommodation_id'])) { do_action('trav_acc_booking_wrong_data'); exit; } // init booking_data fields $booking_fields = array('accommodation_id', 'room_type_id', 'date_from', 'date_to', 'rooms', 'adults', 'kids', 'child_ages'); $booking_data = array(); foreach ($booking_fields as $field) { if (!isset($raw_booking_data[$field])) { do_action('trav_acc_booking_wrong_data'); exit; } else { $booking_data[$field] = $raw_booking_data[$field]; } } // date validation if (trav_strtotime($booking_data['date_from']) >= trav_strtotime($booking_data['date_to'])) { do_action('trav_acc_booking_wrong_data'); exit; } // make an array for redirect url generation $query_args = array('date_from' => $booking_data['date_from'], 'date_to' => $booking_data['date_to'], 'rooms' => $booking_data['rooms'], 'adults' => $booking_data['adults'], 'kids' => $booking_data['kids'], 'child_ages' => $booking_data['child_ages']); // get price data $room_price_data = trav_acc_get_room_price_data($booking_data['accommodation_id'], $booking_data['room_type_id'], $booking_data['date_from'], $booking_data['date_to'], $booking_data['rooms'], $booking_data['adults'], $booking_data['kids'], $booking_data['child_ages']); $acc_url = get_permalink($booking_data['accommodation_id']); $edit_url = add_query_arg($query_args, $acc_url); // redirect if $room_price_data is not valid if (!$room_price_data || !is_array($room_price_data)) { $query_args['error'] = 1; wp_redirect($edit_url); } // calculate tax and total price $tax_rate = get_post_meta($booking_data['accommodation_id'], 'trav_accommodation_tax_rate', true); $tax = 0; if (!empty($tax_rate)) { $tax = $tax_rate * $room_price_data['total_price'] / 100; } $total_price_incl_tax = $room_price_data['total_price'] + $tax; $booking_data['room_price'] = $room_price_data['total_price']; $booking_data['tax'] = $tax; $booking_data['total_price'] = $booking_data['room_price'] + $booking_data['tax']; // calculate deposit payment $deposit_rate = get_post_meta($booking_data['accommodation_id'], 'trav_accommodation_security_deposit', true); // if woocommerce enabled change currency_code and exchange rate as default if (!empty($deposit_rate) && trav_is_woo_enabled()) { $booking_data['currency_code'] = $def_currency; $booking_data['exchange_rate'] = 1; } else { if (!isset($_SESSION['exchange_rate'])) { trav_init_currency(); } $booking_data['currency_code'] = trav_get_user_currency(); $booking_data['exchange_rate'] = $_SESSION['exchange_rate']; } // if payment enabled set deposit price field $is_payment_enabled = !empty($deposit_rate) && trav_is_payment_enabled(); if ($is_payment_enabled) { $booking_data['deposit_price'] = $deposit_rate / 100 * $booking_data['total_price'] * $booking_data['exchange_rate']; } // initialize session values $transaction_id = mt_rand(100000, 999999); $_SESSION['booking_data'][$transaction_id] = $booking_data; //'accommodation_id', 'room_type_id', 'date_from', 'date_to', 'rooms', 'adults', 'kids', 'child_ages', room_price, tax, total_price, currency_code, exchange_rate, deposit_price $review = get_post_meta(trav_acc_org_id($booking_data['accommodation_id']), 'review', true); $review = !empty($review) ? round($review, 1) : 0; // thank you page url $acc_book_conf_url = ''; if (!empty($trav_options['acc_booking_confirmation_page'])) { $acc_book_conf_url = trav_get_permalink_clang($trav_options['acc_booking_confirmation_page']); } else { // thank you page is not set } global $trav_booking_page_data; $trav_booking_page_data['transaction_id'] = $transaction_id; $trav_booking_page_data['review'] = $review; $trav_booking_page_data['acc_url'] = $acc_url; $trav_booking_page_data['edit_url'] = $edit_url; $trav_booking_page_data['booking_data'] = $booking_data; $trav_booking_page_data['room_price_data'] = $room_price_data; $trav_booking_page_data['is_payment_enabled'] = $is_payment_enabled; $trav_booking_page_data['acc_book_conf_url'] = $acc_book_conf_url; $trav_booking_page_data['tax'] = $tax; $trav_booking_page_data['tax_rate'] = $tax_rate; }
<?php get_header(); if (have_posts()) { while (have_posts()) { the_post(); //init variables $tour_id = get_the_ID(); $city = trav_tour_get_city($tour_id); $country = trav_tour_get_country($tour_id); $date_from = isset($_GET['date_from']) ? trav_tophptime($_GET['date_from']) : date(trav_get_date_format('php')); $date_to = isset($_GET['date_to']) ? trav_tophptime($_GET['date_to']) : date(trav_get_date_format('php'), trav_strtotime($date_from) + 86400 * 30); $repeated = get_post_meta($tour_id, 'trav_tour_repeated', true); $multi_book = get_post_meta($tour_id, 'trav_tour_multi_book', true); $isv_setting = get_post_meta($tour_id, 'trav_post_media_type', true); $discount = get_post_meta($tour_id, 'trav_tour_hot', true); $discount_rate = get_post_meta($tour_id, 'trav_tour_discount_rate', true); $sc_list_pos = get_post_meta($tour_id, 'trav_tour_sl_first', true); $schedule_types = trav_tour_get_schedule_types($tour_id); // add to user recent activity trav_update_user_recent_activity($tour_id); ?> <section id="content"> <div class="container tour-detail-page"> <div class="row"> <div id="main" class="col-sm-8 col-md-9"> <div <?php post_class(); ?> >
function trav_get_user_booking_list($user_id, $status = 1, $sortby = 'created', $order = 'desc') { global $wpdb, $trav_options; $sql = ''; $order = $order == 'desc' ? 'desc' : 'asc'; $order_by = ' ORDER BY ' . esc_sql($sortby) . ' ' . $order; $where = ' WHERE 1=1'; $where .= ' AND user_id=' . esc_sql($user_id); if ($status != -1) { $where .= ' AND status=' . esc_sql($status); } // $sql = $wpdb->prepare( 'SELECT * FROM ' . TRAV_ACCOMMODATION_BOOKINGS_TABLE . $where . $order_by, $user_id ); $available_modules = trav_get_available_modules(); $sqls = array(); if (in_array('accommodation', $available_modules)) { $sqls[] = "SELECT 'accommodation' AS post_type, booking_no, pin_code, total_price, created, status, accommodation_id AS post_id, date_from AS event_date, adults, rooms AS tickets FROM " . TRAV_ACCOMMODATION_BOOKINGS_TABLE . $where; } if (in_array('tour', $available_modules)) { $sqls[] = "SELECT 'tour' AS post_type, booking_no, pin_code, total_price, created, status, tour_id AS post_id, tour_date AS event_date, adults, NULL AS tickets FROM " . TRAV_TOUR_BOOKINGS_TABLE . $where; } $sql = implode(' UNION ALL ', $sqls); $sql .= $order_by; //return $sql; $booking_list = $wpdb->get_results($sql); if (empty($booking_list)) { return __('You don\'t have any booked trips yet.', 'trav'); } // if empty return false $acc_book_conf_url = trav_acc_get_book_conf_url(); $tour_book_conf_url = trav_tour_get_book_conf_url(); $html = ''; foreach ($booking_list as $booking_data) { $class = ''; $label = 'UPCOMMING'; if ($booking_data->status == 0) { $class = ' cancelled'; $label = 'CANCELLED'; } if ($booking_data->status == 2) { $class = ' completed'; $label = 'COMPLETED'; } // if ( ( $booking_data->status == 1 ) && ( trav_strtotime( $booking_data->event_date ) < trav_strtotime(date('Y-m-d')) ) ) { $class = ' completed'; $label = 'COMPLETED'; } $html .= '<div class="booking-info clearfix' . $class . '">'; $html .= '<div class="date"> <label class="month">' . date('M', trav_strtotime($booking_data->event_date)) . '</label> <label class="date">' . date('d', trav_strtotime($booking_data->event_date)) . '</label> <label class="day">' . date('D', trav_strtotime($booking_data->event_date)) . '</label> </div>'; $conf_url = ''; $icon_class = ''; if ('accommodation' == $booking_data->post_type) { $conf_url = $acc_book_conf_url; $icon_class = 'soap-icon-hotel blue-color'; } elseif ('tour' == $booking_data->post_type) { $conf_url = $tour_book_conf_url; $icon_class = 'soap-icon-beach yellow-color'; } $url = empty($conf_url) ? '' : add_query_arg(array('booking_no' => $booking_data->booking_no, 'pin_code' => $booking_data->pin_code), $conf_url); $html .= '<h4 class="box-title">'; $html .= '<i class="icon circle ' . $icon_class . '"></i>'; $html .= '<a href="' . esc_url($url) . '">' . get_the_title(trav_acc_clang_id($booking_data->post_id)) . '</a>'; $html .= '<small>'; if ('accommodation' == $booking_data->post_type) { $html .= $booking_data->tickets . __('rooms', 'trav') . ' '; } $html .= $booking_data->adults . __('adults', 'trav') . '</small></h4>'; $html .= '<button class="btn-mini status">' . __($label, 'trav') . '</button>'; $html .= '<dl class="info">'; $html .= '<dt>' . __('booked on', 'trav') . '</dt>'; $html .= '<dd>' . date('l, M, j, Y', trav_strtotime($booking_data->created)) . '</dd>'; $html .= '</dl>'; $html .= '<dl class="info">'; $html .= '<dt>' . __('BOOKING NO', 'trav') . '</dt><dd>' . $booking_data->booking_no . '</dd>'; $html .= '<dt>' . __('PIN CODE', 'trav') . '</dt><dd>' . $booking_data->pin_code . '</dd>'; $html .= '</dl>'; $html .= '</div>'; } return $html; }
</div> <div class="duration text-center"> <i class="soap-icon-clock"></i> <span> <?php echo esc_html(trav_get_day_interval($booking_data['date_from'], $booking_data['date_to']) . ' ' . __('Nights', 'trav')); ?> </span> </div> <div class="check-out"> <label><?php _e('Check out', 'trav'); ?> </label> <span><?php echo date("M j, Y", trav_strtotime($booking_data['date_to'])); ?> <br /><?php $date_to_time = get_post_meta($booking_data['accommodation_id'], 'trav_accommodation_check_out', true); if (isset($date_to_time)) { echo esc_html($date_to_time); } ?> </span> </div> </div> <div class="guest"> <small class="uppercase"><?php echo esc_html($booking_data['rooms'] . ' ' . get_the_title($booking_data['room_type_id'])); ?> for <span class="skin-color"><?php
function trav_ajax_tour_submit_booking() { global $wpdb, $trav_options; // validation $result_json = array('success' => 0, 'result' => ''); if (!isset($_POST['transaction_id']) || !isset($_SESSION['booking_data'][$_POST['transaction_id']])) { $result_json['success'] = 0; $result_json['result'] = __('Sorry, some error occurred on input data validation.', 'trav'); wp_send_json($result_json); } $raw_booking_data = $_SESSION['booking_data'][$_POST['transaction_id']]; $booking_fields = array('tour_id', 'st_id', 'tour_date', 'adults', 'kids', 'total_price', 'currency_code', 'exchange_rate', 'deposit_price'); $booking_data = array(); foreach ($booking_fields as $booking_field) { if (!empty($raw_booking_data[$booking_field])) { $booking_data[$booking_field] = $raw_booking_data[$booking_field]; } } $is_payment_enabled = trav_is_payment_enabled() && !empty($booking_data['deposit_price']); if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'post-' . $booking_data['tour_id'])) { $result_json['success'] = 0; $result_json['result'] = __('Sorry, your nonce did not verify.', 'trav'); wp_send_json($result_json); } if (isset($trav_options['vld_captcha']) && !empty($trav_options['vld_captcha'])) { if (!isset($_POST['security_code']) || $_POST['security_code'] != $_SESSION['security_code']) { $result_json['success'] = 0; $result_json['result'] = __('Captcha error. Please check your security code again.', 'trav'); wp_send_json($result_json); } } if (isset($trav_options['vld_credit_card']) && !empty($trav_options['vld_credit_card'])) { if (!isset($_POST['cc_type']) || !isset($_POST['cc_holder_name']) || !isset($_POST['cc_number']) || !isset($_POST['cc_exp_month']) || !isset($_POST['cc_exp_year']) || !trav_cc_validation($_POST['cc_type'], $_POST['cc_holder_name'], $_POST['cc_number'], $_POST['cc_exp_month'], $_POST['cc_exp_year'])) { $result_json['success'] = 0; $result_json['result'] = __('Vcc validation An error.', 'trav'); wp_send_json($result_json); } } // init variables $post_fields = array('first_name', 'last_name', 'email', 'country_code', 'phone', 'address', 'city', 'zip', 'country', 'special_requirements'); $customer_info = array(); foreach ($post_fields as $post_field) { if (!empty($_POST[$post_field])) { $customer_info[$post_field] = sanitize_text_field($_POST[$post_field]); } } $data = array_merge($customer_info, $booking_data); $data['tour_date'] = date('Y-m-d', trav_strtotime($data['tour_date'])); if (is_user_logged_in()) { $data['user_id'] = get_current_user_id(); } $latest_booking_id = $wpdb->get_var('SELECT id FROM ' . TRAV_TOUR_BOOKINGS_TABLE . ' ORDER BY id DESC LIMIT 1'); $booking_no = mt_rand(1000, 9999); $booking_no .= $latest_booking_id; $pin_code = mt_rand(1000, 9999); if (!isset($_SESSION['exchange_rate'])) { trav_init_currency(); } $default_booking_data = array('first_name' => '', 'last_name' => '', 'email' => '', 'country_code' => '', 'phone' => '', 'address' => '', 'city' => '', 'zip' => '', 'country' => '', 'special_requirements' => '', 'tour_id' => '', 'st_id' => 0, 'tour_date' => '', 'adults' => '', 'kids' => '', 'total_price' => '', 'currency_code' => 'usd', 'exchange_rate' => 1, 'deposit_price' => 0, 'deposit_paid' => $is_payment_enabled ? 0 : 1, 'created' => date('Y-m-d H:i:s'), 'booking_no' => $booking_no, 'pin_code' => $pin_code, 'status' => 1); $data = array_replace($default_booking_data, $data); // credit card offline charge if (!empty($trav_options['vld_credit_card']) && !empty($trav_options['cc_off_charge'])) { $cc_fields = array('cc_type', 'cc_holder_name', 'cc_number', 'cc_cid', 'cc_exp_year', 'cc_exp_month'); $cc_infos = array(); foreach ($cc_fields as $cc_field) { $cc_infos[$cc_field] = empty($_POST[$cc_field]) ? '' : $_POST[$cc_field]; } $data['other'] = serialize($cc_infos); } // recheck availability $room_price_data = trav_tour_get_price_data(array('tour_id' => $data['tour_id'], 'st_id' => $data['st_id'], 'tour_date' => $booking_data['tour_date'], 'adults' => $data['adults'], 'kids' => $data['kids'])); if (empty($room_price_data) || !is_array($room_price_data)) { $result_json['success'] = -1; $result_json['result'] = __('Sorry, The tour you are booking now is just taken by another customer. Please have another look.', 'trav'); wp_send_json($result_json); } do_action('trav_tour_add_booking_before', $data); // save default language tour and room type $data['tour_id'] = trav_tour_org_id($data['tour_id']); // add to db if ($wpdb->insert(TRAV_TOUR_BOOKINGS_TABLE, $data)) { $booking_id = $wpdb->insert_id; $data['booking_id'] = $booking_id; $_SESSION['booking_data'][$_POST['transaction_id']] = $data; $result_json['success'] = 1; $result_json['result']['booking_no'] = $booking_no; $result_json['result']['pin_code'] = $pin_code; $result_json['result']['transaction_id'] = $_POST['transaction_id']; if ($is_payment_enabled) { if (trav_is_woo_enabled()) { // woocommerce do_action('trav_woo_add_tour_booking', $data); $result_json['result']['payment'] = 'woocommerce'; } elseif (trav_is_paypal_enabled()) { // paypal direct $result_json['result']['payment'] = 'paypal'; } } else { $result_json['result']['payment'] = 'no'; } do_action('trav_tour_add_booking_after', $data); } else { $result_json['success'] = 0; $result_json['result'] = __('Sorry, An error occurred while add booking.', 'trav'); } wp_send_json($result_json); }
if (is_tax()) { $queried_taxonomy = get_query_var('taxonomy'); $queried_term = get_query_var('term'); $queried_term_obj = get_term_by('slug', $queried_term, $queried_taxonomy); if ($queried_term_obj) { if ($queried_taxonomy == 'accommodation_type' && !in_array($queried_term_obj->term_id, $acc_type)) { $acc_type[] = $queried_term_obj->term_id; } if ($queried_taxonomy == 'amenity' && !in_array($queried_term_obj->term_id, $amenities)) { $amenities[] = $queried_term_obj->term_id; } } } $date_from = isset($_REQUEST['date_from']) ? trav_sanitize_date($_REQUEST['date_from']) : ''; $date_to = isset($_REQUEST['date_to']) ? trav_sanitize_date($_REQUEST['date_to']) : ''; if (trav_strtotime($date_from) >= trav_strtotime($date_to)) { $date_from = ''; $date_to = ''; } $results = trav_acc_get_search_result($s, $date_from, $date_to, $rooms, $adults, $kids, $order_by_array[$order_by], $order, ($page - 1) * $per_page, $per_page, $min_price, $max_price, $rating, $acc_type, $amenities); $count = trav_acc_get_search_result_count($min_price, $max_price, $rating, $acc_type, $amenities); global $before_article, $after_article, $acc_list; $before_article = ''; $after_article = ''; $acc_list = array(); foreach ($results as $result) { $acc_list[] = $result->acc_id; } ?> <section id="content">