コード例 #1
0
function wpdev_bk_ajax_responder()
{
    session_start();
    // continue current session
    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']);
        }
        loadLocale(WPDEV_BK_LOCALE_RELOAD);
    }
    switch ($action) {
        case 'SAVE_BOOKING':
            wpdev_bk_insert_new_booking_v2();
            die;
            break;
            /////////////////////// BEGIN CUSTOM CODE /////////////////////////
            // enable editing of the fields in the current resource row
        /////////////////////// BEGIN CUSTOM CODE /////////////////////////
        // enable editing of the fields in the current resource row
        case 'EDIT_RESOURCE':
            wpdev_edit_resource();
            die;
            break;
            // save the editing fields in the current resource row
        // save the editing fields in the current resource row
        case 'SAVE_RESOURCE':
            wpdev_save_resource();
            die;
            break;
            // delete the current resource row
        // delete the current resource row
        case 'DELETE_RESOURCE':
            wpdev_delete_resource();
            die;
            break;
            // insert allocations as part of a booking
        // insert allocations as part of a booking
        case 'ADD_ALLOCATION':
            wpdev_add_booking_allocation();
            die;
            break;
            // enable editing of the fields in the current allocation row
        // enable editing of the fields in the current allocation row
        case 'EDIT_ALLOCATION':
            wpdev_edit_allocation();
            die;
            break;
            // save the editing fields in the current allocation row
        // save the editing fields in the current allocation row
        case 'SAVE_ALLOCATION':
            wpdev_save_allocation();
            die;
            break;
            // delete the current allocation row
        // delete the current allocation row
        case 'DELETE_ALLOCATION':
            wpdev_delete_allocation();
            die;
            break;
            // toggle the state of a booking date in the availability table
        // toggle the state of a booking date in the availability table
        case 'TOGGLE_BOOKING_DATE':
            wpdev_toggle_booking_date();
            die;
            break;
            // toggle the checkout state of a booking date in the (edit booking) availability table
        // toggle the checkout state of a booking date in the (edit booking) availability table
        case 'TOGGLE_CHECKOUT_ON_BOOKING_DATE':
            wpdev_toggle_checkout_on_booking_date();
            die;
            break;
            // toggle the checkout state of an allocation from the allocation view
        // toggle the checkout state of an allocation from the allocation view
        case 'TOGGLE_CHECKOUT_FOR_ALLOCATION':
            wpdev_toggle_checkout_for_allocation();
            die;
            break;
        case 'PAGE_AVAILABILITY_TABLE_LEFT_RIGHT':
            wpdev_page_availability_table_left_right();
            die;
            break;
            // add a comment to the current booking
        // add a comment to the current booking
        case 'ADD_BOOKING_COMMENT':
            wpdev_add_booking_comment();
            die;
            break;
        case 'SELECT_DAILY_SUMMARY_DAY':
            wpdev_select_daily_summary_day();
            die;
            break;
            /////////////////////// END CUSTOM CODE ///////////////////////////
        /////////////////////// END CUSTOM CODE ///////////////////////////
        case 'UPDATE_READ_UNREAD':
            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);
            renew_NumOfNewBookings($arrayof_bookings_id, $is_new);
            ?>
  <script type="text/javascript">
                    <?php 
            foreach ($arrayof_bookings_id as $bk_id) {
                if ($is_new == '1') {
                    ?>
                                set_booking_row_read(<?php 
                    echo $bk_id;
                    ?>
);
                            <?php 
                } else {
                    ?>
                                set_booking_row_unread(<?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':
            make_bk_action('check_multiuser_params_for_client_side_by_user_id', $_POST['user_id']);
            // Approve or Unapprove
            $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);
            $denyreason = $_POST["denyreason"];
            $is_send_emeils = $_POST["is_send_emeils"];
            if (count($approved_id) > 0 && $approved_id !== false) {
                $approved_id_str = join(',', $approved_id);
                if (false === $wpdb->query($wpdb->prepare("UPDATE " . $wpdb->prefix . "bookingdates SET approved = '" . $is_approve_or_pending . "' 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 updating to DB', __FILE__, __LINE__);
                    ?>
</div>'; </script> <?php 
                    die;
                }
                if ($is_approve_or_pending == '1') {
                    sendApproveEmails($approved_id_str, $is_send_emeils);
                } 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(<?php 
                        echo $bk_id;
                        ?>
);
                                <?php 
                    } else {
                        ?>
                                    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':
            make_bk_action('check_multiuser_params_for_client_side_by_user_id', $_POST['user_id']);
            $booking_id = $_POST["booking_id"];
            // Booking ID
            $denyreason = $_POST["denyreason"];
            if ($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);
                sendDeclineEmails($approved_id_str, $is_send_emeils, $denyreason);
                if (false === $wpdb->query($wpdb->prepare("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($wpdb->prepare("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(<?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':
            make_bk_action('wpdev_delete_booking_by_visitor');
            break;
        case 'SAVE_BK_COST':
            make_bk_action('wpdev_save_bk_cost');
            break;
        case 'SEND_PAYMENT_REQUEST':
            make_bk_action('wpdev_send_payment_request');
            break;
        case 'CHANGE_PAYMENT_STATUS':
            make_bk_action('wpdev_change_payment_status');
            break;
        case 'UPDATE_BK_RESOURCE_4_BOOKING':
            make_bk_action('wpdev_updating_bk_resource_of_booking');
            break;
        case 'UPDATE_REMARK':
            make_bk_action('wpdev_updating_remark');
            break;
        case 'DELETE_BK_FORM':
            make_bk_action('wpdev_delete_booking_form');
            break;
        case 'USER_SAVE_OPTION':
            if ($_POST['option'] == 'ADMIN_CALENDAR_COUNT') {
                update_user_option($_POST['user_id'], 'booking_admin_calendar_count', $_POST['count']);
            }
            ?>
 <script type="text/javascript">
                    document.getElementById('ajax_message').innerHTML = '<?php 
            echo __('Done', 'wpdev-booking');
            ?>
';
                    jQuery('#ajax_message').fadeOut(1000);
                    <?php 
            if ($_POST['is_reload'] == 1) {
                ?>
 location.reload(true); <?php 
            }
            ?>
                </script> <?php 
            die;
            break;
        case 'USER_SAVE_WINDOW_STATE':
            update_user_option($_POST['user_id'], 'booking_win_' . $_POST['window'], $_POST['is_closed']);
            die;
            break;
        case 'CALCULATE_THE_COST':
            make_bk_action('wpdev_ajax_show_cost');
            die;
            break;
        case 'BOOKING_SEARCH':
            make_bk_action('wpdev_ajax_booking_search');
            die;
            break;
        case 'CHECK_BK_NEWS':
            wpdev_ajax_check_bk_news();
            die;
            break;
        case 'CHECK_BK_VERSION':
            wpdev_ajax_check_bk_version();
            die;
            break;
        case 'SAVE_BK_LISTING_FILTER':
            make_bk_action('wpdev_ajax_save_bk_listing_filter');
            die;
            break;
        case 'EXPORT_BOOKINGS_TO_CSV':
            make_bk_action('wpdev_ajax_export_bookings_to_csv');
            die;
        default:
            if (function_exists('wpdev_pro_bk_ajax')) {
                wpdev_pro_bk_ajax();
            }
            error_log("ERROR: Undefined AJAX action  {$action}");
            die;
    }
}
コード例 #2
0
ファイル: wpdev-booking-ajax.php プロジェクト: dev-lav/htdocs
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;
    }
}