PluginProbe
Booking Calendar / 10.10
Booking Calendar v10.10
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 10.11.3 All 202 releases
booking / includes / page-setup / setup_ajax.php

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

697 lines 39.4 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
256 $setup_steps->db__set_all_steps_as( true ); // Mark All Steps as Done
257
258 break;
259
260 case 'save_and_continue__welcome':
261
262 $setup_steps->db__set_step_as_completed( 'welcome' );
263 break;
264
265 case 'save_and_continue__general_info':
266
267 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
268 if ( isset( $_POST['all_ajx_params']['step_data'] ) && ( ! empty( $_POST['all_ajx_params']['step_data'] ) ) ) {
269 $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
270
271 if ( 'On' === $cleaned_data['wpbc_swp_accept_send'] ) {
272 //wpbc_setup_feedback__send_email( $cleaned_data ); // FixIn: 10.7.1.3.
273 update_bk_option( 'booking_feedback__send_email', $cleaned_data );
274 } else {
275 delete_bk_option( 'booking_feedback__send_email' );
276 }
277
278 wpbc_setup__update__general_info( $cleaned_data );
279 }
280
281 $setup_steps->db__set_step_as_completed( 'general_info' );
282 break;
283
284 case 'save_and_continue__date_time_formats':
285
286 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
287 if ( isset( $_POST['all_ajx_params']['step_data'] ) && ( ! empty( $_POST['all_ajx_params']['step_data'] ) ) ) {
288 $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
289 wpbc_setup__update__date_time_formats( $cleaned_data );
290 }
291
292 $setup_steps->db__set_step_as_completed( 'date_time_formats' );
293 break;
294
295 case 'save_and_continue__bookings_types':
296
297 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
298 if ( isset( $_POST['all_ajx_params']['step_data'] ) && ( ! empty( $_POST['all_ajx_params']['step_data'] ) ) ) {
299 $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
300 wpbc_setup__update__bookings_types( $cleaned_data );
301
302 // FixIn: 10.7.1.3.
303 $cleaned_data_booking_feedback_arr = get_bk_option( 'booking_feedback__send_email' );
304 if (! empty($cleaned_data_booking_feedback_arr)){
305 if ( 'On' === $cleaned_data_booking_feedback_arr['wpbc_swp_accept_send'] ) {
306 $cleaned_data_booking_feedback_arr = array_merge( $cleaned_data_booking_feedback_arr , array( 'type' => 'Type: ' . $cleaned_data ['wpbc_swp_booking_types'] ) );
307 wpbc_setup_feedback__send_email( $cleaned_data_booking_feedback_arr );
308 delete_bk_option( 'booking_feedback__send_email' );
309 }
310 }
311
312 // -------------------------------------------------------------------------------------------------
313 // Save selected option at the next step for paid versions
314 // -------------------------------------------------------------------------------------------------
315 $booking_wizard_data_arr[ 'load_form_template' ] = array();
316 if ( class_exists( 'wpdev_bk_personal' ) ) {
317 if ( 'full_days_bookings' === $cleaned_data['wpbc_swp_booking_types'] ) {
318 $booking_wizard_data_arr['load_form_template'] ['wpbc_swp_booking_form_template_pro'] = 'pro|hints-dev';
319 }
320 if ( 'time_slots_appointments' === $cleaned_data['wpbc_swp_booking_types'] ) {
321 $booking_wizard_data_arr['load_form_template'] ['wpbc_swp_booking_form_template_pro'] = 'pro|appointments30'; // FixIn: 10.7.1.4.
322 }
323 if ( 'changeover_multi_dates_bookings' === $cleaned_data['wpbc_swp_booking_types'] ) {
324 $booking_wizard_data_arr['load_form_template'] ['wpbc_swp_booking_form_template_pro'] = 'pro|wizard';
325 }
326 }
327 // -------------------------------------------------------------------------------------------------
328 }
329
330 $setup_steps->db__set_step_as_completed( 'bookings_types' );
331 break;
332
333 case 'save_and_continue__form_structure':
334
335 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
336 if ( isset( $_POST['all_ajx_params']['step_data'] ) && ( ! empty( $_POST['all_ajx_params']['step_data'] ) ) ) {
337 $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
338 wpbc_setup__update__form_structure( $cleaned_data );
339 }
340
341 $setup_steps->db__set_step_as_completed( 'form_structure' );
342 break;
343
344 case 'load_form_template':
345
346 if (
347 ( 'form_structure' === $data_arr['current_step'] )
348 && ( isset( $_POST['all_ajx_params']['step_data'] ) && ( ! empty( $_POST['all_ajx_params']['step_data'] ) ) )
349 ){
350 $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
351 wpbc_setup__update__form_structure( $cleaned_data );
352 }
353 if (
354 ( 'cal_availability' === $data_arr['current_step'] )
355 && ( isset( $_POST['all_ajx_params']['step_data'] ) && ( ! empty( $_POST['all_ajx_params']['step_data'] ) ) )
356 ){
357 $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
358 wpbc_setup__update__cal_availability( $cleaned_data );
359 }
360 if (
361 ( 'color_theme' === $data_arr['current_step'] )
362 && ( isset( $_POST['all_ajx_params']['step_data'] ) && ( ! empty( $_POST['all_ajx_params']['step_data'] ) ) )
363 ){
364 $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
365 wpbc_setup__update__color_theme( $cleaned_data );
366 }
367
368 break;
369
370 case 'save_and_continue__cal_availability':
371
372 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
373 if ( isset( $_POST['all_ajx_params']['step_data'] ) && ( ! empty( $_POST['all_ajx_params']['step_data'] ) ) ) {
374 $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
375 wpbc_setup__update__cal_availability( $cleaned_data );
376 }
377
378 $setup_steps->db__set_step_as_completed( 'cal_availability' );
379 break;
380
381 case 'save_and_continue__color_theme':
382
383 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
384 if ( isset( $_POST['all_ajx_params']['step_data'] ) && ( ! empty( $_POST['all_ajx_params']['step_data'] ) ) ) {
385 $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
386 wpbc_setup__update__color_theme( $cleaned_data );
387 }
388
389 $setup_steps->db__set_step_as_completed( 'color_theme' );
390 break;
391
392 case 'save_and_continue__optional_other_settings':
393
394 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
395 if ( isset( $_POST['all_ajx_params']['step_data'] ) && ( ! empty( $_POST['all_ajx_params']['step_data'] ) ) ) {
396 $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
397 wpbc_setup__update__optional_other_settings( $cleaned_data );
398 }
399 $setup_steps->db__set_step_as_completed( 'optional_other_settings' );
400 break;
401
402 case 'save_and_continue__wizard_publish':
403
404 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
405 if ( isset( $_POST['all_ajx_params']['step_data'] ) && ( ! empty( $_POST['all_ajx_params']['step_data'] ) ) ) {
406 $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
407 wpbc_setup__update__wizard_publish( $cleaned_data );
408 }
409 $setup_steps->db__set_step_as_completed( 'wizard_publish' );
410 break;
411
412 case 'save_and_continue__get_started':
413
414 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
415 if ( isset( $_POST['all_ajx_params']['step_data'] ) && ( ! empty( $_POST['all_ajx_params']['step_data'] ) ) ) {
416 $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
417 wpbc_setup__update__get_started( $cleaned_data );
418 }
419 $setup_steps->db__set_step_as_completed( 'get_started' );
420 break;
421
422
423 default:
424 // Default
425 }
426
427 //--------------------------------------------------------------------------------------------------------------
428 // Other
429 //--------------------------------------------------------------------------------------------------------------
430 $data_arr['steps_is_done'] = $setup_steps->db__get_steps_is_done();
431 $data_arr['left_navigation'] = wpbc_setup_wizard_page__get_left_navigation_menu_arr();
432 $data_arr['plugin_menu__setup_progress'] = $setup_steps->get_plugin_menu_title__setup_progress();
433
434 //--------------------------------------------------------------------------------------------------------------
435 // Load Calendar depend on Step
436 //--------------------------------------------------------------------------------------------------------------
437 $data_arr['ui'] = array();
438
439 switch ( $data_arr['current_step'] ) {
440
441 case 'form_structure':
442 $data_arr['calendar_force_load'] = '';
443
444 if ( 'save_and_continue__bookings_types' === $cleaned_request_params['do_action'] ) {
445 // We need to reload the calendar skins, because at the previous step 'Booking Types' we updated the calendar skins relative to selected options
446 ob_start();
447 ?>
448 <script type="text/javascript">
449 jQuery( document ).ready( function () {
450 wpbc__calendar__change_skin( '<?php echo esc_url( WPBC_PLUGIN_URL . get_bk_option( 'booking_skin' ) ); ?>' );
451 wpbc__css__change_skin( '<?php echo esc_url( WPBC_PLUGIN_URL . get_bk_option( 'booking_timeslot_picker_skin' ) ); ?>' );
452 } );
453 </script><?php
454 $data_arr['calendar_force_load'] .= ob_get_clean();
455 }
456 $data_arr['calendar_force_load'] .= wpbc_setup_wizard_page__get_shortcode_html( $cleaned_request_params['resource_id'] );
457 break;
458
459 case 'cal_availability':
460
461 $data_arr['calendar_force_load'] = wpbc_setup_wizard_page__get_shortcode_html( $cleaned_request_params['resource_id'] );
462
463 // -----------------------------------------------------------------------------------------------------
464 // == UNAVAILABLE WeekDays ==
465 // -----------------------------------------------------------------------------------------------------
466 $data_arr['ui']['booking_unavailable_day'] = array();
467 for ( $wdi = 0; $wdi < 7; $wdi ++ ) {
468 if ( get_bk_option( 'booking_unavailable_day' . $wdi ) == 'On' ) {
469 $data_arr['ui']['booking_unavailable_day'][] = $wdi;
470 }
471 }
472
473 /**
474 * $unavailable_from_today_arr = [
475 * booking_unavailable_days_num_from_today = "540m"
476 * booking_unavailable_days_num_from_today__hint = ": 2025-01-25 15:19 - 2025-01-26 00:18:42"
477 * booking_available_days_num_from_today = "0"
478 * booking_available_days_num_from_today__hint = ": 26 Jan, 2025 - ..."
479 * ]
480 */
481 $unavailable_from_today_arr = wpbc_get_unavailable_from_today_hints_arr();
482
483 $data_arr['ui']['booking_unavailable_days_num_from_today'] = $unavailable_from_today_arr['booking_unavailable_days_num_from_today'];
484 $data_arr['ui']['booking_unavailable_days_num_from_today__hint'] = $unavailable_from_today_arr['booking_unavailable_days_num_from_today__hint'];
485 $data_arr['ui']['booking_available_days_num_from_today'] = $unavailable_from_today_arr['booking_available_days_num_from_today'];
486 $data_arr['ui']['booking_available_days_num_from_today__hint'] = $unavailable_from_today_arr['booking_available_days_num_from_today__hint'];
487 if(0){
488 // -----------------------------------------------------------------------------------------------------
489 // == UNAVAILABLE Today days ==
490 // -----------------------------------------------------------------------------------------------------
491 // FixIn: 10.8.1.4.
492 $last_unavailable_date = '';
493 if ( 'm' === substr( get_bk_option( 'booking_unavailable_days_num_from_today' ), - 1 ) ) {
494 // -------------------------------------------------------------------------------------------------
495 // == Minutes ==
496 // -------------------------------------------------------------------------------------------------
497 $data_arr['ui']['booking_unavailable_days_num_from_today'] = intval( get_bk_option( 'booking_unavailable_days_num_from_today' ) );
498
499 // Hints.
500 $data_arr['ui']['booking_unavailable_days_num_from_today__hint'] = ': <span style="text-transform: lowercase;font-size:0.9em;">'
501 . __( 'None', 'booking' ) . '</span>';
502 if ( ! empty( $data_arr['ui']['booking_unavailable_days_num_from_today'] ) ) {
503
504 $start_date_unix = strtotime( 'now' );
505 $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' );
506
507 $start_date_unix = strtotime( '+' . ( intval( $data_arr['ui']['booking_unavailable_days_num_from_today'] ) - 1 ) . ' minutes' );
508 $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' );
509
510 $last_unavailable_date = $max_date_with_wp_timezone;
511
512 $data_arr['ui']['booking_unavailable_days_num_from_today__hint'] = ': ' . $todate_with_wp_timezone . ' - ' . $max_date_with_wp_timezone; // FixIn: 10.9.4.2.
513 }
514 $data_arr['ui']['booking_unavailable_days_num_from_today'] .= 'm';
515 } else {
516 // -------------------------------------------------------------------------------------------------
517 // == Days ==
518 // -------------------------------------------------------------------------------------------------
519 $data_arr['ui']['booking_unavailable_days_num_from_today'] = intval( get_bk_option( 'booking_unavailable_days_num_from_today' ) );
520
521 // Hints.
522 $data_arr['ui']['booking_unavailable_days_num_from_today__hint'] = ': <span style="text-transform: lowercase;font-size:0.9em;">' . __( 'None', 'booking' ) . '</span>';
523
524 if ( 1 === $data_arr['ui']['booking_unavailable_days_num_from_today'] ) {
525 $last_unavailable_date = wp_date( 'Y-m-d 00:00:00' );
526 $data_arr['ui']['booking_unavailable_days_num_from_today__hint'] = ': ' . wp_date( 'd M', strtotime( $last_unavailable_date ) );
527 }
528 if ( $data_arr['ui']['booking_unavailable_days_num_from_today'] > 1 ) {
529 $last_unavailable_date = wp_date( 'Y-m-d 00:00:00', strtotime( '+' . ( $data_arr['ui']['booking_unavailable_days_num_from_today'] - 1 ) . ' days' ) );
530 $data_arr['ui']['booking_unavailable_days_num_from_today__hint'] = ': ' . wp_date( 'd M' ) . ' - ' . wp_date( 'd M', strtotime( $last_unavailable_date ) );
531 }
532 }
533
534 // -----------------------------------------------------------------------------------------------------
535 // == AVAILABLE Today days ==
536 // -----------------------------------------------------------------------------------------------------
537 // if ( class_exists( 'wpdev_bk_biz_m' ) ) { .
538 $data_arr['ui']['booking_available_days_num_from_today'] = esc_js( get_bk_option( 'booking_available_days_num_from_today' ) );
539
540 // Hints.
541 // $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 ) ) );
542 if ( '' === $last_unavailable_date ) {
543 $start_date_unix = strtotime( 'now' );
544 $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' );
545 $start_available_date = $todate_with_wp_timezone;
546 } else {
547 $start_available_date = $last_unavailable_date;
548 // We use here with no WP timezone, because timezone already applied to $last_unavailable_date.
549 $start_available_date = wpbc_datetime_localized__no_wp_timezone( strtotime( $last_unavailable_date ), 'Y-m-d 00:00:00' );
550 }
551
552
553 if ( empty( $data_arr['ui']['booking_available_days_num_from_today'] ) ) {
554 $last_available_date = '';
555 } else {
556 // $last_available_date = wp_date( 'Y-m-d 00:00:00', strtotime( '+' . ( $data_arr['ui']['booking_available_days_num_from_today'] ) . ' days' ) );
557 // FixIn: 10.9.6.3.
558 $start_date_unix = strtotime( '+' . ( intval( $data_arr['ui']['booking_available_days_num_from_today'] ) - 1 ) . ' days' );
559 $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' );
560 }
561
562 if ( ! empty( $data_arr['ui']['booking_available_days_num_from_today'] ) ) {
563
564 if ( strtotime( $start_available_date ) < strtotime( $last_available_date ) ) {
565
566 $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 ) );
567 } else if ( strtotime( $start_available_date ) == strtotime( $last_available_date ) ) {
568 $data_arr['ui']['booking_available_days_num_from_today__hint'] = ': ' . wp_date( 'd M, Y', strtotime( $start_available_date ) );
569 } else {
570 $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>' .
571 ' <span style="text-transform: lowercase;font-size:0.9em;color:#cc3a5f;">' .
572 'Start available' . ': ' . wp_date( 'd M, Y', strtotime( $start_available_date ) ) . '<br>' .
573 'Last available' . ': ' . wp_date( 'd M, Y', strtotime( $last_available_date ) ) . '</span>';
574 }
575 } else {
576 $data_arr['ui']['booking_available_days_num_from_today__hint'] = ': ' . wp_date( 'd M, Y', strtotime( $start_available_date ) ) . ' - ...';
577 }
578 }
579
580 $data_arr['ui']['booking_unavailable_extra_in_out'] = get_bk_option( 'booking_unavailable_extra_in_out' );
581 $data_arr['ui']['booking_unavailable_extra_minutes_in'] = get_bk_option( 'booking_unavailable_extra_minutes_in' );
582 $data_arr['ui']['booking_unavailable_extra_minutes_out'] = get_bk_option( 'booking_unavailable_extra_minutes_out' );
583 $data_arr['ui']['booking_unavailable_extra_days_in'] = get_bk_option( 'booking_unavailable_extra_days_in' );
584 $data_arr['ui']['booking_unavailable_extra_days_out'] = get_bk_option( 'booking_unavailable_extra_days_out' );
585
586 break;
587
588 case 'color_theme':
589
590 $data_arr['calendar_force_load'] = wpbc_setup_wizard_page__get_shortcode_html( $cleaned_request_params['resource_id'] );
591 $data_arr['ui']['booking_form_theme'] = get_bk_option( 'booking_form_theme' );
592 $data_arr['ui']['booking_skin'] = get_bk_option( 'booking_skin' );
593 $data_arr['ui']['booking_timeslot_picker_skin'] = get_bk_option( 'booking_timeslot_picker_skin' );
594 break;
595
596 case 'optional_other_settings':
597 $data_arr['calendar_force_load'] = '';//wpbc_setup_wizard_page__get_shortcode_html( $cleaned_request_params['resource_id'] );
598 break;
599
600 case 'wizard_publish':
601 $data_arr['calendar_force_load'] = '';//wpbc_setup_wizard_page__get_shortcode_html( $cleaned_request_params['resource_id'] );
602 break;
603
604 case 'get_started':
605 $data_arr['calendar_force_load'] = '';//wpbc_setup_wizard_page__get_shortcode_html( $cleaned_request_params['resource_id'] );
606 break;
607
608 default:
609 $data_arr['calendar_force_load'] = '';
610 }
611
612
613 // -------------------------------------------------------------------------------------------------------------
614 // Save Wizard history
615 // -------------------------------------------------------------------------------------------------------------
616 // Save to DB
617 $booking_wizard_data_arr[ $cleaned_request_params['do_action'] ] = $cleaned_data;
618 update_bk_option( 'booking_wizard_data', $booking_wizard_data_arr );
619 // Ajax Transfer
620 $data_arr['booking_wizard_data'] = $booking_wizard_data_arr;
621 // -------------------------------------------------------------------------------------------------------------
622
623 //TODO: delete this ?
624 if(0){
625
626 $data_arr['customize_steps'] = array();
627 $data_arr['customize_steps']['action'] = 'none';
628
629 // Actions =================================================================================================
630
631 if ( 'save_calendar_additional' == $cleaned_request_params['do_action'] ) {
632
633 $is_updated = update_bk_option( 'booking_max_monthes_in_calendar', $cleaned_request_params['calendar__booking_max_monthes_in_calendar'] );
634 $is_updated = update_bk_option( 'booking_start_day_weeek', $cleaned_request_params['calendar__booking_start_day_weeek'] );
635 }
636
637 //----------------------------------------------------------------------------------------------------------
638
639 // Get booking resources (sql)
640 $resources_arr = wpbc_ajx_get_all_booking_resources_arr(); /**
641 * Array ( [0] => Array ( [booking_type_id] => 1
642 [title] => Standard
643 [users] => 1
644 [import] =>
645 [export] =>
646 [cost] => 25
647 [default_form] => standard
648 [prioritet] => 0
649 [parent] => 0
650 [visitors] => 2
651 ), ... */
652
653 $resources_arr_sorted = wpbc_ajx_get_sorted_booking_resources_arr( $resources_arr );
654
655 $data_arr['ajx_booking_resources'] = $resources_arr_sorted;
656 }
657
658
659 // -------------------------------------------------------------------------------------------------------------
660 // Save Status of Wizard for specific user
661 // -------------------------------------------------------------------------------------------------------------
662 if ( 'make_reset' !== $cleaned_request_params['do_action'] ) {
663
664 $request_params_to_save = $cleaned_request_params;
665
666 // Do not safe such elements
667 unset( $request_params_to_save['ui_clicked_element_id'] );
668 unset( $request_params_to_save['do_action'] );
669 unset( $request_params_to_save['calendar_force_load'] );
670 unset( $request_params_to_save['plugin_menu__setup_progress'] );
671
672 $is_success_update = $user_request->user_request_params__db_save( $request_params_to_save ); // Save to DB // - $cleaned_request_params - serialized here automatically
673 }
674
675 if ( ! empty( $data_arr['calendar_force_load'] ) ) {
676 $data_arr['calendar_force_load'] = wpbc_clean_calendar_loading_scripts( $data_arr['calendar_force_load'] );
677 }
678 // -------------------------------------------------------------------------------------------------------------
679 // 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.
680 // -------------------------------------------------------------------------------------------------------------
681 wp_send_json( array(
682 'ajx_data' => $data_arr,
683 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
684 'ajx_all_ajx_params' => $_REQUEST[ $request_prefix ], // $_REQUEST[ 'all_ajx_params' ]
685 'ajx_cleaned_params' => $cleaned_request_params
686 ) );
687 }
688
689 }
690
691 /**
692 * Just for loading CSS and JavaScript files
693 */
694 if ( true ) {
695 $setup_wizard_page_loading = new WPBC_AJX__Setup_Wizard__Ajax_Request;
696 $setup_wizard_page_loading->define_ajax_hook();
697 }