PluginProbe
Booking Calendar / 10.15.6
Booking Calendar v10.15.6
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 / includes / page-setup / setup_ajax.php

setup_ajax.php in Booking Calendar 10.15.6, at includes/page-setup/setup_ajax.php

741 lines 42.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php /**
2 * @version 1.0
3 * @description Ajax and Requests Structure for WPBC_AJX__Setup__Ajax_Request
4 * @category Setup Class
5 * @author wpdevelop
6 *
7 * @web-site http://oplugins.com/
8 * @email info@oplugins.com
9 *
10 * @modified 2023-06-23
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
14
15 // =====================================================================================================================
16 // == Get RULES STRUCTURE ==
17 // =====================================================================================================================
18
19 /**
20 * Get params names for escaping and/or default value of such params
21 *
22 * @return array array ( 'resource_id' => array( 'validate' => 'digit_or_csd', 'default' => array( '1' ) )
23 * , ... )
24 */
25 function wpbc_setup_wizard_page__request_rules_structure() {
26
27 return array(
28 'do_action' => array(
29 'validate' => array(
30 'none',
31 'save_and_continue',
32 'make_reset', 'skip_wizard',
33
34 'save_and_continue__welcome',
35 'save_and_continue__general_info',
36 'save_and_continue__date_time_formats',
37 'save_and_continue__bookings_types',
38 'save_and_continue__form_structure',
39 'load_form_template',
40 'save_and_continue__cal_availability',
41 'save_and_continue__color_theme',
42 'save_and_continue__optional_other_settings',
43 'save_and_continue__wizard_publish',
44 'save_and_continue__get_started'
45 ),
46 'default' => 'none'
47 ),
48 'current_step' => array( 'validate' => 's', 'default' => '' ),
49 'resource_id' => array( 'validate' => 'd', 'default' => wpbc_get_default_resource() ),
50 'ui_clicked_element_id' => array( 'validate' => 's', 'default' => '' )
51 // 'calendar__booking_start_day_weeek' => array( 'validate' => array( '0', '1', '2', '3', '4', '5', '6' ), 'default' => get_bk_option( 'booking_start_day_weeek' ) )
52 );
53 }
54
55
56 /**
57 * Get default params
58 *
59 * @return array array ( 'ui_wh_modification_date_radio' => 0
60 * , ... )
61 */
62 function wpbc_setup_wizard_page__get__request_values__default(){
63
64 $request_rules_structure = wpbc_setup_wizard_page__request_rules_structure();
65
66 $default_params_arr = array();
67
68 $structure_type = 'default';
69
70 foreach ( $request_rules_structure as $key => $value ) {
71 $default_params_arr[ $key ] = $value[ $structure_type ];
72 }
73
74 return $default_params_arr;
75 }
76
77
78 // =====================================================================================================================
79 // == Get sanitised Request parameters for Ajax ==
80 // =====================================================================================================================
81
82 /**
83 * Get sanitised request parameters. | 01. -> Firstly check if user saved request params in user_meta DB.
84 * | 02. -> Otherwise check $_REQUEST.
85 * | 03. -> Otherwise Get default.
86 *
87 * @return array|false
88 */
89 function wpbc_setup_wizard_page__get_cleaned_params__saved_request_default(){
90
91 // User Specific Experience with Setup -> saved to user meta_table.
92 // E.g. next time user open the page with saved own settings
93 $user_request = new WPBC_AJX__REQUEST( array(
94 'db_option_name' => 'booking_setup_wizard_page_request_params',
95 'user_id' => wpbc_get_current_user_id(),
96 'request_rules_structure' => wpbc_setup_wizard_page__request_rules_structure()
97 )
98 );
99
100 // -----------------------------------------------------------------------------------------------------------------
101 // Get saved from DB
102 // -----------------------------------------------------------------------------------------------------------------
103 $escaped_request_params_arr = $user_request->get_sanitized__saved__user_request_params();
104
105
106 // -----------------------------------------------------------------------------------------------------------------
107 // Get $_REQUEST or Default :: This request was not saved before, then get sanitized direct parameters , such as: $_REQUEST['resource_id']
108 // -----------------------------------------------------------------------------------------------------------------
109 if ( false === $escaped_request_params_arr ) {
110 $request_prefix = false;
111 $escaped_request_params_arr = $user_request->get_sanitized__in_request__value_or_default( $request_prefix );
112 }
113
114 // -----------------------------------------------------------------------------------------------------------------
115 // == O V E R R I D E - DB params by the params from REQUEST! ==
116 // -----------------------------------------------------------------------------------------------------------------
117 $request_key = 'current_step';
118 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
119 if ( isset( $_REQUEST[ $request_key ] ) ) {
120
121 // Get SANITIZED REQUEST parameters together with default values
122 $request_prefix = false;
123 $url_request_params_arr = $user_request->get_sanitized__in_request__value_or_default( $request_prefix ); // Direct: $_REQUEST['resource_id']
124
125 // Now get only SANITIZED values that exist in REQUEST
126 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
127 $url_request_params_only_arr = array_intersect_key( $url_request_params_arr, $_REQUEST );
128
129 // And now override our DB $escaped_request_params_arr by SANITIZED $_REQUEST values
130 $escaped_request_params_arr = wp_parse_args( $url_request_params_only_arr, $escaped_request_params_arr );
131 }
132 // ---------------------------------------------------------------------------------------------------------
133
134 // //MU
135 // if ( class_exists( 'wpdev_bk_multiuser' ) ) {
136 //
137 // // Check if this MU user activated or super-admin, otherwise show warning
138 // if ( ! wpbc_is_mu_user_can_be_here('activated_user') )
139 // return false;
140 //
141 // // Check if this MU user owner of this resource or super-admin, otherwise show warning
142 // if ( ! wpbc_is_mu_user_can_be_here( 'resource_owner', $escaped_request_params_arr['resource_id'] ) ) {
143 // $default_values = $user_request->get_request_rules__default();
144 // $escaped_request_params_arr['resource_id'] = $default_values['resource_id'];
145 // }
146 // }
147
148 return $escaped_request_params_arr;
149 }
150
151
152 // =====================================================================================================================
153 // == A J A X ==
154 // =====================================================================================================================
155
156 class WPBC_AJX__Setup_Wizard__Ajax_Request {
157
158
159 /**
160 * Define HOOKs for start loading Ajax
161 */
162 public function define_ajax_hook(){
163
164 // Ajax Handlers. Note. "locale_for_ajax" rechecked in wpbc-ajax.php
165 add_action( 'wp_ajax_' . 'WPBC_AJX_SETUP_WIZARD_PAGE', array( $this, 'ajax_' . 'WPBC_AJX_SETUP_WIZARD_PAGE' ) ); // Admin & Client (logged in usres)
166
167 // Ajax Handlers for actions
168 // add_action( 'wp_ajax_nopriv_' . 'WPBC_AJX_BOOKING_LISTING', array( $this, 'ajax_' . 'WPBC_AJX_BOOKING_LISTING' ) ); // Client (not logged in)
169 }
170
171
172 /**
173 * Ajax - Get Listing Data and Response to JS script
174 */
175 public function ajax_WPBC_AJX_SETUP_WIZARD_PAGE() {
176
177 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
178 if ( ! isset( $_POST['all_ajx_params'] ) || empty( $_POST['all_ajx_params'] ) ) { exit; }
179
180 // -------------------------------------------------------------------------------------------------------------
181 // == Security == -> in Ajax Post: 'nonce': wpbc_ajx_booking_listing.get_secure_param( 'nonce' )
182 // -------------------------------------------------------------------------------------------------------------
183 $action_name = 'wpbc_setup_wizard_page_ajx' . '_wpbcnonce';
184 $nonce_post_key = 'nonce';
185 $result_check = check_ajax_referer( $action_name, $nonce_post_key );
186
187 $user_id = ( isset( $_REQUEST['wpbc_ajx_user_id'] ) ) ? intval( $_REQUEST['wpbc_ajx_user_id'] ) : wpbc_get_current_user_id(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
188
189 // -------------------------------------------------------------------------------------------------------------
190 // == Request == -> $_REQUEST['all_ajx_params']['page_num'], $_REQUEST['all_ajx_params']['page_items_count'], ...
191 // -------------------------------------------------------------------------------------------------------------
192 $user_request = new WPBC_AJX__REQUEST( array(
193 'db_option_name' => 'booking_setup_wizard_page_request_params',
194 'user_id' => $user_id,
195 'request_rules_structure' => wpbc_setup_wizard_page__request_rules_structure()
196 )
197 );
198 //--------------------------------------------------------------------------------------------------------------
199 // If in Ajax: all_ajx_params: _wpbc_settings.get_all_..() -> Use prefix "all_ajx_params" THEN Sanitize required REQUEST params
200 //--------------------------------------------------------------------------------------------------------------
201 $request_prefix = 'all_ajx_params';
202 $cleaned_request_params = $user_request->get_sanitized__in_request__value_or_default( $request_prefix ); // NOT Direct: $_REQUEST['all_ajx_params']['resource_id']
203 //--------------------------------------------------------------------------------------------------------------
204
205 $cleaned_data = array();
206 $setup_steps = new WPBC_SETUP_WIZARD_STEPS();
207
208 $data_arr = array();
209 $data_arr['ajx_after_action_message'] = '';
210 $data_arr['ajx_after_action_result'] = 1; // Message Type: ? '1' => 'success' : 'error'
211 //--------------------------------------------------------------------------------------------------------------
212 // Steps
213 //--------------------------------------------------------------------------------------------------------------
214 $data_arr['current_step'] = ( ! empty( $cleaned_request_params['current_step'] )
215 ? $cleaned_request_params['current_step']
216 : $setup_steps->get_active_step_name() ); // e.g. 'general_info' or 'optional_other_settings'
217 $data_arr['steps'] = $setup_steps->get_steps_arr();
218
219 // -------------------------------------------------------------------------------------------------------------
220 // Get Wizard history
221 // -------------------------------------------------------------------------------------------------------------
222 $booking_wizard_data_arr = get_bk_option( 'booking_wizard_data' );
223 $booking_wizard_data_arr = ( empty( $booking_wizard_data_arr ) ) ? array() : $booking_wizard_data_arr;
224
225
226 // =============================================================================================================
227 // == Do Action ==
228 // =============================================================================================================
229 switch ( $cleaned_request_params['do_action'] ) {
230
231 // ---------------------------------------------------------------------------------------------------------
232 // == RESET ==
233 // ---------------------------------------------------------------------------------------------------------
234 case 'make_reset':
235
236 $is_reseted = $user_request->user_request_params__db_delete(); // Delete from DB
237
238 $cleaned_request_params['do_action'] = $is_reseted ? 'reset_done' : 'reset_error';
239
240 $cleaned_request_params = wpbc_setup_wizard_page__get__request_values__default();
241
242 $data_arr['ajx_after_action_message'] = __( 'Start Setup from Beginning', 'booking' );
243
244 $data_arr['current_step'] = 'welcome';
245
246 update_bk_option( 'booking_wizard_data', array() );
247
248 $setup_steps->db__set_all_steps_as( false ); // Clear All Steps Mark as Undone
249 break;
250
251 case 'skip_wizard':
252
253 $data_arr['current_step'] = 'welcome';
254 // $data_arr['redirect_url'] = wpbc_get_settings_url();
255 $data_arr['redirect_url'] = wpbc_get_bookings_url();
256
257 $setup_steps->db__set_all_steps_as( true ); // Mark All Steps as Done
258
259 break;
260
261 case 'save_and_continue__welcome':
262
263 $setup_steps->db__set_step_as_completed( 'welcome' );
264 break;
265
266 case 'save_and_continue__general_info':
267
268 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
269 if ( isset( $_POST['all_ajx_params']['step_data'] ) && ( ! empty( $_POST['all_ajx_params']['step_data'] ) ) ) {
270 $cleaned_data = wpbc_template__general_info__action_validate_data( $_POST['all_ajx_params']['step_data'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
271
272 if ( 'On' === $cleaned_data['wpbc_swp_accept_send'] ) {
273 //wpbc_setup_feedback__send_email( $cleaned_data ); // FixIn: 10.7.1.3.
274 update_bk_option( 'booking_feedback__send_email', $cleaned_data );
275 } else {
276 delete_bk_option( 'booking_feedback__send_email' );
277 }
278
279 wpbc_setup__update__general_info( $cleaned_data );
280 }
281
282 $setup_steps->db__set_step_as_completed( 'general_info' );
283 break;
284
285 case 'save_and_continue__date_time_formats':
286
287 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
288 if ( isset( $_POST['all_ajx_params']['step_data'] ) && ( ! empty( $_POST['all_ajx_params']['step_data'] ) ) ) {
289 $cleaned_data = wpbc_template__date_time_formats__action_validate_data( $_POST['all_ajx_params']['step_data'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
290 wpbc_setup__update__date_time_formats( $cleaned_data );
291 }
292
293 $setup_steps->db__set_step_as_completed( 'date_time_formats' );
294 break;
295
296 case 'save_and_continue__bookings_types':
297
298 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
299 if ( isset( $_POST['all_ajx_params']['step_data'] ) && ( ! empty( $_POST['all_ajx_params']['step_data'] ) ) ) {
300 $cleaned_data = wpbc_template__bookings_types__action_validate_data( $_POST['all_ajx_params']['step_data'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
301
302 // Legacy update booking form and dates selection, as some other options (recurrent time)....
303 wpbc_setup__update__bookings_types( $cleaned_data );
304
305 // FixIn: 10.7.1.3. // FixIn: 10.15.1.1.
306 $cleaned_data_booking_feedback_arr = get_bk_option( 'booking_feedback__send_email' );
307 if (! empty($cleaned_data_booking_feedback_arr)){
308 if ( 'On' === $cleaned_data_booking_feedback_arr['wpbc_swp_accept_send'] ) {
309 $cleaned_data_booking_feedback_arr = array_merge( $cleaned_data_booking_feedback_arr , array( 'type' => 'Type: ' . $cleaned_data ['wpbc_swp_booking_types'] ) );
310 if ( 'time_slots_appointments' === $cleaned_data ['wpbc_swp_booking_types'] ) {
311 $cleaned_data_booking_feedback_arr = array_merge( $cleaned_data_booking_feedback_arr, array( 'appointments_type' => 'Appointment: ' . $cleaned_data ['wpbc_swp_booking_appointments_type'] ) );
312 }
313 wpbc_setup_feedback__send_email( $cleaned_data_booking_feedback_arr );
314 update_bk_option( 'booking_feedback__after_send', $cleaned_data_booking_feedback_arr );
315 delete_bk_option( 'booking_feedback__send_email' );
316 }
317 }
318
319 $is_bfb_enabled = (bool) WPBC_Frontend_Settings::is_bfb_enabled( null );
320 if ( $is_bfb_enabled ) {
321 $or_sep_url = ( defined( 'WPBC_BFB_TEMPLATE_SEARCH_OR_SEPARATOR_URL' ) ) ? (string) WPBC_BFB_TEMPLATE_SEARCH_OR_SEPARATOR_URL : '^';
322 if ( '' === $or_sep_url ) {
323 $or_sep_url = '^';
324 }
325 $template_search_key = '';
326 if ( 'full_days_bookings' === $cleaned_data['wpbc_swp_booking_types'] ) {
327 $template_search_key = 'full-days' . $or_sep_url . 'dates_form';
328 }
329 if ( 'time_slots_appointments' === $cleaned_data['wpbc_swp_booking_types'] ) {
330 if ( 'rangetime' !== $cleaned_data['wpbc_swp_booking_appointments_type'] ) {
331 $template_search_key = 'appointments';// . $or_sep_url . 'duration';
332 } else {
333 $template_search_key = 'time+slots' . $or_sep_url . 'times';
334 }
335 }
336 if ( 'changeover_multi_dates_bookings' === $cleaned_data['wpbc_swp_booking_types'] ) {
337 $template_search_key = 'changeover' . $or_sep_url . 'triangles';
338 }
339 // JavaScript redirect: wpbc_redirect( 'url' ); // PHP: redirect:.
340 // wp_redirect( admin_url( 'admin.php?page=wpbc-settings&tab=builder_booking_form&auto_open_template=' . $cleaned_data ) );
341
342 $cleaned_request_params['do_action'] = 'auto_open_template';
343 $data_arr['redirect_url'] = admin_url( 'admin.php?page=wpbc-settings&tab=builder_booking_form&auto_open_template=' . $template_search_key );
344 $data_arr['current_step'] = 'cal_availability';
345 // Mark as completed, Type of bookings and Form structure!
346 $setup_steps->db__set_step_as_completed( 'bookings_types' );
347 $setup_steps->db__set_step_as_completed( 'form_structure' );
348 break;
349 }
350
351
352 // -------------------------------------------------------------------------------------------------
353 // Save selected option at the next step for paid versions
354 // -------------------------------------------------------------------------------------------------
355 $booking_wizard_data_arr[ 'load_form_template' ] = array();
356 if ( class_exists( 'wpdev_bk_personal' ) ) {
357 if ( 'full_days_bookings' === $cleaned_data['wpbc_swp_booking_types'] ) {
358 $booking_wizard_data_arr['load_form_template'] ['wpbc_swp_booking_form_template_pro'] = 'pro|hints-dev';
359 }
360 if ( 'time_slots_appointments' === $cleaned_data['wpbc_swp_booking_types'] ) {
361 if ( 'durationtime' === $cleaned_data['wpbc_swp_booking_appointments_type'] ) {
362 $booking_wizard_data_arr['load_form_template'] ['wpbc_swp_booking_form_template_pro'] = 'pro|appointments_service_c'; // FixIn: 10.7.1.4.
363 } else {
364 $booking_wizard_data_arr['load_form_template'] ['wpbc_swp_booking_form_template_pro'] = 'pro|appointments30'; // FixIn: 10.7.1.4.
365 }
366 }
367 if ( 'changeover_multi_dates_bookings' === $cleaned_data['wpbc_swp_booking_types'] ) {
368 $booking_wizard_data_arr['load_form_template'] ['wpbc_swp_booking_form_template_pro'] = 'pro|wizard';
369 }
370 }
371 // -------------------------------------------------------------------------------------------------
372 }
373
374 $setup_steps->db__set_step_as_completed( 'bookings_types' );
375 break;
376
377 case 'save_and_continue__form_structure':
378
379 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
380 if ( isset( $_POST['all_ajx_params']['step_data'] ) && ( ! empty( $_POST['all_ajx_params']['step_data'] ) ) ) {
381 $cleaned_data = wpbc_template__form_structure__action_validate_data( $_POST['all_ajx_params']['step_data'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
382 wpbc_setup__update__form_structure( $cleaned_data );
383 }
384
385 $setup_steps->db__set_step_as_completed( 'form_structure' );
386 break;
387
388 case 'load_form_template':
389
390 if (
391 ( 'form_structure' === $data_arr['current_step'] )
392 && ( isset( $_POST['all_ajx_params']['step_data'] ) && ( ! empty( $_POST['all_ajx_params']['step_data'] ) ) )
393 ){
394 $cleaned_data = wpbc_template__form_structure__action_validate_data( $_POST['all_ajx_params']['step_data'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
395 wpbc_setup__update__form_structure( $cleaned_data );
396 }
397 if (
398 ( 'cal_availability' === $data_arr['current_step'] )
399 && ( isset( $_POST['all_ajx_params']['step_data'] ) && ( ! empty( $_POST['all_ajx_params']['step_data'] ) ) )
400 ){
401 $cleaned_data = wpbc_template__cal_availability__action_validate_data( $_POST['all_ajx_params']['step_data'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
402 wpbc_setup__update__cal_availability( $cleaned_data );
403 }
404 if (
405 ( 'color_theme' === $data_arr['current_step'] )
406 && ( isset( $_POST['all_ajx_params']['step_data'] ) && ( ! empty( $_POST['all_ajx_params']['step_data'] ) ) )
407 ){
408 $cleaned_data = wpbc_template__color_theme__action_validate_data( $_POST['all_ajx_params']['step_data'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
409 wpbc_setup__update__color_theme( $cleaned_data );
410 }
411
412 break;
413
414 case 'save_and_continue__cal_availability':
415
416 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
417 if ( isset( $_POST['all_ajx_params']['step_data'] ) && ( ! empty( $_POST['all_ajx_params']['step_data'] ) ) ) {
418 $cleaned_data = wpbc_template__cal_availability__action_validate_data( $_POST['all_ajx_params']['step_data'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
419 wpbc_setup__update__cal_availability( $cleaned_data );
420 }
421
422 $setup_steps->db__set_step_as_completed( 'cal_availability' );
423 break;
424
425 case 'save_and_continue__color_theme':
426
427 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
428 if ( isset( $_POST['all_ajx_params']['step_data'] ) && ( ! empty( $_POST['all_ajx_params']['step_data'] ) ) ) {
429 $cleaned_data = wpbc_template__color_theme__action_validate_data( $_POST['all_ajx_params']['step_data'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
430 wpbc_setup__update__color_theme( $cleaned_data );
431 }
432
433 $setup_steps->db__set_step_as_completed( 'color_theme' );
434 break;
435
436 case 'save_and_continue__optional_other_settings':
437
438 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
439 if ( isset( $_POST['all_ajx_params']['step_data'] ) && ( ! empty( $_POST['all_ajx_params']['step_data'] ) ) ) {
440 $cleaned_data = wpbc_template__optional_other_settings__action_validate_data( $_POST['all_ajx_params']['step_data'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
441 wpbc_setup__update__optional_other_settings( $cleaned_data );
442 }
443 $setup_steps->db__set_step_as_completed( 'optional_other_settings' );
444 break;
445
446 case 'save_and_continue__wizard_publish':
447
448 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
449 if ( isset( $_POST['all_ajx_params']['step_data'] ) && ( ! empty( $_POST['all_ajx_params']['step_data'] ) ) ) {
450 $cleaned_data = wpbc_template__wizard_publish__action_validate_data( $_POST['all_ajx_params']['step_data'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
451 wpbc_setup__update__wizard_publish( $cleaned_data );
452 }
453 $setup_steps->db__set_step_as_completed( 'wizard_publish' );
454 break;
455
456 case 'save_and_continue__get_started':
457
458 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
459 if ( isset( $_POST['all_ajx_params']['step_data'] ) && ( ! empty( $_POST['all_ajx_params']['step_data'] ) ) ) {
460 $cleaned_data = wpbc_template__get_started__action_validate_data( $_POST['all_ajx_params']['step_data'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
461 wpbc_setup__update__get_started( $cleaned_data );
462 }
463 $setup_steps->db__set_step_as_completed( 'get_started' );
464 break;
465
466
467 default:
468 // Default
469 }
470
471 //--------------------------------------------------------------------------------------------------------------
472 // Other
473 //--------------------------------------------------------------------------------------------------------------
474 $data_arr['steps_is_done'] = $setup_steps->db__get_steps_is_done();
475 $data_arr['left_navigation'] = wpbc_setup_wizard_page__get_left_navigation_menu_arr();
476 $data_arr['plugin_menu__setup_progress'] = $setup_steps->get_plugin_menu_title__setup_progress();
477
478 //--------------------------------------------------------------------------------------------------------------
479 // Load Calendar depend on Step
480 //--------------------------------------------------------------------------------------------------------------
481 $data_arr['ui'] = array();
482
483 switch ( $data_arr['current_step'] ) {
484
485 case 'form_structure':
486 $data_arr['calendar_force_load'] = '';
487
488 if ( 'save_and_continue__bookings_types' === $cleaned_request_params['do_action'] ) {
489 // We need to reload the calendar skins, because at the previous step 'Booking Types' we updated the calendar skins relative to selected options
490 ob_start();
491 ?>
492 <script type="text/javascript">
493 jQuery( document ).ready( function () {
494 wpbc__calendar__change_skin( '<?php echo esc_url( WPBC_PLUGIN_URL . get_bk_option( 'booking_skin' ) ); ?>' );
495 wpbc__css__change_skin( '<?php echo esc_url( WPBC_PLUGIN_URL . get_bk_option( 'booking_timeslot_picker_skin' ) ); ?>' );
496 } );
497 </script><?php
498 $data_arr['calendar_force_load'] .= ob_get_clean();
499 }
500 $data_arr['calendar_force_load'] .= wpbc_setup_wizard_page__get_shortcode_html( $cleaned_request_params['resource_id'] );
501 break;
502
503 case 'cal_availability':
504
505 $data_arr['calendar_force_load'] = wpbc_setup_wizard_page__get_shortcode_html( $cleaned_request_params['resource_id'] );
506
507 // -----------------------------------------------------------------------------------------------------
508 // == UNAVAILABLE WeekDays ==
509 // -----------------------------------------------------------------------------------------------------
510 $data_arr['ui']['booking_unavailable_day'] = array();
511 for ( $wdi = 0; $wdi < 7; $wdi ++ ) {
512 if ( get_bk_option( 'booking_unavailable_day' . $wdi ) == 'On' ) {
513 $data_arr['ui']['booking_unavailable_day'][] = $wdi;
514 }
515 }
516
517 /**
518 * $unavailable_from_today_arr = [
519 * booking_unavailable_days_num_from_today = "540m"
520 * booking_unavailable_days_num_from_today__hint = ": 2025-01-25 15:19 - 2025-01-26 00:18:42"
521 * booking_available_days_num_from_today = "0"
522 * booking_available_days_num_from_today__hint = ": 26 Jan, 2025 - ..."
523 * ]
524 */
525 $unavailable_from_today_arr = wpbc_get_unavailable_from_today_hints_arr();
526
527 $data_arr['ui']['booking_unavailable_days_num_from_today'] = $unavailable_from_today_arr['booking_unavailable_days_num_from_today'];
528 $data_arr['ui']['booking_unavailable_days_num_from_today__hint'] = $unavailable_from_today_arr['booking_unavailable_days_num_from_today__hint'];
529 $data_arr['ui']['booking_available_days_num_from_today'] = $unavailable_from_today_arr['booking_available_days_num_from_today'];
530 $data_arr['ui']['booking_available_days_num_from_today__hint'] = $unavailable_from_today_arr['booking_available_days_num_from_today__hint'];
531 if(0){
532 // -----------------------------------------------------------------------------------------------------
533 // == UNAVAILABLE Today days ==
534 // -----------------------------------------------------------------------------------------------------
535 // FixIn: 10.8.1.4.
536 $last_unavailable_date = '';
537 if ( 'm' === substr( get_bk_option( 'booking_unavailable_days_num_from_today' ), - 1 ) ) {
538 // -------------------------------------------------------------------------------------------------
539 // == Minutes ==
540 // -------------------------------------------------------------------------------------------------
541 $data_arr['ui']['booking_unavailable_days_num_from_today'] = intval( get_bk_option( 'booking_unavailable_days_num_from_today' ) );
542
543 // Hints.
544 $data_arr['ui']['booking_unavailable_days_num_from_today__hint'] = ': <span style="text-transform: lowercase;font-size:0.9em;">'
545 . __( 'None', 'booking' ) . '</span>';
546 if ( ! empty( $data_arr['ui']['booking_unavailable_days_num_from_today'] ) ) {
547
548 $start_date_unix = strtotime( 'now' );
549 $todate_with_wp_timezone = wpbc_datetime_localized__use_wp_timezone( gmdate( 'Y-m-d H:i:s', $start_date_unix ), 'Y-m-d H:i' );
550
551 $start_date_unix = strtotime( '+' . ( intval( $data_arr['ui']['booking_unavailable_days_num_from_today'] ) - 1 ) . ' minutes' );
552 $max_date_with_wp_timezone = wpbc_datetime_localized__use_wp_timezone( gmdate( 'Y-m-d H:i:s', $start_date_unix ), 'Y-m-d H:i:s' );
553
554 $last_unavailable_date = $max_date_with_wp_timezone;
555
556 $data_arr['ui']['booking_unavailable_days_num_from_today__hint'] = ': ' . $todate_with_wp_timezone . ' - ' . $max_date_with_wp_timezone; // FixIn: 10.9.4.2.
557 }
558 $data_arr['ui']['booking_unavailable_days_num_from_today'] .= 'm';
559 } else {
560 // -------------------------------------------------------------------------------------------------
561 // == Days ==
562 // -------------------------------------------------------------------------------------------------
563 $data_arr['ui']['booking_unavailable_days_num_from_today'] = intval( get_bk_option( 'booking_unavailable_days_num_from_today' ) );
564
565 // Hints.
566 $data_arr['ui']['booking_unavailable_days_num_from_today__hint'] = ': <span style="text-transform: lowercase;font-size:0.9em;">' . __( 'None', 'booking' ) . '</span>';
567
568 if ( 1 === $data_arr['ui']['booking_unavailable_days_num_from_today'] ) {
569 $last_unavailable_date = wp_date( 'Y-m-d 00:00:00' );
570 $data_arr['ui']['booking_unavailable_days_num_from_today__hint'] = ': ' . wp_date( 'd M', strtotime( $last_unavailable_date ) );
571 }
572 if ( $data_arr['ui']['booking_unavailable_days_num_from_today'] > 1 ) {
573 $last_unavailable_date = wp_date( 'Y-m-d 00:00:00', strtotime( '+' . ( $data_arr['ui']['booking_unavailable_days_num_from_today'] - 1 ) . ' days' ) );
574 $data_arr['ui']['booking_unavailable_days_num_from_today__hint'] = ': ' . wp_date( 'd M' ) . ' - ' . wp_date( 'd M', strtotime( $last_unavailable_date ) );
575 }
576 }
577
578 // -----------------------------------------------------------------------------------------------------
579 // == AVAILABLE Today days ==
580 // -----------------------------------------------------------------------------------------------------
581 // if ( class_exists( 'wpdev_bk_biz_m' ) ) { .
582 $data_arr['ui']['booking_available_days_num_from_today'] = esc_js( get_bk_option( 'booking_available_days_num_from_today' ) );
583
584 // Hints.
585 // $start_available_date = ( '' === $last_unavailable_date ) ? wp_date( 'Y-m-d 00:00:00' ) : wp_date( 'Y-m-d 00:00:00', strtotime( '+1 day', strtotime( $last_unavailable_date ) ) );
586 if ( '' === $last_unavailable_date ) {
587 $start_date_unix = strtotime( 'now' );
588 $todate_with_wp_timezone = wpbc_datetime_localized__use_wp_timezone( gmdate( 'Y-m-d H:i:s', $start_date_unix ), 'Y-m-d 00:00:00' );
589 $start_available_date = $todate_with_wp_timezone;
590 } else {
591 $start_available_date = $last_unavailable_date;
592 // We use here with no WP timezone, because timezone already applied to $last_unavailable_date.
593 $start_available_date = wpbc_datetime_localized__no_wp_timezone( strtotime( $last_unavailable_date ), 'Y-m-d 00:00:00' );
594 }
595
596
597 if ( empty( $data_arr['ui']['booking_available_days_num_from_today'] ) ) {
598 $last_available_date = '';
599 } else {
600 // $last_available_date = wp_date( 'Y-m-d 00:00:00', strtotime( '+' . ( $data_arr['ui']['booking_available_days_num_from_today'] ) . ' days' ) );
601 // FixIn: 10.9.6.3.
602 $start_date_unix = strtotime( '+' . ( intval( $data_arr['ui']['booking_available_days_num_from_today'] ) - 1 ) . ' days' );
603 $last_available_date = wpbc_datetime_localized__use_wp_timezone( gmdate( 'Y-m-d H:i:s', $start_date_unix ), 'Y-m-d 00:00:00' );
604 }
605
606 if ( ! empty( $data_arr['ui']['booking_available_days_num_from_today'] ) ) {
607
608 if ( strtotime( $start_available_date ) < strtotime( $last_available_date ) ) {
609
610 $data_arr['ui']['booking_available_days_num_from_today__hint'] = ': ' . wp_date( 'd M, Y', strtotime( $start_available_date ) ) . ' - ' . wp_date( 'd M, Y', strtotime( $last_available_date ) );
611 } else if ( strtotime( $start_available_date ) == strtotime( $last_available_date ) ) {
612 $data_arr['ui']['booking_available_days_num_from_today__hint'] = ': ' . wp_date( 'd M, Y', strtotime( $start_available_date ) );
613 } else {
614 $data_arr['ui']['booking_available_days_num_from_today__hint'] = ': <span style="text-transform: uppercase;font-size:1.1em;">' . esc_html__( 'None', 'booking' ) . '</span><br>' .
615 ' <span style="text-transform: lowercase;font-size:0.9em;color:#cc3a5f;">' .
616 'Start available' . ': ' . wp_date( 'd M, Y', strtotime( $start_available_date ) ) . '<br>' .
617 'Last available' . ': ' . wp_date( 'd M, Y', strtotime( $last_available_date ) ) . '</span>';
618 }
619 } else {
620 $data_arr['ui']['booking_available_days_num_from_today__hint'] = ': ' . wp_date( 'd M, Y', strtotime( $start_available_date ) ) . ' - ...';
621 }
622 }
623
624 $data_arr['ui']['booking_unavailable_extra_in_out'] = get_bk_option( 'booking_unavailable_extra_in_out' );
625 $data_arr['ui']['booking_unavailable_extra_minutes_in'] = get_bk_option( 'booking_unavailable_extra_minutes_in' );
626 $data_arr['ui']['booking_unavailable_extra_minutes_out'] = get_bk_option( 'booking_unavailable_extra_minutes_out' );
627 $data_arr['ui']['booking_unavailable_extra_days_in'] = get_bk_option( 'booking_unavailable_extra_days_in' );
628 $data_arr['ui']['booking_unavailable_extra_days_out'] = get_bk_option( 'booking_unavailable_extra_days_out' );
629
630 break;
631
632 case 'color_theme':
633
634 $data_arr['calendar_force_load'] = wpbc_setup_wizard_page__get_shortcode_html( $cleaned_request_params['resource_id'] );
635 $data_arr['ui']['booking_form_theme'] = get_bk_option( 'booking_form_theme' );
636 $data_arr['ui']['booking_skin'] = get_bk_option( 'booking_skin' );
637 $data_arr['ui']['booking_timeslot_picker_skin'] = get_bk_option( 'booking_timeslot_picker_skin' );
638 break;
639
640 case 'optional_other_settings':
641 $data_arr['calendar_force_load'] = '';//wpbc_setup_wizard_page__get_shortcode_html( $cleaned_request_params['resource_id'] );
642 break;
643
644 case 'wizard_publish':
645 $data_arr['calendar_force_load'] = '';//wpbc_setup_wizard_page__get_shortcode_html( $cleaned_request_params['resource_id'] );
646 break;
647
648 case 'get_started':
649 $data_arr['calendar_force_load'] = '';//wpbc_setup_wizard_page__get_shortcode_html( $cleaned_request_params['resource_id'] );
650 break;
651
652 default:
653 $data_arr['calendar_force_load'] = '';
654 }
655
656
657 // -------------------------------------------------------------------------------------------------------------
658 // Save Wizard history
659 // -------------------------------------------------------------------------------------------------------------
660 // Save to DB
661 $booking_wizard_data_arr[ $cleaned_request_params['do_action'] ] = $cleaned_data;
662 update_bk_option( 'booking_wizard_data', $booking_wizard_data_arr );
663 // Ajax Transfer
664 $data_arr['booking_wizard_data'] = $booking_wizard_data_arr;
665 // -------------------------------------------------------------------------------------------------------------
666
667 //TODO: delete this ?
668 if(0){
669
670 $data_arr['customize_steps'] = array();
671 $data_arr['customize_steps']['action'] = 'none';
672
673 // Actions =================================================================================================
674
675 if ( 'save_calendar_additional' == $cleaned_request_params['do_action'] ) {
676
677 $is_updated = update_bk_option( 'booking_max_monthes_in_calendar', $cleaned_request_params['calendar__booking_max_monthes_in_calendar'] );
678 $is_updated = update_bk_option( 'booking_start_day_weeek', $cleaned_request_params['calendar__booking_start_day_weeek'] );
679 }
680
681 //----------------------------------------------------------------------------------------------------------
682
683 // Get booking resources (sql)
684 $resources_arr = wpbc_ajx_get_all_booking_resources_arr(); /**
685 * Array ( [0] => Array ( [booking_type_id] => 1
686 [title] => Standard
687 [users] => 1
688 [import] =>
689 [export] =>
690 [cost] => 25
691 [default_form] => standard
692 [prioritet] => 0
693 [parent] => 0
694 [visitors] => 2
695 ), ... */
696
697 $resources_arr_sorted = wpbc_ajx_get_sorted_booking_resources_arr( $resources_arr );
698
699 $data_arr['ajx_booking_resources'] = $resources_arr_sorted;
700 }
701
702
703 // -------------------------------------------------------------------------------------------------------------
704 // Save Status of Wizard for specific user
705 // -------------------------------------------------------------------------------------------------------------
706 if ( 'make_reset' !== $cleaned_request_params['do_action'] ) {
707
708 $request_params_to_save = $cleaned_request_params;
709
710 // Do not safe such elements
711 unset( $request_params_to_save['ui_clicked_element_id'] );
712 unset( $request_params_to_save['do_action'] );
713 unset( $request_params_to_save['calendar_force_load'] );
714 unset( $request_params_to_save['plugin_menu__setup_progress'] );
715
716 $is_success_update = $user_request->user_request_params__db_save( $request_params_to_save ); // Save to DB // - $cleaned_request_params - serialized here automatically
717 }
718
719 if ( ! empty( $data_arr['calendar_force_load'] ) ) {
720 $data_arr['calendar_force_load'] = wpbc_clean_calendar_loading_scripts( $data_arr['calendar_force_load'] );
721 }
722 // -------------------------------------------------------------------------------------------------------------
723 // Send JSON. It will make "wp_json_encode" - so pass only array, and This function call wp_die( '', '', array( 'response' => null, ) ) Pass JS OBJ: response_data in "jQuery.post( " function on success.
724 // -------------------------------------------------------------------------------------------------------------
725 wp_send_json( array(
726 'ajx_data' => $data_arr,
727 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
728 'ajx_all_ajx_params' => $_REQUEST[ $request_prefix ], // $_REQUEST[ 'all_ajx_params' ]
729 'ajx_cleaned_params' => $cleaned_request_params
730 ) );
731 }
732
733 }
734
735 /**
736 * Just for loading CSS and JavaScript files
737 */
738 if ( true ) {
739 $wpbc_setup_wizard_page_loading = new WPBC_AJX__Setup_Wizard__Ajax_Request;
740 $wpbc_setup_wizard_page_loading->define_ajax_hook();
741 }