PluginProbe
Booking Calendar / 11.2
Booking Calendar v11.2
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 / page-form-builder / bfb-ui-elements.php

bfb-ui-elements.php in Booking Calendar 11.2, at includes/page-form-builder/bfb-ui-elements.php

793 lines 30.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * UI elements for settings page.
4 *
5 * @package Booking Calendar.
6 * @author wpdevelop, oplugins
7 * @web-site https://wpbookingcalendar.com/
8 * @email info@wpbookingcalendar.com
9 *
10 * @modified 2025-11-26
11 * @version 1.2
12 * @file: ../includes/page-form-builder/bfb-ui-elements.php
13 */
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit; // Exit if accessed directly.
17 }
18
19
20 // ---------------------------------------------------------------------------------------------------------------------
21 // Top Toolbar - Dropdown Menu - Load / Import
22 // ---------------------------------------------------------------------------------------------------------------------
23
24 /**
25 * Render Form Builder "Load / Import" dropdown in top toolbar.
26 *
27 * This dropdown groups all actions that LOAD or IMPORT the booking form structure:
28 * - Reload last saved form from DB.
29 * - Import from previous "Simple" booking form configuration.
30 *
31 * @param array $config Optional configuration:
32 * - ajax_action_load : AJAX action for loading from DB.
33 * - ajax_nonce_load : Nonce for loading from DB.
34 * - ajax_action_import : AJAX action for import from Simple Form.
35 * - ajax_nonce_import : Nonce for import from Simple Form.
36 * - default_form_key : Default form key to load.
37 * - dropdown_title : Dropdown label in toolbar.
38 *
39 * @return void
40 */
41 function wpbc_bfb__top_toolbar__dropdown_menu__main_forms( $config = array() ) {
42
43 $defaults = array(
44 'ajax_action_load' => 'WPBC_AJX_BFB_LOAD_FORM_CONFIG',
45 'ajax_nonce_load' => '',
46 'ajax_action_import' => 'wpbc_bfb_import_simple_form',
47 'ajax_nonce_import' => '',
48 'default_form_key' => 'default_booking_form',
49 'dropdown_title' => __( 'Forms', 'booking' ),
50 'dropdown_font_icon' => '', // 'wpbc-bi-download',
51 );
52
53 $config = wp_parse_args( $config, $defaults );
54
55 $config['ajax_nonce_import_legacy_forms'] = wp_create_nonce( 'wpbc_bfb_import_legacy_forms' );
56 $config['ajax_action_import_legacy_forms'] = 'WPBC_AJX_BFB_IMPORT_LEGACY_FORMS';
57
58 // Build dropdown items: LOAD / IMPORT actions.
59 $items = array(
60 array(
61 'type' => 'header',
62 'title' => __( 'Restore or Replace Current Form', 'booking' ),
63 ),
64
65 array(
66 'type' => 'link',
67 'title' => __( 'Replace with Template', 'booking' ) . '...',
68 'url' => 'javascript:void(0);',
69 'attr' => array(
70 'onclick' => 'wpbc_bfb__menu_forms__apply_template(this);',
71 'data-wpbc-u-busy-text' => __( 'Applying', 'booking' ) . '...',
72 'title' => __( 'Replace the current form layout with a ready-made template.', 'booking' ),
73 'style' => 'font-weight:600;',
74 ),
75 ),
76
77 // Reload last saved form from DB.
78 array(
79 'type' => 'link',
80 'title' => __( 'Restore last saved version', 'booking' ),
81 'url' => 'javascript:void(0);',
82 'attr' => array(
83 'onclick' => 'wpbc_bfb__ajax_load_current_form(this);',
84 'data-wpbc-bfb-load-nonce' => $config['ajax_nonce_load'],
85 'data-wpbc-bfb-load-action' => $config['ajax_action_load'],
86 'data-wpbc-bfb-form-key' => $config['default_form_key'],
87 'data-wpbc-u-busy-text' => __( 'Loading', 'booking' ) . '...',
88 'title' => __( 'Discard unsaved changes and restore the last saved version of this form.', 'booking' ),
89 ),
90 ),
91
92 array( 'type' => 'divider' ),
93 array(
94 'type' => 'header',
95 'title' => __( 'Create, Open, and Save Forms', 'booking' ),
96 ),
97
98 array(
99 'type' => 'link',
100 'title' => __( 'Create New Form', 'booking' ) . '...',
101 'url' => 'javascript:void(0);',
102 'attr' => array(
103 'onclick' => 'wpbc_bfb__menu_forms__new(this);',
104 'data-wpbc-bfb-load-nonce' => $config['ajax_nonce_load'],
105 'data-wpbc-bfb-load-action' => $config['ajax_action_load'],
106 'data-wpbc-bfb-form-key' => $config['default_form_key'],
107 'data-wpbc-u-busy-text' => __( 'Loading', 'booking' ) . '...',
108 'title' => __( 'Create a new booking form.', 'booking' ),
109 ),
110 ),
111
112 array(
113 'type' => 'link',
114 'title' => __( 'Open', 'booking' ) . ' ...',
115 'url' => 'javascript:void(0);',
116 'attr' => array(
117 'onclick' => 'wpbc_bfb__menu_forms__load(this);',
118 'data-wpbc-bfb-load-nonce' => $config['ajax_nonce_load'],
119 'data-wpbc-bfb-load-action' => $config['ajax_action_load'],
120 'data-wpbc-bfb-form-key' => $config['default_form_key'],
121 'data-wpbc-u-busy-text' => __( 'Loading', 'booking' ) . '...',
122 'title' => __( 'Open an existing saved booking form.', 'booking' ),
123 ),
124 ),
125
126 array(
127 'type' => 'link',
128 'title' => __( 'Save', 'booking' ),
129 'url' => 'javascript:void(0);',
130 'attr' => array(
131 'onclick' => 'wpbc_bfb__ajax_save_current_form(this);',
132 'data-wpbc-bfb-load-nonce' => $config['ajax_nonce_load'],
133 'data-wpbc-bfb-load-action' => $config['ajax_action_load'],
134 'data-wpbc-bfb-form-key' => $config['default_form_key'],
135 'data-wpbc-u-busy-text' => __( 'Saving', 'booking' ) . '...',
136 'title' => __( 'Save changes to the current booking form.', 'booking' ),
137 ),
138 ),
139
140 array(
141 'type' => 'link',
142 'title' => __( 'Save As', 'booking' ) . ' ...',
143 'url' => 'javascript:void(0);',
144 'attr' => array(
145 'onclick' => 'wpbc_bfb__menu_forms__save_as(this);',
146 'data-wpbc-bfb-load-nonce' => $config['ajax_nonce_load'],
147 'data-wpbc-bfb-load-action' => $config['ajax_action_load'],
148 'data-wpbc-bfb-form-key' => $config['default_form_key'],
149 'data-wpbc-u-busy-text' => __( 'Saving', 'booking' ) . '...',
150 'title' => __( 'Save a copy of this form with a new name.', 'booking' ),
151 ),
152 ),
153
154 // array( 'type' => 'divider' ),
155 //
156 // Reload last saved form from DB.
157 // array(
158 // 'type' => 'link',
159 // 'title' => __( 'Load Template Example', 'booking' ),
160 // 'url' => 'javascript:void(0);',
161 // 'attr' => array(
162 // 'onclick' => 'var json_form_structure = wpbc_bfb__form_structure__get_example(); wpbc_bfb__on_structure_loaded( json_form_structure );',
163 // 'data-wpbc-bfb-load-nonce' => $config['ajax_nonce_load'],
164 // 'data-wpbc-bfb-load-action' => $config['ajax_action_load'],
165 // 'data-wpbc-bfb-form-key' => $config['default_form_key'],
166 // 'data-wpbc-u-busy-text' => __( 'Loading', 'booking' ) . '...',
167 // 'title' => __( 'Discard current changes and load the last saved form structure from database.', 'booking' ),
168 // ),
169 // ),
170 );
171
172 $items = wpbc_bfb__top_toolbar__dropdown_menu__main_forms__maybe_add_import_options( $items, $config );
173
174 $el_arr = array(
175 'title' => $config['dropdown_title'],
176 'font_icon' => $config['dropdown_font_icon'],
177 'position' => 'left',
178 'items' => $items,
179 );
180
181 wpbc_ui_el__dropdown_menu( $el_arr );
182 }
183
184 /**
185 * Maybe Add Import Options to the Main "Form" menu in the top toolbar.
186 *
187 * @param array $items - already existed itmes for drop down menu.
188 *
189 * @return array|mixed
190 */
191 function wpbc_bfb__top_toolbar__dropdown_menu__main_forms__maybe_add_import_options( $items = array(), $config = array() ) {
192
193 $items[] = array( 'type' => 'divider' );
194 $items[] = array(
195 'type' => 'header',
196 'title' => __( 'Import Legacy Forms', 'booking' ),
197 );
198
199 // -----------------------------------------------------------------------------------------------------------------
200 // == Import ==
201 // -----------------------------------------------------------------------------------------------------------------
202
203 // == Free Simple == - Import from Simple Form - Usually in - Free version.
204 $items[] = array(
205 'type' => 'link',
206 'title' => __( 'Import from Simple Form', 'booking' ),
207 'url' => 'javascript:void(0);',
208 'attr' => array(
209 'onclick' => 'wpbc_bfb__import_from_simple_form(this);',
210 'data-wpbc-bfb-import-nonce' => $config['ajax_nonce_import'],
211 'data-wpbc-bfb-import-action' => $config['ajax_action_import'],
212 'data-wpbc-u-busy-text' => __( 'Importing', 'booking' ) . '...',
213 'title' => __( 'Import fields from the previous Simple Form into the Form Builder.', 'booking' ),
214 ),
215 );
216
217
218 // == Pro Advanced == - Import booking forms for == Super Booking Admin == user ( user_id = 0 ).
219 if ( class_exists( 'wpdev_bk_personal' ) ) {
220
221 $custom_forms_count = 0;
222 if ( class_exists( 'wpdev_bk_biz_m' ) ) {
223 $booking_forms_extended = get_bk_option( 'booking_forms_extended' );
224 $booking_forms_extended = ( ! empty( $booking_forms_extended ) ) ? maybe_unserialize( $booking_forms_extended ) : array();
225
226 if ( is_array( $booking_forms_extended ) ) {
227 $custom_forms_count = count( $booking_forms_extended );
228 }
229 }
230 ++$custom_forms_count;
231
232 $items[] = array(
233 'type' => 'link',
234 /* translators: 1: number of custom booking forms. */
235 'title' => sprintf( _n( 'Import %s Advanced Form', 'Import %s Advanced Forms', $custom_forms_count, 'booking' ), $custom_forms_count ),
236 'url' => 'javascript:void(0);',
237 'attr' => array(
238 'onclick' => 'wpbc_bfb__import_legacy_forms(this);',
239 'data-wpbc-bfb-import-nonce' => $config['ajax_nonce_import_legacy_forms'],
240 'data-wpbc-bfb-import-action' => $config['ajax_action_import_legacy_forms'],
241 'data-wpbc-bfb-import-mode' => 'all_global',
242 'data-wpbc-bfb-skip-if-exists' => 'overwrite', // 'skip' | 'overwrite'. Default - 'skip'.
243 'data-wpbc-bfb-set-form-not-defined' => 'not_defined', // 'not_defined' | ''. Default - 'not_defined'.
244 'data-wpbc-u-busy-text' => __( 'Importing', 'booking' ) . '...',
245 'title' => __( 'Import all global legacy booking forms into Form Builder storage.', 'booking' ),
246 ),
247 );
248 }
249
250 // Import booking forms for == All Users ==.
251 if ( class_exists( 'wpdev_bk_multiuser' ) ) {
252
253 $is_user_super_admin = apply_bk_filter( 'is_user_super_admin', wpbc_get_current_user_id() );
254
255 if ( ! $is_user_super_admin ) {
256
257 // Import booking forms only for the == Current User == (usually - "Regular User").
258 $items[] = array(
259 'type' => 'link',
260 'title' => __( 'Import Advanced Forms for Current User', 'booking' ),
261 'url' => 'javascript:void(0);',
262 'attr' => array(
263 'onclick' => 'wpbc_bfb__import_legacy_forms(this);',
264 'data-wpbc-bfb-import-nonce' => $config['ajax_nonce_import_legacy_forms'],
265 'data-wpbc-bfb-import-action' => $config['ajax_action_import_legacy_forms'],
266 'data-wpbc-bfb-import-mode' => 'current_context',
267 'data-wpbc-u-busy-text' => __( 'Importing', 'booking' ) . '...',
268 'title' => __( 'Import all existing Advanced Forms for the current user into the Form Builder.', 'booking' ),
269 'data-wpbc-bfb-skip-if-exists' => 'overwrite', // 'skip' | 'overwrite'. Default - 'skip'.
270 'data-wpbc-bfb-set-form-not-defined' => 'not_defined', // 'not_defined' | ''. Default - 'not_defined'.
271 ),
272 );
273 }
274
275 if ( $is_user_super_admin ) {
276
277 $items[] = array(
278 'type' => 'link',
279 'title' => __( 'Import Advanced Forms for All Users', 'booking' ),
280 'url' => 'javascript:void(0);',
281 'attr' => array(
282 'onclick' => 'wpbc_bfb__import_legacy_forms(this);',
283 'data-wpbc-bfb-import-nonce' => $config['ajax_nonce_import_legacy_forms'],
284 'data-wpbc-bfb-import-action' => $config['ajax_action_import_legacy_forms'],
285 'data-wpbc-bfb-import-mode' => 'all_users',
286 'data-wpbc-u-busy-text' => __( 'Importing', 'booking' ) . '...',
287 'title' => __( 'Import all existing Advanced Forms for all users into the Form Builder.', 'booking' ),
288 // 'data-wpbc-bfb-skip-if-exists' => 'overwrite', // 'skip' | 'overwrite'. Default - 'skip'.
289 // 'data-wpbc-bfb-set-form-not-defined' => 'not_defined', // 'not_defined' | ''. Default - 'not_defined'.
290 ),
291 );
292 }
293 }
294 // -----------------------------------------------------------------------------------------------------------------
295
296 return $items;
297 }
298
299
300 /**
301 * Show Form Builder LOAD / IMPORT dropdown + define JS helpers.
302 *
303 * Hooked into: wpbc_ui_el__top_nav__content_center
304 *
305 * @param string $page_tag Current page tag.
306 * @param string $active_page_tab Current tab.
307 * @param string $active_page_subtab Current subtab.
308 *
309 * @return void
310 */
311 function wpbc_bfb__top_toolbar__dropdown_menu__main_forms__show( $page_tag, $active_page_tab, $active_page_subtab ) {
312
313 if ( ! wpbc_is_builder_booking_form_page() ) {
314 return;
315 }
316
317 // === Common config ================================================================================================
318 $ajax_action_load = 'WPBC_AJX_BFB_LOAD_FORM_CONFIG';
319 $ajax_nonce_load = wp_create_nonce( 'wpbc_bfb_form_load' );
320
321 $ajax_action_import = 'wpbc_bfb_import_simple_form';
322 $ajax_nonce_import = wp_create_nonce( $ajax_action_import );
323
324 $default_form_key = 'default_booking_form';
325
326 wpbc_ui_el__divider_vertical( array( 'style' => 'width: 0.75px;' ) );
327 ?>
328 <div class="wpbc_ui_el__buttons_group wpbc_bfb_ui__elements_hide_in_preview0">
329 <?php
330 // Dropdown: all LOAD / IMPORT actions.
331 wpbc_bfb__top_toolbar__dropdown_menu__main_forms(
332 array(
333 'ajax_action_load' => $ajax_action_load,
334 'ajax_nonce_load' => $ajax_nonce_load,
335 'ajax_action_import' => $ajax_action_import,
336 'ajax_nonce_import' => $ajax_nonce_import,
337 'default_form_key' => $default_form_key,
338 )
339 );
340 ?>
341 </div>
342 <?php
343 }
344 add_action( 'wpbc_ui_el__top_nav__content_start', 'wpbc_bfb__top_toolbar__dropdown_menu__main_forms__show', 10, 3 );
345 // add_action( 'wpbc_ui_el__top_nav__content_center', 'wpbc_bfb__top_toolbar__dropdown_menu__main_forms__show', 10, 3 );
346
347
348 /**
349 * Show Form Builder save + preview controls in top toolbar.
350 *
351 * - Outputs a button group with:
352 * - "Open Builder" / "Preview" / "Refresh Preview".
353 * - "Save Form" button that calls wpbc_bfb__ajax_save_current_form() with busy state.
354 *
355 * Hooked into: wpbc_ui_el__top_nav__content_end
356 *
357 * @param string $page_tag Current page tag.
358 * @param string $active_page_tab Current tab.
359 * @param string $active_page_subtab Current subtab.
360 *
361 * @return void
362 */
363 function wpbc_bfb__top_toolbar__show_save_buttons( $page_tag, $active_page_tab, $active_page_subtab ) {
364
365 if ( ! wpbc_is_builder_booking_form_page() ) {
366 return;
367 }
368
369 // Save to DB (same action as before, now via JS helper).
370 $ajax_action_bfb = 'WPBC_AJX_BFB_SAVE_FORM_CONFIG';
371 $ajax_nonce_bfb = wp_create_nonce( 'wpbc_bfb_form_save' );
372
373 $default_form_key = 'default_booking_form';
374 $default_form_title = 'Standard';
375 ?>
376 <div class="wpbc_ui_el__buttons_group wpbc_bfb__top_toolbar_group">
377 <button
378 type="button"
379 class="button button-primary wpbc_bfb_ui__elements_show_in_preview"
380 data-wpbc-bfb-top-refresh-btn="1"
381 data-wpbc-u-busy-text="<?php esc_attr_e( 'Loading preview', 'booking' ); ?>...">
382 <?php esc_html_e( 'Refresh Preview', 'booking' ); ?>
383 </button>
384
385 <!-- data-wpbc-bfb-save-source="auto|builder|advanced" -->
386 <a href="javascript:void(0);"
387 class="button button-primary wpbc_bfb_ui__elements_hide_in_preview"
388 onclick="wpbc_bfb__ajax_save_current_form(this);"
389 data-wpbc-bfb-save-source="<?php echo esc_attr( class_exists( 'wpdev_bk_personal' ) ? 'auto' : 'builder' ); ?>"
390 data-wpbc-bfb-save-nonce="<?php echo esc_attr( $ajax_nonce_bfb ); ?>"
391 data-wpbc-bfb-save-action="<?php echo esc_attr( $ajax_action_bfb ); ?>"
392 data-wpbc-bfb-form-key="<?php echo esc_attr( $default_form_key ); ?>"
393 data-wpbc-bfb-form-title="<?php echo esc_attr( $default_form_title ); ?>"
394 data-wpbc-u-busy-text="<?php esc_attr_e( 'Saving', 'booking' ); ?>...">
395 <?php esc_html_e( 'Save Form', 'booking' ); ?>
396 </a>
397 </div>
398 <?php
399 }
400 add_action( 'wpbc_ui_el__top_nav__content_end', 'wpbc_bfb__top_toolbar__show_save_buttons', 20, 3 );
401
402 /**
403 * Show Form Builder save + preview controls in top toolbar.
404 *
405 * - Outputs a button group with:
406 * - "Open Builder" / "Preview" / "Refresh Preview".
407 * - "Save Form" button that calls wpbc_bfb__ajax_save_current_form() with busy state.
408 *
409 * Hooked into: wpbc_ui_el__top_nav__content_end
410 *
411 * @param string $page_tag Current page tag.
412 * @param string $active_page_tab Current tab.
413 * @param string $active_page_subtab Current subtab.
414 *
415 * @return void
416 */
417 function wpbc_bfb__top_toolbar__show_preview_buttons( $page_tag, $active_page_tab, $active_page_subtab ) {
418
419 if ( ! wpbc_is_builder_booking_form_page() ) {
420 return;
421 }
422
423 wpbc_bfb__top_toolbar__render_live_source_badge();
424
425 // Save to DB (same action as before, now via JS helper).
426 $ajax_action_bfb = 'WPBC_AJX_BFB_SAVE_FORM_CONFIG';
427 $ajax_nonce_bfb = wp_create_nonce( 'wpbc_bfb_form_save' );
428
429 $default_form_key = 'default_booking_form';
430 $default_form_title = 'Standard';
431 ?>
432 <div class="wpbc_ui_el__buttons_group wpbc_bfb__top_toolbar_group">
433 <?php
434 // --- Preview-mode buttons (visible only when body has .wpbc_bfb__mode_preview) ------------------------------
435 ?>
436 <a href="#" class="button button-secondary wpbc_bfb__top_btn_builder wpbc_bfb_ui__elements_show_in_preview" data-wpbc-bfb-top-builder-btn="1">
437 <?php esc_html_e( 'Back to Form Builder', 'booking' ); ?>
438 </a>
439 <?php
440 // --- Builder-mode buttons (default; hidden in preview mode) ---------------------------------------------------
441 // Can be data-wpbc-bfb-preview-source = 'builder' | 'advanced' | 'auto'
442 if (1) {
443 ?>
444 <div class="wpbc_ajx_toolbar wpbc_no_borders ">
445 <div class="ui_container ui_container_small">
446 <div class="ui_group ui_group__publish_preview_buttons">
447 <div class="ui_element">
448 <a class="wpbc_ui_control wpbc_ui_button tooltip_top wpbc_bfb__top_btn_preview wpbc_bfb_ui__elements_hide_in_preview"
449 data-wpbc-bfb-top-preview-btn="1"
450 data-wpbc-u-busy-text="<?php esc_attr_e( 'Loading preview', 'booking' ); ?>..."
451 data-wpbc-bfb-preview-source="<?php echo esc_attr( class_exists( 'wpdev_bk_personal' ) ? 'auto' : 'builder' ); ?>"
452 data-original-title="<?php esc_attr_e( 'Preview this booking form in your theme', 'booking' ); ?>">
453 <i class="menu_icon icon-1x wpbc_icn_visibility"></i>
454 <span class="in-button-text">&nbsp;&nbsp;<?php esc_html_e( 'Preview', 'booking' ); ?></span>
455 </a>
456 <a class="wpbc_ui_control wpbc_ui_button wpbc_ui_button_green tooltip_top wpbc_bfb__top_btn_publish wpbc_bfb_ui__elements_hide_in_preview"
457 data-wpbc-bfb-top-publish-btn="1"
458 data-wpbc-bfb-resource-id="<?php echo esc_attr( wpbc_get_default_resource() ); ?>"
459 data-wpbc-bfb-shortcode-raw="<?php echo esc_attr( '[booking resource_id=' . absint( wpbc_get_default_resource() ) . ' form_type=\'standard\']' ); ?>"
460 data-original-title="<?php esc_attr_e( 'Embed your booking form into the page', 'booking' ); ?>"
461 href="#"
462 >
463 <i class="menu_icon icon-1x wpbc_icn_code"></i>
464 <span class="in-button-text">&nbsp;&nbsp;<?php esc_html_e( 'Publish', 'booking' ); ?></span>
465 </a>
466 <?php if(0){ ?>
467 <a class="wpbc_ui_control wpbc_ui_button wpbc_ui_button_green tooltip_top wpbc_bfb__top_btn_publish wpbc_bfb_ui__elements_hide_in_preview"
468 data-wpbc-bfb-top-publish-btn="1"
469 data-original-title="<?php esc_attr_e('Embed your booking form into the page', 'booking'); ?>"
470 href="<?php echo esc_url( 'admin.php?page=wpbc-resources' ); ?>"
471 <?php
472 /* href="javascript:void(0);" onclick="javascript: wpbc_modal_dialog__show__resource_publish( <?php echo esc_attr( wpbc_get_default_resource() ); ?> );" */
473 ?>
474 >
475 <i class="menu_icon icon-1x wpbc_icn_code"></i>
476 <span class="in-button-text">&nbsp;&nbsp;<?php esc_html_e( 'Publish', 'booking' ); ?></span>
477 </a>
478 <!--input name="wpbc_text_put_in_shortcode" id="wpbc_text_put_in_shortcode" class="put-in" readonly="readonly" onfocus="this.select()" type="text" style="width: auto;flex: 1;" /-->
479 <?php } ?>
480 <?php if(0){ ?>
481 <a class="wpbc_ui_control wpbc_ui_button wpbc_ui_button_green tooltip_top wpbc_bfb__top_btn_publish wpbc_bfb_ui__elements_hide_in_preview"
482 data-wpbc-bfb-top-publish-btn="1"
483 data-original-title="<?php esc_attr_e('Embed your booking form into the page', 'booking'); ?>"
484 href="javascript:void(0);" onclick="javascript: wpbc_resource_page_btn_click(<?php echo esc_attr( wpbc_get_default_resource() ); ?>);"
485 >
486 <i class="menu_icon icon-1x wpbc_icn_code"></i>
487 <span class="in-button-text">&nbsp;&nbsp;<?php esc_html_e( 'Shortcode', 'booking' ); ?></span>
488 </a>
489 <input name="booking_resource_shortcode_<?php echo esc_attr( wpbc_get_default_resource() ); ?>"
490 id="booking_resource_shortcode_<?php echo esc_attr( wpbc_get_default_resource() ); ?>"
491 class="put-in" readonly="readonly" onfocus="this.select()" type="text" style="width: auto;flex: 1;border-radius: 0 2px 2px 0;font-size: 9px;" />
492 <?php } ?>
493 </div>
494 </div>
495 </div>
496 </div>
497 <?php
498
499 } else {
500 ?>
501 <a href="#" class="button button-secondary wpbc_bfb__top_btn_preview wpbc_bfb_ui__elements_hide_in_preview" data-wpbc-bfb-top-preview-btn="1"
502 data-wpbc-u-busy-text="<?php esc_attr_e( 'Loading preview', 'booking' ); ?>..."
503 data-wpbc-bfb-preview-source="<?php echo esc_attr( class_exists( 'wpdev_bk_personal' ) ? 'auto' : 'builder' ); ?>"
504 >
505 <?php esc_html_e( 'Preview', 'booking' ); ?>
506 </a>
507 <?php
508 }
509
510 ?>
511 </div>
512 <?php
513 }
514 add_action( 'wpbc_ui_el__top_nav__content_end', 'wpbc_bfb__top_toolbar__show_preview_buttons', 10, 3 );
515
516
517
518 /**
519 * Render "Live source" badge placeholder for Builder/Advanced sync state.
520 *
521 * JS will update:
522 * - data-wpbc-bfb-live-source: builder|advanced
523 * - data-wpbc-bfb-sync-mode : on|off
524 *
525 * @param array $args Optional args.
526 *
527 * @return void
528 */
529 function wpbc_bfb__top_toolbar__render_live_source_badge() {
530
531 ?>
532 <div class="wpbc_bfb__live_status wpbc_bfb__live_status__builder"><?php echo esc_html__( 'Live: Builder (auto-sync ON)', 'booking' ); ?></div>
533 <div class="wpbc_bfb__live_status wpbc_bfb__live_status__advanced"><?php echo esc_html__( 'Live: Advanced (manual)', 'booking' ); ?></div>
534 <?php
535 }
536
537 function wpbc_bfb__top_toolbar__show_form_name( $page_tag, $active_page_tab, $active_page_subtab ) {
538
539 if ( ! wpbc_is_builder_booking_form_page() ) {
540 return;
541 }
542 /*
543 ?>
544 <div class="wpbc_bfb__hint__form_name">
545 <div class="wpbc_bfb__hint__form_name__label"><?php esc_html_e( 'Form Name', 'booking' ); ?>:</div>
546 <div class="wpbc_bfb__hint__form_name__title"><?php esc_html_e( 'Loading', 'booking' ); ?>...</div>
547 </div>
548 <?php
549 */
550
551 $picture_field_id = 'wpbc_bfb_setting__bfb_form_details__picture_url';
552 ?>
553 <div class="wpbc_bfb__hint__form_name wpbc_bfb__hint__top_bar">
554 <div class="wpbc_bfb__form_details_media__preview wpbc_media_upload_button"
555 role="button"
556 tabindex="0"
557 aria-label="<?php echo esc_attr__( 'Selected image preview', 'booking' ); ?>"
558 data-modal_title="<?php echo esc_attr__( 'Select Image', 'booking' ); ?>"
559 data-btn_title="<?php echo esc_attr__( 'Use this image', 'booking' ); ?>"
560 data-url_field="<?php echo esc_attr( $picture_field_id ); ?>"
561 >
562 <img src="" alt="" class="wpbc_bfb__form_details_media__img">
563 <i class="wpbc_bfb__form_details_media__placeholder menu_icon icon-1x wpbc-bi-image-fill" aria-hidden="true"></i>
564 </div>
565 <div class="wpbc_bfb__hint__form_name__name">
566 <div class="wpbc_bfb__hint__form_name__title">
567 <!-- onclick="javascript:document.querySelector( '[aria-controls=\"wpbc_bfb__inspector_form_details\"]' ).click();" -->
568 <a href="javascript:void(0);" class="value" ><?php esc_html_e( 'Loading', 'booking' ); ?>...</a>
569 </div>
570 <div class="wpbc_bfb__hint__form_name__label">
571 <?php esc_html_e( 'Slug', 'booking' ); ?>:
572 <div class="wpbc_bfb__hint__form_name__slug"><span class="value"></span></div>
573 <i class="menu_icon icon-1x wpbc-bi-pencil0 wpbc-bi-question-circle" aria-hidden="true" title="<?php esc_attr_e( 'Unique identifier used by the system in shortcodes', 'booking' ); ?>"></i>
574 </div>
575 </div>
576 </div>
577 <?php
578 }
579 add_action( 'wpbc_ui_el__top_nav__content_center', 'wpbc_bfb__top_toolbar__show_form_name', 10, 3 );
580 // ---------------------------------------------------------------------------------------------------------------------
581 // In Page Content - Controls
582 // ---------------------------------------------------------------------------------------------------------------------
583
584 /**
585 * Render "Add columns" control template for the Form Builder toolbar.
586 *
587 * This control renders a dropdown that allows to add a new section
588 * with 1–4 columns into the form builder canvas.
589 *
590 * The template is hidden by default and cloned/used by JS.
591 *
592 * @return void
593 */
594 function wpbc_bfb__ui__add_columns_control() {
595 ?>
596 <div id="wpbc_bfb__add_columns_template" class="add_columns_control_template" hidden>
597 <?php
598 $el_arr = array(
599 'font_icon' => 'wpbc_icn_add_circle',
600 'title' => '<span class="nav-tab-text hide_in_mobile">' . esc_html__( 'Add columns', 'booking' ) . ' </span><span class="selected_value"></span>',
601 'hint' => array(
602 'title' => __( 'Select to add columns', 'booking' ),
603 'position' => 'top',
604 ),
605 'position' => 'left',
606 'has_down_arrow' => true,
607 'has_border' => true,
608 'container_class' => 'ul_dropdown_menu__add_sections',
609 'items' => array(
610 array(
611 'type' => 'header',
612 'title' => __( 'Add section with', 'booking' ) . '...',
613 'class' => 'hide_button_if_no_selection',
614 ),
615 array( 'html' => wpbc_bfb__ui__add_columns__get_option( 1 ) ),
616 array( 'html' => wpbc_bfb__ui__add_columns__get_option( 2 ) ),
617 array( 'html' => wpbc_bfb__ui__add_columns__get_option( 3 ) ),
618 array( 'html' => wpbc_bfb__ui__add_columns__get_option( 4 ) ),
619 ),
620 );
621
622 wpbc_ui_el__dropdown_menu( $el_arr );
623 ?>
624 </div>
625 <?php
626 }
627
628 /**
629 * Get HTML for a single "Add columns" option.
630 *
631 * @param int $column_number Number of columns to add (1–4).
632 *
633 * @return string
634 */
635 function wpbc_bfb__ui__add_columns__get_option( $column_number ) {
636 $column_number = (int) $column_number;
637
638 $css_class = 'ul_dropdown_menu_li_action ul_dropdown_menu_li_action_add_sections';
639
640 // Prepare label: "1 Column" / "2 Columns".
641 $label_single = __( 'Column', 'booking' );
642 $label_plural = __( 'Columns', 'booking' );
643 $label = ( 1 === $column_number ) ? $label_single : $label_plural;
644
645 // Build icon class depending on the number of columns.
646 switch ( $column_number ) {
647 case 1:
648 $icon_class = 'wpbc-bi-square';
649 break;
650 case 2:
651 $icon_class = 'wpbc-bi-layout-split';
652 break;
653 case 3:
654 $icon_class = 'wpbc-bi-layout-three-columns';
655 break;
656 case 4:
657 $icon_class = 'wpbc_icn_calendar_view_week';
658 break;
659 default:
660 $icon_class = 'wpbc-bi-square';
661 break;
662 }
663
664 $html = '<a href="javascript:void(0)"';
665 $html .= ' class="' . esc_attr( $css_class ) . '"';
666 $html .= ' data-cols="' . esc_attr( $column_number ) . '"';
667 $html .= ' title="' . esc_attr( __( 'Add columns', 'booking' ) ) . '"';
668 $html .= '>';
669 $html .= sprintf(
670 '%d %s <i class="menu_icon icon-1x %s"></i>',
671 absint( $column_number ),
672 esc_html( $label ),
673 esc_attr( $icon_class )
674 );
675 $html .= '</a>';
676
677 return $html;
678 }
679
680 /**
681 * Show fullscreen warning for mobile / small-screen usage of the Form Builder.
682 *
683 * The builder is optimized for desktop. This fullscreen overlay warns users on
684 * small screens and lets them continue or close the notice.
685 *
686 * @return void
687 */
688 function wpbc_bfb__ui__show_warning__no_mobile_mode() {
689 ?>
690 <div id="wpbc-builder-mobile-notice" class="wpbc-fullscreen-notice">
691 <div class="wpbc-fullscreen-big-logo">
692 <?php
693 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
694 echo wpbc_get_svg_logo_for_html(
695 array(
696 'svg_color' => '#fff',
697 'svg_color_alt' => '#bbb',
698 'opacity' => '0.35',
699 'style_default' => 'background-repeat: no-repeat; background-position: center; display: inline-block; vertical-align: middle;',
700 'style_adjust' => 'background-size: 40px auto; width: 40px; height: 40px; margin-top: 0px;', // This parameters, the adjust size of the logo and position.
701 'css_class' => '',
702 )
703 );
704 ?>
705 <span class="wpbc-fullscreen-big-logo-title"><span class="wpbc-fullscreen-big-logo-title-wp">WP</span>Booking Calendar</span>
706 </div>
707 <h3><?php esc_html_e( 'Our booking form builder is optimized for desktop computers.', 'booking' ); ?></h3>
708 <p><?php esc_html_e( 'We recommend that you edit your forms on a bigger screen. If you\'d like to proceed, please understand that some functionality might not behave as expected.', 'booking' ); ?></p>
709 <div class=" ">
710 <button type="button" class="button-secondary" onclick="javascript: jQuery( '.wpbc-fullscreen-notice').hide();"><?php esc_html_e( 'Continue', 'booking' ); ?></button>
711 <button type="button" class="wpbc_bfb__button-close" onclick="javascript: jQuery( '.wpbc-fullscreen-notice').hide();" title="<?php esc_attr_e( 'Close', 'booking' ); ?>" aria-label="<?php esc_attr_e( 'Close', 'booking' ); ?>"><i class="menu_icon icon-1x wpbc_icn_close"></i></button>
712 </div>
713 </div>
714 <style type="text/css">
715 @media (min-width: 1024px) {
716 #wpbc-builder-mobile-notice {
717 display: none;
718 }
719 .wpbc_settings_page_wrapper.max .wpbc_settings_page_content .wpbc_page {
720 display: block;
721 }
722 }
723 .wpbc-fullscreen-notice {
724 background: #f5f6f7;
725 cursor: default;
726 height: 100%;
727 min-width: 0;
728 padding: 0 20px;
729 overflow: scroll;
730 position: fixed;
731 z-index: 100110;
732 text-align: center;
733 top: 0;
734 right: 0;
735 bottom: 0;
736 left: 0;
737 display: flex;
738 flex-direction: column;
739 justify-content: center;
740 align-items: center;
741 background: #374655;
742 scrollbar-width: thin;
743 }
744 .wpbc-fullscreen-notice * {
745 color: #fff;
746 }
747 .wpbc-fullscreen-big-logo {
748 display: flex;
749 flex-flow: row nowrap;
750 align-items: center;
751 justify-content: flex-start;
752 gap: 10px;
753 position: absolute;
754 top: 20px;
755 left: 20px;
756 }
757 .wpbc-fullscreen-big-logo-title {
758 margin: -15px 0 0 0;
759 font-size: 25px;
760 padding: 0;
761 font-weight: 600;
762 }
763 .wpbc-fullscreen-big-logo-title-wp {
764 position: absolute;
765 font-size: 10px;
766 margin-top: 18px;
767 margin-left: 1px;
768 font-weight: 501;
769 }
770 .wpbc-fullscreen-notice h3{
771 line-height: 1.74em;
772 font-size: 24px;
773 }
774 .wpbc-fullscreen-notice .wpbc_bfb__button-close {
775 position: absolute;
776 top: 20px;
777 right:20px;
778 margin: 0;
779 border: 0;
780 padding: 0;
781 vertical-align: middle;
782 background: 0 0;
783 height: auto;
784 box-sizing: border-box;
785 cursor: pointer;
786 }
787 .wpbc-fullscreen-notice .wpbc_bfb__button-close .wpbc_icn_close::before {
788 font-size: 22px;
789 }
790 </style>
791 <?php
792 }
793