PluginProbe
Booking Calendar / 10.10
Booking Calendar v10.10
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 / _capacity / confirmation_page.php

confirmation_page.php in Booking Calendar 10.10, at includes/_capacity/confirmation_page.php

318 lines 16.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly // FixIn: 9.8.0.4.
4
5 // ---------------------------------------------------------------------------------------------------------------------
6 // == Confirmation Page
7 // ---------------------------------------------------------------------------------------------------------------------
8 /*
9 //Delete it.
10 function wpbc_shortcode__booking_confirmation_debug($attr, $content, $tag) {
11
12 // Normalize attribute keys, lowercase
13 $atts = array_change_key_case( (array) $attr, CASE_LOWER );
14
15 // override default attributes with user attributes
16 $wpbc_atts = shortcode_atts( array(
17 'mode' => 'calendar',
18 'id' => 0
19 ) , $atts, $tag );
20
21 $attr = wpbc_escape_shortcode_params( $wpbc_atts );
22
23
24 $content = preg_replace( '/\R+/', '', $content );
25 $content_utf = mb_convert_encoding( html_entity_decode( $content ), 'HTML-ENTITIES', 'UTF-8' );
26 $search = array( '&lsquo;', '&rsquo;', '&ldquo;', '&rdquo;', '&mdash;' );
27 $replace = array( "'", "'", '"', '"', '-' );
28 $content_utf2 = str_replace($search, $replace, $content_utf);
29
30 $content_utf2 = wp_strip_all_tags( $content_utf2 );
31
32 $content_json = json_decode( $content_utf2 );
33 debuge($content_json);
34
35 die;
36
37
38 $content_str = wp_json_encode( $content_json );
39 $content_str = str_replace(',', ",\n", $content_str);
40
41 $return = wp_json_encode( $attr ) . '<p><pre>' . $content_str . '</pre></p>' . $tag;
42
43 $return .= '<hr/>';
44
45 return $return ;
46 }
47 */
48
49 /**
50 * Load shortcode checking correctly
51 * @return void
52 */
53 function wpbc_init_shortcode__wpbc_booking_confirmation() {
54
55 // Docs: https://developer.wordpress.org/plugins/shortcodes/basic-shortcodes/
56
57 // Universal shortcode 'wpbc' with 'mode' parameter:
58 // Example #1: [wpbc mode="booking_confirm"] <- Get Hash from $_GET['booking_hash']
59 // Example #2: [wpbc mode="booking_confirm" booking_hash="b190e1a1fc6480c03a59444956d3ed22"] <- Always use this HASH from parameter
60 add_shortcode( 'wpbc', 'wpbc_shortcode__booking_confirmation' );
61
62 // ShortHand
63 add_shortcode( 'booking_confirm', 'wpbc_do_shortcode__booking_confirm' );
64 }
65 add_action( 'init', 'wpbc_init_shortcode__wpbc_booking_confirmation', 9999 ); // <- priority to load it last
66
67
68 /**
69 * Universal shortcode worker
70 *
71 * @param array $attr
72 * @param string|null $content
73 * @param string $tag
74 *
75 * @return string
76 */
77 function wpbc_shortcode__booking_confirmation( $attr = array(), $content = null, $tag = '' ) {
78
79 // ob_start();
80
81 $atts = array_change_key_case( (array) $attr, CASE_LOWER ); // Changes the case of all keys in an array
82
83 /*
84 $wpbc_atts = shortcode_atts( array(
85 'mode' => 'calendar',
86 'id' => 1
87 ) , $atts ); // Override default attributes with user attributes
88
89 $attr = wpbc_escape_shortcode_params( $wpbc_atts ); // My escaping
90 */
91
92 $return = '';
93
94 switch ( $attr['mode'] ) {
95
96 case 'booking_confirm':
97
98 $return .= wpbc_do_shortcode__booking_confirm( $attr );
99 break;
100
101 default:
102 $return = '<p style="font-size:9px;">'
103 . 'Invalid shortcode configuration: <strong>[' . $tag . ' ... ]</strong> with the following parameters: ' . wp_json_encode( $attr ) . '. '
104 /* translators: 1: ... */
105 . sprintf( __( 'Find more in the %1$sFAQ%2$s', 'booking' ), '<a href="https://wpbookingcalendar.com/faq/">', '</a>.' )
106 . '</p>';
107 }
108
109 // $possible_output = ob_get_clean();
110 // $return .= $possible_output;
111
112 return $return ;
113 }
114
115
116
117 function wpbc_do_shortcode__booking_confirm( $attr ){
118
119 if ( wpbc_is_on_edit_page() ) {
120 return wpbc_get_preview_for_shortcode( 'booking_confirm', array() ); // FixIn: 9.9.0.39.
121 }
122
123 ob_start();
124
125 $atts = array_change_key_case( (array) $attr, CASE_LOWER ); // Changes the case of all keys in an array
126
127 $wpbc_atts = shortcode_atts( array(
128 //'mode' => 'calendar', // ?
129 //'id' => 1, // ?
130 'booking_hash' => '' // Optional!. Required only for specific situation to show always SAME booking at this page without the $_REQUEST['booking_hash']
131 ) , $atts ); // Override default attributes with user attributes
132
133 $attr = wpbc_escape_shortcode_params( $wpbc_atts ); // My escaping
134
135 $booking_resource_id__arr = wpbc_get_booking_arr__from_hash_in_url( $attr['booking_hash'] ); // <- $attr['booking_hash'] Optional and usually it == '', required only for specific situation to show always SAME booking at this page!
136 $booking_id = intval( $booking_resource_id__arr['booking_id'] );
137 $resource_id = intval( $booking_resource_id__arr['resource_id'] );
138
139 if ( empty( $booking_id ) ) {
140
141 return '<strong>' . esc_html__('Oops!' ,'booking') . '</strong> '
142 . __('We could not find your booking. The link you used may be incorrect or has expired. If you need assistance, please contact our support team.' ,'booking');
143 } else {
144
145
146 // DB Booking Details
147 $booking_data = wpbc_db_get_booking_details( $booking_id ); // {... , "form":"text^cost_hint4^\u20ac76.49~text^original_cost_hint4^...","booking_type":"4","remark":"---","cost":"7.65" ... }
148
149 // DB Booking Dates
150 $booking_dates = wpbc_db_get_booking_dates( $booking_id ); // [ {"booking_dates_id":"10236","booking_id":"4195","booking_date":"2023-11-27 18:00:01","approved":"0","type_id":null} ,...]
151
152 // Parse dates
153 $dates_ymd_arr = array_map( function ( $value ) {
154 $sql_booking_date = $value->booking_date;
155 $value_arr = explode( ' ', $sql_booking_date );
156 return $value_arr[0];
157 }, $booking_dates ); // ["2023-11-27","2023-11-28","2023-11-29"]
158 // Remove duplicates
159 $dates_ymd_arr = array_unique( $dates_ymd_arr );
160 // Sort Dates
161 sort( $dates_ymd_arr ); // [ '2023-10-20', '2023-10-25' ]
162
163
164 $params_arr = array();
165 $params_arr['booking_id'] = $booking_id;
166 $params_arr['resource_id'] = $resource_id;
167 $params_arr['form_data'] = $booking_data->form; // 'text^selected_short_dates_hint11^Sun...',
168 $params_arr['dates_ymd_arr'] = $dates_ymd_arr; // [ '2023-10-20', '2023-10-25' ]
169 $params_arr['times_his_arr'] = wpbc_get_times_his_arr__in_form_data( $params_arr['form_data'], $params_arr['resource_id'] ); // [ '16:00:01', '18:00:02' ]
170
171 /**
172 * Another way of get data
173 * // 3. Get booking dates (sql)
174 * $bookings_obj = array( $booking_data );
175 * $booking_dates_obj = wpbc_ajx_get__booking_dates_obj__sql( $bookings_obj );
176 *
177 * // 4. Include dates into bookings (Wide and Short dates view)
178 * $bookings_with_dates = wpbc_ajx_include_bookingdates_in_bookings( $bookings_obj, $booking_dates_obj );
179 *
180 * // 5. Parse forms
181 * $parsed_bookings = wpbc_ajx_parse_bookings( $bookings_with_dates, $resources_arr ); ??
182 *
183 * wpbc_get_booking_different_params_arr( $booking_data->booking_id, $booking_data->form, $booking_resource_id__arr['resource_id'] );
184 *
185 * $booking_data = wpbc_api_get_booking_by_id( $booking_id );
186 *
187 * $params_arr['form_data'] = $bookings_with_dates[ $booking_id ]->booking_db->form; // 'text^selected_short_dates_hint11^Sun...',
188 *
189 * $params_arr['dates_ymd_arr'] = array_map( function ( $value ) {
190 * $value_arr = explode( ' ', $value );
191 * return $value_arr[0];
192 * }, $bookings_with_dates[ $booking_id ]->dates ); // .->booking_db->dates = [ "2023-11-27 18:00:01", "2023-11-28 00:00:00", "2023-11-29 20:00:02" ]
193 * // Remove duplicates
194 * $params_arr['dates_ymd_arr'] = array_unique( $params_arr['dates_ymd_arr'] );
195 *
196 * // Sort Dates
197 * sort( $params_arr['dates_ymd_arr'] ); // [ '2023-10-20', '2023-10-25' ]
198 */
199
200 // $booking_data_arr = wpbc_get_parsed_booking_data_arr( $params_arr['form_data'], $params_arr['resource_id'], array( 'get' => 'value' ) ); // Get parsed booking form: = [ name = "John", secondname = "Smith", email = "john.smith@server.com", visitors = "2",... ]
201 // $time_as_seconds_arr = wpbc_get_times_his_arr__in_form_data( $params_arr['form_data'], $params_arr['resource_id'], array( 'get' => 'time_as_seconds_arr' ) ); // [ 64800, 72000 ]
202
203 $payment_cost = ( class_exists( 'wpdev_bk_biz_s' ) ) ? ( (float) $booking_data->cost ) : 0;
204 $params_arr['payment_cost'] = $payment_cost; // $bookings_with_dates[ $booking_id ]->booking_db->cost;
205 $params_arr['total_cost'] = $payment_cost;
206 $params_arr['deposit_cost'] = $payment_cost;
207 $params_arr['is_deposit'] = false; // Optional.
208 $params_arr['booking_summary'] = ''; // Optional.
209 $params_arr['gateways_arr'] = ''; // Optional.
210 $params_arr['is_show_coupon_discount_text'] = false; // Because we are at the 'Thank you' page, it can be request, and we do not show this coupon discount ??
211
212
213
214 // =============================================================================================================
215 // Get payment form(s) and Update COST of the booking
216 // =============================================================================================================
217 $payment_params = array();
218
219 // Usually we have this: ( $str_dates__dd_mm_yyyy == $create_params['dates_only_sql_arr'] ) - but for ensure, use saved dates, e.g. $str_dates__dd_mm_yyyy
220 $payment_params['booked_dates_times_arr'] = array(
221 'dates_ymd_arr' => $params_arr['dates_ymd_arr'], // [ '2023-10-20', '2023-10-25' ]
222 'times_his_arr' => $params_arr['times_his_arr'] // ['16:00:01', '18:00:02']
223 );
224 $str_dates__dd_mm_yyyy = wpbc_convert_dates_arr__yyyy_mm_dd__to__dd_mm_yyyy( $params_arr['dates_ymd_arr'] ); // ['2023-10-20','2023-10-25'] => ['20.10.2023','25.10.2023']
225 $payment_params['str_dates__dd_mm_yyyy'] = implode( ',', $str_dates__dd_mm_yyyy ); // REQUIRED -- '14.11.2023, 15.11.2023, 16.11.2023, 17.11.2023'
226 $payment_params['booking_id'] = $params_arr['booking_id']; // REQUIRED -- '2'
227 $payment_params['resource_id'] = $params_arr['resource_id']; // REQUIRED -- '2' can be child resource (changed in wpbc_where_to_save() )
228
229 // This field required only for make cost calculation based on PARENT booking resource. But here we already have the cost from DB, so no need to use parent booking resource
230 $payment_params['initial_resource_id'] = $params_arr['resource_id']; // REQUIRED -- '2' initial calendar - parent resource
231
232 $payment_params['form_data'] = $params_arr['form_data']; // we re-save it, because here can be sync_guid and custom form new data from wpbc_db__booking_save(..) // REQUIRED -- 'text^selected_short_timedates_hint4^06/11/2018 14:00...'
233 $payment_params['times_array'] = array( explode( ':', $params_arr['times_his_arr'][0] ), explode( ':', $params_arr['times_his_arr'][1] ) ); // [ ["10","00","00"], ["12","00","00"] ]
234
235 $payment_params['custom_form'] = wpbc_get__custom_booking_form_name( $params_arr['resource_id'], $params_arr['form_data'] ); // => '' '' | 'some_name'
236 // <editor-fold defaultstate="collapsed" desc=" -- Trick for legacy code -- " >
237 $_POST['booking_form_type'] = $payment_params['custom_form']; // Trick for legacy code for correct cost calculation, relative to "Advanced cost". Required in biz_m.php file in function advanced_cost_apply( $summ , $form , $bktype , $days_array , $is_get_description = false )
238 // </editor-fold>
239
240 // Additional options
241 $payment_params['is_edit_booking'] = 0; // => 0 0 | int - ID of the booking
242 $payment_params['is_duplicate_booking'] = 0; // => 0 0 | 1
243 $payment_params['is_from_admin_panel'] = false; // => false true | false
244 $payment_params['is_show_payment_form'] = 1; // => 1 0 | 1
245
246 // FixIn: 9.9.0.35.
247 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
248 if ( ( ! empty( $_GET['is_show_payment_form'] ) ) && ( 'Off' === $_GET['is_show_payment_form'] ) ) {
249 $payment_params['is_show_payment_form'] = 0;
250 }
251
252 $payment_params['costs_arr'] = array(
253 'total_cost' => $params_arr['payment_cost'],
254 'deposit_cost' => $params_arr['payment_cost']
255 );
256 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
257 if ( ( ! empty( $_GET['booking_pay'] ) ) && ( 1 == intval( $_GET['booking_pay'] ) ) ) {
258 $payment_params['booking_payment_form_in_request_only'] = 1;
259 $params_arr['booking_payment_form_in_request_only'] = 1;
260 }
261
262 // Situation, when we show payment form for "child booking resources", and need to recalculate total booking cost, based on cost of parent resource for "Cash payment" - calc_cost_hint | calc_deposit_hint | calc_original_cost_hint ...
263 if(
264 ( function_exists( 'wpbc_is_this_child_resource' ) )
265 && ( wpbc_is_this_child_resource( $payment_params['resource_id'] ) )
266 ){
267 $bk_parent_br_id = wpbc_get_parent_resource( $payment_params['resource_id'] );
268 $payment_params['initial_resource_id'] = $bk_parent_br_id;
269 //$payment_params['resource_id'] = $payment_params['resource_id'];
270 }
271
272 // GET PAYMENT FORMS
273 if ( function_exists( 'wpbc_maybe_get_payment_form' ) ) {
274
275 $response__payment_form__arr = wpbc_maybe_get_payment_form( $payment_params );
276
277 if ( ( ! empty( $response__payment_form__arr['gateways_output_arr'] ) ) && ( ! empty( $response__payment_form__arr['gateways_output_arr']['gateway_rows'] ) ) ) {
278 $params_arr['gateway_rows'] = $response__payment_form__arr['gateways_output_arr']['gateway_rows'];
279 }
280 if ( ( ! empty( $response__payment_form__arr['gateways_output_arr'] ) ) && ( ! empty( $response__payment_form__arr['gateways_output_arr']['booking_summary'] ) ) ) {
281 $params_arr['booking_summary'] = $response__payment_form__arr['gateways_output_arr']['booking_summary'];
282 }
283
284 } else {
285 $response__payment_form__arr = $payment_params;
286 $response__payment_form__arr['status'] = 'ok';
287 }
288
289 // =============================================================================================================
290
291
292 $confirmation_arr = wpbc_booking_confirmation( $params_arr );
293
294 $confirmation_arr['ty_is_redirect'] = 'message'; // We already at this page, so do not make redirect
295 $confirmation_arr['ty_message'] = ''; // Reset "Thank you" message, because it is oin the Thank you | Payment request page now.
296
297
298 $json_arr = array();
299 $json_arr['ajx_confirmation'] = $confirmation_arr;
300 $json_arr['resource_id'] = $resource_id;
301
302 $return_str = '<div class="wpbc_container ">'
303 . '<div id="booking_form' . $resource_id . '"></div>'
304 . '<script type="text/javascript"> ' . wpbc_jq_ready_start() // FixIn: 10.1.3.7.
305 . ' wpbc_show_thank_you_message_after_booking(' .wp_json_encode( $json_arr ) . '); '
306 //. ' wpbc_show_thank_you_message_after_booking(' . str_replace( array( "\n", '\\n', '\n' ), ' ', wp_json_encode( $json_arr ) ) . '); '
307 . ' setTimeout( function (){ wpbc_do_scroll( "#wpbc_scroll_point_' . intval( $resource_id ) . '", 10 ); }, 500 ); '
308 . wpbc_jq_ready_end() . '</script>' // FixIn: 10.1.3.7.
309 . '</div>';
310 }
311
312
313 $possible_output = ob_get_clean();
314
315 $return_str .= $possible_output;
316
317 return $return_str; // return '<pre>' . var_export($confirmation_arr, true) . '</pre>';
318 }