PluginProbe
Booking Calendar / 11.9
Booking Calendar v11.9
11.9 11.8.4 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 All 205 releases
← All changes | includes/page-add-booking/add_booking__modal.php +129 -6 11.0 → 11.9 View file →
@@ -1,4 +1,4 @@
1 1 <?php
2 2 /**
3 3 * Add Booking modal for Booking Listing and Timeline.
4 4 *
@@ -77,8 +77,9 @@
77 77 </h4>
78 78 <div class="wpbc_modal__add_booking__controls">
79 79 <?php self::print_modal_resource_select(); ?>
80 80 <?php self::print_modal_booking_form_select(); ?>
81 + <?php self::print_modal_allow_past_toggle(); ?>
81 82 </div>
82 83 </div>
83 84 </div>
84 85 <div class="modal-body">
@@ -85,11 +86,13 @@
85 86 <div id="wpbc_modal__add_booking__body" class="wpbc_modal__add_booking__body">
86 87 <?php self::print_loading_spinner(); ?>
87 88 </div>
88 89 </div>
89 - <div class="modal-footer">
90 - <?php self::print_modal_send_emails_toggle(); ?>
91 - <a href="javascript:void(0)" id="wpbc_modal__add_booking__button_send" class="button button-primary" onclick="wpbc_boo_listing__submit__add_booking_modal();">
90 + <div class="modal-footer">
91 + <div class="wpbc_modal__add_booking__footer_time_override" data-wpbc-add-booking-time-override-footer="1"></div>
92 + <?php self::print_modal_send_emails_toggle(); ?>
93 + <?php self::print_add_appointment_entry(); ?>
94 + <a href="javascript:void(0)" id="wpbc_modal__add_booking__button_send" class="button button-primary" onclick="wpbc_boo_listing__submit__add_booking_modal();">
92 95 <?php esc_html_e( 'Add booking', 'booking' ); ?>
93 96 </a>
94 97 <a href="javascript:void(0)" class="button button-secondary" data-dismiss="modal">
95 98 <?php esc_html_e( 'Close', 'booking' ); ?>
@@ -99,9 +102,37 @@
99 102 </div><!-- /.modal-dialog -->
100 103 </div><!-- /.modal -->
101 104 </span>
102 105 <?php
103 - }
106 + }
107 +
108 +
109 + /**
110 + * Print the released route to the Service-first administrator workflow.
111 + *
112 + * The standard Add Booking form remains the popup's primary action. This
113 + * secondary route is hidden by the modal client whenever an existing booking
114 + * is being edited.
115 + *
116 + * @return void
117 + */
118 + private static function print_add_appointment_entry() {
119 + if (
120 + ! function_exists( 'wpbc_add_appointment_page_get_url' )
121 + || ! WPBC_Add_Booking_Component::current_user_can_add_booking()
122 + ) {
123 + return;
124 + }
125 + ?>
126 + <a href="<?php echo esc_url( wpbc_add_appointment_page_get_url() ); ?>"
127 + class="button button-secondary wpbc_modal__add_booking__appointment_entry"
128 + data-wpbc-add-appointment-entry="1"
129 + title="<?php esc_attr_e( 'Choose a Service and Provider before creating the booking', 'booking' ); ?>">
130 + <i class="menu_icon icon-1x wpbc-bi-calendar-plus" aria-hidden="true"></i>
131 + <?php esc_html_e( 'Add Appointment', 'booking' ); ?>
132 + </a>
133 + <?php
134 + }
104 135
105 136
106 137 /**
107 138 * Print modal-scoped email notification toggle.
@@ -139,8 +170,40 @@
139 170 }
140 171
141 172
142 173 /**
174 + * Print modal-scoped toggle for allowing bookings in the past.
175 + *
176 + * @return void
177 + */
178 + private static function print_modal_allow_past_toggle() {
179 +
180 + $el_id = 'wpbc_modal__add_booking__allow_past';
181 +
182 + $params_checkbox = array(
183 + 'id' => $el_id,
184 + 'name' => $el_id,
185 + 'label' => array( 'title' => __( 'Allow booking in the past', 'booking' ), 'position' => 'right' ),
186 + 'style' => '',
187 + 'class' => '',
188 + 'disabled' => false,
189 + 'attr' => array(
190 + 'data-wpbc-add-booking-allow-past' => '1',
191 + ),
192 + 'legend' => '',
193 + 'value' => 'On',
194 + 'selected' => false,
195 + 'hint' => array( 'title' => __( 'Allow booking in the past', 'booking' ), 'position' => 'top' ),
196 + );
197 + ?>
198 + <div class="wpbc_modal__add_booking__control wpbc_modal__add_booking__allow_past_control btn-group" style="position:static;margin:0 0 0 6px;display:inline-flex;vertical-align:middle;">
199 + <?php wpbc_flex_toggle( $params_checkbox ); ?>
200 + </div>
201 + <?php
202 + }
203 +
204 +
205 + /**
143 206 * Print modal loading spinner.
144 207 *
145 208 * @return void
146 209 */
@@ -216,9 +279,9 @@
216 279 * @return void
217 280 */
218 281 private static function print_modal_booking_form_edit_link() {
219 282
220 - if ( ! defined( 'WPBC_NEW_FORM_BUILDER' ) || ! WPBC_NEW_FORM_BUILDER || ! function_exists( 'wpbc_get_settings_url' ) ) {
283 + if ( ! function_exists( 'wpbc_get_settings_url' ) ) {
221 284 return;
222 285 }
223 286
224 287 $base_url = add_query_arg(
@@ -320,8 +383,13 @@
320 383 ) {
321 384 wp_send_json_error( array( 'message' => __( 'You do not have access to this booking resource.', 'booking' ) ), 403 );
322 385 }
323 386
387 + if ( ( 'add' === $args['mode'] ) && ( '' === (string) $args['booking_form'] ) ) {
388 + $args['booking_form'] = WPBC_Add_Booking_Component::get_default_booking_form_for_resource( $args['resource_id'], 'standard' );
389 + $args['custom_booking_form'] = $args['booking_form'];
390 + }
391 +
324 392 $html = self::render_component_with_legacy_request_context( $args );
325 393
326 394 wp_send_json_success(
327 395 array(
@@ -332,11 +400,17 @@
332 400 'title' => ( 'edit' === $args['mode'] ) ? __( 'Edit booking', 'booking' ) : __( 'Add booking', 'booking' ),
333 401 'button_title' => ( 'edit' === $args['mode'] ) ? __( 'Save booking', 'booking' ) : __( 'Add booking', 'booking' ),
334 402 'booking_id' => absint( $args['booking_id'] ),
335 403 'booking_form' => (string) $args['booking_form'],
404 + 'allow_past' => absint( $args['allow_past'] ),
336 405 'selected_dates_without_calendar' => (string) $args['selected_dates_without_calendar'],
406 + 'selected_dates' => (string) $args['selected_dates'],
337 407 'selected_date' => (string) $args['selected_date'],
338 408 'selected_time' => (string) $args['selected_time'],
409 + 'time_override_enabled' => absint( $args['time_override_enabled'] ),
410 + 'time_override_source' => (string) $args['time_override_source'],
411 + 'time_override_start' => (string) $args['time_override_start'],
412 + 'time_override_end' => (string) $args['time_override_end'],
339 413 )
340 414 );
341 415 }
342 416
@@ -354,11 +428,17 @@
354 428 $booking_hash = isset( $_POST['booking_hash'] ) ? sanitize_text_field( wp_unslash( $_POST['booking_hash'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
355 429 $resource_id = isset( $_POST['resource_id'] ) ? absint( $_POST['resource_id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Missing
356 430 $booking_id = isset( $_POST['booking_id'] ) ? absint( $_POST['booking_id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Missing
357 431 $booking_form = isset( $_POST['booking_form'] ) ? sanitize_text_field( wp_unslash( $_POST['booking_form'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
432 + $allow_past = isset( $_POST['allow_past'] ) ? absint( $_POST['allow_past'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Missing
358 433 $selected_dates_without_calendar = isset( $_POST['selected_dates_without_calendar'] ) ? sanitize_text_field( wp_unslash( $_POST['selected_dates_without_calendar'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
434 + $selected_dates = isset( $_POST['selected_dates'] ) ? sanitize_text_field( wp_unslash( $_POST['selected_dates'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
359 435 $selected_date = isset( $_POST['selected_date'] ) ? sanitize_text_field( wp_unslash( $_POST['selected_date'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
360 436 $selected_time = isset( $_POST['selected_time'] ) ? sanitize_text_field( wp_unslash( $_POST['selected_time'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
437 + $time_override_enabled = isset( $_POST['time_override_enabled'] ) ? absint( $_POST['time_override_enabled'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Missing
438 + $time_override_source = isset( $_POST['time_override_source'] ) ? sanitize_key( wp_unslash( $_POST['time_override_source'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
439 + $time_override_start = isset( $_POST['time_override_start'] ) ? self::sanitize_time_hm( wp_unslash( $_POST['time_override_start'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
440 + $time_override_end = isset( $_POST['time_override_end'] ) ? self::sanitize_time_hm( wp_unslash( $_POST['time_override_end'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
361 441
362 442 if ( '' !== $booking_hash ) {
363 443 $hash_resource = wpbc_hash__get_booking_id__resource_id( $booking_hash );
364 444 if ( false === $hash_resource ) {
@@ -367,8 +447,9 @@
367 447
368 448 $booking_id = absint( $hash_resource[0] );
369 449 $resource_id = absint( $hash_resource[1] );
370 450 $mode = 'edit';
451 + $allow_past = 1;
371 452 }
372 453
373 454 return array(
374 455 'mode' => $mode,
@@ -377,11 +458,17 @@
377 458 'booking_id' => $booking_id,
378 459 'booking_hash' => $booking_hash,
379 460 'booking_form' => $booking_form,
380 461 'custom_booking_form' => $booking_form,
462 + 'allow_past' => $allow_past ? 1 : 0,
381 463 'selected_dates_without_calendar' => $selected_dates_without_calendar,
464 + 'selected_dates' => $selected_dates,
382 465 'selected_date' => $selected_date,
383 466 'selected_time' => $selected_time,
467 + 'time_override_enabled' => ( $time_override_enabled && $time_override_start && $time_override_end ) ? 1 : 0,
468 + 'time_override_source' => $time_override_source,
469 + 'time_override_start' => $time_override_start,
470 + 'time_override_end' => $time_override_end,
384 471 'is_toolbar_visible' => false,
385 472 'is_booking_page_js' => false,
386 473 'is_booking_page_popover' => false,
387 474 'is_show_before_content_spacer'=> false,
@@ -393,8 +480,34 @@
393 480 }
394 481
395 482
396 483 /**
484 + * Sanitize HH:MM time value.
485 + *
486 + * @param string $time_value Time value.
487 + *
488 + * @return string
489 + */
490 + private static function sanitize_time_hm( $time_value ) {
491 +
492 + $time_value = trim( sanitize_text_field( (string) $time_value ) );
493 +
494 + if ( ! preg_match( '/^([0-9]{1,2}):([0-9]{2})$/', $time_value, $matches ) ) {
495 + return '';
496 + }
497 +
498 + $hour = absint( $matches[1] );
499 + $minute = absint( $matches[2] );
500 +
501 + if ( $hour > 24 || $minute > 59 || ( 24 === $hour && 0 !== $minute ) ) {
502 + return '';
503 + }
504 +
505 + return sprintf( '%02d:%02d', $hour, $minute );
506 + }
507 +
508 +
509 + /**
397 510 * Render the component with a scoped legacy request context for older renderers that still read $_GET.
398 511 *
399 512 * @param array $args Component args.
400 513 *
@@ -417,8 +530,12 @@
417 530 $query_args['booking_hash'] = $args['booking_hash'];
418 531 $query_args['parent_res'] = 1;
419 532 }
420 533
534 + if ( ! empty( $args['allow_past'] ) || ( '' !== $args['booking_hash'] ) ) {
535 + $query_args['allow_past'] = 1;
536 + }
537 +
421 538 if ( '' !== $args['booking_form'] ) {
422 539 $query_args['booking_form'] = $args['booking_form'];
423 540 }
424 541
@@ -426,9 +543,9 @@
426 543 $_GET[ $key ] = $value;
427 544 $_REQUEST[ $key ] = $value;
428 545 }
429 546
430 - $_SERVER['REQUEST_URI'] = 'admin.php?' . http_build_query( $query_args, '', '&' );
547 + $_SERVER['REQUEST_URI'] = wp_parse_url( admin_url( 'admin.php' ), PHP_URL_PATH ) . '?' . http_build_query( $query_args, '', '&' );
431 548
432 549 try {
433 550 return WPBC_Add_Booking_Component::render( $args );
434 551 } finally {
@@ -517,8 +634,14 @@
517 634 public static function is_supported_admin_page() {
518 635
519 636 if ( ! is_admin() ) {
520 637 return false;
638 + }
639 +
640 + if ( function_exists( 'wpbc_is_availability_page' ) && wpbc_is_availability_page() ) {
641 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
642 + $requested_tab = isset( $_REQUEST['tab'] ) ? sanitize_key( wp_unslash( $_REQUEST['tab'] ) ) : '';
643 + return ( 'time_slots_availability' === $requested_tab );
521 644 }
522 645
523 646 if ( function_exists( 'wpbc_is_bookings_page' ) ) {
524 647 if ( ! wpbc_is_bookings_page() ) {