PluginProbe
Booking Calendar / 11.6.1
Booking Calendar v11.6.1
11.8.4 11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 All 204 releases
booking / includes / page-form-builder / legacy-import / form_simple__get_data.php

form_simple__get_data.php in Booking Calendar 11.6.1, at includes/page-form-builder/legacy-import/form_simple__get_data.php

952 lines 40.3 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( $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 * Previously this data was saved into booking_form; now it is converted/imported into BFB storage.
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 // Legacy Simple form conversion helpers used by the BFB importer.
585 // -------------------------------------------------------------------------------------------------------------
586
587 /**
588 * Get HTML Content of booking form fields and exist field names in this booking form
589 *
590 * @param $params array(
591 * 'visual_form_structure' => wpbc_simple_form__db__get_visual_form_structure(),
592 * 'skip_already_exist_field_types' => array(), // field TYPES, like 'calendar', which we need to skip
593 * 'resource_id' => 1,
594 * 'booking_data__parsed_fields' => array() // It is $booking_data->parsed_fields; in case if we edit the booking form, otherwise array()
595 * )
596 *
597 * @return array // array( $html_form, $exist_fields_arr )
598 */
599 function wpbc_simple_form__get_html_content_of_all_fields__and_fields_arr( $params ) {
600
601 $defaults = array(
602 'visual_form_structure' => wpbc_simple_form__db__get_visual_form_structure(),
603 'skip_already_exist_field_types' => array(), // field TYPES, like 'calendar', which we need to skip
604 'resource_id' => 1,
605 'booking_data__parsed_fields' => array() // It is $booking_data->parsed_fields; in case if we edit the booking form, otherwise array()
606 );
607 $params = wp_parse_args( $params, $defaults );
608
609
610 $exist_fields_arr = array();
611 $html_form = '';
612
613 // FixIn: 10.7.1.6.
614 $rows_arr = array(); // All rows
615 $curr_row_num = 0; // Current row number
616 $max_col = max( intval( get_bk_option( 'booking_form_layout_max_cols' ) ), 1 ); // Maximum number of columns
617
618 // Fields
619 foreach ( $params['visual_form_structure'] as $key => $form_field ) {
620
621 $defaults = array(
622 'type' => 'text',
623 'name' => 'unique_name',
624 'obligatory' => 'Off',
625 'active' => 'On',
626 'required' => 'Off',
627 'label' => '',
628 'value' => ''
629 );
630 $form_field = wp_parse_args( $form_field, $defaults );
631
632 if (
633 ( ! in_array( $form_field['type'], $params['skip_already_exist_field_types'] ) ) &&
634 ( ! in_array( $form_field['name'], $params['skip_already_exist_field_types'] ) ) &&
635 ( ( $form_field['active'] != 'Off' ) || ( $form_field['obligatory'] == 'On' ) )
636 ){
637
638 if ( in_array( $form_field['type'], array( 'calendar', 'captcha', 'submit' ) ) ) {
639 $exist_fields_arr[] = $form_field['type'];
640 } else {
641 $exist_fields_arr[] = $form_field['name'];
642 }
643
644 $field_css_class = 'wpbc_r_' . $exist_fields_arr[ count( $exist_fields_arr ) - 1 ];
645 // $html_form .= ' <r>' . "\n"; // FixIn: 10.7.1.6.
646 $html_form .= ' <c class="' . esc_attr( $field_css_class ) . '"> '; // FixIn: 10.7.1.6.
647
648 // -----------------------------------------------------------------------------------------------------
649 // L abel
650 // -----------------------------------------------------------------------------------------------------
651 $form_field['label'] = wpbc_lang( $form_field['label'] );
652 if ( function_exists( 'icl_translate' ) ) { // WPML.
653 $form_field['label'] = icl_translate( 'wpml_custom', 'wpbc_custom_form_field_label_' . $form_field['name'], $form_field['label'] );
654 }
655
656 if ( ( 'checkbox' !== $form_field['type'] ) && ( 'submit' !== $form_field['type'] ) && ( ! empty( $form_field['label'] ) ) ) {
657 $html_form .= ' <l for="' . $form_field['name'] . $params['resource_id'] . '" >' .
658 $form_field['label'] . ( ( 'On' === $form_field['required'] ) ? '*' : '' ) . // FixIn: 10.9.6.2.
659 '</l><br>';
660 }
661
662 // -----------------------------------------------------------------------------------------------------
663 // Field Shortcode
664 // -----------------------------------------------------------------------------------------------------
665 $html_form .= wpbc_simple_form__get_html_form_input( $form_field, $params['booking_data__parsed_fields'], $params['resource_id'] );
666
667 $html_form .= '</c>' . "\n";
668 // $html_form .= ' </r>' . "\n"; // FixIn: 10.7.1.6.
669
670
671 // -------------------------------------------------------------------------------------------------
672 // Set content by columns
673 // -------------------------------------------------------------------------------------------------
674 // FixIn: 10.7.1.6.
675 if ( ! isset( $rows_arr[ $curr_row_num ] ) ) {
676 $rows_arr[ $curr_row_num ] = array();
677 }
678 if (
679 ( count( $rows_arr[ $curr_row_num ] ) >= $max_col )
680 || ( in_array( $form_field['type'],array( 'textarea', 'calendar', 'submit' ) ) )
681 || ( ( in_array( $form_field['name'], array( 'rangetime' ) ) ) && ( 'On' === get_bk_option( 'booking_timeslot_picker' ) ) )
682 ){
683 $curr_row_num++;
684 $rows_arr[ $curr_row_num ] = array();
685 }
686 // ----------------------------------------------
687 $rows_arr[ $curr_row_num ][] = $html_form;
688 $html_form = '';
689 // ----------------------------------------------
690 if (
691 ( in_array( $form_field['type'],array( 'textarea', 'calendar', 'submit' ) ) )
692 || ( ( in_array( $form_field['name'], array( 'rangetime' ) ) ) && ( 'On' === get_bk_option( 'booking_timeslot_picker' ) ) )
693 ){
694 $curr_row_num++;
695 $rows_arr[ $curr_row_num ] = array();
696 }
697 // -------------------------------------------------------------------------------------------------
698
699 } //active if
700 } //loop
701
702 $html_form = '';
703 foreach ( $rows_arr as $colls_arr ) {
704 $columns_html = implode( "\n", $colls_arr );
705 if ( empty( $columns_html ) ) {
706 continue;
707 }
708 $html_form .= ( false !== strpos( $columns_html, '[calendar]' ) )
709 ? ' <r class="wpbc_r_calendar">' . "\n"
710 : ' <r>' . "\n";
711 $html_form .= $columns_html;
712 $html_form .= ' </r>' . "\n";
713 }
714
715
716 return array( $html_form, $exist_fields_arr );
717 }
718
719
720
721 /**
722 * Get HTML for INPUT based on Stuctured form field data
723 *
724 * @param $form_field array
725 * @param $booking_data__parsed_fields array
726 * @param $resource_id int
727 *
728 * @return string
729 */
730 function wpbc_simple_form__get_html_form_input( $form_field, $booking_data__parsed_fields = array(), $resource_id = 1 ) {
731
732 $my_form = '';
733
734 if ( $form_field['type'] == 'text' ){
735 $my_form.=' <input type="text" name="'. $form_field['name'] . $resource_id . '" id="' . $form_field['name'] . $resource_id . '" class="input-xlarge'
736 . ( ( $form_field['required'] == 'On' ) ? ' wpdev-validates-as-required' : '' )
737 //. ( ( strpos( $form_field['name'], 'phone' ) !== false ) ? ' validate_as_digit' : '' )
738 .'" '
739 . ( isset( $booking_data__parsed_fields[ $form_field['name'] ] ) // FixIn: 9.2.3.4.
740 ? ' value="' . esc_attr( $booking_data__parsed_fields[ $form_field['name'] ] ) . '"'
741 : ''
742 )
743 . '/>';
744 }
745
746 if ( $form_field['type'] == 'email' ) {
747 // FixIn: 10.8.1.2.
748 $my_form.=' <input type="email" name="'. $form_field['name'] . $resource_id . '" id="' . $form_field['name'] . $resource_id . '" class="input-xlarge wpdev-validates-as-email'
749 . ( ( $form_field['required'] == 'On' ) ? ' wpdev-validates-as-required' : '' )
750 . ' wpdev-validates-as-required' // FixIn: 7.0.1.22.
751 .'" '
752 . ( isset( $booking_data__parsed_fields[ $form_field['name'] ] ) // FixIn: 9.2.3.4.
753 ? ' value="' . esc_attr( $booking_data__parsed_fields[ $form_field['name'] ] ) . '"'
754 : ''
755 )
756 . '/>';
757 }
758
759 if ( ( $form_field['type'] == 'selectbox' ) || ( $form_field['type'] == 'select' ) ) {
760
761 $my_form.=' <select name="'. $form_field['name'] . $resource_id . '" id="' . $form_field['name'] . $resource_id . '" class="input-xlarge'
762 . ( ( $form_field['required'] == 'On' ) ? ' wpdev-validates-as-required' : '' )
763 . '" >'; // FixIn: 8.1.1.4.
764
765 $form_field['value'] = preg_split( '/\r\n|\r|\n/', $form_field['value'] );
766
767 foreach ($form_field['value'] as $key => $select_option) { // FixIn: 7.0.1.21.
768
769
770 $select_option = wpbc_lang( $select_option );
771 if ( function_exists('icl_translate') ) // WPML
772 $select_option = icl_translate( 'wpml_custom', 'wpbc_custom_form_select_value_'
773 . wpbc_get_slug_format( $form_field['name']) . '_' .$key
774 , $select_option );
775 // // FixIn: 7.0.1.21.
776 $select_option = str_replace(array("'",'"'), '', $select_option);
777
778 //FixIn: TimeFreeGenerator
779 if ( strpos( $select_option, '@@' ) !== false ) {
780 $select_option_title = explode( '@@', $select_option );
781 $select_option_val = esc_attr( $select_option_title[1] );
782 $select_option_title = trim( $select_option_title[0] );
783 } else {
784 $select_option_val = esc_attr( $select_option );
785 $select_option_title = trim( $select_option );
786
787 if ( 'rangetime' == $form_field['name'] ) {
788 $select_option_title = wpbc_time_slot_in_format( $select_option_title );
789 }
790 }
791
792 //FixIn: 9.2.3.4 10.0.0.52
793 if (
794 (
795 ( isset( $booking_data__parsed_fields[ $form_field['name'] ] ) )
796 && ( $select_option_val == $booking_data__parsed_fields[ $form_field['name'] ] )
797 )
798 || (
799 ( isset( $booking_data__parsed_fields[ $form_field['name'] . '_in_24_hour' ] ) )
800 && ( $select_option_val == $booking_data__parsed_fields[ $form_field['name'] .'_in_24_hour' ] )
801 )
802 ){
803 $is_option_selected = ' selected="selected" ';
804 } else {
805 $is_option_selected = '';
806 }
807
808 $my_form .= ' <option value="' . $select_option_val . '" ' . $is_option_selected . '>' . $select_option_title . '</option>';
809
810 // $my_form.=' <option value="' . $select_option . '">' . $select_option . '</option>';
811 }
812
813 $my_form.=' </select>';
814 }
815
816 if ( $form_field['type'] == 'checkbox' ) {
817
818 $my_form.=' <label for="'. $form_field['name'] . $resource_id . '" class="control-label" style="display: inline-block;">';
819
820 // FixIn: 9.2.3.4.
821 if (
822 ( isset( $booking_data__parsed_fields[ $form_field['name'] ] ) )
823 && (
824 ( $form_field['value'] == $booking_data__parsed_fields[ $form_field['name'] ] )
825 || ( $form_field['label'] == $booking_data__parsed_fields[ $form_field['name'] ] )
826 || ( strtolower( __( 'Yes', 'booking' ) ) == strtolower( $booking_data__parsed_fields[ $form_field['name'] ] ) )
827 )
828 ){
829 $is_option_selected = ' checked="checked" ';
830 } else {
831 $is_option_selected = '';
832 }
833
834 $my_form.=' <input type="checkbox" name="'. $form_field['name'] . $resource_id . '" id="' . $form_field['name'] . $resource_id . '" class="wpdev-checkbox '
835 . ( ( $form_field['required'] == 'On' ) ? ' wpdev-validates-as-required' : '' )
836 . '" style="margin:0 0.25em 3px;" value="true" '
837 . ' value="' . esc_attr( $form_field['label'] ) . '" '
838 . $is_option_selected
839 . '/>';
840
841 $my_form.= '&nbsp;' . $form_field['label']
842 . ( ( $form_field['required'] == 'On' ) ? '' : '' )
843 . '</label>';
844
845 }
846
847 if ( $form_field['type'] == 'textarea' ) {
848 $my_form.=' <textarea rows="3" name="'. $form_field['name'] . $resource_id . '" id="' . $form_field['name'] . $resource_id . '" class="input-xlarge'
849 . ( ( $form_field['required'] == 'On' ) ? ' wpdev-validates-as-required' : '' )
850 . '" >'; // FixIn: 8.1.1.4.
851
852 $my_form.= ( isset( $booking_data__parsed_fields[ $form_field['name'] ] ) // FixIn: 9.2.3.4.
853 ? esc_attr( $booking_data__parsed_fields[ $form_field['name'] ] ) // FixIn: 9.7.4.3.
854 : ''
855 );
856
857 $my_form.='</textarea>';
858 }
859
860 if ( $form_field['type'] == 'calendar' ) {
861 $my_form .= '[calendar]';
862 }
863
864 if ( $form_field['type'] == 'captcha' ) {
865 $my_form .= '[captcha]';
866 }
867
868 if ( $form_field['type'] == 'submit' ) {
869
870 if ( ! empty( $booking_data__parsed_fields ) ) {
871 $submit_button_title = __( 'Change your Booking', 'booking' );
872 } else {
873 $submit_button_title = $form_field['label'];
874 }
875 $submit_button_title = str_replace( '"', '', html_entity_decode( esc_js( $submit_button_title ) ) );
876
877 $submit_button_title = wp_kses_post( $submit_button_title ); // FixIn: 10.6.5.2.
878
879 $my_form .= '<button class="wpbc_button_light" type="button" onclick="wpbc_booking_form_submit(this.form,' . $resource_id . ',\'' . wpbc_get_maybe_reloaded_booking_locale() . '\');" >' .
880 $submit_button_title .
881 '</button>' . "\n";
882 }
883
884 return $my_form;
885 }
886
887
888 /**
889 * Get title for the Send button
890 *
891 * @param $visual_form_structure optional
892 *
893 * @return mixed|string
894 */
895 function wpbc_simple_form__visual__get_send_button_title( $visual_form_structure ) {
896
897 $button_title = '';
898 foreach ( $visual_form_structure as $field_arr ) {
899 if ( 'submit' === $field_arr['type'] ) {
900 $button_title = $field_arr['label'];
901 }
902 }
903
904 // If no title in form visual structure
905 if ( empty( $button_title ) ) {
906 $default_options_values = wpbc_get_default_options();
907 $button_title = ( empty( get_bk_option( 'booking_send_button_title' ) ) ? $default_options_values['booking_send_button_title'] : get_bk_option( 'booking_send_button_title' ) );
908 }
909
910 return $button_title;
911 }
912
913
914
915 /**
916 * Get Calendar Field structure, if this field exist and if this field enabled
917 *
918 * @param $visual_form_structure
919 *
920 * @return mixed|string
921 */
922 function wpbc_simple_form__visual__get_calendar( $visual_form_structure ) {
923
924 foreach ( $visual_form_structure as $field_arr ) {
925 if ( 'calendar' === $field_arr['type'] ) {
926 return $field_arr;
927 }
928 }
929
930 return false;
931 }
932
933
934 /**
935 * Get specific field with specific name
936 *
937 * @param array $visual_form_structure - array of visual form structure.
938 * @param string $field_name - name of field to get. 'durationtime' | 'starttime' | 'endtime' | 'rangetime' ...
939 *
940 * @return false|mixed
941 */
942 function wpbc_simple_form__visual__get_one_field( $visual_form_structure, $field_name = 'starttime' ) {
943
944 foreach ( $visual_form_structure as $field_arr ) {
945 if ( ( $field_name === $field_arr['name'] ) && ( 'On' === $field_arr['active'] ) ) {
946 return $field_arr;
947 }
948 }
949
950 return false;
951 }
952