PluginProbe
Booking Calendar / 11.1
Booking Calendar v11.1
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 / _capacity / calendar_load.php

calendar_load.php in Booking Calendar 11.1, at includes/_capacity/calendar_load.php

445 lines 24.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @file: wp-content/plugins/booking/includes/_capacity/calendar_load.php
4 */
5
6 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly // FixIn: 9.8.0.4.
7
8 /**
9 * Define parameters for calendar -- required for JS calendar show
10 *
11 * @param array $params
12 *
13 * @return string JS code body (no <script> wrapper)
14 */
15 function wpbc__calendar__set_js_params__before_show( $params ) {
16
17 $start_script_code = '';
18
19 // Server Balancer.
20 $balancer_max_threads = intval( get_bk_option( 'booking_load_balancer_max_threads' ) );
21 $balancer_max_threads = ( empty( $balancer_max_threads ) ) ? 1 : $balancer_max_threads;
22 $start_script_code .= " _wpbc.balancer__set_max_threads( " . $balancer_max_threads . " ); ";
23
24 $resource_id = isset( $params['resource_id'] ) ? absint( $params['resource_id'] ) : 1;
25
26 if ( function_exists( 'wpbc_is_booking_used_check_in_out_time' ) ) {
27 $is_enabled_change_over = wpbc_is_booking_used_check_in_out_time( false, $resource_id );
28 $start_script_code .= " _wpbc.calendar__set_param_value( " . $resource_id . " , 'is_enabled_change_over' , " . ( $is_enabled_change_over ? 'true' : 'false' ) . " ); ";
29 $start_script_code .= " _wpbc.set_other_param( 'is_enabled_change_over', " . ( $is_enabled_change_over ? 'true' : 'false' ) . " ); ";
30 }
31
32 // Start Month (require [year,month]).
33 $calendar_scroll_to = 'false';
34 if (
35 isset( $params['start_month_calendar'] )
36 && is_array( $params['start_month_calendar'] )
37 && ( count( $params['start_month_calendar'] ) > 1 )
38 ) {
39 $y = intval( $params['start_month_calendar'][0] );
40 $m = intval( $params['start_month_calendar'][1] );
41 if ( ( $y > 0 ) && ( $m > 0 ) ) {
42 $calendar_scroll_to = "[ " . (string) $y . "," . (string) $m . " ]";
43 }
44 }
45 $start_script_code .= " _wpbc.calendar__set_param_value( " . $resource_id . " , 'calendar_scroll_to' , " . $calendar_scroll_to . " ); ";
46
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'];
50
51 $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
54 if ( ( '' !== $params['calendar_dates_start'] ) || ( '' !== $params['calendar_dates_end'] ) ) {
55 $start_script_code .= wpbc_get_localized_js__time_local( $params['calendar_dates_start'] );
56 }
57
58 // Max months to scroll.
59 $start_script_code .= " _wpbc.calendar__set_param_value( " . $resource_id . " , 'booking_max_monthes_in_calendar' , " . wp_json_encode( (string) get_bk_option( 'booking_max_monthes_in_calendar' ) ) . " ); ";
60
61 // Start of week day.
62 $start_script_code .= " _wpbc.calendar__set_param_value( " . $resource_id . " , 'booking_start_day_weeek' , " . wp_json_encode( (string) get_bk_option( 'booking_start_day_weeek' ) ) . " ); ";
63
64 // Number of visible months.
65 $months_num = isset( $params['calendar_number_of_months'] ) ? (int) $params['calendar_number_of_months'] : 1;
66 $months_num = max( 1, min( 36, $months_num ) );
67 $start_script_code .= " _wpbc.calendar__set_param_value( " . $resource_id . " , 'calendar_number_of_months' , " . wp_json_encode( (string) $months_num ) . " ); ";
68
69 // Days Selection.
70 $days_selection_arr = wpbc__calendar__js_params__get_days_selection_arr();
71
72 $start_script_code .= " _wpbc.calendar__set_param_value( " . $resource_id . ", 'days_select_mode', " . wp_json_encode( (string) $days_selection_arr['days_select_mode'] ) . " ); ";
73 $start_script_code .= " _wpbc.calendar__set_param_value( " . $resource_id . ", 'fixed__days_num', " . intval( $days_selection_arr['fixed__days_num'] ) . " ); ";
74
75 // Keep legacy: these are stored as comma lists like "-1" or "0,1".
76 $start_script_code .= " _wpbc.calendar__set_param_value( " . $resource_id . ", 'fixed__week_days__start', [" . $days_selection_arr['fixed__week_days__start'] . "] ); ";
77 $start_script_code .= " _wpbc.calendar__set_param_value( " . $resource_id . ", 'dynamic__days_min', " . intval( $days_selection_arr['dynamic__days_min'] ) . " ); ";
78 $start_script_code .= " _wpbc.calendar__set_param_value( " . $resource_id . ", 'dynamic__days_max', " . intval( $days_selection_arr['dynamic__days_max'] ) . " ); ";
79 $start_script_code .= " _wpbc.calendar__set_param_value( " . $resource_id . ", 'dynamic__days_specific', [" . $days_selection_arr['dynamic__days_specific'] . "] ); ";
80 $start_script_code .= " _wpbc.calendar__set_param_value( " . $resource_id . ", 'dynamic__week_days__start', [" . $days_selection_arr['dynamic__week_days__start'] . "] ); ";
81
82 // Date / Time formats.
83 $start_script_code .= " _wpbc.calendar__set_param_value( " . $resource_id . ", 'booking_date_format', " . wp_json_encode( (string) get_bk_option( 'booking_date_format' ) ) . " ); ";
84 $start_script_code .= " _wpbc.calendar__set_param_value( " . $resource_id . ", 'booking_time_format', " . wp_json_encode( (string) get_bk_option( 'booking_time_format' ) ) . " ); ";
85
86 // Capacity | availability.
87 if ( class_exists( 'wpdev_bk_biz_l' ) ) {
88 $start_script_code .= " _wpbc.calendar__set_param_value( " . $resource_id . " , 'is_parent_resource' , " . ( wpbc_get_child_resources_number( $resource_id ) ? 1 : 0 ) . " ); ";
89 $start_script_code .= " _wpbc.calendar__set_param_value( " . $resource_id . " , 'booking_capacity_field' , " . wp_json_encode( (string) wpbc_get__booking_capacity_field__name() ) . " ); ";
90 $start_script_code .= " _wpbc.calendar__set_param_value( " . $resource_id . " , 'booking_is_dissbale_booking_for_different_sub_resources' , " . wp_json_encode( (string) get_bk_option( 'booking_is_dissbale_booking_for_different_sub_resources' ) ) . " ); ";
91 }
92 if ( class_exists( 'wpdev_bk_biz_s' ) ) {
93 $start_script_code .= " _wpbc.calendar__set_param_value( " . $resource_id . " , 'booking_recurrent_time' , " . wp_json_encode( (string) get_bk_option( 'booking_recurrent_time' ) ) . " ); ";
94 }
95
96 // Save initial values of days selection for later use in conditional day logic.
97 $start_script_code .= " if ( 'function' === typeof ( wpbc__conditions__SAVE_INITIAL__days_selection_params__bm ) ) { wpbc__conditions__SAVE_INITIAL__days_selection_params__bm( " . $resource_id . " ); } ";
98
99 if (
100 ( ! empty( $params['shortcode_options'] ) )
101 && ( function_exists( 'wpbc_parse_shortcode_option__set_days_selection_conditions' ) )
102 ) {
103 $days_selection_conditions = wpbc_parse_shortcode_option__set_days_selection_conditions( $resource_id, $params['shortcode_options'] );
104
105 if ( ! empty( $days_selection_conditions ) ) {
106 $start_script_code .= " _wpbc.calendar__set_param_value( " . $resource_id . ", 'conditions', " . wp_json_encode( $days_selection_conditions['conditions'] ) . " ); ";
107 $start_script_code .= " _wpbc.seasons__set( " . $resource_id . ", " . wp_json_encode( $days_selection_conditions['seasons'] ) . " ); ";
108 }
109 }
110
111 return $start_script_code;
112 }
113
114
115 /**
116 * Get days selection parameters, which saved in database
117 *
118 * @return array
119 */
120 function wpbc__calendar__js_params__get_days_selection_arr(){
121
122 $specific_days_selection = ( function_exists( 'wpbc_get_specific_range_dates__as_comma_list' ) )
123 ? wpbc_get_specific_range_dates__as_comma_list( get_bk_option( 'booking_range_selection_days_specific_num_dynamic' ) )
124 : '';
125 $data_arr = array();
126 // Modes :: Selection of Days
127 $data_arr['days_select_mode'] = ( 'range' === get_bk_option('booking_type_of_day_selections') )
128 ? get_bk_option('booking_range_selection_type')
129 : get_bk_option( 'booking_type_of_day_selections');
130 $data_arr['fixed__days_num'] = intval( get_bk_option( 'booking_range_selection_days_count' ) ); /* Number of days selection with 1 mouse click */
131 $data_arr['fixed__week_days__start'] = get_bk_option( 'booking_range_start_day' ); /* { -1 - Any | 0 - Su, 1 - Mo, 2 - Tu, 3 - We, 4 - Th, 5 - Fr, 6 - Sat } */
132 $data_arr['dynamic__days_min'] = intval( get_bk_option( 'booking_range_selection_days_count_dynamic' ) ); /* Min. Number of days selection with 2 mouse clicks */
133 $data_arr['dynamic__days_max'] = intval( get_bk_option( 'booking_range_selection_days_max_count_dynamic' ) ); /* Max. Number of days selection with 2 mouse clicks */
134 $data_arr['dynamic__days_specific'] = $specific_days_selection; /* Example: '5,7' */
135 $data_arr['dynamic__week_days__start'] = get_bk_option( 'booking_range_start_day_dynamic' ); /* { -1 - Any | 0 - Su, 1 - Mo, 2 - Tu, 3 - We, 4 - Th, 5 - Fr, 6 - Sat } */
136
137 // Fix about possible issue of downgrade from Paid to free version and try to use 'Range days' selection, which is not supports in that version. // FixIn: 10.4.0.4.
138 if ( ( ! class_exists( 'wpdev_bk_biz_s' ) ) && ( in_array( $data_arr['days_select_mode'], array( 'dynamic', 'fixed' ) ) ) ) {
139 $data_arr['days_select_mode'] = 'multiple';
140 }
141
142 return $data_arr;
143 }
144
145
146
147 /**
148 * Get JavaScript for Calendar Loading:
149 * 1) Show Calendar
150 * 2) Send Ajax to load bookings / availability / data for calendar
151 *
152 * @param array $params
153 *
154 * @return string Either '' (when collected to footer) OR legacy <script>...</script> fallback.
155 */
156 function wpbc__calendar__load( $params = array() ) {
157
158 $defaults = array(
159 'resource_id' => '1',
160 'aggregate_resource_id_arr' => array(),
161 'selected_dates_without_calendar' => '',
162 'calendar_number_of_months' => 1,
163 'start_month_calendar' => false,
164 'shortcode_options' => '',
165 'custom_form' => 'standard',
166 'calendar_dates_start' => '',
167 'calendar_dates_end' => '',
168 'skip_general_availability' => 0,
169 );
170 $params = wp_parse_args( $params, $defaults );
171
172 // Resource ID.
173 $params['resource_id'] = absint( $params['resource_id'] );
174
175 // Build JS BODY (no <script>, no ready wrapper).
176 $js_body = '';
177
178 $js_body .= wpbc__calendar__set_js_params__before_show( $params );
179
180 // Show calendar.
181 $js_body .= " wpbc_calendar_show(" . wp_json_encode( (string) $params['resource_id'] ) . "); ";
182
183 // Security params.
184 $js_body .= " _wpbc.set_secure_param('nonce', " . wp_json_encode( wp_create_nonce( 'wpbc_calendar_load_ajx' . '_wpbcnonce' ) ) . "); ";
185 $js_body .= " _wpbc.set_secure_param('user_id', " . wp_json_encode( (string) wpbc_get_current_user_id() ) . "); ";
186 $js_body .= " _wpbc.set_secure_param('locale', " . wp_json_encode( (string) get_user_locale() ) . "); ";
187
188 // booking_hash (keep legacy GET behavior, sanitized).
189 $get_booking_hash = '';
190 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
191 if ( isset( $_GET['booking_hash'] ) ) {
192 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
193 $raw_hash = wp_unslash( $_GET['booking_hash'] );
194 if ( ! is_array( $raw_hash ) ) {
195 $get_booking_hash = sanitize_text_field( (string) $raw_hash );
196 }
197 }
198
199 // Aggregate type.
200 $aggregate_type = 'all';
201 if (
202 ( ! empty( $params['shortcode_options'] ) )
203 && function_exists( 'wpbc_parse_calendar_options__aggregate_param' )
204 ) {
205 $aggregate_type_res = wpbc_parse_calendar_options__aggregate_param( $params['shortcode_options'] );
206 if ( ( ! empty( $aggregate_type_res ) ) && ( ! empty( $aggregate_type_res['type'] ) ) ) {
207 $aggregate_type = (string) $aggregate_type_res['type'];
208 }
209 }
210
211 // request_uri captured on front-end (legacy rationale).
212 $server_request_uri = '';
213 // phpcs:ignore WordPress.Security.NonceVerification.Missing
214 if ( isset( $_SERVER['REQUEST_URI'] ) ) {
215 // phpcs:ignore WordPress.Security.NonceVerification.Missing
216 $server_request_uri = sanitize_text_field( wp_unslash( (string) $_SERVER['REQUEST_URI'] ) );
217 }
218
219 $params_for_request = array(
220 'resource_id' => $params['resource_id'],
221 'booking_hash' => $get_booking_hash,
222 'request_uri' => $server_request_uri,
223 'custom_form' => (string) $params['custom_form'],
224 'aggregate_resource_id_str' => implode( ',', (array) $params['aggregate_resource_id_arr'] ),
225 'aggregate_type' => (string) $aggregate_type,
226 'skip_general_availability' => (int) $params['skip_general_availability'],
227 );
228
229 // Send Ajax request to load bookings.
230 $js_body .= " wpbc_calendar__load_data__ajx(" . wp_json_encode( $params_for_request ) . "); ";
231
232 // ---------------------------------------------------------------------
233 // Elementor-safe path: add inline via WP scripts (footer-safe, not in content). // FixIn: 10.14.13.2.
234 // ---------------------------------------------------------------------
235 $can_use_wp_inline = ( ! wp_doing_ajax() );
236
237 if ( $can_use_wp_inline && class_exists( 'WPBC_FE_Assets' ) ) {
238
239 $assets_key = 'wpbc:cal-load:' . intval( $params['resource_id'] ) . ':' . md5( wp_json_encode( $params_for_request ) );
240
241 // Try after main client script first (best), fallback to wpbc_all if needed.
242 $added = WPBC_FE_Assets::add_jq_ready_js_to_wp_script( 'wpbc-main-client', $js_body, $assets_key );
243 if ( ! $added ) {
244 $added = WPBC_FE_Assets::add_jq_ready_js_to_wp_script( 'wpbc_all', $js_body, $assets_key );
245 }
246
247 if ( $added ) {
248 return ''; // Important: nothing inline in the content.
249 }
250 }
251
252 // ---------------------------------------------------------------------
253 // Legacy fallback: return inline <script>...</script> (Works in rare contexts without wp_footer / without assets manager).
254 // ---------------------------------------------------------------------
255 $start_script_code = '<script type="text/javascript"> ' . wpbc_jq_ready_start() . $js_body . wpbc_jq_ready_end() . '</script>';
256
257 return $start_script_code;
258 }
259
260
261 /**
262 * Get Booking Calendar option names that belong to General Availability rules.
263 *
264 * @return array
265 */
266 function wpbc__calendar__get_general_availability_option_names() {
267
268 $option_names = array(
269 'booking_unavailable_days_num_from_today',
270 'booking_available_days_num_from_today',
271 'booking_unavailable_extra_in_out',
272 'booking_unavailable_extra_minutes_in',
273 'booking_unavailable_extra_minutes_out',
274 'booking_unavailable_extra_days_in',
275 'booking_unavailable_extra_days_out',
276 );
277
278 foreach ( range( 0, 6 ) as $week_day_num ) {
279 $option_names[] = 'booking_unavailable_day' . $week_day_num;
280 }
281
282 return $option_names;
283 }
284
285
286
287 /**
288 * Response to Ajax request, about loading calendar data
289 *
290 * @return void
291 */
292 function ajax_WPBC_AJX_CALENDAR_LOAD() { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
293
294 // Security ------------------------------------------------------------------------------------------------------ // in Ajax Post: 'nonce': _wpbc.get_secure_param( 'nonce' ),
295 $action_name = 'wpbc_calendar_load_ajx' . '_wpbcnonce';
296 $nonce_post_key = 'nonce';
297 if ( wpbc_is_use_nonce_at_front_end() ) { // FixIn: 10.1.1.2.
298 $result_check = check_ajax_referer( $action_name, $nonce_post_key );
299 }
300
301 $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
302
303 /**
304 * SQL ---------------------------------------------------------------------------
305 *
306 * in Ajax Post: 'search_params': _wpbc.search_get_all_params()
307 *
308 * Use prefix "search_params", if Ajax sent - $_REQUEST['search_params']['page_num'], $_REQUEST['search_params']['page_items_count'], ...
309 */
310
311 /**
312 * Using this class here only for escaping variables
313 */
314 $user_request = new WPBC_AJX__REQUEST( array(
315 'db_option_name' => 'booking__wpbc_calendar_load__request_params',
316 'user_id' => $user_id,
317 'request_rules_structure' => array(
318 'resource_id' => array( 'validate' => 'd', 'default' => 1 ), // 'digit_or_csd'
319 'booking_hash' => array( 'validate' => 's', 'default' => '' ),
320 'request_uri' => array( 'validate' => 's', 'default' => '' ),
321 'custom_form' => array( 'validate' => 's', 'default' => 'standard' ),
322 'aggregate_resource_id_str' => array( 'validate' => 'digit_or_csd', 'default' => '' ), // Comma separated string of resource ID, which was used in 'aggregate' parameter.
323 'aggregate_type' => array( 'validate' => 's', 'default' => 'all' ), // 'all' | 'bookings_only' // FixIn: 9.8.15.10.
324 'dates_to_check' => array( 'validate' => 'array', 'default' => '' ), // 'all' | 'bookings_only' // FixIn: 9.8.15.10.
325 'skip_general_availability' => array( 'validate' => 'd', 'default' => 0 ),
326 )
327 )
328 );
329 $request_prefix = 'calendar_request_params';
330 $request_params = $user_request->get_sanitized__in_request__value_or_default( $request_prefix ); // NOT Direct: $_REQUEST['search_params']['resource_id']
331
332 if ( ! empty( $request_params['skip_general_availability'] ) ) {
333 $can_skip_general_availability = (
334 function_exists( 'wpbc_availability_general__get_manage_cap' )
335 && function_exists( 'wpbc_is_mu_user_can_be_here' )
336 && wpbc_is_mu_user_can_be_here( 'only_super_admin' )
337 && current_user_can( wpbc_availability_general__get_manage_cap() )
338 );
339
340 if ( ! $can_skip_general_availability ) {
341 $request_params['skip_general_availability'] = 0;
342 }
343 }
344
345
346 // Do Job here !! -------------------------------------------------------------------------------------------------
347
348 make_bk_action( 'check_pending_unpaid_bookings__do_auto_cancel', $request_params['resource_id'] );
349
350 $skip_booking_id = wpbc_get_booking_id__from_hash_in_url( $request_params['booking_hash'] ); // Booking ID ( like 1101 ) to skip in calendar
351 $max_days_count = wpbc_get_max_visible_days_in_calendar(); // 365 - number of visible days
352 // Resource ID from aggregate parameter in booking shortcode!
353 $aggregate_resource_id_arr = explode( ',', $request_params['aggregate_resource_id_str'] );
354 $aggregate_resource_id_arr = array_filter( $aggregate_resource_id_arr ); // All entries of array equal to FALSE (0, '', '0' ) will be removed.
355 $aggregate_resource_id_arr = array_unique( $aggregate_resource_id_arr ); // Remove duplicates // FixIn: 9.8.15.10.
356 if ( ( $resource_id_key = array_search( $request_params['resource_id'], $aggregate_resource_id_arr ) ) !== false ) {
357 unset( $aggregate_resource_id_arr[ $resource_id_key ] ); // Remove source booking resource from aggregate ARR. // FixIn: 9.8.15.10.
358 }
359 $aggregate_resource_id_arr = array_values($aggregate_resource_id_arr); // Reset keys
360
361 $availability_per_days__params = array(
362 'resource_id' => $request_params['resource_id'],
363 'max_days_count' => $max_days_count,
364 'skip_booking_id' => $skip_booking_id,
365 '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
366 'custom_form' => $request_params['custom_form']
367 , 'additional_bk_types' => $aggregate_resource_id_arr // It is array of booking resources from aggregate parameter() // arrays | CSD | int // OPTIONAL
368 , 'aggregate_type' => $request_params['aggregate_type'] // It is string: 'all' | 'bookings_only' // OPTIONAL
369 , 'skip_general_availability' => $request_params['skip_general_availability']
370 // , 'as_single_resource' => true // get dates as for 'single resource' or 'parent' resource including bookings in all 'child booking resources'
371 // , 'max_days_count' => wpbc_get_max_visible_days_in_calendar() // 365
372 // , 'timeslots_to_check_intersect' => $timeslots_to_check_intersect //TODO 2023-10-25: delete it, because we get it in wpbc_get_availability_per_days_arr() //array( '12:20 - 12:55', '13:00 - 14:00' )
373 );
374
375 if ( ! empty( $request_params['dates_to_check'] ) ) {
376 $availability_per_days__params['dates_to_check'] = $request_params['dates_to_check']; // Usually if defined it is: [ '2025-01-01', '2025-12-31' ], because of shortcode [booking resource_id=4 calendar_dates_start='2025-01-01' calendar_dates_end='2025-12-31' ...]
377 }
378
379 // If in Booking > Add booking page we use in URL .../wp-admin/admin.php?page=wpbc&tab=add-booking&booking_type=2&as_single_resource=1 then get availability only for single resource.
380 if (
381 ( ! empty( $request_params['request_uri'] ) )
382 && ( strpos( $request_params['request_uri'], 'as_single_resource=1' ) !== false )
383 ){
384 $availability_per_days__params['as_single_resource'] = true;
385 }
386
387 /**
388 * Tricks:
389 * if ( wpbc_is_new_booking_page_url( $request_params['request_uri'] ) ) { $availability_per_days__params['is_days_always_available'] = true; }
390 *
391 * // Set dates in calendar always available only for specific resources with specific ID
392 * if ( in_array( $request_params['resource_id'], array( 12, 15, 17 ) ) ) { $availability_per_days__params['is_days_always_available'] = true; }
393 */
394
395 // Get unavailable dates for calendar
396 // $availability_per_days__params['dates_to_check'] = array( '2025-01-01', '2025-12-31' ); // FixIn: 10.13.1.4.
397 global $wpbc__skip_get_bk_options;
398
399 $previous_skip_get_bk_options = $wpbc__skip_get_bk_options;
400 if ( ! empty( $availability_per_days__params['skip_general_availability'] ) ) {
401 $wpbc__skip_get_bk_options = array_unique(
402 array_merge(
403 (array) $wpbc__skip_get_bk_options,
404 wpbc__calendar__get_general_availability_option_names()
405 )
406 );
407 }
408
409 $availability_per_days_arr = wpbc_get_availability_per_days_arr( $availability_per_days__params );
410 $wpbc__skip_get_bk_options = $previous_skip_get_bk_options;
411
412
413 $ajx_data_arr = array( /**
414 * Send JSON. It will make "wp_json_encode" - so pass only array, and This function call wp_die( '', '', array( 'response' => null, ) ) .
415 * Pass JS OBJ: response_data in "jQuery.post( " function on success.
416 */
417 'ajx_data' => $availability_per_days_arr,
418 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
419 'ajx_search_params' => $_REQUEST[ $request_prefix ],
420 'ajx_cleaned_params' => $request_params,
421 'resource_id' => $request_params['resource_id'],
422 );
423
424 // FixIn: 10.12.4.6.
425 if ( ! in_array( $request_params['resource_id'], $availability_per_days_arr['resources_id_arr__in_dates'] ) ) {
426 $ajx_data_arr['ajx_data']['ajx_after_action_message'] = 'Wrong ID of booking resource. Probably calendar (booking resource) with ID = ' . intval( $request_params['resource_id'] ) . ' not exists. Please check resource_id parameter in the Booking Calendar shortcode.';
427 }
428
429
430
431 // Show message under calendar, if needed.
432 //$availability_per_days_arr['ajx_after_action_message'] = 'Ta Da :))';
433 //$availability_per_days_arr['ajx_after_action_message_status'] = 'warning';
434
435 // Ajax ------------------------------------------------------------------------------------------------------------
436 wp_send_json( $ajx_data_arr );
437
438 }
439
440 if ( is_admin() && ( defined( 'DOING_AJAX' ) ) && ( DOING_AJAX ) ) {
441 add_action( 'wp_ajax_nopriv_' . 'WPBC_AJX_CALENDAR_LOAD', 'ajax_' . 'WPBC_AJX_CALENDAR_LOAD' ); // Client (not logged in)
442 add_action( 'wp_ajax_' . 'WPBC_AJX_CALENDAR_LOAD', 'ajax_' . 'WPBC_AJX_CALENDAR_LOAD' ); // Logged In users (or admin panel)
443 }
444
445