示例#1
0
 static function _get_car_cant_order_by_id($car_id, $check_in, $check_out, $order_item_id = '')
 {
     if (!TravelHelper::checkTableDuplicate('st_cars')) {
         return true;
     }
     global $wpdb;
     $string = "";
     if (!empty($order_item_id)) {
         $string = " AND order_item_id NOT IN ('{$order_item_id}') ";
     }
     $sql = "SELECT\r\n\t\t\tst_booking_id as car_id,\r\n\t\t\tmt.meta_value as number_car,\r\n\t\t\tmt.meta_value - COUNT(st_booking_id) as car_free\r\n\t\t\tFROM {$wpdb->prefix}st_order_item_meta\r\n\t\t\tINNER JOIN {$wpdb->prefix}postmeta as mt ON mt.post_id = st_booking_id AND mt.meta_key = 'number_car'\r\n\t\t\tWHERE\r\n\t\t\tst_booking_post_type = 'st_cars'\r\n\t\t\tAND status NOT IN ('trash', 'canceled')\r\n\t\t\tAND st_booking_id = '{$car_id}'\r\n\t\t\tAND (\r\n\t\t\t\t({$check_in} < check_in_timestamp AND {$check_out} > check_out_timestamp)\r\n\t\t\t\tOR(\r\n\t\t\t\t{$check_in} BETWEEN check_in_timestamp AND check_out_timestamp\r\n\t\t\t)\r\n\t\t\t\tOR(\r\n\t\t\t\t{$check_out} BETWEEN check_in_timestamp AND check_out_timestamp\r\n\t\t\t)\r\n\t\t\t)\r\n\t\t\t{$string}\r\n\t\t\tGROUP BY st_booking_id\r\n\t\t\tHAVING (mt.meta_value - COUNT(st_booking_id) <= 0)";
     $result = $wpdb->get_results($sql, ARRAY_A);
     if (is_array($result) && count($result)) {
         return false;
     }
     return true;
 }
 public function _save_post($id)
 {
     if (!TravelHelper::checkTableDuplicate('st_hotel')) {
         return;
     }
     if (isset($_GET['post_type']) && $_GET['post_type'] == 'st_hotel' && isset($_GET['section']) && $_GET['section'] == 'edit_order_item' && isset($_GET['order_item_id'])) {
         $item_id = $_GET['order_item_id'];
         $status = $_POST['status'];
         if ($status == 'canceled') {
             $status = 'trash';
         }
         global $wpdb;
         $table = $wpdb->prefix . 'st_order_item_meta';
         $data = array('status' => $status);
         $where = array('order_item_id' => $item_id);
         $rs = $wpdb->update($table, $data, $where);
     }
 }
示例#3
0
 function _get_where_query($where)
 {
     if (!TravelHelper::checkTableDuplicate('st_holidays')) {
         return $where;
     }
     global $wpdb;
     if (isset($_REQUEST['location_id']) && !empty($_REQUEST['location_id'])) {
         $location_id = STInput::get('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 (isset($_REQUEST['location_name']) && !empty($_REQUEST['location_name'])) {
         $location_name = STInput::get('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 $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.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($_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['item_name']) and !empty($_REQUEST['item_name'])) {
         $item_name = STInput::request('item_name', '');
         $where .= " AND ({$wpdb->prefix}posts.post_title LIKE '%{$item_name}%')";
     }
     if (isset($_REQUEST['people']) && !empty($_REQUEST['people'])) {
         $people = STInput::get('people', 1);
         $where .= " AND (tb.max_people >= {$people})";
     }
     if (isset($_REQUEST['duration']) && !empty($_REQUEST['duration'])) {
         $duration = intval(STInput::get('duration', 1));
         $today = time();
         $where .= "AND (\r\n                        (\r\n                            tb.duration_day = {$duration}\r\n                            AND tb.type_holiday = 'daily_holiday'\r\n                        )\r\n                    )";
         /*$where .= "AND (
               (
                   tb.duration_day >= {$duration}
                   AND tb.type_holiday = 'daily_holiday'
               )
               OR (
                   (
                      (UNIX_TIMESTAMP(STR_TO_DATE(tb.check_out, '%Y-%m-%d')) - UNIX_TIMESTAMP(STR_TO_DATE(tb.check_in, '%Y-%m-%d'))) / (60*60*24) + 1
                   ) >= {$duration}
               )
           )";*/
     }
     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]);
         $min_range = $priceobj[0];
         $max_range = $priceobj[1];
         /*$where .= " AND (
               (CAST(tb.child_price AS DECIMAL) >= {$min_range} and CAST(tb.child_price AS DECIMAL) <= {$max_range})
               OR (CAST(tb.adult_price AS DECIMAL) >= {$min_range} and CAST(tb.adult_price AS DECIMAL) <= {$max_range})
           ) ";*/
         $where .= " AND ( \r\n                        (CAST(tb.adult_price AS DECIMAL) >= {$min_range} and CAST(tb.adult_price AS DECIMAL) <= {$max_range})\r\n                    ) ";
     }
     $start = STInput::request("start");
     $end = STInput::request("end");
     if (!empty($start) && !empty($end)) {
         $today = date('Y-m-d');
         $check_in = date('Y-m-d', strtotime(TravelHelper::convertDateFormat(STInput::request("start"))));
         $period = TravelHelper::dateDiff($today, $check_in);
         if ($period < 0) {
             $period = 0;
         }
         $check_out = date('Y-m-d', strtotime(TravelHelper::convertDateFormat(STInput::request("end"))));
         $list_date = HolidayHelper::_holidayValidate($check_in);
         if (is_array($list_date) && count($list_date)) {
             $list = implode(',', $list_date);
         } else {
             $list = "''";
         }
         $where .= " AND {$wpdb->posts}.ID NOT IN ({$list})";
         /* $where .= " AND (
            (
                tb.type_holiday = 'specific_date'
                AND (
                    UNIX_TIMESTAMP(
                        STR_TO_DATE(tb.check_in, '%Y-%m-%d')
                    ) - UNIX_TIMESTAMP(
                        STR_TO_DATE('{$check_in}', '%Y-%m-%d')
                    ) <= 0
                )
                AND (
                    UNIX_TIMESTAMP(
                        STR_TO_DATE(tb.check_out, '%Y-%m-%d')
                    ) - UNIX_TIMESTAMP(
                        STR_TO_DATE('{$check_out}', '%Y-%m-%d')
                    ) >= 0
                )
            )
            OR (
                tb.type_holiday = 'daily_holiday'
                AND (tb.holidays_booking_period <= {$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['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                    )";
     }
     return $where;
 }
示例#4
0
 function _update_duplicate_data($id, $data)
 {
     if (!TravelHelper::checkTableDuplicate('st_hotel')) {
         return;
     }
     if (get_post_type($id) == 'hotel_room') {
         $hotel_id = get_post_meta($id, 'room_parent', true);
         $price_avg = get_post_meta($hotel_id, 'price_avg', true);
         if (!$price_avg) {
             return;
         }
         $data = array('multi_location' => get_post_meta($hotel_id, 'multi_location', true), 'id_location' => get_post_meta($hotel_id, 'id_location', true), 'address' => get_post_meta($hotel_id, 'address', true), 'rate_review' => get_post_meta($hotel_id, 'rate_review', true), 'hotel_star' => get_post_meta($hotel_id, 'hotel_star', true), 'price_avg' => $price_avg, 'hotel_booking_period' => get_post_meta($hotel_id, 'hotel_booking_period', true), 'map_lat' => get_post_meta($hotel_id, 'map_lat', true), 'map_lng' => get_post_meta($hotel_id, 'map_lng', true));
         $where = array('post_id' => $hotel_id);
         TravelHelper::updateDuplicate('st_hotel', $data, $where);
     }
 }
示例#5
0
 /**
  * @update 1.1.8
  */
 function _get_where_query_tab_location($where)
 {
     // if in location tab location id = get_the_ID();
     $location_id = get_the_ID();
     if (!TravelHelper::checkTableDuplicate('st_activity')) {
         return $where;
     }
     $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}')) ";
     }
     return $where;
 }
示例#6
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;
 }
示例#7
0
 static function get_min_max_price($post_type = 'st_hotel')
 {
     if (empty($post_type) || !TravelHelper::checkTableDuplicate($post_type)) {
         return array('price_min' => 0, 'price_max' => 500);
     }
     global $wpdb;
     $sql = "\r\n                select \r\n                    min(CAST(price_avg as DECIMAL)) as min,\r\n                    max(CAST(price_avg as DECIMAL)) as max\r\n                from {$wpdb->prefix}st_hotel";
     $results = $wpdb->get_results($sql, OBJECT);
     $price_min = $results[0]->min;
     $price_max = $results[0]->max;
     if (empty($price_min)) {
         $price_min = 0;
     }
     if (empty($price_max)) {
         $price_max = 500;
     }
     return array('min' => ceil($price_min), 'max' => ceil($price_max));
 }
示例#8
0
            } else {
                //$link = home_url(esc_url('?s=&post_type=st_hotel&location_id='.get_the_ID()));
                //$link = home_url(esc_url('?s=&post_type=st_holidays&location_id='.get_the_ID()."&pick-up=".get_the_title()));
                $link = add_query_arg(array('s' => '', 'post_type' => 'st_holidays', 'location_id' => get_the_ID(), 'pick-up' => get_the_title()), home_url('/'));
            }
            if ($offer <= 1) {
                $offer_string = sprintf(__('%d Holiday from %s', ST_TEXTDOMAIN), $offer, $min_price);
            } else {
                $offer_string = sprintf(__('%d Holidays from %s', ST_TEXTDOMAIN), $offer, $min_price);
            }
            echo '<li><a href="' . $link . '"><i class="fa fa-bolt"></i> ' . $offer_string . '</a></li>';
        }
    }
}
$activity = new STActivity();
if ($activity->is_available() && TravelHelper::checkTableDuplicate('st_activity')) {
    $info = new STLocation();
    $info = $info->get_info_by_post_type(get_the_ID(), 'st_activity');
    $min_price = $info['min_max_price']['price_min'];
    $min_price = TravelHelper::format_money($min_price);
    if (empty($min_price) or !$min_price) {
        $min_price = __("Free", ST_TEXTDOMAIN);
    }
    if (is_array($info) && count($info)) {
        $offer = $info['offers'];
        if (!empty($offer)) {
            $page_search = st_get_page_search_result('st_activity');
            if (!empty($page_search) and get_post_type($page_search) == 'page') {
                //$link = add_query_arg(array('location_id'=>get_the_ID()),get_the_permalink($page_search));
                $link = add_query_arg(array('location_id' => get_the_ID(), 'pick-up' => get_the_title()), get_the_permalink($page_search));
            } else {
示例#9
0
 static function _get_query_join($join)
 {
     $st_type = $_SESSION['el_st_type'];
     if (!TravelHelper::checkTableDuplicate($st_type)) {
         return $join;
     }
     global $wpdb;
     $table = $wpdb->prefix . $st_type;
     $join .= " INNER JOIN {$table} as tb ON {$wpdb->prefix}posts.ID = tb.post_id";
     return $join;
 }
示例#10
0
 static function get_min_max_price($post_type)
 {
     if (empty($post_type) || !TravelHelper::checkTableDuplicate($post_type)) {
         return array('price_min' => 0, 'price_max' => 500);
     }
     $meta_key = 'sale_price';
     if ($post_type == 'st_hotel') {
         $meta_key = 'price_avg';
     }
     $location_text = "id_location";
     if ($post_type == 'st_rental') {
         $location_text = 'location_id';
     }
     global $wpdb;
     $sql = "\r\n            select \r\n                min(CAST({$meta_key} as DECIMAL)) as min,\r\n                max(CAST({$meta_key} as DECIMAL)) as max";
     if ($post_type == 'st_tours' || $post_type == 'st_holidays' || $post_type == 'st_activity') {
         /*$sql = "
           select 
               min(CAST(child_price as Decimal)) , 
               min(CAST(adult_price as Decimal)), 
               max(CAST(child_price as Decimal)) , 
               max(CAST(adult_price as Decimal)) 
           " ;*/
         $sql = "\r\n            select \r\n                min(CAST(adult_price as Decimal)), \r\n                max(CAST(adult_price as Decimal)) \r\n            ";
     }
     $sql .= " from {$wpdb->prefix}{$post_type} ";
     $join = "";
     $where = "";
     $join .= " join {$wpdb->posts} on {$wpdb->posts}.ID = {$wpdb->prefix}{$post_type}.post_id ";
     $join = STLocation::edit_join_wpml($join, $post_type);
     $sql .= $join;
     $where = " where (1=1 ) ";
     $where .= "and \r\n                (\r\n                    {$wpdb->posts}.post_status = 'publish'\r\n                )\r\n                    ";
     $where = STLocation::edit_where_wpml($where);
     $sql .= $where;
     //echo $sql;
     $results = $wpdb->get_results($sql, OBJECT);
     $array_price = array();
     if ($post_type == 'st_tours' || $post_type == 'st_holidays' || $post_type == 'st_activity') {
         foreach ($results[0] as $key => $value) {
             $array_price[] = $value;
         }
         $price_min = min($array_price);
         $price_max = max($array_price);
     } else {
         $price_min = $results[0]->min;
         $price_max = $results[0]->max;
     }
     if (!$price_max) {
         $price_max = 500;
     }
     // default 0 500
     return array('price_min' => ceil($price_min), 'price_max' => ceil($price_max));
 }
 static function _get_holiday_cant_order($holiday_id, $check_in)
 {
     if (!TravelHelper::checkTableDuplicate('st_holidays')) {
         return '';
     }
     global $wpdb;
     $sql = "SELECT\r\n\t\t\t\tst_booking_id AS holiday_id,\r\n\t\t\t\tmt.meta_value AS max_people,\r\n\t\t\t\tmt.meta_value - SUM(\r\n\t\t\t\t\tDISTINCT (adult_number + child_number + infant_number)\r\n\t\t\t\t) AS free_people\r\n\t\t\tFROM\r\n\t\t\t\t{$wpdb->prefix}st_order_item_meta\r\n\t\t\tINNER JOIN {$wpdb->prefix}postmeta AS mt ON mt.post_id = st_booking_id\r\n\t\t\tAND mt.meta_key = 'max_people'\r\n\t\t\tWHERE\r\n\t\t\tst_booking_id = '{$holiday_id}'\r\n\t\t\tAND\r\n\t\t\t\tst_booking_post_type = 'st_holidays'\r\n\t\t\tAND (\r\n\t\t\t\tSTR_TO_DATE('{$check_in}', '%m/%d/%Y') = STR_TO_DATE(check_in, '%m/%d/%Y')\r\n\t\t\t)\r\n\t\t\tAND status NOT IN ('trash', 'canceled')\r\n\t\t\tGROUP BY st_booking_id\r\n\t\t\tHAVING\r\n\t\t\tmax_people - SUM(\r\n\t\t\t\t\tDISTINCT (adult_number + child_number + infant_number)\r\n\t\t\t\t) <= 0";
     $result = $wpdb->get_col($sql, 0);
     $list_date = array();
     if (is_array($result) && count($result)) {
         $list_date = $result;
     }
     return $list_date;
 }
示例#12
0
 static function _get_minmax($holiday_id, $year)
 {
     if (!TravelHelper::checkTableDuplicate('st_holidays')) {
         return '';
     }
     // st_holiday
     global $wpdb;
     $sql = "SELECT\r\n\t\t\t\tMIN(check_in_timestamp) AS check_in,\r\n\t\t\t\tMAX(check_out_timestamp) AS check_out\r\n\t\t\tFROM\r\n\t\t\t\t{$wpdb->prefix}st_order_item_meta\r\n\t\t\tINNER JOIN {$wpdb->prefix}st_holidays AS mt ON mt.post_id = st_booking_id\r\n\t\t\tWHERE\r\n\t\t\t\tst_booking_post_type = 'st_holidays'\r\n\t\t\tAND mt.type_holiday = 'daily_holiday'\r\n\t\t\tAND st_booking_id = '{$holiday_id}'\r\n\t\t\tAND YEAR (\r\n\t\t\t\tFROM_UNIXTIME(check_in_timestamp)\r\n\t\t\t) = {$year}\r\n\t\t\tAND YEAR (\r\n\t\t\t\tFROM_UNIXTIME(check_out_timestamp)\r\n\t\t\t) = {$year}\r\n\t\t\tAND status NOT IN ('trash', 'canceled')";
     $min_max = $wpdb->get_row($sql, ARRAY_A);
     return $min_max;
 }
示例#13
0
 static function _get_query_join($join)
 {
     if (!TravelHelper::checkTableDuplicate('st_rental')) {
         return $join;
     }
     global $wpdb;
     $table = $wpdb->prefix . 'st_rental';
     $join .= " INNER JOIN {$table} as tb ON {$wpdb->prefix}posts.ID = tb.post_id";
     return $join;
 }
示例#14
0
 static function _get_query_where($where)
 {
     if (!TravelHelper::checkTableDuplicate('st_holidays')) {
         return $where;
     }
     global $wpdb;
     $only_featured_location = $_SESSION['el_only_featured_location'];
     $st_location = $_SESSION['el_st_location'];
     $featured = $_SESSION['el_featured'];
     if ($only_featured_location == 'yes') {
         if (is_array($featured) && count($featured)) {
             $where .= " AND (";
             $where_tmp = "";
             foreach ($featured as $item) {
                 if (empty($where_tmp)) {
                     $where_tmp .= " tb.multi_location LIKE '%_{$item}_%'";
                 } else {
                     $where_tmp .= " OR tb.multi_location LIKE '%_{$item}_%'";
                 }
             }
             $featured = implode(',', $featured);
             $where_tmp .= " OR tb.id_location IN ({$featured})";
             $where .= $where_tmp . ")";
         }
     } else {
         if (!empty($st_location)) {
             $list = TravelHelper::getLocationByParent($st_location);
             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 '%_{$st_location}_%' OR tb.id_location IN ('{$st_location}')) ";
             }
         }
     }
     return $where;
 }
示例#15
0
 static function _get_query_where($where)
 {
     $post_type = $_SESSION['el_post_type'];
     if (!TravelHelper::checkTableDuplicate($post_type)) {
         return $where;
     }
     global $wpdb;
     $location_field = 'id_location';
     if ($post_type == 'st_rental') {
         $location_field = '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_field} IN ({$list})";
         $where .= $where_tmp . ")";
     } else {
         $where .= " AND (tb.multi_location LIKE '%_{$location_id}_%' OR tb.{$location_field} IN ('{$location_id}')) ";
     }
     return $where;
 }
示例#16
0
 static function _get_disable_date()
 {
     $list_date = array();
     if (!TravelHelper::checkTableDuplicate('st_hotel')) {
         echo json_encode($list_date);
         die;
     }
     $room_id = STInput::request('room_id');
     $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 = STInput::request('year');
     if (empty($year)) {
         $year = date('Y');
     }
     $month = STInput::request('month');
     if (empty($month)) {
         $month = date('m');
     }
     $result = HotelHelper::_get_full_ordered($room_id, $month, $month, $year, $year);
     $number_room = get_post_meta($room_id, 'number_room', true);
     $min_max = HotelHelper::_get_min_max_date_ordered($room_id, $year, $year);
     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, $month, $year, $year);
     if (is_array($list_date_2) && count($list_date_2)) {
         $list_date = array_merge($list_date, $list_date_2);
     }
     echo json_encode($list_date);
     die;
 }
示例#17
0
 function _save_booking($order_id)
 {
     if (!check_admin_referer('shb_action', 'shb_field')) {
         die;
     }
     $data = $this->_check_validate();
     if (is_array($data)) {
         $check_out_field = STCart::get_checkout_fields();
         if (!empty($check_out_field)) {
             foreach ($check_out_field as $field_name => $field_desc) {
                 update_post_meta($order_id, $field_name, STInput::post($field_name));
             }
         }
         $item_data = array('status' => $_POST['status']);
         foreach ($item_data as $val => $value) {
             update_post_meta($order_id, $val, $value);
         }
         if (TravelHelper::checkTableDuplicate('st_rental')) {
             global $wpdb;
             $table = $wpdb->prefix . 'st_order_item_meta';
             $where = array('order_item_id' => $order_id);
             $data = array('status' => $_POST['status']);
             $wpdb->update($table, $data, $where);
         }
         STCart::send_mail_after_booking($order_id, true);
         STCart::send_email_confirm($order_id);
         wp_safe_redirect(self::$booking_page);
     }
 }
示例#18
0
 static function _get_maxmin_by_date($rental_id, $check_in, $check_out)
 {
     if (!TravelHelper::checkTableDuplicate('st_rental')) {
         return '';
     }
     global $wpdb;
     $sql = "SELECT\r\n\t\t\t\t\t\tst_booking_id AS rental_id,\r\n\t\t\t\t\t\tMIN(check_in_timestamp) AS check_in,\r\n\t\t\t\t\t\tMAX(check_out_timestamp) AS check_out\r\n\t\t\t\t\tFROM\r\n\t\t\t\t\t\t{$wpdb->prefix}st_order_item_meta\r\n\t\t\t\t\tINNER JOIN {$wpdb->prefix}postmeta AS mt ON mt.post_id = st_booking_id\r\n\t\t\t\t\tAND mt.meta_key = 'rental_number'\r\n\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t(\r\n\t\t\t\t\t\t\t(\r\n\t\t\t\t\t\t\t\tSTR_TO_DATE('{$check_in}', '%Y-%m-%d') < STR_TO_DATE(check_in, '%m/%d/%Y')\r\n\t\t\t\t\t\t\t\tAND STR_TO_DATE('{$check_out}', '%Y-%m-%d') > STR_TO_DATE(check_out, '%m/%d/%Y')\r\n\t\t\t\t\t\t\t)\r\n\t\t\t\t\t\t\tOR (\r\n\t\t\t\t\t\t\t\tSTR_TO_DATE('{$check_in}', '%Y-%m-%d') BETWEEN STR_TO_DATE(check_in, '%m/%d/%Y')\r\n\t\t\t\t\t\t\t\tAND STR_TO_DATE(check_out, '%m/%d/%Y')\r\n\t\t\t\t\t\t\t)\r\n\t\t\t\t\t\t\tOR (\r\n\t\t\t\t\t\t\t\tSTR_TO_DATE('{$check_out}', '%Y-%m-%d') BETWEEN STR_TO_DATE(check_in, '%m/%d/%Y')\r\n\t\t\t\t\t\t\t\tAND STR_TO_DATE(check_out, '%m/%d/%Y')\r\n\t\t\t\t\t\t\t)\r\n\t\t\t\t\t\t)\r\n\t\t\t\t\tAND st_booking_id = '{$rental_id}'\r\n\t\t\t\t\tAND st_booking_post_type = 'st_rental'\r\n\t\t\t\t\tAND status NOT IN ('trash', 'canceled')";
     $result = $wpdb->get_row($sql, ARRAY_A);
     return $result;
 }