| 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( '‘', '’', '“', '”', '—' ); |
| 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 |
$return .= wpbc_do_shortcode__booking_confirm( $attr ); |
| 98 |
break; |
| 99 |
|
| 100 |
default: |
| 101 |
$return = '<p style="font-size:9px;">Invalid shortcode configuration: <strong>[' . esc_html( $tag ) . ' ... ]</strong>. ' . // FixIn: 10.11.2.1. |
| 102 |
/* translators: 1: ... */ |
| 103 |
sprintf( __( 'Find more in the %1$sFAQ%2$s', 'booking' ), '<a href="https://wpbookingcalendar.com/faq/">', '</a>.' ) . |
| 104 |
'</p>'; |
| 105 |
} |
| 106 |
|
| 107 |
// $possible_output = ob_get_clean(); |
| 108 |
// $return .= $possible_output; |
| 109 |
|
| 110 |
return $return ; |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
function wpbc_do_shortcode__booking_confirm( $attr ){ |
| 116 |
|
| 117 |
if ( wpbc_is_on_edit_page() ) { |
| 118 |
return wpbc_get_preview_for_shortcode( 'booking_confirm', array() ); // FixIn: 9.9.0.39. |
| 119 |
} |
| 120 |
|
| 121 |
ob_start(); |
| 122 |
|
| 123 |
$atts = array_change_key_case( (array) $attr, CASE_LOWER ); // Changes the case of all keys in an array |
| 124 |
|
| 125 |
$wpbc_atts = shortcode_atts( array( |
| 126 |
//'mode' => 'calendar', // ? |
| 127 |
//'id' => 1, // ? |
| 128 |
'booking_hash' => '' // Optional!. Required only for specific situation to show always SAME booking at this page without the $_REQUEST['booking_hash'] |
| 129 |
) , $atts ); // Override default attributes with user attributes |
| 130 |
|
| 131 |
$attr = wpbc_escape_shortcode_params( $wpbc_atts ); // My escaping |
| 132 |
|
| 133 |
$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! |
| 134 |
$booking_id = intval( $booking_resource_id__arr['booking_id'] ); |
| 135 |
$resource_id = intval( $booking_resource_id__arr['resource_id'] ); |
| 136 |
|
| 137 |
if ( empty( $booking_id ) ) { |
| 138 |
|
| 139 |
return '<div class="wpbc_after_booking_thank_you_section"><div class="wpbc_ty__container"><div class="wpbc_ty__header"><strong>' . esc_html__('Oops!' ,'booking') . '</strong> ' |
| 140 |
. __('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') . '</div></div></div>'; |
| 141 |
} else { |
| 142 |
|
| 143 |
|
| 144 |
// DB Booking Details |
| 145 |
$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" ... } |
| 146 |
|
| 147 |
// DB Booking Dates |
| 148 |
$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} ,...] |
| 149 |
|
| 150 |
// Parse dates |
| 151 |
$dates_ymd_arr = array_map( function ( $value ) { |
| 152 |
$sql_booking_date = $value->booking_date; |
| 153 |
$value_arr = explode( ' ', $sql_booking_date ); |
| 154 |
return $value_arr[0]; |
| 155 |
}, $booking_dates ); // ["2023-11-27","2023-11-28","2023-11-29"] |
| 156 |
// Remove duplicates |
| 157 |
$dates_ymd_arr = array_unique( $dates_ymd_arr ); |
| 158 |
// Sort Dates |
| 159 |
sort( $dates_ymd_arr ); // [ '2023-10-20', '2023-10-25' ] |
| 160 |
|
| 161 |
|
| 162 |
$params_arr = array(); |
| 163 |
$params_arr['booking_id'] = $booking_id; |
| 164 |
$params_arr['resource_id'] = $resource_id; |
| 165 |
$params_arr['form_data'] = $booking_data->form; // 'text^selected_short_dates_hint11^Sun...', |
| 166 |
$params_arr['dates_ymd_arr'] = $dates_ymd_arr; // [ '2023-10-20', '2023-10-25' ] |
| 167 |
$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' ] |
| 168 |
|
| 169 |
/** |
| 170 |
* Another way of get data |
| 171 |
* // 3. Get booking dates (sql) |
| 172 |
* $bookings_obj = array( $booking_data ); |
| 173 |
* $booking_dates_obj = wpbc_ajx_get__booking_dates_obj__sql( $bookings_obj ); |
| 174 |
* |
| 175 |
* // 4. Include dates into bookings (Wide and Short dates view) |
| 176 |
* $bookings_with_dates = wpbc_ajx_include_bookingdates_in_the_bookings( $bookings_obj, $booking_dates_obj ); |
| 177 |
* |
| 178 |
* // 5. Parse forms |
| 179 |
* $parsed_bookings = wpbc_ajx_parse_bookings( $bookings_with_dates, $resources_arr ); ?? |
| 180 |
* |
| 181 |
* wpbc_get_booking_different_params_arr( $booking_data->booking_id, $booking_data->form, $booking_resource_id__arr['resource_id'] ); |
| 182 |
* |
| 183 |
* $booking_data = wpbc_api_get_booking_by_id( $booking_id ); |
| 184 |
* |
| 185 |
* $params_arr['form_data'] = $bookings_with_dates[ $booking_id ]->booking_db->form; // 'text^selected_short_dates_hint11^Sun...', |
| 186 |
* |
| 187 |
* $params_arr['dates_ymd_arr'] = array_map( function ( $value ) { |
| 188 |
* $value_arr = explode( ' ', $value ); |
| 189 |
* return $value_arr[0]; |
| 190 |
* }, $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" ] |
| 191 |
* // Remove duplicates |
| 192 |
* $params_arr['dates_ymd_arr'] = array_unique( $params_arr['dates_ymd_arr'] ); |
| 193 |
* |
| 194 |
* // Sort Dates |
| 195 |
* sort( $params_arr['dates_ymd_arr'] ); // [ '2023-10-20', '2023-10-25' ] |
| 196 |
*/ |
| 197 |
|
| 198 |
// $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",... ] |
| 199 |
// $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 ] |
| 200 |
|
| 201 |
$payment_cost = ( class_exists( 'wpdev_bk_biz_s' ) ) ? ( (float) $booking_data->cost ) : 0; |
| 202 |
$params_arr['payment_cost'] = $payment_cost; // $bookings_with_dates[ $booking_id ]->booking_db->cost; |
| 203 |
$params_arr['total_cost'] = $payment_cost; |
| 204 |
$params_arr['deposit_cost'] = $payment_cost; |
| 205 |
$params_arr['is_deposit'] = false; // Optional. |
| 206 |
$params_arr['booking_summary'] = ''; // Optional. |
| 207 |
$params_arr['gateways_arr'] = ''; // Optional. |
| 208 |
$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 ?? |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
// ============================================================================================================= |
| 213 |
// Get payment form(s) and Update COST of the booking |
| 214 |
// ============================================================================================================= |
| 215 |
$payment_params = array(); |
| 216 |
|
| 217 |
// 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 |
| 218 |
$payment_params['booked_dates_times_arr'] = array( |
| 219 |
'dates_ymd_arr' => $params_arr['dates_ymd_arr'], // [ '2023-10-20', '2023-10-25' ] |
| 220 |
'times_his_arr' => $params_arr['times_his_arr'] // ['16:00:01', '18:00:02'] |
| 221 |
); |
| 222 |
$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'] |
| 223 |
$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' |
| 224 |
$payment_params['booking_id'] = $params_arr['booking_id']; // REQUIRED -- '2' |
| 225 |
$payment_params['resource_id'] = $params_arr['resource_id']; // REQUIRED -- '2' can be child resource (changed in wpbc_where_to_save() ) |
| 226 |
|
| 227 |
// 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 |
| 228 |
$payment_params['initial_resource_id'] = $params_arr['resource_id']; // REQUIRED -- '2' initial calendar - parent resource |
| 229 |
|
| 230 |
$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...' |
| 231 |
$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"] ] |
| 232 |
|
| 233 |
$payment_params['custom_form'] = wpbc_get__custom_booking_form_name( $params_arr['resource_id'], $params_arr['form_data'] ); // => '' '' | 'some_name' |
| 234 |
// <editor-fold defaultstate="collapsed" desc=" -- Trick for legacy code -- " > |
| 235 |
$_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 ) |
| 236 |
// </editor-fold> |
| 237 |
|
| 238 |
// Additional options |
| 239 |
$payment_params['is_edit_booking'] = 0; // => 0 0 | int - ID of the booking |
| 240 |
$payment_params['is_duplicate_booking'] = 0; // => 0 0 | 1 |
| 241 |
$payment_params['is_from_admin_panel'] = false; // => false true | false |
| 242 |
$payment_params['is_show_payment_form'] = 1; // => 1 0 | 1 |
| 243 |
|
| 244 |
// FixIn: 9.9.0.35. |
| 245 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 246 |
if ( ( ! empty( $_GET['is_show_payment_form'] ) ) && ( 'Off' === $_GET['is_show_payment_form'] ) ) { |
| 247 |
$payment_params['is_show_payment_form'] = 0; |
| 248 |
} |
| 249 |
|
| 250 |
$payment_params['costs_arr'] = array( |
| 251 |
'total_cost' => $params_arr['payment_cost'], |
| 252 |
'deposit_cost' => $params_arr['payment_cost'] |
| 253 |
); |
| 254 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 255 |
if ( ( ! empty( $_GET['booking_pay'] ) ) && ( 1 == intval( $_GET['booking_pay'] ) ) ) { |
| 256 |
$payment_params['booking_payment_form_in_request_only'] = 1; |
| 257 |
$params_arr['booking_payment_form_in_request_only'] = 1; |
| 258 |
} |
| 259 |
|
| 260 |
// 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 ... |
| 261 |
if( |
| 262 |
( function_exists( 'wpbc_is_this_child_resource' ) ) |
| 263 |
&& ( wpbc_is_this_child_resource( $payment_params['resource_id'] ) ) |
| 264 |
){ |
| 265 |
$bk_parent_br_id = wpbc_get_parent_resource( $payment_params['resource_id'] ); |
| 266 |
$payment_params['initial_resource_id'] = $bk_parent_br_id; |
| 267 |
//$payment_params['resource_id'] = $payment_params['resource_id']; |
| 268 |
} |
| 269 |
|
| 270 |
// GET PAYMENT FORMS |
| 271 |
if ( function_exists( 'wpbc_maybe_get_payment_form' ) ) { |
| 272 |
|
| 273 |
$response__payment_form__arr = wpbc_maybe_get_payment_form( $payment_params ); |
| 274 |
|
| 275 |
if ( ( ! empty( $response__payment_form__arr['gateways_output_arr'] ) ) && ( ! empty( $response__payment_form__arr['gateways_output_arr']['gateway_rows'] ) ) ) { |
| 276 |
$params_arr['gateway_rows'] = $response__payment_form__arr['gateways_output_arr']['gateway_rows']; |
| 277 |
} |
| 278 |
if ( ( ! empty( $response__payment_form__arr['gateways_output_arr'] ) ) && ( ! empty( $response__payment_form__arr['gateways_output_arr']['booking_summary'] ) ) ) { |
| 279 |
$params_arr['booking_summary'] = $response__payment_form__arr['gateways_output_arr']['booking_summary']; |
| 280 |
} |
| 281 |
|
| 282 |
} else { |
| 283 |
$response__payment_form__arr = $payment_params; |
| 284 |
$response__payment_form__arr['status'] = 'ok'; |
| 285 |
} |
| 286 |
|
| 287 |
// ============================================================================================================= |
| 288 |
|
| 289 |
|
| 290 |
$confirmation_arr = wpbc_booking_confirmation( $params_arr ); |
| 291 |
|
| 292 |
$confirmation_arr['ty_is_redirect'] = 'message'; // We already at this page, so do not make redirect |
| 293 |
$confirmation_arr['ty_message'] = ''; // Reset "Thank you" message, because it is oin the Thank you | Payment request page now. |
| 294 |
|
| 295 |
|
| 296 |
$json_arr = array(); |
| 297 |
$json_arr['ajx_confirmation'] = $confirmation_arr; |
| 298 |
$json_arr['resource_id'] = $resource_id; |
| 299 |
|
| 300 |
/* |
| 301 |
* Keep redirected confirmation/payment output in the same styling scope |
| 302 |
* as payment forms shown directly after an AJAX booking. Gateway buttons |
| 303 |
* use the shared .wpbc_button_light styles scoped by |
| 304 |
* .wpbc_container_booking_form. |
| 305 |
*/ |
| 306 |
$return_str = '<div class="wpbc_container wpbc_container_booking_form">' |
| 307 |
. '<div id="booking_form' . $resource_id . '"></div>' |
| 308 |
. '<script type="text/javascript"> ' . wpbc_jq_ready_start() // FixIn: 10.1.3.7. |
| 309 |
. ' wpbc_show_thank_you_message_after_booking(' .wp_json_encode( $json_arr ) . '); ' |
| 310 |
//. ' wpbc_show_thank_you_message_after_booking(' . str_replace( array( "\n", '\\n', '\n' ), ' ', wp_json_encode( $json_arr ) ) . '); ' |
| 311 |
. ' setTimeout( function (){ wpbc_do_scroll( "#wpbc_scroll_point_' . intval( $resource_id ) . '", 10 ); }, 500 ); ' |
| 312 |
. wpbc_jq_ready_end() . '</script>' // FixIn: 10.1.3.7. |
| 313 |
. '</div>'; |
| 314 |
} |
| 315 |
|
| 316 |
|
| 317 |
$possible_output = ob_get_clean(); |
| 318 |
|
| 319 |
$return_str .= $possible_output; |
| 320 |
|
| 321 |
return $return_str; // return '<pre>' . var_export($confirmation_arr, true) . '</pre>'; |
| 322 |
} |
| 323 |
|