PluginProbe
Booking Calendar / 10.1.3
Booking Calendar v10.1.3
11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 10.11.2 All 203 releases
booking / includes / _functions / parse_booking_data.php

parse_booking_data.php in Booking Calendar 10.1.3, at includes/_functions/parse_booking_data.php

791 lines 33.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @version 1.0
4 * @package Booking Calendar
5 * @subpackage Booking Data Parsing functions
6 * @category Functions
7 *
8 * @author wpdevelop
9 * @link https://wpbookingcalendar.com/
10 * @email info@wpbookingcalendar.com
11 *
12 * @modified 2024-05-14
13 */
14
15 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
16
17 // =====================================================================================================================
18 // == B o o k i n g F o r m s P a r s i n g ==
19 // =====================================================================================================================
20
21
22 /**
23 * Parse "text^firstname1^John~..." -> [ 'firstname':[name:"firstname", value:"John" ...] ... ] - Parse (DB) form_data and get fields array values
24 *
25 * @param string $form_data - formatted booking form data from database, like this: 'text^selected_short_dates_hint15^21/02/2023 - 24/02/2023~text^days_number_hint15^4~text^cost_hint15^&amp;#36;400.00~text^deposit_hint15^&amp;#36;40.00~text^standard_bk_cost15^100~...'
26 * @param int $resource_id - ID of booking resource
27 * @param array $params - (optional) default: array() define here what field we need to get array( 'get' => 'value' )
28 *
29 * @return array
30 * [
31 * rangetime = [
32 * type = "selectbox-multiple"
33 * original_name = "rangetime3[]"
34 * name = "rangetime"
35 * value = "12:00 - 14:00"
36 * ]
37 * name = [
38 * type = "text"
39 * original_name = "name3"
40 * name = "name"
41 * value = "test 1"
42 * ]
43 * secondname = [...]
44 * email = [...]
45 * ]
46 *
47 * Example 1:
48 * $structured_booking_data_arr = wpbc_get_parsed_booking_data_arr( $this_booking->form, $resource_id, array( 'get' => 'value' ) );
49 * output: [ "rangetime" : "12:00 - 14:00",
50 * "name": "John" ,
51 * "secondname" : "Smith" , "email" : "test@wpbookingcalendar.com" , "visitors" : "1" ... ]
52 *
53 * Example 2:
54 * $structured_booking_data_arr = wpbc_get_parsed_booking_data_arr( $this_booking->form, $resource_id );
55 * output: [ rangetime = [
56 * type = "selectbox-multiple"
57 * original_name = "rangetime3[]"
58 * name = "rangetime"
59 * value = "12:00 - 14:00"
60 * ]
61 * name = [
62 * type = "text"
63 * original_name = "name3"
64 * name = "name"
65 * value = "test 1"
66 * ]
67 * secondname = [...]
68 * email = [...]
69 * ]
70 */
71 function wpbc_get_parsed_booking_data_arr( $form_data, $resource_id = 1, $params = array( ) ) {
72
73 $booking_data_arr = array();
74
75 if ( ! empty( $form_data ) ) {
76
77 $fields_arr = explode( '~', $form_data );
78
79 foreach ( $fields_arr as $field ) {
80
81 if ( false === strpos( $field, '^' ) ) {
82 break; //FixIn: 9.8.10.2
83 }
84
85 list( $field_type, $field_original_name, $field_value ) = explode( '^', $field );
86
87 $field_name = $field_original_name;
88
89 // Is this multi select in checkboxes: [checkbox* ConducenteExtra "Si" "No"] => [... 6: "checkbox^ConducenteExtra4[]^Si", 7: "checkbox^ConducenteExtra4[]^" ... ]
90 $is_multi_options = ( '[]' == substr( $field_name, - 2 ) );
91
92 $minus_additional = ( '[]' == substr( $field_name, - 2 ) ) ? 2 : 0;
93 $field_name = ( $minus_additional > 0 ) ? substr( $field_name, 0, - $minus_additional ) : $field_name;
94
95
96 $minus_additional = ( strval( $resource_id ) == substr( $field_name, - 1 * ( strlen( strval( $resource_id ) ) ) ) )
97 ? strlen( strval( $resource_id ) ) : 0;
98 $field_name = ( $minus_additional > 0 ) ? substr( $field_name, 0, - $minus_additional ) : $field_name;
99
100 if ( ( 'checkbox' === $field_type ) && ( 'true' === $field_value ) ) {
101 //$field_value = strtolower( __( 'Yes', 'booking' ) );
102 $field_value = 'true';
103 }
104 if ( ( 'checkbox' === $field_type ) && ( 'false' === $field_value ) ) {
105 //$field_value = strtolower( __( 'No', 'booking' ) );
106 $field_value = 'false';
107 }
108
109 if ( ! isset( $booking_data_arr[ $field_name ] ) ) {
110 $booking_data_arr[ $field_name ] = array(
111 'type' => $field_type,
112 'original_name' => $field_original_name,
113 'name' => $field_name,
114 'value' => array( $field_value )
115 );
116 } else {
117 // All values we save as array values, for situations of MULTI options:
118 // [checkbox* ConducenteExtra "Si" "No"] => [... 6: "checkbox^ConducenteExtra4[]^Si", 7: "checkbox^ConducenteExtra4[]^" ... ]
119 $booking_data_arr[ $field_name ]['value'][] = $field_value;
120 }
121 }
122
123 // Convert arrays to string
124 foreach ( $booking_data_arr as $field_name => $field_structure_arr ) { //FixIn: 9.8.9.1
125 $field_structure_arr['value'] = array_filter( $field_structure_arr['value'], function ( $v ) {
126 return ( $v !== '' ); // Remove All '' entries
127 } );
128 $booking_data_arr[ $field_name ]['value'] = implode( ', ', $field_structure_arr['value'] );
129 }
130
131
132 if ( isset( $params['get'] ) ) {
133 /**
134 * Now get only values or other fields: [
135 * "rangetime" : "12:00 - 14:00",
136 * "name":"test 1" ,
137 * "secondname" : "test 1" ,
138 * "email" : "test@wpbookingcalendar.com" ,
139 * "visitors" : "1"
140 * ...
141 * ]
142 */
143
144 foreach ( $booking_data_arr as $field_name => $field_structure_arr ) {
145
146 if ( isset( $field_structure_arr[ $params['get'] ] ) ) {
147 $booking_data_arr[ $field_name ] = $field_structure_arr[ $params['get'] ];
148 } else {
149 $booking_data_arr[ $field_name ] = '-';
150 }
151 }
152 }
153 }
154
155 return $booking_data_arr;
156 }
157
158
159 /**
160 * Convert [ ... ] -> "text^firstname1^John~..." - encoded booking data string (Usually for inserting into DB), from parsed booking data array
161 *
162 * @param array $booking_data_arr - parsed booking data.
163 * @param int $resource_id - ID of booking resource - In case, if we need to RE-UPDATE booking resource, Otherwise skip it
164 *
165 * @return string
166 */
167 function wpbc_encode_booking_data_to_string( $booking_data_arr, $resource_id = 0 ) {
168
169 $fields_arr = array();
170
171 foreach ( $booking_data_arr as $fields ) {
172
173 if ( ! empty( $resource_id ) ) {
174 $fields_arr[] = $fields['type']
175 . '^' . $fields['name'] . $resource_id . ( ( '[]' == substr( $fields['original_name'], - 2 ) ) ? '[]' : '' )
176 . '^' . $fields['value'];
177 } else {
178 $fields_arr[] = $fields['type'] . '^' . $fields['original_name'] . '^' . $fields['value'];
179 }
180
181 }
182
183 $form_data = implode( '~', $fields_arr );
184
185 return $form_data;
186 }
187
188
189 // -------------------------------------------------------------------------------------------------------------
190
191 /**
192 * Get Time fields in booking form_data
193 *
194 * @param string $form_data - formatted booking form data from database, like this: 'text^selected_short_dates_hint15^21/02/2023 - 24/02/2023~text^days_number_hint15^4~text^cost_hint15^&amp;#36;400.00~text^deposit_hint15^&amp;#36;40.00~text^standard_bk_cost15^100~...'
195 * @param int $resource_id - ID of booking resource
196 * @param array $params - (optional) default: array() define here what field we need to get array( 'get' => 'value' )
197 *
198 * @return array [ "18:00:00", "20:00:00" ] <- default
199 *
200 * Example #1: $times_his_arr = wpbc_get_times_his_arr__in_form_data( $form_data, $resource_id); --> [ "18:00:01", "20:00:02" ]
201 * same: $times_his_arr = wpbc_get_times_his_arr__in_form_data( $form_data, $resource_id, array( 'get' => 'times_his_arr' ) ); --> [ "18:00:01", "20:00:02" ]
202 * Example #2: $time_as_seconds_arr = wpbc_get_times_his_arr__in_form_data( $form_data, $resource_id, array( 'get' => 'time_as_seconds_arr' ) ); --> [ 64800, 72000 ]
203 * Example #4: $booking_data_arr = wpbc_get_times_his_arr__in_form_data( $form_data, $resource_id, array( 'get' => 'structured_booking_data_arr' ) ); --> [ name = "John", secondname = "Smith", email = "john.smith@server.com", visitors = "2",... ]
204 *
205 * Example #5: $booking_data_arr = wpbc_get_times_his_arr__in_form_data( $form_data, $resource_id, array( 'get' => 'all' ) );
206 * --> [
207 * 'structured_booking_data_arr' => [ name = "John", secondname = "Smith", email = "john.smith@server.com", visitors = "2",... ]
208 * 'time_as_seconds_arr' => [ 64800, 72000 ]
209 * 'time_as_his_arr' => [ "18:00:01", "20:00:02" ]
210 * ]
211 */
212 function wpbc_get_times_his_arr__in_form_data( $form_data, $resource_id = 1, $params = array() ) {
213
214 $defaults = array(
215 'get' => 'times_his_arr'
216 );
217 $params = wp_parse_args( $params, $defaults );
218
219
220 // Get Time from booking form
221 $local_params = array();
222 /**
223 * Get parsed booking form: = [ name = "John", secondname = "Smith", email = "john.smith@server.com", visitors = "2",... ]
224 */
225 $local_params['structured_booking_data_arr'] = wpbc_get_parsed_booking_data_arr( $form_data, $resource_id, array( 'get' => 'value' ) );
226 // $local_params['all_booking_data_arr'] = wpbc_get_parsed_booking_data_arr( $form_data, $resource_id );
227
228 // Important! : [ 64800, 72000 ]
229 $local_params['time_as_seconds_arr'] = wpbc_get_in_booking_form__time_to_book_as_seconds_arr( $local_params['structured_booking_data_arr'] );
230
231 // [ "18:00:00", "20:00:00" ]
232 $time_as_seconds_arr = $local_params['time_as_seconds_arr'];
233 $time_as_seconds_arr[0] = ( 0 != $time_as_seconds_arr[0] ) ? $time_as_seconds_arr[0] + 1 : $time_as_seconds_arr[0]; // set check in time with ended 1 second
234 $time_as_seconds_arr[1] = ( ( 24 * 60 * 60 ) != $time_as_seconds_arr[1] ) ? $time_as_seconds_arr[1] + 2 : $time_as_seconds_arr[1]; // set check out time with ended 2 seconds
235 if ( ( 0 != $time_as_seconds_arr[0] ) && ( ( 24 * 60 * 60 ) == $time_as_seconds_arr[1] ) ) {
236 //FixIn: 10.0.0.49 - in case if we have start time != 00:00 and end time as 24:00 then set end time as 23:59:52
237 $time_as_seconds_arr[1] += - 8;
238 }
239 // [ '16:00:01', '18:00:02' ]
240 $local_params['times_his_arr'] = array(
241 wpbc_transform__seconds__in__24_hours_his( $time_as_seconds_arr[0] ),
242 wpbc_transform__seconds__in__24_hours_his( $time_as_seconds_arr[1] )
243 );
244 if (
245 ( isset( $params['get'] ) )
246 && ( isset( $local_params[ $params['get'] ] ) )
247 ) {
248 return $local_params[ $params['get'] ];
249 }
250
251 return $local_params;
252 }
253
254
255 // -------------------------------------------------------------------------------------------------------------
256
257 /**
258 * Get readable booking form data. Escape values here, as well!
259 *
260 * - 1. <= BS : 'Booking form show' configuration from standard form in versions up to Business Small version ,
261 * - 2 >= BM : If form data has field of custom form, then from custom form configuration,
262 * - 3 >= BM : Otherwise if resource has default custom booking form, then from this default custom booking form
263 * - 4 = MU : specific form of specific WP User
264 * - 5 finally : simple standard form
265 *
266 * @param string $form_data
267 * @param int $resource_id
268 *
269 * @return string
270 */
271 function wpbc_get__booking_form_data__show( $form_data, $resource_id = 1 , $params = array() ) {
272
273 $defaults = array(
274 'is_replace_unknown_shortcodes' => true,
275 'unknown_shortcodes_replace_by' => ''
276 );
277 $params = wp_parse_args( $params, $defaults );
278
279 $booking_form_show = wpbc_get__booking_form_data_configuration( $resource_id, $form_data );
280
281 $booking_data_arr = wpbc_get_parsed_booking_data_arr( $form_data, $resource_id, array( 'get' => 'value' ) );
282
283 foreach ( $booking_data_arr as $key_param => $value_param ) { //FixIn: 6.1.1.4
284
285 $value_param = esc_html( $value_param ); //FixIn: 9.7.4.1 - escape coded html/xss
286 $value_param = esc_html( html_entity_decode( $value_param ) );
287 $value_param = nl2br($value_param); // Add BR instead if /n elements //FixIn: 9.7.4.2
288 $value_param = wpbc_string__escape__then_convert__n_amp__html( $value_param );
289
290 $value_param = wpbc_replace__true_false__to__yes_no( $value_param ); //FixIn: 9.8.9.1
291
292 if (
293 ( gettype( $value_param ) != 'array' )
294 && ( gettype( $value_param ) != 'object' )
295 ) {
296 $booking_form_show = str_replace( '[' . $key_param . ']', $value_param, $booking_form_show );
297 }
298 }
299
300 if ($params['is_replace_unknown_shortcodes']) {
301 // Remove all shortcodes, which is not replaced early.
302 $booking_form_show = preg_replace( '/[\s]{0,}\[[a-zA-Z0-9.,-_]{0,}\][\s]{0,}/', $params['unknown_shortcodes_replace_by'], $booking_form_show ); //FixIn: 6.1.1.4
303 }
304
305 $booking_form_show = str_replace( "&amp;", '&', $booking_form_show ); //FixIn:7.1.2.12
306
307
308
309 return $booking_form_show;
310 }
311
312
313 /**
314 * Get name of custom booking form, if it was used in form data OR booking resource use this default custom form
315 *
316 * @param int $resource_id
317 * @param string $form_data Form data here, required in >= BM, because such form_data can contain fields about used custom booking form
318 *
319 * @return string
320 */
321 function wpbc_get__custom_booking_form_name( $resource_id = 1, $form_data = '' ) {
322
323 $my_booking_form_name = '';
324
325 if ( class_exists( 'wpdev_bk_biz_m' ) ) {
326
327 if ( false !== strpos( $form_data, 'wpbc_custom_booking_form' . $resource_id . '^' ) ) { //FixIn: 9.4.3.12
328
329 $custom_booking_form_name = substr( $form_data, strpos( $form_data, 'wpbc_custom_booking_form' . $resource_id . '^' ) + strlen( 'wpbc_custom_booking_form' . $resource_id . '^' ) );
330
331 if ( false !== strpos( $custom_booking_form_name, '~' ) ) {
332 $custom_booking_form_name = substr( $custom_booking_form_name, 0, strpos( $custom_booking_form_name, '~' ) );
333 $my_booking_form_name = $custom_booking_form_name;
334 }
335
336 } else {
337
338 // BM :: Get default Custom Form of Resource
339 $my_booking_form_name = apply_bk_filter( 'wpbc_get_default_custom_form', 'standard', $resource_id );
340 }
341
342 if ( 'standard' == $my_booking_form_name ) {
343 $my_booking_form_name = '';
344 }
345 }
346
347 return $my_booking_form_name;
348 }
349
350
351 /**
352 * Get configuration of 'BOOKING FORM F I E L D S SHORTCODES' from - Booking > Settings > Form page
353 *
354 * - 1. <= BS : 'Booking form show' configuration from standard form in versions up to Business Small version ,
355 * - 2 >= BM : If form data has field of custom form, then from custom form configuration,
356 * - 3 >= BM : Otherwise if resource has default custom booking form, then from this default custom booking form
357 * - 4 = MU : specific form of specific WP User
358 * - 5 finally : simple standard form
359 *
360 * @param int $resource_id
361 * @param string $form_name Name of custom booking form, required in >= BM
362 *
363 * @return string
364 *
365 * Example 1: $booking_form = wpbc_get__booking_form_fields__configuration( 1 ); <- Load STANDARD booking form
366 * Example 2: $booking_form = wpbc_get__booking_form_fields__configuration( 1 , 'standard' ); <- Load STANDARD booking form
367 * Example 3: $booking_form = wpbc_get__booking_form_fields__configuration( 1 , 'my_custom_form' ); <- Load CUSTOM booking form with name 'my_custom_form'
368 * Example 4: $booking_form = wpbc_get__booking_form_fields__configuration( 1 , '' ); <- Load CUSTOM booking form, which is DEFAULT for RESOURCE
369 * Example 4: $booking_form = wpbc_get__booking_form_fields__configuration( 10 ); <- If resource ID = 10 belong to REGULAR User, then load booking form for this REGULAR USER
370 *
371 */
372 function wpbc_get__booking_form_fields__configuration( $resource_id = 1, $form_name = 'standard' ) {
373
374 if ( ! class_exists( 'wpdev_bk_personal' ) ) {
375 $booking_form_configuration = wpbc_get_free_form_fields_configuration();
376 } else {
377 $booking_form_configuration = get_bk_option( 'booking_form' );
378
379 if ( class_exists( 'wpdev_bk_biz_m' ) ) {
380
381 if ( $form_name != 'standard' ) {
382
383 $booking_form_configuration = apply_bk_filter( 'wpdev_get_booking_form', $booking_form_configuration, $form_name );
384 }
385
386 // Get default Custom Form for resource, if $form_name == '' wpbc_get__booking_form_fields__configuration(1,'')
387 if ( empty( $form_name ) ) {
388
389 $resource_default_custom_form_name = apply_bk_filter( 'wpbc_get_default_custom_form', 'standard', $resource_id );
390
391 $booking_form_configuration = apply_bk_filter( 'wpdev_get_booking_form', $booking_form_configuration, $resource_default_custom_form_name );
392 }
393
394 //MU :: if resource of "Regular User" - then GET STANDARD user form ( if ( get_bk_option( 'booking_is_custom_forms_for_regular_users' ) !== 'On' ) )
395 $booking_form_configuration = apply_bk_filter( 'wpbc_multiuser_get_booking_form_fields_configuration_of_regular_user', $booking_form_configuration, $resource_id, $form_name ); //FixIn: 8.1.3.19
396 }
397 }
398
399 // Language
400 $booking_form_configuration = wpbc_lang( $booking_form_configuration );
401
402 return $booking_form_configuration;
403 }
404
405
406 /**
407 * Get configuration of 'BOOKING FORM DATA' from - Booking > Settings > Form page
408 *
409 * - 1. <= BS : 'Booking form show' configuration from standard form in versions up to Business Small version ,
410 * - 2 >= BM : If form data has field of custom form, then from custom form configuration,
411 * - 3 >= BM : Otherwise if resource has default custom booking form, then from this default custom booking form
412 * - 4 = MU : specific form of specific WP User
413 * - 5 finally : simple standard form
414 *
415 * @param int $resource_id
416 * @param string $form_data Form data here, required in >= BM, because such form_data can contain fields about used custom booking form
417 *
418 * @return string
419 */
420 function wpbc_get__booking_form_data_configuration( $resource_id = 1, $form_data = '' ) {
421
422 if ( ! class_exists( 'wpdev_bk_personal' ) ) {
423
424 $booking_form_show = wpbc_get_free_booking_show_form();
425
426 } else {
427
428 $booking_form_show = get_bk_option( 'booking_form_show' );
429 $booking_form_show = wpbc_bf__replace_custom_html_shortcodes( $booking_form_show );
430
431 if ( class_exists( 'wpdev_bk_biz_m' ) ) {
432
433 if ( false !== strpos( $form_data, 'wpbc_custom_booking_form' . $resource_id . '^' ) ) { //FixIn: 9.4.3.12
434
435 $custom_booking_form_name = substr( $form_data, strpos( $form_data, 'wpbc_custom_booking_form' . $resource_id . '^' ) + strlen( 'wpbc_custom_booking_form' . $resource_id . '^' ) );
436 if ( false !== strpos( $custom_booking_form_name, '~' ) ) {
437 $custom_booking_form_name = substr( $custom_booking_form_name, 0, strpos( $custom_booking_form_name, '~' ) );
438 }
439 $booking_form_show = apply_bk_filter( 'wpdev_get_booking_form_content', $booking_form_show, $custom_booking_form_name );
440 $my_booking_form_name = $custom_booking_form_name;
441 } else {
442
443 // BM :: Get default Custom Form of Resource
444 $my_booking_form_name = apply_bk_filter( 'wpbc_get_default_custom_form', 'standard', $resource_id );
445 if ( ( $my_booking_form_name != 'standard' ) && ( ! empty( $my_booking_form_name ) ) ) {
446 $booking_form_show = apply_bk_filter( 'wpdev_get_booking_form_content', $booking_form_show, $my_booking_form_name );
447 }
448 }
449
450 //MU :: if resource of "Regular User" - then GET STANDARD user form ( if ( get_bk_option( 'booking_is_custom_forms_for_regular_users' ) !== 'On' ) )
451 $booking_form_show = apply_bk_filter( 'wpbc_multiuser_get_booking_form_show_of_regular_user', $booking_form_show, $resource_id, $my_booking_form_name ); //FixIn: 8.1.3.19
452 }
453 }
454
455 // Language
456 $booking_form_show = wpbc_lang( $booking_form_show );
457
458 return $booking_form_show;
459 }
460
461
462 /**
463 * Get (in Free version) configuration of 'BOOKING FORM DATA' from - Booking > Settings > Form page
464 *
465 * @return false|mixed
466 */
467 function wpbc_get_free_booking_show_form() {
468
469 $booking_form_show = apply_bk_filter( 'wpbc_get_free_booking_show_form' );
470 return $booking_form_show;
471 }
472
473 // Get form
474 function wpbc_get_free_form_fields_configuration() {
475
476 $my_form = apply_bk_filter( 'wpbc_get_free_booking_form_shortcodes' );
477
478 return $my_form;
479 }
480
481 // -------------------------------------------------------------------------------------------------------------
482
483
484 /**
485 * Replace resource_ID of booking in 'form_data'
486 * Useful, when we need to save booking from one resource into another.
487 *
488 * @param $booking__form_data__str 'selectbox-multiple^rangetime2[]^18:00 - 20:00~checkbox^fee2[]^true~text^name2^John~text^secondname2^Smith...'
489 * @param $new_resource_id 10
490 * @param $old_resource_id 2
491 *
492 * @return string 'selectbox-multiple^rangetime10[]^18:00 - 20:00~checkbox^fee10[]^true~text^name10^John~text^secondname10^Smith...'
493 */
494 function wpbc_get__form_data__with_replaced_id( $booking__form_data__str, $new_resource_id, $old_resource_id ) {
495
496 $all_booking_data_arr = wpbc_get_parsed_booking_data_arr( $booking__form_data__str, $old_resource_id );
497
498 $new__form_data__str = wpbc_encode_booking_data_to_string( $all_booking_data_arr, $new_resource_id );
499
500 return $new__form_data__str;
501 }
502
503
504 /**
505 * Get arr of all Fields Names from all booking forms (including custom)
506 *
507 * @return array = [
508 0: [ name = "standard", num = 8, listing = [ ... ] ],
509 1: [
510 name = "minimal"
511 num = 7
512 listing = [
513 labels = [
514 0 = " adults"
515 1 = " children"
516 2 = " infants"
517 3 = " gender"
518 4 = " full_name"
519 5 = " email"
520 6 = " phone"
521 fields = {array[7]}
522 0 = " adults"
523 1 = " children"
524 2 = " infants"
525 3 = " gender"
526 4 = " full_name"
527 5 = " email"
528 6 = " phone"
529 fields_type = {array[7]}
530 0 = "select"
531 1 = "select"
532 2 = "select"
533 3 = "radio"
534 4 = "text"
535 5 = "email"
536 6 = "text"
537 ]
538 ]
539 2: [], ...
540 * ]
541 */
542 function wpbc_get__in_all_forms__field_names_arr() {
543
544 $booking_form_fields_arr = array();
545 $booking_form_fields_arr[] = array( 'name' => 'standard', 'form' => wpbc_bf__replace_custom_html_shortcodes( get_bk_option( 'booking_form' ) ), 'content' => wpbc_bf__replace_custom_html_shortcodes( get_bk_option( 'booking_form_show' ) ) );
546
547 /**
548 * Get custom booking form configurations: [
549 * [ name = "minimal",
550 * form = "[calendar]...",
551 * content = "<div class="payment-content-form"> [name] ..."
552 * ],
553 * ...
554 * ]
555 */
556 $is_can = apply_bk_filter( 'multiuser_is_user_can_be_here', true, 'only_super_admin' );
557 if ( ( $is_can ) || ( get_bk_option( 'booking_is_custom_forms_for_regular_users' ) === 'On' ) ) {
558 $booking_forms_extended = get_bk_option( 'booking_forms_extended' );
559 $booking_forms_extended = maybe_unserialize( $booking_forms_extended );
560 if ( false !== $booking_forms_extended ) {
561 foreach ( $booking_forms_extended as $form_extended ) {
562 $booking_form_fields_arr[] = $form_extended;
563 }
564 }
565 }
566
567 foreach ( $booking_form_fields_arr as $form_key => $booking_form_element ) {
568
569 $booking_form = $booking_form_element['form'];
570
571 $types = 'text[*]?|email[*]?|time[*]?|textarea[*]?|select[*]?|selectbox[*]?|checkbox[*]?|radio|acceptance|captchac|captchar|file[*]?|quiz';
572 $regex = '%\[\s*(' . $types . ')(\s+[a-zA-Z][0-9a-zA-Z:._-]*)([-0-9a-zA-Z:#_/|\s]*)?((?:\s*(?:"[^"]*"|\'[^\']*\'))*)?\s*\]%';
573 $regex2 = '%\[\s*(country[*]?|starttime[*]?|endtime[*]?)(\s*[a-zA-Z]*[0-9a-zA-Z:._-]*)([-0-9a-zA-Z:#_/|\s]*)*((?:\s*(?:"[^"]*"|\'[^\']*\'))*)?\s*\]%';
574 $fields_count = preg_match_all($regex, $booking_form, $fields_matches) ;
575 $fields_count2 = preg_match_all($regex2, $booking_form, $fields_matches2) ;
576
577 //Gathering Together 2 arrays $fields_matches and $fields_matches2
578 foreach ($fields_matches2 as $key => $value) {
579 if ($key == 2) $value = $fields_matches2[1];
580 foreach ($value as $v) {
581 $fields_matches[$key][count($fields_matches[$key])] = $v;
582 }
583 }
584 $fields_count += $fields_count2;
585
586 $booking_form_fields_arr[ $form_key ]['num'] = $fields_count;
587 $booking_form_fields_arr[ $form_key ]['listing'] = array(); //$fields_matches;
588
589 $fields_matches[1] = array_map( 'trim', $fields_matches[1] );
590 $fields_matches[2] = array_map( 'trim', $fields_matches[2] );
591
592 $booking_form_fields_arr[ $form_key ]['listing']['labels'] = array_map( 'ucfirst', $fields_matches[2] );
593 $booking_form_fields_arr[ $form_key ]['listing']['fields'] = $fields_matches[2] ;
594
595 foreach ( $fields_matches[1] as $key_fm => $value_fm ) {
596 $fields_matches[1][ $key_fm ] = trim( str_replace( '*', '', $value_fm ) );
597 }
598
599 $booking_form_fields_arr[ $form_key ]['listing']['fields_type'] = $fields_matches[1];
600
601 // Reset
602 unset( $booking_form_fields_arr[ $form_key ]['form'] );
603 unset( $booking_form_fields_arr[ $form_key ]['content'] );
604 }
605
606 return $booking_form_fields_arr;
607 }
608
609
610 // -------------------------------------------------------------------------------------------------------------
611
612
613 /**
614 * Get arr with booking form fields values, after parsing form_data. Avoid to use this function in a future.
615 *
616 * @param $formdata
617 * @param $bktype
618 * @param $booking_form_show
619 * @param $extended_params
620 *
621 * @return array
622 */
623 function wpbc__legacy__get_form_content_arr ( $formdata, $bktype =-1, $booking_form_show ='', $extended_params = array() ) {
624
625 if ( $bktype == -1 ) {
626 $bktype = ( function_exists( 'get__default_type' ) ) ? get__default_type() : 1;
627 }
628
629 if ( $booking_form_show === '' ) {
630
631 $booking_form_show = wpbc_get__booking_form_data_configuration( $bktype, $formdata );
632 }
633
634 $formdata_array = explode('~',$formdata);
635 $formdata_array_count = count($formdata_array);
636 $email_adress='';
637 $name_of_person = '';
638 $coupon_code = '';
639 $secondname_of_person = '';
640 $visitors_count = 1;
641 $select_box_selected_items = array();
642 $check_box_selected_items = array();
643 $all_fields_array = array();
644 $all_fields_array_without_types = array();
645 $checkbox_value=array();
646
647 for ( $i=0 ; $i < $formdata_array_count ; $i++) {
648
649 if ( empty( $formdata_array[$i] ) ) {
650 continue;
651 }
652
653 $elemnts = explode('^',$formdata_array[$i]);
654
655 $type = $elemnts[0];
656 $element_name = $elemnts[1];
657 $value = $elemnts[2];
658
659 //FixIn: 9.7.4.1 - escape coded html/xss
660 $value = esc_html( $value );
661 $value = esc_html( html_entity_decode( $value ) );
662 $value = nl2br($value); // Add BR instead if /n elements //FixIn: 9.7.4.2
663 // Escaping for timeline popovers and for other places
664 $value = wpbc_string__escape__then_convert__n_amp__html( $value );
665
666 $count_pos = strlen( $bktype );
667
668 $type_name = $elemnts[1];
669 $type_name = str_replace('[]','',$type_name);
670 if ($bktype == substr( $type_name, -1*$count_pos ) ) $type_name = substr( $type_name, 0, -1*$count_pos ); // $type_name = str_replace($bktype,'',$elemnts[1]);
671
672 if ( ( ($type_name == 'email') || ($type == 'email') ) && ( empty($email_adress) ) ) $email_adress = $value; //FixIn: 6.0.1.9
673 if ( ($type_name == 'coupon') || ($type == 'coupon') ) $coupon_code = $value;
674 if ( ($type_name == 'name') || ($type == 'name') ) $name_of_person = $value;
675 if ( ($type_name == 'secondname') || ($type == 'secondname') ) $secondname_of_person = $value;
676 if ( ($type_name == 'visitors') || ($type == 'visitors') ) $visitors_count = $value;
677
678
679 if ($type == 'checkbox') {
680 if ($value == 'true') {
681 $value = strtolower( __( 'yes', 'booking' ) );
682 }
683
684 if ($value == 'false') {
685 $value = strtolower( __( 'no', 'booking' ) );
686 }
687
688 if ( $value !='' )
689 if ( ( isset($checkbox_value[ str_replace('[]','',(string) $element_name) ]) ) && ( is_array($checkbox_value[ str_replace('[]','',(string) $element_name) ]) ) ) {
690 $checkbox_value[ str_replace('[]','',(string) $element_name) ][] = $value;
691 } else {
692 $checkbox_value[ str_replace('[]','',(string) $element_name) ] = array($value);
693 }
694
695 $value = '['. $type_name .']'; //FixIn: 6.1.1.14
696 }
697
698 if ( ( $type == 'select-one') || ( $type == 'selectbox-one') || ( $type == 'select-multiple' ) || ( $type == 'selectbox-multiple' ) || ( $type == 'radio' ) ) { // add all select box selected items to return array
699 $select_box_selected_items[$type_name] = $value;
700 }
701
702 if ( ($type == 'checkbox') && (isset($checkbox_value)) ) {
703 if (isset( $checkbox_value[ str_replace('[]','',(string) $element_name) ] )) {
704 if (is_array( $checkbox_value[ str_replace('[]','',(string) $element_name) ] ))
705 $current_checkbox_value = implode(', ', $checkbox_value[ str_replace('[]','',(string) $element_name) ] );
706 else
707 $current_checkbox_value = $checkbox_value[ str_replace('[]','',(string) $element_name) ] ;
708 } else {
709 $current_checkbox_value = '';
710 }
711 $all_fields_array[ str_replace('[]','',(string) $element_name) ] = $current_checkbox_value;
712 $all_fields_array_without_types[ substr( str_replace('[]','',(string) $element_name), 0 , -1*strlen( $bktype ) ) ] = $current_checkbox_value;
713
714 $check_box_selected_items[$type_name] = $current_checkbox_value;
715 } else {
716
717 //FixIn: 8.4.2.11
718 $all_fields_array_without_types[ substr( str_replace('[]','',(string) $element_name), 0 , -1*strlen( $bktype ) ) ] = $value;
719 /**
720 ['_all_'] => $all_fields_array, CONVERT to " AM/PM "
721 ['_all_fields_'] => $all_fields_array_without_types => in " 24 hour " format - for ability correct calculate Booking > Resources > Advanced cost page.
722 */
723 if ( ( $type_name == 'rangetime' ) || ( $type == 'rangetime' ) ) {
724 $value = wpbc_time_slot_in_format( $value );
725 }
726 $all_fields_array[ str_replace('[]','',(string) $element_name) ] = $value;
727 //FixIn: 8.4.2.11
728
729 }
730 $is_skip_replace = false; //FixIn: 7.0.1.45
731 if ( ( $type == 'radio' ) && empty( $value ) )
732 $is_skip_replace = true;
733 if ( ! $is_skip_replace ) {
734 $booking_form_show = str_replace( '[' . $type_name . ']', $value, $booking_form_show );
735 }
736 }
737
738 if (! isset($all_fields_array_without_types[ 'booking_resource_id' ])) $all_fields_array_without_types[ 'booking_resource_id' ] = $bktype;
739 if (! isset($all_fields_array_without_types[ 'resource_id' ])) $all_fields_array_without_types[ 'resource_id' ] = $bktype;
740 if (! isset($all_fields_array_without_types[ 'type_id' ])) $all_fields_array_without_types[ 'type_id' ] = $bktype;
741
742 if (! isset($all_fields_array_without_types[ 'type' ])) $all_fields_array_without_types[ 'type' ] = $bktype;
743 if (! isset($all_fields_array_without_types[ 'resource' ])) $all_fields_array_without_types[ 'resource' ] = $bktype;
744
745 foreach ($extended_params as $key_param=>$value_param) {
746 if (! isset($all_fields_array_without_types[ $key_param ])) $all_fields_array_without_types[ $key_param ] = $value_param;
747 }
748
749 foreach ( $all_fields_array_without_types as $key_param=>$value_param) { //FixIn: 6.1.1.4
750 if ( ( gettype ( $value_param ) != 'array' )
751 && ( gettype ( $value_param ) != 'object' )
752 ) {
753 $booking_form_show = str_replace( '['. $key_param .']', $value_param ,$booking_form_show);
754
755 $all_fields_array_without_types[ $key_param ] = str_replace( "&amp;", '&', $value_param ); //FixIn:7.1.2.12
756 }
757
758
759 }
760 // Remove all shortcodes, which is not replaced early.
761 $booking_form_show = preg_replace ('/[\s]{0,}\[[a-zA-Z0-9.,-_]{0,}\][\s]{0,}/', '', $booking_form_show); //FixIn: 6.1.1.4
762
763 $booking_form_show = str_replace( "&amp;", '&', $booking_form_show ); //FixIn:7.1.2.12
764
765 $return_array = array(
766 'content' => $booking_form_show,
767 'email' => $email_adress,
768 'name' => $name_of_person,
769 'secondname' => $secondname_of_person,
770 'visitors' => $visitors_count,
771 'coupon' => $coupon_code,
772 '_all_' => $all_fields_array,
773 '_all_fields_' => $all_fields_array_without_types
774 );
775
776 foreach ( $select_box_selected_items as $key => $value ) {
777 if ( ! isset( $return_array[ $key ] ) ) {
778 $return_array[ $key ] = $value;
779 }
780 }
781 foreach ( $check_box_selected_items as $key => $value ) {
782 if ( ! isset( $return_array[ $key ] ) ) {
783 $return_array[ $key ] = $value;
784 }
785 }
786
787 return $return_array;
788 }
789
790
791