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