| 1 |
<?php /** |
| 2 |
* @version 1.0 |
| 3 |
* @package Booking Calendar |
| 4 |
* @category Simple Booking Form Setup |
| 5 |
* @author wpdevelop |
| 6 |
* |
| 7 |
* @web-site https://wpbookingcalendar.com/ |
| 8 |
* @email info@wpbookingcalendar.com |
| 9 |
* |
| 10 |
* @modified 2024-08-16 |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 14 |
|
| 15 |
|
| 16 |
/** |
| 17 |
* Get - Visual - Booking Form Structure |
| 18 |
* |
| 19 |
* @return array|false|mixed|null |
| 20 |
*/ |
| 21 |
function wpbc_simple_form__db__get_visual_form_structure( $custom_booking_form = 'standard' ) { |
| 22 |
|
| 23 |
// == Custom Forms == Start // Get Custom booking form |
| 24 |
if ( class_exists( 'wpdev_bk_biz_m' ) ) { |
| 25 |
$form_name = wpbc_get_sanitized_custom_booking_form_name_from_url(); |
| 26 |
if ( empty( $form_name ) ) { |
| 27 |
$form_name = $custom_booking_form; |
| 28 |
} |
| 29 |
if ( ( ! empty( $form_name ) ) && ( 'standard' !== $form_name ) ) { |
| 30 |
$custom_booking_form = wpbc_get_custom_booking_form__for_simple_form_mode( $form_name ); |
| 31 |
if ( ! empty( $custom_booking_form ) ) { |
| 32 |
return $custom_booking_form; |
| 33 |
} |
| 34 |
} |
| 35 |
} |
| 36 |
// == Custom Forms == End |
| 37 |
|
| 38 |
$visual_form_structure = get_bk_option( 'booking_form_visual' ); |
| 39 |
$visual_form_structure = maybe_unserialize( $visual_form_structure ); |
| 40 |
|
| 41 |
if ( $visual_form_structure == false ) { |
| 42 |
// Get blank data |
| 43 |
$visual_form_structure = wpbc_simple_form__visual__get_default_form(); |
| 44 |
} |
| 45 |
|
| 46 |
return $visual_form_structure; |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
/** |
| 51 |
* Get == Content of booking fields data == based on Visual Structure |
| 52 |
* |
| 53 |
* @param $visual_form_structure array |
| 54 |
* |
| 55 |
* @return string |
| 56 |
*/ |
| 57 |
function wpbc_simple_form__get_form_show__as_shortcodes( $visual_form_structure = false ) { |
| 58 |
|
| 59 |
if ( empty( $visual_form_structure ) ) { |
| 60 |
$visual_form_structure = wpbc_simple_form__db__get_visual_form_structure(); |
| 61 |
} |
| 62 |
$visual_form_structure = maybe_unserialize( $visual_form_structure ); |
| 63 |
|
| 64 |
|
| 65 |
$booking_form_show = '<div class="simple-content-form" style="text-align:left;word-wrap: break-word;">' . "\n"; |
| 66 |
|
| 67 |
$skip_already_exist_field_types = array( 'calendar', 'submit', 'captcha' ); |
| 68 |
|
| 69 |
foreach ( $visual_form_structure as $key => $form_field ) { |
| 70 |
|
| 71 |
$defaults = array( |
| 72 |
'type' => 'text', |
| 73 |
'name' => 'unique_name', |
| 74 |
'obligatory' => 'Off', |
| 75 |
'active' => 'On', |
| 76 |
'required' => 'Off', |
| 77 |
'label' => '', |
| 78 |
'value' => '' |
| 79 |
); |
| 80 |
$form_field = wp_parse_args( $form_field, $defaults ); |
| 81 |
|
| 82 |
if ( |
| 83 |
( ! in_array( $form_field['type'], $skip_already_exist_field_types ) ) |
| 84 |
&& ( ( $form_field['active'] != 'Off' ) || ( $form_field['obligatory'] == 'On' ) ) |
| 85 |
){ |
| 86 |
// L abel language |
| 87 |
$form_field['label'] = wpbc_lang( $form_field['label'] ); |
| 88 |
if ( function_exists( 'icl_translate' ) ) { |
| 89 |
$form_field['label'] = icl_translate( 'wpml_custom', 'wpbc_custom_form_field_label_' . $form_field['name'], $form_field['label'] ); // WPML |
| 90 |
} |
| 91 |
// FixIn: 10.10.1.3. |
| 92 |
if ( |
| 93 |
( in_array( $form_field['type'], array( 'select', 'selectbox', 'checkbox' ) ) ) && |
| 94 |
( in_array( $form_field['name'], array( 'rangetime', 'durationtime' ) ) ) //, 'starttime', 'endtime'. |
| 95 |
) { |
| 96 |
$booking_form_show .= ' <b>' . $form_field['label'] . '</b>: ' . '<f><span class="field_data_val"><span>[' . $form_field['name'] . '_val]</span> / </span>[' . $form_field['name'] . ']</f><br/>' . "\n"; |
| 97 |
} else { |
| 98 |
$booking_form_show .= ' <b>' . $form_field['label'] . '</b>: ' . '<f>[' . $form_field['name'] . ']</f><br/>' . "\n"; |
| 99 |
} |
| 100 |
|
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
$booking_form_show.='</div>'; |
| 105 |
|
| 106 |
return $booking_form_show; |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
/** |
| 111 |
* This function get transfer "Booking form" from "Simple (free) --> Paid" Free Structure -> Shortcodes |
| 112 |
* |
| 113 |
* usually later it saved update_bk_option( 'booking_form', ... ) on $this->update() function |
| 114 |
* |
| 115 |
* Get Booking form in Shortcodes - format compatible with premium versions |
| 116 |
* |
| 117 |
* @param $visual_form_structure |
| 118 |
* |
| 119 |
* @return string |
| 120 |
*/ |
| 121 |
function wpbc_simple_form__get_booking_form__as_shortcodes( $visual_form_structure = false ) { |
| 122 |
|
| 123 |
// ------------------------------------------------------------------------------------------------------------- |
| 124 |
// Get simple booking form structure |
| 125 |
// ------------------------------------------------------------------------------------------------------------- |
| 126 |
if ( empty( $visual_form_structure ) ) { |
| 127 |
$visual_form_structure = wpbc_simple_form__db__get_visual_form_structure(); |
| 128 |
} |
| 129 |
$visual_form_structure = maybe_unserialize( $visual_form_structure ); |
| 130 |
|
| 131 |
// ------------------------------------------------------------------------------------------------------------- |
| 132 |
// Get Booking Form - Structure - |
| 133 |
// ------------------------------------------------------------------------------------------------------------- |
| 134 |
$booking_form_structure = get_bk_option( 'booking_form_structure_type' ); |
| 135 |
if ( empty( $booking_form_structure ) ) { |
| 136 |
$booking_form_structure = 'vertical'; |
| 137 |
} |
| 138 |
|
| 139 |
// ------------------------------------------------------------------------------------------------------------- |
| 140 |
// Booking Form |
| 141 |
// ------------------------------------------------------------------------------------------------------------- |
| 142 |
$html_form = ''; |
| 143 |
$skip_already_exist_field_types = array(); |
| 144 |
$exist_fields_arr = array(); |
| 145 |
|
| 146 |
if ( in_array( $booking_form_structure, array( 'wizard_2columns', 'wizard_services_a' ), true ) ) { |
| 147 |
|
| 148 |
$wizard_step_number = 1; |
| 149 |
|
| 150 |
$skip_already_exist_field_types[] = 'submit'; |
| 151 |
|
| 152 |
if ( 'wizard_services_a' === $booking_form_structure ) { |
| 153 |
// Add border form - class="wpbc_wizard__border_container". |
| 154 |
$html_form .= '<div class="wpbc_wizard__border_container">' . "\n"; |
| 155 |
} |
| 156 |
|
| 157 |
$html_form .= ' <div class="wpbc_wizard_step wpbc__form__div wpbc_wizard_step' . esc_attr( $wizard_step_number ) . '">' . "\n"; |
| 158 |
|
| 159 |
// Is 'durationtime' field exist ? |
| 160 |
$rangetime_field_arr = wpbc_simple_form__visual__get_one_field( $visual_form_structure, 'durationtime' ); |
| 161 |
$wizard_steps_count = ( ! empty( $rangetime_field_arr ) ) ? 3 : 2; |
| 162 |
// Timeline Step #1. |
| 163 |
if ( 'wizard_services_a' === $booking_form_structure ) { |
| 164 |
$html_form .= ' <r>' . "\n"; |
| 165 |
$html_form .= ' <c class="wpbc_aling_center"> ' . "\n"; |
| 166 |
$html_form .= ' [steps_timeline steps_count="' . esc_attr( $wizard_steps_count ) . '" active_step="' . esc_attr( $wizard_step_number ) . '"] ' . "\n"; |
| 167 |
$html_form .= ' </c>' . "\n"; |
| 168 |
$html_form .= ' </r>' . "\n"; |
| 169 |
} |
| 170 |
$html_form .= ' <r>' . "\n"; |
| 171 |
|
| 172 |
if ( ! empty( $rangetime_field_arr ) ) { |
| 173 |
|
| 174 |
$html_form .= ' <c class="wpbc_aling_center"> ' . "\n"; |
| 175 |
|
| 176 |
// Get HTML content of All Fields in booking form. |
| 177 |
list( $html_all_fields, $range_time_exist_fields_arr ) = wpbc_simple_form__get_shortcode_content_of_all_fields__and_fields_arr( |
| 178 |
array( |
| 179 |
'visual_form_structure' => array( $rangetime_field_arr ), |
| 180 |
'skip_already_exist_field_types' => array(), |
| 181 |
) |
| 182 |
); |
| 183 |
|
| 184 |
$html_form .= $html_all_fields; |
| 185 |
$html_form .= ' </c>' . "\n"; |
| 186 |
|
| 187 |
$skip_already_exist_field_types = array_merge( $skip_already_exist_field_types, $range_time_exist_fields_arr ); |
| 188 |
|
| 189 |
$html_form .= ' </r>' . "\n"; |
| 190 |
$html_form .= ' <hr><r>' . "\n"; |
| 191 |
$html_form .= ' <c style="justify-content: flex-end;">' . "\n"; |
| 192 |
$html_form .= ' <a class="wpbc_button_light wpbc_wizard_step_button wpbc_wizard_step_' . esc_attr( ( $wizard_step_number + 1 ) ) . '" >' . "\n"; |
| 193 |
$html_form .= ' ' . esc_attr__( 'Next', 'booking' ) . "\n"; |
| 194 |
$html_form .= ' </a>' . "\n"; |
| 195 |
$html_form .= ' </c>' . "\n"; |
| 196 |
$html_form .= ' </r>' . "\n"; |
| 197 |
$html_form .= ' </div>' . "\n"; |
| 198 |
++$wizard_step_number; |
| 199 |
$html_form .= ' <div class="wpbc_wizard_step wpbc__form__div wpbc_wizard_step' . esc_attr( $wizard_step_number ) . ' wpbc_wizard_step_hidden" style="display:none;clear:both;">' . "\n"; |
| 200 |
$html_form .= ' <r>' . "\n"; |
| 201 |
|
| 202 |
// Timeline Step #2. |
| 203 |
if ( 'wizard_services_a' === $booking_form_structure ) { |
| 204 |
$html_form .= ' <c class="wpbc_aling_center"> ' . "\n"; |
| 205 |
$html_form .= ' [steps_timeline steps_count="' . esc_attr( $wizard_steps_count ) . '" active_step="' . esc_attr( $wizard_step_number ) . '"] ' . "\n"; |
| 206 |
$html_form .= ' </c>' . "\n"; |
| 207 |
$html_form .= ' </r>' . "\n"; |
| 208 |
$html_form .= ' <r>' . "\n"; |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
$calendar_field_arr = wpbc_simple_form__visual__get_calendar( $visual_form_structure ); |
| 214 |
if ( ! empty( $calendar_field_arr ) ) { |
| 215 |
$html_form .= ' <c style="margin-top:0;"> ' . "\n"; |
| 216 |
// Get HTML content of All Fields in booking form. |
| 217 |
list( $html_all_fields, $calendar_exist_fields_arr ) = wpbc_simple_form__get_shortcode_content_of_all_fields__and_fields_arr( |
| 218 |
array( |
| 219 |
'visual_form_structure' => array( $calendar_field_arr ), |
| 220 |
'skip_already_exist_field_types' => array(), |
| 221 |
) |
| 222 |
); |
| 223 |
$html_form .= $html_all_fields; |
| 224 |
$html_form .= ' </c>' . "\n"; |
| 225 |
|
| 226 |
$skip_already_exist_field_types = array_merge( $skip_already_exist_field_types, $calendar_exist_fields_arr ); |
| 227 |
} else { |
| 228 |
$html_form .= ' <c> <l>Select Date:</l><br /> [calendar] </c>' . "\n"; |
| 229 |
$skip_already_exist_field_types[] = 'calendar'; |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
$time_field_arr = array( 'rangetime', 'starttime', 'endtime' ); |
| 234 |
foreach ( $time_field_arr as $time_field_name ) { |
| 235 |
$rangetime_field_arr = wpbc_simple_form__visual__get_one_field( $visual_form_structure, $time_field_name ); |
| 236 |
if ( ! empty( $rangetime_field_arr ) ) { |
| 237 |
|
| 238 |
$html_form .= ' <c style="margin-top:0;"> ' . "\n"; |
| 239 |
// Get HTML content of All Fields in booking form. |
| 240 |
list( $html_all_fields, $range_time_exist_fields_arr ) = wpbc_simple_form__get_shortcode_content_of_all_fields__and_fields_arr( |
| 241 |
array( |
| 242 |
'visual_form_structure' => array( $rangetime_field_arr ), |
| 243 |
'skip_already_exist_field_types' => array(), |
| 244 |
) |
| 245 |
); |
| 246 |
$html_form .= $html_all_fields; |
| 247 |
$html_form .= ' </c>' . "\n"; |
| 248 |
|
| 249 |
$skip_already_exist_field_types = array_merge( $skip_already_exist_field_types, $range_time_exist_fields_arr ); |
| 250 |
} |
| 251 |
} |
| 252 |
|
| 253 |
$html_form .= ' </r>' . "\n"; |
| 254 |
$html_form .= ' <hr><r style="flex-flow: row nowrap;">' . "\n"; |
| 255 |
if ( $wizard_step_number > 1 ) { |
| 256 |
$html_form .= ' <c style="justify-content: flex-start;">' . "\n"; |
| 257 |
$html_form .= ' <a class="wpbc_button_light wpbc_wizard_step_button wpbc_wizard_step_' . esc_attr( ( $wizard_step_number - 1 ) ) . '" >' . "\n"; |
| 258 |
$html_form .= ' ' . esc_attr__( 'Back', 'booking' ) . "\n"; |
| 259 |
$html_form .= ' </a>' . "\n"; |
| 260 |
$html_form .= ' </c>' . "\n"; |
| 261 |
} |
| 262 |
$html_form .= ' <c style="justify-content: flex-end;">' . "\n"; |
| 263 |
$html_form .= ' <a class="wpbc_button_light wpbc_wizard_step_button wpbc_wizard_step_' . esc_attr( ( $wizard_step_number + 1 ) ) . '" >' . "\n"; |
| 264 |
$html_form .= ' ' . esc_attr__( 'Next', 'booking' ) . "\n"; |
| 265 |
$html_form .= ' </a>' . "\n"; |
| 266 |
$html_form .= ' </c>' . "\n"; |
| 267 |
$html_form .= ' </r>' . "\n"; |
| 268 |
$html_form .= ' </div>' . "\n"; |
| 269 |
++$wizard_step_number; |
| 270 |
$html_form .= ' <div class="wpbc_wizard_step wpbc__form__div wpbc_wizard_step' . esc_attr( $wizard_step_number ) . ' wpbc_wizard_step_hidden" style="display:none;clear:both;">' . "\n"; |
| 271 |
// Timeline Step #3. |
| 272 |
if ( 'wizard_services_a' === $booking_form_structure ) { |
| 273 |
$html_form .= ' <r>' . "\n"; |
| 274 |
$html_form .= ' <c class="wpbc_aling_center"> ' . "\n"; |
| 275 |
$html_form .= ' [steps_timeline steps_count="' . esc_attr( $wizard_steps_count ) . '" active_step="' . esc_attr( $wizard_step_number ) . '"] ' . "\n"; |
| 276 |
$html_form .= ' </c>' . "\n"; |
| 277 |
$html_form .= ' </r>' . "\n"; |
| 278 |
} |
| 279 |
} |
| 280 |
|
| 281 |
|
| 282 |
if ( 'form_right' === $booking_form_structure ) { |
| 283 |
$html_form .= '<r>' . "\n"; |
| 284 |
$html_form .= ' <c>' . "\n"; |
| 285 |
$html_form .= ' [calendar]' . "\n"; |
| 286 |
$html_form .= ' </c>' . "\n"; |
| 287 |
$html_form .= ' <c>' . "\n"; |
| 288 |
|
| 289 |
$skip_already_exist_field_types[] = 'calendar'; |
| 290 |
} |
| 291 |
|
| 292 |
$html_form .= '<div class="wpbc__form__div">' . "\n"; |
| 293 |
|
| 294 |
// Get HTML content of All Fields in booking form. |
| 295 |
list( $html_all_fields, $exist_fields_arr ) = wpbc_simple_form__get_shortcode_content_of_all_fields__and_fields_arr( |
| 296 |
array( |
| 297 |
'visual_form_structure' => $visual_form_structure, |
| 298 |
'skip_already_exist_field_types' => $skip_already_exist_field_types, |
| 299 |
) |
| 300 |
); |
| 301 |
|
| 302 |
$exist_fields_arr = array_merge( $exist_fields_arr, $skip_already_exist_field_types ); |
| 303 |
$html_form .= $html_all_fields; |
| 304 |
|
| 305 |
|
| 306 |
// ------------------------------------------------------------------------------------------------------------- |
| 307 |
// Double recheck if these fields NOT exist. This double rechecking for MIGRATION period started on 2024-08-17. Later it can be removed |
| 308 |
// ------------------------------------------------------------------------------------------------------------- |
| 309 |
if ( ! in_array( 'calendar', $exist_fields_arr, true ) ) { |
| 310 |
$html_form = '[calendar]' . "\n" . $html_form; |
| 311 |
} |
| 312 |
// Captcha ?? |
| 313 |
if ( ( ! in_array( 'captcha', $exist_fields_arr, true ) ) && ( 'On' === get_bk_option( 'booking_is_use_captcha' ) ) ) { |
| 314 |
$html_form .= ' <spacer>height:10px;</spacer>' . "\n"; |
| 315 |
$html_form .= ' <r>' . "\n"; |
| 316 |
$html_form .= ' <c> [captcha] </c>' . "\n"; |
| 317 |
$html_form .= ' </r>' . "\n"; |
| 318 |
} |
| 319 |
// Submit ?? |
| 320 |
if ( ! in_array( 'submit', $exist_fields_arr, true ) ) { |
| 321 |
$submit_button_title = wpbc_simple_form__visual__get_send_button_title( $visual_form_structure ); |
| 322 |
$submit_button_title = str_replace( '"', '', html_entity_decode( esc_js( wpbc_lang( $submit_button_title ) ), ENT_QUOTES ) ); |
| 323 |
|
| 324 |
$html_form .= ' <r>' . "\n"; |
| 325 |
$html_form .= ' <c> <p>[submit class:btn "' . esc_attr( $submit_button_title ) . '"]</p> </c>' . "\n"; |
| 326 |
$html_form .= ' </r>' . "\n"; |
| 327 |
} |
| 328 |
// ------------------------------------------------------------------------------------------------------------- |
| 329 |
// - End - This double rechecking for MIGRATION period started on 2024-08-17. Later it can be removed |
| 330 |
// ------------------------------------------------------------------------------------------------------------- |
| 331 |
|
| 332 |
$html_form .= '</div>' . "\n"; |
| 333 |
|
| 334 |
// ------------------------------------------------------------------------------------------------------------- |
| 335 |
// == Booking Form :: Structure == |
| 336 |
// ------------------------------------------------------------------------------------------------------------- |
| 337 |
if ( 'form_right' === $booking_form_structure ) { |
| 338 |
$html_form .= ' </c>' . "\n"; |
| 339 |
$html_form .= ' </r>' . "\n"; |
| 340 |
} |
| 341 |
|
| 342 |
if ( in_array( $booking_form_structure, array( 'wizard_2columns', 'wizard_services_a' ), true ) ) { |
| 343 |
|
| 344 |
$html_form .= ' <hr><r style="flex-flow: row nowrap;">' . "\n"; |
| 345 |
$html_form .= ' <c style="justify-content: flex-start;">' . "\n"; |
| 346 |
$html_form .= ' <a class="wpbc_button_light wpbc_wizard_step_button wpbc_wizard_step_' . esc_attr( ( $wizard_step_number - 1 ) ) . '" >' . "\n"; |
| 347 |
$html_form .= ' ' . esc_attr__( 'Back', 'booking' ) . "\n"; |
| 348 |
$html_form .= ' </a>' . "\n"; |
| 349 |
$html_form .= ' </c>' . "\n"; |
| 350 |
$html_form .= ' <c style="justify-content: flex-end;">' . "\n"; |
| 351 |
|
| 352 |
$submit_button_title = ( ! empty( $booking_data__parsed_fields ) ) ? __( 'Change your Booking', 'booking' ) |
| 353 |
: wpbc_simple_form__visual__get_send_button_title( $visual_form_structure ); |
| 354 |
$submit_button_title = str_replace( '"', '', html_entity_decode( esc_js( wpbc_lang( $submit_button_title ) ), ENT_QUOTES ) ); |
| 355 |
$submit_button_title = wp_kses_post( $submit_button_title ); |
| 356 |
$html_form .= '[submit class:btn "' . esc_attr( $submit_button_title ) . '"]'; |
| 357 |
|
| 358 |
$html_form .= ' </c>' . "\n"; |
| 359 |
$html_form .= ' </r>' . "\n"; |
| 360 |
$html_form .= ' </div>' . "\n"; |
| 361 |
if ( 'wizard_services_a' === $booking_form_structure ) { |
| 362 |
$html_form .= '</div>' . "\n"; // Add border form - class="wpbc_wizard__border_container". |
| 363 |
} |
| 364 |
} |
| 365 |
|
| 366 |
|
| 367 |
$form_css_class_arr = array(); |
| 368 |
|
| 369 |
// Center Form. |
| 370 |
if ( 'form_center' === $booking_form_structure ) { |
| 371 |
$form_css_class_arr[] = 'wpbc_booking_form_structure'; |
| 372 |
$form_css_class_arr[] = 'wpbc_form_center'; |
| 373 |
} |
| 374 |
|
| 375 |
$html_form = '<div class="wpbc_booking_form_simple ' . implode( ' ', $form_css_class_arr ) . '">' . "\n" . $html_form . '</div>'; |
| 376 |
|
| 377 |
// Form Width. |
| 378 |
$form_layout_width = get_bk_option( 'booking_form_layout_width' ); |
| 379 |
$form_layout_width_px_pr = get_bk_option( 'booking_form_layout_width_px_pr' ); |
| 380 |
// FixIn: 10.7.1.6 .wpbc__field.wpbc_r_calendar to .wpbc__row.wpbc_r_calendar . |
| 381 |
$html_form_style = ''; |
| 382 |
if ( ! wpbc_is_this_demo() ) { |
| 383 |
$html_form_style = '<style type="text/css">.wpbc_container_booking_form .block_hints, .wpbc_booking_form_simple.wpbc_form_center .wpbc__form__div .wpbc__row.wpbc_r_calendar, .wpbc_booking_form_simple .wpbc__form__div .wpbc__row:not(.wpbc_r_calendar){max-width:' . $form_layout_width . $form_layout_width_px_pr . ';} </style>' . "\n"; |
| 384 |
} |
| 385 |
$html_form = $html_form_style . $html_form; |
| 386 |
|
| 387 |
return $html_form; |
| 388 |
} |
| 389 |
|
| 390 |
// ------------------------------------------------------------------------------------------------------------- |
| 391 |
// -> PAID. When works in paid version in simple mode, system get data from here |
| 392 |
// ------------------------------------------------------------------------------------------------------------- |
| 393 |
|
| 394 |
/** |
| 395 |
* Get SHORTCODES Content of ALL booking form fields and exist field names in this booking form |
| 396 |
* |
| 397 |
* @param $params array( |
| 398 |
* 'visual_form_structure' => wpbc_simple_form__db__get_visual_form_structure(), |
| 399 |
* 'skip_already_exist_field_types' => array(), // field TYPES, like 'calendar', which we need to skip |
| 400 |
* ) |
| 401 |
* |
| 402 |
* @return array // array( $html_form, $exist_fields_arr ) |
| 403 |
*/ |
| 404 |
function wpbc_simple_form__get_shortcode_content_of_all_fields__and_fields_arr( $params ){ |
| 405 |
|
| 406 |
$defaults = array( |
| 407 |
'visual_form_structure' => wpbc_simple_form__db__get_visual_form_structure(), |
| 408 |
'skip_already_exist_field_types' => array(), // field TYPES, like 'calendar', which we need to skip |
| 409 |
); |
| 410 |
$params = wp_parse_args( $params, $defaults ); |
| 411 |
|
| 412 |
$skip_already_exist_field_types = $params['skip_already_exist_field_types']; |
| 413 |
|
| 414 |
$exist_fields_arr = array(); |
| 415 |
$html_form = ''; |
| 416 |
|
| 417 |
// FixIn: 10.7.1.6. |
| 418 |
$rows_arr = array(); // All rows |
| 419 |
$curr_row_num = 0; // Current row number |
| 420 |
$max_col = max( intval( get_bk_option( 'booking_form_layout_max_cols' ) ), 1 ); // Maximum number of columns |
| 421 |
|
| 422 |
// Fields |
| 423 |
foreach ( $params['visual_form_structure'] as $key => $form_field ) { |
| 424 |
|
| 425 |
$defaults = array( |
| 426 |
'type' => 'text' |
| 427 |
, 'name' => 'unique_name' |
| 428 |
, 'obligatory' => 'Off' |
| 429 |
, 'active' => 'On' |
| 430 |
, 'required' => 'Off' |
| 431 |
, 'label' => '' |
| 432 |
, 'value' => '' |
| 433 |
); |
| 434 |
$form_field = wp_parse_args( $form_field, $defaults ); |
| 435 |
|
| 436 |
if ( |
| 437 |
( ! in_array( $form_field['type'], $skip_already_exist_field_types ) ) && |
| 438 |
( ! in_array( $form_field['name'], $skip_already_exist_field_types ) ) && |
| 439 |
( ( $form_field['active'] != 'Off' ) || ( $form_field['obligatory'] == 'On' ) ) |
| 440 |
) { |
| 441 |
|
| 442 |
if ( in_array( $form_field['type'], array( 'calendar', 'captcha', 'submit' ) ) ) { |
| 443 |
$exist_fields_arr[] = $form_field['type']; |
| 444 |
} else { |
| 445 |
$exist_fields_arr[] = $form_field['name']; |
| 446 |
} |
| 447 |
|
| 448 |
$field_css_class = 'wpbc_r_' . $exist_fields_arr[ count( $exist_fields_arr ) - 1 ]; |
| 449 |
// $html_form .= ' <r>' . "\n"; // FixIn: 10.7.1.6. |
| 450 |
$html_form .= ' <c class="' . esc_attr( $field_css_class ) . '">'; // FixIn: 10.7.1.6. |
| 451 |
|
| 452 |
// ----------------------------------------------------------------------------------------------------- |
| 453 |
// L abel |
| 454 |
// ----------------------------------------------------------------------------------------------------- |
| 455 |
$form_field['label'] = wpbc_lang( $form_field['label'] ); |
| 456 |
if ( function_exists( 'icl_translate' ) ) { // WPML |
| 457 |
$form_field['label'] = icl_translate( 'wpml_custom', 'wpbc_custom_form_field_label_' . $form_field['name'], $form_field['label'] ); |
| 458 |
} |
| 459 |
|
| 460 |
if ( ( 'checkbox' !== $form_field['type'] ) && ( 'submit' !== $form_field['type'] ) ) { |
| 461 |
$html_form .= ' <l>' . $form_field['label'] . ( ( ! empty( $form_field['label'] ) ) |
| 462 |
? ( ( 'On' === $form_field['required'] ) ? '*' : '' ) // FixIn: 10.9.6.2. |
| 463 |
: '' ) . '</l><br>'; |
| 464 |
} |
| 465 |
|
| 466 |
// ----------------------------------------------------------------------------------------------------- |
| 467 |
// Field Shortcode |
| 468 |
// ----------------------------------------------------------------------------------------------------- |
| 469 |
|
| 470 |
if ( $form_field['type'] == 'calendar' ) { |
| 471 |
$html_form .= '[calendar]'; |
| 472 |
} |
| 473 |
|
| 474 |
if ( $form_field['type'] == 'captcha' ){ |
| 475 |
$html_form .= '[captcha]'; |
| 476 |
} |
| 477 |
|
| 478 |
if ( $form_field['type'] == 'submit' ) { |
| 479 |
$submit_button_title = str_replace( '"', '', html_entity_decode( esc_js( $form_field['label'] ) ) ); |
| 480 |
$html_form .= '[submit class:btn "' . esc_attr( $submit_button_title ) . '"]'; |
| 481 |
} |
| 482 |
|
| 483 |
|
| 484 |
if ( $form_field['type'] == 'text' ) { // Text |
| 485 |
$html_form .= '[text' |
| 486 |
. ( ( $form_field['required'] == 'On' ) ? '*' : '' ) |
| 487 |
. ' '. $form_field['name'] |
| 488 |
.']'; |
| 489 |
} |
| 490 |
|
| 491 |
if ( $form_field['type'] == 'email' ){ // Email |
| 492 |
$html_form .= '[email' |
| 493 |
. ( ( $form_field['required'] == 'On' ) ? '*' : '' ) |
| 494 |
. ' '. $form_field['name'] |
| 495 |
.']'; |
| 496 |
} |
| 497 |
|
| 498 |
if ( ( $form_field['type'] == 'selectbox' ) || ( $form_field['type'] == 'select' ) ){ // Select |
| 499 |
$html_form .= '[selectbox' |
| 500 |
. ( ( $form_field['required'] == 'On' ) ? '*' : '' ) |
| 501 |
. ' '. $form_field['name']; |
| 502 |
|
| 503 |
$form_field['value'] = preg_split( '/\r\n|\r|\n/', $form_field['value'] ); |
| 504 |
foreach ($form_field['value'] as $select_option) { |
| 505 |
|
| 506 |
$select_option = str_replace(array("'",'"'), '', $select_option); |
| 507 |
|
| 508 |
$html_form.=' "' . $select_option . '"'; |
| 509 |
} |
| 510 |
|
| 511 |
$html_form .= ']'; |
| 512 |
} |
| 513 |
|
| 514 |
if ( $form_field['type'] == 'textarea' ){ // Textarea |
| 515 |
$html_form .= '[textarea' |
| 516 |
. ( ( $form_field['required'] == 'On' ) ? '*' : '' ) |
| 517 |
. ' '. $form_field['name'] |
| 518 |
.']'; |
| 519 |
} |
| 520 |
|
| 521 |
if ( $form_field['type'] == 'checkbox' ) { // Checkbox |
| 522 |
$html_form .= '[checkbox' |
| 523 |
. ( ( $form_field['required'] == 'On' ) ? '*' : '' ) |
| 524 |
. ' '. $form_field['name']; |
| 525 |
$html_form .= ' use_label_element'; |
| 526 |
$html_form .= ' "' . str_replace( array('"', "'"), '', $form_field['label'] ) .'"]'; |
| 527 |
} |
| 528 |
|
| 529 |
$html_form .= ' </c>' . "\n"; |
| 530 |
// $html_form .= ' </r>' . "\n"; // FixIn: 10.7.1.6. |
| 531 |
|
| 532 |
|
| 533 |
// ------------------------------------------------------------------------------------------------- |
| 534 |
// Set content by columns |
| 535 |
// ------------------------------------------------------------------------------------------------- |
| 536 |
// FixIn: 10.7.1.6. |
| 537 |
if ( ! isset( $rows_arr[ $curr_row_num ] ) ) { |
| 538 |
$rows_arr[ $curr_row_num ] = array(); |
| 539 |
} |
| 540 |
if ( |
| 541 |
( count( $rows_arr[ $curr_row_num ] ) >= $max_col ) |
| 542 |
|| ( in_array( $form_field['type'],array( 'textarea', 'calendar', 'submit' ) ) ) |
| 543 |
|| ( ( in_array( $form_field['name'], array( 'rangetime' ) ) ) && ( 'On' === get_bk_option( 'booking_timeslot_picker' ) ) ) |
| 544 |
){ |
| 545 |
$curr_row_num++; |
| 546 |
$rows_arr[ $curr_row_num ] = array(); |
| 547 |
} |
| 548 |
// ---------------------------------------------- |
| 549 |
$rows_arr[ $curr_row_num ][] = $html_form; |
| 550 |
$html_form = ''; |
| 551 |
// ---------------------------------------------- |
| 552 |
if( |
| 553 |
( in_array( $form_field['type'],array( 'textarea', 'calendar', 'submit' ) ) ) |
| 554 |
|| ( ( in_array( $form_field['name'], array( 'rangetime' ) ) ) && ( 'On' === get_bk_option( 'booking_timeslot_picker' ) ) ) |
| 555 |
){ |
| 556 |
$curr_row_num++; |
| 557 |
$rows_arr[ $curr_row_num ] = array(); |
| 558 |
} |
| 559 |
// ------------------------------------------------------------------------------------------------- |
| 560 |
|
| 561 |
} //active if |
| 562 |
} //loop |
| 563 |
|
| 564 |
|
| 565 |
$html_form = ''; |
| 566 |
foreach ( $rows_arr as $colls_arr ) { |
| 567 |
$columns_html = implode( "\n", $colls_arr ); |
| 568 |
if ( empty( $columns_html ) ) { |
| 569 |
continue; |
| 570 |
} |
| 571 |
$html_form .= ( false !== strpos( $columns_html, '[calendar]' ) ) |
| 572 |
? ' <r class="wpbc_r_calendar">' . "\n" |
| 573 |
: ' <r>' . "\n"; |
| 574 |
$html_form .= $columns_html; |
| 575 |
$html_form .= ' </r>' . "\n"; |
| 576 |
} |
| 577 |
|
| 578 |
|
| 579 |
return array( $html_form, $exist_fields_arr ); |
| 580 |
} |
| 581 |
|
| 582 |
|
| 583 |
/** |
| 584 |
* Get HTML of booking form based on Visual Structure. This func. for pure FREE version - getting HTML content of booking form. |
| 585 |
* Get booking form in HTML in Free version |
| 586 |
* |
| 587 |
* @param $resource_id |
| 588 |
* |
| 589 |
* @return array|mixed|string|string[] |
| 590 |
*/ |
| 591 |
function wpbc_simple_form__get_booking_form__as_html( $resource_id = 1, $custom_booking_form = 'standard', $custom_params = array() ) { |
| 592 |
|
| 593 |
$booking_data__parsed_fields = array(); |
| 594 |
$booking_data__dates = array(); |
| 595 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 596 |
if ( isset( $_GET['booking_hash'] ) ) { |
| 597 |
|
| 598 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing /* FixIn: sanitize_unslash */ |
| 599 |
$get_booking_hash = ( ( isset( $_GET['booking_hash'] ) ) ? sanitize_text_field( wp_unslash( $_GET['booking_hash'] ) ) : '' ); |
| 600 |
|
| 601 |
$booking_id__resource_id = wpbc_hash__get_booking_id__resource_id( $get_booking_hash ); |
| 602 |
|
| 603 |
if ( false !== $booking_id__resource_id ) { |
| 604 |
$booking_data = wpbc_search_booking_by_id( $booking_id__resource_id[0] ); |
| 605 |
if ( false !== $booking_data ) { |
| 606 |
$booking_data__parsed_fields = $booking_data->parsed_fields; |
| 607 |
$booking_data__dates = $booking_data->dates; |
| 608 |
} |
| 609 |
} |
| 610 |
} |
| 611 |
|
| 612 |
$visual_form_structure = wpbc_simple_form__db__get_visual_form_structure( $custom_booking_form ); |
| 613 |
|
| 614 |
$booking_form_structure = get_bk_option( 'booking_form_structure_type' ); |
| 615 |
if ( empty( $booking_form_structure ) ) { |
| 616 |
$booking_form_structure = 'vertical'; |
| 617 |
} |
| 618 |
|
| 619 |
// ------------------------------------------------------------------------------------------------------------- |
| 620 |
// Booking Form |
| 621 |
// ------------------------------------------------------------------------------------------------------------- |
| 622 |
$html_form = ''; |
| 623 |
|
| 624 |
$skip_already_exist_field_types = array(); |
| 625 |
|
| 626 |
// FixIn: 10.7.1.7. |
| 627 |
if ( in_array( $booking_form_structure, array( 'wizard_2columns', 'wizard_services_a' ), true ) ) { |
| 628 |
|
| 629 |
$wizard_step_number = 1; |
| 630 |
|
| 631 |
$skip_already_exist_field_types[] = 'submit'; |
| 632 |
|
| 633 |
if ( 'wizard_services_a' === $booking_form_structure ) { |
| 634 |
// Add border form - class="wpbc_wizard__border_container". |
| 635 |
$html_form .= '<div class="wpbc_wizard__border_container">' . "\n"; |
| 636 |
} |
| 637 |
|
| 638 |
$html_form .= ' <div class="wpbc_wizard_step wpbc__form__div wpbc_wizard_step' . esc_attr( $wizard_step_number ) . '">' . "\n"; |
| 639 |
|
| 640 |
// Is 'durationtime' field exist ? |
| 641 |
$rangetime_field_arr = wpbc_simple_form__visual__get_one_field( $visual_form_structure, 'durationtime' ); |
| 642 |
$wizard_steps_count = ( ! empty( $rangetime_field_arr ) ) ? 3 : 2; |
| 643 |
// Timeline Step #1. |
| 644 |
if ( 'wizard_services_a' === $booking_form_structure ) { |
| 645 |
$html_form .= ' <r>' . "\n"; |
| 646 |
$html_form .= ' <c class="wpbc_aling_center"> ' . "\n"; |
| 647 |
$html_form .= ' [steps_timeline steps_count="' . esc_attr( $wizard_steps_count ) . '" active_step="' . esc_attr( $wizard_step_number ) . '"] ' . "\n"; |
| 648 |
$html_form .= ' </c>' . "\n"; |
| 649 |
$html_form .= ' </r>' . "\n"; |
| 650 |
} |
| 651 |
$html_form .= ' <r>' . "\n"; |
| 652 |
|
| 653 |
if ( ! empty( $rangetime_field_arr ) ) { |
| 654 |
|
| 655 |
$html_form .= ' <c class="wpbc_aling_center"> ' . "\n"; |
| 656 |
|
| 657 |
// Get HTML content of All Fields in booking form. |
| 658 |
list( $html_all_fields, $range_time_exist_fields_arr ) = wpbc_simple_form__get_html_content_of_all_fields__and_fields_arr( |
| 659 |
array( |
| 660 |
'visual_form_structure' => array( $rangetime_field_arr ), |
| 661 |
'skip_already_exist_field_types' => $skip_already_exist_field_types, |
| 662 |
'resource_id' => $resource_id, |
| 663 |
'booking_data__parsed_fields' => $booking_data__parsed_fields, |
| 664 |
) |
| 665 |
); |
| 666 |
$html_form .= $html_all_fields; |
| 667 |
$html_form .= ' </c>' . "\n"; |
| 668 |
|
| 669 |
$skip_already_exist_field_types = array_merge( $skip_already_exist_field_types, $range_time_exist_fields_arr ); |
| 670 |
|
| 671 |
$html_form .= ' </r>' . "\n"; |
| 672 |
$html_form .= ' <hr><r>' . "\n"; |
| 673 |
$html_form .= ' <c style="justify-content: flex-end;">' . "\n"; |
| 674 |
$html_form .= ' <a class="wpbc_button_light wpbc_wizard_step_button wpbc_wizard_step_' . esc_attr( ( $wizard_step_number + 1 ) ) . '" >' . "\n"; |
| 675 |
$html_form .= ' ' . esc_attr__( 'Next', 'booking' ) . "\n"; |
| 676 |
$html_form .= ' </a>' . "\n"; |
| 677 |
$html_form .= ' </c>' . "\n"; |
| 678 |
$html_form .= ' </r>' . "\n"; |
| 679 |
$html_form .= ' </div>' . "\n"; |
| 680 |
++$wizard_step_number; |
| 681 |
$html_form .= ' <div class="wpbc_wizard_step wpbc__form__div wpbc_wizard_step' . esc_attr( ( $wizard_step_number ) ) . ' wpbc_wizard_step_hidden" style="display:none;clear:both;">' . "\n"; |
| 682 |
$html_form .= ' <r>' . "\n"; |
| 683 |
|
| 684 |
// Timeline Step #2. |
| 685 |
if ( 'wizard_services_a' === $booking_form_structure ) { |
| 686 |
$html_form .= ' <c class="wpbc_aling_center"> ' . "\n"; |
| 687 |
$html_form .= ' [steps_timeline steps_count="' . esc_attr( $wizard_steps_count ) . '" active_step="' . esc_attr( $wizard_step_number ) . '"] ' . "\n"; |
| 688 |
$html_form .= ' </c>' . "\n"; |
| 689 |
$html_form .= ' </r>' . "\n"; |
| 690 |
$html_form .= ' <r>' . "\n"; |
| 691 |
} |
| 692 |
} |
| 693 |
|
| 694 |
$calendar_field_arr = wpbc_simple_form__visual__get_calendar( $visual_form_structure ); |
| 695 |
if ( ! empty( $calendar_field_arr ) ) { |
| 696 |
$html_form .= ' <c style="margin-top:0;"> ' . "\n"; |
| 697 |
// Get HTML content of All Fields in booking form. |
| 698 |
list( $html_all_fields, $calendar_exist_fields_arr ) = wpbc_simple_form__get_html_content_of_all_fields__and_fields_arr( |
| 699 |
array( |
| 700 |
'visual_form_structure' => array( $calendar_field_arr ), |
| 701 |
'skip_already_exist_field_types' => $skip_already_exist_field_types, |
| 702 |
'resource_id' => $resource_id, |
| 703 |
'booking_data__parsed_fields' => $booking_data__parsed_fields, |
| 704 |
) |
| 705 |
); |
| 706 |
$html_form .= $html_all_fields; |
| 707 |
$html_form .= ' </c>' . "\n"; |
| 708 |
|
| 709 |
$skip_already_exist_field_types = array_merge( $skip_already_exist_field_types, $calendar_exist_fields_arr ); |
| 710 |
} else { |
| 711 |
$html_form .= ' <c> <l>Select Date:</l><br /> [calendar] </c>' . "\n"; |
| 712 |
$skip_already_exist_field_types[] = 'calendar'; |
| 713 |
} |
| 714 |
|
| 715 |
|
| 716 |
$time_field_arr = array( 'rangetime', 'starttime', 'endtime' ); |
| 717 |
foreach ( $time_field_arr as $time_field_name ) { |
| 718 |
$rangetime_field_arr = wpbc_simple_form__visual__get_one_field( $visual_form_structure, $time_field_name ); |
| 719 |
if ( ! empty( $rangetime_field_arr ) ) { |
| 720 |
|
| 721 |
$html_form .= ' <c style="margin-top:0;"> ' . "\n"; |
| 722 |
// Get HTML content of All Fields in booking form. |
| 723 |
list( $html_all_fields, $range_time_exist_fields_arr ) = wpbc_simple_form__get_html_content_of_all_fields__and_fields_arr( |
| 724 |
array( |
| 725 |
'visual_form_structure' => array( $rangetime_field_arr ), |
| 726 |
'skip_already_exist_field_types' => $skip_already_exist_field_types, |
| 727 |
'resource_id' => $resource_id, |
| 728 |
'booking_data__parsed_fields' => $booking_data__parsed_fields, |
| 729 |
) |
| 730 |
); |
| 731 |
$html_form .= $html_all_fields; |
| 732 |
$html_form .= ' </c>' . "\n"; |
| 733 |
|
| 734 |
$skip_already_exist_field_types = array_merge( $skip_already_exist_field_types, $range_time_exist_fields_arr ); |
| 735 |
} |
| 736 |
} |
| 737 |
|
| 738 |
$html_form .= ' </r>' . "\n"; |
| 739 |
$html_form .= ' <hr><r style="flex-flow: row nowrap;">' . "\n"; |
| 740 |
if ( $wizard_step_number > 1 ) { |
| 741 |
$html_form .= ' <c style="justify-content: flex-start;">' . "\n"; |
| 742 |
$html_form .= ' <a class="wpbc_button_light wpbc_wizard_step_button wpbc_wizard_step_' . esc_attr( ( $wizard_step_number - 1 ) ) . '" >' . "\n"; |
| 743 |
$html_form .= ' ' . esc_attr__( 'Back', 'booking' ) . "\n"; |
| 744 |
$html_form .= ' </a>' . "\n"; |
| 745 |
$html_form .= ' </c>' . "\n"; |
| 746 |
} |
| 747 |
$html_form .= ' <c style="justify-content: flex-end;">' . "\n"; |
| 748 |
$html_form .= ' <a class="wpbc_button_light wpbc_wizard_step_button wpbc_wizard_step_' . esc_attr( ( $wizard_step_number + 1 ) ) . '" >' . "\n"; |
| 749 |
$html_form .= ' ' . esc_attr__( 'Next', 'booking' ) . "\n"; |
| 750 |
$html_form .= ' </a>' . "\n"; |
| 751 |
$html_form .= ' </c>' . "\n"; |
| 752 |
$html_form .= ' </r>' . "\n"; |
| 753 |
$html_form .= ' </div>' . "\n"; |
| 754 |
++$wizard_step_number; |
| 755 |
$html_form .= ' <div class="wpbc_wizard_step wpbc__form__div wpbc_wizard_step' . esc_attr( ( $wizard_step_number ) ) . ' wpbc_wizard_step_hidden" style="display:none;clear:both;">' . "\n"; |
| 756 |
// Timeline Step #3. |
| 757 |
if ( 'wizard_services_a' === $booking_form_structure ) { |
| 758 |
$html_form .= ' <r>' . "\n"; |
| 759 |
$html_form .= ' <c class="wpbc_aling_center"> ' . "\n"; |
| 760 |
$html_form .= ' [steps_timeline steps_count="' . esc_attr( $wizard_steps_count ) . '" active_step="' . esc_attr( $wizard_step_number ) . '"] ' . "\n"; |
| 761 |
$html_form .= ' </c>' . "\n"; |
| 762 |
$html_form .= ' </r>' . "\n"; |
| 763 |
} |
| 764 |
} |
| 765 |
|
| 766 |
if ( 'form_right' === $booking_form_structure ) { |
| 767 |
$html_form .= '<r>' . "\n"; |
| 768 |
$html_form .= ' <c>' . "\n"; |
| 769 |
$html_form .= ' [calendar]' . "\n"; |
| 770 |
$html_form .= ' </c>' . "\n"; |
| 771 |
$html_form .= ' <c>' . "\n"; |
| 772 |
|
| 773 |
$skip_already_exist_field_types[] = 'calendar'; |
| 774 |
} |
| 775 |
$html_form .= ' <div class="wpbc__form__div">' . "\n"; |
| 776 |
|
| 777 |
|
| 778 |
// Get HTML content of All Fields in booking form. |
| 779 |
list( $html_all_fields, $exist_fields_arr ) = wpbc_simple_form__get_html_content_of_all_fields__and_fields_arr( |
| 780 |
array( |
| 781 |
'visual_form_structure' => $visual_form_structure, |
| 782 |
'skip_already_exist_field_types' => $skip_already_exist_field_types, |
| 783 |
'resource_id' => $resource_id, |
| 784 |
'booking_data__parsed_fields' => $booking_data__parsed_fields, |
| 785 |
) |
| 786 |
); |
| 787 |
$exist_fields_arr = array_merge( $exist_fields_arr, $skip_already_exist_field_types ); |
| 788 |
$html_form .= $html_all_fields; |
| 789 |
|
| 790 |
// ------------------------------------------------------------------------------------------------------------- |
| 791 |
// Double recheck if these fields NOT exist. This double rechecking for MIGRATION period started on 2024-08-17. Later it can be removed |
| 792 |
// ------------------------------------------------------------------------------------------------------------- |
| 793 |
if ( ! in_array( 'calendar', $exist_fields_arr ) ) { |
| 794 |
$html_form = '[calendar]' . "\n" . $html_form; |
| 795 |
} |
| 796 |
// Captcha ?? |
| 797 |
if ( ( ! in_array( 'captcha', $exist_fields_arr ) ) && ( get_bk_option( 'booking_is_use_captcha' ) == 'On' ) ) { |
| 798 |
$html_form .= ' <spacer>height:10px;</spacer>' . "\n"; |
| 799 |
$html_form .= ' <r>' . "\n"; |
| 800 |
$html_form .= ' <c> [captcha] </c>' . "\n"; |
| 801 |
$html_form .= ' </r>' . "\n"; |
| 802 |
} |
| 803 |
// Submit ?? |
| 804 |
if ( ! in_array( 'submit', $exist_fields_arr ) ) { |
| 805 |
|
| 806 |
$submit_button_title = ( ! empty( $booking_data__parsed_fields ) ) ? __( 'Change your Booking', 'booking' ) |
| 807 |
: wpbc_simple_form__visual__get_send_button_title( $visual_form_structure ); |
| 808 |
|
| 809 |
$submit_button_title = str_replace( '"', '', html_entity_decode( esc_js( wpbc_lang( $submit_button_title ) ), ENT_QUOTES ) ); |
| 810 |
$submit_button_title = wp_kses_post( $submit_button_title ); // FixIn: 10.6.5.2. |
| 811 |
|
| 812 |
$html_form .= ' <r>' . "\n"; |
| 813 |
$html_form .= ' <c> <p>'; |
| 814 |
$html_form .= '<button class="wpbc_button_light" type="button" onclick="wpbc_booking_form_submit(this.form,' . $resource_id . ',\'' . wpbc_get_maybe_reloaded_booking_locale() . '\');" >' . $submit_button_title . '</button>'; |
| 815 |
$html_form .= '</p> </c>' . "\n"; |
| 816 |
$html_form .= ' </r>' . "\n"; |
| 817 |
} |
| 818 |
// ------------------------------------------------------------------------------------------------------------- |
| 819 |
// - End - This double rechecking for MIGRATION period started on 2024-08-17. Later it can be removed |
| 820 |
// ------------------------------------------------------------------------------------------------------------- |
| 821 |
|
| 822 |
|
| 823 |
$html_form .= ' </div>' . "\n"; |
| 824 |
|
| 825 |
if ( 'form_right' === $booking_form_structure ) { |
| 826 |
$html_form .= ' </c>' . "\n"; |
| 827 |
$html_form .= '</r>' . "\n"; |
| 828 |
} |
| 829 |
|
| 830 |
if ( in_array( $booking_form_structure, array( 'wizard_2columns', 'wizard_services_a' ), true ) ) { |
| 831 |
$html_form .= ' <hr><r style="flex-flow: row nowrap;">' . "\n"; |
| 832 |
$html_form .= ' <c style="justify-content: flex-start;">' . "\n"; |
| 833 |
$html_form .= ' <a class="wpbc_button_light wpbc_wizard_step_button wpbc_wizard_step_' . esc_attr( ( $wizard_step_number - 1 ) ) . '" >' . "\n"; |
| 834 |
$html_form .= ' ' . esc_attr__( 'Back', 'booking' ) . "\n"; |
| 835 |
$html_form .= ' </a>' . "\n"; |
| 836 |
$html_form .= ' </c>' . "\n"; |
| 837 |
$html_form .= ' <c style="justify-content: flex-end;">' . "\n"; |
| 838 |
|
| 839 |
$submit_button_title = ( ! empty( $booking_data__parsed_fields ) ) ? __( 'Change your Booking', 'booking' ) : wpbc_simple_form__visual__get_send_button_title( $visual_form_structure ); |
| 840 |
$submit_button_title = str_replace( '"', '', html_entity_decode( esc_js( wpbc_lang( $submit_button_title ) ), ENT_QUOTES ) ); |
| 841 |
$submit_button_title = wp_kses_post( $submit_button_title ); |
| 842 |
|
| 843 |
$html_form .= ' <button class="wpbc_button_light" type="button" onclick="wpbc_booking_form_submit(this.form,' . $resource_id . ',\'' . wpbc_get_maybe_reloaded_booking_locale() . '\');" >' . $submit_button_title . '</button>'; |
| 844 |
$html_form .= ' </c>' . "\n"; |
| 845 |
$html_form .= ' </r>' . "\n"; |
| 846 |
$html_form .= ' </div>' . "\n"; |
| 847 |
if ( 'wizard_services_a' === $booking_form_structure ) { |
| 848 |
$html_form .= '</div>' . "\n"; // Add border form - class="wpbc_wizard__border_container". |
| 849 |
} |
| 850 |
} |
| 851 |
|
| 852 |
// ------------------------------------------------------------------------------------------------------------- |
| 853 |
// == Booking Form :: Structure == |
| 854 |
// ------------------------------------------------------------------------------------------------------------- |
| 855 |
$form_css_class_arr = array(); |
| 856 |
|
| 857 |
// Center Form. |
| 858 |
if ( 'form_center' === $booking_form_structure ) { |
| 859 |
$form_css_class_arr[] = 'wpbc_booking_form_structure'; |
| 860 |
$form_css_class_arr[] = 'wpbc_form_center'; |
| 861 |
} |
| 862 |
$html_form = '<div class="wpbc_booking_form_simple ' . implode( ' ', $form_css_class_arr ) . '">' . "\n" . $html_form . '</div>'; |
| 863 |
|
| 864 |
// Form Width. |
| 865 |
$form_layout_width = get_bk_option( 'booking_form_layout_width' ); |
| 866 |
$form_layout_width_px_pr = get_bk_option( 'booking_form_layout_width_px_pr' ); |
| 867 |
// FixIn: 10.7.1.6 .wpbc__field.wpbc_r_calendar to .wpbc__row.wpbc_r_calendar . |
| 868 |
$html_form_style = ''; |
| 869 |
if ( ! wpbc_is_this_demo() ) { |
| 870 |
$html_form_style = '<style type="text/css">.wpbc_container_booking_form .block_hints, .wpbc_booking_form_simple.wpbc_form_center .wpbc__form__div .wpbc__row.wpbc_r_calendar, .wpbc_booking_form_simple .wpbc__form__div .wpbc__row:not(.wpbc_r_calendar){max-width:' . $form_layout_width . $form_layout_width_px_pr . ';} </style>' . "\n"; |
| 871 |
} |
| 872 |
$html_form = $html_form_style . $html_form; |
| 873 |
|
| 874 |
if ( ! empty( $booking_data__dates ) ) { |
| 875 |
$html_form .= wpbc_get_dates_selection_js_code( $booking_data__dates, $resource_id ); // FixIn: 9.2.3.4. |
| 876 |
} |
| 877 |
|
| 878 |
$admin_uri = ltrim( str_replace( get_site_url( null, '', 'admin' ), '', admin_url( 'admin.php?' ) ), '/' ); |
| 879 |
$server_request_uri = ( ( isset( $_SERVER['REQUEST_URI'] ) ) ? sanitize_text_field( $_SERVER['REQUEST_URI'] ) : '' ); /* phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash */ /* FixIn: sanitize_unslash */ |
| 880 |
$server_http_referer_uri = ( ( isset( $_SERVER['HTTP_REFERER'] ) ) ? sanitize_text_field( $_SERVER['HTTP_REFERER'] ) : '' ); /* phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash */ /* FixIn: sanitize_unslash */ |
| 881 |
if ( ( strpos( $server_request_uri, $admin_uri ) !== false ) && ( isset( $server_http_referer_uri ) ) ) { |
| 882 |
$html_form .= '<input type="hidden" name="wpdev_http_referer" id="wpdev_http_referer" value="' . $server_http_referer_uri . '" />'; |
| 883 |
} |
| 884 |
|
| 885 |
// Parse Simple HTML tags. |
| 886 |
$booking_form = wpbc_bf__replace_custom_html_shortcodes( $html_form ); |
| 887 |
|
| 888 |
return $booking_form; |
| 889 |
} |
| 890 |
|
| 891 |
|
| 892 |
// ------------------------------------------------------------------------------------------------------------- |
| 893 |
// -> FREE. When works in free version in simple mode, system get data from here |
| 894 |
// ------------------------------------------------------------------------------------------------------------- |
| 895 |
|
| 896 |
/** |
| 897 |
* Get HTML Content of booking form fields and exist field names in this booking form |
| 898 |
* |
| 899 |
* @param $params array( |
| 900 |
* 'visual_form_structure' => wpbc_simple_form__db__get_visual_form_structure(), |
| 901 |
* 'skip_already_exist_field_types' => array(), // field TYPES, like 'calendar', which we need to skip |
| 902 |
* 'resource_id' => 1, |
| 903 |
* 'booking_data__parsed_fields' => array() // It is $booking_data->parsed_fields; in case if we edit the booking form, otherwise array() |
| 904 |
* ) |
| 905 |
* |
| 906 |
* @return array // array( $html_form, $exist_fields_arr ) |
| 907 |
*/ |
| 908 |
function wpbc_simple_form__get_html_content_of_all_fields__and_fields_arr( $params ) { |
| 909 |
|
| 910 |
$defaults = array( |
| 911 |
'visual_form_structure' => wpbc_simple_form__db__get_visual_form_structure(), |
| 912 |
'skip_already_exist_field_types' => array(), // field TYPES, like 'calendar', which we need to skip |
| 913 |
'resource_id' => 1, |
| 914 |
'booking_data__parsed_fields' => array() // It is $booking_data->parsed_fields; in case if we edit the booking form, otherwise array() |
| 915 |
); |
| 916 |
$params = wp_parse_args( $params, $defaults ); |
| 917 |
|
| 918 |
|
| 919 |
$exist_fields_arr = array(); |
| 920 |
$html_form = ''; |
| 921 |
|
| 922 |
// FixIn: 10.7.1.6. |
| 923 |
$rows_arr = array(); // All rows |
| 924 |
$curr_row_num = 0; // Current row number |
| 925 |
$max_col = max( intval( get_bk_option( 'booking_form_layout_max_cols' ) ), 1 ); // Maximum number of columns |
| 926 |
|
| 927 |
// Fields |
| 928 |
foreach ( $params['visual_form_structure'] as $key => $form_field ) { |
| 929 |
|
| 930 |
$defaults = array( |
| 931 |
'type' => 'text', |
| 932 |
'name' => 'unique_name', |
| 933 |
'obligatory' => 'Off', |
| 934 |
'active' => 'On', |
| 935 |
'required' => 'Off', |
| 936 |
'label' => '', |
| 937 |
'value' => '' |
| 938 |
); |
| 939 |
$form_field = wp_parse_args( $form_field, $defaults ); |
| 940 |
|
| 941 |
if ( |
| 942 |
( ! in_array( $form_field['type'], $params['skip_already_exist_field_types'] ) ) && |
| 943 |
( ! in_array( $form_field['name'], $params['skip_already_exist_field_types'] ) ) && |
| 944 |
( ( $form_field['active'] != 'Off' ) || ( $form_field['obligatory'] == 'On' ) ) |
| 945 |
){ |
| 946 |
|
| 947 |
if ( in_array( $form_field['type'], array( 'calendar', 'captcha', 'submit' ) ) ) { |
| 948 |
$exist_fields_arr[] = $form_field['type']; |
| 949 |
} else { |
| 950 |
$exist_fields_arr[] = $form_field['name']; |
| 951 |
} |
| 952 |
|
| 953 |
$field_css_class = 'wpbc_r_' . $exist_fields_arr[ count( $exist_fields_arr ) - 1 ]; |
| 954 |
// $html_form .= ' <r>' . "\n"; // FixIn: 10.7.1.6. |
| 955 |
$html_form .= ' <c class="' . esc_attr( $field_css_class ) . '"> '; // FixIn: 10.7.1.6. |
| 956 |
|
| 957 |
// ----------------------------------------------------------------------------------------------------- |
| 958 |
// L abel |
| 959 |
// ----------------------------------------------------------------------------------------------------- |
| 960 |
$form_field['label'] = wpbc_lang( $form_field['label'] ); |
| 961 |
if ( function_exists( 'icl_translate' ) ) { // WPML. |
| 962 |
$form_field['label'] = icl_translate( 'wpml_custom', 'wpbc_custom_form_field_label_' . $form_field['name'], $form_field['label'] ); |
| 963 |
} |
| 964 |
|
| 965 |
if ( ( 'checkbox' !== $form_field['type'] ) && ( 'submit' !== $form_field['type'] ) && ( ! empty( $form_field['label'] ) ) ) { |
| 966 |
$html_form .= ' <l for="' . $form_field['name'] . $params['resource_id'] . '" >' . |
| 967 |
$form_field['label'] . ( ( 'On' === $form_field['required'] ) ? '*' : '' ) . // FixIn: 10.9.6.2. |
| 968 |
'</l><br>'; |
| 969 |
} |
| 970 |
|
| 971 |
// ----------------------------------------------------------------------------------------------------- |
| 972 |
// Field Shortcode |
| 973 |
// ----------------------------------------------------------------------------------------------------- |
| 974 |
$html_form .= wpbc_simple_form__get_html_form_input( $form_field, $params['booking_data__parsed_fields'], $params['resource_id'] ); |
| 975 |
|
| 976 |
$html_form .= '</c>' . "\n"; |
| 977 |
// $html_form .= ' </r>' . "\n"; // FixIn: 10.7.1.6. |
| 978 |
|
| 979 |
|
| 980 |
// ------------------------------------------------------------------------------------------------- |
| 981 |
// Set content by columns |
| 982 |
// ------------------------------------------------------------------------------------------------- |
| 983 |
// FixIn: 10.7.1.6. |
| 984 |
if ( ! isset( $rows_arr[ $curr_row_num ] ) ) { |
| 985 |
$rows_arr[ $curr_row_num ] = array(); |
| 986 |
} |
| 987 |
if ( |
| 988 |
( count( $rows_arr[ $curr_row_num ] ) >= $max_col ) |
| 989 |
|| ( in_array( $form_field['type'],array( 'textarea', 'calendar', 'submit' ) ) ) |
| 990 |
|| ( ( in_array( $form_field['name'], array( 'rangetime' ) ) ) && ( 'On' === get_bk_option( 'booking_timeslot_picker' ) ) ) |
| 991 |
){ |
| 992 |
$curr_row_num++; |
| 993 |
$rows_arr[ $curr_row_num ] = array(); |
| 994 |
} |
| 995 |
// ---------------------------------------------- |
| 996 |
$rows_arr[ $curr_row_num ][] = $html_form; |
| 997 |
$html_form = ''; |
| 998 |
// ---------------------------------------------- |
| 999 |
if ( |
| 1000 |
( in_array( $form_field['type'],array( 'textarea', 'calendar', 'submit' ) ) ) |
| 1001 |
|| ( ( in_array( $form_field['name'], array( 'rangetime' ) ) ) && ( 'On' === get_bk_option( 'booking_timeslot_picker' ) ) ) |
| 1002 |
){ |
| 1003 |
$curr_row_num++; |
| 1004 |
$rows_arr[ $curr_row_num ] = array(); |
| 1005 |
} |
| 1006 |
// ------------------------------------------------------------------------------------------------- |
| 1007 |
|
| 1008 |
} //active if |
| 1009 |
} //loop |
| 1010 |
|
| 1011 |
$html_form = ''; |
| 1012 |
foreach ( $rows_arr as $colls_arr ) { |
| 1013 |
$columns_html = implode( "\n", $colls_arr ); |
| 1014 |
if ( empty( $columns_html ) ) { |
| 1015 |
continue; |
| 1016 |
} |
| 1017 |
$html_form .= ( false !== strpos( $columns_html, '[calendar]' ) ) |
| 1018 |
? ' <r class="wpbc_r_calendar">' . "\n" |
| 1019 |
: ' <r>' . "\n"; |
| 1020 |
$html_form .= $columns_html; |
| 1021 |
$html_form .= ' </r>' . "\n"; |
| 1022 |
} |
| 1023 |
|
| 1024 |
|
| 1025 |
return array( $html_form, $exist_fields_arr ); |
| 1026 |
} |
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
/** |
| 1031 |
* Get HTML for INPUT based on Stuctured form field data |
| 1032 |
* |
| 1033 |
* @param $form_field array |
| 1034 |
* @param $booking_data__parsed_fields array |
| 1035 |
* @param $resource_id int |
| 1036 |
* |
| 1037 |
* @return string |
| 1038 |
*/ |
| 1039 |
function wpbc_simple_form__get_html_form_input( $form_field, $booking_data__parsed_fields = array(), $resource_id = 1 ) { |
| 1040 |
|
| 1041 |
$my_form = ''; |
| 1042 |
|
| 1043 |
if ( $form_field['type'] == 'text' ){ |
| 1044 |
$my_form.=' <input type="text" name="'. $form_field['name'] . $resource_id . '" id="' . $form_field['name'] . $resource_id . '" class="input-xlarge' |
| 1045 |
. ( ( $form_field['required'] == 'On' ) ? ' wpdev-validates-as-required' : '' ) |
| 1046 |
//. ( ( strpos( $form_field['name'], 'phone' ) !== false ) ? ' validate_as_digit' : '' ) |
| 1047 |
.'" ' |
| 1048 |
. ( isset( $booking_data__parsed_fields[ $form_field['name'] ] ) // FixIn: 9.2.3.4. |
| 1049 |
? ' value="' . esc_attr( $booking_data__parsed_fields[ $form_field['name'] ] ) . '"' |
| 1050 |
: '' |
| 1051 |
) |
| 1052 |
. '/>'; |
| 1053 |
} |
| 1054 |
|
| 1055 |
if ( $form_field['type'] == 'email' ) { |
| 1056 |
// FixIn: 10.8.1.2. |
| 1057 |
$my_form.=' <input type="email" name="'. $form_field['name'] . $resource_id . '" id="' . $form_field['name'] . $resource_id . '" class="input-xlarge wpdev-validates-as-email' |
| 1058 |
. ( ( $form_field['required'] == 'On' ) ? ' wpdev-validates-as-required' : '' ) |
| 1059 |
. ' wpdev-validates-as-required' // FixIn: 7.0.1.22. |
| 1060 |
.'" ' |
| 1061 |
. ( isset( $booking_data__parsed_fields[ $form_field['name'] ] ) // FixIn: 9.2.3.4. |
| 1062 |
? ' value="' . esc_attr( $booking_data__parsed_fields[ $form_field['name'] ] ) . '"' |
| 1063 |
: '' |
| 1064 |
) |
| 1065 |
. '/>'; |
| 1066 |
} |
| 1067 |
|
| 1068 |
if ( ( $form_field['type'] == 'selectbox' ) || ( $form_field['type'] == 'select' ) ) { |
| 1069 |
|
| 1070 |
$my_form.=' <select name="'. $form_field['name'] . $resource_id . '" id="' . $form_field['name'] . $resource_id . '" class="input-xlarge' |
| 1071 |
. ( ( $form_field['required'] == 'On' ) ? ' wpdev-validates-as-required' : '' ) |
| 1072 |
. '" >'; // FixIn: 8.1.1.4. |
| 1073 |
|
| 1074 |
$form_field['value'] = preg_split( '/\r\n|\r|\n/', $form_field['value'] ); |
| 1075 |
|
| 1076 |
foreach ($form_field['value'] as $key => $select_option) { // FixIn: 7.0.1.21. |
| 1077 |
|
| 1078 |
|
| 1079 |
$select_option = wpbc_lang( $select_option ); |
| 1080 |
if ( function_exists('icl_translate') ) // WPML |
| 1081 |
$select_option = icl_translate( 'wpml_custom', 'wpbc_custom_form_select_value_' |
| 1082 |
. wpbc_get_slug_format( $form_field['name']) . '_' .$key |
| 1083 |
, $select_option ); |
| 1084 |
// // FixIn: 7.0.1.21. |
| 1085 |
$select_option = str_replace(array("'",'"'), '', $select_option); |
| 1086 |
|
| 1087 |
//FixIn: TimeFreeGenerator |
| 1088 |
if ( strpos( $select_option, '@@' ) !== false ) { |
| 1089 |
$select_option_title = explode( '@@', $select_option ); |
| 1090 |
$select_option_val = esc_attr( $select_option_title[1] ); |
| 1091 |
$select_option_title = trim( $select_option_title[0] ); |
| 1092 |
} else { |
| 1093 |
$select_option_val = esc_attr( $select_option ); |
| 1094 |
$select_option_title = trim( $select_option ); |
| 1095 |
|
| 1096 |
if ( 'rangetime' == $form_field['name'] ) { |
| 1097 |
$select_option_title = wpbc_time_slot_in_format( $select_option_title ); |
| 1098 |
} |
| 1099 |
} |
| 1100 |
|
| 1101 |
//FixIn: 9.2.3.4 10.0.0.52 |
| 1102 |
if ( |
| 1103 |
( |
| 1104 |
( isset( $booking_data__parsed_fields[ $form_field['name'] ] ) ) |
| 1105 |
&& ( $select_option_val == $booking_data__parsed_fields[ $form_field['name'] ] ) |
| 1106 |
) |
| 1107 |
|| ( |
| 1108 |
( isset( $booking_data__parsed_fields[ $form_field['name'] . '_in_24_hour' ] ) ) |
| 1109 |
&& ( $select_option_val == $booking_data__parsed_fields[ $form_field['name'] .'_in_24_hour' ] ) |
| 1110 |
) |
| 1111 |
){ |
| 1112 |
$is_option_selected = ' selected="selected" '; |
| 1113 |
} else { |
| 1114 |
$is_option_selected = ''; |
| 1115 |
} |
| 1116 |
|
| 1117 |
$my_form .= ' <option value="' . $select_option_val . '" ' . $is_option_selected . '>' . $select_option_title . '</option>'; |
| 1118 |
|
| 1119 |
// $my_form.=' <option value="' . $select_option . '">' . $select_option . '</option>'; |
| 1120 |
} |
| 1121 |
|
| 1122 |
$my_form.=' </select>'; |
| 1123 |
} |
| 1124 |
|
| 1125 |
if ( $form_field['type'] == 'checkbox' ) { |
| 1126 |
|
| 1127 |
$my_form.=' <label for="'. $form_field['name'] . $resource_id . '" class="control-label" style="display: inline-block;">'; |
| 1128 |
|
| 1129 |
// FixIn: 9.2.3.4. |
| 1130 |
if ( |
| 1131 |
( isset( $booking_data__parsed_fields[ $form_field['name'] ] ) ) |
| 1132 |
&& ( |
| 1133 |
( $form_field['value'] == $booking_data__parsed_fields[ $form_field['name'] ] ) |
| 1134 |
|| ( $form_field['label'] == $booking_data__parsed_fields[ $form_field['name'] ] ) |
| 1135 |
|| ( strtolower( __( 'Yes', 'booking' ) ) == strtolower( $booking_data__parsed_fields[ $form_field['name'] ] ) ) |
| 1136 |
) |
| 1137 |
){ |
| 1138 |
$is_option_selected = ' checked="checked" '; |
| 1139 |
} else { |
| 1140 |
$is_option_selected = ''; |
| 1141 |
} |
| 1142 |
|
| 1143 |
$my_form.=' <input type="checkbox" name="'. $form_field['name'] . $resource_id . '" id="' . $form_field['name'] . $resource_id . '" class="wpdev-checkbox ' |
| 1144 |
. ( ( $form_field['required'] == 'On' ) ? ' wpdev-validates-as-required' : '' ) |
| 1145 |
. '" style="margin:0 0.25em 3px;" value="true" ' |
| 1146 |
. ' value="' . esc_attr( $form_field['label'] ) . '" ' |
| 1147 |
. $is_option_selected |
| 1148 |
. '/>'; |
| 1149 |
|
| 1150 |
$my_form.= ' ' . $form_field['label'] |
| 1151 |
. ( ( $form_field['required'] == 'On' ) ? '' : '' ) |
| 1152 |
. '</label>'; |
| 1153 |
|
| 1154 |
} |
| 1155 |
|
| 1156 |
if ( $form_field['type'] == 'textarea' ) { |
| 1157 |
$my_form.=' <textarea rows="3" name="'. $form_field['name'] . $resource_id . '" id="' . $form_field['name'] . $resource_id . '" class="input-xlarge' |
| 1158 |
. ( ( $form_field['required'] == 'On' ) ? ' wpdev-validates-as-required' : '' ) |
| 1159 |
. '" >'; // FixIn: 8.1.1.4. |
| 1160 |
|
| 1161 |
$my_form.= ( isset( $booking_data__parsed_fields[ $form_field['name'] ] ) // FixIn: 9.2.3.4. |
| 1162 |
? esc_attr( $booking_data__parsed_fields[ $form_field['name'] ] ) // FixIn: 9.7.4.3. |
| 1163 |
: '' |
| 1164 |
); |
| 1165 |
|
| 1166 |
$my_form.='</textarea>'; |
| 1167 |
} |
| 1168 |
|
| 1169 |
if ( $form_field['type'] == 'calendar' ) { |
| 1170 |
$my_form .= '[calendar]'; |
| 1171 |
} |
| 1172 |
|
| 1173 |
if ( $form_field['type'] == 'captcha' ) { |
| 1174 |
$my_form .= '[captcha]'; |
| 1175 |
} |
| 1176 |
|
| 1177 |
if ( $form_field['type'] == 'submit' ) { |
| 1178 |
|
| 1179 |
if ( ! empty( $booking_data__parsed_fields ) ) { |
| 1180 |
$submit_button_title = __( 'Change your Booking', 'booking' ); |
| 1181 |
} else { |
| 1182 |
$submit_button_title = $form_field['label']; |
| 1183 |
} |
| 1184 |
$submit_button_title = str_replace( '"', '', html_entity_decode( esc_js( $submit_button_title ) ) ); |
| 1185 |
|
| 1186 |
$submit_button_title = wp_kses_post( $submit_button_title ); // FixIn: 10.6.5.2. |
| 1187 |
|
| 1188 |
$my_form .= '<button class="wpbc_button_light" type="button" onclick="wpbc_booking_form_submit(this.form,' . $resource_id . ',\'' . wpbc_get_maybe_reloaded_booking_locale() . '\');" >' . |
| 1189 |
$submit_button_title . |
| 1190 |
'</button>' . "\n"; |
| 1191 |
} |
| 1192 |
|
| 1193 |
return $my_form; |
| 1194 |
} |
| 1195 |
|
| 1196 |
|
| 1197 |
/** |
| 1198 |
* Get title for the Send button |
| 1199 |
* |
| 1200 |
* @param $visual_form_structure optional |
| 1201 |
* |
| 1202 |
* @return mixed|string |
| 1203 |
*/ |
| 1204 |
function wpbc_simple_form__visual__get_send_button_title( $visual_form_structure ) { |
| 1205 |
|
| 1206 |
$button_title = ''; |
| 1207 |
foreach ( $visual_form_structure as $field_arr ) { |
| 1208 |
if ( 'submit' === $field_arr['type'] ) { |
| 1209 |
$button_title = $field_arr['label']; |
| 1210 |
} |
| 1211 |
} |
| 1212 |
|
| 1213 |
// If no title in form visual structure |
| 1214 |
if ( empty( $button_title ) ) { |
| 1215 |
$default_options_values = wpbc_get_default_options(); |
| 1216 |
$button_title = ( empty( get_bk_option( 'booking_send_button_title' ) ) ? $default_options_values['booking_send_button_title'] : get_bk_option( 'booking_send_button_title' ) ); |
| 1217 |
} |
| 1218 |
|
| 1219 |
return $button_title; |
| 1220 |
} |
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
/** |
| 1225 |
* Get Calendar Field structure, if this field exist and if this field enabled |
| 1226 |
* |
| 1227 |
* @param $visual_form_structure |
| 1228 |
* |
| 1229 |
* @return mixed|string |
| 1230 |
*/ |
| 1231 |
function wpbc_simple_form__visual__get_calendar( $visual_form_structure ) { |
| 1232 |
|
| 1233 |
foreach ( $visual_form_structure as $field_arr ) { |
| 1234 |
if ( 'calendar' === $field_arr['type'] ) { |
| 1235 |
return $field_arr; |
| 1236 |
} |
| 1237 |
} |
| 1238 |
|
| 1239 |
return false; |
| 1240 |
} |
| 1241 |
|
| 1242 |
|
| 1243 |
/** |
| 1244 |
* Get specific field with specific name |
| 1245 |
* |
| 1246 |
* @param array $visual_form_structure - array of visual form structure. |
| 1247 |
* @param string $field_name - name of field to get. 'durationtime' | 'starttime' | 'endtime' | 'rangetime' ... |
| 1248 |
* |
| 1249 |
* @return false|mixed |
| 1250 |
*/ |
| 1251 |
function wpbc_simple_form__visual__get_one_field( $visual_form_structure, $field_name = 'starttime' ) { |
| 1252 |
|
| 1253 |
foreach ( $visual_form_structure as $field_arr ) { |
| 1254 |
if ( ( $field_name === $field_arr['name'] ) && ( 'On' === $field_arr['active'] ) ) { |
| 1255 |
return $field_arr; |
| 1256 |
} |
| 1257 |
} |
| 1258 |
|
| 1259 |
return false; |
| 1260 |
} |
| 1261 |
|