function wpdev_get_bk_listing_structure_engine($args)
{
    global $wpdb;
    $sql_boking_listing = wpdev_sql_get_booking_lising($args);
    $sql_start_count = $sql_boking_listing[0];
    $sql_start_select = $sql_boking_listing[1];
    $sql = $sql_boking_listing[2];
    $sql_where = $sql_boking_listing[3];
    $sql_order = $sql_boking_listing[4];
    $sql_limit = $sql_boking_listing[5];
    $num_per_page_check = get_bk_option('bookings_num_per_page');
    if (empty($num_per_page_check)) {
        $num_per_page_check = '10';
    }
    $defaults = array('wh_booking_type' => '', 'wh_approved' => '', 'wh_booking_id' => '', 'wh_is_new' => '', 'wh_pay_status' => '', 'wh_keyword' => '', 'wh_booking_date' => '', 'wh_booking_date2' => '', 'wh_modification_date' => '', 'wh_modification_date2' => '', 'wh_cost' => '', 'wh_cost2' => '', 'or_sort' => get_bk_option('booking_sort_order'), 'page_num' => '1', 'page_items_count' => $num_per_page_check);
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    $page_start = ($page_num - 1) * $page_items_count;
    // Get Bookings Array
    $bookings_res = $wpdb->get_results($wpdb->prepare($sql_start_select . $sql . $sql_where . $sql_order . $sql_limit));
    // Get Number of booking for the pages
    $bookings_count = $wpdb->get_results($wpdb->prepare($sql_start_count . $sql . $sql_where));
    // Get NUMBER of Bookings
    if (count($bookings_count) > 0) {
        $bookings_count = $bookings_count[0]->count;
    } else {
        $bookings_count = 0;
    }
    // Bookings array init                 - Get the ID list of ALL bookings
    $booking_id_list = array();
    $bookings = array();
    $short_days = array();
    $short_days_type_id = array();
    if (count($bookings_res) > 0) {
        foreach ($bookings_res as $booking) {
            if (!in_array($booking->booking_id, $booking_id_list)) {
                $booking_id_list[] = $booking->booking_id;
            }
            $bookings[$booking->booking_id] = $booking;
            $bookings[$booking->booking_id]->dates = array();
            $bookings[$booking->booking_id]->dates_short = array();
            $bk_list_type = isset($booking->booking_type) ? $booking->booking_type : '1';
            $cont = get_form_content($booking->form, $bk_list_type);
            // $search = REPLACED LINE HERE!!
            $replace = array("  ", "   ", "   ");
            $cont['content'] = preg_replace($search, $replace, $cont['content']);
            $bookings[$booking->booking_id]->form_show = $cont['content'];
            unset($cont['content']);
            $bookings[$booking->booking_id]->form_data = $cont;
        }
    }
    $booking_id_list = implode(",", $booking_id_list);
    if (!empty($booking_id_list)) {
        // Get Dates  for all our Bookings
        $sql = " SELECT *\r\n            FROM " . $wpdb->prefix . "bookingdates as dt\r\n            WHERE dt.booking_id in ( " . $booking_id_list . ") ";
        if (class_exists('wpdev_bk_biz_l')) {
            $sql .= " ORDER BY booking_id, type_id, booking_date   ";
        } else {
            $sql .= " ORDER BY booking_id, booking_date   ";
        }
        $booking_dates = $wpdb->get_results($wpdb->prepare($sql));
    } else {
        $booking_dates = array();
    }
    $last_booking_id = '';
    // Add Dates to Bookings array
    foreach ($booking_dates as $date) {
        $bookings[$date->booking_id]->dates[] = $date;
        if ($date->booking_id != $last_booking_id) {
            if (!empty($last_booking_id)) {
                if ($last_show_day != $dte) {
                    $short_days[] = $dte;
                    $short_days_type_id[] = $last_day_id;
                }
                $bookings[$last_booking_id]->dates_short = $short_days;
                $bookings[$last_booking_id]->dates_short_id = $short_days_type_id;
            }
            $last_day = '';
            $last_day_id = '';
            $last_show_day = '';
            $short_days = array();
            $short_days_type_id = array();
        }
        $last_booking_id = $date->booking_id;
        $dte = $date->booking_date;
        if (empty($last_day)) {
            // First date
            $short_days[] = $dte;
            $short_days_type_id[] = isset($date->type_id) ? $date->type_id : '';
            $last_show_day = $dte;
        } else {
            // All other days
            if (wpdevbk_is_next_day($dte, $last_day)) {
                if ($last_show_day != '-') {
                    $short_days[] = '-';
                    $short_days_type_id[] = '';
                }
                $last_show_day = '-';
            } else {
                if ($last_show_day != $last_day) {
                    $short_days[] = $last_day;
                    $short_days_type_id[] = $last_day_id;
                }
                $short_days[] = ',';
                $short_days_type_id[] = '';
                $short_days[] = $dte;
                $short_days_type_id[] = isset($date->type_id) ? $date->type_id : '';
                $last_show_day = $dte;
            }
        }
        $last_day = $dte;
        $last_day_id = isset($date->type_id) ? $date->type_id : '';
    }
    if (isset($dte)) {
        if ($last_show_day != $dte) {
            $short_days[] = $dte;
            $short_days_type_id[] = isset($date->type_id) ? $date->type_id : '';
        }
    }
    if (isset($bookings[$last_booking_id])) {
        $bookings[$last_booking_id]->dates_short = $short_days;
        $bookings[$last_booking_id]->dates_short_id = $short_days_type_id;
    }
    $booking_types = apply_bk_filter('wpdebk_get_keyed_all_bk_resources', array());
    return array($bookings, $booking_types, $bookings_count, $page_num, $page_items_count);
}
Example #2
0
function wpdev_get_bk_listing_structure_engine($args)
{
    global $wpdb;
    ///debuge($_REQUEST);
    $sql_boking_listing = wpdev_sql_get_booking_lising($args);
    //debuge($sql_boking_listing);
    $sql_start_count = $sql_boking_listing[0];
    $sql_start_select = $sql_boking_listing[1];
    $sql = $sql_boking_listing[2];
    $sql_where = $sql_boking_listing[3];
    $sql_order = $sql_boking_listing[4];
    $sql_limit = $sql_boking_listing[5];
    $num_per_page_check = get_bk_option('bookings_num_per_page');
    if (empty($num_per_page_check)) {
        $num_per_page_check = '10';
    }
    $defaults = array('wh_booking_type' => '', 'wh_approved' => '', 'wh_booking_id' => '', 'wh_is_new' => '', 'wh_pay_status' => '', 'wh_keyword' => '', 'wh_booking_date' => '', 'wh_booking_date2' => '', 'wh_modification_date' => '', 'wh_modification_date2' => '', 'wh_cost' => '', 'wh_cost2' => '', 'or_sort' => get_bk_option('booking_sort_order'), 'page_num' => '1', 'page_items_count' => $num_per_page_check);
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    $page_start = ($page_num - 1) * $page_items_count;
    //debuge($sql_start_select . $sql . $sql_where . $sql_order . $sql_limit);
    //debuge($sql_start_select . $sql . $sql_where . $sql_order . $sql_limit);
    // Get Bookings Array
    $bookings_res = $wpdb->get_results($sql_start_select . $sql . $sql_where . $sql_order . $sql_limit);
    // Get Number of booking for the pages
    $bookings_count = $wpdb->get_results($sql_start_count . $sql . $sql_where);
    // Get NUMBER of Bookings
    if (count($bookings_count) > 0) {
        $bookings_count = $bookings_count[0]->count;
    } else {
        $bookings_count = 0;
    }
    $booking_types = apply_bk_filter('wpdebk_get_keyed_all_bk_resources', array());
    // Bookings array init                 - Get the ID list of ALL bookings
    $booking_id_list = array();
    $bookings = array();
    $short_days = array();
    $short_days_type_id = array();
    if (count($bookings_res) > 0) {
        foreach ($bookings_res as $booking) {
            if (!in_array($booking->booking_id, $booking_id_list)) {
                $booking_id_list[] = $booking->booking_id;
            }
            $bookings[$booking->booking_id] = $booking;
            $bookings[$booking->booking_id]->dates = array();
            $bookings[$booking->booking_id]->dates_short = array();
            $bk_list_type = isset($booking->booking_type) ? $booking->booking_type : '1';
            $cont = get_form_content($booking->form, $bk_list_type, '', array('booking_id' => $booking->booking_id, 'resource_title' => isset($booking_types[$booking->booking_type]) ? $booking_types[$booking->booking_type] : ''));
            $search = array("'(<br[ ]?[/]?>)+'si", "'(<p[ ]?[/]?>)+'si", "'(<div[ ]?[/]?>)+'si");
            $replace = array("&nbsp;&nbsp;", " &nbsp; ", " &nbsp; ");
            $cont['content'] = preg_replace($search, $replace, $cont['content']);
            $bookings[$booking->booking_id]->form_show = $cont['content'];
            unset($cont['content']);
            $bookings[$booking->booking_id]->form_data = $cont;
        }
    }
    $booking_id_list = implode(",", $booking_id_list);
    $booking_id_list = wpbc_clean_string_for_db($booking_id_list);
    if (!empty($booking_id_list)) {
        // Get Dates  for all our Bookings
        $sql = " SELECT *\n            FROM {$wpdb->prefix}bookingdates as dt\n            WHERE dt.booking_id in ( {$booking_id_list} ) ";
        if (class_exists('wpdev_bk_biz_l')) {
            $sql .= " ORDER BY booking_id, type_id, booking_date   ";
        } else {
            $sql .= " ORDER BY booking_id, booking_date   ";
        }
        $booking_dates = $wpdb->get_results($sql);
    } else {
        $booking_dates = array();
    }
    $last_booking_id = '';
    // Add Dates to Bookings array
    foreach ($booking_dates as $date) {
        $bookings[$date->booking_id]->dates[] = $date;
        if ($date->booking_id != $last_booking_id) {
            if (!empty($last_booking_id)) {
                if ($last_show_day != $dte) {
                    $short_days[] = $dte;
                    $short_days_type_id[] = $last_day_id;
                }
                $bookings[$last_booking_id]->dates_short = $short_days;
                $bookings[$last_booking_id]->dates_short_id = $short_days_type_id;
            }
            $last_day = '';
            $last_day_id = '';
            $last_show_day = '';
            $short_days = array();
            $short_days_type_id = array();
        }
        $last_booking_id = $date->booking_id;
        $dte = $date->booking_date;
        if (empty($last_day)) {
            // First date
            $short_days[] = $dte;
            $short_days_type_id[] = isset($date->type_id) ? $date->type_id : '';
            $last_show_day = $dte;
        } else {
            // All other days
            if (wpdevbk_is_next_day($dte, $last_day)) {
                if ($last_show_day != '-') {
                    $short_days[] = '-';
                    $short_days_type_id[] = '';
                }
                $last_show_day = '-';
            } else {
                if ($last_show_day != $last_day) {
                    $short_days[] = $last_day;
                    $short_days_type_id[] = $last_day_id;
                }
                $short_days[] = ',';
                $short_days_type_id[] = '';
                $short_days[] = $dte;
                $short_days_type_id[] = isset($date->type_id) ? $date->type_id : '';
                $last_show_day = $dte;
            }
        }
        $last_day = $dte;
        $last_day_id = isset($date->type_id) ? $date->type_id : '';
    }
    if (isset($dte)) {
        if ($last_show_day != $dte) {
            $short_days[] = $dte;
            $short_days_type_id[] = isset($date->type_id) ? $date->type_id : '';
        }
    }
    if (isset($bookings[$last_booking_id])) {
        $bookings[$last_booking_id]->dates_short = $short_days;
        $bookings[$last_booking_id]->dates_short_id = $short_days_type_id;
    }
    // If we selected the Dates as "Check In - Today/Tommorow", then show only the bookings, where check in date is Today
    if (isset($args['wh_booking_date']) && $args['wh_booking_date'] == '7') {
        //$today_mysql_format = date('Y-m-d');
        $today_mysql_format = date('Y-m-d', time() + 86400);
        //1 Day = 24*60*60 = 86400
        foreach ($bookings as $bc_id => $bc_value) {
            $check_in_date = $bc_value->dates_short[0];
            $check_in_date = explode(' ', $check_in_date);
            $check_in_date = $check_in_date[0];
            // 2014-02-25
            if ($today_mysql_format != $check_in_date) {
                unset($bookings[$bc_id]);
                $bookings_count--;
            }
        }
    }
    // If we selected the Dates as "Check Out - Tomorow", then show only the bookings, where check out date is Tomorrow
    if (isset($args['wh_booking_date']) && $args['wh_booking_date'] == '8') {
        $tomorrow_mysql_format = date('Y-m-d', time() + 86400);
        //1 Day = 24*60*60 = 86400
        foreach ($bookings as $bc_id => $bc_value) {
            if (count($bc_value->dates_short) == 1) {
                $check_out_date = $bc_value->dates_short[0];
            } else {
                $check_out_date = $bc_value->dates_short[2];
            }
            $check_out_date = explode(' ', $check_out_date);
            $check_out_date = $check_out_date[0];
            // 2014-02-25
            if ($tomorrow_mysql_format != $check_out_date) {
                unset($bookings[$bc_id]);
                $bookings_count--;
            }
        }
    }
    //debuge(array($bookings , $booking_types, $bookings_count, $page_num,  $page_items_count));
    return array($bookings, $booking_types, $bookings_count, $page_num, $page_items_count);
}