PluginProbe
Booking Calendar / 11.1
Booking Calendar v11.1
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.1, at includes/page-form-builder/bfb-ui-elements.php

789 lines 30.4 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' ) && ( ! empty( maybe_unserialize( get_bk_option( 'booking_forms_extended' ) ) ) ) ) {
223 $custom_forms_count = maybe_unserialize( get_bk_option( 'booking_forms_extended' ) );
224 $custom_forms_count = count( $custom_forms_count );
225 }
226 ++$custom_forms_count;
227
228 $items[] = array(
229 'type' => 'link',
230 /* translators: 1: number of custom booking forms. */
231 'title' => sprintf( _n( 'Import %s Advanced Form', 'Import %s Advanced Forms', $custom_forms_count, 'booking' ), $custom_forms_count ),
232 'url' => 'javascript:void(0);',
233 'attr' => array(
234 'onclick' => 'wpbc_bfb__import_legacy_forms(this);',
235 'data-wpbc-bfb-import-nonce' => $config['ajax_nonce_import_legacy_forms'],
236 'data-wpbc-bfb-import-action' => $config['ajax_action_import_legacy_forms'],
237 'data-wpbc-bfb-import-mode' => 'all_global',
238 'data-wpbc-bfb-skip-if-exists' => 'overwrite', // 'skip' | 'overwrite'. Default - 'skip'.
239 'data-wpbc-bfb-set-form-not-defined' => 'not_defined', // 'not_defined' | ''. Default - 'not_defined'.
240 'data-wpbc-u-busy-text' => __( 'Importing', 'booking' ) . '...',
241 'title' => __( 'Import all global legacy booking forms into Form Builder storage.', 'booking' ),
242 ),
243 );
244 }
245
246 // Import booking forms for == All Users ==.
247 if ( class_exists( 'wpdev_bk_multiuser' ) ) {
248
249 $is_user_super_admin = apply_bk_filter( 'is_user_super_admin', wpbc_get_current_user_id() );
250
251 if ( ! $is_user_super_admin ) {
252
253 // Import booking forms only for the == Current User == (usually - "Regular User").
254 $items[] = array(
255 'type' => 'link',
256 'title' => __( 'Import Advanced Forms for Current User', 'booking' ),
257 'url' => 'javascript:void(0);',
258 'attr' => array(
259 'onclick' => 'wpbc_bfb__import_legacy_forms(this);',
260 'data-wpbc-bfb-import-nonce' => $config['ajax_nonce_import_legacy_forms'],
261 'data-wpbc-bfb-import-action' => $config['ajax_action_import_legacy_forms'],
262 'data-wpbc-bfb-import-mode' => 'current_context',
263 'data-wpbc-u-busy-text' => __( 'Importing', 'booking' ) . '...',
264 'title' => __( 'Import all existing Advanced Forms for the current user into the Form Builder.', 'booking' ),
265 'data-wpbc-bfb-skip-if-exists' => 'overwrite', // 'skip' | 'overwrite'. Default - 'skip'.
266 'data-wpbc-bfb-set-form-not-defined' => 'not_defined', // 'not_defined' | ''. Default - 'not_defined'.
267 ),
268 );
269 }
270
271 if ( $is_user_super_admin ) {
272
273 $items[] = array(
274 'type' => 'link',
275 'title' => __( 'Import Advanced Forms for All Users', 'booking' ),
276 'url' => 'javascript:void(0);',
277 'attr' => array(
278 'onclick' => 'wpbc_bfb__import_legacy_forms(this);',
279 'data-wpbc-bfb-import-nonce' => $config['ajax_nonce_import_legacy_forms'],
280 'data-wpbc-bfb-import-action' => $config['ajax_action_import_legacy_forms'],
281 'data-wpbc-bfb-import-mode' => 'all_users',
282 'data-wpbc-u-busy-text' => __( 'Importing', 'booking' ) . '...',
283 'title' => __( 'Import all existing Advanced Forms for all users into the Form Builder.', 'booking' ),
284 // 'data-wpbc-bfb-skip-if-exists' => 'overwrite', // 'skip' | 'overwrite'. Default - 'skip'.
285 // 'data-wpbc-bfb-set-form-not-defined' => 'not_defined', // 'not_defined' | ''. Default - 'not_defined'.
286 ),
287 );
288 }
289 }
290 // -----------------------------------------------------------------------------------------------------------------
291
292 return $items;
293 }
294
295
296 /**
297 * Show Form Builder LOAD / IMPORT dropdown + define JS helpers.
298 *
299 * Hooked into: wpbc_ui_el__top_nav__content_center
300 *
301 * @param string $page_tag Current page tag.
302 * @param string $active_page_tab Current tab.
303 * @param string $active_page_subtab Current subtab.
304 *
305 * @return void
306 */
307 function wpbc_bfb__top_toolbar__dropdown_menu__main_forms__show( $page_tag, $active_page_tab, $active_page_subtab ) {
308
309 if ( ! wpbc_is_builder_booking_form_page() ) {
310 return;
311 }
312
313 // === Common config ================================================================================================
314 $ajax_action_load = 'WPBC_AJX_BFB_LOAD_FORM_CONFIG';
315 $ajax_nonce_load = wp_create_nonce( 'wpbc_bfb_form_load' );
316
317 $ajax_action_import = 'wpbc_bfb_import_simple_form';
318 $ajax_nonce_import = wp_create_nonce( $ajax_action_import );
319
320 $default_form_key = 'default_booking_form';
321
322 wpbc_ui_el__divider_vertical( array( 'style' => 'width: 0.75px;' ) );
323 ?>
324 <div class="wpbc_ui_el__buttons_group wpbc_bfb_ui__elements_hide_in_preview0">
325 <?php
326 // Dropdown: all LOAD / IMPORT actions.
327 wpbc_bfb__top_toolbar__dropdown_menu__main_forms(
328 array(
329 'ajax_action_load' => $ajax_action_load,
330 'ajax_nonce_load' => $ajax_nonce_load,
331 'ajax_action_import' => $ajax_action_import,
332 'ajax_nonce_import' => $ajax_nonce_import,
333 'default_form_key' => $default_form_key,
334 )
335 );
336 ?>
337 </div>
338 <?php
339 }
340 add_action( 'wpbc_ui_el__top_nav__content_start', 'wpbc_bfb__top_toolbar__dropdown_menu__main_forms__show', 10, 3 );
341 // add_action( 'wpbc_ui_el__top_nav__content_center', 'wpbc_bfb__top_toolbar__dropdown_menu__main_forms__show', 10, 3 );
342
343
344 /**
345 * Show Form Builder save + preview controls in top toolbar.
346 *
347 * - Outputs a button group with:
348 * - "Open Builder" / "Preview" / "Refresh Preview".
349 * - "Save Form" button that calls wpbc_bfb__ajax_save_current_form() with busy state.
350 *
351 * Hooked into: wpbc_ui_el__top_nav__content_end
352 *
353 * @param string $page_tag Current page tag.
354 * @param string $active_page_tab Current tab.
355 * @param string $active_page_subtab Current subtab.
356 *
357 * @return void
358 */
359 function wpbc_bfb__top_toolbar__show_save_buttons( $page_tag, $active_page_tab, $active_page_subtab ) {
360
361 if ( ! wpbc_is_builder_booking_form_page() ) {
362 return;
363 }
364
365 // Save to DB (same action as before, now via JS helper).
366 $ajax_action_bfb = 'WPBC_AJX_BFB_SAVE_FORM_CONFIG';
367 $ajax_nonce_bfb = wp_create_nonce( 'wpbc_bfb_form_save' );
368
369 $default_form_key = 'default_booking_form';
370 $default_form_title = 'Standard';
371 ?>
372 <div class="wpbc_ui_el__buttons_group wpbc_bfb__top_toolbar_group">
373 <button
374 type="button"
375 class="button button-primary wpbc_bfb_ui__elements_show_in_preview"
376 data-wpbc-bfb-top-refresh-btn="1"
377 data-wpbc-u-busy-text="<?php esc_attr_e( 'Loading preview', 'booking' ); ?>...">
378 <?php esc_html_e( 'Refresh Preview', 'booking' ); ?>
379 </button>
380
381 <!-- data-wpbc-bfb-save-source="auto|builder|advanced" -->
382 <a href="javascript:void(0);"
383 class="button button-primary wpbc_bfb_ui__elements_hide_in_preview"
384 onclick="wpbc_bfb__ajax_save_current_form(this);"
385 data-wpbc-bfb-save-source="<?php echo esc_attr( class_exists( 'wpdev_bk_personal' ) ? 'auto' : 'builder' ); ?>"
386 data-wpbc-bfb-save-nonce="<?php echo esc_attr( $ajax_nonce_bfb ); ?>"
387 data-wpbc-bfb-save-action="<?php echo esc_attr( $ajax_action_bfb ); ?>"
388 data-wpbc-bfb-form-key="<?php echo esc_attr( $default_form_key ); ?>"
389 data-wpbc-bfb-form-title="<?php echo esc_attr( $default_form_title ); ?>"
390 data-wpbc-u-busy-text="<?php esc_attr_e( 'Saving', 'booking' ); ?>...">
391 <?php esc_html_e( 'Save Form', 'booking' ); ?>
392 </a>
393 </div>
394 <?php
395 }
396 add_action( 'wpbc_ui_el__top_nav__content_end', 'wpbc_bfb__top_toolbar__show_save_buttons', 20, 3 );
397
398 /**
399 * Show Form Builder save + preview controls in top toolbar.
400 *
401 * - Outputs a button group with:
402 * - "Open Builder" / "Preview" / "Refresh Preview".
403 * - "Save Form" button that calls wpbc_bfb__ajax_save_current_form() with busy state.
404 *
405 * Hooked into: wpbc_ui_el__top_nav__content_end
406 *
407 * @param string $page_tag Current page tag.
408 * @param string $active_page_tab Current tab.
409 * @param string $active_page_subtab Current subtab.
410 *
411 * @return void
412 */
413 function wpbc_bfb__top_toolbar__show_preview_buttons( $page_tag, $active_page_tab, $active_page_subtab ) {
414
415 if ( ! wpbc_is_builder_booking_form_page() ) {
416 return;
417 }
418
419 wpbc_bfb__top_toolbar__render_live_source_badge();
420
421 // Save to DB (same action as before, now via JS helper).
422 $ajax_action_bfb = 'WPBC_AJX_BFB_SAVE_FORM_CONFIG';
423 $ajax_nonce_bfb = wp_create_nonce( 'wpbc_bfb_form_save' );
424
425 $default_form_key = 'default_booking_form';
426 $default_form_title = 'Standard';
427 ?>
428 <div class="wpbc_ui_el__buttons_group wpbc_bfb__top_toolbar_group">
429 <?php
430 // --- Preview-mode buttons (visible only when body has .wpbc_bfb__mode_preview) ------------------------------
431 ?>
432 <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">
433 <?php esc_html_e( 'Back to Form Builder', 'booking' ); ?>
434 </a>
435 <?php
436 // --- Builder-mode buttons (default; hidden in preview mode) ---------------------------------------------------
437 // Can be data-wpbc-bfb-preview-source = 'builder' | 'advanced' | 'auto'
438 if (1) {
439 ?>
440 <div class="wpbc_ajx_toolbar wpbc_no_borders ">
441 <div class="ui_container ui_container_small">
442 <div class="ui_group ui_group__publish_preview_buttons">
443 <div class="ui_element">
444 <a class="wpbc_ui_control wpbc_ui_button tooltip_top wpbc_bfb__top_btn_preview wpbc_bfb_ui__elements_hide_in_preview"
445 data-wpbc-bfb-top-preview-btn="1"
446 data-wpbc-u-busy-text="<?php esc_attr_e( 'Loading preview', 'booking' ); ?>..."
447 data-wpbc-bfb-preview-source="<?php echo esc_attr( class_exists( 'wpdev_bk_personal' ) ? 'auto' : 'builder' ); ?>"
448 data-original-title="<?php esc_attr_e( 'Preview this booking form in your theme', 'booking' ); ?>">
449 <i class="menu_icon icon-1x wpbc_icn_visibility"></i>
450 <span class="in-button-text">&nbsp;&nbsp;<?php esc_html_e( 'Preview', 'booking' ); ?></span>
451 </a>
452 <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"
453 data-wpbc-bfb-top-publish-btn="1"
454 data-wpbc-bfb-resource-id="<?php echo esc_attr( wpbc_get_default_resource() ); ?>"
455 data-wpbc-bfb-shortcode-raw="<?php echo esc_attr( '[booking resource_id=' . absint( wpbc_get_default_resource() ) . ' form_type=\'standard\']' ); ?>"
456 data-original-title="<?php esc_attr_e( 'Embed your booking form into the page', 'booking' ); ?>"
457 href="#"
458 >
459 <i class="menu_icon icon-1x wpbc_icn_code"></i>
460 <span class="in-button-text">&nbsp;&nbsp;<?php esc_html_e( 'Publish', 'booking' ); ?></span>
461 </a>
462 <?php if(0){ ?>
463 <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"
464 data-wpbc-bfb-top-publish-btn="1"
465 data-original-title="<?php esc_attr_e('Embed your booking form into the page', 'booking'); ?>"
466 href="<?php echo esc_url( 'admin.php?page=wpbc-resources' ); ?>"
467 <?php
468 /* href="javascript:void(0);" onclick="javascript: wpbc_modal_dialog__show__resource_publish( <?php echo esc_attr( wpbc_get_default_resource() ); ?> );" */
469 ?>
470 >
471 <i class="menu_icon icon-1x wpbc_icn_code"></i>
472 <span class="in-button-text">&nbsp;&nbsp;<?php esc_html_e( 'Publish', 'booking' ); ?></span>
473 </a>
474 <!--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;" /-->
475 <?php } ?>
476 <?php if(0){ ?>
477 <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"
478 data-wpbc-bfb-top-publish-btn="1"
479 data-original-title="<?php esc_attr_e('Embed your booking form into the page', 'booking'); ?>"
480 href="javascript:void(0);" onclick="javascript: wpbc_resource_page_btn_click(<?php echo esc_attr( wpbc_get_default_resource() ); ?>);"
481 >
482 <i class="menu_icon icon-1x wpbc_icn_code"></i>
483 <span class="in-button-text">&nbsp;&nbsp;<?php esc_html_e( 'Shortcode', 'booking' ); ?></span>
484 </a>
485 <input name="booking_resource_shortcode_<?php echo esc_attr( wpbc_get_default_resource() ); ?>"
486 id="booking_resource_shortcode_<?php echo esc_attr( wpbc_get_default_resource() ); ?>"
487 class="put-in" readonly="readonly" onfocus="this.select()" type="text" style="width: auto;flex: 1;border-radius: 0 2px 2px 0;font-size: 9px;" />
488 <?php } ?>
489 </div>
490 </div>
491 </div>
492 </div>
493 <?php
494
495 } else {
496 ?>
497 <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"
498 data-wpbc-u-busy-text="<?php esc_attr_e( 'Loading preview', 'booking' ); ?>..."
499 data-wpbc-bfb-preview-source="<?php echo esc_attr( class_exists( 'wpdev_bk_personal' ) ? 'auto' : 'builder' ); ?>"
500 >
501 <?php esc_html_e( 'Preview', 'booking' ); ?>
502 </a>
503 <?php
504 }
505
506 ?>
507 </div>
508 <?php
509 }
510 add_action( 'wpbc_ui_el__top_nav__content_end', 'wpbc_bfb__top_toolbar__show_preview_buttons', 10, 3 );
511
512
513
514 /**
515 * Render "Live source" badge placeholder for Builder/Advanced sync state.
516 *
517 * JS will update:
518 * - data-wpbc-bfb-live-source: builder|advanced
519 * - data-wpbc-bfb-sync-mode : on|off
520 *
521 * @param array $args Optional args.
522 *
523 * @return void
524 */
525 function wpbc_bfb__top_toolbar__render_live_source_badge() {
526
527 ?>
528 <div class="wpbc_bfb__live_status wpbc_bfb__live_status__builder"><?php echo esc_html__( 'Live: Builder (auto-sync ON)', 'booking' ); ?></div>
529 <div class="wpbc_bfb__live_status wpbc_bfb__live_status__advanced"><?php echo esc_html__( 'Live: Advanced (manual)', 'booking' ); ?></div>
530 <?php
531 }
532
533 function wpbc_bfb__top_toolbar__show_form_name( $page_tag, $active_page_tab, $active_page_subtab ) {
534
535 if ( ! wpbc_is_builder_booking_form_page() ) {
536 return;
537 }
538 /*
539 ?>
540 <div class="wpbc_bfb__hint__form_name">
541 <div class="wpbc_bfb__hint__form_name__label"><?php esc_html_e( 'Form Name', 'booking' ); ?>:</div>
542 <div class="wpbc_bfb__hint__form_name__title"><?php esc_html_e( 'Loading', 'booking' ); ?>...</div>
543 </div>
544 <?php
545 */
546
547 $picture_field_id = 'wpbc_bfb_setting__bfb_form_details__picture_url';
548 ?>
549 <div class="wpbc_bfb__hint__form_name wpbc_bfb__hint__top_bar">
550 <div class="wpbc_bfb__form_details_media__preview wpbc_media_upload_button"
551 role="button"
552 tabindex="0"
553 aria-label="<?php echo esc_attr__( 'Selected image preview', 'booking' ); ?>"
554 data-modal_title="<?php echo esc_attr__( 'Select Image', 'booking' ); ?>"
555 data-btn_title="<?php echo esc_attr__( 'Use this image', 'booking' ); ?>"
556 data-url_field="<?php echo esc_attr( $picture_field_id ); ?>"
557 >
558 <img src="" alt="" class="wpbc_bfb__form_details_media__img">
559 <i class="wpbc_bfb__form_details_media__placeholder menu_icon icon-1x wpbc-bi-image-fill" aria-hidden="true"></i>
560 </div>
561 <div class="wpbc_bfb__hint__form_name__name">
562 <div class="wpbc_bfb__hint__form_name__title">
563 <!-- onclick="javascript:document.querySelector( '[aria-controls=\"wpbc_bfb__inspector_form_details\"]' ).click();" -->
564 <a href="javascript:void(0);" class="value" ><?php esc_html_e( 'Loading', 'booking' ); ?>...</a>
565 </div>
566 <div class="wpbc_bfb__hint__form_name__label">
567 <?php esc_html_e( 'Slug', 'booking' ); ?>:
568 <div class="wpbc_bfb__hint__form_name__slug"><span class="value"></span></div>
569 <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>
570 </div>
571 </div>
572 </div>
573 <?php
574 }
575 add_action( 'wpbc_ui_el__top_nav__content_center', 'wpbc_bfb__top_toolbar__show_form_name', 10, 3 );
576 // ---------------------------------------------------------------------------------------------------------------------
577 // In Page Content - Controls
578 // ---------------------------------------------------------------------------------------------------------------------
579
580 /**
581 * Render "Add columns" control template for the Form Builder toolbar.
582 *
583 * This control renders a dropdown that allows to add a new section
584 * with 1–4 columns into the form builder canvas.
585 *
586 * The template is hidden by default and cloned/used by JS.
587 *
588 * @return void
589 */
590 function wpbc_bfb__ui__add_columns_control() {
591 ?>
592 <div id="wpbc_bfb__add_columns_template" class="add_columns_control_template" hidden>
593 <?php
594 $el_arr = array(
595 'font_icon' => 'wpbc_icn_add_circle',
596 'title' => '<span class="nav-tab-text hide_in_mobile">' . esc_html__( 'Add columns', 'booking' ) . ' </span><span class="selected_value"></span>',
597 'hint' => array(
598 'title' => __( 'Select to add columns', 'booking' ),
599 'position' => 'top',
600 ),
601 'position' => 'left',
602 'has_down_arrow' => true,
603 'has_border' => true,
604 'container_class' => 'ul_dropdown_menu__add_sections',
605 'items' => array(
606 array(
607 'type' => 'header',
608 'title' => __( 'Add section with', 'booking' ) . '...',
609 'class' => 'hide_button_if_no_selection',
610 ),
611 array( 'html' => wpbc_bfb__ui__add_columns__get_option( 1 ) ),
612 array( 'html' => wpbc_bfb__ui__add_columns__get_option( 2 ) ),
613 array( 'html' => wpbc_bfb__ui__add_columns__get_option( 3 ) ),
614 array( 'html' => wpbc_bfb__ui__add_columns__get_option( 4 ) ),
615 ),
616 );
617
618 wpbc_ui_el__dropdown_menu( $el_arr );
619 ?>
620 </div>
621 <?php
622 }
623
624 /**
625 * Get HTML for a single "Add columns" option.
626 *
627 * @param int $column_number Number of columns to add (1–4).
628 *
629 * @return string
630 */
631 function wpbc_bfb__ui__add_columns__get_option( $column_number ) {
632 $column_number = (int) $column_number;
633
634 $css_class = 'ul_dropdown_menu_li_action ul_dropdown_menu_li_action_add_sections';
635
636 // Prepare label: "1 Column" / "2 Columns".
637 $label_single = __( 'Column', 'booking' );
638 $label_plural = __( 'Columns', 'booking' );
639 $label = ( 1 === $column_number ) ? $label_single : $label_plural;
640
641 // Build icon class depending on the number of columns.
642 switch ( $column_number ) {
643 case 1:
644 $icon_class = 'wpbc-bi-square';
645 break;
646 case 2:
647 $icon_class = 'wpbc-bi-layout-split';
648 break;
649 case 3:
650 $icon_class = 'wpbc-bi-layout-three-columns';
651 break;
652 case 4:
653 $icon_class = 'wpbc_icn_calendar_view_week';
654 break;
655 default:
656 $icon_class = 'wpbc-bi-square';
657 break;
658 }
659
660 $html = '<a href="javascript:void(0)"';
661 $html .= ' class="' . esc_attr( $css_class ) . '"';
662 $html .= ' data-cols="' . esc_attr( $column_number ) . '"';
663 $html .= ' title="' . esc_attr( __( 'Add columns', 'booking' ) ) . '"';
664 $html .= '>';
665 $html .= sprintf(
666 '%d %s <i class="menu_icon icon-1x %s"></i>',
667 absint( $column_number ),
668 esc_html( $label ),
669 esc_attr( $icon_class )
670 );
671 $html .= '</a>';
672
673 return $html;
674 }
675
676 /**
677 * Show fullscreen warning for mobile / small-screen usage of the Form Builder.
678 *
679 * The builder is optimized for desktop. This fullscreen overlay warns users on
680 * small screens and lets them continue or close the notice.
681 *
682 * @return void
683 */
684 function wpbc_bfb__ui__show_warning__no_mobile_mode() {
685 ?>
686 <div id="wpbc-builder-mobile-notice" class="wpbc-fullscreen-notice">
687 <div class="wpbc-fullscreen-big-logo">
688 <?php
689 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
690 echo wpbc_get_svg_logo_for_html(
691 array(
692 'svg_color' => '#fff',
693 'svg_color_alt' => '#bbb',
694 'opacity' => '0.35',
695 'style_default' => 'background-repeat: no-repeat; background-position: center; display: inline-block; vertical-align: middle;',
696 'style_adjust' => 'background-size: 40px auto; width: 40px; height: 40px; margin-top: 0px;', // This parameters, the adjust size of the logo and position.
697 'css_class' => '',
698 )
699 );
700 ?>
701 <span class="wpbc-fullscreen-big-logo-title"><span class="wpbc-fullscreen-big-logo-title-wp">WP</span>Booking Calendar</span>
702 </div>
703 <h3><?php esc_html_e( 'Our booking form builder is optimized for desktop computers.', 'booking' ); ?></h3>
704 <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>
705 <div class=" ">
706 <button type="button" class="button-secondary" onclick="javascript: jQuery( '.wpbc-fullscreen-notice').hide();"><?php esc_html_e( 'Continue', 'booking' ); ?></button>
707 <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>
708 </div>
709 </div>
710 <style type="text/css">
711 @media (min-width: 1024px) {
712 #wpbc-builder-mobile-notice {
713 display: none;
714 }
715 .wpbc_settings_page_wrapper.max .wpbc_settings_page_content .wpbc_page {
716 display: block;
717 }
718 }
719 .wpbc-fullscreen-notice {
720 background: #f5f6f7;
721 cursor: default;
722 height: 100%;
723 min-width: 0;
724 padding: 0 20px;
725 overflow: scroll;
726 position: fixed;
727 z-index: 100110;
728 text-align: center;
729 top: 0;
730 right: 0;
731 bottom: 0;
732 left: 0;
733 display: flex;
734 flex-direction: column;
735 justify-content: center;
736 align-items: center;
737 background: #374655;
738 scrollbar-width: thin;
739 }
740 .wpbc-fullscreen-notice * {
741 color: #fff;
742 }
743 .wpbc-fullscreen-big-logo {
744 display: flex;
745 flex-flow: row nowrap;
746 align-items: center;
747 justify-content: flex-start;
748 gap: 10px;
749 position: absolute;
750 top: 20px;
751 left: 20px;
752 }
753 .wpbc-fullscreen-big-logo-title {
754 margin: -15px 0 0 0;
755 font-size: 25px;
756 padding: 0;
757 font-weight: 600;
758 }
759 .wpbc-fullscreen-big-logo-title-wp {
760 position: absolute;
761 font-size: 10px;
762 margin-top: 18px;
763 margin-left: 1px;
764 font-weight: 501;
765 }
766 .wpbc-fullscreen-notice h3{
767 line-height: 1.74em;
768 font-size: 24px;
769 }
770 .wpbc-fullscreen-notice .wpbc_bfb__button-close {
771 position: absolute;
772 top: 20px;
773 right:20px;
774 margin: 0;
775 border: 0;
776 padding: 0;
777 vertical-align: middle;
778 background: 0 0;
779 height: auto;
780 box-sizing: border-box;
781 cursor: pointer;
782 }
783 .wpbc-fullscreen-notice .wpbc_bfb__button-close .wpbc_icn_close::before {
784 font-size: 22px;
785 }
786 </style>
787 <?php
788 }
789