PluginProbe
Booking Calendar / 10.11.2
Booking Calendar v10.11.2
11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 10.11.2 10.11.3 All 202 releases
booking / includes / page-form-simple / form_simple__get_data.php

form_simple__get_data.php in Booking Calendar 10.11.2, at includes/page-form-simple/form_simple__get_data.php

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