Beispiel #1
0
 function do_add_to_cart()
 {
     $pass_validate = true;
     $item_id = STInput::request('item_id', '');
     if ($item_id <= 0 || get_post_type($item_id) != 'st_holidays') {
         STTemplate::set_message(__('This holiday is not available..', ST_TEXTDOMAIN), 'danger');
         $pass_validate = false;
         return false;
     }
     $number = 1;
     $adult_number = intval(STInput::request('adult_number', 1));
     $child_number = intval(STInput::request('child_number', 0));
     $infant_number = intval(STInput::request('infant_number', 0));
     $data['adult_number'] = $adult_number;
     $data['child_number'] = $child_number;
     $data['infant_number'] = $infant_number;
     $max_number = intval(get_post_meta($item_id, 'max_people', true));
     $type_holiday = get_post_meta($item_id, 'type_holiday', true);
     $data['type_holiday'] = $type_holiday;
     $today = date('Y-m-d');
     $check_in = STInput::request('check_in', '');
     $check_out = STInput::request('check_out', '');
     if (!$check_in || !$check_out) {
         STTemplate::set_message(__('Select a holiday in the calendar above.', ST_TEXTDOMAIN), 'danger');
         $pass_validate = FALSE;
         return false;
     }
     $compare = TravelHelper::dateCompare($today, $check_in);
     if ($compare < 0) {
         STTemplate::set_message(__('This holiday has expired', ST_TEXTDOMAIN), 'danger');
         $pass_validate = false;
         return false;
     }
     $booking_period = intval(get_post_meta($item_id, 'holidays_booking_period', true));
     $period = TravelHelper::dateDiff($today, $check_in);
     if ($period < $booking_period) {
         STTemplate::set_message(sprintf(__('This holiday allow minimum booking is %d day(s)', ST_TEXTDOMAIN), $booking_period), 'danger');
         $pass_validate = false;
         return false;
     }
     if ($adult_number + $child_number + $infant_number > $max_number) {
         STTemplate::set_message(sprintf(__('Max of people for this holiday is %d people', ST_TEXTDOMAIN), $max_number), 'danger');
         $pass_validate = FALSE;
         return false;
     }
     $holiday_available = HolidayHelper::checkAvailableHoliday($item_id, strtotime($check_in), strtotime($check_out));
     if (!$holiday_available) {
         STTemplate::set_message(__('The check in, check out day is not invalid or this holiday not available.', ST_TEXTDOMAIN), 'danger');
         $pass_validate = FALSE;
         return false;
     }
     $free_people = intval(get_post_meta($item_id, 'max_people', true));
     $result = HolidayHelper::_get_free_peple($item_id, strtotime($check_in), strtotime($check_out));
     if (is_array($result) && count($result)) {
         $free_people = intval($result['free_people']);
     }
     if ($free_people < $adult_number + $child_number + $infant_number) {
         STTemplate::set_message(sprintf(__('This holiday only vacant %d people', ST_TEXTDOMAIN), $free_people), 'danger');
         $pass_validate = FALSE;
         return false;
     }
     $data_price = STPrice::getPriceByPeopleHoliday($item_id, strtotime($check_in), strtotime($check_out), $adult_number, $child_number, $infant_number);
     $total_price = $data_price['total_price'];
     $sale_price = STPrice::getSaleHolidaySalePrice($item_id, $total_price, $type_holiday, strtotime($check_in));
     $data['check_in'] = date('m/d/Y', strtotime($check_in));
     $data['check_out'] = date('m/d/Y', strtotime($check_out));
     $people_price = STPrice::getPeoplePrice($item_id, strtotime($check_in), strtotime($check_out));
     $data = wp_parse_args($data, $people_price);
     $data['ori_price'] = $sale_price;
     $data['currency'] = TravelHelper::get_current_currency('symbol');
     $data['currency_rate'] = TravelHelper::get_current_currency('rate');
     $data['currency_pos'] = TravelHelper::get_current_currency('booking_currency_pos');
     $data['commission'] = TravelHelper::get_commission();
     $data['data_price'] = $data_price;
     $data['discount_rate'] = STPrice::get_discount_rate($item_id, strtotime($check_in));
     if ($pass_validate) {
         $data['duration'] = $type_holiday == 'daily_holiday' ? floatval(get_post_meta($item_id, 'duration_day', true)) : '';
         if ($pass_validate) {
             STCart::add_cart($item_id, $number, $sale_price, $data);
         }
     }
     return $pass_validate;
 }
Beispiel #2
0
 public function _get_availability_hotel_room()
 {
     $list_date = array();
     $room_id = STInput::request('post_id', '');
     $check_in = STInput::request('start', '');
     $check_out = STInput::request('end', '');
     $hotel_id = intval(get_post_meta($room_id, 'room_parent', true));
     $allow_full_day = get_post_meta($hotel_id, 'allow_full_day', true);
     if (!$allow_full_day || $allow_full_day == '') {
         $allow_full_day = 'on';
     }
     $year = date('Y', $check_in);
     if (empty($year)) {
         $year = date('Y');
     }
     $year2 = date('Y', $check_out);
     if (empty($year2)) {
         $year2 = date('Y');
     }
     $month = date('m', $check_in);
     if (empty($month)) {
         $month = date('m');
     }
     $month2 = date('m', $check_out);
     if (empty($month2)) {
         $month2 = date('m');
     }
     $result = HotelHelper::_get_full_ordered($room_id, $month, $month2, $year, $year2);
     $number_room = get_post_meta($room_id, 'number_room', true);
     $min_max = HotelHelper::_get_min_max_date_ordered($room_id, $year, $year2);
     if (is_array($min_max) && count($min_max) && is_array($result) && count($result)) {
         $disable = array();
         for ($i = intval($min_max['min_date']); $i <= intval($min_max['max_date']); $i = strtotime('+1 day', $i)) {
             $num_room = 0;
             foreach ($result as $key => $date) {
                 if ($allow_full_day == 'on') {
                     if ($i >= intval($date['check_in_timestamp']) && $i <= intval($date['check_out_timestamp'])) {
                         $num_room += $date['number_room'];
                     }
                 } else {
                     if ($i > intval($date['check_in_timestamp']) && $i < intval($date['check_out_timestamp'])) {
                         $num_room += $date['number_room'];
                     }
                 }
             }
             $disable[$i] = $num_room;
         }
         if (count($disable)) {
             foreach ($disable as $key => $num_room) {
                 if (intval($num_room) >= $number_room) {
                     $list_date[] = date(TravelHelper::getDateFormat(), $key);
                 }
             }
         }
     }
     $list_date_2 = AvailabilityHelper::_getDisableCustomDate($room_id, $month, $month2, $year, $year2);
     $date1 = strtotime($year . '-' . $month . '-01');
     $date2 = strtotime($year2 . '-' . $month2 . '-01');
     $date2 = strtotime(date('Y-m-t', $date2));
     $today = strtotime(date('Y-m-d'));
     $return = array();
     $booking_period = intval(get_post_meta($hotel_id, 'hotel_booking_period', true));
     for ($i = $date1; $i <= $date2; $i = strtotime('+1 day', $i)) {
         $period = TravelHelper::dateDiff(date('Y-m-d', $today), date('Y-m-d', $i));
         $d = date(TravelHelper::getDateFormat(), $i);
         if (in_array($d, $list_date)) {
             $return[] = array('start' => date('Y-m-d', $i), 'date' => date('Y-m-d', $i), 'day' => date('d', $i), 'status' => 'booked');
         } else {
             if ($i < $today) {
                 $return[] = array('start' => date('Y-m-d', $i), 'date' => date('Y-m-d', $i), 'day' => date('d', $i), 'status' => 'past');
             } else {
                 if (in_array($d, $list_date_2)) {
                     $return[] = array('start' => date('Y-m-d', $i), 'date' => date('Y-m-d', $i), 'day' => date('d', $i), 'status' => 'disabled');
                 } else {
                     if ($period < $booking_period) {
                         $return[] = array('start' => date('Y-m-d', $i), 'date' => date('Y-m-d', $i), 'day' => date('d', $i), 'status' => 'disabled');
                     } else {
                         $return[] = array('start' => date('Y-m-d', $i), 'date' => date('Y-m-d', $i), 'day' => date('d', $i), 'status' => 'avalable', 'price' => TravelHelper::format_money(STPrice::getRoomPriceOnlyCustomPrice($room_id, $i, strtotime('+1 day', $i), 1)));
                     }
                 }
             }
         }
     }
     echo json_encode($return);
     die;
 }
 function do_add_to_cart()
 {
     $pass_validate = true;
     $item_id = intval(STInput::request('item_id', ''));
     if ($item_id <= 0 || get_post_type($item_id) != 'st_activity') {
         STTemplate::set_message(__('This activity is not available..', ST_TEXTDOMAIN), 'danger');
         $pass_validate = false;
         return false;
     }
     $number = 1;
     $type_activity = STInput::request('type_activity', 'specific_date');
     $adult_number = intval(STInput::request('adult_number', 1));
     $child_number = intval(STInput::request('child_number', 0));
     $infant_number = intval(STInput::request('infant_number', 0));
     $max_number = intval(get_post_meta($item_id, 'max_people', true));
     $today = date('Y-m-d');
     if ($adult_number + $child_number + $infant_number > $max_number) {
         STTemplate::set_message(sprintf(__('Max of people for this activity is %d people', ST_TEXTDOMAIN), $max_number), 'danger');
         $pass_validate = FALSE;
         return false;
     }
     if ($type_activity == 'specific_date') {
         $check_in = TravelHelper::convertDateFormat(STInput::request('check_in', ''));
         $check_out = TravelHelper::convertDateFormat(STInput::request('check_out', ''));
         if (empty($check_in)) {
             STTemplate::set_message(__('The check in field is not empty.', ST_TEXTDOMAIN), 'danger');
             $pass_validate = false;
             return false;
         }
         if (empty($check_out)) {
             STTemplate::set_message(__('The check out field is not empty.', ST_TEXTDOMAIN), 'danger');
             $pass_validate = false;
             return false;
         }
         $compare = TravelHelper::dateCompare($today, $check_in);
         if ($compare < 0) {
             STTemplate::set_message(__('This activity has expired', ST_TEXTDOMAIN), 'danger');
             $pass_validate = false;
             return false;
         }
         $people = $adult_number + $child_number + $child_number;
         $result = ActivityHelper::_get_free_peple_special($item_id, $check_in, $check_out);
         $free_people = intval(get_post_meta($item_id, 'max_people', true));
         if (is_array($result) && count($result)) {
             $free_people = intval($result['free_people']);
         }
         if ($free_people < $people) {
             STTemplate::set_message(sprintf(__('This activity only vacant %d people', ST_TEXTDOMAIN), $free_people), 'danger');
             $pass_validate = false;
             return false;
         }
         $data['check_in'] = date('m/d/Y', strtotime($check_in));
         $data['check_out'] = date('m/d/Y', strtotime($check_out));
     } elseif ($type_activity == 'daily_activity') {
         $check_in = STInput::request('check_in', '');
         if (empty($check_in)) {
             STTemplate::set_message(__('The check in field is not empty.', ST_TEXTDOMAIN), 'danger');
             $pass_validate = false;
             return false;
         }
         $check_in = TravelHelper::convertDateFormat($check_in);
         $check_in = date('Y-m-d', strtotime($check_in));
         $duration = intval(get_post_meta($item_id, 'duration', true));
         $check_out = $duration >= 2 ? strtotime('+ ' . $duration . ' days', strtotime($check_in)) : strtotime('+ ' . $duration . ' day', strtotime($check_in));
         $check_out = date('Y-m-d', $check_out);
         $booking_period = intval(get_post_meta($item_id, 'activity_booking_period', true));
         $period = TravelHelper::dateDiff($today, $check_in);
         $compare = TravelHelper::dateCompare($today, $check_in);
         if ($compare < 0) {
             STTemplate::set_message(__('You can not set check-in date in the past', ST_TEXTDOMAIN), 'danger');
             $pass_validate = false;
             return false;
         }
         if ($booking_period && $booking_period > $period) {
             STTemplate::set_message(sprintf(__('This activity allow minimum booking is %d day(s)', ST_TEXTDOMAIN), $booking_period), 'danger');
             $pass_validate = false;
             return false;
         }
         $people = $adult_number + $child_number + $child_number;
         $result = ActivityHelper::_get_free_peple_daily($item_id, $check_in);
         $free_people = intval(get_post_meta($item_id, 'max_people', true));
         if (is_array($result) && count($result)) {
             $free_people = intval($result['free_people']);
         }
         if ($free_people < $people) {
             STTemplate::set_message(sprintf(__('This activity only vacant %d people', ST_TEXTDOMAIN), $free_people), 'danger');
             $pass_validate = false;
             return false;
         }
         $data['duration'] = $duration;
     }
     $data['adult_number'] = $adult_number;
     $data['child_number'] = $child_number;
     $data['infant_number'] = $infant_number;
     $data['check_in'] = date('m/d/Y', strtotime($check_in));
     $data['check_out'] = date('m/d/Y', strtotime($check_out));
     $data['type_activity'] = $type_activity;
     $data_price = STPrice::getPriceByPeople($item_id, strtotime($check_in), strtotime($check_out), $adult_number, $child_number, $infant_number);
     $total_price = $data_price['total_price'];
     $sale_price = STPrice::getSaleTourSalePrice($item_id, $total_price, $type_activity, strtotime($check_in));
     $discount_rate = STPrice::get_discount_rate($item_id, strtotime($check_in));
     $data['adult_price'] = floatval(get_post_meta($item_id, 'adult_price', true));
     $data['child_price'] = floatval(get_post_meta($item_id, 'child_price', true));
     $data['infant_price'] = floatval(get_post_meta($item_id, 'infant_price', true));
     $data['ori_price'] = $sale_price;
     $data['currency'] = TravelHelper::get_current_currency('symbol');
     $data['currency_rate'] = TravelHelper::get_current_currency('rate');
     $data['currency_pos'] = TravelHelper::get_current_currency('booking_currency_pos');
     $data['commission'] = TravelHelper::get_commission();
     $data['data_price'] = $data_price;
     $data['discount_rate'] = $discount_rate;
     if ($pass_validate) {
         $pass_validate = apply_filters('st_activity_add_cart_validate', $pass_validate);
     }
     if ($pass_validate) {
         STCart::add_cart($item_id, $number, $sale_price, $data);
     }
     return $pass_validate;
 }
                    </td>
                    <td style="border-left: 1px solid #bcbcbc;border-top: 1px solid #bcbcbc;border-bottom: 1px solid #bcbcbc;padding: 6px;background: #e4e4e4;border-right: 1px solid #bcbcbc;">
                        <?php 
echo __('Information', ST_TEXTDOMAIN);
?>
                    </td>
                </tr>
                <?php 
$total = 0;
$i = 0;
$i++;
$order_item_id = $order_id;
$object_id = get_post_meta($order_item_id, 'item_id', true);
$check_in = get_post_meta($order_item_id, 'check_in', true);
$check_out = get_post_meta($order_item_id, 'check_out', true);
$numberday = TravelHelper::dateDiff($check_in, $check_out);
$item_price = floatval(get_post_meta($order_item_id, 'item_price', true));
?>
                    <tr>
                        <td style="padding: 6px;border-left: 1px solid #bcbcbc;border-bottom: 1px solid #bcbcbc;" valign="top" align="center" width="5%">
                            <?php 
echo esc_html($i);
?>
                        </td>
                        <td width="35%" style="vertical-align: top;padding: 6px;border-bottom:1px dashed #ccc;border-left: 1px solid #bcbcbc;border-bottom: 1px solid #bcbcbc;">
                            <?php 
echo get_the_post_thumbnail($object_id, array(360, 270, 'bfi_thumb' => true), array('style' => 'max-width:100%;height:auto'));
?>
                        </td >
                        <td style="padding: 6px;vertical-align: top;border-bottom:1px dashed #ccc;border-left: 1px solid #bcbcbc;border-bottom: 1px solid #bcbcbc;border-right: 1px solid #bcbcbc;">
Beispiel #5
0
 function _get_where_query($where)
 {
     if (!TravelHelper::checkTableDuplicate('st_rental')) {
         return $where;
     }
     global $wpdb;
     if ($location_id = STInput::get('location_id') and STInput::get('location_id') or get_post_type(get_the_ID()) == 'location') {
         if (!$location_id) {
             $location_id = get_the_ID();
         }
         $list = TravelHelper::getLocationByParent($location_id);
         if (is_array($list) && count($list)) {
             $where .= " AND (";
             $where_tmp = "";
             foreach ($list as $item) {
                 if (empty($where_tmp)) {
                     $where_tmp .= "tb.multi_location LIKE '%_{$item}_%'";
                 } else {
                     $where_tmp .= " OR tb.multi_location LIKE '%_{$item}_%'";
                 }
             }
             $list = implode(',', $list);
             $where_tmp .= " OR tb.location_id IN ({$list})";
             $where .= $where_tmp . ")";
         } else {
             $where .= " AND (tb.multi_location LIKE '%_{$location_id}_%' OR tb.location_id IN ('{$location_id}')) ";
         }
     } elseif ($location_name = STInput::request('location_name')) {
         $ids_location = TravelerObject::_get_location_by_name($location_name);
         if (is_array($ids_location) && count($ids_location)) {
             $ids_location_tmp = array();
             foreach ($ids_location as $item) {
                 $list = TravelHelper::getLocationByParent($item);
                 if (is_array($list) && count($list)) {
                     foreach ($list as $item) {
                         $ids_location_tmp[] = $item;
                     }
                 }
             }
             if (count($ids_location_tmp)) {
                 $ids_location = $ids_location_tmp;
             }
         }
         if (!empty($ids_location)) {
             $where .= " AND ((";
             $where_tmp = "";
             foreach ($ids_location as $id) {
                 if (empty($where_tmp)) {
                     $where_tmp .= " tb.multi_location LIKE '%_{$id}_%' ";
                 } else {
                     $where_tmp .= " OR tb.multi_location LIKE '%_{$id}_%' ";
                 }
             }
             $ids_location = implode(',', $ids_location);
             $where_tmp .= " OR (tb.location_id IN ({$ids_location})";
             $where .= $where_tmp . ")";
             $where .= " OR (tb.address LIKE '%{$location_name}%'";
             $where .= " OR {$wpdb->prefix}posts.post_title LIKE '%{$location_name}%')))";
         } else {
             if (!empty($_REQUEST['search_all'])) {
                 $where .= " AND (tb.address LIKE '%{$location_name}%'";
                 $where .= " OR {$wpdb->prefix}posts.post_title LIKE '%{$location_name}%')";
             }
         }
     } elseif ($address = STInput::request('address', '')) {
         $value = STInput::request('address');
         $value = explode(",", $value);
         if (!empty($value[0]) and !empty($value[2])) {
             $where .= " AND (tb.address LIKE '%{$value[0]}%' OR tb.address LIKE '%{$value[2]}%')";
         } else {
             $where .= " AND (tb.address LIKE '%{$address}%')";
         }
     }
     if (isset($_GET['start']) && isset($_GET['end']) and !empty($_GET['start']) and !empty($_GET['end'])) {
         $check_in = date('Y-m-d', strtotime(TravelHelper::convertDateFormat($_GET['start'])));
         $check_out = date('Y-m-d', strtotime(TravelHelper::convertDateFormat($_GET['end'])));
         $today = date('m/d/Y');
         $period = TravelHelper::dateDiff($today, $check_in);
         $adult_number = STInput::get('adult_number', 0);
         if (intval($adult_number) < 0) {
             $adult_number = 0;
         }
         $children_number = STInput::get('children_num', 0);
         if (intval($children_number) < 0) {
             $children_number = 0;
         }
         $list_rental = RentalHelper::_rentalValidate($check_in, $check_out, $adult_number, $children_number, 1);
         if (!is_array($list_rental) || count($list_rental) <= 0) {
             $list_rental = "''";
         } else {
             $list_rental = implode(',', $list_rental);
         }
         $where .= " AND {$wpdb->posts}.ID NOT IN ({$list_rental}) AND CAST(tb.rentals_booking_period AS UNSIGNED) <= {$period}";
     }
     if ($star = STInput::get('star_rate')) {
         $stars = STInput::get('star_rate', 1);
         $stars = explode(',', $stars);
         $all_star = array();
         if (!empty($stars) && is_array($stars)) {
             foreach ($stars as $val) {
                 for ($i = $val; $i < $val + 0.9; $i += 0.1) {
                     if ($i) {
                         $all_star[] = $i;
                     }
                 }
             }
         }
         $list_star = implode(',', $all_star);
         if ($list_star) {
             $where .= " AND (tb.rate_review IN ({$list_star}))";
         }
     }
     if ($price = STInput::get('price_range')) {
         $priceobj = explode(';', $price);
         $priceobj[0] = TravelHelper::convert_money_to_default($priceobj[0]);
         $where .= " AND (tb.sale_price >= {$priceobj[0]})";
         if (isset($priceobj[1])) {
             $priceobj[1] = TravelHelper::convert_money_to_default($priceobj[1]);
             $where .= " AND (tb.sale_price <= {$priceobj[1]})";
         }
     }
     if (isset($_REQUEST['range']) and isset($_REQUEST['location_id'])) {
         $range = STInput::request('range', '5');
         $location_id = STInput::request('location_id');
         $post_type = get_query_var('post_type');
         $map_lat = (double) get_post_meta($location_id, 'map_lat', true);
         $map_lng = (double) get_post_meta($location_id, 'map_lng', true);
         global $wpdb;
         $where .= "\r\n                AND {$wpdb->posts}.ID IN (\r\n                        SELECT ID FROM (\r\n                            SELECT {$wpdb->posts}.*,( 6371 * acos( cos( radians({$map_lat}) ) * cos( radians( mt1.meta_value ) ) *\r\n                                            cos( radians( mt2.meta_value ) - radians({$map_lng}) ) + sin( radians({$map_lat}) ) *\r\n                                            sin( radians( mt1.meta_value ) ) ) ) AS distance\r\n                                                FROM {$wpdb->posts}, {$wpdb->postmeta} as mt1,{$wpdb->postmeta} as mt2\r\n                                                WHERE {$wpdb->posts}.ID = mt1.post_id\r\n                                                and {$wpdb->posts}.ID=mt2.post_id\r\n                                                AND mt1.meta_key = 'map_lat'\r\n                                                and mt2.meta_key = 'map_lng'\r\n                                                AND {$wpdb->posts}.post_status = 'publish'\r\n                                                AND {$wpdb->posts}.post_type = '{$post_type}'\r\n                                                AND {$wpdb->posts}.post_date < NOW()\r\n                                                GROUP BY {$wpdb->posts}.ID HAVING distance<{$range}\r\n                                                ORDER BY distance ASC\r\n                        ) as st_data\r\n\t            )";
     }
     if (isset($_REQUEST['item_id']) and !empty($_REQUEST['item_id'])) {
         $item_id = STInput::request('item_id', '');
         $where .= " AND ({$wpdb->prefix}posts.ID = '{$item_id}')";
     }
     if (!empty($_REQUEST['room_num_search'])) {
         $room_num_search = $_REQUEST['room_num_search'];
         $list_not_in = RentalHelper::get_list_not_in($room_num_search);
         $where .= " AND {$wpdb->prefix}posts.ID NOT IN ({$list_not_in})";
     }
     return $where;
 }
        ?>
 : </strong>
                <?php 
        echo esc_html($duration);
        ?>
            </p>
            <?php 
    }
    ?>
        <?php 
} else {
    if ($type_tour == 'specific_date') {
        ?>
            <?php 
        if ($check_in and $check_out) {
            $period = TravelHelper::dateDiff($check_in, $check_out);
            ?>
                <p>
                    <strong><?php 
            st_the_language('tour_date');
            ?>
 : </strong>
                    <?php 
            echo date_i18n(TravelHelper::getDateFormat(), strtotime($check_in));
            ?>
 -
                    <?php 
            echo date_i18n(TravelHelper::getDateFormat(), strtotime($check_out));
            ?>
                </p>
            <?php 
 function _check_validate()
 {
     $data = array();
     $order_item_id = STInput::request('order_item_id', '');
     $st_first_name = STInput::request('st_first_name', '');
     if (empty($st_first_name)) {
         STAdmin::set_message(__('The firstname field is not empty.', ST_TEXTDOMAIN), 'danger');
         return false;
     }
     $st_last_name = STInput::request('st_last_name', '');
     if (empty($st_last_name)) {
         STAdmin::set_message(__('The lastname field is not empty.', ST_TEXTDOMAIN), 'danger');
         return false;
     }
     $st_email = STInput::request('st_email', '');
     if (empty($st_email)) {
         STAdmin::set_message(__('The email field is not empty.', ST_TEXTDOMAIN), 'danger');
         return false;
     }
     $st_phone = STInput::request('st_phone', '');
     if (empty($st_phone)) {
         STAdmin::set_message(__('The phone field is not empty.', ST_TEXTDOMAIN), 'danger');
         return false;
     }
     if (STInput::request('section', '') != 'edit_order_item') {
         $item_id = intval(STInput::request('item_id', ''));
         if ($item_id <= 0 || get_post_type($item_id) != 'st_holidays') {
             STAdmin::set_message(__('The holiday field is not empty.', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         $type_holiday = get_post_meta($item_id, 'type_holiday', true);
         $today = date('Y-m-d');
         $check_in = STInput::request('check_in', '');
         $check_out = STInput::request('check_out', '');
         if (!$check_in || !$check_out) {
             STAdmin::set_message(__('Select a holiday in the calendar above.', ST_TEXTDOMAIN), 'danger');
             $pass_validate = FALSE;
             return false;
         }
         $compare = TravelHelper::dateCompare($today, $check_in);
         if ($compare < 0) {
             STAdmin::set_message(__('This holiday has expired', ST_TEXTDOMAIN), 'danger');
             $pass_validate = false;
             return false;
         }
         $duration = ($type_holiday = 'daily_holiday') ? get_post_meta($item_id, 'duration_day', true) : '';
         $booking_period = intval(get_post_meta($item_id, 'holidays_booking_period', true));
         $period = TravelHelper::dateDiff($today, $check_in);
         if ($period < $booking_period) {
             STAdmin::set_message(sprintf(__('This holiday allow minimum booking is %d day(s)', ST_TEXTDOMAIN), $booking_period), 'danger');
             $pass_validate = false;
             return false;
         }
         $adult_number = intval(STInput::request('adult_number', 1));
         $child_number = intval(STInput::request('child_number', 0));
         $infant_number = intval(STInput::request('infant_number', 0));
         $max_number = intval(get_post_meta($item_id, 'max_people', true));
         if ($adult_number + $child_number + $infant_number > $max_number) {
             STAdmin::set_message(sprintf(__('Max of people for this holiday is %d people', ST_TEXTDOMAIN), $max_number), 'danger');
             return false;
         }
         $holiday_available = HolidayHelper::checkAvailableHoliday($item_id, strtotime($check_in), strtotime($check_out));
         if (!$holiday_available) {
             STAdmin::set_message(__('The check in, check out day is not invalid or this holiday not available.', ST_TEXTDOMAIN), 'danger');
             $pass_validate = FALSE;
             return false;
         }
         $free_people = intval(get_post_meta($item_id, 'max_people', true));
         $result = HolidayHelper::_get_free_peple($item_id, strtotime($check_in), strtotime($check_out), $order_item_id);
         if (is_array($result) && count($result)) {
             $free_people = intval($result['free_people']);
         }
         if ($free_people > $max_number) {
             STAdmin::set_message(sprintf(__('This holiday only vacant %d people', ST_TEXTDOMAIN), $free_people), 'danger');
             $pass_validate = FALSE;
             return false;
         }
         $data['order_item_id'] = $order_item_id;
         $data['item_id'] = $item_id;
         $data['check_in'] = date('m/d/Y', strtotime($check_in));
         $data['check_out'] = date('m/d/Y', strtotime($check_out));
         $data['adult_number'] = $adult_number;
         $data['child_number'] = $child_number;
         $data['infant_number'] = $infant_number;
         $data['type_holiday'] = $type_holiday;
         $data['duration'] = $duration;
         $people_price = STPrice::getPeoplePrice($item_id, strtotime($check_in), strtotime($check_out));
         $data = wp_parse_args($data, $people_price);
     }
     return $data;
 }
 function check_validate()
 {
     $data = array();
     $order_item_id = STInput::request('order_item_id', '');
     $st_first_name = STInput::request('st_first_name', '');
     if (empty($st_first_name)) {
         STAdmin::set_message(__('The firstname field is not empty.', ST_TEXTDOMAIN), 'danger');
         return false;
     }
     $st_last_name = STInput::request('st_last_name', '');
     if (empty($st_last_name)) {
         STAdmin::set_message(__('The lastname field is not empty.', ST_TEXTDOMAIN), 'danger');
         return false;
     }
     $st_email = STInput::request('st_email', '');
     if (empty($st_email)) {
         STAdmin::set_message(__('The email field is not empty.', ST_TEXTDOMAIN), 'danger');
         return false;
     }
     $st_phone = STInput::request('st_phone', '');
     if (empty($st_phone)) {
         STAdmin::set_message(__('The phone field is not empty.', ST_TEXTDOMAIN), 'danger');
         return false;
     }
     if (STInput::request('section', '') != 'edit_order_item') {
         $item_id = intval(STInput::request('item_id', ''));
         if ($item_id <= 0 || get_post_type($item_id) != 'st_activity') {
             STAdmin::set_message(__('The activity field is not empty.', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         $type_activity = STInput::request('type_activity', 'daily_activity');
         $today = date('Y-m-d');
         $check_in = STInput::request('check_in', '');
         if (empty($check_in)) {
             STAdmin::set_message(__('The check in field is not empty.', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         $check_in = date('Y-m-d', strtotime($check_in));
         $check_out = STInput::request('check_out', '');
         if (empty($check_out)) {
             STAdmin::set_message(__('The check out field is not empty.', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         $check_out = date('Y-m-d', strtotime($check_out));
         $adult_number = intval(STInput::request('adult_number', 1));
         $child_number = intval(STInput::request('child_number', 0));
         $infant_number = intval(STInput::request('infant_number', 0));
         $max_number = intval(get_post_meta($item_id, 'max_people', true));
         if ($adult_number + $child_number + $infant_number > $max_number) {
             STAdmin::set_message(sprintf(__('Max of people for this activity is %d people', ST_TEXTDOMAIN), $max_number), 'danger');
             return false;
         }
         if ($type_activity == 'daily_activity') {
             $booking_period = intval(get_post_meta($item_id, 'activity_booking_period', true));
             $period = TravelHelper::dateDiff($today, $check_in);
             $compare = TravelHelper::dateCompare($today, $check_in);
             if ($compare < 0) {
                 STAdmin::set_message(__('You can not set check-in date in the past', ST_TEXTDOMAIN), 'danger');
                 return false;
             }
             if ($booking_period && $booking_period > $period) {
                 STAdmin::set_message(sprintf(__('This activity allow minimum booking is %d day(s)', ST_TEXTDOMAIN), $booking_period), 'danger');
                 return false;
             }
             $people = $adult_number + $child_number + $infant_number;
             $result = ActivityHelper::_get_free_peple_daily($item_id, $check_in, $order_item_id);
             $free_people = intval(get_post_meta($item_id, 'max_people', true));
             if (is_array($result) && count($result)) {
                 $free_people = intval($result['free_people']);
             }
             if ($free_people < $people) {
                 STAdmin::set_message(sprintf(__('This activity only vacant %d people', ST_TEXTDOMAIN), $free_people), 'danger');
                 return false;
             }
             $duration = get_post_meta($item_id, 'duration', true);
             $data['duration'] = $duration;
         } elseif ($type_activity == 'specific_date') {
             $compare = TravelHelper::dateCompare($today, $check_in);
             if ($compare < 0) {
                 STAdmin::set_message(__('This activity has expired', ST_TEXTDOMAIN), 'danger');
                 return false;
             }
             $people = $adult_number + $child_number + $infant_number;
             $result = ActivityHelper::_get_free_peple_special($item_id, $check_in, $check_out, $order_item_id);
             $free_people = intval(get_post_meta($item_id, 'max_people', true));
             if (is_array($result) && count($result)) {
                 $free_people = intval($result['free_people']);
             }
             if ($free_people < $people) {
                 STAdmin::set_message(sprintf(__('This activity only vacant %d people', ST_TEXTDOMAIN), $free_people), 'danger');
                 return false;
             }
         }
         $data['item_id'] = $item_id;
         $data['order_item_id'] = $order_item_id;
         $data['check_in'] = date('m/d/Y', strtotime($check_in));
         $data['check_out'] = date('m/d/Y', strtotime($check_out));
         $data['adult_number'] = $adult_number;
         $data['child_number'] = $child_number;
         $data['infant_number'] = $infant_number;
         $data['type_activity'] = $type_activity;
         $data['adult_price'] = floatval(get_post_meta($item_id, 'adult_price', true));
         $data['child_price'] = floatval(get_post_meta($item_id, 'child_price', true));
         $data['infant_price'] = floatval(get_post_meta($item_id, 'infant_price', true));
     }
     return $data;
 }
 static function _get_list_availability_holiday_frontend($holiday_id, $check_in, $check_out)
 {
     $results = array();
     $today = strtotime(date('Y-m-d'));
     if (get_post_type($holiday_id) == 'st_holidays') {
         $adult_price = floatval(get_post_meta($holiday_id, 'adult_price', true));
         $child_price = floatval(get_post_meta($holiday_id, 'child_price', true));
         $infant_price = floatval(get_post_meta($holiday_id, 'infant_price', true));
         $type_holiday = get_post_meta($holiday_id, 'type_holiday', true);
         $booking_period = intval(get_post_meta($holiday_id, 'holidays_booking_period', true));
         $data_holiday = self::_getdataHolidayEachDate($holiday_id, $check_in, $check_out);
         if (is_array($data_holiday) && count($data_holiday)) {
             foreach ($data_holiday as $key => $val) {
                 if ($val->status == 'available') {
                     $cant_book = self::_get_holiday_cant_order($holiday_id, date('m/d/Y', $val->check_in));
                     $period = TravelHelper::dateDiff(date('Y-m-d', $today), date('Y-m-d', $val->check_in));
                     if (intval($val->groupday) == 1) {
                         if ($val->check_in >= $today && count($cant_book) <= 0 && $period >= $booking_period) {
                             $results[] = array('start' => date('Y-m-d', $val->check_in), 'end' => date('Y-m-d', $val->check_out), 'adult_price' => TravelHelper::format_money($val->adult_price), 'child_price' => TravelHelper::format_money($val->child_price), 'infant_price' => TravelHelper::format_money($val->infant_price), 'status' => 'available');
                         }
                     } else {
                         if ($val->check_in >= $today && count($cant_book) <= 0 && $period >= $booking_period) {
                             $results[] = array('start' => date('Y-m-d', $val->check_in), 'end' => date('Y-m-d', $val->check_in), 'adult_price' => TravelHelper::format_money($val->adult_price), 'child_price' => TravelHelper::format_money($val->child_price), 'infant_price' => TravelHelper::format_money($val->infant_price), 'status' => 'available');
                         }
                     }
                 }
             }
             if ($type_holiday == 'daily_holiday') {
                 for ($i = $check_in; $i <= $check_out; $i = strtotime('+1 day', $i)) {
                     $in_item = false;
                     $status = 'available';
                     foreach ($data_holiday as $key => $val) {
                         if ($i >= $val->check_in && $i <= $val->check_out) {
                             $in_item = true;
                             $status = $val->status;
                             break;
                         }
                     }
                     if (!$in_item) {
                         $cant_book = self::_get_holiday_cant_order($holiday_id, date('m/d/Y', $i));
                         $period = TravelHelper::dateDiff(date('Y-m-d', $today), date('Y-m-d', $i));
                         if ($i >= $today && count($cant_book) <= 0 && $period >= $booking_period) {
                             $results[] = array('start' => date('Y-m-d', $i), 'end' => date('Y-m-d', $i), 'adult_price' => TravelHelper::format_money($adult_price), 'child_price' => TravelHelper::format_money($child_price), 'infant_price' => TravelHelper::format_money($infant_price), 'status' => 'available');
                         }
                     }
                 }
             }
         } else {
             if ($type_holiday == 'daily_holiday') {
                 for ($i = $check_in; $i <= $check_out; $i = strtotime('+1 day', $i)) {
                     $cant_book = self::_get_holiday_cant_order($holiday_id, date('m/d/Y', $i));
                     $period = TravelHelper::dateDiff(date('Y-m-d', $today), date('Y-m-d', $i));
                     if ($i >= $today && count($cant_book) <= 0 && $period >= $booking_period) {
                         $results[] = array('title' => get_the_title($holiday_id), 'start' => date('Y-m-d', $i), 'end' => date('Y-m-d', $i), 'adult_price' => TravelHelper::format_money($adult_price), 'child_price' => TravelHelper::format_money($child_price), 'infant_price' => TravelHelper::format_money($infant_price), 'status' => 'available');
                     }
                 }
             }
         }
     }
     return $results;
 }
 function check_validate()
 {
     $data = array();
     $order_item_id = STInput::request('order_item_id', '');
     $st_first_name = STInput::request('st_first_name', '');
     if (empty($st_first_name)) {
         STAdmin::set_message(__('The firstname field is not empty.', ST_TEXTDOMAIN), 'danger');
         return false;
     }
     $st_last_name = STInput::request('st_last_name', '');
     if (empty($st_last_name)) {
         STAdmin::set_message(__('The lastname field is not empty.', ST_TEXTDOMAIN), 'danger');
         return false;
     }
     $st_email = STInput::request('st_email', '');
     if (empty($st_email)) {
         STAdmin::set_message(__('The email field is not empty.', ST_TEXTDOMAIN), 'danger');
         return false;
     }
     $st_phone = STInput::request('st_phone', '');
     if (empty($st_phone)) {
         STAdmin::set_message(__('The phone field is not empty.', ST_TEXTDOMAIN), 'danger');
         return false;
     }
     if (STInput::request('section', '') != 'edit_order_item') {
         $item_id = intval(STInput::request('item_id', ''));
         if ($item_id <= 0 || get_post_type($item_id) != 'st_cars') {
             STAdmin::set_message(__('The car field is not empty.', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         $pick_up = STInput::request('pick_up', '');
         $drop_off = STInput::request('drop_off', '');
         if (!empty($pick_up) && !empty($drop_off)) {
             $pickup_country = get_post_meta($pick_up, 'location_country', true);
             if (!$pickup_country) {
                 STAdmin::set_message(__('The \'country\' field not set for the \'\'', ST_TEXTDOMAIN) . get_the_title($pick_up), 'danger');
                 $pass_validate = false;
                 return false;
             }
             $dropoff_country = get_post_meta($drop_off, 'location_country', true);
             if (!$dropoff_country) {
                 STAdmin::set_message(__('The \'country\' field not set for the \'\'', ST_TEXTDOMAIN) . get_the_title($drop_off), 'danger');
                 $pass_validate = false;
                 return false;
             }
             if ($pickup_country != $dropoff_country) {
                 STAdmin::set_message(__('The country is not same', ST_TEXTDOMAIN), 'danger');
                 $pass_validate = false;
                 return false;
             }
         }
         $check_in = STInput::request('check_in', '');
         if (empty($check_in)) {
             STAdmin::set_message(__('The check in field  is not empty.', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         $check_in_time = STInput::request('check_in_time', '');
         if (empty($check_in_time)) {
             STAdmin::set_message(__('The check in time field  is not empty.', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         $check_out = STInput::request('check_out', '');
         if (empty($check_out)) {
             STAdmin::set_message(__('The check out field  is not empty.', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         $check_out_time = STInput::request('check_out_time', '');
         if (empty($check_out_time)) {
             STAdmin::set_message(__('The check out time field  is not empty.', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         $check_in_full = $check_in . ' ' . strtoupper($check_in_time);
         $check_out_full = $check_out . ' ' . strtoupper($check_out_time);
         $check_in_timestamp = strtotime($check_in_full);
         $check_out_timestamp = strtotime($check_out_full);
         $today = date('m/d/Y');
         $period = TravelHelper::dateDiff($today, $check_in);
         $compare = TravelHelper::dateCompare($today, $check_out);
         $booking_period = intval(get_post_meta($item_id, 'cars_booking_period', true));
         if ($booking_period <= 0) {
             $booking_period = 0;
         }
         if ($check_in_timestamp - $check_out_timestamp >= 0) {
             STAdmin::set_message(__('The drop off datetime is later than the pick up datetime.', ST_TEXTDOMAIN), 'danger');
             $pass_validate = false;
             return false;
         }
         if ($compare < 0) {
             STAdmin::set_message(__('You can not set check-in date in the past', ST_TEXTDOMAIN), 'danger');
             $pass_validate = false;
             return false;
         }
         if ($period < $booking_period) {
             STAdmin::set_message(sprintf(__('This car allow minimum booking is %d day(s)', ST_TEXTDOMAIN), $booking_period), 'danger');
             $pass_validate = false;
             return false;
         }
         if (!CarHelper::_get_car_cant_order_by_id($item_id, $check_in_timestamp, $check_out_timestamp, $order_item_id)) {
             STAdmin::set_message(__('This car is full order', ST_TEXTDOMAIN), 'danger');
             $pass_validate = false;
             return false;
         }
         $data = array('order_item_id' => $order_item_id, 'item_id' => $item_id, 'location_id_pick_up' => $pick_up, 'location_id_drop_off' => $drop_off, 'check_in' => date('Y-m-d', strtotime($check_in)), 'check_out' => date('Y-m-d', strtotime($check_out)), 'check_in_timestamp' => $check_in_timestamp, 'check_out_timestamp' => $check_out_timestamp, 'st_booking_post_type' => 'st_cars', 'st_booking_id' => $item_id, 'check_in_time' => $check_in_time, 'check_out_time' => $check_out_time);
     }
     return $data;
 }
Beispiel #11
0
 static function _holidayValidate($check_in)
 {
     global $wpdb;
     $cant_book = self::_get_holiday_cant_order($check_in);
     $holidays = self::_getAllHolidayID();
     $results = array();
     $today = date('Y-m-d');
     if (is_array($holidays) && count($holidays)) {
         foreach ($holidays as $holiday) {
             $type_holiday = get_post_meta($holiday, 'type_holiday', true);
             $data_holiday = AvailabilityHelper::_getdataHolidayEachDate($holiday, strtotime($check_in), strtotime($check_in));
             $booking_period = intval(get_post_meta($holiday, 'holidays_booking_period', true));
             if (is_array($data_holiday) && count($data_holiday)) {
                 $full = 0;
                 foreach ($data_holiday as $key => $val) {
                     $period = TravelHelper::dateDiff($today, date('Y-m-d', $val->check_in));
                     if ($val->status != 'available' || $period < $booking_period) {
                         $full += 1;
                     }
                 }
                 if ($full == count($data_holiday)) {
                     $results[] = $holiday;
                 }
             } else {
                 if ($type_holiday != 'daily_holiday') {
                     $results[] = $holiday;
                 }
             }
         }
     }
     if (count($results)) {
         $cant_book = array_unique(array_merge($cant_book, $results));
     }
     return $cant_book;
 }
Beispiel #12
0
 static function _tourValidate($check_in)
 {
     global $wpdb;
     $cant_book = self::_get_tour_cant_order($check_in);
     $tours = self::_getAllTourID();
     $results = array();
     $today = date('Y-m-d');
     if (is_array($tours) && count($tours)) {
         foreach ($tours as $tour) {
             $type_tour = get_post_meta($tour, 'type_tour', true);
             $data_tour = AvailabilityHelper::_getdataTourEachDate($tour, strtotime($check_in), strtotime($check_in));
             $booking_period = intval(get_post_meta($tour, 'tours_booking_period', true));
             if (is_array($data_tour) && count($data_tour)) {
                 $full = 0;
                 foreach ($data_tour as $key => $val) {
                     $period = TravelHelper::dateDiff($today, date('Y-m-d', $val->check_in));
                     if ($val->status != 'available' || $period < $booking_period) {
                         $full += 1;
                     }
                 }
                 if ($full == count($data_tour)) {
                     $results[] = $tour;
                 }
             } else {
                 if ($type_tour != 'daily_tour') {
                     $results[] = $tour;
                 }
             }
         }
     }
     if (count($results)) {
         $cant_book = array_unique(array_merge($cant_book, $results));
     }
     return $cant_book;
 }
Beispiel #13
0
                    <?php 
}
?>
                </ul>
                <ul class="booking-item-features booking-item-features-small clearfix">
                    <?php 
get_template_part('single-hotel/room-facility', 'list');
?>

                </ul>
            </div>
            <div class="col-md-3">
                    <?php 
$start = TravelHelper::convertDateFormat(STInput::request('start'));
$end = TravelHelper::convertDateFormat(STInput::request('end'));
$numberday = TravelHelper::dateDiff($start, $end);
$is_search_room = STInput::request('is_search_room');
?>
                    <?php 
if ($start and $end and $is_search_room) {
    ?>
                        <?php 
    $room_id = get_the_ID();
    $room_num_search = intval(STInput::request('room_num_search', 1));
    $sale_price = STPrice::getRoomPrice($room_id, strtotime($start), strtotime($end), $room_num_search);
    $total_price = STPrice::getRoomPriceOnlyCustomPrice($room_id, strtotime($start), strtotime($end), $room_num_search);
    ?>
                        <?php 
    if ($sale_price < $total_price) {
        ?>
                        <span class="text-lg  onsale mr20">
Beispiel #14
0
                            <?php 
        }
        ?>

                            <td class="post-title page-title column-title">
                                <?php 
        $check_in = date(TravelHelper::getDateFormat(), strtotime(get_post_meta($post_id, 'check_in', true)));
        $check_out = date(TravelHelper::getDateFormat(), strtotime(get_post_meta($post_id, 'check_out', true)));
        echo balanceTags($check_in . "<br/>");
        $duration = "";
        if ($type_tour == 'daily_tour') {
            $duration_unit = get_post_meta($item_id, 'duration_unit', true);
            $duration = get_post_meta($post_id, 'duration', true);
            echo __("Duration", ST_TEXTDOMAIN) . ': ' . $duration . ' ' . TravelHelper::get_duration_text($duration_unit, $duration);
        } else {
            $diff = TravelHelper::dateDiff(get_post_meta($post_id, 'check_in', true), get_post_meta($post_id, 'check_out', true));
            if (!empty($diff) and $diff) {
                if ($diff > 1) {
                    $duration .= esc_attr($diff) . " " . __("days", ST_TEXTDOMAIN);
                } else {
                    $duration .= esc_attr($diff) . " " . __("day", ST_TEXTDOMAIN);
                }
            }
            echo __("Duration", ST_TEXTDOMAIN) . ": " . $duration;
        }
        ?>
                            </td>
                            <td class="post-title page-title column-title">
                               <?php 
        $price = get_post_meta($post_id, 'total_price', true);
        $currency = get_post_meta($post_id, 'currency', true);
Beispiel #15
0
 function _get_where_query($where)
 {
     if (!TravelHelper::checkTableDuplicate('st_hotel')) {
         return $where;
     }
     global $wpdb;
     $where .= "";
     if (isset($_REQUEST['location_id']) && !empty($_REQUEST['location_id'])) {
         $location_id = STInput::request('location_id', '');
         $list = TravelHelper::getLocationByParent($location_id);
         if (is_array($list) && count($list)) {
             $where .= " AND (";
             $where_tmp = "";
             foreach ($list as $item) {
                 if (empty($where_tmp)) {
                     $where_tmp .= "tb.multi_location LIKE '%_{$item}_%'";
                 } else {
                     $where_tmp .= " OR tb.multi_location LIKE '%_{$item}_%'";
                 }
             }
             $list = implode(',', $list);
             $where_tmp .= " OR tb.id_location IN ({$list})";
             $where .= $where_tmp . ")";
         } else {
             $where .= " AND (tb.multi_location LIKE '%_{$location_id}_%' OR tb.id_location IN ('{$location_id}')) ";
         }
     } else {
         if (!empty($_REQUEST['location_name'])) {
             $location_name = STInput::request('location_name', '');
             $ids_location = TravelerObject::_get_location_by_name($location_name);
             if (is_array($ids_location) && count($ids_location)) {
                 $ids_location_tmp = array();
                 foreach ($ids_location as $item) {
                     $list = TravelHelper::getLocationByParent($item);
                     if (is_array($list) && count($list)) {
                         foreach ($list as $item) {
                             $ids_location_tmp[] = $item;
                         }
                     }
                 }
                 if (count($ids_location_tmp)) {
                     $ids_location = $ids_location_tmp;
                 }
             }
             if (is_array($ids_location) && count($ids_location)) {
                 $where .= " AND ((";
                 $where_tmp = "";
                 foreach ($ids_location as $id) {
                     if (empty($where_tmp)) {
                         $where_tmp .= " tb.multi_location LIKE '%_{$id}_%' ";
                     } else {
                         $where_tmp .= " OR tb.multi_location LIKE '%_{$id}_%' ";
                     }
                 }
                 $ids_location = implode(',', $ids_location);
                 $where_tmp .= " OR (tb.id_location IN ({$ids_location})";
                 $where .= $where_tmp . ")";
                 $where .= " OR (tb.address LIKE '%{$location_name}%'";
                 $where .= " OR {$wpdb->prefix}posts.post_title LIKE '%{$location_name}%')))";
             } else {
                 if (!empty($_REQUEST['search_all'])) {
                     $where .= " AND (tb.address LIKE '%{$location_name}%'";
                     $where .= " OR {$wpdb->prefix}posts.post_title LIKE '%{$location_name}%')";
                 }
             }
         } elseif (isset($_REQUEST['address']) && !empty($_REQUEST['address'])) {
             $address = STInput::request('address', '');
             $value = STInput::request('address');
             $value = explode(",", $value);
             if (!empty($value[0]) and !empty($value[2])) {
                 $where .= " AND ( tb.address LIKE '%{$value[0]}%' OR tb.address LIKE '%{$value[2]}%')";
             } else {
                 $where .= " AND ( tb.address LIKE '%{$address}%')";
             }
         }
     }
     if (isset($_GET['start']) && !empty($_GET['start']) && isset($_GET['end']) && !empty($_GET['end'])) {
         $check_in = date('Y-m-d', strtotime(TravelHelper::convertDateFormat($_GET['start'])));
         $check_out = date('Y-m-d', strtotime(TravelHelper::convertDateFormat($_GET['end'])));
         $today = date('m/d/Y');
         $period = TravelHelper::dateDiff($today, $check_in);
         $adult_number = STInput::get('adult_number', 0);
         if (intval($adult_number) < 0) {
             $adult_number = 0;
         }
         $children_number = STInput::get('children_num', 0);
         if (intval($children_number) < 0) {
             $children_number = 0;
         }
         $number_room = STInput::get('room_num_search', 0);
         if (intval($number_room) < 0) {
             $number_room = 0;
         }
         $list_hotel = HotelHelper::_hotelValidate($check_in, $check_out, $adult_number, $children_number, $number_room);
         if (!is_array($list_hotel) || count($list_hotel) <= 0) {
             $list_hotel = "''";
         } else {
             $list_hotel = implode(',', $list_hotel);
         }
         $where .= " AND {$wpdb->prefix}posts.ID NOT IN ({$list_hotel}) AND CAST(tb.hotel_booking_period AS UNSIGNED) <= {$period}";
     }
     if (isset($_REQUEST['star_rate']) && !empty($_REQUEST['star_rate'])) {
         $stars = STInput::get('star_rate', 1);
         $stars = explode(',', $stars);
         $all_star = array();
         if (!empty($stars) && is_array($stars)) {
             foreach ($stars as $val) {
                 for ($i = $val; $i < $val + 0.9; $i += 0.1) {
                     if ($i) {
                         $all_star[] = $i;
                     }
                 }
             }
         }
         $list_star = implode(',', $all_star);
         if ($list_star) {
             $where .= " AND (tb.rate_review IN ({$list_star}))";
         }
     }
     if (isset($_REQUEST['hotel_rate']) && !empty($_REQUEST['hotel_rate'])) {
         $hotel_rate = STInput::get('hotel_rate', '');
         $where .= " AND (tb.hotel_star IN ({$hotel_rate}))";
     }
     if (isset($_REQUEST['price_range']) && !empty($_REQUEST['price_range'])) {
         $price = STInput::get('price_range', '0;0');
         $priceobj = explode(';', $price);
         // convert to default money
         $priceobj[0] = TravelHelper::convert_money_to_default($priceobj[0]);
         $priceobj[1] = TravelHelper::convert_money_to_default($priceobj[1]);
         $where .= " AND (tb.price_avg >= {$priceobj[0]})";
         if (isset($priceobj[1])) {
             $priceobj[1] = TravelHelper::convert_money_to_default($priceobj[1]);
             $where .= " AND (tb.price_avg <= {$priceobj[1]})";
         }
     }
     if (isset($_REQUEST['range']) and isset($_REQUEST['location_id'])) {
         $range = STInput::request('range', '5');
         $location_id = STInput::request('location_id');
         $post_type = get_query_var('post_type');
         $map_lat = (double) get_post_meta($location_id, 'map_lat', true);
         $map_lng = (double) get_post_meta($location_id, 'map_lng', true);
         global $wpdb;
         $where .= "\r\n                AND {$wpdb->posts}.ID IN (\r\n                        SELECT ID FROM (\r\n                            SELECT {$wpdb->posts}.*,( 6371 * acos( cos( radians({$map_lat}) ) * cos( radians( mt1.meta_value ) ) *\r\n                                            cos( radians( mt2.meta_value ) - radians({$map_lng}) ) + sin( radians({$map_lat}) ) *\r\n                                            sin( radians( mt1.meta_value ) ) ) ) AS distance\r\n                                                FROM {$wpdb->posts}, {$wpdb->postmeta} as mt1,{$wpdb->postmeta} as mt2\r\n                                                WHERE {$wpdb->posts}.ID = mt1.post_id\r\n                                                and {$wpdb->posts}.ID=mt2.post_id\r\n                                                AND mt1.meta_key = 'map_lat'\r\n                                                and mt2.meta_key = 'map_lng'\r\n                                                AND {$wpdb->posts}.post_status = 'publish'\r\n                                                AND {$wpdb->posts}.post_type = '{$post_type}'\r\n                                                AND {$wpdb->posts}.post_date < NOW()\r\n                                                GROUP BY {$wpdb->posts}.ID HAVING distance<{$range}\r\n                                                ORDER BY distance ASC\r\n                        ) as st_data\r\n\t            )";
     }
     if (!empty($_REQUEST['taxonomy_hotel_room'])) {
         $tax = STInput::request('taxonomy_hotel_room');
         if (!empty($tax) and is_array($tax)) {
             $tax_query = array();
             foreach ($tax as $key => $value) {
                 if ($value) {
                     $ids = "";
                     $ids_tmp = explode(',', $value);
                     if (!empty($ids_tmp)) {
                         foreach ($ids_tmp as $k => $v) {
                             if (!empty($v)) {
                                 $ids[] = $v;
                             }
                         }
                     }
                     if (!empty($ids)) {
                         $tax_query[] = array('taxonomy' => $key, 'terms' => $ids);
                     }
                 }
             }
             $where_room = '';
             if (!empty($tax_query)) {
                 $where_room = ' AND (';
                 foreach ($tax_query as $k => $v) {
                     $ids = implode(',', $v['terms']);
                     if ($k > 0) {
                         $where_room .= " AND ";
                     }
                     $where_room .= "  (\r\n                                                    SELECT COUNT(1)\r\n                                                    FROM wp_term_relationships\r\n                                                    WHERE term_taxonomy_id IN ({$ids})\r\n                                                    AND object_id = wp_posts.ID\r\n                                                  ) = " . count($v['terms']) . "  ";
                 }
                 $where_room .= " ) ";
             }
             $where .= " AND {$wpdb->posts}.ID IN\r\n                        (\r\n                           SELECT ID FROM\r\n                           (\r\n                              SELECT meta1.meta_value as ID\r\n                                    FROM {$wpdb->prefix}posts\r\n\r\n                                    INNER JOIN {$wpdb->prefix}postmeta as meta1 ON wp_posts.ID = meta1.post_id and meta1.meta_key='room_parent'\r\n                                    WHERE 1=1\r\n                                    {$where_room}\r\n                                    AND {$wpdb->prefix}posts.post_type = 'hotel_room'\r\n                                    GROUP BY meta1.meta_value\r\n                           ) as ids\r\n                        ) ";
         }
     }
     if (isset($_REQUEST['item_id']) and !empty($_REQUEST['item_id'])) {
         $item_id = STInput::request('item_id', '');
         $where .= " AND ({$wpdb->prefix}posts.ID = '{$item_id}')";
     }
     return $where;
 }
 public function _check_validate()
 {
     $data = array();
     $order_item_id = STInput::request('order_item_id', '');
     $st_first_name = STInput::request('st_first_name', '');
     if (empty($st_first_name)) {
         STAdmin::set_message(__('The firstname field is not empty.', ST_TEXTDOMAIN), 'danger');
         return false;
     }
     $st_last_name = STInput::request('st_last_name', '');
     if (empty($st_last_name)) {
         STAdmin::set_message(__('The lastname field is not empty.', ST_TEXTDOMAIN), 'danger');
         return false;
     }
     $st_email = STInput::request('st_email', '');
     if (empty($st_email)) {
         STAdmin::set_message(__('The email field is not empty.', ST_TEXTDOMAIN), 'danger');
         return false;
     }
     $st_phone = STInput::request('st_phone', '');
     if (empty($st_phone)) {
         STAdmin::set_message(__('The phone field is not empty.', ST_TEXTDOMAIN), 'danger');
         return false;
     }
     if (STInput::request('section', '') != 'edit_order_item') {
         $item_id = intval(STInput::request('item_id', ''));
         if ($item_id <= 0 || get_post_type($item_id) != 'st_rental') {
             STAdmin::set_message(__('The rental field is not empty.', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         $check_in = STInput::request('check_in', '');
         if (empty($check_in)) {
             STAdmin::set_message(__('Date is invalid', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         $check_out = STInput::request('check_out', '');
         if (empty($check_out)) {
             STAdmin::set_message(__('Date is invalid', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         if (STInput::request('adult_number', '') == "") {
             STAdmin::set_message(__('The No. adults field is not empty', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         $adult_number = intval(STInput::request('adult_number', ''));
         if ($adult_number <= 0) {
             $adult_number = 1;
         }
         if (STInput::request('child_number', '') == "") {
             STAdmin::set_message(__('The No. children field is not empty', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         $child_number = intval(STInput::request('child_number', ''));
         if ($child_number <= 0) {
             $child_number = 0;
         }
         if (strtotime($check_out) - strtotime($check_in) <= 0) {
             STAdmin::set_message(__('The check-out is later than the check-in.', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         $adult = intval(get_post_meta($item_id, 'rental_max_adult', true));
         $children = intval(get_post_meta($item_id, 'rental_max_children', true));
         if ($adult_number > $adult) {
             STAdmin::set_message(__('Number of adults in the room are incorrect.', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         if ($child_number > $children) {
             STAdmin::set_message(__('Number of children in the room are incorrect.', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         $today = date('m/d/Y');
         $period = TravelHelper::dateDiff($today, $check_in);
         $compare = TravelHelper::dateCompare($today, $check_in);
         $booking_period = get_post_meta($item_id, 'rentals_booking_period', true);
         if (empty($booking_period) || $booking_period <= 0) {
             $booking_period = 0;
         }
         if ($compare < 0) {
             STAdmin::set_message(__('You can not set check-in date in the past', ST_TEXTDOMAIN), 'danger');
             return false;
         }
         if ($period < $booking_period) {
             STAdmin::set_message(sprintf(__('This rental allow minimum booking is %d day(s)', ST_TEXTDOMAIN), $booking_period), 'danger');
             return false;
         }
         $checkin_ymd = date('Y-m-d', strtotime($check_in));
         $checkout_ymd = date('Y-m-d', strtotime($check_out));
         if (!RentalHelper::check_day_cant_order($item_id, $checkin_ymd, $checkout_ymd, 1)) {
             STAdmin::set_message(sprintf(__('This rental is not available from %s to %s.', ST_TEXTDOMAIN), $checkin_ymd, $checkout_ymd), 'danger');
             $pass_validate = FALSE;
             return false;
         }
         if (!RentalHelper::_check_room_available($item_id, $checkin_ymd, $checkout_ymd, 1)) {
             STAdmin::set_message(__('This rental is not available.', ST_TEXTDOMAIN), 'danger');
             $pass_validate = FALSE;
             return false;
         }
         $data = array('order_item_id' => $order_item_id, 'item_id' => $item_id, 'type' => 'normal_booking', 'check_in' => $check_in, 'check_out' => $check_out, 'st_booking_post_type' => 'st_rental', 'st_booking_id' => $item_id, 'adult_number' => $adult_number, 'child_number' => $child_number, 'room_num_search' => 1, 'check_in_timestamp' => strtotime($check_in), 'check_out_timestamp' => strtotime($check_out), 'status' => $_POST['status']);
     }
     return $data;
 }
Beispiel #17
0
 function _get_where_query($where)
 {
     if (!TravelHelper::checkTableDuplicate('st_cars')) {
         return $where;
     }
     global $wpdb;
     if (!empty($_REQUEST['location_id_pick_up']) or !empty($_REQUEST['location_id'])) {
         $location_id = intval(STInput::get('location_id_pick_up', ''));
         if (empty($location_id)) {
             $location_id = STInput::request('location_id');
         }
         $list = TravelHelper::getLocationByParent($location_id);
         if (is_array($list) && count($list)) {
             $where .= " AND (";
             $where_tmp = "";
             foreach ($list as $item) {
                 if (empty($where_tmp)) {
                     $where_tmp .= "tb.multi_location LIKE '%_{$item}_%'";
                 } else {
                     $where_tmp .= " OR tb.multi_location LIKE '%_{$item}_%'";
                 }
             }
             $list = implode(',', $list);
             $where_tmp .= " OR tb.id_location IN ({$list})";
             $where .= $where_tmp . ")";
         } else {
             $where .= " AND (tb.multi_location LIKE '%_{$location_id}_%' OR tb.id_location IN ('{$location_id}')) ";
         }
     } elseif (!empty($_REQUEST['pick-up']) or !empty($_REQUEST['location_name'])) {
         $location_name = STInput::request('pick-up', '');
         if (empty($location_name)) {
             $location_name = STInput::request('location_name');
         }
         $ids_location = TravelerObject::_get_location_by_name($location_name);
         if (is_array($ids_location) && count($ids_location)) {
             $ids_location_tmp = array();
             foreach ($ids_location as $item) {
                 $list = TravelHelper::getLocationByParent($item);
                 if (is_array($list) && count($list)) {
                     foreach ($list as $item) {
                         $ids_location_tmp[] = $item;
                     }
                 }
             }
             if (count($ids_location_tmp)) {
                 $ids_location = $ids_location_tmp;
             }
         }
         if (!empty($ids_location)) {
             $where .= " AND ((";
             $where_tmp = "";
             foreach ($ids_location as $item) {
                 if (empty($where_tmp)) {
                     $where_tmp .= "tb.multi_location LIKE '%_{$item}_%'";
                 } else {
                     $where_tmp .= " OR tb.multi_location LIKE '%_{$item}_%'";
                 }
             }
             $ids_location = implode(',', $ids_location);
             $where_tmp .= " OR tb.id_location IN ({$ids_location})";
             $where .= $where_tmp . ")";
             $where .= " OR (tb.cars_address LIKE '%{$location_name}%'";
             $where .= " OR {$wpdb->prefix}posts.post_title LIKE '%{$location_name}%'))";
         } else {
             if (!empty($_REQUEST['search_all'])) {
                 $where .= " AND (tb.cars_address LIKE '%{$location_name}%'";
                 $where .= " OR {$wpdb->prefix}posts.post_title LIKE '%{$location_name}%')";
             }
         }
     }
     if (isset($_REQUEST['price_range'])) {
         $price = STInput::get('price_range', '0;0');
         $priceobj = explode(';', $price);
         $priceobj[0] = TravelHelper::convert_money_to_default($priceobj[0]);
         $priceobj[1] = TravelHelper::convert_money_to_default($priceobj[1]);
         $where .= " AND (tb.sale_price >= {$priceobj[0]})";
         if (isset($priceobj[1])) {
             $priceobj[1] = TravelHelper::convert_money_to_default($priceobj[1]);
             $where .= " AND (tb.sale_price <= {$priceobj[1]})";
         }
     }
     if (isset($_REQUEST['pick-up-date']) && isset($_REQUEST['drop-off-date']) && !empty($_REQUEST['pick-up-date']) && !empty($_REQUEST['drop-off-date'])) {
         $pick_up_date = TravelHelper::convertDateFormat(STInput::request('pick-up-date'));
         $drop_off_date = TravelHelper::convertDateFormat(STInput::request('drop-off-date'));
         $pick_up_time = "";
         $drop_off_time = "";
         if (isset($_REQUEST['pick-up-time']) && !empty($_REQUEST['pick-up-time'])) {
             $pick_up_time = STInput::request('pick-up-time', '12:00 PM');
         }
         if (isset($_REQUEST['drop-off-time']) && !empty($_REQUEST['drop-off-time'])) {
             $drop_off_time = STInput::request('drop-off-time', '12:00 PM');
         }
         $check_in = $pick_up_date . ' ' . $pick_up_time;
         $check_in = strtotime($check_in);
         $check_out = $drop_off_date . ' ' . $drop_off_time;
         $check_out = strtotime($check_out);
         $list_date = CarHelper::_get_car_cant_order($check_in, $check_out);
         $where .= " AND ({$wpdb->posts}.ID NOT IN ({$list_date}))";
         $today = date('Y-m-d');
         $check_in = date('Y-m-d', $check_in);
         $period = TravelHelper::dateDiff($today, $check_in);
         $where .= " AND (CAST(tb.cars_booking_period AS UNSIGNED) <= {$period})";
     }
     if (isset($_REQUEST['item_id']) and !empty($_REQUEST['item_id'])) {
         $item_id = STInput::request('item_id', '');
         $where .= " AND ({$wpdb->prefix}posts.ID = '{$item_id}')";
     }
     if (isset($_REQUEST['location_id'])) {
         $table = $wpdb->prefix . 'st_cars';
         $id = STInput::request('location_id', '');
         $where .= " AND (\r\n                    tb.multi_location LIKE '%_{$id}_%'\r\n                    or tb.id_location = '{$id}'\r\n                    )";
     }
     if (isset($_REQUEST['range']) and isset($_REQUEST['location_id_pick_up'])) {
         $range = STInput::request('range', '5');
         $location_id = STInput::request('location_id_pick_up');
         $post_type = get_query_var('post_type');
         $map_lat = (double) get_post_meta($location_id, 'map_lat', true);
         $map_lng = (double) get_post_meta($location_id, 'map_lng', true);
         global $wpdb;
         $where .= "\r\n                AND {$wpdb->posts}.ID IN (\r\n                        SELECT ID FROM (\r\n                            SELECT {$wpdb->posts}.*,( 6371 * acos( cos( radians({$map_lat}) ) * cos( radians( mt1.meta_value ) ) *\r\n                                            cos( radians( mt2.meta_value ) - radians({$map_lng}) ) + sin( radians({$map_lat}) ) *\r\n                                            sin( radians( mt1.meta_value ) ) ) ) AS distance\r\n                                                FROM {$wpdb->posts}, {$wpdb->postmeta} as mt1,{$wpdb->postmeta} as mt2\r\n                                                WHERE {$wpdb->posts}.ID = mt1.post_id\r\n                                                and {$wpdb->posts}.ID=mt2.post_id\r\n                                                AND mt1.meta_key = 'map_lat'\r\n                                                and mt2.meta_key = 'map_lng'\r\n                                                AND {$wpdb->posts}.post_status = 'publish'\r\n                                                AND {$wpdb->posts}.post_type = '{$post_type}'\r\n                                                AND {$wpdb->posts}.post_date < NOW()\r\n                                                GROUP BY {$wpdb->posts}.ID HAVING distance<{$range}\r\n                                                ORDER BY distance ASC\r\n                        ) as st_data\r\n\t            )";
     }
     return $where;
 }