Beispiel #1
0
function wpdev_bk_ajax_responder()
{
    global $wpdb;
    $action = $_POST['ajax_action'];
    if (isset($_POST['wpdev_active_locale'])) {
        // Reload locale according request parameter
        global $l10n;
        if (isset($l10n['wpdev-booking'])) {
            unset($l10n['wpdev-booking']);
        }
        if (!defined('WPDEV_BK_LOCALE_RELOAD')) {
            define('WPDEV_BK_LOCALE_RELOAD', $_POST['wpdev_active_locale']);
        }
        // Reload locale settings, its required for the correct  dates format
        if (isset($l10n['default'])) {
            unset($l10n['default']);
        }
        // Unload locale
        add_filter('locale', 'getBookingLocale', 999);
        // Set filter to load the locale of the Booking Calendar
        load_default_textdomain();
        // Load default locale
        global $wp_locale;
        $wp_locale = new WP_Locale();
        // Reload class
        loadLocale(WPDEV_BK_LOCALE_RELOAD);
    }
    switch ($action) {
        case 'INSERT_INTO_TABLE':
            wpdev_check_nonce_in_admin_panel($action);
            wpdev_bk_insert_new_booking();
            die;
            break;
        case 'UPDATE_READ_UNREAD':
            wpdev_check_nonce_in_admin_panel();
            make_bk_action('check_multiuser_params_for_client_side_by_user_id', $_POST['user_id']);
            $is_read_or_unread = $_POST["is_read_or_unread"];
            if ($is_read_or_unread == 1) {
                $is_new = '1';
            } else {
                $is_new = '0';
            }
            $id_of_new_bookings = $_POST["booking_id"];
            $arrayof_bookings_id = explode('|', $id_of_new_bookings);
            $user_id = $_POST["user_id"];
            renew_NumOfNewBookings($arrayof_bookings_id, $is_new, $user_id);
            //debuge($arrayof_bookings_id, 'all_array');
            ?>
  <script type="text/javascript">
                    <?php 
            foreach ($arrayof_bookings_id as $bk_id) {
                if ($bk_id == 'all') {
                    $bk_id = 0;
                }
                if ($is_new == '1') {
                    ?>
                                set_booking_row_unread(<?php 
                    echo $bk_id;
                    ?>
);
                            <?php 
                } else {
                    ?>
                                set_booking_row_read(<?php 
                    echo $bk_id;
                    ?>
);                                
                            <?php 
                }
                ?>
                    <?php 
            }
            ?>
                    <?php 
            if ($is_new == '1') {
                ?>
                    //    var my_num = parseInt(jQuery('.bk-update-count').text()) + parseInt(1<?php 
                echo '*' . count($arrayof_bookings_id);
                ?>
);
                    <?php 
            } else {
                ?>
                    //    var my_num = parseInt(jQuery('.bk-update-count').text()) - parseInt(1<?php 
                echo '*' . count($arrayof_bookings_id);
                ?>
);
                    <?php 
            }
            ?>
                    //jQuery('.bk-update-count').html( my_num );
                    document.getElementById('ajax_message').innerHTML = '<?php 
            if ($is_new == '1') {
                echo __('Set as Read', 'wpdev-booking');
            } else {
                echo __('Set as Unread', 'wpdev-booking');
            }
            ?>
';
                    jQuery('#ajax_message').fadeOut(1000);
                </script> <?php 
            die;
            break;
        case 'UPDATE_APPROVE':
            wpdev_check_nonce_in_admin_panel();
            make_bk_action('check_multiuser_params_for_client_side_by_user_id', $_POST['user_id']);
            // Approve or Reject
            $is_approve_or_pending = $_POST["is_approve_or_pending"];
            if ($is_approve_or_pending == 1) {
                $is_approve_or_pending = '1';
            } else {
                $is_approve_or_pending = '0';
            }
            // Booking ID
            $booking_id = $_POST["booking_id"];
            $approved_id = explode('|', $booking_id);
            if (!isset($_POST["denyreason"])) {
                $_POST["denyreason"] = '';
            }
            $denyreason = $_POST["denyreason"];
            $is_send_emeils = $_POST["is_send_emeils"];
            if (count($approved_id) > 0 && $approved_id !== false) {
                $approved_id_str = join(',', $approved_id);
                $approved_id_str = wpbc_clean_string_for_db($approved_id_str);
                if (false === $wpdb->query($wpdb->prepare("UPDATE {$wpdb->prefix}bookingdates SET approved = %s WHERE booking_id IN ({$approved_id_str})", $is_approve_or_pending))) {
                    ?>
 <script type="text/javascript"> document.getElementById('ajax_message').innerHTML = '<div style=&quot;height:20px;width:100%;text-align:center;margin:15px auto;&quot;><?php 
                    bk_error('Error during updating to DB', __FILE__, __LINE__);
                    ?>
</div>'; </script> <?php 
                    die;
                }
                renew_NumOfNewBookings(explode(',', $approved_id_str));
                if ($is_approve_or_pending == '1') {
                    sendApproveEmails($approved_id_str, $is_send_emeils, $denyreason);
                    $all_bk_id_what_canceled = apply_bk_filter('cancel_pending_same_resource_bookings_for_specific_dates', false, $approved_id_str);
                    //debuge($pending_bookings);
                } else {
                    sendDeclineEmails($approved_id_str, $is_send_emeils, $denyreason);
                }
                ?>
  <script type="text/javascript">
                        <?php 
                foreach ($approved_id as $bk_id) {
                    if ($is_approve_or_pending == '1') {
                        ?>
                                    set_booking_row_approved_in_timeline(<?php 
                        echo $bk_id;
                        ?>
);
                                    set_booking_row_approved(<?php 
                        echo $bk_id;
                        ?>
);
                                    set_booking_row_read(<?php 
                        echo $bk_id;
                        ?>
);
                                <?php 
                    } else {
                        ?>
                                    set_booking_row_pending_in_timeline(<?php 
                        echo $bk_id;
                        ?>
);
                                    set_booking_row_pending(<?php 
                        echo $bk_id;
                        ?>
);
                                <?php 
                    }
                    ?>
                        <?php 
                }
                ?>
                        document.getElementById('ajax_message').innerHTML = '<?php 
                if ($is_approve_or_pending == '1') {
                    echo __('Set as Approved', 'wpdev-booking');
                } else {
                    echo __('Set as Pending', 'wpdev-booking');
                }
                ?>
';
                        jQuery('#ajax_message').fadeOut(1000);
                    </script> <?php 
                die;
            }
            break;
        case 'DELETE_APPROVE':
            wpdev_check_nonce_in_admin_panel();
            make_bk_action('check_multiuser_params_for_client_side_by_user_id', $_POST['user_id']);
            $booking_id = $_POST["booking_id"];
            // Booking ID
            if (!isset($_POST["denyreason"])) {
                $_POST["denyreason"] = '';
            }
            $denyreason = $_POST["denyreason"];
            if ($denyreason == __('Reason for cancellation here', 'wpdev-booking') || $denyreason == __('Reason of cancellation here', 'wpdev-booking') || $denyreason == 'Reason of cancel here') {
                $denyreason = '';
            }
            $is_send_emeils = $_POST["is_send_emeils"];
            $approved_id = explode('|', $booking_id);
            if (count($approved_id) > 0 && $approved_id != false && $approved_id != '') {
                $approved_id_str = join(',', $approved_id);
                $approved_id_str = wpbc_clean_string_for_db($approved_id_str);
                sendDeclineEmails($approved_id_str, $is_send_emeils, $denyreason);
                if (false === $wpdb->query("DELETE FROM {$wpdb->prefix}bookingdates WHERE booking_id IN ({$approved_id_str})")) {
                    ?>
 <script type="text/javascript"> document.getElementById('ajax_message').innerHTML = '<div style=&quot;height:20px;width:100%;text-align:center;margin:15px auto;&quot;><?php 
                    bk_error('Error during deleting dates at DB', __FILE__, __LINE__);
                    ?>
</div>'; </script> <?php 
                    die;
                }
                if (false === $wpdb->query("DELETE FROM {$wpdb->prefix}booking WHERE booking_id IN ({$approved_id_str})")) {
                    ?>
 <script type="text/javascript"> document.getElementById('ajax_message').innerHTML = '<div style=&quot;height:20px;width:100%;text-align:center;margin:15px auto;&quot;><?php 
                    bk_error('Error during deleting reservation at DB', __FILE__, __LINE__);
                    ?>
</div>'; </script> <?php 
                    die;
                }
                ?>
                    <script type="text/javascript">
                        <?php 
                foreach ($approved_id as $bk_id) {
                    ?>
                            set_booking_row_deleted_in_timeline(<?php 
                    echo $bk_id;
                    ?>
);
                            set_booking_row_deleted(<?php 
                    echo $bk_id;
                    ?>
);
                        <?php 
                }
                ?>
                        document.getElementById('ajax_message').innerHTML = '<?php 
                echo __('Deleted', 'wpdev-booking');
                ?>
';
                        jQuery('#ajax_message').fadeOut(1000);
                    </script>
                <?php 
                die;
            }
            break;
        case 'DELETE_BY_VISITOR':
            wpdev_check_nonce_in_admin_panel($action);
            make_bk_action('wpdev_delete_booking_by_visitor');
            break;
        case 'SAVE_BK_COST':
            wpdev_check_nonce_in_admin_panel();
            make_bk_action('wpdev_save_bk_cost');
            break;
        case 'SEND_PAYMENT_REQUEST':
            wpdev_check_nonce_in_admin_panel();
            make_bk_action('wpdev_send_payment_request');
            break;
        case 'CHANGE_PAYMENT_STATUS':
            wpdev_check_nonce_in_admin_panel();
            make_bk_action('wpdev_change_payment_status');
            break;
        case 'UPDATE_BK_RESOURCE_4_BOOKING':
            wpdev_check_nonce_in_admin_panel();
            make_bk_action('wpdev_updating_bk_resource_of_booking');
            break;
        case 'UPDATE_REMARK':
            wpdev_check_nonce_in_admin_panel();
            make_bk_action('wpdev_updating_remark');
            break;
        case 'DELETE_BK_FORM':
            wpdev_check_nonce_in_admin_panel();
            make_bk_action('wpdev_delete_booking_form');
            break;
        case 'USER_SAVE_WINDOW_STATE':
            wpdev_check_nonce_in_admin_panel();
            update_user_option($_POST['user_id'], 'booking_win_' . $_POST['window'], $_POST['is_closed']);
            die;
            break;
        case 'CALCULATE_THE_COST':
            wpdev_check_nonce_in_admin_panel($action);
            make_bk_action('wpdev_ajax_show_cost');
            die;
            break;
        case 'BOOKING_SEARCH':
            wpdev_check_nonce_in_admin_panel($action);
            make_bk_action('wpdev_ajax_booking_search');
            die;
            break;
        case 'CHECK_BK_NEWS':
            wpdev_check_nonce_in_admin_panel();
            wpdev_ajax_check_bk_news();
            die;
            break;
        case 'CHECK_BK_FEATURES':
            wpdev_check_nonce_in_admin_panel();
            wpdev_ajax_check_bk_news('info/features/');
            die;
            break;
        case 'CHECK_BK_VERSION':
            wpdev_check_nonce_in_admin_panel();
            wpdev_ajax_check_bk_version();
            die;
            break;
        case 'SAVE_BK_LISTING_FILTER':
            wpdev_check_nonce_in_admin_panel();
            make_bk_action('wpdev_ajax_save_bk_listing_filter');
            die;
            break;
        case 'DELETE_BK_LISTING_FILTER':
            wpdev_check_nonce_in_admin_panel();
            make_bk_action('wpdev_ajax_delete_bk_listing_filter');
            die;
            break;
        case 'EXPORT_BOOKINGS_TO_CSV':
            wpdev_check_nonce_in_admin_panel();
            make_bk_action('wpdev_ajax_export_bookings_to_csv');
            die;
        default:
            wpdev_check_nonce_in_admin_panel();
            if (function_exists('wpdev_pro_bk_ajax')) {
                wpdev_pro_bk_ajax();
            }
            die;
    }
}
function renew_NumOfNewBookings($id_of_new_bookings, $is_new = '0', $user_id = 1)
{
    global $wpdb;
    if (count($id_of_new_bookings) > 0) {
        if (is_field_in_table_exists('booking', 'is_new') == 0) {
            return 0;
        }
        // do not created this field, so return 0
        $id_of_new_bookings = implode(',', $id_of_new_bookings);
        $id_of_new_bookings = wpbc_clean_string_for_db($id_of_new_bookings);
        //debuge($id_of_new_bookings);
        if ($id_of_new_bookings == 'all') {
            $update_sql = "UPDATE {$wpdb->prefix}booking AS bk SET bk.is_new = {$is_new} ";
            //debuge($update_sql);
            $update_sql = apply_bk_filter('update_sql_for_checking_new_bookings', $update_sql, 0, $user_id);
        } else {
            $update_sql = "UPDATE {$wpdb->prefix}booking AS bk SET bk.is_new = {$is_new} WHERE bk.booking_id IN  ( {$id_of_new_bookings} ) ";
        }
        if (false === $wpdb->query($update_sql)) {
            bk_error('Error during updating status of bookings at DB', __FILE__, __LINE__);
            die;
        }
    }
}
Beispiel #3
0
function wpdev_get_bk_listing_structure_engine($args)
{
    global $wpdb;
    ///debuge($_REQUEST);
    $sql_boking_listing = wpdev_sql_get_booking_listing($args);
    //debuge($args, $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';
            if (isset($booking->sync_gid) && !empty($booking->sync_gid)) {
                $booking->form .= "~text^sync_gid{$booking->booking_type}^{$booking->sync_gid}";
            }
            $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
        $today_mysql_format = date_i18n('Y-m-d', time() + get_option('gmt_offset') * HOUR_IN_SECONDS + DAY_IN_SECONDS);
        // Tommorow day with gmt offset
        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--;
            }
        }
    }
    //debuge( 'Before filtering:',  date('Y-m-d', time() +86400 ), $_REQUEST, $bookings ) ;
    // 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
        $tomorrow_mysql_format = date_i18n('Y-m-d', time() + get_option('gmt_offset') * HOUR_IN_SECONDS + DAY_IN_SECONDS);
        // Tommorow day with gmt offset
        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(  'After filtering:', $tomorrow_mysql_format, $bookings ) ;
    //debuge(array($bookings , $booking_types, $bookings_count, $page_num,  $page_items_count));
    return array($bookings, $booking_types, $bookings_count, $page_num, $page_items_count);
}
function wpbc_ajax_DELETE_APPROVE()
{
    global $wpdb;
    wpdev_check_nonce_in_admin_panel();
    make_bk_action('check_multiuser_params_for_client_side_by_user_id', $_POST['user_id']);
    $booking_id = $_POST["booking_id"];
    // Booking ID
    if (!isset($_POST["denyreason"])) {
        $_POST["denyreason"] = '';
    }
    $denyreason = $_POST["denyreason"];
    if ($denyreason == __('Reason for cancellation here', 'booking') || $denyreason == __('Reason of cancellation here', 'booking') || $denyreason == 'Reason of cancel here') {
        $denyreason = '';
    }
    $is_send_emeils = $_POST["is_send_emeils"];
    $approved_id = explode('|', $booking_id);
    if (count($approved_id) > 0 && $approved_id != false && $approved_id != '') {
        $approved_id_str = join(',', $approved_id);
        $approved_id_str = wpbc_clean_string_for_db($approved_id_str);
        sendDeclineEmails($approved_id_str, $is_send_emeils, $denyreason);
        if (false === $wpdb->query("DELETE FROM {$wpdb->prefix}bookingdates WHERE booking_id IN ({$approved_id_str})")) {
            ?>
 <script type="text/javascript"> document.getElementById('ajax_message').innerHTML = '<div style=&quot;height:20px;width:100%;text-align:center;margin:15px auto;&quot;><?php 
            bk_error('Error during deleting dates at DB', __FILE__, __LINE__);
            ?>
</div>'; </script> <?php 
            die;
        }
        if (false === $wpdb->query("DELETE FROM {$wpdb->prefix}booking WHERE booking_id IN ({$approved_id_str})")) {
            ?>
 <script type="text/javascript"> document.getElementById('ajax_message').innerHTML = '<div style=&quot;height:20px;width:100%;text-align:center;margin:15px auto;&quot;><?php 
            bk_error('Error during deleting reservation at DB', __FILE__, __LINE__);
            ?>
</div>'; </script> <?php 
            die;
        }
        ?>
            <script type="text/javascript">
                <?php 
        foreach ($approved_id as $bk_id) {
            ?>
                    set_booking_row_deleted_in_timeline(<?php 
            echo $bk_id;
            ?>
);
                    set_booking_row_deleted(<?php 
            echo $bk_id;
            ?>
);
                <?php 
        }
        ?>
                document.getElementById('ajax_message').innerHTML = '<?php 
        echo __('Deleted', 'booking');
        ?>
';
                jQuery('#ajax_message').fadeOut(1000);
            </script>
        <?php 
    }
}