PluginProbe
Booking Calendar / 10.1.3
Booking Calendar v10.1.3
11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 10.11.2 All 203 releases
booking / core / lib / wpbc-ajax.php

wpbc-ajax.php in Booking Calendar 10.1.3, at core/lib/wpbc-ajax.php

439 lines 19.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @version 1.0
4 * @package Booking Calendar
5 * @subpackage Ajax Responder
6 * @category Bookings
7 *
8 * @author wpdevelop
9 * @link https://wpbookingcalendar.com/
10 * @email info@wpbookingcalendar.com
11 *
12 * @modified 2014.05.26
13 */
14
15 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
16
17
18
19 // ---------------------------------------------------------------------------------------------------------------------
20 // A j a x H o o k s f o r s p e c i f i c A c t i o n s /////
21 // ---------------------------------------------------------------------------------------------------------------------
22
23
24 //FixIn: Flex TimeLine 1.0
25 function wpbc_ajax_WPBC_FLEXTIMELINE_NAV() {
26
27 // if ( ! wpbc_check_nonce_in_admin_panel( $_POST['action'] ) ) return false; //FixIn: 7.2.1.10 // This line for admin panel
28
29 if ( wpbc_is_use_nonce_at_front_end() ) { //FixIn: 10.1.1.2
30 $nonce = ( isset($_REQUEST['wpbc_nonce']) ) ? $_REQUEST['wpbc_nonce'] : '';
31 if ( ! wp_verify_nonce( $nonce, $_POST['action'] ) ) { // This nonce is not valid.
32 wp_die(
33 sprintf(__('%sError!%s Request do not pass security check! Please refresh the page and try one more time.' ,'booking'),'<strong>','</strong>')
34 . '<br/>' . sprintf( __( 'Please check more %shere%s', 'booking' ), '<a href="https://wpbookingcalendar.com/faq/request-do-not-pass-security-check/?after_update=10.1.1" target="_blank">', '</a>.' ) //FixIn: 8.8.3.6
35 ); // Its prevent of showing '0' et the end of request.
36 }
37 }
38 make_bk_action('wpbc_ajax_flex_timeline');
39 wp_die(''); // Its prevent of showing '0' et the end of request.
40 }
41
42
43 function wpbc_ajax_CALCULATE_THE_COST() {
44
45 if ( wpbc_is_use_nonce_at_front_end() ) { //FixIn: 10.1.1.2
46 if ( ! wpbc_check_nonce_in_admin_panel( $_POST['action'] ) ) {
47 return false;//FixIn: 7.2.1.10
48 }
49 }
50 make_bk_action( 'wpdev_ajax_show_cost' );
51 }
52
53
54
55 //FixIn: 9.6.3.5
56
57 function wpbc_ajax_UPDATE_APPROVE() {
58
59 global $wpdb;
60
61 if ( ! wpbc_check_nonce_in_admin_panel() ) return false; //FixIn: 7.2.1.10
62
63 make_bk_action('check_multiuser_params_for_client_side_by_user_id', $_POST['user_id'] );
64
65 // Approve or Reject
66 $is_approve_or_pending = $_POST[ "is_approve_or_pending" ];
67 if ($is_approve_or_pending == 1)
68 $is_approve_or_pending = '1';
69 else
70 $is_approve_or_pending = '0';
71
72 $booking_id = $_POST[ "booking_id" ];
73 $approved_id = explode('|',$booking_id);
74 $approved_id = wpbc_clean_digit_or_csd( $approved_id ); //FixIn: 8.4.5.15
75
76 if (! isset($_POST["denyreason"]))
77 $_POST["denyreason"] = '';
78 $denyreason = stripslashes( $_POST["denyreason"] ); //FixIn: 7.0.1.46 - translate words like don\'t to don't
79 $is_send_emeils = $_POST["is_send_emeils"];
80
81
82 if ( ( count($approved_id) > 0 ) && ( $approved_id !== false ) ) {
83
84 $approved_id_str = join( ',', $approved_id);
85 $approved_id_str = wpbc_clean_digit_or_csd( $approved_id_str );
86
87 if ( false === $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->prefix}bookingdates SET approved = %s WHERE booking_id IN ({$approved_id_str})", $is_approve_or_pending ) ) ){
88 ?> <script type="text/javascript">
89 var my_message = '<?php echo html_entity_decode( esc_js( get_debuge_error('Error during updating to DB' ,__FILE__,__LINE__) ),ENT_QUOTES) ; ?>';
90 wpbc_admin_show_message( my_message, 'error', 30000 );
91 </script> <?php
92 die();
93 }
94
95 //FixIn: 8.6.1.10
96 $curr_user = get_user_by( 'id', (int) $_POST['user_id'] );
97 $user_info = $curr_user->first_name . ' ' . $curr_user->last_name . ' (' . $curr_user->user_email . ')'; // get_user_meta( $curr_user->ID, 'nickname' )
98 wpbc_db__add_log_info( explode(',',$approved_id_str),
99 ( ( $is_approve_or_pending == '1' ) ? __( 'Approved by:', 'booking' ) : __( 'Declined by:', 'booking' ) )
100 . ' ' . $user_info );
101
102 wpbc_db_update_number_new_bookings( explode(',', $approved_id_str) );
103
104 do_action( 'wpbc_booking_approved', $approved_id_str, $is_approve_or_pending ); //FixIn: 8.7.6.1
105
106 if ($is_approve_or_pending == '1') {
107 if ( ! empty($is_send_emeils ) ) //FixIn: 7.0.1.5
108 wpbc_send_email_approved($approved_id_str, $is_send_emeils,$denyreason);
109 $all_bk_id_what_canceled = apply_bk_filter('cancel_pending_same_resource_bookings_for_specific_dates', false, $approved_id_str );
110 } else {
111 if ( ! empty($is_send_emeils ) )
112 wpbc_send_email_deny($approved_id_str, $is_send_emeils,$denyreason);
113 }
114
115 ?> <script type="text/javascript">
116 <?php foreach ($approved_id as $bk_id) {
117 if ($is_approve_or_pending == '1') { ?>
118 set_booking_row_approved_in_timeline(<?php echo $bk_id ?>);
119 set_booking_row_approved(<?php echo $bk_id ?>);
120 set_booking_row_read(<?php echo $bk_id ?>);
121 <?php } else { ?>
122 set_booking_row_pending_in_timeline(<?php echo $bk_id ?>);
123 set_booking_row_pending(<?php echo $bk_id ?>);
124 <?php }?>
125 <?php } ?>
126 <?php if ($is_approve_or_pending == '1') { ?>
127 var my_message = '<?php echo html_entity_decode( esc_js( __('Set as Approved' ,'booking') ),ENT_QUOTES) ; ?>';
128 <?php } else { ?>
129 var my_message = '<?php echo html_entity_decode( esc_js( __('Set as Pending' ,'booking') ),ENT_QUOTES) ; ?>';
130 <?php } ?>
131 wpbc_admin_show_message( my_message, 'success', 3000 );
132 </script> <?php
133 }
134 }
135
136
137 //FixIn: 6.1.1.10
138 function wpbc_ajax_TRASH_RESTORE() {
139 global $wpdb;
140
141 if ( ! wpbc_check_nonce_in_admin_panel() ) return false; //FixIn: 7.2.1.10
142
143 make_bk_action('check_multiuser_params_for_client_side_by_user_id', $_POST['user_id'] );
144
145 $booking_id = $_POST[ "booking_id" ]; // Booking ID
146
147 if ( ! isset($_POST["denyreason"] ) )
148 $_POST["denyreason"] = '';
149 $denyreason = stripslashes( $_POST["denyreason"] ); //FixIn: 7.0.1.46 - trasnalte words like don\'t to don't
150 if ( ( $denyreason == __('Reason for cancellation here' ,'booking'))
151 || ( $denyreason == __('Reason of cancellation here' ,'booking'))
152 || ( $denyreason == 'Reason of cancel here')
153 ) $denyreason = '';
154 $is_send_emeils = $_POST["is_send_emeils"];
155
156 $approved_id = explode('|',$booking_id);
157 $approved_id = wpbc_clean_digit_or_csd( $approved_id ); //FixIn: 8.4.5.15
158
159 $is_trash = intval( $_POST["is_trash"] );
160
161 if ( (count($approved_id)>0) && ($approved_id !=false) && ($approved_id !='')) {
162
163 $approved_id_str = join( ',', $approved_id);
164 $approved_id_str = wpbc_clean_like_string_for_db( $approved_id_str );
165
166 do_action( 'wpbc_booking_trash', $booking_id, $is_trash ); //FixIn: 8.7.6.2
167
168 if ( $is_trash ) {
169 if ( ! empty( $is_send_emeils ) ) { //FixIn: 8.1.3.35
170 wpbc_send_email_trash( $approved_id_str, $is_send_emeils, $denyreason );
171 }
172 } else {
173 if ( ! empty( $is_send_emeils ) ) { //FixIn: 8.1.3.35
174 // wpbc_send_email_approved($approved_id_str, $is_send_emeils,$denyreason); //FixIn: 8.1.2.7
175 }
176 }
177
178 if ( false === $wpdb->query( "UPDATE {$wpdb->prefix}booking AS bk SET bk.trash = {$is_trash} WHERE booking_id IN ({$approved_id_str})" ) ){
179 ?> <script type="text/javascript">
180 var my_message = '<?php echo html_entity_decode( esc_js( get_debuge_error('Error during trash booking in DB' ,__FILE__,__LINE__) ),ENT_QUOTES) ; ?>';
181 wpbc_admin_show_message( my_message, 'error', 30000 );
182 </script> <?php
183 die();
184 }
185
186 // Update the Hash and Cost of the booking
187 $booking_id_arr = explode(',', $approved_id_str ); //FixIn: 8.6.1.11
188 foreach ( $booking_id_arr as $booking_id ) {
189 wpbc_hash__update_booking_hash( $booking_id );
190 }
191
192 ?> <script type="text/javascript">
193 <?php
194
195 if ( $is_trash ) {
196
197 foreach ($approved_id as $bk_id) {
198 ?>
199 set_booking_row_trash(<?php echo $bk_id ?>);
200 //set_booking_row_deleted_in_timeline(<?php echo $bk_id ?>);
201 //setTimeout(function() { set_booking_row_deleted(<?php echo $bk_id ?>); }, 1000);
202 <?php
203 }
204 ?>
205 var my_message = '<?php echo html_entity_decode( esc_js( __('Moved to trash' ,'booking') ),ENT_QUOTES) ; ?>';
206 wpbc_admin_show_message( my_message, 'success', 3000 );
207 <?php
208 } else {
209 foreach ($approved_id as $bk_id) {
210 ?> set_booking_row_restore(<?php echo $bk_id ?>); <?php
211 }
212 ?>
213 var my_message = '<?php echo html_entity_decode( esc_js( __('Restored' ,'booking') ),ENT_QUOTES) ; ?>';
214 wpbc_admin_show_message( my_message, 'success', 3000 );
215 <?php
216 }
217 ?>
218 </script>
219 <?php
220 }
221 }
222
223 //FixIn: 9.6.3.5
224
225
226 function wpbc_ajax_DELETE_APPROVE() {
227
228 global $wpdb;
229
230 if ( ! wpbc_check_nonce_in_admin_panel() ) return false; //FixIn: 7.2.1.10
231
232 make_bk_action('check_multiuser_params_for_client_side_by_user_id', $_POST['user_id'] );
233
234 $booking_id = $_POST[ "booking_id" ]; // Booking ID
235 if ( ! isset($_POST["denyreason"] ) )
236 $_POST["denyreason"] = '';
237 $denyreason = stripslashes( $_POST["denyreason"] ); //FixIn: 7.0.1.46 - trasnalte words like don\'t to don't
238 if ( ( $denyreason == __('Reason for cancellation here' ,'booking'))
239 || ( $denyreason == __('Reason of cancellation here' ,'booking'))
240 || ( $denyreason == 'Reason of cancel here')
241 ) $denyreason = '';
242 $is_send_emeils = $_POST["is_send_emeils"];
243 $approved_id = explode('|',$booking_id);
244 $approved_id = wpbc_clean_digit_or_csd( $approved_id ); //FixIn: 8.4.5.15
245
246 if ( (count($approved_id)>0) && ($approved_id !=false) && ($approved_id !='')) {
247
248 $approved_id_str = join( ',', $approved_id);
249 $approved_id_str = wpbc_clean_like_string_for_db( $approved_id_str );
250
251 do_action( 'wpbc_booking_delete', $approved_id_str ); //FixIn: 8.7.6.3
252
253 if ( ! empty( $is_send_emeils ) ) { //FixIn: 8.1.3.35
254 wpbc_send_email_deleted( $approved_id_str, $is_send_emeils, $denyreason );
255 }
256
257 if ( false === $wpdb->query( "DELETE FROM {$wpdb->prefix}bookingdates WHERE booking_id IN ({$approved_id_str})" ) ){
258 ?> <script type="text/javascript">
259 var my_message = '<?php echo html_entity_decode( esc_js( get_debuge_error('Error during deleting dates in DB' ,__FILE__,__LINE__) ),ENT_QUOTES) ; ?>';
260 wpbc_admin_show_message( my_message, 'error', 30000 );
261 </script> <?php
262 die();
263 }
264
265 if ( false === $wpdb->query( "DELETE FROM {$wpdb->prefix}booking WHERE booking_id IN ({$approved_id_str})" ) ){
266 ?> <script type="text/javascript">
267 var my_message = '<?php echo html_entity_decode( esc_js( get_debuge_error('Error during deleting booking in DB' ,__FILE__,__LINE__) ),ENT_QUOTES) ; ?>';
268 wpbc_admin_show_message( my_message, 'error', 30000 );
269 </script> <?php
270 die();
271 }
272 ?>
273 <script type="text/javascript">
274 <?php foreach ($approved_id as $bk_id) { ?>
275 set_booking_row_deleted_in_timeline(<?php echo $bk_id ?>);
276 set_booking_row_deleted(<?php echo $bk_id ?>);
277 <?php } ?>
278 var my_message = '<?php echo html_entity_decode( esc_js( __('Deleted' ,'booking') ),ENT_QUOTES) ; ?>';
279 wpbc_admin_show_message( my_message, 'success', 3000 );
280 </script>
281 <?php
282 }
283 }
284
285
286 function wpbc_ajax_DELETE_BY_VISITOR() {
287
288 if ( wpbc_is_use_nonce_at_front_end() ) { //FixIn: 10.1.1.2
289 if ( ! wpbc_check_nonce_in_admin_panel( $_POST['action'] ) ) {
290 return false; //FixIn: 7.2.1.10
291 }
292 }
293
294 make_bk_action('wpdev_delete_booking_by_visitor');
295 }
296
297
298
299
300
301 function wpbc_ajax_DELETE_BK_FORM() {
302
303 if ( ! wpbc_check_nonce_in_admin_panel() ) return false; //FixIn: 7.2.1.10
304 make_bk_action('check_multiuser_params_for_client_side_by_user_id', $_POST['user_id'] );
305 make_bk_action('wpbc_make_delete_custom_booking_form');
306 }
307
308
309 function wpbc_ajax_USER_SAVE_WINDOW_STATE() {
310
311 if ( ! wpbc_check_nonce_in_admin_panel() ) return false;
312
313 update_user_option( (int) $_POST['user_id'], 'booking_win_' . esc_attr( $_POST['window'] ) , (int) $_POST['is_closed'] );
314
315 wp_send_json_success(); //FixIn: 7.2.1.10.2 //Fix "400 Bad Request" error showing. At some situations, if Ajax request does not return anything, its will generate an issue
316 }
317
318
319 /** Save Custom User Data */
320 function wpbc_ajax_USER_SAVE_CUSTOM_DATA() {
321
322 if ( ! wpbc_check_nonce_in_admin_panel() ) return false;
323 /* Exmaple of $_POST:
324 [data_name] => add_booking_calendar_options
325 [data_value] => calendar_months_count=1&calendar_months_num_in_1_row=1&calendar_width=500px&calendar_cell_height
326 */
327 $post_param = explode( '&', $_POST['data_value'] ); // "&" was set by jQuery.param( data_params ) in client side.
328 $data_to_save = array();
329 foreach ( $post_param as $param ) {
330 $param_data = explode( '=', $param );
331
332 $data_to_save[ $param_data[0] ] = ( isset( $param_data[1] ) ) ? esc_attr( $param_data[1] ) : '';
333 }
334 /* Exmaple:
335 Array
336 (
337 [calendar_months_count] => 1
338 [calendar_months_num_in_1_row] => 1
339 [calendar_width] => 500px
340 [calendar_cell_height] =>
341 )
342 */
343
344 // Save Custom User Data
345 update_user_option( (int) $_POST['user_id'], 'booking_custom_' . esc_attr( $_POST['data_name'] ) , serialize( $data_to_save ) );
346
347 ?> <script type="text/javascript">
348 var my_message = '<?php echo html_entity_decode( esc_js( __('Saved' ,'booking') ),ENT_QUOTES) ; ?>';
349 wpbc_admin_show_message( my_message, 'success', 1000 );
350 <?php if ( ! empty( $_POST['is_reload'] ) == 1 ) { ?>
351 setTimeout(function ( ) {location.reload(true);} ,1500);
352 <?php } ?>
353 </script> <?php
354 die();
355
356 }
357
358
359 function wpbc_ajax_BOOKING_SEARCH() {
360
361 if ( wpbc_is_use_nonce_at_front_end() ) { //FixIn: 10.1.1.2
362 if ( ! wpbc_check_nonce_in_admin_panel( $_POST['action'] ) ) {
363 return false; //FixIn: 7.2.1.10
364 }
365 }
366
367 if ( function_exists( 'wpbc_ajax_start_searching' ) ) {
368 wpbc_ajax_start_searching();
369 }
370 }
371
372
373 function wpbc_ajax_CHECK_BK_NEWS() {
374
375 if ( ! wpbc_check_nonce_in_admin_panel() ) return false; //FixIn: 7.2.1.10
376 wpdev_ajax_check_bk_news();
377 }
378
379
380 function wpbc_ajax_CHECK_BK_FEATURES() {
381
382 if ( ! wpbc_check_nonce_in_admin_panel() ) return false; //FixIn: 7.2.1.10
383 wpdev_ajax_check_bk_news('info/features/');
384 }
385
386
387 function wpbc_ajax_CHECK_BK_VERSION() {
388
389 if ( ! wpbc_check_nonce_in_admin_panel() ) return false; //FixIn: 7.2.1.10
390 wpdev_ajax_check_bk_version();
391 }
392
393
394
395
396
397 // ---------------------------------------------------------------------------------------------------------------------
398 // R u n A j a x //////////////////////////////////
399 // ---------------------------------------------------------------------------------------------------------------------
400 if ( is_admin() && ( defined( 'DOING_AJAX' ) ) && ( DOING_AJAX ) ) {
401
402 //FixIn: 8.9.4.5
403
404 // Hooks list
405 $actions_list = array(
406 'WPBC_FLEXTIMELINE_NAV' => 'both' //FixIn: Flex TimeLine 1.0
407 ,'CALCULATE_THE_COST' => 'both'
408
409
410 ,'UPDATE_APPROVE' => 'admin'
411 ,'DELETE_APPROVE' => 'admin'
412 ,'DELETE_BY_VISITOR' => 'both'
413 ,'TRASH_RESTORE' => 'admin' //FixIn: 6.1.1.10
414
415 ,'DELETE_BK_FORM' => 'admin'
416 ,'USER_SAVE_WINDOW_STATE' => 'admin'
417 ,'USER_SAVE_CUSTOM_DATA' => 'admin'
418 ,'BOOKING_SEARCH' => 'both'
419 ,'CHECK_BK_NEWS' => 'admin'
420 ,'CHECK_BK_FEATURES' => 'admin'
421 ,'CHECK_BK_VERSION' => 'admin'
422
423 , 'WPBC_IMPORT_ICS_URL' => 'admin' //FixIn: 7.3
424 );
425
426 $actions_list = apply_filters( 'wpbc_ajax_action_list', $actions_list );
427
428 foreach ($actions_list as $action_name => $action_where) {
429
430 if ( ( isset($_POST['action']) ) && ( $_POST['action'] == $action_name ) ){
431
432 if ( ( $action_where == 'admin' ) || ( $action_where == 'both' ) )
433 add_action( 'wp_ajax_' . $action_name, 'wpbc_ajax_' . $action_name); // Admin & Client (logged in usres)
434
435 if ( ( $action_where == 'both' ) || ( $action_where == 'client' ) )
436 add_action( 'wp_ajax_nopriv_' . $action_name, 'wpbc_ajax_' . $action_name); // Client (not logged in)
437 }
438 }
439 }