| 1 |
<?php /** |
| 2 |
* @version 1.0 |
| 3 |
* @description AJX_Bookings |
| 4 |
* @category AJX_Bookings Actions |
| 5 |
* @author wpdevelop |
| 6 |
* |
| 7 |
* @web-site http://oplugins.com/ |
| 8 |
* @email info@oplugins.com |
| 9 |
* |
| 10 |
* @modified 2022-06-10 |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 14 |
|
| 15 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 16 |
// Main Ajax handler |
| 17 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 18 |
|
| 19 |
/** |
| 20 |
* Ajax Actions - Get Listing Data and Response to JS script |
| 21 |
*/ |
| 22 |
function wpbc_ajax_WPBC_AJX_BOOKING_ACTIONS() { |
| 23 |
|
| 24 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 25 |
if ( ! isset( $_POST['action_params'] ) || empty( $_POST['action_params'] ) ) { |
| 26 |
exit; |
| 27 |
} |
| 28 |
|
| 29 |
$ajax_errors = new WPBC_AJAX_ERROR_CATCHING(); |
| 30 |
|
| 31 |
// Security ----------------------------------------------------------------------------------------------- // in Ajax Post: 'nonce': wpbc_ajx_booking_listing.get_secure_param( 'nonce' ), |
| 32 |
$action_name = 'wpbc_ajx_booking_listing_ajx' . '_wpbcnonce'; |
| 33 |
$nonce_post_key = 'nonce'; |
| 34 |
$result_check = check_ajax_referer( $action_name, $nonce_post_key ); |
| 35 |
|
| 36 |
$user_id = ( isset( $_REQUEST['wpbc_ajx_user_id'] ) ) ? intval( $_REQUEST['wpbc_ajx_user_id'] ) : wpbc_get_current_user_id(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 37 |
|
| 38 |
// Get clean Parameters for SQL --------------------------------------------------------------------------- |
| 39 |
$request_rules_structure = array( |
| 40 |
'booking_action' => array( 'validate' => array( |
| 41 |
'set_booking_locale', |
| 42 |
'set_booking_pending' , |
| 43 |
'set_booking_approved', |
| 44 |
'move_booking_to_trash', |
| 45 |
'restore_booking_from_trash', |
| 46 |
'delete_booking_completely', |
| 47 |
'set_booking_as_read', |
| 48 |
'set_booking_as_unread', |
| 49 |
'empty_trash', |
| 50 |
'set_booking_note', |
| 51 |
'change_booking_resource', |
| 52 |
'duplicate_booking_to_other_resource', |
| 53 |
'set_payment_status', |
| 54 |
'set_booking_cost', |
| 55 |
'send_payment_request', |
| 56 |
'import_google_calendar', |
| 57 |
'export_csv', |
| 58 |
'feedback_01' |
| 59 |
|
| 60 |
), 'default' => '' ), |
| 61 |
'booking_id' => array( 'validate' => 'digit_or_csd', 'default' => 0 ), |
| 62 |
'selected_resource_id' => array( 'validate' => 'd', 'default' => 0 ), |
| 63 |
'booking_meta_locale' => array( 'validate' => 's', 'default' => '' ), |
| 64 |
'reason_of_action' => array( 'validate' => 's', 'default' => '' ), |
| 65 |
'remark' => array( 'validate' => 's', 'default' => '' ), |
| 66 |
'ui_clicked_element_id' => array( 'validate' => 's', 'default' => '' ), |
| 67 |
'selected_payment_status' => array( 'validate' => 's', 'default' => '' ), |
| 68 |
'booking_cost' => array( 'validate' => 's', 'default' => '' ), |
| 69 |
|
| 70 |
'export_type' => array( 'validate' => array( 'csv_all', 'csv_page' ), 'default' => 'csv_page' ), |
| 71 |
'csv_export_separator' => array( 'validate' => array( 'semicolon', 'comma' ), 'default' => ';' ), |
| 72 |
'csv_export_skip_fields' => array( 'validate' => 's', 'default' => '' ), |
| 73 |
|
| 74 |
'booking_gcal_events_from' => array( 'validate' => 's', 'default' => '' ), |
| 75 |
'booking_gcal_events_from_offset' => array( 'validate' => 's', 'default' => '' ), |
| 76 |
'booking_gcal_events_from_offset_type' => array( 'validate' => 's', 'default' => '' ), |
| 77 |
'booking_gcal_events_until' => array( 'validate' => 's', 'default' => '' ), |
| 78 |
'booking_gcal_events_until_offset' => array( 'validate' => 's', 'default' => '' ), |
| 79 |
'booking_gcal_events_until_offset_type' => array( 'validate' => 's', 'default' => '' ), |
| 80 |
'booking_gcal_events_max' => array( 'validate' => 'd', 'default' => 25 ), |
| 81 |
'booking_gcal_resource' => array( 'validate' => 's', 'default' => '' ), |
| 82 |
|
| 83 |
'feedback__note' => array( 'validate' => 's', 'default' => '' ), |
| 84 |
'feedback_stars' => array( 'validate' => 'd', 'default' => 0 ) |
| 85 |
); |
| 86 |
|
| 87 |
$user_request = new WPBC_AJX__REQUEST( array( |
| 88 |
'db_option_name' => 'booking_listing_request_params', |
| 89 |
'user_id' => wpbc_get_current_user_id(), |
| 90 |
'request_rules_structure' => $request_rules_structure |
| 91 |
) |
| 92 |
); |
| 93 |
$request_prefix = 'action_params'; |
| 94 |
$request_params = $user_request->get_sanitized__in_request__value_or_default( $request_prefix ); // NOT Direct: $_REQUEST['action_params']['resource_id'] |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
$action_result = array(); |
| 101 |
|
| 102 |
switch ( $request_params['booking_action'] ) { |
| 103 |
|
| 104 |
case 'set_booking_locale': |
| 105 |
$action_result = wpbc_booking_do_action__set_booking_locale( $request_params['booking_id'] |
| 106 |
, array( |
| 107 |
'user_id' => $user_id, |
| 108 |
'booking_locale' => $request_params['booking_meta_locale'] |
| 109 |
) |
| 110 |
); |
| 111 |
break; |
| 112 |
|
| 113 |
case 'set_booking_pending': // Pending |
| 114 |
$action_result = wpbc_booking_do_action__set_booking_approved_or_pending( $request_params['booking_id'] |
| 115 |
, array( |
| 116 |
'user_id' => $user_id, |
| 117 |
'reason_of_action' => $request_params['reason_of_action'], |
| 118 |
'is_approve' => '0' |
| 119 |
) |
| 120 |
); |
| 121 |
break; |
| 122 |
|
| 123 |
case 'set_booking_approved': // Approve |
| 124 |
$action_result = wpbc_booking_do_action__set_booking_approved_or_pending( $request_params['booking_id'] |
| 125 |
, array( |
| 126 |
'user_id' => $user_id, |
| 127 |
'reason_of_action' => $request_params['reason_of_action'], |
| 128 |
'is_approve' => '1' |
| 129 |
) |
| 130 |
); |
| 131 |
break; |
| 132 |
|
| 133 |
case 'move_booking_to_trash': // Approve |
| 134 |
$action_result = wpbc_booking_do_action__trash_booking_or_restore( $request_params['booking_id'] |
| 135 |
, array( |
| 136 |
'user_id' => $user_id, |
| 137 |
'reason_of_action' => $request_params['reason_of_action'], |
| 138 |
'is_trash' => '1' |
| 139 |
) |
| 140 |
); |
| 141 |
break; |
| 142 |
|
| 143 |
case 'restore_booking_from_trash': |
| 144 |
$action_result = wpbc_booking_do_action__trash_booking_or_restore( $request_params['booking_id'] |
| 145 |
, array( |
| 146 |
'user_id' => $user_id, |
| 147 |
'reason_of_action' => $request_params['reason_of_action'], |
| 148 |
'is_trash' => '0' |
| 149 |
) |
| 150 |
); |
| 151 |
break; |
| 152 |
|
| 153 |
case 'delete_booking_completely': |
| 154 |
$action_result = wpbc_booking_do_action__delete_booking_completely( $request_params['booking_id'] |
| 155 |
, array( |
| 156 |
'user_id' => $user_id, |
| 157 |
'reason_of_action' => $request_params['reason_of_action'], |
| 158 |
) |
| 159 |
); |
| 160 |
break; |
| 161 |
|
| 162 |
case 'set_booking_as_read': |
| 163 |
$action_result = wpbc_booking_do_action__set_booking_as_read_unread( $request_params['booking_id'] |
| 164 |
, array( |
| 165 |
'user_id' => $user_id, |
| 166 |
'is_new' => '0' |
| 167 |
) |
| 168 |
); |
| 169 |
break; |
| 170 |
|
| 171 |
case 'set_booking_as_unread': |
| 172 |
$action_result = wpbc_booking_do_action__set_booking_as_read_unread( $request_params['booking_id'] |
| 173 |
, array( |
| 174 |
'user_id' => $user_id, |
| 175 |
'is_new' => '1' |
| 176 |
) |
| 177 |
); |
| 178 |
break; |
| 179 |
|
| 180 |
case 'empty_trash': |
| 181 |
$action_result = wpbc_booking_do_action__empty_trash( array( |
| 182 |
'user_id' => $user_id |
| 183 |
) ); |
| 184 |
break; |
| 185 |
|
| 186 |
case 'set_booking_note': |
| 187 |
$action_result = wpbc_booking_do_action__set_booking_note( $request_params['booking_id'] |
| 188 |
, array( |
| 189 |
'user_id' => $user_id, |
| 190 |
'remark' => $request_params['remark'], |
| 191 |
) |
| 192 |
); |
| 193 |
break; |
| 194 |
|
| 195 |
case 'change_booking_resource': // Pending |
| 196 |
$action_result = wpbc_booking_do_action__change_booking_resource( $request_params['booking_id'] |
| 197 |
, $request_params['selected_resource_id'] |
| 198 |
, array( |
| 199 |
'user_id' => $user_id |
| 200 |
) |
| 201 |
); |
| 202 |
break; |
| 203 |
case 'duplicate_booking_to_other_resource': |
| 204 |
$action_result = wpbc_booking_do_action__duplicate_booking_to_other_resource( $request_params['booking_id'] |
| 205 |
, $request_params['selected_resource_id'] |
| 206 |
, array( |
| 207 |
'user_id' => $user_id |
| 208 |
) |
| 209 |
); |
| 210 |
break; |
| 211 |
case 'set_payment_status': |
| 212 |
$action_result = wpbc_booking_do_action__set_payment_status( $request_params['booking_id'] |
| 213 |
, $request_params['selected_payment_status'] |
| 214 |
, array( |
| 215 |
'user_id' => $user_id |
| 216 |
) |
| 217 |
); |
| 218 |
break; |
| 219 |
case 'set_booking_cost': |
| 220 |
$action_result = wpbc_booking_do_action__set_booking_cost( $request_params['booking_id'] |
| 221 |
, $request_params['booking_cost'] |
| 222 |
, array( |
| 223 |
'user_id' => $user_id |
| 224 |
) |
| 225 |
); |
| 226 |
break; |
| 227 |
case 'send_payment_request': |
| 228 |
$action_result = wpbc_booking_do_action__send_payment_request( $request_params['booking_id'] |
| 229 |
, $request_params['reason_of_action'] |
| 230 |
, array( |
| 231 |
'user_id' => $user_id |
| 232 |
) |
| 233 |
); |
| 234 |
break; |
| 235 |
|
| 236 |
case 'import_google_calendar': |
| 237 |
$action_result = wpbc_booking_do_action__import_google_calendar( $request_params |
| 238 |
, array( |
| 239 |
'user_id' => $user_id |
| 240 |
) |
| 241 |
); |
| 242 |
break; |
| 243 |
|
| 244 |
case 'export_csv': |
| 245 |
|
| 246 |
$action_result = wpbc_booking_do_action__export_csv( $request_params |
| 247 |
, array( |
| 248 |
'user_id' => $user_id |
| 249 |
) |
| 250 |
); |
| 251 |
break; |
| 252 |
|
| 253 |
case 'feedback_01': |
| 254 |
|
| 255 |
$action_result = wpbc_booking_do_action__feedback_01( $request_params |
| 256 |
, array( |
| 257 |
'user_id' => $user_id |
| 258 |
) |
| 259 |
); |
| 260 |
break; |
| 261 |
|
| 262 |
default: |
| 263 |
} |
| 264 |
|
| 265 |
|
| 266 |
$defaults = array( |
| 267 |
'new_listing_params' => false // required for Import Google Calendar bookings |
| 268 |
, 'after_action_result' => false |
| 269 |
/* translators: 1: ... */ |
| 270 |
, 'after_action_message' => sprintf( __( 'No actions %s has been processed.', 'booking') |
| 271 |
, ' <strong>' . $request_params['booking_action'] . '</strong> ' ) |
| 272 |
); |
| 273 |
$action_result = wp_parse_args( $action_result, $defaults ); |
| 274 |
|
| 275 |
// Check if there were some errors -------------------------------------------------------------------------------- |
| 276 |
$error_messages = $ajax_errors->get_error_messages(); |
| 277 |
if ( ! empty( $error_messages ) ) { |
| 278 |
$action_result['after_action_message'] .= $error_messages; |
| 279 |
} |
| 280 |
|
| 281 |
// Hook for other integrations |
| 282 |
do_action( 'wpbc_' . $request_params['booking_action'], $request_params, $action_result ); // FixIn: 9.5.3.3. |
| 283 |
|
| 284 |
//------------------------------------------------------------------------------------------------------------------ |
| 285 |
// Send JSON. Its will make "wp_json_encode" - so pass only array, and This function call wp_die( '', '', array( 'response' => null, ) ) Pass JS OBJ: response_data in "jQuery.post( " function on success. |
| 286 |
wp_send_json( array( |
| 287 |
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 288 |
'ajx_action_params' => $_REQUEST['action_params'], // Do not clean input parameters. |
| 289 |
'ajx_cleaned_params' => $request_params, // Cleaned input parameters. |
| 290 |
'ajx_after_action_message' => $action_result['after_action_message'], // Message to show. |
| 291 |
'ajx_after_action_result' => (int) $action_result['after_action_result'], // Result key 0 | 1. |
| 292 |
'ajx_after_action_result_all_params_arr' => $action_result, // All result parameters. |
| 293 |
) ); |
| 294 |
} |
| 295 |
|
| 296 |
|
| 297 |
// <editor-fold defaultstate="collapsed" desc=" == Ajax Actions for bookings == " > |
| 298 |
|
| 299 |
/** |
| 300 |
* Action: set booking as Locale |
| 301 |
* |
| 302 |
* @param int $booking_id ID of booking 10 |
| 303 |
* @param $params |
| 304 |
* |
| 305 |
* @return array |
| 306 |
*/ |
| 307 |
function wpbc_booking_do_action__set_booking_locale( $booking_id, $params ){ |
| 308 |
|
| 309 |
$booking_locale = $params['booking_locale']; |
| 310 |
|
| 311 |
// LOG --------------------------------------------------------------------------------------------------------- |
| 312 |
$curr_user = get_user_by( 'id', (int) $params['user_id'] ); |
| 313 |
wpbc_db__add_log_info( $booking_id, |
| 314 |
/* translators: 1: ... */ |
| 315 |
sprintf( __( 'Booking locale changed to %s by:', 'booking' ), $booking_locale ) |
| 316 |
. ' ' . $curr_user->first_name . ' ' . $curr_user->last_name . ' (' . $curr_user->user_email . ')' |
| 317 |
); |
| 318 |
|
| 319 |
// Action --------------------------------------------------------------------------------------------------------- |
| 320 |
$option_arr = array( 'booking_meta_locale' => $booking_locale ); |
| 321 |
|
| 322 |
$result = wpbc_save_booking_meta_option( $booking_id, $option_arr ); |
| 323 |
|
| 324 |
if ( $result ) { |
| 325 |
$after_action_result = true; |
| 326 |
$after_action_message = ( ( false === strpos( $booking_id, ',' ) ) |
| 327 |
/* translators: 1: ... */ |
| 328 |
? sprintf( __( 'Booking has been changed locale to %s', 'booking' ), "<strong>{$booking_locale}</strong>" ) |
| 329 |
/* translators: 1: ... */ |
| 330 |
: sprintf( __( 'Bookings have been changed locale to %s', 'booking' ), "<strong>{$booking_locale}</strong>" ) |
| 331 |
) |
| 332 |
. ' <span style="font-size:0.9em;">( ID = <strong>' . $booking_id . '</strong> )</span>'; |
| 333 |
} else { |
| 334 |
$after_action_result = false; |
| 335 |
$after_action_message = ( ( false === strpos( $booking_id, ',' ) ) |
| 336 |
/* translators: 1: ... */ |
| 337 |
? sprintf( __( 'Booking has NOT been changed locale to %s', 'booking' ), "<strong>{$booking_locale}</strong>" ) |
| 338 |
/* translators: 1: ... */ |
| 339 |
: sprintf( __( 'Bookings have NOT been changed locale to %s', 'booking' ), "<strong>{$booking_locale}</strong>" ) |
| 340 |
) |
| 341 |
. ' <span style="font-size:0.9em;">( ID = <strong>' . $booking_id . '</strong> )</span>'; |
| 342 |
} |
| 343 |
|
| 344 |
return array( |
| 345 |
'after_action_result' => $after_action_result, |
| 346 |
'after_action_message' => $after_action_message |
| 347 |
); |
| 348 |
} |
| 349 |
|
| 350 |
/** |
| 351 |
* Action: Get Google Calendar Link |
| 352 |
* |
| 353 |
* @param $booking_data array( |
| 354 |
'form_data' => array( ... ) |
| 355 |
'form_show' => .... |
| 356 |
'dates_short' => array( ... ) |
| 357 |
) |
| 358 |
* |
| 359 |
* @return string URL of encoded link for adding to Google Calendar |
| 360 |
*/ |
| 361 |
function wpbc_booking_do_action__get_google_calendar_link( $booking_data ){ |
| 362 |
|
| 363 |
$params = array(); |
| 364 |
$params['timezone'] = get_bk_option('booking_gcal_timezone'); |
| 365 |
|
| 366 |
$booking_gcal_events_form_fields = maybe_unserialize( get_bk_option( 'booking_gcal_events_form_fields') ); // array( [title]=>text^name, [description]=>textarea^details, [where]=>text^ ) |
| 367 |
|
| 368 |
// Fields ---------------------------------------------------------------------------------------------------------- |
| 369 |
$fields = array( 'title' => '', 'description' => '', 'where' => '' ); |
| 370 |
|
| 371 |
foreach ( $fields as $key_name => $field_value ) { |
| 372 |
|
| 373 |
if ( ! empty( $booking_gcal_events_form_fields[ $key_name ] ) ) { |
| 374 |
|
| 375 |
$field_name = explode( '^', $booking_gcal_events_form_fields[ $key_name ] ); |
| 376 |
|
| 377 |
$field_name = $field_name[ ( count( $field_name ) - 1 ) ]; // FixIn: 8.7.7.6. |
| 378 |
|
| 379 |
if ( 'description' === $key_name ) { // FixIn: 8.1.3.2. |
| 380 |
|
| 381 |
if ( isset( $booking_data['form_show'] ) ) { // FixIn: 8.7.3.14. |
| 382 |
// FixIn: 8.7.11.4. |
| 383 |
$fields[ $key_name ] = $booking_data['form_show']; |
| 384 |
$fields[ $key_name ] = htmlspecialchars_decode($fields[ $key_name ], ENT_QUOTES ); |
| 385 |
$fields[ $key_name ] = urlencode($fields[ $key_name ]); |
| 386 |
$fields[ $key_name ] = htmlentities($fields[ $key_name ] ); |
| 387 |
$fields[ $key_name ] = htmlspecialchars_decode ( $fields[ $key_name ], ENT_NOQUOTES ); |
| 388 |
} |
| 389 |
|
| 390 |
} else if ( ( ! empty( $field_name ) ) |
| 391 |
&& ( ! empty( $booking_data['form_data'] ) ) |
| 392 |
&& ( ! empty( $booking_data['form_data'][ $field_name ] ) ) |
| 393 |
) { |
| 394 |
// FixIn: 8.7.11.4. |
| 395 |
$fields[ $key_name ] = $booking_data['form_data'][ $field_name ]; |
| 396 |
$fields[ $key_name ] = htmlspecialchars_decode($fields[ $key_name ], ENT_QUOTES ); |
| 397 |
/** |
| 398 |
* // Convert here from usual symbols to URL symbols https://www.url-encode-decode.com/ |
| 399 |
$fields[ $key_name ] = str_replace( array( '%','#', '+', '&' ) |
| 400 |
, array( '%25','%23', '%2B', '%26') |
| 401 |
, $fields[ $key_name ] |
| 402 |
); |
| 403 |
*/ |
| 404 |
$fields[ $key_name ] = urlencode($fields[ $key_name ]); |
| 405 |
$fields[ $key_name ] = htmlentities($fields[ $key_name ] ); |
| 406 |
$fields[ $key_name ] = htmlspecialchars_decode ( $fields[ $key_name ], ENT_NOQUOTES ); |
| 407 |
} |
| 408 |
} |
| 409 |
} |
| 410 |
|
| 411 |
// Dates ----------------------------------------------------------------------------------------------------------- |
| 412 |
$check_in_timestamp = $check_out_timestamp = ''; |
| 413 |
if ( ! empty( $booking_data[ 'dates_short' ] ) ) { |
| 414 |
|
| 415 |
/** |
| 416 |
* All day events, you can use 20161208/20161209 - note that the old google documentation gets it wrong. |
| 417 |
* You must use the following date as the end date for a one day all day event, |
| 418 |
* or +1 day to whatever you want the end date to be. |
| 419 |
*/ |
| 420 |
|
| 421 |
$check_in_timestamp = strtotime( $booking_data[ 'dates_short' ][ 0 ], current_time( 'timestamp' ) ); |
| 422 |
$check_out_timestamp = strtotime( $booking_data[ 'dates_short' ][ ( count( $booking_data[ 'dates_short' ] ) - 1 ) ], current_time( 'timestamp' ) ); |
| 423 |
|
| 424 |
if ( trim( substr( $booking_data[ 'dates_short' ][ 0 ], 11 ) ) == '00:00:00' ) { |
| 425 |
if ( trim( substr( $booking_data[ 'dates_short' ][ ( count( $booking_data[ 'dates_short' ] ) - 1 ) ], 11 ) ) == '00:00:00' ) { |
| 426 |
$check_in_timestamp = gmdate( "Ymd", $check_in_timestamp ); // All day |
| 427 |
} else { |
| 428 |
$check_in_timestamp = gmdate( "Ymd\T000000", $check_in_timestamp ); // All day starting on 00:00:00 // FixIn: 10.0.0.28. |
| 429 |
} |
| 430 |
} else { |
| 431 |
$check_in_timestamp = gmdate( "Ymd\THis", $check_in_timestamp ); //$check_in_timestamp = gmdate( "Ymd\THis\Z", $check_in_timestamp ); |
| 432 |
} |
| 433 |
|
| 434 |
if ( trim( substr( $booking_data[ 'dates_short' ][ ( count( $booking_data[ 'dates_short' ] ) - 1 ) ], 11 ) ) == '00:00:00' ) { |
| 435 |
$check_out_timestamp = strtotime( '+1 day', $check_out_timestamp ); |
| 436 |
$check_out_timestamp = gmdate( "Ymd", $check_out_timestamp ); // All day |
| 437 |
} else { |
| 438 |
$check_out_timestamp = gmdate( "Ymd\THis", $check_out_timestamp ); //$check_out_timestamp = gmdate( "Ymd\THis\Z", $check_out_timestamp ); |
| 439 |
} |
| 440 |
} |
| 441 |
|
| 442 |
// Link ----------------------------------------------------------------------------------------------------------- |
| 443 |
/** |
| 444 |
* Convert an ISO date/time to a UNIX timestamp |
| 445 |
function iso_to_ts( $iso ) { |
| 446 |
sscanf( $iso, "%u-%u-%uT%u:%u:%uZ", $year, $month, $day, $hour, $minute, $second ); |
| 447 |
return mktime( $hour, $minute, $second, $month, $day, $year ); |
| 448 |
20140127T224000Z |
| 449 |
gmdate("Ymd\THis\Z", time()); |
| 450 |
*/ |
| 451 |
|
| 452 |
/** |
| 453 |
* action: action=TEMPLATE |
| 454 |
A default required parameter. |
| 455 |
|
| 456 |
src: |
| 457 |
Example: src=default%40gmail.com |
| 458 |
Format: src=text |
| 459 |
This is not covered by Google help but is an optional parameter in order to add an event to a shared calendar rather than a user's default. |
| 460 |
|
| 461 |
text: |
| 462 |
Example: text=Garden%20Waste%20Collection |
| 463 |
Format: text=text |
| 464 |
This is a required parameter giving the event title. |
| 465 |
|
| 466 |
dates: |
| 467 |
Example: dates=20090621T063000Z/20090621T080000Z (i.e. an event on 21 June 2009 from 7.30am to 9.0am British Summer Time (=GMT+1)). |
| 468 |
Format: dates=YYYYMMDDToHHMMSSZ/YYYYMMDDToHHMMSSZ |
| 469 |
This required parameter gives the start and end dates and times (in Greenwich Mean Time) for the event. |
| 470 |
|
| 471 |
location: |
| 472 |
Example: location=Home |
| 473 |
Format: location=text |
| 474 |
The obvious location field. |
| 475 |
|
| 476 |
trp: |
| 477 |
Example: trp=false |
| 478 |
Format: trp=true/false |
| 479 |
Show event as busy (true) or available (false) |
| 480 |
|
| 481 |
sprop: |
| 482 |
Example: sprop=http%3A%2F%2Fwww.me.org |
| 483 |
Example: sprop=name:Home%20Page |
| 484 |
Format: sprop=website and/or sprop=name:website_name |
| 485 |
*/ |
| 486 |
|
| 487 |
//$link_add2gcal = 'http://www.google.com/calendar/event?action=TEMPLATE'; |
| 488 |
//$link_add2gcal .= '&text=' . $fields['title']; |
| 489 |
$link_add2gcal = 'https://calendar.google.com/calendar/r/eventedit?'; // FixIn: 8.7.3.10. |
| 490 |
$link_add2gcal .= 'text=' . $fields['title']; // FixIn: 8.7.11.4. |
| 491 |
$link_add2gcal .= '&dates=' . $check_in_timestamp . '/' . $check_out_timestamp; //$link_add2gcal .= '&dates=[start-custom format='Ymd\\THi00\\Z']/[end-custom format='Ymd\\THi00\\Z']'; |
| 492 |
$link_add2gcal .= '&details=' . ( ( 'On' !== get_bk_option( 'booking_g_cal_export_no_data' ) ) ? $fields['description'] : '' ); //FixIn: 10.3.0.1 // FixIn: 8.7.11.4. |
| 493 |
$link_add2gcal .= '&location=' . ( ( 'On' !== get_bk_option( 'booking_g_cal_export_no_data' ) ) ? $fields['where'] : '' ); // FixIn: 8.7.11.4. |
| 494 |
$link_add2gcal .= '&trp=false'; |
| 495 |
if ( ! empty( $params['timezone'] ) ) { |
| 496 |
$link_add2gcal .= '&ctz=' . str_replace( '%', '%25', $params['timezone'] ); //FixIn: 8.7.3.10 //TimeZone |
| 497 |
} |
| 498 |
//$link_add2gcal .= '&sprop='; |
| 499 |
//$link_add2gcal .= '&sprop=name:'; |
| 500 |
|
| 501 |
return $link_add2gcal; |
| 502 |
} |
| 503 |
|
| 504 |
/** |
| 505 |
* Action: move booking to Trash | Restore |
| 506 |
* |
| 507 |
* @param $booking_id_arr array or int of booking ID |
| 508 |
* @param $params array array of parameters: array( 'user_id' => 1, 'reason_of_action' => 'Because...', 'is_trash' => '1' ) |
| 509 |
* |
| 510 |
* @return array |
| 511 |
* |
| 512 |
* Example: |
| 513 |
*/ |
| 514 |
function wpbc_booking_do_action__trash_booking_or_restore( $booking_id_arr, $params ){ |
| 515 |
|
| 516 |
make_bk_action('check_multiuser_params_for_client_side_by_user_id', $params['user_id'] ); |
| 517 |
|
| 518 |
// Get ID list of bookings, like '1' or '3,7,9' ---------------------------------------------------------------- |
| 519 |
if ( ! is_array( $booking_id_arr ) ) { |
| 520 |
$booking_id_arr = array( $booking_id_arr ); |
| 521 |
} |
| 522 |
$booking_is_csd = join( ',', $booking_id_arr ); |
| 523 |
$booking_is_csd = wpbc_clean_digit_or_csd( $booking_is_csd ); |
| 524 |
|
| 525 |
|
| 526 |
// Get reason of action -------------------------------------------------------------------------------------------- |
| 527 |
$action_reason = $params['reason_of_action']; // stripslashes( $params['reason_of_action'] ); // translate words like don\'t to don't |
| 528 |
|
| 529 |
// Get reason of action -------------------------------------------------------------------------------------------- |
| 530 |
$is_trash_or_restore = $params['is_trash']; |
| 531 |
|
| 532 |
// Is send email for this action ---------------------------------------------------------------------------------- |
| 533 |
$is_send_emeils = wpbc_ajx__user_request_option__is_send_emails( $params['user_id'] ); |
| 534 |
|
| 535 |
|
| 536 |
// ----------------------------------------------------------------------------------------------------------------- |
| 537 |
|
| 538 |
if ( empty( $booking_is_csd ) ) { |
| 539 |
$after_action_result = false; |
| 540 |
$after_action_message = __( 'No bookings have been selected. Please select one or more bookings.', 'booking' ); |
| 541 |
|
| 542 |
} else { |
| 543 |
$after_action_result = true; |
| 544 |
if ( $is_trash_or_restore == '1' ) { |
| 545 |
$after_action_message = '<strong style="font-size: 1.4em;">' . count( explode( ',', $booking_is_csd ) ) .'</strong> ' |
| 546 |
. ( ( false === strpos( $booking_is_csd, ',' ) ) |
| 547 |
/* translators: 1: ... */ |
| 548 |
? sprintf( __( 'Booking has been %1$s trashed %2$s', 'booking' ), '<strong>', '</strong>' ) |
| 549 |
/* translators: 1: ... */ |
| 550 |
: sprintf( __( 'Bookings have been %1$s trashed %2$s', 'booking' ) , '<strong>', '</strong>' ) |
| 551 |
) |
| 552 |
. ' <span style="font-size:0.9em;">( ID = <strong>' . $booking_is_csd . '</strong> )</span>'; |
| 553 |
} else { |
| 554 |
$after_action_message = '<strong style="font-size: 1.4em;">' . count( explode( ',', $booking_is_csd ) ) .'</strong> ' |
| 555 |
. ( ( false === strpos( $booking_is_csd, ',' ) ) |
| 556 |
/* translators: 1: ... */ |
| 557 |
? sprintf( __( 'Booking has been set as %1$s restored %2$s', 'booking' ), '<strong>', '</strong>' ) |
| 558 |
/* translators: 1: ... */ |
| 559 |
: sprintf( __( 'Bookings have been set as %1$s restored %2$s', 'booking' ), '<strong>', '</strong>' ) |
| 560 |
) |
| 561 |
. ' <span style="font-size:0.9em;">( ID = <strong>' . $booking_is_csd . '</strong> )</span>'; |
| 562 |
} |
| 563 |
// SQL --------------------------------------------------------------------------------------------------- |
| 564 |
global $wpdb; |
| 565 |
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare, WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
| 566 |
$prepared_sql = $wpdb->prepare( "UPDATE {$wpdb->prefix}booking AS bk SET bk.trash = %s WHERE booking_id IN ({$booking_is_csd})", $is_trash_or_restore ); |
| 567 |
if ( $is_trash_or_restore == '1' ) { |
| 568 |
// Trash |
| 569 |
$my_trash_date = wpbc_datetime_localized( gmdate( 'Y-m-d H:i:s' ), 'Y-m-d H:i:s' ); |
| 570 |
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare, WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
| 571 |
$prepared_sql = $wpdb->prepare( "UPDATE {$wpdb->prefix}booking AS bk SET bk.trash = %s, bk.is_trash = %s WHERE booking_id IN ({$booking_is_csd})", $is_trash_or_restore, $my_trash_date ); |
| 572 |
} else { |
| 573 |
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare, WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
| 574 |
$prepared_sql = $wpdb->prepare( "UPDATE {$wpdb->prefix}booking AS bk SET bk.trash = %s, bk.is_trash = NULL WHERE booking_id IN ({$booking_is_csd})", $is_trash_or_restore ); |
| 575 |
} |
| 576 |
|
| 577 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared |
| 578 |
$after_action_result = $wpdb->query( $prepared_sql ); |
| 579 |
if ( false === $after_action_result ) { |
| 580 |
$after_action_message = 'Error during updating to DB. File:' . __FILE__ . ' on line: ' . __LINE__; |
| 581 |
} else { |
| 582 |
$after_action_result = true; |
| 583 |
} |
| 584 |
|
| 585 |
// Update the Hash and Cost of the booking |
| 586 |
$bk_id_arr = explode(',', $booking_is_csd ); // FixIn: 8.6.1.11. |
| 587 |
foreach ( $bk_id_arr as $bk_id ) { |
| 588 |
wpbc_hash__update_booking_hash( $bk_id ); |
| 589 |
} |
| 590 |
|
| 591 |
// LOG --------------------------------------------------------------------------------------------------------- |
| 592 |
$curr_user = get_user_by( 'id', (int) $params['user_id'] ); |
| 593 |
wpbc_db__add_log_info( explode( ',', $booking_is_csd ), |
| 594 |
( ( $is_trash_or_restore == '1' ) ? __( 'Trashed by:', 'booking' ) : __( 'Restored by:', 'booking' ) ) |
| 595 |
. ' ' . $curr_user->first_name . ' ' . $curr_user->last_name . ' (' . $curr_user->user_email . ')' |
| 596 |
); |
| 597 |
|
| 598 |
// :: ? :: Update 'is_new' status of bookings in Database |
| 599 |
// wpbc_db_update_number_new_bookings( explode( ',', $booking_is_csd ), '0', $params['user_id'] ); |
| 600 |
|
| 601 |
// Just action hook for some other addons |
| 602 |
do_action( 'wpbc_booking_action__trash', $booking_is_csd, $is_trash_or_restore ); // FixIn: 8.7.6.2. |
| 603 |
|
| 604 |
// Emails ------------------------------------------------------------------------------------------------------ |
| 605 |
if ( ! empty( $is_send_emeils ) ) { |
| 606 |
|
| 607 |
if ( $is_trash_or_restore == '1' ) { |
| 608 |
wpbc_send_email_trash( $booking_is_csd, $is_send_emeils, $action_reason ); |
| 609 |
} else { |
| 610 |
//wpbc_send_email_approved( $booking_is_csd, $is_send_emeils, $action_reason ); |
| 611 |
//wpbc_send_email_deny( $booking_is_csd, $is_send_emeils, $action_reason ); |
| 612 |
} |
| 613 |
} |
| 614 |
} |
| 615 |
|
| 616 |
return array( |
| 617 |
'after_action_result' => $after_action_result, |
| 618 |
'after_action_message' => $after_action_message |
| 619 |
); |
| 620 |
} |
| 621 |
|
| 622 |
/** |
| 623 |
* Action: set booking as Approved | Pending |
| 624 |
* |
| 625 |
* @param $booking_id_arr array or int of booking ID |
| 626 |
* @param $params array array of parameters: array( 'user_id' => 1, 'reason_of_action' => 'Because...', 'is_approve' => '1' ) |
| 627 |
* |
| 628 |
* @return array |
| 629 |
* |
| 630 |
* Example: |
| 631 |
* Approved: |
| 632 |
$action_result = wpbc_booking_do_action__set_booking_approved_or_pending( $request_params['booking_id'] |
| 633 |
, array( |
| 634 |
'user_id' => $user_id, |
| 635 |
'reason_of_action' => $request_params['reason_of_action'], |
| 636 |
'is_approve' => '1' |
| 637 |
) |
| 638 |
); |
| 639 |
* Pending: |
| 640 |
$action_result = wpbc_booking_do_action__set_booking_approved_or_pending( $request_params['booking_id'] |
| 641 |
, array( |
| 642 |
'user_id' => $user_id, |
| 643 |
'reason_of_action' => $request_params['reason_of_action'], |
| 644 |
'is_approve' => '0' |
| 645 |
) |
| 646 |
); |
| 647 |
*/ |
| 648 |
function wpbc_booking_do_action__set_booking_approved_or_pending( $booking_id_arr, $params ){ |
| 649 |
|
| 650 |
/** |
| 651 |
* |
| 652 |
* For creation of new bookings or editing use something like this: |
| 653 |
* |
| 654 |
// Be sure to make load in Booking Listing this: wp_enqueue_script( 'wpbc-main-client', wpbc_plugin_url( '/js/client.js' ), array( 'wpbc-datepick' ), WP_BK_VERSION_NUM, array( 'in_footer' => WPBC_JS_IN_FOOTER ) ); |
| 655 |
new wpdev_booking(); // Define ability to work with shortcodes |
| 656 |
$return_sh = do_shortcode('[booking type=1 nummonths=2]'); |
| 657 |
wp_send_json($return_sh); // Send calendar |
| 658 |
*/ |
| 659 |
|
| 660 |
make_bk_action('check_multiuser_params_for_client_side_by_user_id', $params['user_id'] ); |
| 661 |
|
| 662 |
// Get ID list of bookings, like '1' or '3,7,9' ---------------------------------------------------------------- |
| 663 |
if ( ! is_array( $booking_id_arr ) ) { |
| 664 |
$booking_id_arr = array( $booking_id_arr ); |
| 665 |
} |
| 666 |
$booking_id_csd = join( ',', $booking_id_arr ); |
| 667 |
$booking_id_csd = wpbc_clean_digit_or_csd( $booking_id_csd ); |
| 668 |
|
| 669 |
|
| 670 |
// Get reason of action -------------------------------------------------------------------------------------------- |
| 671 |
$action_reason = $params['reason_of_action']; // stripslashes( $params['reason_of_action'] ); // translate words like don\'t to don't |
| 672 |
|
| 673 |
// Get reason of action -------------------------------------------------------------------------------------------- |
| 674 |
$is_approve_or_pending = $params['is_approve']; |
| 675 |
|
| 676 |
// Is send email for this action ---------------------------------------------------------------------------------- |
| 677 |
$is_send_emeils = wpbc_ajx__user_request_option__is_send_emails( $params['user_id'] ); |
| 678 |
|
| 679 |
|
| 680 |
// ----------------------------------------------------------------------------------------------------------------- |
| 681 |
|
| 682 |
if ( empty( $booking_id_csd ) ) { |
| 683 |
$after_action_result = false; |
| 684 |
$after_action_message = __( 'No bookings have been selected. Please select one or more bookings.', 'booking' ); |
| 685 |
|
| 686 |
} else { |
| 687 |
$after_action_result = true; |
| 688 |
if ( $is_approve_or_pending == '1' ) { |
| 689 |
$after_action_message = '<strong style="font-size: 1.4em;">' . count( explode( ',', $booking_id_csd ) ) .'</strong> ' |
| 690 |
. ( ( false === strpos( $booking_id_csd, ',' ) ) |
| 691 |
/* translators: 1: ... */ |
| 692 |
? sprintf( __( 'Booking has been %1$s approved %2$s', 'booking' ), '<strong>', '</strong>' ) |
| 693 |
/* translators: 1: ... */ |
| 694 |
: sprintf( __( 'Bookings have been %1$s approved %2$s', 'booking' ) , '<strong>', '</strong>' ) |
| 695 |
) |
| 696 |
. ' <span style="font-size:0.9em;">( ID = <strong>' . $booking_id_csd . '</strong> )</span>'; |
| 697 |
} else { |
| 698 |
$after_action_message = '<strong style="font-size: 1.4em;">' . count( explode( ',', $booking_id_csd ) ) .'</strong> ' |
| 699 |
. ( ( false === strpos( $booking_id_csd, ',' ) ) |
| 700 |
/* translators: 1: ... */ |
| 701 |
? sprintf( __( 'Booking has been set as %1$s pending %2$s', 'booking' ), '<strong>', '</strong>' ) |
| 702 |
/* translators: 1: ... */ |
| 703 |
: sprintf( __( 'Bookings have been set as %1$s pending %2$s', 'booking' ), '<strong>', '</strong>' ) |
| 704 |
) |
| 705 |
. ' <span style="font-size:0.9em;">( ID = <strong>' . $booking_id_csd . '</strong> )</span>'; |
| 706 |
} |
| 707 |
// SQL --------------------------------------------------------------------------------------------------- |
| 708 |
global $wpdb; |
| 709 |
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare, WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
| 710 |
$prepared_sql = $wpdb->prepare( "UPDATE {$wpdb->prefix}bookingdates SET approved = %s WHERE booking_id IN ({$booking_id_csd})", $is_approve_or_pending ); |
| 711 |
|
| 712 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared |
| 713 |
$after_action_result = $wpdb->query( $prepared_sql ); |
| 714 |
if ( false === $after_action_result ) { |
| 715 |
$after_action_message = 'Error during updating to DB. File:' . __FILE__ . ' on line: ' . __LINE__; |
| 716 |
} else { |
| 717 |
$after_action_result = true; |
| 718 |
} |
| 719 |
|
| 720 |
// LOG --------------------------------------------------------------------------------------------------------- |
| 721 |
$curr_user = get_user_by( 'id', (int) $params['user_id'] ); |
| 722 |
wpbc_db__add_log_info( explode( ',', $booking_id_csd ), |
| 723 |
( ( $is_approve_or_pending == '1' ) ? __( 'Approved by:', 'booking' ) : __( 'Declined by:', 'booking' ) ) |
| 724 |
. ' ' . $curr_user->first_name . ' ' . $curr_user->last_name . ' (' . $curr_user->user_email . ')' |
| 725 |
); |
| 726 |
|
| 727 |
// Update 'is_new' status of bookings in Database |
| 728 |
wpbc_db_update_number_new_bookings( explode( ',', $booking_id_csd ), '0', $params['user_id'] ); |
| 729 |
|
| 730 |
// Just action hook for some other addons |
| 731 |
do_action( 'wpbc_booking_action__approved', $booking_id_csd, $is_approve_or_pending ); // FixIn: 8.7.6.1. |
| 732 |
|
| 733 |
// Emails ------------------------------------------------------------------------------------------------------ |
| 734 |
if ( ! empty( $is_send_emeils ) ) { |
| 735 |
|
| 736 |
if ( $is_approve_or_pending == '1' ) { |
| 737 |
wpbc_send_email_approved( $booking_id_csd, $is_send_emeils, $action_reason ); |
| 738 |
} else { |
| 739 |
wpbc_send_email_deny( $booking_id_csd, $is_send_emeils, $action_reason ); |
| 740 |
} |
| 741 |
} |
| 742 |
|
| 743 |
// Cancel other pending bookings for the same date ------------------------------------------------------------ |
| 744 |
if ( $is_approve_or_pending == '1' ) { |
| 745 |
$all_bk_id_what_canceled = apply_bk_filter( 'cancel_pending_same_resource_bookings_for_specific_dates', false, $booking_id_csd ); |
| 746 |
} |
| 747 |
} |
| 748 |
|
| 749 |
return array( |
| 750 |
'after_action_result' => $after_action_result, |
| 751 |
'after_action_message' => $after_action_message |
| 752 |
); |
| 753 |
} |
| 754 |
|
| 755 |
/** |
| 756 |
* Action: booking Completely Delete |
| 757 |
* |
| 758 |
* @param $booking_id_arr array or int of booking ID |
| 759 |
* @param $params array array of parameters: array( 'user_id' => 1, 'reason_of_action' => 'Because...' ) |
| 760 |
* |
| 761 |
* @return array |
| 762 |
* |
| 763 |
* Example: |
| 764 |
*/ |
| 765 |
function wpbc_booking_do_action__delete_booking_completely( $booking_id_arr, $params ){ |
| 766 |
|
| 767 |
make_bk_action('check_multiuser_params_for_client_side_by_user_id', $params['user_id'] ); |
| 768 |
|
| 769 |
// Get ID list of bookings, like '1' or '3,7,9' ---------------------------------------------------------------- |
| 770 |
if ( ! is_array( $booking_id_arr ) ) { |
| 771 |
$booking_id_arr = array( $booking_id_arr ); |
| 772 |
} |
| 773 |
$booking_is_csd = join( ',', $booking_id_arr ); |
| 774 |
$booking_is_csd = wpbc_clean_digit_or_csd( $booking_is_csd ); |
| 775 |
|
| 776 |
|
| 777 |
// Get reason of action -------------------------------------------------------------------------------------------- |
| 778 |
$action_reason = $params['reason_of_action']; // stripslashes( $params['reason_of_action'] ); // translate words like don\'t to don't |
| 779 |
|
| 780 |
// Is send email for this action ---------------------------------------------------------------------------------- |
| 781 |
$is_send_emeils = wpbc_ajx__user_request_option__is_send_emails( $params['user_id'] ); |
| 782 |
|
| 783 |
|
| 784 |
// ----------------------------------------------------------------------------------------------------------------- |
| 785 |
|
| 786 |
if ( empty( $booking_is_csd ) ) { |
| 787 |
$after_action_result = false; |
| 788 |
$after_action_message = __( 'No bookings have been selected. Please select one or more bookings.', 'booking' ); |
| 789 |
|
| 790 |
} else { |
| 791 |
$after_action_result = true; |
| 792 |
$bookings_count = '<strong style="font-size: 1.4em;">' . count( explode( ',', $booking_is_csd ) ) .'</strong> '; |
| 793 |
$after_action_message = $bookings_count . ' ' |
| 794 |
. ( ( false === strpos( $booking_is_csd, ',' ) ) |
| 795 |
/* translators: 1: ... */ |
| 796 |
? strtolower( sprintf( __( 'Booking has been %1$s deleted %2$s', 'booking' ), '<strong>', '</strong>' ) ) |
| 797 |
/* translators: 1: ... */ |
| 798 |
: strtolower( sprintf( __( 'Bookings have been %1$s deleted %2$s', 'booking' ) , '<strong>', '</strong>' ) ) |
| 799 |
) |
| 800 |
. ' <span style="font-size:0.9em;">( ID = <strong>' . implode( ', ', explode( ',', $booking_is_csd ) ) . '</strong> )</span>'; |
| 801 |
|
| 802 |
// LOG --------------------------------------------------------------------------------------------------------- |
| 803 |
$curr_user = get_user_by( 'id', (int) $params['user_id'] ); |
| 804 |
wpbc_db__add_log_info( explode( ',', $booking_is_csd ), |
| 805 |
__( 'Deleted by:', 'booking' ) |
| 806 |
. ' ' . $curr_user->first_name . ' ' . $curr_user->last_name . ' (' . $curr_user->user_email . ')' |
| 807 |
); |
| 808 |
|
| 809 |
// Just action hook for some other addons |
| 810 |
do_action( 'wpbc_booking_action__delete', $booking_is_csd ); // FixIn: 8.7.6.3. |
| 811 |
|
| 812 |
// Emails ------------------------------------------------------------------------------------------------------ |
| 813 |
if ( ! empty( $is_send_emeils ) ) { |
| 814 |
|
| 815 |
wpbc_send_email_deleted( $booking_is_csd, $is_send_emeils, $action_reason ); |
| 816 |
} |
| 817 |
|
| 818 |
// SQL --------------------------------------------------------------------------------------------------- |
| 819 |
global $wpdb; |
| 820 |
|
| 821 |
// Dates |
| 822 |
$prepared_sql = "DELETE FROM {$wpdb->prefix}bookingdates WHERE booking_id IN ({$booking_is_csd})"; |
| 823 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared |
| 824 |
$after_action_result = $wpdb->query( $prepared_sql ); |
| 825 |
if ( false === $after_action_result ) { |
| 826 |
$after_action_message = 'Error during deleting dates in DB. File:' . __FILE__ . ' on line: ' . __LINE__; |
| 827 |
} else { |
| 828 |
$after_action_result = true; |
| 829 |
} |
| 830 |
// Bookings |
| 831 |
$prepared_sql = "DELETE FROM {$wpdb->prefix}booking WHERE booking_id IN ({$booking_is_csd})"; |
| 832 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared |
| 833 |
$after_action_result = $wpdb->query( $prepared_sql ); |
| 834 |
if ( false === $after_action_result ) { |
| 835 |
$after_action_message = 'Error during deleting bookings in DB. File:' . __FILE__ . ' on line: ' . __LINE__; |
| 836 |
} else { |
| 837 |
$after_action_result = true; |
| 838 |
} |
| 839 |
|
| 840 |
} |
| 841 |
|
| 842 |
return array( |
| 843 |
'after_action_result' => $after_action_result, |
| 844 |
'after_action_message' => $after_action_message |
| 845 |
); |
| 846 |
} |
| 847 |
|
| 848 |
/** |
| 849 |
* Action: set booking as Read (Old) | Unread (New) |
| 850 |
* |
| 851 |
* @param $booking_id_arr array or int of booking ID |
| 852 |
* @param $params array array of parameters: array( 'user_id' => 1, 'is_new' => '1' ) |
| 853 |
* |
| 854 |
* @return array |
| 855 |
* |
| 856 |
* Example: |
| 857 |
$action_result = wpbc_booking_do_action__set_booking_as_read_unread( $request_params['booking_id'] |
| 858 |
, array( |
| 859 |
'user_id' => $user_id, |
| 860 |
'is_new' => '0' |
| 861 |
) |
| 862 |
); |
| 863 |
|
| 864 |
*/ |
| 865 |
function wpbc_booking_do_action__set_booking_as_read_unread( $booking_id_arr, $params ){ |
| 866 |
|
| 867 |
make_bk_action('check_multiuser_params_for_client_side_by_user_id', $params['user_id'] ); |
| 868 |
|
| 869 |
// Get ID list of bookings, like '1' or '3,7,9' ---------------------------------------------------------------- |
| 870 |
if ( ! is_array( $booking_id_arr ) ) { |
| 871 |
$booking_id_arr = array( $booking_id_arr ); |
| 872 |
} |
| 873 |
$booking_id_csd = join( ',', $booking_id_arr ); |
| 874 |
$booking_id_csd = wpbc_clean_digit_or_csd( $booking_id_csd ); |
| 875 |
|
| 876 |
// Get reason of action -------------------------------------------------------------------------------------------- |
| 877 |
$is_new = $params['is_new']; |
| 878 |
|
| 879 |
// Is send email for this action ---------------------------------------------------------------------------------- |
| 880 |
$is_send_emeils = wpbc_ajx__user_request_option__is_send_emails( $params['user_id'] ); |
| 881 |
|
| 882 |
// ----------------------------------------------------------------------------------------------------------------- |
| 883 |
|
| 884 |
if ( empty( $booking_id_csd ) ) { |
| 885 |
$after_action_result = false; |
| 886 |
$after_action_message = __( 'No bookings have been selected. Please select one or more bookings.', 'booking' ); |
| 887 |
|
| 888 |
} else { |
| 889 |
$after_action_result = true; |
| 890 |
if ( $is_new == '1' ) { |
| 891 |
$after_action_message = ( ( false === strpos( $booking_id_csd, ',' ) ) |
| 892 |
/* translators: 1: ... */ |
| 893 |
? sprintf( __( 'Booking has been set as %1$s new %2$s', 'booking' ), '<strong>', '</strong>' ) |
| 894 |
/* translators: 1: ... */ |
| 895 |
: sprintf( __( 'Bookings have been set as %1$s new %2$s', 'booking' ) , '<strong>', '</strong>' ) |
| 896 |
) |
| 897 |
. ' <span style="font-size:0.9em;">( ID = <strong>' . (( '-1' == $booking_id_csd ) ? __( 'all', 'booking' ) : $booking_id_csd) . '</strong> )</span>'; |
| 898 |
} else { |
| 899 |
$after_action_message = ( ( false === strpos( $booking_id_csd, ',' ) ) |
| 900 |
/* translators: 1: ... */ |
| 901 |
? sprintf( __( 'The booking has been marked as %1$s read %2$s', 'booking' ), '<strong>', '</strong>' ) |
| 902 |
/* translators: 1: ... */ |
| 903 |
: sprintf( __( 'Bookings have been marked as %1$s read %2$s', 'booking' ), '<strong>', '</strong>' ) |
| 904 |
) |
| 905 |
. ' <span style="font-size:0.9em;">( ID = <strong>' . (( '-1' == $booking_id_csd ) ? __( 'all', 'booking' ) : $booking_id_csd) . '</strong> )</span>'; |
| 906 |
} |
| 907 |
// SQL --------------------------------------------------------------------------------------------------- |
| 908 |
global $wpdb; |
| 909 |
if ('-1' == $booking_id_csd ){ |
| 910 |
$prepared_sql = $wpdb->prepare( "UPDATE {$wpdb->prefix}booking AS bk SET bk.is_new = %s", $is_new ); |
| 911 |
|
| 912 |
$prepared_sql .= " WHERE ( 1 = 1 ) "; |
| 913 |
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare, WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
| 914 |
$prepared_sql = apply_bk_filter('update_where_sql_for_getting_bookings_in_multiuser', $prepared_sql ); |
| 915 |
} else { |
| 916 |
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare, WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
| 917 |
$prepared_sql = $wpdb->prepare( "UPDATE {$wpdb->prefix}booking AS bk SET bk.is_new = %s WHERE booking_id IN ({$booking_id_csd})", $is_new ); |
| 918 |
} |
| 919 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared |
| 920 |
$after_action_result = $wpdb->query( $prepared_sql ); |
| 921 |
if ( false === $after_action_result ) { |
| 922 |
$after_action_message = 'Error during updating to DB. File:' . __FILE__ . ' on line: ' . __LINE__; |
| 923 |
} else { |
| 924 |
$after_action_result = true; |
| 925 |
} |
| 926 |
|
| 927 |
// LOG --------------------------------------------------------------------------------------------------------- |
| 928 |
$curr_user = get_user_by( 'id', (int) $params['user_id'] ); |
| 929 |
wpbc_db__add_log_info( explode( ',', $booking_id_csd ), |
| 930 |
( ( $is_new == '1' ) ? __( 'Set as unread by:', 'booking' ) : __( 'Set as read by:', 'booking' ) ) |
| 931 |
. ' ' . $curr_user->first_name . ' ' . $curr_user->last_name . ' (' . $curr_user->user_email . ')' |
| 932 |
); |
| 933 |
|
| 934 |
// Just action hook for some other addons |
| 935 |
do_action( 'wpbc_booking_action__changed_new_status', $booking_id_csd, $is_new ); // FixIn: 8.7.6.1. |
| 936 |
|
| 937 |
// Emails ------------------------------------------------------------------------------------------------------ |
| 938 |
if ( ! empty( $is_send_emeils ) ) { |
| 939 |
|
| 940 |
if ( $is_new == '1' ) { |
| 941 |
//wpbc_send_email_approved( $booking_id_csd, $is_send_emeils, $action_reason ); |
| 942 |
} else { |
| 943 |
//wpbc_send_email_deny( $booking_id_csd, $is_send_emeils, $action_reason ); |
| 944 |
} |
| 945 |
} |
| 946 |
} |
| 947 |
|
| 948 |
return array( |
| 949 |
'after_action_result' => $after_action_result, |
| 950 |
'after_action_message' => $after_action_message |
| 951 |
); |
| 952 |
} |
| 953 |
|
| 954 |
/** |
| 955 |
* Action: Emty Trash |
| 956 |
* |
| 957 |
* @param $params array array of parameters: array( 'user_id' => 1 ) |
| 958 |
* |
| 959 |
* @return array |
| 960 |
* |
| 961 |
* Example: |
| 962 |
*/ |
| 963 |
function wpbc_booking_do_action__empty_trash( $params ){ |
| 964 |
|
| 965 |
make_bk_action('check_multiuser_params_for_client_side_by_user_id', $params['user_id'] ); |
| 966 |
|
| 967 |
// Is send email for this action ---------------------------------------------------------------------------------- |
| 968 |
$is_send_emeils = wpbc_ajx__user_request_option__is_send_emails( $params['user_id'] ); |
| 969 |
|
| 970 |
// Get bookings ID to delete ------------------------------------------------------------------------------- |
| 971 |
global $wpdb; |
| 972 |
|
| 973 |
$sql = "SELECT * FROM {$wpdb->prefix}booking as bk WHERE bk.trash = 1"; |
| 974 |
|
| 975 |
$sql = apply_bk_filter( 'update_where_sql_for_getting_bookings_in_multiuser', $sql, $params['user_id'] ); // Get booking resources of this user only: $user_id |
| 976 |
|
| 977 |
$max_bookings_to_erase = 1000; |
| 978 |
$sql .= " LIMIT 0, " . $max_bookings_to_erase; |
| 979 |
|
| 980 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared |
| 981 |
$bookings_in_trash = $wpdb->get_results( $sql ); |
| 982 |
|
| 983 |
$bookings_id_in_trash_arr = array(); |
| 984 |
|
| 985 |
foreach ( $bookings_in_trash as $booking_obj ) { |
| 986 |
$bookings_id_in_trash_arr[] = $booking_obj->booking_id; |
| 987 |
} |
| 988 |
$booking_is_csd = implode( ',', $bookings_id_in_trash_arr ); |
| 989 |
|
| 990 |
// Empty trash ------------------------------------------------------------------------------------------------ |
| 991 |
|
| 992 |
if ( empty( $booking_is_csd ) ) { |
| 993 |
$after_action_result = false; |
| 994 |
$after_action_message = __( 'No bookings in trash to erase.', 'booking' ); |
| 995 |
|
| 996 |
} else { |
| 997 |
$after_action_result = true; |
| 998 |
if ( count( $bookings_id_in_trash_arr ) < $max_bookings_to_erase ) { |
| 999 |
$after_action_message = sprintf( __( 'Trash has been erased.', 'booking' ) , '<strong>', '</strong>' ) |
| 1000 |
. ' <span style="font-size:0.9em;">( ID = <strong>' . substr( $booking_is_csd, 0 , 500 ) . '</strong> )</span>'; |
| 1001 |
} else { |
| 1002 |
/* translators: 1: ... */ |
| 1003 |
$after_action_message = sprintf( __( 'From trash has been erased %s bookings.', 'booking' ) , '<strong> ' . count( $bookings_id_in_trash_arr ) . ' </strong> ' ) ; |
| 1004 |
} |
| 1005 |
|
| 1006 |
// LOG ----------------------------------------------------------------------------------------------------- |
| 1007 |
// $curr_user = get_user_by( 'id', (int) $params['user_id'] ); |
| 1008 |
// wpbc_db__add_log_info( explode( ',', $booking_is_csd ), |
| 1009 |
// __( 'Deleted by:', 'booking' ) |
| 1010 |
// . ' ' . $curr_user->first_name . ' ' . $curr_user->last_name . ' (' . $curr_user->user_email . ')' |
| 1011 |
// ); |
| 1012 |
|
| 1013 |
// Just action hook for some other addons |
| 1014 |
do_action( 'wpbc_booking_action__empty_trash' ); // FixIn: 8.7.6.3. |
| 1015 |
|
| 1016 |
// Emails ------------------------------------------------------------------------------------------------------ |
| 1017 |
if ( ! empty( $is_send_emeils ) ) { |
| 1018 |
|
| 1019 |
// wpbc_send_email_deleted( $booking_is_csd, $is_send_emeils, __( 'Empty Trash', 'booking' ) ); |
| 1020 |
} |
| 1021 |
|
| 1022 |
// SQL --------------------------------------------------------------------------------------------------- |
| 1023 |
|
| 1024 |
// Dates |
| 1025 |
$prepared_sql = "DELETE FROM {$wpdb->prefix}bookingdates WHERE booking_id IN ({$booking_is_csd})"; |
| 1026 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared |
| 1027 |
$after_action_result = $wpdb->query( $prepared_sql ); |
| 1028 |
if ( false === $after_action_result ) { |
| 1029 |
$after_action_message = 'Error during deleting dates in DB. File:' . __FILE__ . ' on line: ' . __LINE__; |
| 1030 |
} else { |
| 1031 |
$after_action_result = true; |
| 1032 |
} |
| 1033 |
// Bookings |
| 1034 |
$prepared_sql = "DELETE FROM {$wpdb->prefix}booking WHERE booking_id IN ({$booking_is_csd})"; |
| 1035 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared |
| 1036 |
$after_action_result = $wpdb->query( $prepared_sql ); |
| 1037 |
if ( false === $after_action_result ) { |
| 1038 |
$after_action_message = 'Error during deleting bookings in DB. File:' . __FILE__ . ' on line: ' . __LINE__; |
| 1039 |
} else { |
| 1040 |
$after_action_result = true; |
| 1041 |
} |
| 1042 |
|
| 1043 |
} |
| 1044 |
|
| 1045 |
return array( |
| 1046 |
'after_action_result' => $after_action_result, |
| 1047 |
'after_action_message' => $after_action_message |
| 1048 |
); |
| 1049 |
} |
| 1050 |
|
| 1051 |
/** |
| 1052 |
* Action: save booking Remark |
| 1053 |
* |
| 1054 |
* @param $booking_id_arr array or int of booking ID |
| 1055 |
* @param $params array array of parameters: array( 'user_id' => 1, 'remark' => 'Because...') |
| 1056 |
* |
| 1057 |
* @return array |
| 1058 |
* |
| 1059 |
* Example: |
| 1060 |
*/ |
| 1061 |
function wpbc_booking_do_action__set_booking_note( $booking_id_arr, $params ){ |
| 1062 |
|
| 1063 |
make_bk_action('check_multiuser_params_for_client_side_by_user_id', $params['user_id'] ); |
| 1064 |
|
| 1065 |
// Get ID list of bookings, like '1' or '3,7,9' ------------------------------------------------------------ |
| 1066 |
if ( ! is_array( $booking_id_arr ) ) { |
| 1067 |
$booking_id_arr = array( $booking_id_arr ); |
| 1068 |
} |
| 1069 |
$booking_id_csd = join( ',', $booking_id_arr ); |
| 1070 |
$booking_id_csd = wpbc_clean_digit_or_csd( $booking_id_csd ); |
| 1071 |
|
| 1072 |
// Get remark -------------------------------------------------------------------------------------------------- |
| 1073 |
$remark_text = $params['remark']; // stripslashes( $params['reason_of_action'] ); // translate words like don\'t to don't |
| 1074 |
|
| 1075 |
// Is send email for this action ------------------------------------------------------------------------------ |
| 1076 |
// $is_send_emeils = wpbc_ajx__user_request_option__is_send_emails( $params['user_id'] ); |
| 1077 |
|
| 1078 |
|
| 1079 |
// ----------------------------------------------------------------------------------------------------------------- |
| 1080 |
|
| 1081 |
if ( empty( $booking_id_csd ) ) { |
| 1082 |
$after_action_result = false; |
| 1083 |
$after_action_message = __( 'No bookings have been selected. Please select one or more bookings.', 'booking' ); |
| 1084 |
|
| 1085 |
} else { |
| 1086 |
$after_action_result = true; |
| 1087 |
$after_action_message = __( 'Note has been saved', 'booking' ) |
| 1088 |
. ' <span style="font-size:0.9em;">( ID = <strong>' . $booking_id_csd . '</strong> )</span>'; |
| 1089 |
// SQL --------------------------------------------------------------------------------------------------- |
| 1090 |
global $wpdb; |
| 1091 |
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare, WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
| 1092 |
$prepared_sql = $wpdb->prepare( "UPDATE {$wpdb->prefix}booking SET remark = %s WHERE booking_id IN ({$booking_id_csd})", $remark_text ); |
| 1093 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared |
| 1094 |
$after_action_result = $wpdb->query( $prepared_sql ); |
| 1095 |
if ( false === $after_action_result ) { |
| 1096 |
$after_action_message = 'Error during updating to DB. File:' . __FILE__ . ' on line: ' . __LINE__; |
| 1097 |
} else { |
| 1098 |
$after_action_result = true; |
| 1099 |
} |
| 1100 |
|
| 1101 |
// LOG --------------------------------------------------------------------------------------------------------- |
| 1102 |
if (0) { |
| 1103 |
$curr_user = get_user_by( 'id', (int) $params['user_id'] ); |
| 1104 |
wpbc_db__add_log_info( explode( ',', $booking_id_csd ), |
| 1105 |
__( 'Note saved by:', 'booking' ) |
| 1106 |
. ' ' . $curr_user->first_name . ' ' . $curr_user->last_name . ' (' . $curr_user->user_email . ')' |
| 1107 |
); |
| 1108 |
} |
| 1109 |
|
| 1110 |
// Just action hook for some other addons |
| 1111 |
do_action( 'wpbc_booking_action__note_saved', $booking_id_csd, $remark_text ); |
| 1112 |
|
| 1113 |
// Emails ------------------------------------------------------------------------------------------------------ |
| 1114 |
if ( 0 ) { |
| 1115 |
if ( ! empty( $is_send_emeils ) ) { |
| 1116 |
wpbc_send_email_approved( $booking_id_csd, $is_send_emeils, $remark_text ); |
| 1117 |
} |
| 1118 |
} |
| 1119 |
} |
| 1120 |
|
| 1121 |
return array( |
| 1122 |
'after_action_result' => $after_action_result, |
| 1123 |
'after_action_message' => $after_action_message |
| 1124 |
); |
| 1125 |
} |
| 1126 |
|
| 1127 |
/** |
| 1128 |
* Action: change Booking Resource |
| 1129 |
* |
| 1130 |
* @param $booking_id_arr array or int of booking ID |
| 1131 |
* @param $selected_resource_id int of booking resource |
| 1132 |
* @param $params array array of parameters: array( 'user_id' => 1 ) |
| 1133 |
* |
| 1134 |
* @return array |
| 1135 |
* |
| 1136 |
* Example: |
| 1137 |
*/ |
| 1138 |
function wpbc_booking_do_action__change_booking_resource( $booking_id_arr, $selected_resource_id, $params ) { |
| 1139 |
|
| 1140 |
make_bk_action('check_multiuser_params_for_client_side_by_user_id', $params['user_id'] ); |
| 1141 |
|
| 1142 |
// Get ID list of bookings, like '1' or '3,7,9' ---------------------------------------------------------------- |
| 1143 |
if ( ! is_array( $booking_id_arr ) ) { |
| 1144 |
$booking_id_arr = array( $booking_id_arr ); |
| 1145 |
} |
| 1146 |
$booking_id_csd = join( ',', $booking_id_arr ); |
| 1147 |
$booking_id_csd = wpbc_clean_digit_or_csd( $booking_id_csd ); |
| 1148 |
|
| 1149 |
// ID of booking resource ------------------------------------------------------------------------------------------ |
| 1150 |
$selected_resource_id = intval($selected_resource_id); |
| 1151 |
|
| 1152 |
// Is send email for this action ---------------------------------------------------------------------------------- |
| 1153 |
$is_send_emeils = wpbc_ajx__user_request_option__is_send_emails( $params['user_id'] ); |
| 1154 |
|
| 1155 |
// ----------------------------------------------------------------------------------------------------------------- |
| 1156 |
|
| 1157 |
if ( empty( $booking_id_csd ) ) { |
| 1158 |
$after_action_result = false; |
| 1159 |
$after_action_message = __( 'No bookings have been selected. Please select one or more bookings.', 'booking' ); |
| 1160 |
|
| 1161 |
} else { |
| 1162 |
$after_action_result = true; |
| 1163 |
|
| 1164 |
$after_action_message = ( ( false === strpos( $booking_id_csd, ',' ) ) |
| 1165 |
/* translators: 1: ... */ |
| 1166 |
? sprintf( __( 'Booking has been changed %1$s booking resource %2$s', 'booking' ), '<strong>', '</strong>' ) |
| 1167 |
/* translators: 1: ... */ |
| 1168 |
: sprintf( __( 'Bookings have been changed %1$s booking resource %2$s', 'booking' ), '<strong>', '</strong>' ) |
| 1169 |
) |
| 1170 |
. ' <span style="font-size:0.9em;">( ID = <strong>' . $booking_id_csd . '</strong> )</span>'; |
| 1171 |
|
| 1172 |
|
| 1173 |
$work_booking_id_arr = explode( ',', $booking_id_csd ); |
| 1174 |
|
| 1175 |
foreach ( $work_booking_id_arr as $selected_booking_id ) { |
| 1176 |
|
| 1177 |
// SQL --------------------------------------------------------------------------------------------------- |
| 1178 |
list( $after_action_result, $after_action_message, $formdata_new ) = wpbc__sql__change_booking_resource_for_booking( $selected_booking_id, $selected_resource_id ); |
| 1179 |
|
| 1180 |
if ( $after_action_result ) { |
| 1181 |
// LOG --------------------------------------------------------------------------------------------------------- |
| 1182 |
$curr_user = get_user_by( 'id', (int) $params['user_id'] ); |
| 1183 |
wpbc_db__add_log_info( explode( ',', $selected_booking_id ), |
| 1184 |
__( 'Booking resource changed by:', 'booking' ) |
| 1185 |
. ' ' . $curr_user->first_name . ' ' . $curr_user->last_name . ' (' . $curr_user->user_email . ')' |
| 1186 |
); |
| 1187 |
|
| 1188 |
// Just action hook for some other addons |
| 1189 |
do_action( 'wpbc_booking_action__change_booking_resource', $selected_booking_id, $selected_resource_id ); |
| 1190 |
|
| 1191 |
// Emails ------------------------------------------------------------------------------------------------------ |
| 1192 |
if ( ! empty( $is_send_emeils ) ) { |
| 1193 |
wpbc_send_email_modified( $selected_booking_id, $selected_resource_id, $formdata_new ); |
| 1194 |
} |
| 1195 |
} |
| 1196 |
} |
| 1197 |
} |
| 1198 |
|
| 1199 |
return array( |
| 1200 |
'after_action_result' => $after_action_result, |
| 1201 |
'after_action_message' => $after_action_message |
| 1202 |
); |
| 1203 |
|
| 1204 |
} |
| 1205 |
|
| 1206 |
/** |
| 1207 |
* Change booking resource for specific booking -- SQL manipulation |
| 1208 |
* @param $selected_booking_id |
| 1209 |
* @param $selected_resource_id |
| 1210 |
* |
| 1211 |
* @return array |
| 1212 |
*/ |
| 1213 |
function wpbc__sql__change_booking_resource_for_booking( $selected_booking_id, $selected_resource_id ){ |
| 1214 |
|
| 1215 |
global $wpdb; |
| 1216 |
|
| 1217 |
$booking_id = intval( $selected_booking_id ); |
| 1218 |
$resource_id = intval( $selected_resource_id ); |
| 1219 |
$db_form_data_new = ''; |
| 1220 |
|
| 1221 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 1222 |
// 1.Get dates of SOURCE booking |
| 1223 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 1224 |
if ( 1 ) { |
| 1225 |
// 1.1.Get booking data of SOURCE booking |
| 1226 |
$sql = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}booking as bk WHERE booking_id = %d ", $booking_id ); |
| 1227 |
|
| 1228 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared |
| 1229 |
$res = $wpdb->get_row( $sql ); |
| 1230 |
|
| 1231 |
$db_form_data_old = $res->form; |
| 1232 |
$resource_id_old = $res->booking_type; |
| 1233 |
|
| 1234 |
// 1.2. Get dates of SOURCE booking |
| 1235 |
$sql = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}bookingdates as dt WHERE booking_id = %d ORDER BY booking_date ASC ", $booking_id ); |
| 1236 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared |
| 1237 |
$old_resource_dates_array = $wpdb->get_results( $sql ); |
| 1238 |
} |
| 1239 |
|
| 1240 |
|
| 1241 |
//TODO: 2023-10-03 14:49 this is new workflow have to be: |
| 1242 |
if (0){ |
| 1243 |
$booking_p = array( |
| 1244 |
'dates' => TRANSFORM_IT( $old_resource_dates_array ) // -> array( '2017-06-23 14:00:01', '2017-06-24 00:00:00', '2017-06-25', '2017-06-26 12:00:02' ) |
| 1245 |
, 'resource_id' => $resource_id |
| 1246 |
, 'params' => array() // 'is_use_booking_recurrent_time' => false ) // Commented, because get from Booking > Settings General page |
| 1247 |
); |
| 1248 |
$is_dates_booked = wpbc_api_is_dates_booked( $booking_p[ 'dates' ], $booking_p[ 'resource_id' ], $booking_p[ 'params' ] ); |
| 1249 |
} |
| 1250 |
|
| 1251 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 1252 |
// 2. Get bookings of selected booking resource - checking if some dates there is booked or not |
| 1253 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 1254 |
$exist_dates_results = wpbc_get_booking_dates_in_resource_for_folowing_dates( $old_resource_dates_array , $resource_id ); |
| 1255 |
|
| 1256 |
|
| 1257 |
if ( ( count( $exist_dates_results ) == 3 ) && ( false === $exist_dates_results[0] ) ){ |
| 1258 |
// // ERROR :: number of check in/dates does not equal to number of check out dates. |
| 1259 |
return $exist_dates_results; |
| 1260 |
} |
| 1261 |
|
| 1262 |
if ( get_bk_option('booking_change_resource_skip_checking') === 'On' ) { // FixIn: 8.4.5.4. |
| 1263 |
$is_date_time_booked = false; |
| 1264 |
} else { |
| 1265 |
$is_date_time_booked = wpbc_check_dates_intersections( $old_resource_dates_array, $exist_dates_results ); |
| 1266 |
} |
| 1267 |
|
| 1268 |
if ( $is_date_time_booked ) { |
| 1269 |
|
| 1270 |
$after_action_result = false; |
| 1271 |
$after_action_message = __( 'Warning! The resource was not changed. Current dates are already booked there.', 'booking' ); |
| 1272 |
|
| 1273 |
} else { // Possible to change |
| 1274 |
|
| 1275 |
$db_form_data_new = wpbc_update_resource_id_in_dbformatted_booking_data( $db_form_data_old, $resource_id_old, $resource_id ); |
| 1276 |
|
| 1277 |
// Update |
| 1278 |
$update_sql = $wpdb->prepare( "UPDATE {$wpdb->prefix}booking AS bk SET bk.form=%s, bk.booking_type=%d WHERE bk.booking_id=%d;" |
| 1279 |
, $db_form_data_new, $resource_id, $booking_id ); |
| 1280 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared |
| 1281 |
if ( false === $wpdb->query( $update_sql ) ) { |
| 1282 |
$after_action_result = false; |
| 1283 |
$after_action_message = get_debuge_error( 'Error during updating booking reource type in BD', __FILE__, __LINE__ ); |
| 1284 |
|
| 1285 |
return array( $after_action_result, $after_action_message, $db_form_data_new ); |
| 1286 |
} |
| 1287 |
|
| 1288 |
|
| 1289 |
if ( class_exists( 'wpdev_bk_biz_l' ) ) { |
| 1290 |
$update_sql = $wpdb->prepare( "UPDATE {$wpdb->prefix}bookingdates SET type_id=NULL WHERE booking_id=%d ", $booking_id ); |
| 1291 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared |
| 1292 |
if ( false === $wpdb->query( $update_sql ) ) { |
| 1293 |
$after_action_result = false; |
| 1294 |
$after_action_message = get_debuge_error( 'Error during updating dates type in BD', __FILE__, __LINE__ ); |
| 1295 |
|
| 1296 |
return array( $after_action_result, $after_action_message, $db_form_data_new ); |
| 1297 |
} |
| 1298 |
} |
| 1299 |
|
| 1300 |
$booking_resources_arr = wpbc_ajx_get_all_booking_resources_arr(); |
| 1301 |
$after_action_result = true; |
| 1302 |
/* translators: 1: ... */ |
| 1303 |
$after_action_message = sprintf( __( 'Booking %1$s has been changed booking resource from %2$s to %3$s', 'booking' ) |
| 1304 |
, '<strong>[ID=' . $booking_id . ']</strong>' |
| 1305 |
, '<strong>' . wpbc_lang( $booking_resources_arr[ $resource_id_old ]['title'] ) . '</strong>' |
| 1306 |
, '<strong>' . wpbc_lang( $booking_resources_arr[ $resource_id ]['title'] ) . '</strong>' |
| 1307 |
); |
| 1308 |
|
| 1309 |
// Everything Cool :) - booking resource changed |
| 1310 |
} |
| 1311 |
|
| 1312 |
return array( $after_action_result, $after_action_message , $db_form_data_new ); |
| 1313 |
} |
| 1314 |
|
| 1315 |
/** |
| 1316 |
* Get booking dates (bookings obj) of selected booking resource - checking if some dates there is booked or not |
| 1317 |
* |
| 1318 |
* @param $old_resource_dates_array array of OBJ with ..->booking_date |
| 1319 |
* @param int $resource_id Resource ID, where we get dates. |
| 1320 |
* |
| 1321 |
* @return array array of booking OBJ with ..->booking_date |
| 1322 |
*/ |
| 1323 |
function wpbc_get_booking_dates_in_resource_for_folowing_dates( $old_resource_dates_array , $resource_id ){ |
| 1324 |
|
| 1325 |
global $wpdb; |
| 1326 |
|
| 1327 |
$dates_sql_between = ''; |
| 1328 |
$check_in_dates_arr = array(); |
| 1329 |
$check_out_dates_arr = array(); |
| 1330 |
|
| 1331 |
if ( 'On' === get_bk_option( 'booking_recurrent_time' ) ) { // If we are using recurrent time slots ? |
| 1332 |
|
| 1333 |
foreach ( $old_resource_dates_array as $k => $v ) { |
| 1334 |
|
| 1335 |
if ( ':02' == substr( $v->booking_date, - 3 ) ) { |
| 1336 |
$check_out_dates_arr[] = $v->booking_date; |
| 1337 |
} |
| 1338 |
if ( ':01' == substr( $v->booking_date, - 3 ) ) { |
| 1339 |
$check_in_dates_arr[] = $v->booking_date; |
| 1340 |
} |
| 1341 |
} |
| 1342 |
|
| 1343 |
if ( count( $check_out_dates_arr ) == count( $check_in_dates_arr ) ) { |
| 1344 |
$dates_sql_between_arr = array(); |
| 1345 |
foreach ( $check_in_dates_arr as $k => $v ) { |
| 1346 |
|
| 1347 |
$dates_sql_between_arr [] = ' ( dt.booking_date BETWEEN "' . $check_in_dates_arr[ $k ] . '" AND "' . $check_out_dates_arr[ $k ] . '" ) '; |
| 1348 |
} |
| 1349 |
$dates_sql_between = implode( 'OR', $dates_sql_between_arr ); |
| 1350 |
|
| 1351 |
//TODO: remove (), if only 1 element in array |
| 1352 |
|
| 1353 |
} else { |
| 1354 |
// ERROR :: number of check in/dates does not equal to number of check out dates. |
| 1355 |
$after_action_result = false; |
| 1356 |
$after_action_message = '<strong>Error</strong>. Number of check in times of booking dates does not equal to number of check out days.' |
| 1357 |
. '<br>Check in dates: ' . implode( ', ', $check_in_dates_arr ) |
| 1358 |
. '<br>Check out dates: ' . implode( ', ', $check_out_dates_arr ); |
| 1359 |
|
| 1360 |
return array( $after_action_result, $after_action_message, '' ); |
| 1361 |
} |
| 1362 |
} |
| 1363 |
|
| 1364 |
if ( '' == $dates_sql_between ) { |
| 1365 |
|
| 1366 |
$temp_check_in = $old_resource_dates_array[0]->booking_date; |
| 1367 |
$temp_check_out = $old_resource_dates_array[ ( count( $old_resource_dates_array ) - 1 ) ]->booking_date; |
| 1368 |
|
| 1369 |
if ( ':02' != substr( $temp_check_out, - 3 ) ) { |
| 1370 |
$temp_check_out = gmdate( 'Y-m-d H:i:s', strtotime( '+1 day -1 second', strtotime( $temp_check_out ) ) ); |
| 1371 |
} |
| 1372 |
|
| 1373 |
$dates_sql_between .= ' dt.booking_date BETWEEN "' . $temp_check_in . '" AND "' . $temp_check_out . '" '; |
| 1374 |
} |
| 1375 |
|
| 1376 |
|
| 1377 |
$sql = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}booking as bk |
| 1378 |
INNER JOIN {$wpdb->prefix}bookingdates as dt |
| 1379 |
ON bk.booking_id = dt.booking_id |
| 1380 |
WHERE bk.trash != 1 AND bk.booking_type = %d", $resource_id ); |
| 1381 |
$sql .= " AND ( {$dates_sql_between} ) "; |
| 1382 |
|
| 1383 |
// In BL version its does not check for booking belonging to several booking resources |
| 1384 |
if ( class_exists( 'wpdev_bk_biz_l' ) ) { |
| 1385 |
$sql .= " OR bk.booking_id IN ( " |
| 1386 |
. " SELECT DISTINCT booking_id FROM {$wpdb->prefix}bookingdates as dtt |
| 1387 |
WHERE dtt.type_id = {$resource_id} " |
| 1388 |
//."AND DATE(dt.booking_date) IN ( {$dates_string} )" |
| 1389 |
. " AND ( " . str_replace( 'dt.', 'dtt.', $dates_sql_between ) . " ) " |
| 1390 |
. ") "; |
| 1391 |
} |
| 1392 |
$sql .= " ORDER BY bk.booking_id DESC, dt.booking_date ASC "; |
| 1393 |
|
| 1394 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared |
| 1395 |
$exist_dates_results = $wpdb->get_results( $sql ); |
| 1396 |
|
| 1397 |
// We have found only intersected dates. Now we need to get all dates from such bookings, for having correct "Start and end time times for the booking" |
| 1398 |
// and does not add some "start time at the begining of the day inside of wpbc_check_dates_intersections( ) function |
| 1399 |
if ( count( $exist_dates_results ) > 0 ) { |
| 1400 |
|
| 1401 |
// Get ID of all bookings that inside of this interval |
| 1402 |
$my_booking_id_arr = []; |
| 1403 |
foreach ( $exist_dates_results as $key => $booking_obj ) { |
| 1404 |
$my_booking_id_arr[] = $booking_obj->booking_id; |
| 1405 |
} |
| 1406 |
// Get all dates of such bookings (not only intersected! |
| 1407 |
$sql = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}booking as bk |
| 1408 |
INNER JOIN {$wpdb->prefix}bookingdates as dt |
| 1409 |
ON bk.booking_id = dt.booking_id |
| 1410 |
WHERE bk.booking_id IN (" . implode( ',', $my_booking_id_arr ) . ") AND bk.trash != 1 AND bk.booking_type = %d", $resource_id ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 1411 |
$sql .= " ORDER BY bk.booking_id DESC, dt.booking_date ASC "; |
| 1412 |
|
| 1413 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared |
| 1414 |
$exist_dates_results = $wpdb->get_results( $sql ); |
| 1415 |
} |
| 1416 |
|
| 1417 |
return $exist_dates_results; |
| 1418 |
} |
| 1419 |
|
| 1420 |
/** |
| 1421 |
* Update "Content of booking fields data" from old booking resource id SUFFIX to new booking Resource ID |
| 1422 |
* |
| 1423 |
* @param string $db_form_data_old |
| 1424 |
* @param int $resource_id_old |
| 1425 |
* @param int $resource_id_new |
| 1426 |
* |
| 1427 |
* @return void |
| 1428 |
*/ |
| 1429 |
function wpbc_update_resource_id_in_dbformatted_booking_data( $db_form_data_old, $resource_id_old, $resource_id_new ) { |
| 1430 |
|
| 1431 |
$db_form_data_new = array(); |
| 1432 |
|
| 1433 |
$form_data_arr = explode( '~', $db_form_data_old ); |
| 1434 |
$fields_count = count( $form_data_arr ); |
| 1435 |
|
| 1436 |
for ( $i = 0; $i < $fields_count; $i ++ ) { |
| 1437 |
|
| 1438 |
list( $type, $element_name, $value ) = explode( '^', $form_data_arr[ $i ] ); |
| 1439 |
|
| 1440 |
if ( substr( $element_name, - 2 ) == '[]' ) { |
| 1441 |
$element_name = str_replace( '[]', '', $element_name ); |
| 1442 |
} |
| 1443 |
|
| 1444 |
$element_name = substr( $element_name, 0, - 1 * strlen( $resource_id_old ) ) . $resource_id_new; // Change resource ID in field |
| 1445 |
|
| 1446 |
$db_form_data_new[] = $type . '^' . $element_name . '^' . $value; |
| 1447 |
} |
| 1448 |
|
| 1449 |
return implode( '~', $db_form_data_new ); |
| 1450 |
} |
| 1451 |
|
| 1452 |
/** |
| 1453 |
* Action: Duplicate Booking into other Resource |
| 1454 |
* |
| 1455 |
* @param $booking_id_arr array or int of booking ID |
| 1456 |
* @param $selected_resource_id int of booking resource |
| 1457 |
* @param $params array array of parameters: array( 'user_id' => 1 ) |
| 1458 |
* |
| 1459 |
* @return array |
| 1460 |
* |
| 1461 |
* Example: |
| 1462 |
*/ |
| 1463 |
function wpbc_booking_do_action__duplicate_booking_to_other_resource( $booking_id_arr, $selected_resource_id, $params ) { |
| 1464 |
|
| 1465 |
make_bk_action('check_multiuser_params_for_client_side_by_user_id', $params['user_id'] ); |
| 1466 |
|
| 1467 |
// Get ID list of bookings, like '1' or '3,7,9' ---------------------------------------------------------------- |
| 1468 |
if ( ! is_array( $booking_id_arr ) ) { |
| 1469 |
$booking_id_arr = array( $booking_id_arr ); |
| 1470 |
} |
| 1471 |
$booking_id_csd = join( ',', $booking_id_arr ); |
| 1472 |
$booking_id_csd = wpbc_clean_digit_or_csd( $booking_id_csd ); |
| 1473 |
|
| 1474 |
// ID of booking resource ------------------------------------------------------------------------------------------ |
| 1475 |
$selected_resource_id = intval($selected_resource_id); |
| 1476 |
|
| 1477 |
// Is send email for this action ---------------------------------------------------------------------------------- |
| 1478 |
$is_send_emeils = wpbc_ajx__user_request_option__is_send_emails( $params['user_id'] ); |
| 1479 |
|
| 1480 |
// ----------------------------------------------------------------------------------------------------------------- |
| 1481 |
|
| 1482 |
if ( empty( $booking_id_csd ) ) { |
| 1483 |
$after_action_result = false; |
| 1484 |
$after_action_message = __( 'No bookings have been selected. Please select one or more bookings.', 'booking' ); |
| 1485 |
|
| 1486 |
} else { |
| 1487 |
$after_action_result = true; |
| 1488 |
|
| 1489 |
$after_action_message = ( ( false === strpos( $booking_id_csd, ',' ) ) |
| 1490 |
/* translators: 1: ... */ |
| 1491 |
? sprintf( __( 'Booking has been %1$s duplicated %2$s', 'booking' ), '<strong>', '</strong>' ) |
| 1492 |
/* translators: 1: ... */ |
| 1493 |
: sprintf( __( 'Bookings have been %1$s duplicated %2$s', 'booking' ), '<strong>', '</strong>' ) |
| 1494 |
) |
| 1495 |
. ' <span style="font-size:0.9em;">( ID = <strong>' . $booking_id_csd . '</strong> )</span>'; |
| 1496 |
|
| 1497 |
|
| 1498 |
$work_booking_id_arr = explode( ',', $booking_id_csd ); |
| 1499 |
|
| 1500 |
foreach ( $work_booking_id_arr as $selected_booking_id ) { |
| 1501 |
|
| 1502 |
// SQL --------------------------------------------------------------------------------------------------- |
| 1503 |
list( $after_action_result, $after_action_message, $formdata_new ) = wpbc__sql__duplicate_booking_to_other_resource_for_booking( $selected_booking_id, $selected_resource_id, $params ); |
| 1504 |
|
| 1505 |
if ( $after_action_result ) { |
| 1506 |
// LOG --------------------------------------------------------------------------------------------------------- |
| 1507 |
$curr_user = get_user_by( 'id', (int) $params['user_id'] ); |
| 1508 |
wpbc_db__add_log_info( explode( ',', $selected_booking_id ), |
| 1509 |
__( 'Booking resource changed by:', 'booking' ) |
| 1510 |
. ' ' . $curr_user->first_name . ' ' . $curr_user->last_name . ' (' . $curr_user->user_email . ')' |
| 1511 |
); |
| 1512 |
|
| 1513 |
// Just action hook for some other addons |
| 1514 |
do_action( 'wpbc_booking_action__duplicate_booking_to_other_resource', $selected_booking_id, $selected_resource_id ); |
| 1515 |
|
| 1516 |
// Emails ------------------------------------------------------------------------------------------------------ |
| 1517 |
if ( ! empty( $is_send_emeils ) ) { |
| 1518 |
// We are sending emails about the new booking, if we have created it. |
| 1519 |
// wpbc_send_email_modified( $selected_booking_id, $selected_resource_id, $formdata_new ); |
| 1520 |
} |
| 1521 |
} |
| 1522 |
} |
| 1523 |
} |
| 1524 |
|
| 1525 |
return array( |
| 1526 |
'after_action_result' => $after_action_result, |
| 1527 |
'after_action_message' => $after_action_message |
| 1528 |
); |
| 1529 |
|
| 1530 |
} |
| 1531 |
|
| 1532 |
/** |
| 1533 |
* Duplicate booking in another resource -- SQL manipulation |
| 1534 |
* @param $selected_booking_id |
| 1535 |
* @param $selected_resource_id |
| 1536 |
* |
| 1537 |
* @return array |
| 1538 |
*/ |
| 1539 |
function wpbc__sql__duplicate_booking_to_other_resource_for_booking( $selected_booking_id, $selected_resource_id, $params ){ |
| 1540 |
global $wpdb; |
| 1541 |
|
| 1542 |
$booking_id = intval( $selected_booking_id ); |
| 1543 |
$resource_id = intval( $selected_resource_id ); |
| 1544 |
$db_form_data_new = ''; |
| 1545 |
$booking_resources_arr = wpbc_ajx_get_all_booking_resources_arr(); |
| 1546 |
|
| 1547 |
$is_send_emails = wpbc_ajx__user_request_option__is_send_emails( $params['user_id'] ); |
| 1548 |
|
| 1549 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 1550 |
// 1.Get dates of SOURCE booking |
| 1551 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 1552 |
if ( 1 ) { |
| 1553 |
// 1.1.Get booking data of SOURCE booking |
| 1554 |
$sql = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}booking as bk WHERE booking_id = %d ", $booking_id ); |
| 1555 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared |
| 1556 |
$res = $wpdb->get_row( $sql ); |
| 1557 |
$db_form_data_old = $res->form; |
| 1558 |
$resource_id_old = $res->booking_type; |
| 1559 |
|
| 1560 |
// 1.2. Get dates of SOURCE booking |
| 1561 |
$sql = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}bookingdates as dt WHERE booking_id = %d ORDER BY booking_date ASC ", $booking_id ); |
| 1562 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared |
| 1563 |
$old_resource_dates_array = $wpdb->get_results( $sql ); |
| 1564 |
} |
| 1565 |
|
| 1566 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 1567 |
// 2. Get bookings of selected booking resource - checking if some dates there is booked or not |
| 1568 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 1569 |
$exist_dates_results = wpbc_get_booking_dates_in_resource_for_folowing_dates( $old_resource_dates_array , $resource_id ); |
| 1570 |
|
| 1571 |
if ( ( count( $exist_dates_results ) == 3 ) && ( false === $exist_dates_results[0] ) ){ |
| 1572 |
// // ERROR :: number of check in/dates does not equal to number of check out dates. |
| 1573 |
return $exist_dates_results; |
| 1574 |
} |
| 1575 |
|
| 1576 |
if ( get_bk_option('booking_change_resource_skip_checking') === 'On' ) { // FixIn: 8.4.5.4. |
| 1577 |
$is_date_time_booked = false; |
| 1578 |
} else { |
| 1579 |
$is_date_time_booked = wpbc_check_dates_intersections( $old_resource_dates_array, $exist_dates_results ); |
| 1580 |
} |
| 1581 |
|
| 1582 |
if ( $is_date_time_booked ) { |
| 1583 |
|
| 1584 |
$after_action_result = false; |
| 1585 |
$after_action_message = '<strong>' . esc_html__( 'Warning', 'booking' ) . '!</strong> ' |
| 1586 |
/* translators: 1: ... */ |
| 1587 |
. sprintf( __( 'Booking %1$s has not been duplicated in booking resource %2$s. Current dates are already booked there.' , 'booking' ) |
| 1588 |
, '<strong style="font-size:0.9em;">[ID=' . $booking_id . ']</strong>' |
| 1589 |
, '<strong>' . wpbc_lang( $booking_resources_arr[ $resource_id ]['title'] ) . '</strong>' |
| 1590 |
); |
| 1591 |
|
| 1592 |
} else { // Possible to change |
| 1593 |
|
| 1594 |
$db_form_data_new = wpbc_update_resource_id_in_dbformatted_booking_data( $db_form_data_old, $resource_id_old, $resource_id ); |
| 1595 |
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Recommended |
| 1596 |
$wpdev_active_locale = isset( $_REQUEST['wpbc_ajx_locale'] ) ? sanitize_text_field( $_REQUEST['wpbc_ajx_locale'] ) : 'en_US'; |
| 1597 |
|
| 1598 |
|
| 1599 |
// Change dates from DateObj( $selected_date->booking_date = '2015-10-17' ) to array ( '17.10.2015' ) |
| 1600 |
$my_dates_for_sql = array(); |
| 1601 |
foreach ($old_resource_dates_array as $selected_date) { |
| 1602 |
$selected_date = explode( '-', $selected_date->booking_date ); |
| 1603 |
$my_dates_for_sql[] = sprintf( "%02d.%02d.%04d", $selected_date[2], $selected_date[1], $selected_date[0] ); |
| 1604 |
} |
| 1605 |
$my_dates_for_sql = implode( ', ', $my_dates_for_sql ); |
| 1606 |
|
| 1607 |
// Create a new booking |
| 1608 |
$request_save_params = array( |
| 1609 |
'resource_id' => $resource_id, // 2 |
| 1610 |
'dates_ddmmyy_csv' => $my_dates_for_sql, // '04.10.2023, 05.10.2023, 06.10.2023' |
| 1611 |
'form_data' => $db_form_data_new, // 'text^cost_hint2^150.00฿~selectbox-multiple^rangetime2[]^14:00...' |
| 1612 |
'booking_hash' => '', // 'sdfsf34534rf' |
| 1613 |
'custom_form' => '', // 'custom_form_name' |
| 1614 |
'is_emails_send' => $is_send_emails, // 0 | 1 |
| 1615 |
'is_show_payment_form' => 0 // 0 | 1 |
| 1616 |
// 'request_uri' => $_SERVER['HTTP_REFERER'] |
| 1617 |
// 'user_id' => wpbc_get_current_user_id() |
| 1618 |
// 'sync_gid' => '' |
| 1619 |
// 'is_approve_booking' => 0 |
| 1620 |
); |
| 1621 |
$booking_save_arr = wpbc_booking_save( $request_save_params ); |
| 1622 |
|
| 1623 |
if ( 'ok' === $booking_save_arr['ajx_data']['status'] ) { // Everything Cool :) - booking has been duplicated |
| 1624 |
|
| 1625 |
$booking_id_new = $booking_save_arr['booking_id']; |
| 1626 |
$after_action_result = true; |
| 1627 |
/* translators: 1: ... */ |
| 1628 |
$after_action_message = sprintf( __( 'Booking %1$s has been duplicated in booking resource %2$s. New booking %3$s.', 'booking' ) |
| 1629 |
, '<strong style="font-size:0.9em;">[ID=' . $booking_id . ']</strong>' |
| 1630 |
, '<strong>' . wpbc_lang( $booking_resources_arr[ $resource_id ]['title'] ) . '</strong>' |
| 1631 |
, '<strong style="font-size:0.9em;">[ID=' . $booking_id_new . ']</strong>' |
| 1632 |
); |
| 1633 |
} else { // Error |
| 1634 |
$after_action_result = false; |
| 1635 |
$after_action_message = $booking_save_arr['ajx_data']['ajx_after_action_message']; |
| 1636 |
} |
| 1637 |
} |
| 1638 |
|
| 1639 |
return array( $after_action_result, $after_action_message , $db_form_data_new ); |
| 1640 |
} |
| 1641 |
|
| 1642 |
/** |
| 1643 |
* Action: Set payment status for the booking |
| 1644 |
* |
| 1645 |
* @param $booking_id_arr array or int of booking ID |
| 1646 |
* @param $selected_payment_status string payment status of booking |
| 1647 |
* @param $params array array of parameters: array( 'user_id' => 1 ) |
| 1648 |
* |
| 1649 |
* @return array |
| 1650 |
* |
| 1651 |
* Example: |
| 1652 |
*/ |
| 1653 |
function wpbc_booking_do_action__set_payment_status( $booking_id_arr, $selected_payment_status, $params ) { |
| 1654 |
|
| 1655 |
global $wpdb; |
| 1656 |
|
| 1657 |
make_bk_action('check_multiuser_params_for_client_side_by_user_id', $params['user_id'] ); |
| 1658 |
|
| 1659 |
// Get ID list of bookings, like '1' or '3,7,9' ---------------------------------------------------------------- |
| 1660 |
if ( ! is_array( $booking_id_arr ) ) { |
| 1661 |
$booking_id_arr = array( $booking_id_arr ); |
| 1662 |
} |
| 1663 |
$booking_id_csd = join( ',', $booking_id_arr ); |
| 1664 |
$booking_id_csd = wpbc_clean_digit_or_csd( $booking_id_csd ); |
| 1665 |
|
| 1666 |
|
| 1667 |
// Is send email for this action ---------------------------------------------------------------------------------- |
| 1668 |
$is_send_emeils = wpbc_ajx__user_request_option__is_send_emails( $params['user_id'] ); |
| 1669 |
|
| 1670 |
// ----------------------------------------------------------------------------------------------------------------- |
| 1671 |
|
| 1672 |
if ( empty( $booking_id_csd ) ) { |
| 1673 |
$after_action_result = false; |
| 1674 |
$after_action_message = __( 'No bookings have been selected. Please select one or more bookings.', 'booking' ); |
| 1675 |
|
| 1676 |
} else { |
| 1677 |
$after_action_result = true; |
| 1678 |
$after_action_message = ''; |
| 1679 |
|
| 1680 |
$work_booking_id_arr = explode( ',', $booking_id_csd ); |
| 1681 |
|
| 1682 |
foreach ( $work_booking_id_arr as $selected_booking_id ) { |
| 1683 |
|
| 1684 |
// SQL --------------------------------------------------------------------------------------------------- |
| 1685 |
$sql = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}booking as bk WHERE bk.booking_id= %d ", $selected_booking_id ); |
| 1686 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared |
| 1687 |
$result_bk = $wpdb->get_results( $sql ); |
| 1688 |
|
| 1689 |
$old_pay_status = ''; |
| 1690 |
|
| 1691 |
if ( ( 0 == count( $result_bk ) ) ) { |
| 1692 |
// Error |
| 1693 |
$after_action_result = false; |
| 1694 |
/* translators: 1: ... */ |
| 1695 |
$after_action_message .= sprintf( __( 'There is no booking %s', 'booking' ) |
| 1696 |
, ' <span style="font-size:0.9em;">( ID = <strong>' . $booking_id_csd . '</strong> )</span>' |
| 1697 |
); |
| 1698 |
} else { |
| 1699 |
$old_pay_status = $result_bk[0]->pay_status; |
| 1700 |
} |
| 1701 |
|
| 1702 |
$update_sql = $wpdb->prepare( "UPDATE {$wpdb->prefix}booking AS bk SET bk.pay_status= %s WHERE bk.booking_id= %d ", $selected_payment_status, $selected_booking_id ); |
| 1703 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared |
| 1704 |
if ( false === $wpdb->query( $update_sql ) ) { |
| 1705 |
// Error |
| 1706 |
$after_action_result = false; |
| 1707 |
$after_action_message .= 'Error during updating to DB. File:' . __FILE__ . ' on line: ' . __LINE__; |
| 1708 |
} else { |
| 1709 |
// Success |
| 1710 |
/* translators: 1: ... */ |
| 1711 |
$after_action_message .= sprintf( __( 'Payment status for Booking %1$s has been updated from %2$s to %3$s', 'booking' ) |
| 1712 |
, ' <span style="font-size:0.9em;">( ID = <strong>' . $selected_booking_id . '</strong> )</span>' |
| 1713 |
, '<strong>"' . wpbc__format__get_payment_status_title( $old_pay_status ) . '"</strong>' |
| 1714 |
, '<strong>"' . wpbc__format__get_payment_status_title( $selected_payment_status ) . '"</strong>' |
| 1715 |
) . '<br/>'; |
| 1716 |
} |
| 1717 |
|
| 1718 |
|
| 1719 |
if ( $after_action_result ) { |
| 1720 |
// LOG --------------------------------------------------------------------------------------------------------- |
| 1721 |
$curr_user = get_user_by( 'id', (int) $params['user_id'] ); |
| 1722 |
wpbc_db__add_log_info( explode( ',', $selected_booking_id ), |
| 1723 |
$after_action_message |
| 1724 |
. '. ' . __( 'Changed by:', 'booking' ) |
| 1725 |
. ' ' . $curr_user->first_name . ' ' . $curr_user->last_name . ' (' . $curr_user->user_email . ')' |
| 1726 |
); |
| 1727 |
|
| 1728 |
// Just action hook for some other addons |
| 1729 |
do_action( 'wpbc_booking_action__set_payment_status', $selected_booking_id, $selected_payment_status , $old_pay_status ); |
| 1730 |
|
| 1731 |
// Emails ------------------------------------------------------------------------------------------------------ |
| 1732 |
if ( ! empty( $is_send_emeils ) ) { |
| 1733 |
// We are sending emails about the new booking, if we have created it. |
| 1734 |
// wpbc_send_email_modified( $selected_booking_id, $selected_resource_id, $formdata_new ); |
| 1735 |
} |
| 1736 |
} |
| 1737 |
} |
| 1738 |
} |
| 1739 |
|
| 1740 |
return array( |
| 1741 |
'after_action_result' => $after_action_result, |
| 1742 |
'after_action_message' => $after_action_message |
| 1743 |
); |
| 1744 |
|
| 1745 |
} |
| 1746 |
|
| 1747 |
/** |
| 1748 |
* Get title of the payment status |
| 1749 |
* |
| 1750 |
* @param $payment_status_key |
| 1751 |
* |
| 1752 |
* @return string |
| 1753 |
*/ |
| 1754 |
function wpbc__format__get_payment_status_title( $payment_status_key ){ |
| 1755 |
|
| 1756 |
$selected_payment_status_text = $payment_status_key; |
| 1757 |
|
| 1758 |
$select_box_options = get_payment_status_titles(); |
| 1759 |
$select_box_options = array_flip( $select_box_options ); |
| 1760 |
|
| 1761 |
if ( ! empty( $select_box_options[ $payment_status_key ] ) ) { |
| 1762 |
$selected_payment_status_text = $select_box_options[ $payment_status_key ]; |
| 1763 |
} |
| 1764 |
|
| 1765 |
return $selected_payment_status_text; |
| 1766 |
} |
| 1767 |
|
| 1768 |
|
| 1769 |
/** |
| 1770 |
* Action: Set Booking Cost |
| 1771 |
* |
| 1772 |
* @param $booking_id_arr array or int of booking ID |
| 1773 |
* @param $booking_cost string booking cost |
| 1774 |
* @param $params array array of parameters: array( 'user_id' => 1 ) |
| 1775 |
* |
| 1776 |
* @return array |
| 1777 |
* |
| 1778 |
* Example: |
| 1779 |
*/ |
| 1780 |
function wpbc_booking_do_action__set_booking_cost( $booking_id_arr, $booking_cost, $params ) { |
| 1781 |
|
| 1782 |
global $wpdb; |
| 1783 |
|
| 1784 |
make_bk_action('check_multiuser_params_for_client_side_by_user_id', $params['user_id'] ); |
| 1785 |
|
| 1786 |
// Get ID list of bookings, like '1' or '3,7,9' ---------------------------------------------------------------- |
| 1787 |
if ( ! is_array( $booking_id_arr ) ) { |
| 1788 |
$booking_id_arr = array( $booking_id_arr ); |
| 1789 |
} |
| 1790 |
$booking_id_csd = join( ',', $booking_id_arr ); |
| 1791 |
$booking_id_csd = wpbc_clean_digit_or_csd( $booking_id_csd ); |
| 1792 |
|
| 1793 |
|
| 1794 |
// Is send email for this action ---------------------------------------------------------------------------------- |
| 1795 |
$is_send_emeils = wpbc_ajx__user_request_option__is_send_emails( $params['user_id'] ); |
| 1796 |
|
| 1797 |
// ----------------------------------------------------------------------------------------------------------------- |
| 1798 |
|
| 1799 |
$booking_cost = str_replace(',', '.', $booking_cost); |
| 1800 |
$booking_cost = floatval( $booking_cost ); |
| 1801 |
|
| 1802 |
|
| 1803 |
if ( empty( $booking_id_csd ) ) { |
| 1804 |
$after_action_result = false; |
| 1805 |
$after_action_message = __( 'No bookings have been selected. Please select one or more bookings.', 'booking' ); |
| 1806 |
|
| 1807 |
} else { |
| 1808 |
$after_action_result = true; |
| 1809 |
$after_action_message = ''; |
| 1810 |
|
| 1811 |
$work_booking_id_arr = explode( ',', $booking_id_csd ); |
| 1812 |
|
| 1813 |
foreach ( $work_booking_id_arr as $selected_booking_id ) { |
| 1814 |
|
| 1815 |
// SQL --------------------------------------------------------------------------------------------------- |
| 1816 |
$sql = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}booking as bk WHERE bk.booking_id= %d ", $selected_booking_id ); |
| 1817 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared |
| 1818 |
$result_bk = $wpdb->get_results( $sql ); |
| 1819 |
|
| 1820 |
$old_booking_cost = ''; |
| 1821 |
|
| 1822 |
if ( ( 0 == count( $result_bk ) ) ) { |
| 1823 |
// Error |
| 1824 |
$after_action_result = false; |
| 1825 |
/* translators: 1: ... */ |
| 1826 |
$after_action_message .= sprintf( __( 'There is no booking %s', 'booking' ) |
| 1827 |
, ' <span style="font-size:0.9em;">( ID = <strong>' . $booking_id_csd . '</strong> )</span>' |
| 1828 |
); |
| 1829 |
} else { |
| 1830 |
$old_booking_cost = $result_bk[0]->cost; |
| 1831 |
} |
| 1832 |
|
| 1833 |
$update_sql = $wpdb->prepare( "UPDATE {$wpdb->prefix}booking AS bk SET bk.cost = %f WHERE bk.booking_id = %d ", $booking_cost, $selected_booking_id ); |
| 1834 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared |
| 1835 |
if ( false === $wpdb->query( $update_sql ) ) { |
| 1836 |
// Error |
| 1837 |
$after_action_result = false; |
| 1838 |
$after_action_message .= 'Error during updating to DB. File:' . __FILE__ . ' on line: ' . __LINE__; |
| 1839 |
} else { |
| 1840 |
// Success |
| 1841 |
/* translators: 1: ... */ |
| 1842 |
$after_action_message .= sprintf( __( 'Cost for Booking %1$s has been updated from %2$s to %3$s', 'booking' ) |
| 1843 |
, ' <span style="font-size:0.9em;">( ID = <strong>' . $selected_booking_id . '</strong> )</span>' |
| 1844 |
, '<strong>"' . wpbc__format__get_payment_status_title( $old_booking_cost ) . '"</strong>' |
| 1845 |
, '<strong>"' . wpbc__format__get_payment_status_title( $booking_cost ) . '"</strong>' |
| 1846 |
) . '<br/>'; |
| 1847 |
} |
| 1848 |
|
| 1849 |
|
| 1850 |
if ( $after_action_result ) { |
| 1851 |
// LOG --------------------------------------------------------------------------------------------------------- |
| 1852 |
$curr_user = get_user_by( 'id', (int) $params['user_id'] ); |
| 1853 |
wpbc_db__add_log_info( explode( ',', $selected_booking_id ), |
| 1854 |
$after_action_message |
| 1855 |
. '. ' . __( 'Changed by:', 'booking' ) |
| 1856 |
. ' ' . $curr_user->first_name . ' ' . $curr_user->last_name . ' (' . $curr_user->user_email . ')' |
| 1857 |
); |
| 1858 |
|
| 1859 |
// Just action hook for some other addons |
| 1860 |
do_action( 'wpbc_booking_action__set_booking_cost', $selected_booking_id, $booking_cost , $old_booking_cost ); |
| 1861 |
|
| 1862 |
// Emails ------------------------------------------------------------------------------------------------------ |
| 1863 |
if ( ! empty( $is_send_emeils ) ) { |
| 1864 |
|
| 1865 |
if ( get_bk_option( 'booking_send_email_on_cost_change' ) == 'On' ) { // FixIn: 8.1.3.30. |
| 1866 |
$booking_data = apply_bk_filter( 'wpbc_get_booking_data', $selected_booking_id ); |
| 1867 |
wpbc_send_email_modified( $selected_booking_id, $booking_data['type'], $booking_data['form'] ); |
| 1868 |
} |
| 1869 |
} |
| 1870 |
|
| 1871 |
} |
| 1872 |
} |
| 1873 |
} |
| 1874 |
|
| 1875 |
return array( |
| 1876 |
'after_action_result' => $after_action_result, |
| 1877 |
'after_action_message' => $after_action_message |
| 1878 |
); |
| 1879 |
} |
| 1880 |
|
| 1881 |
|
| 1882 |
/** |
| 1883 |
* Action: Send Payment request |
| 1884 |
* |
| 1885 |
* @param $booking_id_arr array or int of booking ID |
| 1886 |
* @param $booking_cost string booking cost |
| 1887 |
* @param $params array array of parameters: array( 'user_id' => 1 ) |
| 1888 |
* |
| 1889 |
* @return array |
| 1890 |
*/ |
| 1891 |
function wpbc_booking_do_action__send_payment_request($booking_id_arr, $reason_of_action, $params ) { |
| 1892 |
global $wpdb; |
| 1893 |
|
| 1894 |
make_bk_action('check_multiuser_params_for_client_side_by_user_id', $params['user_id'] ); |
| 1895 |
|
| 1896 |
// Get ID list of bookings, like '1' or '3,7,9' ---------------------------------------------------------------- |
| 1897 |
if ( ! is_array( $booking_id_arr ) ) { |
| 1898 |
$booking_id_arr = array( $booking_id_arr ); |
| 1899 |
} |
| 1900 |
$booking_id_csd = join( ',', $booking_id_arr ); |
| 1901 |
$booking_id_csd = wpbc_clean_digit_or_csd( $booking_id_csd ); |
| 1902 |
|
| 1903 |
|
| 1904 |
// Is send email for this action ---------------------------------------------------------------------------------- |
| 1905 |
$is_send_emeils = wpbc_ajx__user_request_option__is_send_emails( $params['user_id'] ); |
| 1906 |
|
| 1907 |
// ----------------------------------------------------------------------------------------------------------------- |
| 1908 |
|
| 1909 |
if ( empty( $booking_id_csd ) ) { |
| 1910 |
$after_action_result = false; |
| 1911 |
$after_action_message = __( 'No bookings have been selected. Please select one or more bookings.', 'booking' ); |
| 1912 |
|
| 1913 |
} else { |
| 1914 |
$after_action_result = true; |
| 1915 |
$after_action_message = ''; |
| 1916 |
|
| 1917 |
$work_booking_id_arr = explode( ',', $booking_id_csd ); |
| 1918 |
|
| 1919 |
foreach ( $work_booking_id_arr as $selected_booking_id ) { |
| 1920 |
|
| 1921 |
// SQL --------------------------------------------------------------------------------------------------- |
| 1922 |
$sql = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}booking as bk WHERE bk.booking_id= %d ", $selected_booking_id ); |
| 1923 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared |
| 1924 |
$result_bk = $wpdb->get_results( $sql ); |
| 1925 |
|
| 1926 |
$old_booking_cost = ''; |
| 1927 |
|
| 1928 |
if ( ( 0 == count( $result_bk ) ) ) { |
| 1929 |
// Error |
| 1930 |
$after_action_result = false; |
| 1931 |
/* translators: 1: ... */ |
| 1932 |
$after_action_message .= sprintf( __( 'There is no booking %s', 'booking' ) |
| 1933 |
, ' <span style="font-size:0.9em;">( ID = <strong>' . $booking_id_csd . '</strong> )</span>' |
| 1934 |
); |
| 1935 |
} else { |
| 1936 |
$old_booking_cost = $result_bk[0]->cost; |
| 1937 |
|
| 1938 |
$is_email_payment_request_adress = get_bk_option( 'booking_is_email_payment_request_adress' ); |
| 1939 |
if ( 'Off' != $is_email_payment_request_adress ) { |
| 1940 |
|
| 1941 |
$reason_of_action = htmlspecialchars( str_replace( '\"', '"', $reason_of_action ) ); |
| 1942 |
$reason_of_action = str_replace( "\'", "'", $reason_of_action ); |
| 1943 |
|
| 1944 |
foreach ( $result_bk as $res ) { |
| 1945 |
|
| 1946 |
$is_send = wpbc_send_email_payment_request( $res->booking_id, $res->booking_type, $res->form, $reason_of_action ); |
| 1947 |
|
| 1948 |
if ( $is_send ) { |
| 1949 |
// Update Payment request number |
| 1950 |
$pay_request_numer = $res->pay_request + 1; |
| 1951 |
$update_sql = $wpdb->prepare( "UPDATE {$wpdb->prefix}booking AS bk SET bk.pay_request= %d WHERE bk.booking_id= %d ", $pay_request_numer, $res->booking_id ); |
| 1952 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared |
| 1953 |
if ( false === $wpdb->query( $update_sql ) ) { |
| 1954 |
// Error |
| 1955 |
$after_action_result = false; |
| 1956 |
$after_action_message .= 'Error during updating to DB. File:' . __FILE__ . ' on line: ' . __LINE__; |
| 1957 |
} else { |
| 1958 |
// Success |
| 1959 |
/* translators: 1: ... */ |
| 1960 |
$after_action_message .= sprintf( __( 'Payment request for Booking %1$s has been sent. Cost for payment: %2$s', 'booking' ) |
| 1961 |
, ' <span style="font-size:0.9em;">( ID = <strong>' . $selected_booking_id . '</strong> )</span>' |
| 1962 |
, '<strong>"' . wpbc__format__get_payment_status_title( $old_booking_cost ) . '"</strong>' |
| 1963 |
) . '<br/>'; |
| 1964 |
} |
| 1965 |
} |
| 1966 |
} |
| 1967 |
} |
| 1968 |
} |
| 1969 |
|
| 1970 |
if ( $after_action_result ) { |
| 1971 |
// LOG --------------------------------------------------------------------------------------------------------- |
| 1972 |
$curr_user = get_user_by( 'id', (int) $params['user_id'] ); |
| 1973 |
wpbc_db__add_log_info( explode( ',', $selected_booking_id ), |
| 1974 |
$after_action_message |
| 1975 |
. '. ' . __( 'Send by:', 'booking' ) |
| 1976 |
. ' ' . $curr_user->first_name . ' ' . $curr_user->last_name . ' (' . $curr_user->user_email . ')' |
| 1977 |
); |
| 1978 |
|
| 1979 |
// Just action hook for some other addons |
| 1980 |
do_action( 'wpbc_booking_action__send_payment_request', $selected_booking_id, $reason_of_action , $old_booking_cost ); |
| 1981 |
|
| 1982 |
// Emails ------------------------------------------------------------------------------------------------------ |
| 1983 |
/* |
| 1984 |
if ( ! empty( $is_send_emeils ) ) { |
| 1985 |
|
| 1986 |
if ( get_bk_option( 'booking_send_email_on_cost_change' ) == 'On' ) { |
| 1987 |
$booking_data = apply_bk_filter( 'wpbc_get_booking_data', $selected_booking_id ); |
| 1988 |
wpbc_send_email_modified( $selected_booking_id, $booking_data['type'], $booking_data['form'] ); |
| 1989 |
} |
| 1990 |
} |
| 1991 |
*/ |
| 1992 |
} |
| 1993 |
} |
| 1994 |
|
| 1995 |
} |
| 1996 |
|
| 1997 |
return array( |
| 1998 |
'after_action_result' => $after_action_result, |
| 1999 |
'after_action_message' => $after_action_message |
| 2000 |
); |
| 2001 |
} |
| 2002 |
|
| 2003 |
|
| 2004 |
function wpbc_booking_do_action__import_google_calendar( $request_params, $params ) { |
| 2005 |
|
| 2006 |
$return_array = array(); |
| 2007 |
|
| 2008 |
$user_bk_id = (int) $params['user_id']; |
| 2009 |
|
| 2010 |
global $wpdb; |
| 2011 |
|
| 2012 |
$wpbc_Google_Calendar = new WPBC_Google_Calendar(); |
| 2013 |
|
| 2014 |
$wpbc_Google_Calendar->setSilent(); |
| 2015 |
|
| 2016 |
$wpbc_Google_Calendar->set_timezone( get_bk_option('booking_gcal_timezone') ); |
| 2017 |
|
| 2018 |
$wpbc_Google_Calendar->set_events_from_with_array( array( |
| 2019 |
$request_params['booking_gcal_events_from'], |
| 2020 |
$request_params['booking_gcal_events_from_offset'], |
| 2021 |
$request_params['booking_gcal_events_from_offset_type'] |
| 2022 |
) ); |
| 2023 |
|
| 2024 |
$wpbc_Google_Calendar->set_events_until_with_array( array( |
| 2025 |
$request_params['booking_gcal_events_until'], |
| 2026 |
$request_params['booking_gcal_events_until_offset'], |
| 2027 |
$request_params['booking_gcal_events_until_offset_type'] |
| 2028 |
) ); |
| 2029 |
|
| 2030 |
$wpbc_Google_Calendar->set_events_max( $request_params['booking_gcal_events_max'] ); |
| 2031 |
|
| 2032 |
if ( ( isset( $request_params['booking_gcal_resource'] ) ) && ( empty( $request_params['booking_gcal_resource'] ) ) ) { |
| 2033 |
|
| 2034 |
$wpbc_Google_Calendar->setUrl( get_bk_option( 'booking_gcal_feed') ); |
| 2035 |
$import_result = $wpbc_Google_Calendar->run(); |
| 2036 |
|
| 2037 |
} else { |
| 2038 |
|
| 2039 |
if ( $request_params['booking_gcal_resource'] != 'all' ) { // One resource |
| 2040 |
|
| 2041 |
$wpbc_booking_resource_id = intval( $request_params['booking_gcal_resource'] ); |
| 2042 |
|
| 2043 |
$wpbc_Google_Calendar->setResource( $wpbc_booking_resource_id ); |
| 2044 |
|
| 2045 |
$wpbc_booking_resource_feed = get_booking_resource_attr( $wpbc_booking_resource_id ); |
| 2046 |
$wpbc_booking_resource_feed = $wpbc_booking_resource_feed->import; |
| 2047 |
$wpbc_Google_Calendar->setUrl( $wpbc_booking_resource_feed ); |
| 2048 |
|
| 2049 |
$import_result = $wpbc_Google_Calendar->run(); |
| 2050 |
} else { // All resources |
| 2051 |
|
| 2052 |
$where = ''; // Where for the different situation: BL and MU |
| 2053 |
|
| 2054 |
if ( class_exists( 'wpdev_bk_multiuser' ) ) { // MultiUser - only specific booking resources for specific Regular User in Admin panel. |
| 2055 |
|
| 2056 |
$is_user_super_admin = apply_bk_filter( 'is_user_super_admin', $user_bk_id ); |
| 2057 |
|
| 2058 |
if ( ! $is_user_super_admin ) { |
| 2059 |
$where .= ' WHERE users = ' . intval( $user_bk_id ) . ' '; |
| 2060 |
} |
| 2061 |
} |
| 2062 |
|
| 2063 |
$my_sql = "SELECT booking_type_id, import FROM {$wpdb->prefix}bookingtypes {$where}"; |
| 2064 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared |
| 2065 |
$types_list = $wpdb->get_results( $my_sql ); |
| 2066 |
|
| 2067 |
foreach ($types_list as $wpbc_booking_resource) { |
| 2068 |
$wpbc_booking_resource_id = $wpbc_booking_resource->booking_type_id; |
| 2069 |
$wpbc_booking_resource_feed = $wpbc_booking_resource->import; |
| 2070 |
if ( ( ! empty( $wpbc_booking_resource_feed ) ) && ( $wpbc_booking_resource_feed != null ) && ( $wpbc_booking_resource_feed != '/' ) ) { |
| 2071 |
|
| 2072 |
$wpbc_Google_Calendar->setUrl( $wpbc_booking_resource_feed ); |
| 2073 |
$wpbc_Google_Calendar->setResource( $wpbc_booking_resource_id ); |
| 2074 |
$import_result = $wpbc_Google_Calendar->run(); |
| 2075 |
} |
| 2076 |
} |
| 2077 |
} |
| 2078 |
} |
| 2079 |
|
| 2080 |
|
| 2081 |
if ( ( isset( $import_result ) ) && ( false != $import_result ) ) { |
| 2082 |
$after_action_result = true; |
| 2083 |
/* translators: 1: ... */ |
| 2084 |
$after_action_message = sprintf( __( '%s new bookings have been imported', 'booking' ) |
| 2085 |
, ' <span style="font-size:1em;"> <strong>' . count( $wpbc_Google_Calendar->events ) . '</strong> </span>' |
| 2086 |
) ; |
| 2087 |
if ( 0 != count( $wpbc_Google_Calendar->events ) ) { |
| 2088 |
$after_action_message .= '<br/><br/>' . esc_html__( 'The filter settings have been updated to reflect these imported bookings. The page will be reloaded.', 'booking' ); |
| 2089 |
} |
| 2090 |
|
| 2091 |
if ( ! empty( $wpbc_Google_Calendar->getErrorMessage() ) ) { |
| 2092 |
$after_action_message .= '<div style="max-width:60rem;margin:2em 10px;">' . $wpbc_Google_Calendar->getErrorMessage() . '</div>'; |
| 2093 |
$return_array['after_action_result_delay'] = 100000000000000; |
| 2094 |
} |
| 2095 |
|
| 2096 |
} else { |
| 2097 |
$after_action_result = false; |
| 2098 |
$after_action_message = __( 'No bookings have been imported.', 'booking' ) |
| 2099 |
. '<br/><br/>' |
| 2100 |
. sprintf( __( 'Please configure settings for import Google Calendar events', 'booking' ), '<b>', ',</b>' ) |
| 2101 |
. ' <a href="' . esc_url( wpbc_get_settings_url() . '&tab=sync&subtab=gcal' ). '">' . esc_html__('here' ,'booking') . '.</a>' |
| 2102 |
. '<br/><br/>' |
| 2103 |
. $wpbc_Google_Calendar->getErrorMessage(); |
| 2104 |
$return_array['after_action_result_delay'] = 100000000000000; |
| 2105 |
} |
| 2106 |
|
| 2107 |
|
| 2108 |
if ( 0 == count( $wpbc_Google_Calendar->events ) ) { |
| 2109 |
$new_listing_params = false; |
| 2110 |
} else { |
| 2111 |
$new_listing_params = array( |
| 2112 |
"sort" => "booking_id", |
| 2113 |
"sort_type" => "DESC", |
| 2114 |
"page_num" => 1, |
| 2115 |
"page_items_count" => "50", |
| 2116 |
"create_date" => "", |
| 2117 |
"keyword" => "", |
| 2118 |
"source" => "", |
| 2119 |
"wh_booking_type" => array( "0" ), |
| 2120 |
"wh_approved" => "", |
| 2121 |
"wh_booking_date" => array( "3" ), |
| 2122 |
"ui_wh_booking_date_radio" => 0, |
| 2123 |
"ui_wh_booking_date_next" => 1, |
| 2124 |
"ui_wh_booking_date_prior" => 1, |
| 2125 |
"ui_wh_booking_date_checkin" => "", |
| 2126 |
"ui_wh_booking_date_checkout" => "", |
| 2127 |
"wh_what_bookings" => "imported", |
| 2128 |
"wh_modification_date" => array( "1" ), |
| 2129 |
"ui_wh_modification_date_prior" => "1", |
| 2130 |
"ui_wh_modification_date_checkin" => "", |
| 2131 |
"ui_wh_modification_date_checkout" => "", |
| 2132 |
"wh_pay_status" => array( "all" ), |
| 2133 |
"ui_wh_pay_status_radio" => "", |
| 2134 |
"ui_wh_pay_status_custom" => "", |
| 2135 |
"wh_cost" => "", |
| 2136 |
"wh_cost2" => "", |
| 2137 |
"wh_sort" => "booking_id__desc", |
| 2138 |
"wh_trash" => "any", |
| 2139 |
'reload_url_params' => htmlspecialchars_decode( esc_url( wpbc_get_bookings_url() . '&tab=vm_booking_listing' ) ) |
| 2140 |
); |
| 2141 |
} |
| 2142 |
|
| 2143 |
|
| 2144 |
$return_array['after_action_result'] = $after_action_result; |
| 2145 |
$return_array['after_action_message'] = $after_action_message; |
| 2146 |
$return_array['new_listing_params'] = $new_listing_params; |
| 2147 |
|
| 2148 |
return $return_array; |
| 2149 |
} |
| 2150 |
|
| 2151 |
|
| 2152 |
function wpbc_booking_do_action__export_csv( $request_params, $params ){ |
| 2153 |
|
| 2154 |
global $wpdb; |
| 2155 |
|
| 2156 |
make_bk_action( 'check_multiuser_params_for_client_side_by_user_id', $params['user_id'] ); |
| 2157 |
|
| 2158 |
$booking_id_csd = $request_params['booking_id']; |
| 2159 |
$booking_id_csd = wpbc_clean_digit_or_csd( $booking_id_csd ); |
| 2160 |
if ( empty( $booking_id_csd ) ) { |
| 2161 |
// Export all bookings (no selected bookings was in the listing |
| 2162 |
} |
| 2163 |
|
| 2164 |
$export_type = $request_params['export_type']; // csv_page | csv_all |
| 2165 |
|
| 2166 |
// Is send email for this action ---------------------------------------------------------------------------------- |
| 2167 |
$is_send_emeils = wpbc_ajx__user_request_option__is_send_emails( $params['user_id'] ); |
| 2168 |
|
| 2169 |
// ----------------------------------------------------------------------------------------------------------------- |
| 2170 |
|
| 2171 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 2172 |
if ( ! isset( $_POST['search_params'] ) || empty( $_POST['search_params'] ) ) { |
| 2173 |
|
| 2174 |
$after_action_result = false; |
| 2175 |
$after_action_message = __('Error', 'booking') . '! ' . 'Search parameters for CSV generating are empty.'; |
| 2176 |
|
| 2177 |
} else { |
| 2178 |
|
| 2179 |
|
| 2180 |
$user_request = new WPBC_AJX__REQUEST( array( |
| 2181 |
'db_option_name' => 'booking_listing_request_params', |
| 2182 |
'user_id' => wpbc_get_current_user_id(), |
| 2183 |
'request_rules_structure' => wpbc_ajx_get__request_params__names_default() |
| 2184 |
) |
| 2185 |
); |
| 2186 |
$request_prefix = 'search_params'; |
| 2187 |
$request_params_for_listing = $user_request->get_sanitized__in_request__value_or_default( $request_prefix ); // NOT Direct: $_REQUEST['search_params']['resource_id'] |
| 2188 |
|
| 2189 |
|
| 2190 |
|
| 2191 |
// $data_arr = wpbc_ajx_get_booking_data_arr( $request_params_for_listing ); |
| 2192 |
|
| 2193 |
$export_csv_url = wpbc_csv_get_url_export( $request_params_for_listing ); |
| 2194 |
|
| 2195 |
$after_action_result = true; |
| 2196 |
$after_action_message = __('Processing' ,'booking') . '... '; |
| 2197 |
} |
| 2198 |
|
| 2199 |
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Recommended |
| 2200 |
$wpbc_ajx_locale = ( isset( $_REQUEST['wpbc_ajx_locale'] ) ) ? sanitize_text_field( $_REQUEST['wpbc_ajx_locale'] ) : 'en_US'; |
| 2201 |
|
| 2202 |
return array( |
| 2203 |
|
| 2204 |
'export_csv_url' => $export_csv_url |
| 2205 |
. '&export_type=' . $export_type |
| 2206 |
. '&selected_id=' . $booking_id_csd |
| 2207 |
. '&csv_export_separator=' . $request_params['csv_export_separator'] |
| 2208 |
. '&csv_export_skip_fields=' . $request_params['csv_export_skip_fields'] |
| 2209 |
. '&wpbc_ajx_locale=' . $wpbc_ajx_locale |
| 2210 |
. '&wpbc_ajx_locale_reload=force' , |
| 2211 |
'after_action_result' => $after_action_result, |
| 2212 |
'after_action_message' => $after_action_message |
| 2213 |
); |
| 2214 |
} |
| 2215 |
// </editor-fold> |
| 2216 |
|
| 2217 |
//TODO: Delete 2025-04-23 ? |
| 2218 |
// <editor-fold defaultstate="collapsed" desc=" == Button Actions Templates for UI == " > |
| 2219 |
|
| 2220 |
|
| 2221 |
/** |
| 2222 |
* Show Costs booking Test field |
| 2223 |
*/ |
| 2224 |
function wpbc_for_booking_template__action_cost(){ |
| 2225 |
|
| 2226 |
if ( ! class_exists('wpdev_bk_biz_s') ) { |
| 2227 |
return false; |
| 2228 |
} |
| 2229 |
|
| 2230 |
$booking_action = 'set_booking_cost'; |
| 2231 |
$el_id = 'ui_btn_' . $booking_action . '{{data.parsed_fields.booking_id}}'; |
| 2232 |
|
| 2233 |
if ( ! wpbc_is_user_can( $booking_action, wpbc_get_current_user_id() ) ) { |
| 2234 |
return false; |
| 2235 |
} |
| 2236 |
|
| 2237 |
$params_addon = array( |
| 2238 |
'type' => 'span' |
| 2239 |
, 'label' => '{{{data[\'parsed_fields\'][\'currency_symbol\']}}}' |
| 2240 |
, 'html' => '{{{data[\'parsed_fields\'][\'currency_symbol\']}}}'//''// '<i class="menu_icon icon-1x wpbc_icn_event"></i>' //'<strong>' . esc_html__( 'Dates', 'booking ' ) . '</strong>' |
| 2241 |
//, 'icon' => array( 'icon_font' => 'wpbc_icn_event', 'position' => 'right', 'icon_img' => '' ) |
| 2242 |
//, 'class' => 'wpbc_ui_button inactive' |
| 2243 |
, 'style' => 'font-weight:600;font-size: 14px;line-height: 28px;' |
| 2244 |
, 'attr' => array() |
| 2245 |
); |
| 2246 |
|
| 2247 |
$param_text = array( |
| 2248 |
'type' => 'text' |
| 2249 |
, 'id' => $el_id . '_cost' |
| 2250 |
, 'name' => $el_id . '_cost' |
| 2251 |
, 'label' => '' |
| 2252 |
, 'disabled' => false |
| 2253 |
, 'class' => 'set_booking_cost_text_field' |
| 2254 |
, 'style' => 'width:5em;font-weight:600;' |
| 2255 |
, 'placeholder' => '0' |
| 2256 |
, 'attr' => array() |
| 2257 |
, 'is_escape_value' => false |
| 2258 |
, 'value' => '{{data[\'parsed_fields\'][\'cost\']}}' |
| 2259 |
, 'onfocus' => '' |
| 2260 |
, 'onkeydown' => "jQuery('.ui__set_booking_cost__section_in_booking_{{data['parsed_fields']['booking_id']}}').show();" // JavaScript code |
| 2261 |
); |
| 2262 |
|
| 2263 |
?><div class="ui_element ui_nowrap"><?php |
| 2264 |
//wpbc_flex_addon( $params_addon ); |
| 2265 |
wpbc_flex_label( $params_addon ); |
| 2266 |
wpbc_flex_text( $param_text ); |
| 2267 |
?></div><?php |
| 2268 |
|
| 2269 |
|
| 2270 |
$params_button_save = array( |
| 2271 |
'type' => 'button' , |
| 2272 |
'title' => __( 'Save cost', 'booking' ) . ' ', // Title of the button |
| 2273 |
'hint' => array( 'title' => __( 'Save Changes', 'booking' ), 'position' => 'top' ), // Hint |
| 2274 |
'link' => 'javascript:void(0)', // Direct link or skip it |
| 2275 |
'action' => "wpbc_ajx_booking__ui_click_save__set_booking_cost( {{data['parsed_fields']['booking_id']}}, this, '{$booking_action}', '{$el_id}' );" , |
| 2276 |
'style' => '', // Any CSS class here |
| 2277 |
'mobile_show_text' => true, // Show or hide text, when viewing on Mobile devices (small window size). |
| 2278 |
'icon' => array( 'icon_font' => 'wpbc_icn_check _circle_outline', 'position' => 'right', 'icon_img' => '' ), |
| 2279 |
'class' => 'wpbc_ui_button_primary', // '' | 'wpbc_ui_button_primary' |
| 2280 |
'attr' => array( 'id' => $el_id . '_save' ) |
| 2281 |
); |
| 2282 |
|
| 2283 |
$params_button_cancel = array( |
| 2284 |
'type' => 'button' , |
| 2285 |
'title' => __( 'Cancel', 'booking' ) . ' ', // Title of the button |
| 2286 |
'hint' => array( 'title' => __('Close' ,'booking'), 'position' => 'top' ), // Hint |
| 2287 |
'link' => 'javascript:void(0)', // Direct link or skip it |
| 2288 |
'action' => "wpbc_ajx_booking__ui_click_close__set_booking_cost();" , |
| 2289 |
'style' => '', // Any CSS class here |
| 2290 |
'mobile_show_text' => true, // Show or hide text, when viewing on Mobile devices (small window size). |
| 2291 |
'icon' => array( 'icon_font' => 'wpbc_icn_close _block', 'position' => 'right', 'icon_img' => '' ), |
| 2292 |
'class' => '', // '' | 'wpbc_ui_button_primary' |
| 2293 |
'attr' => array( 'id' => $el_id . '_cancel' ) |
| 2294 |
); |
| 2295 |
|
| 2296 |
?><div class="ui_element ui_nowrap ui__set_booking_cost__section_in_booking ui__set_booking_cost__section_in_booking_{{data['parsed_fields']['booking_id']}}"><?php |
| 2297 |
wpbc_flex_button( $params_button_save ); |
| 2298 |
?></div><?php |
| 2299 |
?><div class="ui_element ui_nowrap ui__set_booking_cost__section_in_booking ui__set_booking_cost__section_in_booking_{{data['parsed_fields']['booking_id']}}"><?php |
| 2300 |
wpbc_flex_button( $params_button_cancel ); |
| 2301 |
?></div><?php |
| 2302 |
|
| 2303 |
} |
| 2304 |
|
| 2305 |
|
| 2306 |
|
| 2307 |
/** |
| 2308 |
* Show Payment Status booking Button |
| 2309 |
*/ |
| 2310 |
function wpbc_for_booking_template__action_set_payment_status(){ |
| 2311 |
|
| 2312 |
if ( ! class_exists('wpdev_bk_biz_s') ) { |
| 2313 |
return false; |
| 2314 |
} |
| 2315 |
|
| 2316 |
$booking_action = 'set_payment_status'; |
| 2317 |
|
| 2318 |
if ( ! wpbc_is_user_can( $booking_action, wpbc_get_current_user_id() ) ) { |
| 2319 |
return false; |
| 2320 |
} |
| 2321 |
|
| 2322 |
$params = array( |
| 2323 |
'type' => 'button', |
| 2324 |
'title' => '', |
| 2325 |
'hint' => array( |
| 2326 |
'title' => __( 'Payment status', 'booking' ), |
| 2327 |
'position' => 'top' |
| 2328 |
), |
| 2329 |
'link' => 'javascript:void(0)', |
| 2330 |
'action' => "wpbc_ajx_booking__ui_click_show__set_payment_status( {{data['parsed_fields']['booking_id']}} );", |
| 2331 |
'icon' => array( |
| 2332 |
'icon_font' => 'wpbc_icn_sell', |
| 2333 |
'position' => 'left', |
| 2334 |
'icon_img' => '' |
| 2335 |
), |
| 2336 |
'class' => '', |
| 2337 |
'style' => '', |
| 2338 |
'mobile_show_text' => true, |
| 2339 |
'attr' => array() |
| 2340 |
); |
| 2341 |
|
| 2342 |
|
| 2343 |
?><div class="ui_element"><?php |
| 2344 |
wpbc_flex_button( $params ); |
| 2345 |
?></div><?php |
| 2346 |
} |
| 2347 |
|
| 2348 |
|
| 2349 |
/** |
| 2350 |
* Selectbox | Save | Close buttons for "Payment status" section |
| 2351 |
* @return false|void |
| 2352 |
*/ |
| 2353 |
function wpbc_for_booking_template_section__set_payment_status(){ |
| 2354 |
|
| 2355 |
if ( ! class_exists('wpdev_bk_biz_s') ) { |
| 2356 |
return false; |
| 2357 |
} |
| 2358 |
|
| 2359 |
$booking_action = 'set_payment_status'; |
| 2360 |
|
| 2361 |
$el_id = 'ui_btn_' . $booking_action . '{{data.parsed_fields.booking_id}}'; |
| 2362 |
|
| 2363 |
if ( ! wpbc_is_user_can( $booking_action, wpbc_get_current_user_id() ) ) { |
| 2364 |
return false; |
| 2365 |
} |
| 2366 |
|
| 2367 |
$select_box_options = get_payment_status_titles(); |
| 2368 |
$select_box_options = array_flip( $select_box_options ); |
| 2369 |
$params_select = array( |
| 2370 |
'id' => $el_id // HTML ID of element |
| 2371 |
, 'name' => $el_id |
| 2372 |
, 'label' => ''//__( 'Payment status', 'booking' ) // Label (optional) |
| 2373 |
, 'style' => '' // CSS of select element |
| 2374 |
, 'class' => '' // CSS Class of select element |
| 2375 |
, 'multiple' => false |
| 2376 |
, 'attr' => array( |
| 2377 |
'data-placeholder' => __( 'Change status', 'booking' ), |
| 2378 |
'ajx-selected-value' => '{{data.parsed_fields.pay_status}}' |
| 2379 |
) |
| 2380 |
, 'disabled' => false |
| 2381 |
, 'disabled_options' => array() // If some options disabled, then it has to list here |
| 2382 |
, 'options' => $select_box_options |
| 2383 |
//, 'value' => "{{data['parsed_fields']['pay_status']}}"//isset( $escaped_search_request_params[ $el_id ] ) ? $escaped_search_request_params[ $el_id ] : $defaults[ $el_id ] // Some Value from options array that selected by default |
| 2384 |
//, 'onfocus' => "console.log( 'ON FOCUS:', jQuery( this ).val(), 'in element:' , jQuery( this ) );" // JavaScript code |
| 2385 |
//, 'onchange' => "console.log( 'ON CHANGE:', jQuery( this ).val(), 'in element:' , jQuery( this ) );" // JavaScript code |
| 2386 |
); |
| 2387 |
|
| 2388 |
$params_button_save = array( |
| 2389 |
'type' => 'button' , |
| 2390 |
'title' => __( 'Change status', 'booking' ) . ' ', // Title of the button |
| 2391 |
'hint' => array( 'title' => __( 'Save Changes', 'booking' ), 'position' => 'top' ), // Hint |
| 2392 |
'link' => 'javascript:void(0)', // Direct link or skip it |
| 2393 |
'action' => "wpbc_ajx_booking__ui_click_save__set_payment_status( {{data['parsed_fields']['booking_id']}}, this, '{$booking_action}', '{$el_id}' );" , |
| 2394 |
'style' => '', // Any CSS class here |
| 2395 |
'mobile_show_text' => true, // Show or hide text, when viewing on Mobile devices (small window size). |
| 2396 |
'icon' => array( 'icon_font' => 'wpbc_icn_check _circle_outline', 'position' => 'right', 'icon_img' => '' ), |
| 2397 |
'class' => 'wpbc_ui_button_primary', // '' | 'wpbc_ui_button_primary' |
| 2398 |
'attr' => array( 'id' => $el_id . '_save' ) |
| 2399 |
); |
| 2400 |
|
| 2401 |
$params_button_cancel = array( |
| 2402 |
'type' => 'button' , |
| 2403 |
'title' => __( 'Cancel', 'booking' ) . ' ', // Title of the button |
| 2404 |
'hint' => array( 'title' => __('Close' ,'booking'), 'position' => 'top' ), // Hint |
| 2405 |
'link' => 'javascript:void(0)', // Direct link or skip it |
| 2406 |
'action' => "wpbc_ajx_booking__ui_click_close__set_payment_status();" , |
| 2407 |
'style' => '', // Any CSS class here |
| 2408 |
'mobile_show_text' => true, // Show or hide text, when viewing on Mobile devices (small window size). |
| 2409 |
'icon' => array( 'icon_font' => 'wpbc_icn_close _block', 'position' => 'right', 'icon_img' => '' ), |
| 2410 |
'class' => '', // '' | 'wpbc_ui_button_primary' |
| 2411 |
'attr' => array( 'id' => $el_id . '_cancel' ) |
| 2412 |
); |
| 2413 |
|
| 2414 |
|
| 2415 |
?><div class="ui_element" style="flex:100%;"></div> |
| 2416 |
<div id="ui__set_payment_status__section_in_booking_{{data['parsed_fields']['booking_id']}}" |
| 2417 |
class="ui__set_payment_status__section_in_booking ui__under_actions_row__section_in_booking" |
| 2418 |
> |
| 2419 |
<div class="wpbc_ajx_toolbar wpbc_buttons_row wpbc_buttons_row_for_booking highlight_action_section"> <div class="ui_container ui_container_small"> <div class="ui_group"> |
| 2420 |
|
| 2421 |
<div class="ui_element"> |
| 2422 |
<?php wpbc_flex_select($params_select); ?> |
| 2423 |
</div> |
| 2424 |
|
| 2425 |
<div class="ui_element" > |
| 2426 |
<?php wpbc_flex_button($params_button_save); ?> |
| 2427 |
</div> |
| 2428 |
|
| 2429 |
<div class="ui_element"> |
| 2430 |
<?php wpbc_flex_button($params_button_cancel); ?> |
| 2431 |
</div> |
| 2432 |
|
| 2433 |
</div> </div> </div> |
| 2434 |
<div class="clear"></div> |
| 2435 |
|
| 2436 |
</div><?php |
| 2437 |
|
| 2438 |
} |
| 2439 |
|
| 2440 |
|
| 2441 |
/** |
| 2442 |
* Show Edit booking Button |
| 2443 |
*/ |
| 2444 |
function wpbc_for_booking_template__action_edit_booking(){ |
| 2445 |
|
| 2446 |
// FixIn: 9.2.3.4. |
| 2447 |
// if ( ! class_exists('wpdev_bk_personal') ) { |
| 2448 |
// return false; |
| 2449 |
// } |
| 2450 |
|
| 2451 |
$booking_action = 'edit_booking'; |
| 2452 |
|
| 2453 |
if ( ! wpbc_is_user_can( $booking_action, wpbc_get_current_user_id() ) ) { |
| 2454 |
return false; |
| 2455 |
} |
| 2456 |
|
| 2457 |
$edit_booking_url = 'admin.php?page=' . wpbc_get_new_booking_url( false, false) |
| 2458 |
. '&booking_type={{data.parsed_fields.resource_id}}&booking_hash={{data.parsed_fields.hash}}&parent_res=1' ; |
| 2459 |
// FixIn: 10.10.1.2 $edit_booking_url .= ( 'Off' !== get_bk_option( 'booking_is_resource_no_update__during_editing' ) ) ? '&resource_no_update=1' : ''; // FixIn: 9.4.2.3. |
| 2460 |
|
| 2461 |
$edit_booking_url .= '&booking_form={{data.parsed_fields.wpbc_custom_booking_form}}'; // FixIn: 9.4.3.12. |
| 2462 |
|
| 2463 |
$edit_booking_url .= '&is_show_payment_form=Off'; // FixIn: 9.9.0.38. |
| 2464 |
|
| 2465 |
$params = array( |
| 2466 |
'type' => 'button', |
| 2467 |
'title' => '', |
| 2468 |
'hint' => array( |
| 2469 |
'title' => __( 'Edit Booking', 'booking' ), |
| 2470 |
'position' => 'top' |
| 2471 |
), |
| 2472 |
'link' => $edit_booking_url,//'javascript:void(0)', |
| 2473 |
'action' => '',//"js_func( {{data['parsed_fields']['booking_id']}} );", |
| 2474 |
'icon' => array( |
| 2475 |
'icon_font' => 'wpbc_icn_draw', |
| 2476 |
'position' => 'left', |
| 2477 |
'icon_img' => '' |
| 2478 |
), |
| 2479 |
'class' => '', |
| 2480 |
'style' => '', |
| 2481 |
'mobile_show_text' => true, |
| 2482 |
'attr' => array() |
| 2483 |
); |
| 2484 |
|
| 2485 |
|
| 2486 |
?><div class="ui_element <# if ( '' == data['parsed_fields']['hash']) { #>disabled<# } #>"><?php |
| 2487 |
wpbc_flex_button( $params ); |
| 2488 |
?></div><?php |
| 2489 |
} |
| 2490 |
|
| 2491 |
/** |
| 2492 |
* Show Change booking resource for booking Button |
| 2493 |
*/ |
| 2494 |
function wpbc_for_booking_template__action_change_resource(){ |
| 2495 |
|
| 2496 |
if ( ! class_exists('wpdev_bk_personal') ) { |
| 2497 |
return false; |
| 2498 |
} |
| 2499 |
|
| 2500 |
$booking_action = 'change_booking_resource'; |
| 2501 |
|
| 2502 |
if ( ! wpbc_is_user_can( $booking_action, wpbc_get_current_user_id() ) ) { |
| 2503 |
return false; |
| 2504 |
} |
| 2505 |
|
| 2506 |
$params = array( |
| 2507 |
'type' => 'button', |
| 2508 |
'title' => '', |
| 2509 |
'hint' => array( |
| 2510 |
'title' => __( 'Change Resource', 'booking' ), |
| 2511 |
'position' => 'top' |
| 2512 |
), |
| 2513 |
'link' => 'javascript:void(0)', |
| 2514 |
'action' => "wpbc_ajx_booking__ui_click_show__change_resource( {{data['parsed_fields']['booking_id']}}, {{data['parsed_fields']['resource_id']}} );", |
| 2515 |
'icon' => array( |
| 2516 |
'icon_font' => 'wpbc_icn_shuffle', |
| 2517 |
'position' => 'left', |
| 2518 |
'icon_img' => '' |
| 2519 |
), |
| 2520 |
'class' => '', |
| 2521 |
'style' => '', |
| 2522 |
'mobile_show_text' => true, |
| 2523 |
'attr' => array() |
| 2524 |
); |
| 2525 |
|
| 2526 |
|
| 2527 |
?><div class="ui_element"><?php |
| 2528 |
wpbc_flex_button( $params ); |
| 2529 |
?></div><?php |
| 2530 |
} |
| 2531 |
|
| 2532 |
/** |
| 2533 |
* Selectbox | Save | Close buttons for "Change booking resources" section |
| 2534 |
* @return false|void |
| 2535 |
*/ |
| 2536 |
function wpbc_for_booking_template_section__change_booking_resource(){ |
| 2537 |
|
| 2538 |
if ( ! class_exists('wpdev_bk_personal') ) { |
| 2539 |
return false; |
| 2540 |
} |
| 2541 |
|
| 2542 |
$booking_action = 'change_booking_resource'; |
| 2543 |
|
| 2544 |
$el_id = 'ui_btn_' . $booking_action; |
| 2545 |
|
| 2546 |
if ( ! wpbc_is_user_can( $booking_action, wpbc_get_current_user_id() ) ) { |
| 2547 |
return false; |
| 2548 |
} |
| 2549 |
|
| 2550 |
?><div class="ui_element" style="flex:100%;"></div> |
| 2551 |
<div id="ui__change_booking_resource__section_in_booking_{{data['parsed_fields']['booking_id']}}" |
| 2552 |
class="ui__change_booking_resource__section_in_booking ui__under_actions_row__section_in_booking" |
| 2553 |
></div><?php |
| 2554 |
} |
| 2555 |
|
| 2556 |
|
| 2557 |
/** |
| 2558 |
* Show Duplicate booking Button |
| 2559 |
*/ |
| 2560 |
function wpbc_for_booking_template__action_duplicate_booking_to_other_resource(){ |
| 2561 |
|
| 2562 |
if ( ! class_exists('wpdev_bk_personal') ) { |
| 2563 |
return false; |
| 2564 |
} |
| 2565 |
|
| 2566 |
$booking_action = 'duplicate_booking_to_other_resource'; |
| 2567 |
|
| 2568 |
if ( ! wpbc_is_user_can( $booking_action, wpbc_get_current_user_id() ) ) { |
| 2569 |
return false; |
| 2570 |
} |
| 2571 |
|
| 2572 |
$params = array( |
| 2573 |
'type' => 'button', |
| 2574 |
'title' => '', |
| 2575 |
'hint' => array( |
| 2576 |
'title' => __( 'Duplicate Booking', 'booking' ), |
| 2577 |
'position' => 'top' |
| 2578 |
), |
| 2579 |
'link' => 'javascript:void(0)', |
| 2580 |
'action' => "wpbc_ajx_booking__ui_click_show__duplicate_booking( {{data['parsed_fields']['booking_id']}}, {{data['parsed_fields']['resource_id']}} );", |
| 2581 |
'icon' => array( |
| 2582 |
'icon_font' => 'wpbc_icn_content_copy', |
| 2583 |
'position' => 'left', |
| 2584 |
'icon_img' => '' |
| 2585 |
), |
| 2586 |
'class' => '', |
| 2587 |
'style' => '', |
| 2588 |
'mobile_show_text' => true, |
| 2589 |
'attr' => array() |
| 2590 |
); |
| 2591 |
|
| 2592 |
|
| 2593 |
?><div class="ui_element"><?php |
| 2594 |
wpbc_flex_button( $params ); |
| 2595 |
?></div><?php |
| 2596 |
} |
| 2597 |
|
| 2598 |
/** |
| 2599 |
* Selectbox | Save | Close buttons for "Duplicate booking" section |
| 2600 |
* @return false|void |
| 2601 |
*/ |
| 2602 |
function wpbc_for_booking_template_section__duplicate_booking_to_other_resource(){ |
| 2603 |
|
| 2604 |
if ( ! class_exists('wpdev_bk_personal') ) { |
| 2605 |
return false; |
| 2606 |
} |
| 2607 |
|
| 2608 |
$booking_action = 'duplicate_booking_to_other_resource'; |
| 2609 |
|
| 2610 |
$el_id = 'ui_btn_' . $booking_action; |
| 2611 |
|
| 2612 |
if ( ! wpbc_is_user_can( $booking_action, wpbc_get_current_user_id() ) ) { |
| 2613 |
return false; |
| 2614 |
} |
| 2615 |
|
| 2616 |
?><div class="ui_element" style="flex:100%;"></div> |
| 2617 |
<div id="ui__duplicate_booking_to_other_resource__section_in_booking_{{data['parsed_fields']['booking_id']}}" |
| 2618 |
class="ui__duplicate_booking_to_other_resource__section_in_booking ui__under_actions_row__section_in_booking" |
| 2619 |
></div><?php |
| 2620 |
} |
| 2621 |
|
| 2622 |
|
| 2623 |
/** |
| 2624 |
* Show Print booking Button |
| 2625 |
*/ |
| 2626 |
function wpbc_for_booking_template__action_print(){ |
| 2627 |
|
| 2628 |
if ( ! class_exists('wpdev_bk_personal') ) { |
| 2629 |
//return false; |
| 2630 |
} |
| 2631 |
|
| 2632 |
$booking_action = 'set_print'; |
| 2633 |
|
| 2634 |
if ( ! wpbc_is_user_can( $booking_action, wpbc_get_current_user_id() ) ) { |
| 2635 |
return false; |
| 2636 |
} |
| 2637 |
|
| 2638 |
$params = array( |
| 2639 |
'type' => 'button', |
| 2640 |
'title' => '', |
| 2641 |
'hint' => array( |
| 2642 |
'title' => __( 'Print', 'booking' ), |
| 2643 |
'position' => 'top' |
| 2644 |
), |
| 2645 |
'link' => 'javascript:void(0)', |
| 2646 |
'action' => "wpbc_print_dialog__show( {{data['parsed_fields']['booking_id']}} );", |
| 2647 |
'icon' => array( |
| 2648 |
'icon_font' => 'wpbc_icn_print', |
| 2649 |
'position' => 'left', |
| 2650 |
'icon_img' => '' |
| 2651 |
), |
| 2652 |
'class' => '', |
| 2653 |
'style' => '', |
| 2654 |
'mobile_show_text' => true, |
| 2655 |
'attr' => array() |
| 2656 |
); |
| 2657 |
|
| 2658 |
|
| 2659 |
?><div class="ui_element"><?php |
| 2660 |
wpbc_flex_button( $params ); |
| 2661 |
?></div><?php |
| 2662 |
} |
| 2663 |
|
| 2664 |
/** |
| 2665 |
* Show Remark booking Button |
| 2666 |
*/ |
| 2667 |
function wpbc_for_booking_template__action_remark(){ |
| 2668 |
|
| 2669 |
if ( ! class_exists('wpdev_bk_personal') ) { |
| 2670 |
return false; |
| 2671 |
} |
| 2672 |
|
| 2673 |
$booking_action = 'set_booking_note'; |
| 2674 |
|
| 2675 |
if ( ! wpbc_is_user_can( $booking_action, wpbc_get_current_user_id() ) ) { |
| 2676 |
return false; |
| 2677 |
} |
| 2678 |
|
| 2679 |
$params = array( |
| 2680 |
'type' => 'button', |
| 2681 |
'title' => '', |
| 2682 |
'hint' => array( |
| 2683 |
'title' => __( 'Edit Note', 'booking' ), |
| 2684 |
'position' => 'top' |
| 2685 |
), |
| 2686 |
'link' => 'javascript:void(0)', |
| 2687 |
'action' => "wpbc_ajx_booking__ui_click__remark( jQuery( this ) );", |
| 2688 |
'icon' => array( |
| 2689 |
'icon_font' => 'wpbc_icn_mode_comment', |
| 2690 |
'position' => 'left', |
| 2691 |
'icon_img' => '' |
| 2692 |
), |
| 2693 |
'class' => "{$booking_action}_button", |
| 2694 |
'style' => '', |
| 2695 |
'mobile_show_text' => true, |
| 2696 |
'attr' => array( 'id' => "{$booking_action}_button{{data.parsed_fields.booking_id}}" ) |
| 2697 |
); |
| 2698 |
|
| 2699 |
?><div class="ui_element"><?php |
| 2700 |
wpbc_flex_button( $params ); |
| 2701 |
?></div><?php |
| 2702 |
} |
| 2703 |
|
| 2704 |
function wpbc_for_booking_template_section__action_remark_textarea(){ |
| 2705 |
|
| 2706 |
if ( ! class_exists('wpdev_bk_personal') ) { |
| 2707 |
return false; |
| 2708 |
} |
| 2709 |
|
| 2710 |
$booking_action = 'set_booking_note'; |
| 2711 |
|
| 2712 |
$el_id = 'ui_btn_' . $booking_action; |
| 2713 |
|
| 2714 |
if ( ! wpbc_is_user_can( $booking_action, wpbc_get_current_user_id() ) ) { |
| 2715 |
return false; |
| 2716 |
} |
| 2717 |
|
| 2718 |
$params_textarea = array( |
| 2719 |
'id' => "{$booking_action}_text_{{data.parsed_fields.booking_id}}" // HTML ID of element |
| 2720 |
, 'name' => "{$booking_action}_text_{{data.parsed_fields.booking_id}}" // HTML ID of element |
| 2721 |
, 'label' => '' |
| 2722 |
, 'style' => 'height: 8em; width: 100%;' // CSS of select element |
| 2723 |
, 'class' => "{$booking_action}_text" // CSS Class of select element |
| 2724 |
, 'disabled' => false |
| 2725 |
, 'attr' => array() // Any additional attributes, if this radio | checkbox element |
| 2726 |
, 'rows' => '3' |
| 2727 |
, 'cols' => '50' |
| 2728 |
, 'placeholder' => '' |
| 2729 |
, 'value' => '{{{data.parsed_fields.remark}}}' // FixIn: 9.4.4.1. |
| 2730 |
, 'is_escape_value' => true |
| 2731 |
//, 'onfocus' => "console.log( 'ON FOCUS:', jQuery( this ).val() , 'in element:' , jQuery( this ) );" // JavaScript code |
| 2732 |
//, 'onchange' => "console.log( 'ON CHANGE:', jQuery( this ).val() , 'in element:' , jQuery( this ) );" // JavaScript code |
| 2733 |
); |
| 2734 |
|
| 2735 |
$params_button_save = array( |
| 2736 |
'type' => 'button' , |
| 2737 |
'title' => __( 'Save', 'booking' ) . ' ', // Title of the button |
| 2738 |
'hint' => array( 'title' => __( 'Save Changes', 'booking' ), 'position' => 'top' ), // Hint |
| 2739 |
'link' => 'javascript:void(0)', // Direct link or skip it |
| 2740 |
'action' => "wpbc_ajx_booking_ajax_action_request( { |
| 2741 |
'booking_action' : '{$booking_action}', |
| 2742 |
'booking_id' : {{data.parsed_fields.booking_id}}, |
| 2743 |
'remark' : jQuery( '#{$booking_action}_text_{{data.parsed_fields.booking_id}}' ).val(), |
| 2744 |
'ui_clicked_element_id': '{$el_id}' |
| 2745 |
} ); |
| 2746 |
wpbc_button_enable_loading_icon( this ); " , |
| 2747 |
'style' => '', // Any CSS class here |
| 2748 |
'mobile_show_text' => true, // Show or hide text, when viewing on Mobile devices (small window size). |
| 2749 |
'icon' => array( 'icon_font' => 'wpbc_icn_check _circle_outline', 'position' => 'right', 'icon_img' => '' ), |
| 2750 |
'class' => 'wpbc_ui_button_primary', // '' | 'wpbc_ui_button_primary' |
| 2751 |
'attr' => array( 'id' => $el_id ) |
| 2752 |
); |
| 2753 |
|
| 2754 |
$params_button_cancel = array( |
| 2755 |
'type' => 'button' , |
| 2756 |
'title' => __( 'Cancel', 'booking' ) . ' ', // Title of the button |
| 2757 |
'hint' => array( 'title' => __('Close' ,'booking'), 'position' => 'top' ), // Hint |
| 2758 |
'link' => 'javascript:void(0)', // Direct link or skip it |
| 2759 |
'action' => "wpbc_ajx_booking__ui_click__remark( jQuery( '#{$booking_action}_button{{data.parsed_fields.booking_id}}' ) );" , |
| 2760 |
'style' => '', // Any CSS class here |
| 2761 |
'mobile_show_text' => true, // Show or hide text, when viewing on Mobile devices (small window size). |
| 2762 |
'icon' => array( 'icon_font' => 'wpbc_icn_close _block', 'position' => 'right', 'icon_img' => '' ), |
| 2763 |
'class' => '', // '' | 'wpbc_ui_button_primary' |
| 2764 |
'attr' => array( 'id' => $el_id . '_cancel' ) |
| 2765 |
); |
| 2766 |
|
| 2767 |
//$user_id = ( isset( $_REQUEST['wpbc_ajx_user_id'] ) ) ? intval( $_REQUEST['wpbc_ajx_user_id'] ) : wpbc_get_current_user_id(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 2768 |
//$is_expand_remarks = wpbc_ajx__user_request_option__is_expand_remarks( $user_id ); |
| 2769 |
|
| 2770 |
?><div class="ui_remark_section is_expand_remarks_<?php //echo ($is_expand_remarks) ? 'on' : 'off'; ?>" |
| 2771 |
style="<# if ( 'Off' === wpbc_ajx_booking_listing.search_get_param('ui_usr__is_expand_remarks') ) { #>display: none;<# } #>" |
| 2772 |
><?php |
| 2773 |
|
| 2774 |
wpbc_flex_textarea( $params_textarea ); |
| 2775 |
|
| 2776 |
?><div class="ui_group"><?php |
| 2777 |
|
| 2778 |
?><div class="ui_element" ><?php |
| 2779 |
wpbc_flex_button($params_button_save); |
| 2780 |
?></div><?php |
| 2781 |
|
| 2782 |
?><div class="ui_element"><?php |
| 2783 |
wpbc_flex_button($params_button_cancel); |
| 2784 |
?></div><?php |
| 2785 |
|
| 2786 |
?></div><?php |
| 2787 |
|
| 2788 |
?></div><?php |
| 2789 |
} |
| 2790 |
|
| 2791 |
/** |
| 2792 |
* Show Locale booking Button |
| 2793 |
*/ |
| 2794 |
function wpbc_for_booking_template__action_locale(){ |
| 2795 |
|
| 2796 |
$booking_action = 'set_booking_locale'; |
| 2797 |
|
| 2798 |
if ( ! wpbc_is_user_can( $booking_action, wpbc_get_current_user_id() ) ) { |
| 2799 |
return false; |
| 2800 |
} |
| 2801 |
|
| 2802 |
?><span class="ui_element_locale"><?php |
| 2803 |
|
| 2804 |
$params = array( |
| 2805 |
'type' => 'button', |
| 2806 |
'id' => "button_locale_for_booking{{data['parsed_fields']['booking_id']}}", |
| 2807 |
'title' => '', |
| 2808 |
'hint' => array( |
| 2809 |
'title' => __( 'Change Language', 'booking' ), |
| 2810 |
'position' => 'top' |
| 2811 |
), |
| 2812 |
'link' => 'javascript:void(0)', |
| 2813 |
'action' => "jQuery('#locale_for_booking{{data[\'parsed_fields\'][\'booking_id\']}}').toggle();jQuery(this).hide();", |
| 2814 |
'icon' => array( |
| 2815 |
'icon_font' => 'wpbc_icn_language', |
| 2816 |
'position' => 'left', |
| 2817 |
'icon_img' => '' |
| 2818 |
), |
| 2819 |
'class' => 'set_booking_locale_button', |
| 2820 |
'style' => '', |
| 2821 |
'mobile_show_text' => true, |
| 2822 |
'attr' => array() |
| 2823 |
); |
| 2824 |
|
| 2825 |
?><div class="ui_element"><?php |
| 2826 |
wpbc_flex_button( $params ); |
| 2827 |
?></div><?php |
| 2828 |
|
| 2829 |
|
| 2830 |
$el_id = "locale_for_booking{{data.parsed_fields.booking_id}}"; |
| 2831 |
?><# |
| 2832 |
var selected_locale_value = ''; |
| 2833 |
if ( |
| 2834 |
( 'undefined' !== typeof( data.parsed_fields.booking_options) ) |
| 2835 |
&& ( 'undefined' !== typeof( data.parsed_fields.booking_options.booking_meta_locale ) ) |
| 2836 |
){ |
| 2837 |
var selected_locale_value = data.parsed_fields.booking_options.booking_meta_locale; |
| 2838 |
} |
| 2839 |
#><?php |
| 2840 |
|
| 2841 |
$availbale_locales_in_system = get_available_languages(); |
| 2842 |
$select_box_options = array(); |
| 2843 |
$select_box_options[''] = __( 'Default Locale', 'booking' ); |
| 2844 |
$select_box_options['en_US'] = 'English (United States)'; |
| 2845 |
|
| 2846 |
foreach ( $availbale_locales_in_system as $locale ) { |
| 2847 |
$select_box_options[$locale] = $locale; |
| 2848 |
} |
| 2849 |
|
| 2850 |
$params_select = array( |
| 2851 |
'id' => $el_id // HTML ID of element |
| 2852 |
, 'name' => $el_id |
| 2853 |
, 'label' => '' // __( 'Next Days', 'booking' ) // Label (optional) |
| 2854 |
, 'style' => 'display: none;' // CSS of select element |
| 2855 |
, 'class' => 'set_booking_locale_selectbox' // CSS Class of select element |
| 2856 |
//, 'multiple' => true |
| 2857 |
, 'attr' => array( 'value_of_selected_option' => '{{selected_locale_value}}' ) // Any additional attributes, if this radio | checkbox element |
| 2858 |
, 'disabled' => false |
| 2859 |
, 'disabled_options' => array() // If some options disabled, then it has to list here |
| 2860 |
, 'options' => $select_box_options |
| 2861 |
//, 'value' => isset( $escaped_search_request_params[ $el_id ] ) ? $escaped_search_request_params[ $el_id ] : $defaults[ $el_id ] // Some Value from options array that selected by default |
| 2862 |
//, 'onfocus' => "console.log( 'ON FOCUS:', jQuery( this ).val(), 'in element:' , jQuery( this ) );" // JavaScript code |
| 2863 |
, 'onchange' => "jQuery(this).hide(); |
| 2864 |
var jButton = jQuery('#button_locale_for_booking{{data[\'parsed_fields\'][\'booking_id\']}}'); |
| 2865 |
jButton.show(); |
| 2866 |
wpbc_button_enable_loading_icon( jButton.get(0) ); " |
| 2867 |
. " wpbc_ajx_booking_ajax_action_request( { |
| 2868 |
'booking_action' : '{$booking_action}', |
| 2869 |
'booking_id' : {{data[\'parsed_fields\'][\'booking_id\']}}, |
| 2870 |
'booking_meta_locale' : jQuery('#locale_for_booking{{data[\'parsed_fields\'][\'booking_id\']}} option:selected').val() |
| 2871 |
} );" |
| 2872 |
|
| 2873 |
); |
| 2874 |
|
| 2875 |
?><div class="ui_element"><?php |
| 2876 |
wpbc_flex_select( $params_select ); |
| 2877 |
?></div><?php |
| 2878 |
|
| 2879 |
?></span><?php |
| 2880 |
} |
| 2881 |
|
| 2882 |
/** |
| 2883 |
* Show "Add to Google Calendar" booking Button |
| 2884 |
*/ |
| 2885 |
function wpbc_for_booking_template__action_add_google_calendar(){ |
| 2886 |
|
| 2887 |
$booking_action = 'booking_add_google_calendar'; |
| 2888 |
|
| 2889 |
if ( ! wpbc_is_user_can( $booking_action, wpbc_get_current_user_id() ) ) { |
| 2890 |
return false; |
| 2891 |
} |
| 2892 |
|
| 2893 |
$params = array( |
| 2894 |
'type' => 'button', |
| 2895 |
'title' => '', |
| 2896 |
'hint' => array( |
| 2897 |
'title' => __( 'Add to Google Calendar', 'booking' ), |
| 2898 |
'position' => 'top' |
| 2899 |
), |
| 2900 |
'link' => "{{{data['parsed_fields']['google_calendar_link']}}}", // "{{{encodeURIComponent(data['parsed_fields']['google_calendar_link'])}}}", |
| 2901 |
'options' => array( 'link' => 'no_decode' ), |
| 2902 |
//'link' => 'javascript:void(0)', |
| 2903 |
//'action' => " wpbc_ajx_booking_ajax_action_request( { |
| 2904 |
// 'booking_action' : '{$booking_action}', |
| 2905 |
// 'booking_id' : {{data['parsed_fields']['booking_id']}} |
| 2906 |
// } ); |
| 2907 |
// ", |
| 2908 |
'icon' => array( |
| 2909 |
'icon_font' => 'wpbc_icn_event', |
| 2910 |
'position' => 'left', |
| 2911 |
'icon_img' => '' |
| 2912 |
), |
| 2913 |
'class' => '', |
| 2914 |
'style' => '', |
| 2915 |
'mobile_show_text' => true, |
| 2916 |
'attr' => array('target'=>'_blank') |
| 2917 |
); |
| 2918 |
|
| 2919 |
?><div class="ui_element"><?php |
| 2920 |
wpbc_flex_button( $params ); |
| 2921 |
?></div><?php |
| 2922 |
} |
| 2923 |
|
| 2924 |
/** |
| 2925 |
* Show Trash booking Button |
| 2926 |
*/ |
| 2927 |
function wpbc_for_booking_template__action_trash(){ |
| 2928 |
|
| 2929 |
$booking_action = 'move_booking_to_trash'; |
| 2930 |
|
| 2931 |
if ( ! wpbc_is_user_can( $booking_action, wpbc_get_current_user_id() ) ) { |
| 2932 |
return false; |
| 2933 |
} |
| 2934 |
|
| 2935 |
$params = array( |
| 2936 |
'type' => 'button', |
| 2937 |
'hint' => array( 'title' => __( 'Reject - move to trash', 'booking' ), 'position' => 'top' ), |
| 2938 |
'title' => '', |
| 2939 |
'link' => 'javascript:void(0)', |
| 2940 |
'action' => "if ( wpbc_are_you_sure('" . esc_attr( __( 'Do you really want to do this ?', 'booking' ) ) . "') ) { |
| 2941 |
wpbc_ajx_booking_ajax_action_request( { |
| 2942 |
'booking_action' : '{$booking_action}', |
| 2943 |
'booking_id' : {{data['parsed_fields']['booking_id']}} |
| 2944 |
} ); |
| 2945 |
wpbc_button_enable_loading_icon( this ); |
| 2946 |
}", |
| 2947 |
'icon' => array( |
| 2948 |
'icon_font' => 'wpbc_icn_delete_outline', |
| 2949 |
'position' => 'left', |
| 2950 |
'icon_img' => '' |
| 2951 |
), |
| 2952 |
'class' => '', |
| 2953 |
'style' => '', |
| 2954 |
'mobile_show_text' => true, |
| 2955 |
'attr' => array() |
| 2956 |
); |
| 2957 |
|
| 2958 |
?><# if ( '0' == data['parsed_fields']['trash']) { #><?php |
| 2959 |
?><div class="ui_element"><?php |
| 2960 |
wpbc_flex_button( $params ); |
| 2961 |
?></div><?php |
| 2962 |
?><# } #><?php |
| 2963 |
} |
| 2964 |
|
| 2965 |
/** |
| 2966 |
* Show Restore from Trash booking Button |
| 2967 |
*/ |
| 2968 |
function wpbc_for_booking_template__action_trash_restore(){ |
| 2969 |
|
| 2970 |
$booking_action = 'restore_booking_from_trash'; |
| 2971 |
|
| 2972 |
if ( ! wpbc_is_user_can( $booking_action, wpbc_get_current_user_id() ) ) { |
| 2973 |
return false; |
| 2974 |
} |
| 2975 |
|
| 2976 |
$params = array( |
| 2977 |
'type' => 'button', |
| 2978 |
'hint' => array( 'title' => __( 'Restore', 'booking' ), 'position' => 'top' ), |
| 2979 |
'title' => '', |
| 2980 |
'link' => 'javascript:void(0)', |
| 2981 |
'action' => "if ( wpbc_are_you_sure('" . esc_attr( __( 'Do you really want to do this ?', 'booking' ) ) . "') ) { |
| 2982 |
wpbc_ajx_booking_ajax_action_request( { |
| 2983 |
'booking_action' : '{$booking_action}', |
| 2984 |
'booking_id' : {{data['parsed_fields']['booking_id']}} |
| 2985 |
} ); |
| 2986 |
wpbc_button_enable_loading_icon( this ); |
| 2987 |
}", |
| 2988 |
'icon' => array( |
| 2989 |
'icon_font' => 'wpbc_icn_rotate_left', |
| 2990 |
'position' => 'left', |
| 2991 |
'icon_img' => '' |
| 2992 |
), |
| 2993 |
'class' => '', |
| 2994 |
'style' => '', |
| 2995 |
'mobile_show_text' => true, |
| 2996 |
'attr' => array() |
| 2997 |
); |
| 2998 |
|
| 2999 |
?><# if ( '1' == data['parsed_fields']['trash']) { #><?php |
| 3000 |
?><div class="ui_element"><?php |
| 3001 |
wpbc_flex_button( $params ); |
| 3002 |
?></div><?php |
| 3003 |
?><# } #><?php |
| 3004 |
} |
| 3005 |
|
| 3006 |
/** |
| 3007 |
* Show Completely Delete booking Button |
| 3008 |
*/ |
| 3009 |
function wpbc_for_booking_template__action_delete(){ |
| 3010 |
|
| 3011 |
$booking_action = 'delete_booking_completely'; |
| 3012 |
|
| 3013 |
if ( ! wpbc_is_user_can( $booking_action, wpbc_get_current_user_id() ) ) { |
| 3014 |
return false; |
| 3015 |
} |
| 3016 |
|
| 3017 |
$params = array( |
| 3018 |
'type' => 'button', |
| 3019 |
'hint' => array( 'title' => __( 'Completely Delete', 'booking' ), 'position' => 'top' ), |
| 3020 |
'title' => '', |
| 3021 |
'link' => 'javascript:void(0)', |
| 3022 |
'action' => "if ( wpbc_are_you_sure('" . esc_attr( __( 'Do you really want to delete this booking ?', 'booking' ) ) . "') ) { |
| 3023 |
wpbc_ajx_booking_ajax_action_request( { |
| 3024 |
'booking_action' : '{$booking_action}', |
| 3025 |
'booking_id' : {{data['parsed_fields']['booking_id']}} |
| 3026 |
} ); |
| 3027 |
wpbc_button_enable_loading_icon( this ); |
| 3028 |
}", |
| 3029 |
'icon' => array( |
| 3030 |
'icon_font' => 'wpbc_icn_close', |
| 3031 |
'position' => 'left', |
| 3032 |
'icon_img' => '' |
| 3033 |
), |
| 3034 |
'class' => '', |
| 3035 |
'style' => '', |
| 3036 |
'mobile_show_text' => true, |
| 3037 |
'attr' => array() |
| 3038 |
); |
| 3039 |
|
| 3040 |
?><# if ( '1' == data['parsed_fields']['trash']) { #><?php |
| 3041 |
?><div class="ui_element"><?php |
| 3042 |
wpbc_flex_button( $params ); |
| 3043 |
?></div><?php |
| 3044 |
?><# } #><?php |
| 3045 |
} |
| 3046 |
|
| 3047 |
/** |
| 3048 |
* Show Approved booking Button |
| 3049 |
*/ |
| 3050 |
function wpbc_for_booking_template__action_approved(){ |
| 3051 |
|
| 3052 |
$booking_action = 'set_booking_approved'; |
| 3053 |
|
| 3054 |
if ( ! wpbc_is_user_can( $booking_action, wpbc_get_current_user_id() ) ) { |
| 3055 |
return false; |
| 3056 |
} |
| 3057 |
|
| 3058 |
$params = array( |
| 3059 |
'type' => 'button', |
| 3060 |
'title' => '', |
| 3061 |
'hint' => array( |
| 3062 |
'title' => __( 'Approve', 'booking' ), |
| 3063 |
'position' => 'top' |
| 3064 |
), |
| 3065 |
'link' => 'javascript:void(0)', |
| 3066 |
'action' => "wpbc_ajx_booking_ajax_action_request( { |
| 3067 |
'booking_action' : '{$booking_action}', |
| 3068 |
'booking_id' : {{data['parsed_fields']['booking_id']}} |
| 3069 |
} ); |
| 3070 |
wpbc_button_enable_loading_icon( this ); ", |
| 3071 |
'icon' => array( |
| 3072 |
'icon_font' => 'wpbc_icn_check_circle_outline', |
| 3073 |
'position' => 'left', |
| 3074 |
'icon_img' => '' |
| 3075 |
), |
| 3076 |
'class' => '', |
| 3077 |
'style' => '', |
| 3078 |
'mobile_show_text' => true, |
| 3079 |
'attr' => array() |
| 3080 |
); |
| 3081 |
|
| 3082 |
?><# if ( '0' == data['approved']) { #><?php |
| 3083 |
?><div class="ui_element"><?php |
| 3084 |
wpbc_flex_button( $params ); |
| 3085 |
?></div><?php |
| 3086 |
?><# } #><?php |
| 3087 |
} |
| 3088 |
|
| 3089 |
/** |
| 3090 |
* Show Pending booking Button |
| 3091 |
*/ |
| 3092 |
function wpbc_for_booking_template__action_pending(){ |
| 3093 |
|
| 3094 |
$booking_action = 'set_booking_pending'; |
| 3095 |
|
| 3096 |
if ( ! wpbc_is_user_can( $booking_action, wpbc_get_current_user_id() ) ) { |
| 3097 |
return false; |
| 3098 |
} |
| 3099 |
|
| 3100 |
$params = array( |
| 3101 |
'type' => 'button', |
| 3102 |
'title' => '', |
| 3103 |
'hint' => array( |
| 3104 |
'title' => __( 'Pending', 'booking' ), |
| 3105 |
'position' => 'top' |
| 3106 |
), |
| 3107 |
'link' => 'javascript:void(0)', |
| 3108 |
'action' => "if ( wpbc_are_you_sure('" . esc_attr( __( 'Do you really want to set booking as pending ?', 'booking' ) ) . "') ) { |
| 3109 |
wpbc_ajx_booking_ajax_action_request( { |
| 3110 |
'booking_action' : '{$booking_action}', |
| 3111 |
'booking_id' : {{data['parsed_fields']['booking_id']}} |
| 3112 |
} ); |
| 3113 |
wpbc_button_enable_loading_icon( this ); |
| 3114 |
}", |
| 3115 |
'icon' => array( |
| 3116 |
'icon_font' => 'wpbc_icn_block', |
| 3117 |
'position' => 'left', |
| 3118 |
'icon_img' => '' |
| 3119 |
), |
| 3120 |
'class' => '', |
| 3121 |
'style' => '', |
| 3122 |
'mobile_show_text' => true, |
| 3123 |
'attr' => array() |
| 3124 |
); |
| 3125 |
|
| 3126 |
?><# if ( '1' == data['approved']) { #><?php |
| 3127 |
?><div class="ui_element"><?php |
| 3128 |
wpbc_flex_button( $params ); |
| 3129 |
?></div><?php |
| 3130 |
?><# } #><?php |
| 3131 |
} |
| 3132 |
|
| 3133 |
/** |
| 3134 |
* Show Read booking Button |
| 3135 |
*/ |
| 3136 |
function wpbc_for_booking_template__action_read(){ |
| 3137 |
|
| 3138 |
$booking_action = 'set_booking_as_read'; |
| 3139 |
|
| 3140 |
if ( ! wpbc_is_user_can( $booking_action, wpbc_get_current_user_id() ) ) { |
| 3141 |
return false; |
| 3142 |
} |
| 3143 |
|
| 3144 |
$params = array( |
| 3145 |
'type' => 'button', |
| 3146 |
'title' => '', |
| 3147 |
'hint' => array( |
| 3148 |
'title' => __( 'New booking', 'booking' ), |
| 3149 |
'position' => 'top' |
| 3150 |
), |
| 3151 |
'link' => 'javascript:void(0)', |
| 3152 |
'action' => " wpbc_ajx_booking_ajax_action_request( { |
| 3153 |
'booking_action' : '{$booking_action}', |
| 3154 |
'booking_id' : {{data['parsed_fields']['booking_id']}} |
| 3155 |
} ); |
| 3156 |
wpbc_button_enable_loading_icon( this ); ", |
| 3157 |
'icon' => array( |
| 3158 |
'icon_font' => 'wpbc_icn_fiber_manual_record',// 'wpbc_icn_visibility', |
| 3159 |
'position' => 'left', |
| 3160 |
'icon_img' => '' |
| 3161 |
), |
| 3162 |
'class' => 'wpbc_is_new_button', |
| 3163 |
'style' => '', |
| 3164 |
'mobile_show_text' => true, |
| 3165 |
'attr' => array() |
| 3166 |
); |
| 3167 |
|
| 3168 |
?><# if ( '1' == data.parsed_fields.is_new ) { #><?php |
| 3169 |
wpbc_flex_button( $params ); |
| 3170 |
?><# } #><?php |
| 3171 |
} |
| 3172 |
|
| 3173 |
// </editor-fold> |
| 3174 |
|
| 3175 |
|
| 3176 |
|
| 3177 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 3178 |
// Support functions |
| 3179 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 3180 |
|
| 3181 |
/** |
| 3182 |
* Catch some errors, if such errors exist during our Ajx request |
| 3183 |
*/ |
| 3184 |
class WPBC_AJAX_ERROR_CATCHING{ |
| 3185 |
|
| 3186 |
public $errors_arr; |
| 3187 |
|
| 3188 |
function __construct() { |
| 3189 |
|
| 3190 |
$this->errors_arr = array(); |
| 3191 |
|
| 3192 |
// Catch Error messages |
| 3193 |
add_action( 'wp_error_added', array( $this, 'wpbc_wp_error_added' ), 10, 4 ); |
| 3194 |
|
| 3195 |
if ( ! defined( 'WPBC_AJAX_ERROR_CATCH' ) ) { define( 'WPBC_AJAX_ERROR_CATCH', true ); } // Check somewhere to not show error messages: if ( ( defined( 'WPBC_AJAX_ERROR_CATCH' ) ) && ( WPBC_AJAX_ERROR_CATCH ) ) { return false; } |
| 3196 |
} |
| 3197 |
|
| 3198 |
/** |
| 3199 |
* Catch Error messages |
| 3200 |
* |
| 3201 |
* @param $code |
| 3202 |
* @param $message |
| 3203 |
* @param $data |
| 3204 |
* @param $this_link |
| 3205 |
* |
| 3206 |
* @return void |
| 3207 |
*/ |
| 3208 |
function wpbc_wp_error_added( $code, $message, $data, $this_link ){ |
| 3209 |
|
| 3210 |
$this->errors_arr[] = array( |
| 3211 |
'code' => $code, |
| 3212 |
'message' => $message, |
| 3213 |
'data' => $data, |
| 3214 |
'this_link' => $this_link |
| 3215 |
) ; |
| 3216 |
} |
| 3217 |
|
| 3218 |
/** |
| 3219 |
* Get summary of all errors |
| 3220 |
* @return string |
| 3221 |
*/ |
| 3222 |
function get_error_messages(){ |
| 3223 |
|
| 3224 |
$error_message = array(); |
| 3225 |
|
| 3226 |
foreach ( $this->errors_arr as $error ) { |
| 3227 |
$error_message[] = 'Error: ' . $error['code'] . '. ' . $error['message']; |
| 3228 |
} |
| 3229 |
$error_message = implode( '<br/>', $error_message ); |
| 3230 |
|
| 3231 |
if ( ! empty( $error_message ) ) { |
| 3232 |
$error_message = '<div class="wpbc_ajx_errors">' |
| 3233 |
.'<br/><strong>' . esc_html__( 'Some errors were encountered.', 'booking' ) . '</strong><br/>' |
| 3234 |
. $error_message |
| 3235 |
. '</div>'; |
| 3236 |
} |
| 3237 |
return $error_message; |
| 3238 |
} |
| 3239 |
} |
| 3240 |
|
| 3241 |
|
| 3242 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 3243 |
// Check what user can do |
| 3244 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 3245 |
|
| 3246 |
/** |
| 3247 |
* Check permission of this user on specific actions, like approving or deleting of bookings |
| 3248 |
* |
| 3249 |
* @param string $action like 'set_pnding' |
| 3250 |
* @param int $user_id like 1 |
| 3251 |
* |
| 3252 |
* @return bool |
| 3253 |
*/ |
| 3254 |
function wpbc_is_user_can( $action, $user_id = 0 ){ |
| 3255 |
|
| 3256 |
if ( 0 == $user_id ) { |
| 3257 |
$user_id = wpbc_get_current_user_id(); |
| 3258 |
} |
| 3259 |
$user = get_userdata( $user_id ); |
| 3260 |
$user_roles = (array) ( empty( $user ) ? array() : $user->roles ); // Standard WordPress Roles: 'administrator' | 'editor' | 'author' | 'contributor' | 'subscriber' |
| 3261 |
|
| 3262 |
|
| 3263 |
// Get here list of actions that user can do |
| 3264 |
switch ( $action ) { |
| 3265 |
case 'set_booking_pending': |
| 3266 |
break; |
| 3267 |
case 'set_booking_approved': |
| 3268 |
break; |
| 3269 |
case 'move_booking_to_trash': |
| 3270 |
break; |
| 3271 |
case 'restore_booking_from_trash': |
| 3272 |
break; |
| 3273 |
case 'delete_booking_completely': |
| 3274 |
// if ( ! in_array( 'administrator', $user_roles ) ) { return false; } |
| 3275 |
break; |
| 3276 |
case 'booking_add_google_calendar': |
| 3277 |
break; |
| 3278 |
case 'set_booking_locale': |
| 3279 |
break; |
| 3280 |
case 'set_booking_as_read': |
| 3281 |
break; |
| 3282 |
case 'set_booking_as_unread': |
| 3283 |
break; |
| 3284 |
case 'empty_trash': |
| 3285 |
break; |
| 3286 |
case 'set_booking_note': |
| 3287 |
break; |
| 3288 |
case 'edit_booking': |
| 3289 |
break; |
| 3290 |
case 'change_booking_resource': |
| 3291 |
break; |
| 3292 |
case 'duplicate_booking_to_other_resource': |
| 3293 |
break; |
| 3294 |
case 'set_payment_status': |
| 3295 |
break; |
| 3296 |
case 'set_booking_cost': |
| 3297 |
break; |
| 3298 |
case 'send_payment_request': |
| 3299 |
break; |
| 3300 |
case 'import_google_calendar': |
| 3301 |
break; |
| 3302 |
case 'export_csv': |
| 3303 |
break; |
| 3304 |
default: |
| 3305 |
// Default |
| 3306 |
} |
| 3307 |
|
| 3308 |
return true; |
| 3309 |
} |