| 1 |
<?php |
| 2 |
/** |
| 3 |
* Add Booking modal for Booking Listing and Timeline. |
| 4 |
* |
| 5 |
* @package Booking Calendar |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; // Exit, if accessed directly. |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* Class WPBC_Add_Booking_Modal |
| 14 |
*/ |
| 15 |
class WPBC_Add_Booking_Modal { |
| 16 |
|
| 17 |
const AJAX_ACTION = 'WPBC_AJX_ADD_BOOKING_MODAL'; |
| 18 |
|
| 19 |
/** |
| 20 |
* Print top toolbar button for opening the Add Booking popup. |
| 21 |
* |
| 22 |
* @param string $page_tag Current page tag. |
| 23 |
* @param string $active_page_tab Current tab. |
| 24 |
* @param string $active_page_subtab Current subtab. |
| 25 |
* |
| 26 |
* @return false|void |
| 27 |
*/ |
| 28 |
public static function print_top_toolbar_button( $page_tag, $active_page_tab, $active_page_subtab ) { |
| 29 |
|
| 30 |
if ( ( 'wpbc' !== $page_tag ) || ! in_array( $active_page_tab, array( 'vm_booking_listing', 'vm_calendar' ), true ) ) { |
| 31 |
return false; |
| 32 |
} |
| 33 |
|
| 34 |
if ( ! WPBC_Add_Booking_Component::current_user_can_add_booking() ) { |
| 35 |
return false; |
| 36 |
} |
| 37 |
|
| 38 |
?> |
| 39 |
<div class="wpbc_ui_el__buttons_group wpbc_booking_listing__top_toolbar_group"> |
| 40 |
<a href="javascript:void(0);" |
| 41 |
id="wpbc_booking_listing_add_booking_button" |
| 42 |
class="button button-primary" |
| 43 |
onclick="wpbc_boo_listing__click__add_booking_modal( { mode: 'add' } );" |
| 44 |
title="<?php esc_attr_e( 'Create booking without leaving this view', 'booking' ); ?>"> |
| 45 |
<i class="menu_icon icon-1x wpbc-bi-plus"></i> |
| 46 |
<?php esc_html_e( 'New booking', 'booking' ); ?> |
| 47 |
</a> |
| 48 |
</div> |
| 49 |
<?php |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
/** |
| 54 |
* Get template for modal window. |
| 55 |
* |
| 56 |
* @return void |
| 57 |
*/ |
| 58 |
public static function template_for_modal() { |
| 59 |
|
| 60 |
$nonce = wp_create_nonce( strtolower( self::AJAX_ACTION ) . '_wpbcnonce' ); |
| 61 |
?> |
| 62 |
<span class="wpdevelop"> |
| 63 |
<div id="wpbc_modal__add_booking__section" |
| 64 |
class="modal wpbc_popup_modal wpbc_modal_in_listing wpbc_modal__add_booking__section" |
| 65 |
tabindex="-1" |
| 66 |
role="dialog" |
| 67 |
data-wpbc-add-booking-nonce="<?php echo esc_attr( $nonce ); ?>" |
| 68 |
data-wpbc-add-booking-resource-id=""> |
| 69 |
<div class="modal-dialog modal-lg"> |
| 70 |
<div class="modal-content"> |
| 71 |
<div class="modal-header"> |
| 72 |
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> |
| 73 |
<div class="wpbc_modal__add_booking__header_main"> |
| 74 |
<h4 class="modal-title"> |
| 75 |
<span class="wpbc_modal__add_booking__title"><?php esc_html_e( 'Add booking', 'booking' ); ?></span> |
| 76 |
<sup class="wpbc_modal__add_booking__booking_id wpbc_modal__booking_id__in_title"></sup> |
| 77 |
</h4> |
| 78 |
<div class="wpbc_modal__add_booking__controls"> |
| 79 |
<?php self::print_modal_resource_select(); ?> |
| 80 |
<?php self::print_modal_booking_form_select(); ?> |
| 81 |
</div> |
| 82 |
</div> |
| 83 |
</div> |
| 84 |
<div class="modal-body"> |
| 85 |
<div id="wpbc_modal__add_booking__body" class="wpbc_modal__add_booking__body"> |
| 86 |
<?php self::print_loading_spinner(); ?> |
| 87 |
</div> |
| 88 |
</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();"> |
| 92 |
<?php esc_html_e( 'Add booking', 'booking' ); ?> |
| 93 |
</a> |
| 94 |
<a href="javascript:void(0)" class="button button-secondary" data-dismiss="modal"> |
| 95 |
<?php esc_html_e( 'Close', 'booking' ); ?> |
| 96 |
</a> |
| 97 |
</div> |
| 98 |
</div><!-- /.modal-content --> |
| 99 |
</div><!-- /.modal-dialog --> |
| 100 |
</div><!-- /.modal --> |
| 101 |
</span> |
| 102 |
<?php |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
/** |
| 107 |
* Print modal-scoped email notification toggle. |
| 108 |
* |
| 109 |
* The legacy Add Booking page uses #is_send_email_for_pending. Timeline uses the same id, |
| 110 |
* so the modal needs its own id to avoid cross-toggling that page control. |
| 111 |
* |
| 112 |
* @return void |
| 113 |
*/ |
| 114 |
private static function print_modal_send_emails_toggle() { |
| 115 |
|
| 116 |
$el_id = 'wpbc_modal__add_booking__is_send_email_for_pending'; |
| 117 |
$el_value = ( get_bk_option( 'booking_send_emails_off_addbooking' ) !== 'On' ) ? 'On' : 'Off'; |
| 118 |
|
| 119 |
$params_checkbox = array( |
| 120 |
'id' => $el_id, |
| 121 |
'name' => $el_id, |
| 122 |
'label' => array( 'title' => __( 'Emails sending', 'booking' ), 'position' => 'right' ), |
| 123 |
'style' => '', |
| 124 |
'class' => '', |
| 125 |
'disabled' => false, |
| 126 |
'attr' => array( |
| 127 |
'data-wpbc-add-booking-send-emails' => '1', |
| 128 |
), |
| 129 |
'legend' => '', |
| 130 |
'value' => $el_value, |
| 131 |
'selected' => ( 'On' === $el_value ), |
| 132 |
'hint' => array( 'title' => __( 'Send email notification to customer about this operation', 'booking' ), 'position' => 'top' ), |
| 133 |
); |
| 134 |
?> |
| 135 |
<div class="btn-group" style="position:static;margin:0 10px 0 0;display:inline-flex;vertical-align:middle;"> |
| 136 |
<?php wpbc_flex_toggle( $params_checkbox ); ?> |
| 137 |
</div> |
| 138 |
<?php |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
/** |
| 143 |
* Print modal loading spinner. |
| 144 |
* |
| 145 |
* @return void |
| 146 |
*/ |
| 147 |
private static function print_loading_spinner() { |
| 148 |
?> |
| 149 |
<div class="wpbc_spins_loading_container"> |
| 150 |
<div class="wpbc_booking_form_spin_loader"> |
| 151 |
<div class="wpbc_spins_loader_wrapper"> |
| 152 |
<div class="wpbc_spin_loader_one_new"></div> |
| 153 |
</div> |
| 154 |
</div> |
| 155 |
<span><?php esc_html_e( 'Loading', 'booking' ); ?>...</span> |
| 156 |
</div> |
| 157 |
<?php |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
/** |
| 162 |
* Print booking resource selector for the modal header. |
| 163 |
* |
| 164 |
* @return void |
| 165 |
*/ |
| 166 |
private static function print_modal_resource_select() { |
| 167 |
|
| 168 |
$selected_resource = absint( wpbc_get_default_resource() ); |
| 169 |
$selected_resource = $selected_resource ? $selected_resource : 1; |
| 170 |
$resources = self::get_booking_resource_options(); |
| 171 |
?> |
| 172 |
<label class="wpbc_modal__add_booking__control wpbc_modal__add_booking__resource_control" for="wpbc_modal__add_booking__resource_id"> |
| 173 |
<span><?php esc_html_e( 'Resource', 'booking' ); ?>:</span> |
| 174 |
<select id="wpbc_modal__add_booking__resource_id" class="wpbc_modal__add_booking__resource_id"> |
| 175 |
<?php foreach ( $resources as $resource_id => $resource ) : ?> |
| 176 |
<option value="<?php echo esc_attr( absint( $resource_id ) ); ?>" <?php selected( absint( $resource_id ), $selected_resource ); ?>> |
| 177 |
<?php echo esc_html( $resource['title'] ); ?> |
| 178 |
</option> |
| 179 |
<?php endforeach; ?> |
| 180 |
</select> |
| 181 |
</label> |
| 182 |
<?php |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
/** |
| 187 |
* Print custom booking form selector for the modal header. |
| 188 |
* |
| 189 |
* @return void |
| 190 |
*/ |
| 191 |
private static function print_modal_booking_form_select() { |
| 192 |
|
| 193 |
$form_options = self::get_booking_form_options(); |
| 194 |
if ( count( $form_options ) <= 1 ) { |
| 195 |
return; |
| 196 |
} |
| 197 |
?> |
| 198 |
<label class="wpbc_modal__add_booking__control wpbc_modal__add_booking__form_control" for="wpbc_modal__add_booking__booking_form"> |
| 199 |
<span><?php esc_html_e( 'Booking Form', 'booking' ); ?>:</span> |
| 200 |
<select id="wpbc_modal__add_booking__booking_form" class="wpbc_modal__add_booking__booking_form"> |
| 201 |
<?php foreach ( $form_options as $form_name => $form_title ) : ?> |
| 202 |
<option value="<?php echo esc_attr( $form_name ); ?>"> |
| 203 |
<?php echo esc_html( $form_title ); ?> |
| 204 |
</option> |
| 205 |
<?php endforeach; ?> |
| 206 |
</select> |
| 207 |
</label> |
| 208 |
<?php self::print_modal_booking_form_edit_link(); ?> |
| 209 |
<?php |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
/** |
| 214 |
* Print link to edit currently selected form in Forms Builder. |
| 215 |
* |
| 216 |
* @return void |
| 217 |
*/ |
| 218 |
private static function print_modal_booking_form_edit_link() { |
| 219 |
|
| 220 |
if ( ! defined( 'WPBC_NEW_FORM_BUILDER' ) || ! WPBC_NEW_FORM_BUILDER || ! function_exists( 'wpbc_get_settings_url' ) ) { |
| 221 |
return; |
| 222 |
} |
| 223 |
|
| 224 |
$base_url = add_query_arg( |
| 225 |
array( |
| 226 |
'tab' => 'builder_booking_form', |
| 227 |
'form_name' => 'standard', |
| 228 |
), |
| 229 |
wpbc_get_settings_url() |
| 230 |
); |
| 231 |
?> |
| 232 |
<a href="<?php echo esc_url( $base_url ); ?>" |
| 233 |
class="wpbc_modal__add_booking__edit_form_link" |
| 234 |
data-wpbc-add-booking-form-builder-url="<?php echo esc_url( remove_query_arg( 'form_name', $base_url ) ); ?>" |
| 235 |
target="_blank" |
| 236 |
rel="noopener noreferrer" |
| 237 |
title="<?php esc_attr_e( 'Edit selected booking form', 'booking' ); ?>"> |
| 238 |
<i class="menu_icon icon-1x wpbc_icn_draw"></i> |
| 239 |
<span><?php esc_html_e( 'Edit form', 'booking' ); ?></span> |
| 240 |
</a> |
| 241 |
<?php |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
/** |
| 246 |
* Enqueue client booking-form scripts required by the modal body. |
| 247 |
* |
| 248 |
* @param string $where_to_load Load context. |
| 249 |
* |
| 250 |
* @return void |
| 251 |
*/ |
| 252 |
public static function enqueue_js_files( $where_to_load ) { |
| 253 |
|
| 254 |
if ( ! self::is_supported_admin_page() || ! in_array( $where_to_load, array( 'admin', 'both' ), true ) ) { |
| 255 |
return; |
| 256 |
} |
| 257 |
|
| 258 |
wp_enqueue_script( 'wpbc-main-client', wpbc_plugin_url( '/js/client.js' ), array( 'wpbc-datepick' ), WP_BK_VERSION_NUM, array( 'in_footer' => WPBC_JS_IN_FOOTER ) ); |
| 259 |
wp_enqueue_script( 'wpbc_capacity', wpbc_plugin_url( '/includes/_capacity/_out/create_booking.js' ), array( 'wpbc-main-client' ), WP_BK_VERSION_NUM, array( 'in_footer' => WPBC_JS_IN_FOOTER ) ); |
| 260 |
wp_enqueue_script( 'wpbc-times', wpbc_plugin_url( '/js/wpbc_times.js' ), array( 'wpbc-main-client' ), WP_BK_VERSION_NUM, array( 'in_footer' => WPBC_JS_IN_FOOTER ) ); |
| 261 |
wp_enqueue_script( 'wpbc-time-selector', wpbc_plugin_url( '/js/wpbc_time-selector.js' ), array( 'wpbc-times' ), WP_BK_VERSION_NUM, array( 'in_footer' => WPBC_JS_IN_FOOTER ) ); |
| 262 |
wp_enqueue_script( 'wpbc-imask', wpbc_plugin_url( '/vendors/imask/dist/imask.js' ), array( 'wpbc-main-client' ), WP_BK_VERSION_NUM, array( 'in_footer' => WPBC_JS_IN_FOOTER ) ); |
| 263 |
wp_enqueue_script( 'wpbc-boo_listing_ajx_actions', wpbc_plugin_url( '/includes/page-bookings/_out/boo_listing__actions.js' ), array( 'wpbc_all', 'wpbc-modal' ), WP_BK_VERSION_NUM, array( 'in_footer' => WPBC_JS_IN_FOOTER ) ); |
| 264 |
|
| 265 |
if ( 'On' === get_bk_option( 'booking_is_use_phone_validation' ) ) { |
| 266 |
wp_enqueue_script( 'wpbc-iphone-validator', wpbc_plugin_url( '/js/wpbc_phone_validator.js' ), array( 'wpbc-imask' ), WP_BK_VERSION_NUM, array( 'in_footer' => WPBC_JS_IN_FOOTER ) ); |
| 267 |
} |
| 268 |
} |
| 269 |
|
| 270 |
|
| 271 |
/** |
| 272 |
* Enqueue front-end booking-form styles required by the modal body. |
| 273 |
* |
| 274 |
* @param string $where_to_load Load context. |
| 275 |
* |
| 276 |
* @return void |
| 277 |
*/ |
| 278 |
public static function enqueue_css_files( $where_to_load ) { |
| 279 |
|
| 280 |
if ( ! self::is_supported_admin_page() || ! in_array( $where_to_load, array( 'admin', 'both' ), true ) ) { |
| 281 |
return; |
| 282 |
} |
| 283 |
|
| 284 |
if ( function_exists( 'wpbc_enqueue_styles__front_end' ) ) { |
| 285 |
wpbc_enqueue_styles__front_end(); |
| 286 |
} |
| 287 |
} |
| 288 |
|
| 289 |
|
| 290 |
/** |
| 291 |
* AJAX: render Add Booking modal body. |
| 292 |
* |
| 293 |
* @return void |
| 294 |
*/ |
| 295 |
public static function ajax_render() { |
| 296 |
|
| 297 |
check_ajax_referer( strtolower( self::AJAX_ACTION ) . '_wpbcnonce', 'nonce' ); |
| 298 |
|
| 299 |
if ( ! wpbc_is_mu_user_can_be_here( 'activated_user' ) ) { |
| 300 |
wp_send_json_error( array( 'message' => __( 'You do not have access to this page.', 'booking' ) ), 403 ); |
| 301 |
} |
| 302 |
|
| 303 |
$args = self::get_clean_request_args(); |
| 304 |
|
| 305 |
if ( ( 'add' === $args['mode'] ) && ! WPBC_Add_Booking_Component::current_user_can_add_booking() ) { |
| 306 |
wp_send_json_error( array( 'message' => __( 'You do not have access to this page.', 'booking' ) ), 403 ); |
| 307 |
} |
| 308 |
|
| 309 |
if ( empty( $args['resource_id'] ) ) { |
| 310 |
$args['resource_id'] = wpbc_get_default_resource(); |
| 311 |
} |
| 312 |
|
| 313 |
if ( empty( $args['resource_id'] ) ) { |
| 314 |
wp_send_json_error( array( 'message' => __( 'Booking resource type is not defined.', 'booking' ) ), 400 ); |
| 315 |
} |
| 316 |
|
| 317 |
if ( |
| 318 |
class_exists( 'wpdev_bk_multiuser' ) |
| 319 |
&& ! wpbc_is_mu_user_can_be_here( 'resource_owner', $args['resource_id'] ) |
| 320 |
) { |
| 321 |
wp_send_json_error( array( 'message' => __( 'You do not have access to this booking resource.', 'booking' ) ), 403 ); |
| 322 |
} |
| 323 |
|
| 324 |
$html = self::render_component_with_legacy_request_context( $args ); |
| 325 |
|
| 326 |
wp_send_json_success( |
| 327 |
array( |
| 328 |
'html' => $html, |
| 329 |
'resource_id' => absint( $args['resource_id'] ), |
| 330 |
'booking_hash' => (string) $args['booking_hash'], |
| 331 |
'mode' => (string) $args['mode'], |
| 332 |
'title' => ( 'edit' === $args['mode'] ) ? __( 'Edit booking', 'booking' ) : __( 'Add booking', 'booking' ), |
| 333 |
'button_title' => ( 'edit' === $args['mode'] ) ? __( 'Save booking', 'booking' ) : __( 'Add booking', 'booking' ), |
| 334 |
'booking_id' => absint( $args['booking_id'] ), |
| 335 |
'booking_form' => (string) $args['booking_form'], |
| 336 |
'selected_dates_without_calendar' => (string) $args['selected_dates_without_calendar'], |
| 337 |
'selected_date' => (string) $args['selected_date'], |
| 338 |
'selected_time' => (string) $args['selected_time'], |
| 339 |
) |
| 340 |
); |
| 341 |
} |
| 342 |
|
| 343 |
|
| 344 |
/** |
| 345 |
* Get sanitized request args. |
| 346 |
* |
| 347 |
* @return array |
| 348 |
*/ |
| 349 |
private static function get_clean_request_args() { |
| 350 |
|
| 351 |
$mode = isset( $_POST['mode'] ) ? sanitize_key( wp_unslash( $_POST['mode'] ) ) : 'add'; // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 352 |
$mode = in_array( $mode, array( 'add', 'edit' ), true ) ? $mode : 'add'; |
| 353 |
|
| 354 |
$booking_hash = isset( $_POST['booking_hash'] ) ? sanitize_text_field( wp_unslash( $_POST['booking_hash'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 355 |
$resource_id = isset( $_POST['resource_id'] ) ? absint( $_POST['resource_id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 356 |
$booking_id = isset( $_POST['booking_id'] ) ? absint( $_POST['booking_id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 357 |
$booking_form = isset( $_POST['booking_form'] ) ? sanitize_text_field( wp_unslash( $_POST['booking_form'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 358 |
$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 |
| 359 |
$selected_date = isset( $_POST['selected_date'] ) ? sanitize_text_field( wp_unslash( $_POST['selected_date'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 360 |
$selected_time = isset( $_POST['selected_time'] ) ? sanitize_text_field( wp_unslash( $_POST['selected_time'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 361 |
|
| 362 |
if ( '' !== $booking_hash ) { |
| 363 |
$hash_resource = wpbc_hash__get_booking_id__resource_id( $booking_hash ); |
| 364 |
if ( false === $hash_resource ) { |
| 365 |
wp_send_json_error( array( 'message' => __( 'We could not find your booking. The link you used may be incorrect or has expired.', 'booking' ) ), 404 ); |
| 366 |
} |
| 367 |
|
| 368 |
$booking_id = absint( $hash_resource[0] ); |
| 369 |
$resource_id = absint( $hash_resource[1] ); |
| 370 |
$mode = 'edit'; |
| 371 |
} |
| 372 |
|
| 373 |
return array( |
| 374 |
'mode' => $mode, |
| 375 |
'resource_id' => $resource_id, |
| 376 |
'booking_type' => $resource_id, |
| 377 |
'booking_id' => $booking_id, |
| 378 |
'booking_hash' => $booking_hash, |
| 379 |
'booking_form' => $booking_form, |
| 380 |
'custom_booking_form' => $booking_form, |
| 381 |
'selected_dates_without_calendar' => $selected_dates_without_calendar, |
| 382 |
'selected_date' => $selected_date, |
| 383 |
'selected_time' => $selected_time, |
| 384 |
'is_toolbar_visible' => false, |
| 385 |
'is_booking_page_js' => false, |
| 386 |
'is_booking_page_popover' => false, |
| 387 |
'is_show_before_content_spacer'=> false, |
| 388 |
'is_show_footer_email_toggle' => false, |
| 389 |
'content_css_class' => 'add_booking_page_content wpbc_add_booking_component__in_modal', |
| 390 |
'content_style' => 'width:100%;margin-bottom:20px;', |
| 391 |
'is_echo' => 0, |
| 392 |
); |
| 393 |
} |
| 394 |
|
| 395 |
|
| 396 |
/** |
| 397 |
* Render the component with a scoped legacy request context for older renderers that still read $_GET. |
| 398 |
* |
| 399 |
* @param array $args Component args. |
| 400 |
* |
| 401 |
* @return string |
| 402 |
*/ |
| 403 |
private static function render_component_with_legacy_request_context( $args ) { |
| 404 |
|
| 405 |
$old_get = $_GET; |
| 406 |
$old_request = $_REQUEST; |
| 407 |
$old_request_uri = isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : ''; |
| 408 |
|
| 409 |
$query_args = array( |
| 410 |
'page' => 'wpbc', |
| 411 |
'tab' => 'add-booking', |
| 412 |
'booking_type' => absint( $args['resource_id'] ), |
| 413 |
'is_show_payment_form' => 'Off', |
| 414 |
); |
| 415 |
|
| 416 |
if ( '' !== $args['booking_hash'] ) { |
| 417 |
$query_args['booking_hash'] = $args['booking_hash']; |
| 418 |
$query_args['parent_res'] = 1; |
| 419 |
} |
| 420 |
|
| 421 |
if ( '' !== $args['booking_form'] ) { |
| 422 |
$query_args['booking_form'] = $args['booking_form']; |
| 423 |
} |
| 424 |
|
| 425 |
foreach ( $query_args as $key => $value ) { |
| 426 |
$_GET[ $key ] = $value; |
| 427 |
$_REQUEST[ $key ] = $value; |
| 428 |
} |
| 429 |
|
| 430 |
$_SERVER['REQUEST_URI'] = 'admin.php?' . http_build_query( $query_args, '', '&' ); |
| 431 |
|
| 432 |
try { |
| 433 |
return WPBC_Add_Booking_Component::render( $args ); |
| 434 |
} finally { |
| 435 |
$_GET = $old_get; |
| 436 |
$_REQUEST = $old_request; |
| 437 |
$_SERVER['REQUEST_URI'] = $old_request_uri; |
| 438 |
} |
| 439 |
} |
| 440 |
|
| 441 |
|
| 442 |
/** |
| 443 |
* Get booking resource options for the modal selector. |
| 444 |
* |
| 445 |
* @return array |
| 446 |
*/ |
| 447 |
private static function get_booking_resource_options() { |
| 448 |
|
| 449 |
$resources = array(); |
| 450 |
|
| 451 |
if ( function_exists( 'wpbc_get_all_booking_resources_list' ) ) { |
| 452 |
$resources = wpbc_get_all_booking_resources_list(); |
| 453 |
} |
| 454 |
|
| 455 |
if ( empty( $resources ) ) { |
| 456 |
$default_resource = absint( wpbc_get_default_resource() ); |
| 457 |
$default_resource = $default_resource ? $default_resource : 1; |
| 458 |
$resources = array( |
| 459 |
$default_resource => array( |
| 460 |
'title' => __( 'Default', 'booking' ), |
| 461 |
'attr' => array(), |
| 462 |
), |
| 463 |
); |
| 464 |
} |
| 465 |
|
| 466 |
return $resources; |
| 467 |
} |
| 468 |
|
| 469 |
|
| 470 |
/** |
| 471 |
* Get booking form options for the modal selector. |
| 472 |
* |
| 473 |
* @return array |
| 474 |
*/ |
| 475 |
private static function get_booking_form_options() { |
| 476 |
|
| 477 |
$options = array( |
| 478 |
'standard' => __( 'Standard', 'booking' ), |
| 479 |
); |
| 480 |
|
| 481 |
if ( ! class_exists( 'WPBC_FE_Custom_Form_Helper' ) ) { |
| 482 |
return $options; |
| 483 |
} |
| 484 |
|
| 485 |
$is_can = apply_bk_filter( 'multiuser_is_user_can_be_here', true, 'only_super_admin' ); |
| 486 |
if ( ( ! $is_can ) && ( 'On' !== get_bk_option( 'booking_is_custom_forms_for_regular_users' ) ) ) { |
| 487 |
return $options; |
| 488 |
} |
| 489 |
|
| 490 |
$owner_user_id = WPBC_FE_Custom_Form_Helper::wpbc_mu__get_current__owner_user_id(); |
| 491 |
$forms = WPBC_FE_Custom_Form_Helper::get_custom_booking_forms_list( |
| 492 |
array( |
| 493 |
'include_standard' => false, |
| 494 |
'owner_user_id' => $owner_user_id, |
| 495 |
'statuses' => array( 'published' ), |
| 496 |
'list_mode' => 'auto', |
| 497 |
) |
| 498 |
); |
| 499 |
|
| 500 |
foreach ( $forms as $form ) { |
| 501 |
if ( empty( $form['name'] ) ) { |
| 502 |
continue; |
| 503 |
} |
| 504 |
$form_title = ! empty( $form['title'] ) ? $form['title'] : $form['name']; |
| 505 |
$options[ $form['name'] ] = wpbc_lang( $form_title ); |
| 506 |
} |
| 507 |
|
| 508 |
return $options; |
| 509 |
} |
| 510 |
|
| 511 |
|
| 512 |
/** |
| 513 |
* Check if assets should be loaded for Booking Listing or Timeline view. |
| 514 |
* |
| 515 |
* @return bool |
| 516 |
*/ |
| 517 |
public static function is_supported_admin_page() { |
| 518 |
|
| 519 |
if ( ! is_admin() ) { |
| 520 |
return false; |
| 521 |
} |
| 522 |
|
| 523 |
if ( function_exists( 'wpbc_is_bookings_page' ) ) { |
| 524 |
if ( ! wpbc_is_bookings_page() ) { |
| 525 |
return false; |
| 526 |
} |
| 527 |
} else { |
| 528 |
$server_request_uri = ( isset( $_SERVER['REQUEST_URI'] ) ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 529 |
if ( ( false === strpos( $server_request_uri, 'page=wpbc' ) ) || ( false !== strpos( $server_request_uri, 'page=wpbc-' ) ) ) { |
| 530 |
return false; |
| 531 |
} |
| 532 |
} |
| 533 |
|
| 534 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 535 |
$requested_tab = isset( $_REQUEST['tab'] ) ? sanitize_key( wp_unslash( $_REQUEST['tab'] ) ) : ''; |
| 536 |
if ( '' !== $requested_tab ) { |
| 537 |
return in_array( $requested_tab, array( 'vm_booking_listing', 'vm_calendar' ), true ); |
| 538 |
} |
| 539 |
|
| 540 |
if ( function_exists( 'wpbc_get_default_saved_view_mode_for_wpbc_page' ) ) { |
| 541 |
return in_array( wpbc_get_default_saved_view_mode_for_wpbc_page(), array( 'vm_booking_listing', 'vm_calendar' ), true ); |
| 542 |
} |
| 543 |
|
| 544 |
return true; |
| 545 |
} |
| 546 |
|
| 547 |
|
| 548 |
/** |
| 549 |
* Backward-compatible alias for existing Add Booking modal checks. |
| 550 |
* |
| 551 |
* @return bool |
| 552 |
*/ |
| 553 |
public static function is_booking_listing_admin_page() { |
| 554 |
|
| 555 |
return self::is_supported_admin_page(); |
| 556 |
} |
| 557 |
} |
| 558 |
|
| 559 |
/** |
| 560 |
* Check if Booking Listing or Timeline needs the Add Booking modal client assets. |
| 561 |
* |
| 562 |
* @return bool |
| 563 |
*/ |
| 564 |
if ( ! function_exists( 'wpbc_is_add_booking_modal_on_booking_listing_page' ) ) { |
| 565 |
/** |
| 566 |
* Check if Booking Listing or Timeline needs the Add Booking modal client assets. |
| 567 |
* |
| 568 |
* @return bool |
| 569 |
*/ |
| 570 |
function wpbc_is_add_booking_modal_on_booking_listing_page() { |
| 571 |
return WPBC_Add_Booking_Modal::is_supported_admin_page(); |
| 572 |
} |
| 573 |
} |
| 574 |
|
| 575 |
add_action( 'wpbc_ui_el__top_nav__content_end', array( 'WPBC_Add_Booking_Modal', 'print_top_toolbar_button' ), 19, 3 ); |
| 576 |
add_action( 'wpbc_hook_booking_template__hidden_templates', array( 'WPBC_Add_Booking_Modal', 'template_for_modal' ) ); |
| 577 |
add_action( 'wpbc_enqueue_js_files', array( 'WPBC_Add_Booking_Modal', 'enqueue_js_files' ), 52 ); |
| 578 |
add_action( 'wpbc_enqueue_css_files', array( 'WPBC_Add_Booking_Modal', 'enqueue_css_files' ), 52 ); |
| 579 |
add_action( 'wp_ajax_' . WPBC_Add_Booking_Modal::AJAX_ACTION, array( 'WPBC_Add_Booking_Modal', 'ajax_render' ) ); |
| 580 |
|