| 1 |
<?php |
| 2 |
/** |
| 3 |
* Description. |
| 4 |
* |
| 5 |
* @package Booking Calendar. |
| 6 |
* @author wpdevelop, oplugins |
| 7 |
* @web-site https://wpbookingcalendar.com/ |
| 8 |
* @email info@wpbookingcalendar.com |
| 9 |
* |
| 10 |
* @since 11.0.x |
| 11 |
* @file ../W:/w3/beta/www/wp-content/plugins/booking/includes/_front_end\class-custom-forms-helper.php.php |
| 12 |
* |
| 13 |
* @modified 2026-02-22 15:22 |
| 14 |
*/ |
| 15 |
|
| 16 |
if ( ! defined( 'ABSPATH' ) ) { |
| 17 |
exit; // Exit if accessed directly. |
| 18 |
} |
| 19 |
|
| 20 |
|
| 21 |
/** |
| 22 |
* Custom Form Helper. |
| 23 |
* |
| 24 |
* @since 11.0.x. |
| 25 |
*/ |
| 26 |
class WPBC_FE_Custom_Form_Helper { |
| 27 |
|
| 28 |
/** |
| 29 |
* List available booking forms from BFB storage. |
| 30 |
* |
| 31 |
* Returned array format: |
| 32 |
* array( |
| 33 |
* 'standard' => array( 'title' => '...', 'engine' => 'standard', 'name' => '' ), |
| 34 |
* 'mybfb' => array( 'title' => '...', 'engine' => 'bfb', 'name' => 'mybfb', 'id' => 12, 'status' => 'published' ), |
| 35 |
* ) |
| 36 |
* |
| 37 |
* @param array $params - array( |
| 38 |
* 'include_standard' => true, - include_standard (bool) default true . |
| 39 |
* 'owner_user_id' => 0, - owner_user_id (int) default 0 (0 = no filter) . |
| 40 |
* 'statuses' => array( 'published' ), - statuses (array) default array('published') . |
| 41 |
* 'list_mode' => 'bfb', - deprecated; BFB storage is always used. |
| 42 |
* ) |
| 43 |
* |
| 44 |
* @return array |
| 45 |
*/ |
| 46 |
public static function get_custom_booking_forms_list( $params = array() ) { |
| 47 |
|
| 48 |
$params = wp_parse_args( |
| 49 |
$params, |
| 50 |
array( |
| 51 |
'include_standard' => true, |
| 52 |
'owner_user_id' => 0, |
| 53 |
'statuses' => array( 'published' ), |
| 54 |
'list_mode' => 'bfb', |
| 55 |
) |
| 56 |
); |
| 57 |
|
| 58 |
$forms_list_arr = array(); |
| 59 |
|
| 60 |
// 1) Standard. |
| 61 |
if ( ! empty( $params['include_standard'] ) ) { |
| 62 |
$forms_list_arr['standard'] = array( |
| 63 |
'title' => __( 'Standard booking form', 'booking' ), |
| 64 |
'engine' => 'standard', |
| 65 |
'name' => '', |
| 66 |
); |
| 67 |
} |
| 68 |
|
| 69 |
// 2) BFB. |
| 70 |
if ( ! ( function_exists( 'wpbc_is_table_exists' ) && ! wpbc_is_table_exists( 'booking_form_structures' ) ) ) { |
| 71 |
|
| 72 |
global $wpdb; |
| 73 |
|
| 74 |
$owner_user_id = absint( $params['owner_user_id'] ); |
| 75 |
|
| 76 |
$statuses = ( isset( $params['statuses'] ) && is_array( $params['statuses'] ) ) ? $params['statuses'] : array(); |
| 77 |
$statuses = array_values( array_filter( array_map( 'sanitize_key', $statuses ) ) ); |
| 78 |
if ( empty( $statuses ) ) { |
| 79 |
$statuses = array( 'published' ); |
| 80 |
} |
| 81 |
|
| 82 |
$where = array(); |
| 83 |
$args = array(); |
| 84 |
|
| 85 |
$in_placeholders = implode( ',', array_fill( 0, count( $statuses ), '%s' ) ); |
| 86 |
$where[] = "status IN ($in_placeholders)"; |
| 87 |
$args = array_merge( $args, $statuses ); |
| 88 |
|
| 89 |
// FixIn: 2026-03-08. |
| 90 |
// if ( $owner_user_id > 0 ) { |
| 91 |
$where[] = 'owner_user_id = %d'; |
| 92 |
$args[] = $owner_user_id; |
| 93 |
// } |
| 94 |
|
| 95 |
$sql = "SELECT booking_form_id, form_slug, owner_user_id, status |
| 96 |
FROM {$wpdb->prefix}booking_form_structures |
| 97 |
WHERE " . implode( ' AND ', $where ) . ' |
| 98 |
ORDER BY is_default DESC, updated_at DESC, version DESC, booking_form_id DESC |
| 99 |
LIMIT 500'; |
| 100 |
|
| 101 |
$wpdb->last_error = ''; |
| 102 |
|
| 103 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter |
| 104 |
$rows = $wpdb->get_results( $wpdb->prepare( $sql, $args ), ARRAY_A ); |
| 105 |
|
| 106 |
if ( empty( $wpdb->last_error ) && ! empty( $rows ) ) { |
| 107 |
foreach ( $rows as $row ) { |
| 108 |
|
| 109 |
$form_slug = isset( $row['form_slug'] ) ? sanitize_text_field( (string) $row['form_slug'] ) : ''; |
| 110 |
if ( '' === $form_slug ) { |
| 111 |
continue; |
| 112 |
} |
| 113 |
|
| 114 |
$forms_list_arr[ $form_slug ] = array( |
| 115 |
'title' => $form_slug, // slug as label. |
| 116 |
'engine' => 'bfb', |
| 117 |
'name' => $form_slug, |
| 118 |
'id' => isset( $row['booking_form_id'] ) ? absint( $row['booking_form_id'] ) : 0, |
| 119 |
'status' => isset( $row['status'] ) ? sanitize_key( (string) $row['status'] ) : '', |
| 120 |
'owner_user_id' => isset( $row['owner_user_id'] ) ? absint( $row['owner_user_id'] ) : 0, |
| 121 |
); |
| 122 |
} |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
return $forms_list_arr; |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
public static function get_default_custom_form__for__booking_resource( $booking_resource_id ) { |
| 131 |
|
| 132 |
$default_custom_form = 'standard'; |
| 133 |
|
| 134 |
if ( ! class_exists( 'wpdev_bk_biz_m' ) ) { |
| 135 |
return $default_custom_form; |
| 136 |
} |
| 137 |
|
| 138 |
global $wpdb; |
| 139 |
$wpdb->last_error = ''; |
| 140 |
|
| 141 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 142 |
$result = $wpdb->get_row( $wpdb->prepare( "SELECT default_form FROM {$wpdb->prefix}bookingtypes WHERE booking_type_id = %d ", $booking_resource_id ) ); |
| 143 |
|
| 144 |
// If table does not exist or query fails, do not fatal — just skip. |
| 145 |
if ( empty( $wpdb->last_error ) && ! empty( $result ) ) { |
| 146 |
return $result->default_form; |
| 147 |
} |
| 148 |
|
| 149 |
return $default_custom_form; |
| 150 |
} |
| 151 |
|
| 152 |
/** |
| 153 |
* Get ID of current logged in user in MU logic. If user super admin, then return 0. |
| 154 |
* |
| 155 |
* @return int return ( > 0 ) only for the "regular users" in MU context. |
| 156 |
*/ |
| 157 |
public static function wpbc_mu__get_current__owner_user_id() { |
| 158 |
// == MU owner logic == |
| 159 |
$owner_user_id = 0; |
| 160 |
if ( class_exists( 'wpdev_bk_multiuser' ) ) { |
| 161 |
$current_user_id = wpbc_get_current_user_id(); |
| 162 |
$is_user_super_admin = apply_bk_filter( 'is_user_super_admin', $current_user_id ); |
| 163 |
if ( ! $is_user_super_admin ) { |
| 164 |
$owner_user_id = $current_user_id; |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
return $owner_user_id; |
| 169 |
} |
| 170 |
|
| 171 |
// == HMTL ========================================================================================================= |
| 172 |
/** |
| 173 |
* Custom booking forms - HTML Selectbox -> WP Booking Calendar > Add Booking page. |
| 174 |
* |
| 175 |
* @return void |
| 176 |
*/ |
| 177 |
public static function wpbc_bfb__custom_booking_forms_list__selectbox_html( $params = array() ) { |
| 178 |
|
| 179 |
// == Legacy | Check if we can be here. == |
| 180 |
$is_can = apply_bk_filter( 'multiuser_is_user_can_be_here', true, 'only_super_admin' ); |
| 181 |
if ( ( ! $is_can ) && ( get_bk_option( 'booking_is_custom_forms_for_regular_users' ) !== 'On' ) ) { |
| 182 |
return; |
| 183 |
} |
| 184 |
|
| 185 |
// == MU owner logic == |
| 186 |
$owner_user_id = self::wpbc_mu__get_current__owner_user_id(); |
| 187 |
|
| 188 |
$form_params = array( |
| 189 |
'include_standard' => false, |
| 190 |
'owner_user_id' => $owner_user_id, |
| 191 |
'statuses' => array( 'published' ), |
| 192 |
'list_mode' => 'auto', // auto | legacy | bfb | both. |
| 193 |
); |
| 194 |
$booking_forms_extended = self::get_custom_booking_forms_list( $form_params ); |
| 195 |
|
| 196 |
if ( empty( $booking_forms_extended ) ) { |
| 197 |
return array(); |
| 198 |
} |
| 199 |
|
| 200 |
$defaults = array( |
| 201 |
'on_change' => false, |
| 202 |
'title' => __( 'Booking Form', 'booking' ) . ':', |
| 203 |
); |
| 204 |
$params = wp_parse_args( $params, $defaults ); |
| 205 |
|
| 206 |
// ------------------------------------------------------------------------------------------------------------- |
| 207 |
|
| 208 |
// == Check if selected booking resource, which has default custom booking form == |
| 209 |
$selected_booking_resource = isset( $_GET['booking_type'] ) ? intval( $_GET['booking_type'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 210 |
|
| 211 |
// Set Default custom booking form for specific selected booking resource. |
| 212 |
if ( ( $selected_booking_resource > 0 ) && ( ! isset( $_GET['booking_form'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 213 |
$my_booking_form_name = self::get_default_custom_form__for__booking_resource( $selected_booking_resource ); |
| 214 |
if ( ! empty( $my_booking_form_name ) ) { |
| 215 |
$_GET['booking_form'] = $my_booking_form_name; |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
// ------------------------------------------------------------------------------------------------------------- |
| 220 |
|
| 221 |
$get_parameter_name = 'booking_form'; |
| 222 |
|
| 223 |
if ( false === $params['on_change'] ) { |
| 224 |
$link_base = wpbc_get_new_booking_url__base( array( $get_parameter_name ) ) . '&' . $get_parameter_name . '='; |
| 225 |
$on_change = 'location.href=\'' . $link_base . '\' + this.value;'; |
| 226 |
} else { |
| 227 |
$on_change = $params['on_change']; |
| 228 |
} |
| 229 |
|
| 230 |
// Show DropDown list with Custom forms selection. |
| 231 |
wpbc_dropdown_list_with_custom_forms__free( $booking_forms_extended, $on_change, $params ); |
| 232 |
} |
| 233 |
|
| 234 |
/** |
| 235 |
* Custom booking forms - HTML Selectbox -> Modal Shortcode |
| 236 |
* |
| 237 |
* @param array $params - [ |
| 238 |
* 'name' => $id, |
| 239 |
* 'title' => __( 'Booking Form', 'booking' ), |
| 240 |
* 'description' => __( 'Select custom booking form', 'booking' ), |
| 241 |
* 'group' => $group_key, |
| 242 |
* ] |
| 243 |
* @return void |
| 244 |
*/ |
| 245 |
public static function wpbc_bfb__custom_booking_forms_list__selectbox_html__sh_modal( $params ){ |
| 246 |
|
| 247 |
// == Legacy | Check if we can be here. == |
| 248 |
$is_can = apply_bk_filter( 'multiuser_is_user_can_be_here', true, 'only_super_admin' ); |
| 249 |
if ( ( ! $is_can ) && ( get_bk_option( 'booking_is_custom_forms_for_regular_users' ) !== 'On' ) ) { |
| 250 |
return; |
| 251 |
} |
| 252 |
|
| 253 |
// == MU owner logic == |
| 254 |
$owner_user_id = self::wpbc_mu__get_current__owner_user_id(); |
| 255 |
|
| 256 |
$form_params = array( |
| 257 |
'include_standard' => false, |
| 258 |
'owner_user_id' => $owner_user_id, |
| 259 |
'statuses' => array( 'published' ), |
| 260 |
'list_mode' => 'auto', // auto | legacy | bfb | both. |
| 261 |
); |
| 262 |
|
| 263 |
$booking_forms_extended = self::get_custom_booking_forms_list( $form_params ); |
| 264 |
|
| 265 |
if ( empty( $booking_forms_extended ) ) { |
| 266 |
return array(); |
| 267 |
} |
| 268 |
|
| 269 |
// ----------------------------------------------------------------------------------------------------------------- |
| 270 |
|
| 271 |
$defaults = array( |
| 272 |
'name' => 'select_booking_form', |
| 273 |
'title' => __( 'Booking Form', 'booking' ), |
| 274 |
'description' => __( 'Select default custom booking form', 'booking' ), |
| 275 |
'group' => 'general', |
| 276 |
'init_options' => array(), // Init default list of options. |
| 277 |
); |
| 278 |
$params = wp_parse_args( $params, $defaults ); |
| 279 |
|
| 280 |
|
| 281 |
$form_options = $params['init_options']; |
| 282 |
$form_options['standard'] = array( |
| 283 |
'title' => __( 'Standard', 'booking' ), |
| 284 |
'class' => '', |
| 285 |
'attr' => array( 'style' => '' ), |
| 286 |
); |
| 287 |
|
| 288 |
$form_options['optgroup_cf_s'] = array( 'optgroup' => true, 'close' => false, 'title' => ' ' . __( 'Custom Forms', 'booking' ) ); |
| 289 |
|
| 290 |
foreach ( $booking_forms_extended as $cust_form ) { |
| 291 |
|
| 292 |
$form_options[ $cust_form['name'] ] = array( |
| 293 |
'title' => wpbc_lang( $cust_form['name'] ), |
| 294 |
'attr' => array(), |
| 295 |
); |
| 296 |
} |
| 297 |
|
| 298 |
$form_options['optgroup_cf_e'] = array( 'optgroup' => true, 'close' => true ); |
| 299 |
|
| 300 |
WPBC_Settings_API::field_select_row_static( |
| 301 |
$params['name'], |
| 302 |
array( |
| 303 |
'type' => 'select', |
| 304 |
'title' => $params['title'], |
| 305 |
'label' => '', |
| 306 |
'disabled' => false, |
| 307 |
'disabled_options' => array(), |
| 308 |
'multiple' => false, |
| 309 |
'description' => $params['description'], |
| 310 |
'description_tag' => 'span', |
| 311 |
'tr_class' => $params['group'] . '_standard_section', |
| 312 |
'group' => $params['group'], |
| 313 |
'class' => '', |
| 314 |
'css' => 'margin-right:10px;', |
| 315 |
'only_field' => false, |
| 316 |
'attr' => array(), |
| 317 |
'value' => '', |
| 318 |
'options' => $form_options, |
| 319 |
) |
| 320 |
); |
| 321 |
} |
| 322 |
|
| 323 |
/** |
| 324 |
* Custom booking forms - HTML Selectbox -> Resource Table Field. |
| 325 |
* |
| 326 |
* @param $row_num |
| 327 |
* @param $resource - array( |
| 328 |
* [booking_type_id] => 1 |
| 329 |
* [title] => Default |
| 330 |
* [users] => 1 |
| 331 |
* [import] => |
| 332 |
* [export] => |
| 333 |
* [cost] => 25 |
| 334 |
* [default_form] => standard |
| 335 |
* [prioritet] => 0 |
| 336 |
* [parent] => 0 |
| 337 |
* [visitors] => 1 |
| 338 |
* [id] => 1 |
| 339 |
* [count] => 6 |
| 340 |
* ) |
| 341 |
* |
| 342 |
* @return void |
| 343 |
*/ |
| 344 |
public static function wpbc_bfb__custom_booking_forms_list__selectbox_html__in_resource_table( $row_num, $resource ){ |
| 345 |
|
| 346 |
// == Legacy | Check if we can be here. == |
| 347 |
$is_can = apply_bk_filter( 'multiuser_is_user_can_be_here', true, 'only_super_admin' ); |
| 348 |
if ( ( ! $is_can ) && ( get_bk_option( 'booking_is_custom_forms_for_regular_users' ) !== 'On' ) ) { |
| 349 |
return; |
| 350 |
} |
| 351 |
|
| 352 |
// == MU owner logic == |
| 353 |
if ( class_exists( 'wpdev_bk_multiuser' ) ) { // Check what to show in MU // FixIn: 8.1.3.19. |
| 354 |
$is_booking_resource_user_super_admin = apply_bk_filter( 'is_user_super_admin', $resource['users'] ); |
| 355 |
} else { |
| 356 |
$is_booking_resource_user_super_admin = true; |
| 357 |
} |
| 358 |
|
| 359 |
if ($is_booking_resource_user_super_admin){ |
| 360 |
$owner_user_id = 0; |
| 361 |
} else { |
| 362 |
$owner_user_id = absint( $resource[ 'users' ] ); |
| 363 |
} |
| 364 |
|
| 365 |
|
| 366 |
$form_params = array( |
| 367 |
'include_standard' => false, |
| 368 |
'owner_user_id' => $owner_user_id, |
| 369 |
'statuses' => array( 'published' ), |
| 370 |
'list_mode' => 'auto', // auto | legacy | bfb | both. |
| 371 |
); |
| 372 |
|
| 373 |
$booking_forms_extended = self::get_custom_booking_forms_list( $form_params ); |
| 374 |
|
| 375 |
if ( empty( $booking_forms_extended ) ) { |
| 376 |
return array(); |
| 377 |
} |
| 378 |
|
| 379 |
// ------------------------------------------------------------------------------------------------------------- |
| 380 |
|
| 381 |
$form_options = array(); |
| 382 |
foreach ( $booking_forms_extended as $cust_form ) { |
| 383 |
|
| 384 |
$form_options[ $cust_form['name'] ] = array( |
| 385 |
'title' => wpbc_lang( $cust_form['name'] ), |
| 386 |
'selected' => ( ( isset( $resource['default_form'] ) ) && ( $resource['default_form'] === $cust_form['name'] ) ), |
| 387 |
); |
| 388 |
} |
| 389 |
|
| 390 |
|
| 391 |
?><label for="booking_resource_default_form_<?php echo esc_attr( $resource['id' ] ); ?>" |
| 392 |
class="wpbc_ui_control_label " style=""><span style="font-weight:400"><?php esc_html_e( 'Default Form', 'booking' ); ?>: </span></label><?php |
| 393 |
|
| 394 |
?><select autocomplete="off" id="booking_resource_default_form_<?php echo esc_attr( $resource['id' ] ); ?>" |
| 395 |
name="booking_resource_default_form_<?php echo esc_attr( $resource['id' ] ); ?>" |
| 396 |
class="wpbc_ui_control wpbc_ui_select" |
| 397 |
><?php |
| 398 |
|
| 399 |
?><option value="standard" style="padding:3px;border-bottom: 1px dashed #ccc;" ><?php echo esc_attr( __('Standard', 'booking') ); ?></option><?php |
| 400 |
|
| 401 |
?><optgroup label="<?php echo esc_attr( ' ' . __('Custom Forms' ,'booking') ); ?>"><?php |
| 402 |
|
| 403 |
foreach ( $form_options as $option_value => $option_data ) { |
| 404 |
|
| 405 |
?><option value="<?php echo esc_attr( $option_value ); ?>" |
| 406 |
<?php selected( $option_data['selected'], true ); ?> |
| 407 |
><?php echo esc_attr( $option_data['title'] ); ?></option><?php |
| 408 |
} |
| 409 |
|
| 410 |
?></optgroup><?php |
| 411 |
|
| 412 |
?></select><?php |
| 413 |
} |
| 414 |
|
| 415 |
/** |
| 416 |
* Ovverides this function: wpbc_toolbar__get_custom_forms__options_for_selection() |
| 417 |
* and this method: self:get_custom_forms_arr__for_options() overide this function: wpbc_get_custom_forms_arr__for_options() |
| 418 |
* @return array|void |
| 419 |
*/ |
| 420 |
public static function wpbc_bfb__custom_booking_forms_list__selectbox_html__for_elementor() { |
| 421 |
|
| 422 |
$form_options = array(); |
| 423 |
$form_options['standard'] = array( |
| 424 |
'title' => __( 'Standard', 'booking' ), |
| 425 |
'id' => '', |
| 426 |
'name' => '', |
| 427 |
'style' => 'padding:3px;border-bottom: 1px dashed #ccc;', |
| 428 |
'class' => '', |
| 429 |
'disabled' => false, |
| 430 |
'selected' => false, |
| 431 |
'attr' => array(), |
| 432 |
); |
| 433 |
|
| 434 |
// ------------------------------------------------------------------------------------------------------------- |
| 435 |
|
| 436 |
// == Legacy | Check if we can be here. == |
| 437 |
$is_can = apply_bk_filter( 'multiuser_is_user_can_be_here', true, 'only_super_admin' ); |
| 438 |
if ( ( ! $is_can ) && ( get_bk_option( 'booking_is_custom_forms_for_regular_users' ) !== 'On' ) ) { |
| 439 |
return $form_options; |
| 440 |
} |
| 441 |
|
| 442 |
// == MU owner logic == |
| 443 |
$owner_user_id = self::wpbc_mu__get_current__owner_user_id(); |
| 444 |
|
| 445 |
$form_params = array( |
| 446 |
'include_standard' => false, |
| 447 |
'owner_user_id' => $owner_user_id, |
| 448 |
'statuses' => array( 'published' ), |
| 449 |
'list_mode' => 'auto', // auto | legacy | bfb | both. |
| 450 |
); |
| 451 |
|
| 452 |
$booking_forms_extended = self::get_custom_booking_forms_list( $form_params ); |
| 453 |
|
| 454 |
if ( empty( $booking_forms_extended ) ) { |
| 455 |
return array(); |
| 456 |
} |
| 457 |
|
| 458 |
|
| 459 |
// Show DropDown list with Custom forms selection. |
| 460 |
$form_options = self::get_custom_forms_arr__for_options( $booking_forms_extended ); |
| 461 |
|
| 462 |
return $form_options; |
| 463 |
} |
| 464 |
|
| 465 |
/** |
| 466 |
* Get array with Custom Forms - prepared for selectbox options |
| 467 |
* |
| 468 |
* @param $booking_forms_extended |
| 469 |
* |
| 470 |
* @return array |
| 471 |
*/ |
| 472 |
protected static function get_custom_forms_arr__for_options( $booking_forms_extended ) { |
| 473 |
|
| 474 |
$form_options = array(); |
| 475 |
|
| 476 |
$form_options['standard'] = array( |
| 477 |
'title' => __( 'Standard', 'booking' ), |
| 478 |
'id' => '', |
| 479 |
'name' => '', |
| 480 |
'style' => 'padding:3px;border-bottom: 1px dashed #ccc;', |
| 481 |
'class' => '', |
| 482 |
'disabled' => false, |
| 483 |
'selected' => false, |
| 484 |
'attr' => array(), |
| 485 |
); |
| 486 |
|
| 487 |
$form_options['optgroup_cf_s'] = array( |
| 488 |
'optgroup' => true, |
| 489 |
'close' => false, |
| 490 |
'title' => ' ' . __( 'Custom Forms', 'booking' ), |
| 491 |
); |
| 492 |
|
| 493 |
foreach ( $booking_forms_extended as $cust_form ) { |
| 494 |
|
| 495 |
$form_options[ $cust_form['name'] ] = array( |
| 496 |
'title' => wpbc_lang( $cust_form['name'] ), |
| 497 |
'id' => '', |
| 498 |
'name' => '', |
| 499 |
'style' => '', |
| 500 |
'class' => '', |
| 501 |
'disabled' => false, |
| 502 |
'selected' => ( ( isset( $_GET['booking_form'] ) ) && ( $_GET['booking_form'] === $cust_form['name'] ) ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 503 |
'attr' => array(), |
| 504 |
); |
| 505 |
} |
| 506 |
|
| 507 |
$form_options['optgroup_cf_e'] = array( 'optgroup' => true, 'close' => true ); |
| 508 |
|
| 509 |
return $form_options; |
| 510 |
} |
| 511 |
|
| 512 |
// ================================================================================================================= |
| 513 |
|
| 514 |
/** |
| 515 |
* Maybe get the 'custom booking form name' in the $_POST | $_ GET request |
| 516 |
* |
| 517 |
* @param string $request_type - 'post' | 'get'. |
| 518 |
* @param string $request_key_name - 'booking_form_type'. |
| 519 |
* |
| 520 |
* @return array|string|string[] |
| 521 |
*/ |
| 522 |
public static function get__custom_form_name__in__post( $request_type = 'post', $request_key_name = 'booking_form_type' ) { |
| 523 |
|
| 524 |
$request_type = ( 'post' === $request_type ) ? 'post' : 'get'; |
| 525 |
|
| 526 |
$booking_form_name = ''; |
| 527 |
|
| 528 |
if ( 'post' === $request_type ) { |
| 529 |
|
| 530 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 531 |
$booking_form_name = isset( $_POST[ $request_key_name ] ) ? sanitize_text_field( wp_unslash( $_POST[ $request_key_name ] ) ) : ''; |
| 532 |
} else { |
| 533 |
$booking_form_name = isset( $_GET[ $request_key_name ] ) ? sanitize_text_field( wp_unslash( $_GET[ $request_key_name ] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 534 |
} |
| 535 |
|
| 536 |
// Legacy escaping. |
| 537 |
$booking_form_name = str_replace( "\'", '', $booking_form_name ); |
| 538 |
|
| 539 |
if ( 'standard' === $booking_form_name ) { |
| 540 |
// Form does not exist. |
| 541 |
$booking_form_name = ''; |
| 542 |
} |
| 543 |
|
| 544 |
return $booking_form_name; |
| 545 |
} |
| 546 |
|
| 547 |
/** |
| 548 |
* Maybe get the 'custom booking form name' from the "Content of booking fields data" from parameter: ~text^wpbc_custom_booking_form + resource_ID^custom_form_name |
| 549 |
* |
| 550 |
* @param string $booking_form_data - form data, e.g.: 'text^selected_short_timedates_hint1^...~text^nights_number_hint1^0~text^cost_hint1^$0.00~text^name1^John~text^secondname1^Smith~email^email1^s@wpbookingcalendar.com~text^phone1^~selectbox-one^visitors1^1~selectbox-one^children1^0~textarea^details1^~coupon^coupon1^~checkbox^term_and_condition1[]^ . |
| 551 |
* @param int $resource_id - ID of booking resource. |
| 552 |
* |
| 553 |
* @return mixed |
| 554 |
*/ |
| 555 |
public static function get__custom_form_name__in__form_data( $booking_form_data, $resource_id ) { |
| 556 |
|
| 557 |
if ( false !== strpos( $booking_form_data, 'wpbc_custom_booking_form' . $resource_id . '^' ) ) { |
| 558 |
|
| 559 |
$parsed_booking_data_arr = wpbc_get_parsed_booking_data_arr( $booking_form_data, $resource_id, array( 'get' => 'value' ) ); |
| 560 |
|
| 561 |
if ( ! empty( $parsed_booking_data_arr['wpbc_custom_booking_form'] ) ) { |
| 562 |
return $parsed_booking_data_arr['wpbc_custom_booking_form']; |
| 563 |
} |
| 564 |
} |
| 565 |
return ''; |
| 566 |
} |
| 567 |
|
| 568 |
// ================================================================================================================= |
| 569 |
|
| 570 |
/** |
| 571 |
* Maybe implement 'custom booking form name' parameter: ~text^wpbc_custom_booking_form + resource_ID^custom_form_name |
| 572 |
* |
| 573 |
* @param string $booking_form_data - form data, e.g.: 'text^selected_short_timedates_hint1^...~text^nights_number_hint1^0~text^cost_hint1^$0.00~text^name1^John~text^secondname1^Smith~email^email1^s@wpbookingcalendar.com~text^phone1^~selectbox-one^visitors1^1~selectbox-one^children1^0~textarea^details1^~coupon^coupon1^~checkbox^term_and_condition1[]^ . |
| 574 |
* @param string $custom_form_name - custom booking form name. |
| 575 |
* @param int $resource_id - ID of booking resource. |
| 576 |
* |
| 577 |
* @return mixed |
| 578 |
*/ |
| 579 |
public static function maybe_implement__custom_form_name__in__form_data( $booking_form_data, $custom_form_name, $resource_id ) { |
| 580 |
|
| 581 |
$resource_id = absint( $resource_id ); |
| 582 |
$booking_form_data = (string) $booking_form_data; |
| 583 |
$custom_form_name = sanitize_text_field( (string) $custom_form_name ); |
| 584 |
|
| 585 |
if ( $resource_id <= 0 || '' === $custom_form_name ) { |
| 586 |
return $booking_form_data; |
| 587 |
} |
| 588 |
|
| 589 |
if ( false === strpos( $booking_form_data, 'wpbc_custom_booking_form' . $resource_id . '^' ) ) { |
| 590 |
|
| 591 |
// We have no custom form name parameter, so need to implement it. |
| 592 |
$booking_form_data .= '~text^wpbc_custom_booking_form' . $resource_id . '^' . $custom_form_name; |
| 593 |
} |
| 594 |
|
| 595 |
return $booking_form_data; |
| 596 |
} |
| 597 |
|
| 598 |
|
| 599 |
/** |
| 600 |
* Get 'Advanced Costs' | 'Form Options Cost' of each field in booking form: [ 'rangetime' => [ '10:00_-_15:00' = 115.0, '16:00_-_21:30' = 135.0, ... ], ... ] |
| 601 |
* |
| 602 |
* @param string $booking_form_name - Optional custom booking form name. |
| 603 |
* |
| 604 |
* @return array|mixed|string - [ 'rangetime' => [ '10:00_-_15:00' = 115.0, '16:00_-_21:30' = 135.0, ... ], ... ]. |
| 605 |
*/ |
| 606 |
public static function get_form_options_costs__fields_arr( $booking_form_name = '' ) { |
| 607 |
|
| 608 |
if ( ( empty( $booking_form_name ) ) || ( 'standard' === $booking_form_name ) ) { |
| 609 |
$booking_form_name = ''; |
| 610 |
} |
| 611 |
|
| 612 |
$field__values = ( '' === $booking_form_name ) |
| 613 |
? get_bk_option( 'booking_advanced_costs_values' ) |
| 614 |
: get_bk_option( 'booking_advanced_costs_values_for' . $booking_form_name ); |
| 615 |
|
| 616 |
$form_options_costs__fields_arr = ( ! empty( $field__values ) ) ? maybe_unserialize( $field__values ) : array(); |
| 617 |
|
| 618 |
return $form_options_costs__fields_arr; |
| 619 |
} |
| 620 |
} |
| 621 |
|
| 622 |
add_action( 'wpbc_resources_table_show_col__customform_field', array( 'WPBC_FE_Custom_Form_Helper', 'wpbc_bfb__custom_booking_forms_list__selectbox_html__in_resource_table' ), 11, 2 ); |
| 623 |
/* Remove second "default custom booking form" of legacy scripts, if enabled BFB. */ |
| 624 |
add_action( |
| 625 |
'init', |
| 626 |
function () { |
| 627 |
remove_action( 'wpbc_resources_table_show_col__customform_field', 'wpbc_resources_table_show_col__customform_field__bm', 10 ); |
| 628 |
} |
| 629 |
); |
| 630 |
|
| 631 |
|
| 632 |
/** |
| 633 |
* Register compatibility wrappers after all Free and Pro PHP files are loaded. |
| 634 |
* |
| 635 |
* Pro versions before 11.4 declare these functions while loading their legacy |
| 636 |
* custom-form module. Waiting until the end of `wpbc_loaded_php_files` lets the |
| 637 |
* legacy implementation keep ownership and prevents function redeclaration |
| 638 |
* fatals during mixed-version updates. |
| 639 |
* |
| 640 |
* @return void |
| 641 |
*/ |
| 642 |
function wpbc_register_custom_form_compatibility_wrappers() { |
| 643 |
|
| 644 |
if ( ! function_exists( 'wpbc_get_custom_booking_form' ) ) { |
| 645 |
/** |
| 646 |
* Compatibility wrapper for older custom-form filters. |
| 647 |
* |
| 648 |
* @param string $default_return_form_content Default value. |
| 649 |
* @param string $custom_form_name Form slug. |
| 650 |
* @param mixed $serialized_form_content Deprecated legacy payload. Ignored. |
| 651 |
* @param string $what_to_return 'form' or 'content'. |
| 652 |
* @param bool $is_replace_simple_html Whether to replace custom HTML shortcodes. |
| 653 |
* |
| 654 |
* @return string |
| 655 |
*/ |
| 656 |
function wpbc_get_custom_booking_form( $default_return_form_content, $custom_form_name, $serialized_form_content = false, $what_to_return = 'content', $is_replace_simple_html = true ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
| 657 |
|
| 658 |
$custom_form_name = sanitize_text_field( (string) $custom_form_name ); |
| 659 |
if ( '' === $custom_form_name ) { |
| 660 |
return $default_return_form_content; |
| 661 |
} |
| 662 |
|
| 663 |
$pair = array(); |
| 664 |
if ( function_exists( 'wpbc_bfb_get_booking_form_pair' ) ) { |
| 665 |
$pair = wpbc_bfb_get_booking_form_pair( |
| 666 |
array( |
| 667 |
'form_slug' => $custom_form_name, |
| 668 |
'status' => 'published', |
| 669 |
) |
| 670 |
); |
| 671 |
} |
| 672 |
|
| 673 |
$value = ''; |
| 674 |
if ( 'form' === $what_to_return ) { |
| 675 |
$value = isset( $pair['form'] ) ? (string) $pair['form'] : ''; |
| 676 |
} else { |
| 677 |
$value = isset( $pair['content'] ) ? (string) $pair['content'] : ''; |
| 678 |
} |
| 679 |
|
| 680 |
if ( '' === trim( $value ) ) { |
| 681 |
$value = (string) $default_return_form_content; |
| 682 |
} |
| 683 |
|
| 684 |
if ( $is_replace_simple_html ) { |
| 685 |
$value = wpbc_bf__replace_custom_html_shortcodes( $value ); |
| 686 |
} |
| 687 |
|
| 688 |
return $value; |
| 689 |
} |
| 690 |
} |
| 691 |
|
| 692 |
if ( ! function_exists( 'wpbc_toolbar_btn__form_selection' ) ) { |
| 693 |
/** |
| 694 |
* Compatibility toolbar wrapper used by older admin screens. |
| 695 |
* |
| 696 |
* @param array $params Optional select params. |
| 697 |
* |
| 698 |
* @return void |
| 699 |
*/ |
| 700 |
function wpbc_toolbar_btn__form_selection( $params = array() ) { |
| 701 |
WPBC_FE_Custom_Form_Helper::wpbc_bfb__custom_booking_forms_list__selectbox_html( $params ); |
| 702 |
} |
| 703 |
} |
| 704 |
|
| 705 |
if ( ! function_exists( 'wpbc_toolbar_btn__custom_forms_in_settings_fields' ) ) { |
| 706 |
/** |
| 707 |
* Compatibility toolbar wrapper used by Advanced Cost settings. |
| 708 |
* |
| 709 |
* @param bool $is_show_add_new_custom_form Deprecated. Ignored. |
| 710 |
* |
| 711 |
* @return void |
| 712 |
*/ |
| 713 |
function wpbc_toolbar_btn__custom_forms_in_settings_fields( $is_show_add_new_custom_form = true ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
| 714 |
WPBC_FE_Custom_Form_Helper::wpbc_bfb__custom_booking_forms_list__selectbox_html( array( 'on_change' => 'wpbc_change_custom_booking_form_in_url__and_reload(this);' ) ); |
| 715 |
} |
| 716 |
} |
| 717 |
} |
| 718 |
|
| 719 |
if ( did_action( 'wpbc_loaded_php_files' ) ) { |
| 720 |
wpbc_register_custom_form_compatibility_wrappers(); |
| 721 |
} else { |
| 722 |
add_action( 'wpbc_loaded_php_files', 'wpbc_register_custom_form_compatibility_wrappers', PHP_INT_MAX ); |
| 723 |
} |
| 724 |
|
| 725 |
|
| 726 |
/** |
| 727 |
* Show Selectbox with Custom Forms |
| 728 |
* |
| 729 |
* @param $booking_forms_extended |
| 730 |
* @param $on_change |
| 731 |
* @param $params |
| 732 |
* |
| 733 |
* @return void |
| 734 |
*/ |
| 735 |
function wpbc_dropdown_list_with_custom_forms__free( $booking_forms_extended, $on_change , $params = array() ) { |
| 736 |
|
| 737 |
$defaults = array( |
| 738 |
'on_change' => false, |
| 739 |
'title' => __( 'Booking Form', 'booking' ) . ':', |
| 740 |
); |
| 741 |
$params = wp_parse_args( $params, $defaults ); |
| 742 |
|
| 743 |
|
| 744 |
// ----------------------------------------------------------------------------------------------------------------- |
| 745 |
// DropDown list with Custom Forms. |
| 746 |
// ----------------------------------------------------------------------------------------------------------------- |
| 747 |
|
| 748 |
$form_options = array(); |
| 749 |
|
| 750 |
$form_options['standard'] = array( |
| 751 |
'title' => __( 'Standard', 'booking' ), |
| 752 |
'id' => '', |
| 753 |
'name' => '', |
| 754 |
'style' => 'padding:3px;border-bottom: 1px dashed #ccc;', |
| 755 |
'class' => '', |
| 756 |
'disabled' => false, |
| 757 |
'selected' => false, |
| 758 |
'attr' => array(), |
| 759 |
); |
| 760 |
|
| 761 |
$form_options['optgroup_cf_s'] = array( |
| 762 |
'optgroup' => true, |
| 763 |
'close' => false, |
| 764 |
'title' => ' ' . __( 'Custom Forms', 'booking' ), |
| 765 |
); |
| 766 |
|
| 767 |
foreach ( $booking_forms_extended as $cust_form ) { |
| 768 |
|
| 769 |
$form_options[ $cust_form['name'] ] = array( |
| 770 |
'title' => wpbc_lang( $cust_form['name'] ), |
| 771 |
'id' => '', |
| 772 |
'name' => '', |
| 773 |
'style' => '', |
| 774 |
'class' => '', |
| 775 |
'disabled' => false, |
| 776 |
'selected' => ( ( isset( $_GET['booking_form'] ) ) && ( $_GET['booking_form'] === $cust_form['name'] ) ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 777 |
'attr' => array(), |
| 778 |
); |
| 779 |
} |
| 780 |
|
| 781 |
$templates['optgroup_cf_e'] = array( 'optgroup' => true, 'close' => true ); |
| 782 |
|
| 783 |
|
| 784 |
$params = array( |
| 785 |
'label_for' => 'select_booking_form', // "For" parameter of label element. |
| 786 |
'label' => '', // Label above the input group. |
| 787 |
'style' => '', // CSS Style of entire div element. |
| 788 |
'items' => array( |
| 789 |
array( |
| 790 |
'type' => 'addon', |
| 791 |
'element' => 'text', // text | radio | checkbox. |
| 792 |
'text' => $params['title'], |
| 793 |
'class' => '', // Any CSS class here. |
| 794 |
'style' => 'font-weight:600;', // CSS Style of entire div element. |
| 795 |
), |
| 796 |
array( |
| 797 |
'type' => 'select', |
| 798 |
'id' => 'select_booking_form', // HTML ID of element. |
| 799 |
'name' => 'select_booking_form', |
| 800 |
'options' => $form_options, |
| 801 |
// Associated array of titles and values |
| 802 |
// , 'disabled_options' => array( 'any' ) // If some options disbaled, then its must list here. |
| 803 |
// , 'default' => 'specific' // Some Value from optins array that selected by default. |
| 804 |
'style' => '', // CSS of select element. |
| 805 |
'class' => '', // CSS Class of select element. |
| 806 |
'attr' => array(), // Any additional attributes, if this radio | checkbox element. |
| 807 |
'onchange' => $on_change, |
| 808 |
), |
| 809 |
), |
| 810 |
); |
| 811 |
echo '<div class="control-group wpbc-no-padding">'; |
| 812 |
wpbc_bs_input_group( $params ); |
| 813 |
echo '</div>'; |
| 814 |
} |
| 815 |
|