PluginProbe
Booking Calendar / 11.0
Booking Calendar v11.0
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 / _custom_forms / class-custom-forms-helper.php

class-custom-forms-helper.php in Booking Calendar 11.0, at includes/_custom_forms/class-custom-forms-helper.php

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