| @@ -44,13 +44,15 @@ | ||
| 44 | 44 | } |
| 45 | 45 | $start_script_code .= " _wpbc.calendar__set_param_value( " . $resource_id . " , 'calendar_scroll_to' , " . $calendar_scroll_to . " ); "; |
| 46 | 46 | |
| 47 | 47 | // Set Start / End Date in Calendar (JSON encode => safe quotes). |
| 48 | - $params['calendar_dates_start'] = ( empty( $params['calendar_dates_start'] ) ) ? '' : (string) $params['calendar_dates_start']; | |
| 49 | - $params['calendar_dates_end'] = ( empty( $params['calendar_dates_end'] ) ) ? '' : (string) $params['calendar_dates_end']; | |
| 48 | + $params['calendar_dates_start'] = ( empty( $params['calendar_dates_start'] ) ) ? '' : (string) $params['calendar_dates_start']; | |
| 49 | + $params['calendar_dates_end'] = ( empty( $params['calendar_dates_end'] ) ) ? '' : (string) $params['calendar_dates_end']; | |
| 50 | + $params['classic_booking_context_token'] = empty( $params['classic_booking_context_token'] ) ? '' : (string) $params['classic_booking_context_token']; | |
| 50 | 51 | |
| 51 | 52 | $start_script_code .= " _wpbc.calendar__set_param_value( " . $resource_id . " , 'calendar_dates_start' , " . wp_json_encode( $params['calendar_dates_start'] ) . " ); "; |
| 52 | - $start_script_code .= " _wpbc.calendar__set_param_value( " . $resource_id . " , 'calendar_dates_end' , " . wp_json_encode( $params['calendar_dates_end'] ) . " ); "; | |
| 53 | + $start_script_code .= " _wpbc.calendar__set_param_value( " . $resource_id . " , 'calendar_dates_end' , " . wp_json_encode( $params['calendar_dates_end'] ) . " ); "; | |
| 54 | + $start_script_code .= " _wpbc.booking__set_param_value( " . $resource_id . " , 'classic_booking_context_token' , " . wp_json_encode( $params['classic_booking_context_token'] ) . " ); "; | |
| 53 | 55 | |
| 54 | 56 | if ( ( '' !== $params['calendar_dates_start'] ) || ( '' !== $params['calendar_dates_end'] ) ) { |
| 55 | 57 | $start_script_code .= wpbc_get_localized_js__time_local( $params['calendar_dates_start'] ); |
| 56 | 58 | } |
| @@ -66,9 +68,9 @@ | ||
| 66 | 68 | $months_num = max( 1, min( 36, $months_num ) ); |
| 67 | 69 | $start_script_code .= " _wpbc.calendar__set_param_value( " . $resource_id . " , 'calendar_number_of_months' , " . wp_json_encode( (string) $months_num ) . " ); "; |
| 68 | 70 | |
| 69 | 71 | // Days Selection. |
| 70 | - $days_selection_arr = wpbc__calendar__js_params__get_days_selection_arr(); | |
| 72 | + $days_selection_arr = wpbc__calendar__js_params__get_days_selection_arr(); | |
| 71 | 73 | |
| 72 | 74 | $start_script_code .= " _wpbc.calendar__set_param_value( " . $resource_id . ", 'days_select_mode', " . wp_json_encode( (string) $days_selection_arr['days_select_mode'] ) . " ); "; |
| 73 | 75 | $start_script_code .= " _wpbc.calendar__set_param_value( " . $resource_id . ", 'fixed__days_num', " . intval( $days_selection_arr['fixed__days_num'] ) . " ); "; |
| 74 | 76 | |
| @@ -134,11 +136,11 @@ | ||
| 134 | 136 | |
| 135 | 137 | /** |
| 136 | 138 | * Get days selection parameters, which saved in database |
| 137 | 139 | * |
| 138 | - * @return array | |
| 139 | - */ | |
| 140 | - function wpbc__calendar__js_params__get_days_selection_arr(){ | |
| 140 | + * @return array | |
| 141 | + */ | |
| 142 | + function wpbc__calendar__js_params__get_days_selection_arr(){ | |
| 141 | 143 | |
| 142 | 144 | $specific_days_selection = ( function_exists( 'wpbc_get_specific_range_dates__as_comma_list' ) ) |
| 143 | 145 | ? wpbc_get_specific_range_dates__as_comma_list( get_bk_option( 'booking_range_selection_days_specific_num_dynamic' ) ) |
| 144 | 146 | : ''; |
| @@ -193,12 +195,13 @@ | ||
| 193 | 195 | 'start_month_calendar' => false, |
| 194 | 196 | 'shortcode_options' => '', |
| 195 | 197 | 'custom_form' => 'standard', |
| 196 | 198 | 'calendar_dates_start' => '', |
| 197 | - 'calendar_dates_end' => '', | |
| 199 | + 'calendar_dates_end' => '', | |
| 200 | + 'classic_booking_context_token' => '', | |
| 198 | 201 | 'skip_general_availability' => 0, |
| 199 | - 'calendar_request_overrides' => array(), | |
| 200 | - ); | |
| 202 | + 'calendar_request_overrides' => array(), | |
| 203 | + ); | |
| 201 | 204 | $params = wp_parse_args( $params, $defaults ); |
| 202 | 205 | |
| 203 | 206 | // Resource ID. |
| 204 | 207 | $params['resource_id'] = absint( $params['resource_id'] ); |
| @@ -253,16 +256,19 @@ | ||
| 253 | 256 | 'request_uri' => $server_request_uri, |
| 254 | 257 | 'custom_form' => (string) $params['custom_form'], |
| 255 | 258 | 'aggregate_resource_id_str' => implode( ',', (array) $params['aggregate_resource_id_arr'] ), |
| 256 | 259 | 'aggregate_type' => (string) $aggregate_type, |
| 257 | - 'skip_general_availability' => (int) $params['skip_general_availability'], | |
| 260 | + 'skip_general_availability' => (int) $params['skip_general_availability'], | |
| 261 | + 'classic_booking_context_token' => (string) $params['classic_booking_context_token'], | |
| 258 | 262 | ); |
| 259 | 263 | |
| 260 | - if ( ! empty( $params['calendar_request_overrides'] ) && is_array( $params['calendar_request_overrides'] ) ) { | |
| 261 | - foreach ( $params['calendar_request_overrides'] as $override_key => $override_value ) { | |
| 262 | - if ( 0 === strpos( (string) $override_key, 'wpbc_settings_calendar_preview' ) ) { | |
| 263 | - $params_for_request[ $override_key ] = $override_value; | |
| 264 | - } | |
| 264 | + if ( ! empty( $params['calendar_request_overrides'] ) && is_array( $params['calendar_request_overrides'] ) ) { | |
| 265 | + foreach ( $params['calendar_request_overrides'] as $override_key => $override_value ) { | |
| 266 | + if ( 'allow_past' === $override_key ) { | |
| 267 | + $params_for_request['allow_past'] = ! empty( $override_value ) ? 1 : 0; | |
| 268 | + } elseif ( 0 === strpos( (string) $override_key, 'wpbc_settings_calendar_preview' ) ) { | |
| 269 | + $params_for_request[ $override_key ] = $override_value; | |
| 270 | + } | |
| 265 | 271 | } |
| 266 | 272 | } |
| 267 | 273 | |
| 268 | 274 | // Send Ajax request to load bookings. |
| @@ -355,10 +361,12 @@ | ||
| 355 | 361 | 'user_id' => $user_id, |
| 356 | 362 | 'request_rules_structure' => array( |
| 357 | 363 | 'resource_id' => array( 'validate' => 'd', 'default' => 1 ), // 'digit_or_csd' |
| 358 | 364 | 'booking_hash' => array( 'validate' => 's', 'default' => '' ), |
| 359 | - 'request_uri' => array( 'validate' => 's', 'default' => '' ), | |
| 360 | - 'custom_form' => array( 'validate' => 's', 'default' => 'standard' ), | |
| 365 | + 'request_uri' => array( 'validate' => 's', 'default' => '' ), | |
| 366 | + 'custom_form' => array( 'validate' => 's', 'default' => 'standard' ), | |
| 367 | + 'allow_past' => array( 'validate' => 'd', 'default' => 0 ), | |
| 368 | + 'classic_booking_context_token' => array( 'validate' => 'strong', 'default' => '' ), | |
| 361 | 369 | 'aggregate_resource_id_str' => array( 'validate' => 'digit_or_csd', 'default' => '' ), // Comma separated string of resource ID, which was used in 'aggregate' parameter. |
| 362 | 370 | 'aggregate_type' => array( 'validate' => 's', 'default' => 'all' ), // 'all' | 'bookings_only' // FixIn: 9.8.15.10. |
| 363 | 371 | 'dates_to_check' => array( 'validate' => 'array', 'default' => '' ), // 'all' | 'bookings_only' // FixIn: 9.8.15.10. |
| 364 | 372 | 'skip_general_availability' => array( 'validate' => 'd', 'default' => 0 ), |
| @@ -397,10 +405,32 @@ | ||
| 397 | 405 | 'wpbc_settings_calendar_preview_booked_details' => array( 'validate' => 's', 'default' => '' ), |
| 398 | 406 | ) |
| 399 | 407 | ) |
| 400 | 408 | ); |
| 401 | - $request_prefix = 'calendar_request_params'; | |
| 402 | - $request_params = $user_request->get_sanitized__in_request__value_or_default( $request_prefix ); // NOT Direct: $_REQUEST['search_params']['resource_id'] | |
| 409 | + $request_prefix = 'calendar_request_params'; | |
| 410 | + $request_params = $user_request->get_sanitized__in_request__value_or_default( $request_prefix ); // NOT Direct: $_REQUEST['search_params']['resource_id'] | |
| 411 | + if ( ! empty( $request_params['classic_booking_context_token'] ) && function_exists( 'wpbc_classic_booking_context_validate_submission' ) ) { | |
| 412 | + $classic_context = wpbc_classic_booking_context_validate_submission( | |
| 413 | + $request_params['classic_booking_context_token'], | |
| 414 | + $request_params['resource_id'], | |
| 415 | + $request_params['dates_to_check'], | |
| 416 | + $request_params['custom_form'], | |
| 417 | + $request_params['aggregate_resource_id_str'] | |
| 418 | + ); | |
| 419 | + if ( ! is_wp_error( $classic_context ) ) { | |
| 420 | + $request_params['allow_past'] = ! empty( $classic_context['allow_past'] ) ? 1 : 0; | |
| 421 | + // Use the signed canonical set so equivalent wire shapes cannot change availability input. | |
| 422 | + $request_params['aggregate_resource_id_str'] = implode( ',', $classic_context['aggregate_resource_ids'] ); | |
| 423 | + $request_params['dates_to_check'] = array( | |
| 424 | + $classic_context['calendar_dates_start'], | |
| 425 | + $classic_context['calendar_dates_end'], | |
| 426 | + ); | |
| 427 | + } else { | |
| 428 | + $request_params['allow_past'] = 0; | |
| 429 | + } | |
| 430 | + } | |
| 431 | + $can_allow_past = ! empty( $request_params['allow_past'] ); | |
| 432 | + $request_params['allow_past'] = $can_allow_past ? 1 : 0; | |
| 403 | 433 | |
| 404 | 434 | if ( ! empty( $request_params['skip_general_availability'] ) ) { |
| 405 | 435 | $can_skip_general_availability = ( |
| 406 | 436 | function_exists( 'wpbc_availability_general__get_manage_cap' ) |
| @@ -429,14 +459,15 @@ | ||
| 429 | 459 | unset( $aggregate_resource_id_arr[ $resource_id_key ] ); // Remove source booking resource from aggregate ARR. // FixIn: 9.8.15.10. |
| 430 | 460 | } |
| 431 | 461 | $aggregate_resource_id_arr = array_values($aggregate_resource_id_arr); // Reset keys |
| 432 | 462 | |
| 433 | - $availability_per_days__params = array( | |
| 434 | - 'resource_id' => $request_params['resource_id'], | |
| 435 | - 'max_days_count' => $max_days_count, | |
| 436 | - 'skip_booking_id' => $skip_booking_id, | |
| 437 | - 'request_uri' => $request_params['request_uri'], // It different in Ajax requests than $server_request_uri . It's used for change-over days to detect for exception at specific pages | |
| 438 | - 'custom_form' => $request_params['custom_form'] | |
| 463 | + $availability_per_days__params = array( | |
| 464 | + 'resource_id' => $request_params['resource_id'], | |
| 465 | + 'max_days_count' => $max_days_count, | |
| 466 | + 'skip_booking_id' => $skip_booking_id, | |
| 467 | + 'request_uri' => $request_params['request_uri'], // It different in Ajax requests than $server_request_uri . It's used for change-over days to detect for exception at specific pages | |
| 468 | + 'custom_form' => $request_params['custom_form'], | |
| 469 | + 'allow_past' => ! empty( $request_params['allow_past'] ) | |
| 439 | 470 | , 'additional_bk_types' => $aggregate_resource_id_arr // It is array of booking resources from aggregate parameter() // arrays | CSD | int // OPTIONAL |
| 440 | 471 | , 'aggregate_type' => $request_params['aggregate_type'] // It is string: 'all' | 'bookings_only' // OPTIONAL |
| 441 | 472 | , 'skip_general_availability' => $request_params['skip_general_availability'] |
| 442 | 473 | // , 'as_single_resource' => true // get dates as for 'single resource' or 'parent' resource including bookings in all 'child booking resources' |