Exemple #1
0
 function trav_ajax_acc_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('accommodation_id', 'room_type_id', 'rooms', 'adults', 'kids', 'child_ages', 'total_price', 'room_price', 'tax', 'currency_code', 'exchange_rate', 'deposit_price', 'date_from', 'date_to', 'created', 'booking_no', 'pin_code', 'status');
     $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['room_type_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['child_ages'] = serialize($data['child_ages']);
     $data['date_from'] = date('Y-m-d', trav_strtotime($data['date_from']));
     $data['date_to'] = date('Y-m-d', trav_strtotime($data['date_to']));
     if (is_user_logged_in()) {
         $data['user_id'] = get_current_user_id();
     }
     $latest_booking_id = $wpdb->get_var('SELECT id FROM ' . TRAV_ACCOMMODATION_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' => '', 'accommodation_id' => '', 'room_type_id' => '', 'rooms' => '', 'adults' => '', 'kids' => '', 'child_ages' => '', 'total_price' => '', 'room_price' => '', 'tax' => '', 'currency_code' => 'usd', 'exchange_rate' => 1, 'deposit_price' => 0, 'deposit_paid' => $is_payment_enabled ? 0 : 1, 'date_from' => '', 'date_to' => '', '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_acc_get_room_price_data($data['accommodation_id'], $data['room_type_id'], $booking_data['date_from'], $booking_data['date_to'], $data['rooms'], $data['adults'], $data['kids'], $data['child_ages']);
     if (!$room_price_data || !is_array($room_price_data)) {
         $result_json['success'] = -1;
         $result_json['result'] = __('Sorry, The room you are booking now is just taken by another customer. Please have another look.', 'trav');
         wp_send_json($result_json);
     }
     do_action('trav_acc_add_booking_before', $data);
     // save default language accommodation and room type
     $data['accommodation_id'] = trav_acc_org_id($data['accommodation_id']);
     $data['room_type_id'] = trav_room_org_id($data['room_type_id']);
     // add to db
     if ($wpdb->insert(TRAV_ACCOMMODATION_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_acc_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_acc_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 (isset($acc_meta['trav_accommodation_brief'])) {
            echo esc_html($acc_meta['trav_accommodation_brief'][0]);
        } else {
            $brief_content = apply_filters('the_content', get_post_field('post_content', $acc_id));
            echo wp_kses_post(wp_trim_words($brief_content, 20, ''));
        }
        ?>
								</p>
								<?php 
        if (is_user_logged_in()) {
            $user_id = get_current_user_id();
            $wishlist = get_user_meta($user_id, 'wishlist', true);
            if (empty($wishlist)) {
                $wishlist = array();
            }
            if (!in_array(trav_acc_org_id($acc_id), $wishlist)) {
                ?>
										<a class="button yellow-bg full-width uppercase btn-small btn-add-wishlist" data-label-add="<?php 
                _e('add to wishlist', 'trav');
                ?>
" data-label-remove="<?php 
                _e('remove from wishlist', 'trav');
                ?>
"><?php 
                _e('add to wishlist', 'trav');
                ?>
</a>
									<?php 
            } else {
                ?>
										<a class="button yellow-bg full-width uppercase btn-small btn-remove-wishlist" data-label-add="<?php 
Exemple #3
0
 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;
 }
        function prepare_items()
        {
            global $wpdb;
            $per_page = 10;
            $columns = $this->get_columns();
            $hidden = array();
            $sortable = $this->get_sortable_columns();
            $this->_column_headers = array($columns, $hidden, $sortable);
            $this->process_bulk_action();
            $orderby = !empty($_REQUEST['orderby']) ? sanitize_sql_orderby($_REQUEST['orderby']) : 'id';
            //If no sort, default to title
            $order = !empty($_REQUEST['order']) ? sanitize_text_field($_REQUEST['order']) : 'desc';
            //If no order, default to desc
            $current_page = $this->get_pagenum();
            $post_table_name = $wpdb->prefix . 'posts';
            $where = "1=1";
            if (!empty($_REQUEST['accommodation_id'])) {
                $where .= " AND Trav_Reviews.post_id = '" . esc_sql(trav_acc_org_id($_REQUEST['accommodation_id'])) . "'";
            }
            if (!empty($_REQUEST['reviewer_ip'])) {
                $where .= " AND Trav_Reviews.reviewer_ip = '" . esc_sql($_REQUEST['reviewer_ip']) . "'";
            }
            $status = isset($_REQUEST['status']) ? esc_sql($_REQUEST['status']) : 0;
            if ($status != -1) {
                $where .= " AND Trav_Reviews.status = '" . esc_sql($status) . "'";
            }
            $sql = $wpdb->prepare('SELECT Trav_Reviews.* , accommodation.post_title as accommodation_name FROM %1$s as Trav_Reviews
						INNER JOIN %2$s as accommodation ON Trav_Reviews.post_id=accommodation.ID
						WHERE ' . $where . ' ORDER BY %4$s %5$s
						LIMIT %6$s, %7$s', TRAV_REVIEWS_TABLE, $post_table_name, '', $orderby, $order, $per_page * ($current_page - 1), $per_page);
            $data = $wpdb->get_results($sql, ARRAY_A);
            $sql = "SELECT COUNT(*) FROM " . TRAV_REVIEWS_TABLE . " as Trav_Reviews where " . $where;
            $total_items = $wpdb->get_var($sql);
            $this->items = $data;
            $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page)));
        }
        function prepare_items()
        {
            global $wpdb;
            $per_page = 10;
            $columns = $this->get_columns();
            $hidden = array();
            $sortable = $this->get_sortable_columns();
            $this->_column_headers = array($columns, $hidden, $sortable);
            $this->process_bulk_action();
            $orderby = !empty($_REQUEST['orderby']) ? sanitize_sql_orderby($_REQUEST['orderby']) : 'id';
            //If no sort, default to title
            $order = !empty($_REQUEST['order']) ? sanitize_text_field($_REQUEST['order']) : 'desc';
            //If no order, default to desc
            $current_page = $this->get_pagenum();
            $post_table_name = $wpdb->prefix . 'posts';
            $where = "1=1";
            if (!empty($_REQUEST['accommodation_id'])) {
                $where .= " AND Trav_Vacancies.accommodation_id = '" . esc_sql(trav_acc_org_id($_REQUEST['accommodation_id'])) . "'";
            }
            if (!empty($_REQUEST['room_type_id'])) {
                $where .= " AND Trav_Vacancies.room_type_id = '" . esc_sql(trav_room_org_id($_REQUEST['room_type_id'])) . "'";
            }
            if (!empty($_REQUEST['date'])) {
                $where .= " AND Trav_Vacancies.date_from <= '" . esc_sql($_REQUEST['date']) . "' and Trav_Vacancies.date_to > '" . $_REQUEST['date'] . "'";
            }
            if (!current_user_can('manage_options')) {
                $where .= " AND accommodation.post_author = '" . get_current_user_id() . "' ";
            }
            $sql = $wpdb->prepare('SELECT Trav_Vacancies.* , accommodation.ID as acc_id, accommodation.post_title as accommodation_name, room_type.ID as room_type_id, room_type.post_title as room_type_name FROM %1$s as Trav_Vacancies
						INNER JOIN %2$s as accommodation ON Trav_Vacancies.accommodation_id=accommodation.ID
						INNER JOIN %2$s as room_type ON Trav_Vacancies.room_type_id=room_type.ID
						WHERE ' . $where . ' ORDER BY %4$s %5$s
						LIMIT %6$s, %7$s', TRAV_ACCOMMODATION_VACANCIES_TABLE, $post_table_name, '', $orderby, $order, $per_page * ($current_page - 1), $per_page);
            $data = $wpdb->get_results($sql, ARRAY_A);
            $sql = sprintf('SELECT COUNT(*) FROM %1$s as Trav_Vacancies INNER JOIN %2$s as accommodation ON Trav_Vacancies.accommodation_id=accommodation.ID WHERE %3$s', TRAV_ACCOMMODATION_VACANCIES_TABLE, $post_table_name, $where);
            $total_items = $wpdb->get_var($sql);
            $this->items = $data;
            $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page)));
        }