← All changes
|
includes/page-availability/availability__class.php
+146
-65
10.1.3
→
11.8.3
View file →
| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | <?php /** |
| 2 | 2 | * @version 1.0 |
| 3 | 3 | * @description WPBC_AJX__Availability |
| 4 | 4 | * @category WPBC_AJX__Availability Class |
| @@ -21,10 +21,11 @@ | ||
| 21 | 21 | * Define HOOKs for loading CSS and JavaScript files |
| 22 | 22 | */ |
| 23 | 23 | public function init_load_css_js_tpl() { |
| 24 | 24 | |
| 25 | + $server_request_uri = ( ( isset( $_SERVER['REQUEST_URI'] ) ) ? sanitize_text_field( $_SERVER['REQUEST_URI'] ) : '' ); /* phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash */ /* FixIn: sanitize_unslash */ | |
| 25 | 26 | // Load only at specific Page |
| 26 | - if ( strpos( $_SERVER['REQUEST_URI'], 'page=wpbc-availability' ) !== false ) { | |
| 27 | + if ( strpos( $server_request_uri, 'page=wpbc-availability' ) !== false ) { | |
| 27 | 28 | |
| 28 | 29 | add_action( 'wpbc_enqueue_js_files', array( $this, 'js_load_files' ), 50 ); |
| 29 | 30 | add_action( 'wpbc_enqueue_css_files', array( $this, 'enqueue_css_files' ), 50 ); |
| 30 | 31 | |
| @@ -41,21 +42,17 @@ | ||
| 41 | 42 | if ( wpbc_is_availability_page() ) |
| 42 | 43 | if ( ( is_admin() ) && ( in_array( $where_to_load, array( 'admin', 'both' ) ) ) ) { |
| 43 | 44 | |
| 44 | 45 | wp_enqueue_script( 'wpbc-ajx_availability_page' |
| 45 | - , trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/availability_page.js' /* wpbc_plugin_url( '/_out/js/codemirror.js' ) */ | |
| 46 | - , array( 'wpbc-global-vars' ), WP_BK_VERSION_NUM, $in_footer ); //FixIn: 9.8.1 | |
| 46 | + , trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/availability_page.js' /* wpbc_plugin_url( '/_out/js/code_mirror.js' ) */ | |
| 47 | + , array( 'wpbc_all' ), WP_BK_VERSION_NUM, $in_footer ); //FixIn: 9.8.1 | |
| 47 | 48 | |
| 48 | - wp_enqueue_script( 'wpbc-general_ui_js_css' | |
| 49 | - , wpbc_plugin_url( '/includes/_general_ui_js_css/_out/wpbc_main_ui_funcs.js' ) | |
| 50 | - , array( 'wpbc-global-vars' ), WP_BK_VERSION_NUM, $in_footer ); //FixIn: 9.8.1 | |
| 51 | - | |
| 52 | - wp_enqueue_script( 'wpbc_all', wpbc_plugin_url( '/_dist/all/_out/wpbc_all.js' ), array( 'wpbc-datepick' ), WP_BK_VERSION_NUM ); //FixIn: 9.8.6.1 | |
| 53 | - wp_enqueue_script( 'wpbc-main-client', wpbc_plugin_url( '/js/client.js' ), array( 'wpbc-datepick' ), WP_BK_VERSION_NUM ); | |
| 54 | - wp_enqueue_script( 'wpbc-times', wpbc_plugin_url( '/js/wpbc_times.js' ), array( 'wpbc-main-client' ), WP_BK_VERSION_NUM ); | |
| 49 | + wp_enqueue_script( 'wpbc_all', wpbc_plugin_url( '/_dist/all/_out/wpbc_all.js' ), array( 'jquery' ), WP_BK_VERSION_NUM, array( 'in_footer' => WPBC_JS_IN_FOOTER ) ); // FixIn: 9.8.6.1. | |
| 50 | + 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 ) ); | |
| 51 | + wp_enqueue_script( 'wpbc-times', wpbc_plugin_url( '/js/wpbc_times.js' ), array( 'wpbc-main-client' ), WP_BK_VERSION_NUM, array( 'in_footer' => WPBC_JS_IN_FOOTER ) ); | |
| 55 | 52 | /** |
| 56 | 53 | * |
| 57 | - * wp_localize_script( 'wpbc-global-vars', 'wpbc_live_request_obj' | |
| 54 | + * wp_localize_script( 'wpbc_all', 'wpbc_live_request_obj' | |
| 58 | 55 | * , array( |
| 59 | 56 | * 'ajx_booking' => '', |
| 60 | 57 | * 'reminders' => '' |
| 61 | 58 | * ) |
| @@ -91,9 +88,9 @@ | ||
| 91 | 88 | |
| 92 | 89 | $default_resource_id = wpbc_get_default_resource(); |
| 93 | 90 | |
| 94 | 91 | return array( |
| 95 | - 'do_action' => array( 'validate' => array( 'none', 'set_availability', 'make_reset', 'erase_availability' ), 'default' => 'none' ) | |
| 92 | + 'do_action' => array( 'validate' => array( 'none', 'set_availability', 'make_reset', 'erase_availability', 'change_month_number_in_row' ), 'default' => 'none' ) // FixIn: 10.8.1.5. | |
| 96 | 93 | |
| 97 | 94 | , 'resource_id' => array( 'validate' => 'd', 'default' => $default_resource_id ) // 'digit_or_csd' can check about 'digit_or_csd' in arrays, as well // if ['0'] - All booking resources |
| 98 | 95 | , 'dates_selection' => array( 'validate' => 's', 'default' => '' ) |
| 99 | 96 | , 'dates_availability' => array( 'validate' => array( 'unavailable', 'available' ), 'default' => 'unavailable' ) |
| @@ -101,12 +98,12 @@ | ||
| 101 | 98 | , 'ui_clicked_element_id' => array( 'validate' => 's', 'default' => '' ) |
| 102 | 99 | , 'ui_usr__availability_selected_toolbar' => array( 'validate' => array( 'info', 'calendar_settings' ), 'default' => 'info' ) |
| 103 | 100 | |
| 104 | 101 | // Calendar settings |
| 105 | - , 'calendar__start_week_day' => array( 'validate' => array( '0','1','2','3','4','5','6' ), 'default' => get_bk_option( 'booking_start_day_weeek' ) ) | |
| 102 | + , 'calendar__start_week_day' => array( 'validate' => array( '0','1','2','3','4','5','6' ), 'default' => intval(get_bk_option( 'booking_start_day_weeek' )) ) | |
| 106 | 103 | , 'calendar__days_selection_mode' => array( 'validate' => array( 'multiple', 'dynamic' ), 'default' => 'dynamic' ) |
| 107 | 104 | , 'calendar__view__visible_months' => array( 'validate' => 'd', 'default' => 12 ) |
| 108 | - , 'calendar__view__months_in_row' => array( 'validate' => 'd', 'default' => 4 ) | |
| 105 | + , 'calendar__view__months_in_row' => array( 'validate' => 'd', 'default' => 3 ) // FixIn: 10.8.1.5. | |
| 109 | 106 | , 'calendar__view__width' => array( 'validate' => 's', 'default' => '100%' ) |
| 110 | 107 | , 'calendar__view__max_width' => array( 'validate' => 's', 'default' => '' ) // default '' it's will be set as 341px, |
| 111 | 108 | , 'calendar__view__cell_height' => array( 'validate' => 's', 'default' => '38px' ) // '48px' || '' |
| 112 | 109 | |
| @@ -115,11 +112,8 @@ | ||
| 115 | 112 | // , 'calendar__view__width' => array( 'validate' => 's', 'default' => '300px' ) |
| 116 | 113 | // , 'calendar__view__max_width' => array( 'validate' => 's', 'default' => '300px' ) // default '' it's will be set as 341px, |
| 117 | 114 | // , 'calendar__view__cell_height' => array( 'validate' => 's', 'default' => '48px' ) // '45px' || '' |
| 118 | 115 | |
| 119 | - , 'calendar__timeslot_day_bg_as_available' => array( 'validate' => 's' | |
| 120 | - , 'default' => ('On' === get_bk_option( 'booking_timeslot_day_bg_as_available' ) ) ? ' wpbc_timeslot_day_bg_as_available' : '' ) | |
| 121 | - | |
| 122 | 116 | ); |
| 123 | 117 | |
| 124 | 118 | } |
| 125 | 119 | |
| @@ -159,14 +153,14 @@ | ||
| 159 | 153 | * @param $page string |
| 160 | 154 | */ |
| 161 | 155 | public function hook__page_footer_tmpl( $page ){ |
| 162 | 156 | |
| 163 | - // page=wpbc&view_mode=vm_booking_listing | |
| 157 | + // page=wpbc&tab=vm_booking_listing | |
| 164 | 158 | if ( 'wpbc-ajx_booking_availability' === $page ) { // from >> do_action( 'wpbc_hook_settings_page_footer', 'wpbc-ajx_booking_availability' ); as availability_page.php in bottom of content method |
| 165 | 159 | $this->template__main_page_content(); |
| 166 | 160 | |
| 167 | 161 | $this->template_toolbar_select_booking_resource(); |
| 168 | - | |
| 162 | + $this->template_toolbar_select_month_number_in_row(); // FixIn: 10.8.1.5. | |
| 169 | 163 | $this->template__widget_available_unavailable(); |
| 170 | 164 | $this->template__widget_calendar_legend(); |
| 171 | 165 | } |
| 172 | 166 | } |
| @@ -196,9 +190,9 @@ | ||
| 196 | 190 | <?php |
| 197 | 191 | $is_booking_change_over_days_triangles = get_bk_option( 'booking_change_over_days_triangles' ); |
| 198 | 192 | $is_booking_change_over_days_triangles = ( $is_booking_change_over_days_triangles !== 'Off' ) ? "wpbc_change_over_triangle" : ''; |
| 199 | 193 | ?> |
| 200 | - <div class="wpbc_ajx_avy__calendar <?php echo $is_booking_change_over_days_triangles; ?>"><?php _e('Calendar is loading...', 'booking'); ?></div> | |
| 194 | + <div class="wpbc_ajx_avy__calendar <?php echo esc_attr( $is_booking_change_over_days_triangles ); ?>"><?php esc_html_e('Calendar is loading...', 'booking'); ?></div> | |
| 201 | 195 | </div> |
| 202 | 196 | <div class="wpbc_ajx_avy__section_right"> |
| 203 | 197 | <div class="wpbc_widgets"> |
| 204 | 198 | <# <?php if (0) { ?><script type="text/javascript"><?php } ?> |
| @@ -208,8 +202,12 @@ | ||
| 208 | 202 | |
| 209 | 203 | var wpbc_widget__available_unavailable = wp.template( 'wpbc_ajx_widget_available_unavailable' ); |
| 210 | 204 | var wpbc_widget__calendar_legend = wp.template( 'wpbc_ajx_widget_calendar_legend' ); |
| 211 | 205 | |
| 206 | + // FixIn: 10.8.1.5. | |
| 207 | + var wpbc_ajx_select_month_number_in_row = wp.template( 'wpbc_ajx_select_month_number_in_row' ); | |
| 208 | + jQuery( '#wpbc_template__select_month_number_in_row').html( wpbc_ajx_select_month_number_in_row( data ) ); | |
| 209 | + | |
| 212 | 210 | <?php if (0) { ?></script><?php } ?> |
| 213 | 211 | #> |
| 214 | 212 | |
| 215 | 213 | {{{ wpbc_widget__available_unavailable( data.ajx_cleaned_params ) }}} |
| @@ -226,9 +224,9 @@ | ||
| 226 | 224 | |
| 227 | 225 | ?><script type="text/html" id="tmpl-wpbc_ajx_widget_available_unavailable"> |
| 228 | 226 | <div class="wpbc_widget wpbc_widget_available_unavailable"> |
| 229 | 227 | <div class="wpbc_widget_header"> |
| 230 | - <span class="wpbc_widget_header_text"><?php _e('Apply availability', 'booking'); ?></span> | |
| 228 | + <span class="wpbc_widget_header_text"><?php esc_html_e('Apply availability', 'booking'); ?></span> | |
| 231 | 229 | <a href="/" class="wpbc_widget_header_settings_link"><i class="menu_icon icon-1x wpbc_icn_settings"></i></a> |
| 232 | 230 | </div> |
| 233 | 231 | <div class="wpbc_widget_content wpbc_ajx_toolbar" style="margin:0 0 20px;"> |
| 234 | 232 | <div class="ui_container" > |
| @@ -287,9 +285,9 @@ | ||
| 287 | 285 | |
| 288 | 286 | ?><script type="text/html" id="tmpl-wpbc_ajx_widget_calendar_legend"> |
| 289 | 287 | <div class="wpbc_widget wpbc_widget_calendar_legend"> |
| 290 | 288 | <div class="wpbc_widget_header"> |
| 291 | - <span class="wpbc_widget_header_text"><?php _e('Calendar Legend', 'booking'); ?></span> | |
| 289 | + <span class="wpbc_widget_header_text"><?php esc_html_e('Calendar Legend', 'booking'); ?></span> | |
| 292 | 290 | <a href="/" class="wpbc_widget_header_settings_link"><i class="menu_icon icon-1x wpbc_icn_settings"></i></a> |
| 293 | 291 | </div> |
| 294 | 292 | <div class="wpbc_widget_content wpbc_ajx_toolbar" style="margin:0 0 20px;"> |
| 295 | 293 | <div class="ui_container" > |
| @@ -296,9 +294,9 @@ | ||
| 296 | 294 | <div class="ui_group ui_group__available_unavailable"><?php |
| 297 | 295 | |
| 298 | 296 | ?><div class="ui_element ui_nowrap"><?php |
| 299 | 297 | |
| 300 | - //echo wpbc_replace_shortcodes_in_booking_form__legend_items( '[legend_items]' ); | |
| 298 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 301 | 299 | echo wpbc_replace_shortcodes_in_booking_form__legend_items( |
| 302 | 300 | '[legend_items' |
| 303 | 301 | . ' items="resource_unavailable"' |
| 304 | 302 | . ' titles="resource_unavailable={' |
| @@ -303,9 +301,9 @@ | ||
| 303 | 301 | . ' items="resource_unavailable"' |
| 304 | 302 | . ' titles="resource_unavailable={' |
| 305 | 303 | . htmlspecialchars( __( "Resource unavailable days", 'booking' ), ENT_QUOTES) |
| 306 | 304 | . '}"' |
| 307 | - . ' text_for_day_cell="' . date( 'd' ) . '"' | |
| 305 | + . ' text_for_day_cell="' . gmdate( 'd' ) . '"' | |
| 308 | 306 | . ' unavailable_day_cell_tag="a"' |
| 309 | 307 | .']' |
| 310 | 308 | ); |
| 311 | 309 | ?></div><?php |
| @@ -312,8 +310,9 @@ | ||
| 312 | 310 | |
| 313 | 311 | ?><div style="border-top:1px solid #d3d3d3;width:100%;margin: 10px 0 -5px;"></div><?php |
| 314 | 312 | |
| 315 | 313 | ?><div class="ui_element ui_nowrap"><?php |
| 314 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 316 | 315 | echo wpbc_replace_shortcodes_in_booking_form__legend_items( |
| 317 | 316 | '[legend_items' |
| 318 | 317 | . ' items="unavailable,available,pending,approved,partially"' |
| 319 | 318 | . ' titles="' |
| @@ -319,9 +318,9 @@ | ||
| 319 | 318 | . ' titles="' |
| 320 | 319 | //.' unavailable={' . htmlspecialchars( __( "Unavailable", 'booking' ), ENT_QUOTES ) . '}' |
| 321 | 320 | //.' pending={' . htmlspecialchars( __( "Pending", 'booking' ), ENT_QUOTES ) . '}' |
| 322 | 321 | .'"' |
| 323 | - . ' text_for_day_cell="' . date( 'd' ) . '"' | |
| 322 | + . ' text_for_day_cell="' . gmdate( 'd' ) . '"' | |
| 324 | 323 | . ' unavailable_day_cell_tag="span"' |
| 325 | 324 | .']' |
| 326 | 325 | ); |
| 327 | 326 | |
| @@ -350,11 +349,9 @@ | ||
| 350 | 349 | if ( ! class_exists('wpdev_bk_personal') ) { |
| 351 | 350 | echo '</script>'; |
| 352 | 351 | return false; |
| 353 | 352 | } |
| 354 | - /* | |
| 355 | - ?><# console.log( ' == TEMPLATE PARAMS "wpbc_ajx_change_booking_resource" == ', data ); #><?php | |
| 356 | - */ | |
| 353 | + | |
| 357 | 354 | $booking_action = 'select_booking_resource'; |
| 358 | 355 | |
| 359 | 356 | $el_id = 'ui_btn_' . $booking_action; |
| 360 | 357 | |
| @@ -368,14 +365,14 @@ | ||
| 368 | 365 | |
| 369 | 366 | wpbc_flex_label( |
| 370 | 367 | array( |
| 371 | 368 | 'id' => $el_id |
| 372 | - , 'label' => '<span class="" style="font-weight:600;">' . __( 'Booking resource', 'booking' ) . ':</span>' | |
| 369 | + , 'label' => '<span class="" style="font-weight:600;">' . esc_html__( 'Booking resource', 'booking' ) . ':</span>' | |
| 373 | 370 | ) |
| 374 | 371 | ); |
| 375 | 372 | |
| 376 | 373 | ?><select class="wpbc_ui_control wpbc_ui_select change_booking_resource_selectbox" |
| 377 | - id="<?php echo $el_id; ?>" name="<?php echo $el_id; ?>" | |
| 374 | + id="<?php echo esc_attr( $el_id ); ?>" name="<?php echo esc_attr( $el_id ); ?>" | |
| 378 | 375 | |
| 379 | 376 | <?php /* ?>onfocus="javascript:console.log( 'ON FOCUS:', jQuery( this ).val(), 'in element:' , jQuery( this ) );"<?php /**/ ?> |
| 380 | 377 | |
| 381 | 378 | onchange="javascript:wpbc_admin_show_message_processing( '' );wpbc_ajx_availability__send_request_with_params( { |
| @@ -422,8 +419,62 @@ | ||
| 422 | 419 | |
| 423 | 420 | ?></script><?php |
| 424 | 421 | } |
| 425 | 422 | |
| 423 | + | |
| 424 | + | |
| 425 | + private function template_toolbar_select_month_number_in_row(){ // FixIn: 10.8.1.5. | |
| 426 | + | |
| 427 | + // Template | |
| 428 | + ?><script type="text/html" id="tmpl-wpbc_ajx_select_month_number_in_row"><?php | |
| 429 | + | |
| 430 | + /* | |
| 431 | + ?><# console.log( ' == TEMPLATE PARAMS "wpbc_ajx_change_month_number_in_row" == ', data ); #><?php | |
| 432 | + */ | |
| 433 | + $booking_action = 'select_month_number_in_row'; | |
| 434 | + | |
| 435 | + $el_id = 'ui_btn_' . $booking_action; | |
| 436 | + | |
| 437 | + ?><div class="ui_element"><?php | |
| 438 | + ?><div class="wpbc_ui_separtor" style="margin-left: 8px;"></div><?php | |
| 439 | + ?></div><?php | |
| 440 | + | |
| 441 | + ?><div class="ui_element"><?php | |
| 442 | + | |
| 443 | + wpbc_flex_label( | |
| 444 | + array( | |
| 445 | + 'id' => $el_id | |
| 446 | + , 'label' => '<span class="" style="font-weight:600;">' . esc_html__( 'Number of months in a row', 'booking' ) . ':</span>' | |
| 447 | + ) | |
| 448 | + ); | |
| 449 | + | |
| 450 | + ?><select class="wpbc_ui_control wpbc_ui_select change_month_number_in_row_selectbox" | |
| 451 | + id="<?php echo esc_attr( $el_id ); ?>" name="<?php echo esc_attr( $el_id ); ?>" | |
| 452 | + | |
| 453 | + <?php /* ?>onfocus="javascript:console.log( 'ON FOCUS:', jQuery( this ).val(), 'in element:' , jQuery( this ) );"<?php /**/ ?> | |
| 454 | + | |
| 455 | + onchange="javascript:wpbc_admin_show_message_processing( '' );wpbc_ajx_availability__send_request_with_params( { | |
| 456 | + 'calendar__view__months_in_row': jQuery( '.change_month_number_in_row_selectbox option:selected' ).val() | |
| 457 | + , 'do_action': 'change_month_number_in_row' | |
| 458 | + } );" | |
| 459 | + ><# | |
| 460 | + for (var month_index = 2; month_index < 7; month_index++ ){ | |
| 461 | + #><option value="{{month_index}}" | |
| 462 | + <# | |
| 463 | + if ( data.ajx_cleaned_params.calendar__view__months_in_row == month_index ) { | |
| 464 | + #> selected="SELECTED" <# | |
| 465 | + } | |
| 466 | + #> | |
| 467 | + >{{month_index}}</option><# | |
| 468 | + } | |
| 469 | + #> | |
| 470 | + </select><?php | |
| 471 | + | |
| 472 | + ?></div><?php | |
| 473 | + | |
| 474 | + ?></script><?php | |
| 475 | + } | |
| 476 | + | |
| 426 | 477 | // </editor-fold> |
| 427 | 478 | |
| 428 | 479 | |
| 429 | 480 | |
| @@ -451,8 +502,9 @@ | ||
| 451 | 502 | * Ajax - Get Listing Data and Response to JS script |
| 452 | 503 | */ |
| 453 | 504 | public function ajax_WPBC_AJX_AVAILABILITY() { |
| 454 | 505 | |
| 506 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing | |
| 455 | 507 | if ( ! isset( $_POST['search_params'] ) || empty( $_POST['search_params'] ) ) { exit; } |
| 456 | 508 | |
| 457 | 509 | // Security ----------------------------------------------------------------------------------------------- // in Ajax Post: 'nonce': wpbc_ajx_booking_listing.get_secure_param( 'nonce' ), |
| 458 | 510 | $action_name = 'wpbc_ajx_availability_ajx' . '_wpbcnonce'; |
| @@ -458,9 +510,9 @@ | ||
| 458 | 510 | $action_name = 'wpbc_ajx_availability_ajx' . '_wpbcnonce'; |
| 459 | 511 | $nonce_post_key = 'nonce'; |
| 460 | 512 | $result_check = check_ajax_referer( $action_name, $nonce_post_key ); |
| 461 | 513 | |
| 462 | - $user_id = ( isset( $_REQUEST['wpbc_ajx_user_id'] ) ) ? intval( $_REQUEST['wpbc_ajx_user_id'] ) : wpbc_get_current_user_id(); | |
| 514 | + $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 | |
| 463 | 515 | |
| 464 | 516 | /** |
| 465 | 517 | * SQL --------------------------------------------------------------------------- |
| 466 | 518 | * |
| @@ -479,9 +531,40 @@ | ||
| 479 | 531 | $request_prefix = 'search_params'; |
| 480 | 532 | $request_params = $user_request->get_sanitized__in_request__value_or_default( $request_prefix ); // NOT Direct: $_REQUEST['search_params']['resource_id'] |
| 481 | 533 | |
| 482 | 534 | //---------------------------------------------------------------------------------------------------------- |
| 535 | + // Get booking resources (sql) | |
| 536 | + $resources_arr = wpbc_ajx_get_all_booking_resources_arr(); /** | |
| 537 | + * Array ( [0] => Array ( [booking_type_id] => 1 | |
| 538 | + [title] => Standard | |
| 539 | + [users] => 1 | |
| 540 | + [import] => | |
| 541 | + [export] => | |
| 542 | + [cost] => 25 | |
| 543 | + [default_form] => standard | |
| 544 | + [prioritet] => 0 | |
| 545 | + [parent] => 0 | |
| 546 | + [visitors] => 2 | |
| 547 | + ), ... */ | |
| 483 | 548 | |
| 549 | + $resources_arr_sorted = wpbc_ajx_get_sorted_booking_resources_arr( $resources_arr ); | |
| 550 | + | |
| 551 | + // FixIn: 10.3.0.7. | |
| 552 | + // Check if $request_params['resource_id'] exist in $resources_arr_sorted, because it possible situation, when some booking resources was deleted and we do not need to load old data. | |
| 553 | + $is_resource_exist = false; | |
| 554 | + foreach ( $resources_arr_sorted as $resource_index => $resource_value_arr ) { | |
| 555 | + if ( intval( $resource_value_arr['booking_type_id'] ) === intval( $request_params['resource_id'] ) ) { | |
| 556 | + $is_resource_exist = true; | |
| 557 | + break; // All good | |
| 558 | + } | |
| 559 | + } | |
| 560 | + if ( ! $is_resource_exist ) { | |
| 561 | + if ( count( $resources_arr_sorted ) > 0 ) { | |
| 562 | + $request_params['resource_id'] = intval( $resources_arr_sorted[0]['booking_type_id'] ); | |
| 563 | + } | |
| 564 | + } | |
| 565 | + | |
| 566 | + | |
| 484 | 567 | $data_arr = array(); |
| 485 | 568 | $data_arr['ajx_after_action_message'] = ''; |
| 486 | 569 | $data_arr['ajx_after_action_result'] = 1; |
| 487 | 570 | |
| @@ -496,13 +579,15 @@ | ||
| 496 | 579 | ) ); |
| 497 | 580 | |
| 498 | 581 | if ( false !== $row_number ) { |
| 499 | 582 | if ( 'available' == $request_params['dates_availability'] ) { |
| 500 | - $data_arr['ajx_after_action_message'] = sprintf( _n( '%s date has been set as %s available %s', '%s dates has been set as %s available %s', $row_number, 'booking' ) | |
| 583 | + /* translators: 1: ... */ | |
| 584 | + $data_arr['ajx_after_action_message'] = sprintf( _n( '%1$s date has been set as %2$s available %3$s', '%1$s dates has been set as %2$s available %3$s', $row_number, 'booking' ) | |
| 501 | 585 | , '<strong>' . $row_number . '</strong>' |
| 502 | 586 | , '<strong style="color:#11be4c;">', '</strong>' ); |
| 503 | 587 | } else { |
| 504 | - $data_arr['ajx_after_action_message'] = sprintf( _n( '%s date has been set as %s unavailable %s', '%s dates has been set as %s unavailable %s', $row_number, 'booking' ) | |
| 588 | + /* translators: 1: ... */ | |
| 589 | + $data_arr['ajx_after_action_message'] = sprintf( _n( '%1$s date has been set as %2$s unavailable %3$s', '%1$s dates has been set as %2$s unavailable %3$s', $row_number, 'booking' ) | |
| 505 | 590 | , '<strong>' . $row_number . '</strong>' |
| 506 | 591 | , '<strong style="color:#e43939;">', '</strong>' ); |
| 507 | 592 | } |
| 508 | 593 | $data_arr['ajx_after_action_result'] = ( $row_number > 0 ) ? 1 : 0; |
| @@ -518,8 +603,9 @@ | ||
| 518 | 603 | //'prop_value' => $request_params['dates_availability'], // 'available', 'unavailable' , 'pending', 'approved' |
| 519 | 604 | 'dates_selection' => 'all' // '2023-04-04 | 2023-04-07' |
| 520 | 605 | ) ); |
| 521 | 606 | $data_arr['ajx_after_action_message'] = ( $row_number > 0 ) |
| 607 | + /* translators: 1: ... */ | |
| 522 | 608 | ? sprintf( __( 'All %s unavailable dates has been removed', 'booking' ), '<strong>' . $row_number . '</strong>' ) |
| 523 | 609 | : sprintf( __( 'No unavailable dates.', 'booking' ), $row_number ); |
| 524 | 610 | $data_arr['ajx_after_action_result'] = ( $row_number > 0 ) ? 1 : 0; |
| 525 | 611 | |
| @@ -524,10 +610,16 @@ | ||
| 524 | 610 | $data_arr['ajx_after_action_result'] = ( $row_number > 0 ) ? 1 : 0; |
| 525 | 611 | |
| 526 | 612 | } |
| 527 | 613 | |
| 614 | + // FixIn: 10.8.1.5. | |
| 615 | + if ( 'change_month_number_in_row' == $request_params['do_action'] ) { | |
| 616 | + // $request_params['calendar__view__months_in_row']; // Saving this parameter | |
| 617 | + /* translators: 1: ... */ | |
| 618 | + $data_arr['ajx_after_action_message'] = sprintf( __( 'Set month number in a row as %s', 'booking' ), '<strong>' . $request_params['calendar__view__months_in_row'] . '</strong>' ); | |
| 619 | + $data_arr['ajx_after_action_result'] = 1; | |
| 620 | + } | |
| 528 | 621 | |
| 529 | - | |
| 530 | 622 | $data_arr['booked_dates'] = wpbc__sql__get_booked_dates( array( |
| 531 | 623 | 'resource_id' => $request_params['resource_id'] |
| 532 | 624 | ) ); |
| 533 | 625 | |
| @@ -539,24 +631,9 @@ | ||
| 539 | 631 | |
| 540 | 632 | |
| 541 | 633 | //---------------------------------------------------------------------------------------------------------- |
| 542 | 634 | |
| 543 | - // Get booking resources (sql) | |
| 544 | - $resources_arr = wpbc_ajx_get_all_booking_resources_arr(); /** | |
| 545 | - * Array ( [0] => Array ( [booking_type_id] => 1 | |
| 546 | - [title] => Standard | |
| 547 | - [users] => 1 | |
| 548 | - [import] => | |
| 549 | - [export] => | |
| 550 | - [cost] => 25 | |
| 551 | - [default_form] => standard | |
| 552 | - [prioritet] => 0 | |
| 553 | - [parent] => 0 | |
| 554 | - [visitors] => 2 | |
| 555 | - ), ... */ | |
| 556 | 635 | |
| 557 | - $resources_arr_sorted = wpbc_ajx_get_sorted_booking_resources_arr( $resources_arr ); | |
| 558 | - | |
| 559 | 636 | $data_arr['ajx_booking_resources'] = $resources_arr_sorted; |
| 560 | 637 | |
| 561 | 638 | //---------------------------------------------------------------------------------------------------------- |
| 562 | 639 | |
| @@ -563,19 +640,23 @@ | ||
| 563 | 640 | $data_arr['ajx_nonce_calendar'] = wp_nonce_field( 'CALCULATE_THE_COST', 'wpbc_nonce' . 'CALCULATE_THE_COST' . $request_params['resource_id'], true, false ); |
| 564 | 641 | |
| 565 | 642 | $data_arr['popover_hints'] = array(); |
| 566 | 643 | |
| 567 | - $data_arr['popover_hints']['season_unavailable'] = '<strong>' . __( 'Season unavailable day', 'booking' ) . '</strong><hr>' | |
| 568 | - . sprintf( __( 'Change this date status at %sBooking Calendar %s Availability %s Season Availability page.', 'booking' ), '<br>', '>', '>' ); | |
| 569 | - $data_arr['popover_hints']['weekdays_unavailable'] = '<strong>' . __( 'Unavailable week day', 'booking' ) . '</strong><hr>' | |
| 570 | - . sprintf( __( 'Change this date status at %sBooking Calendar %s Settings General page %s in "Availability" section.', 'booking' ), '<br>', '>', '<br>' ); | |
| 571 | - $data_arr['popover_hints']['before_after_unavailable'] = '<strong>' . __( 'Unavailable day, depends on today day', 'booking' ) . '</strong><hr>' | |
| 572 | - . sprintf( __( 'Change this date status at %sBooking Calendar %s Settings General page %s in "Availability" section.', 'booking' ), '<br>', '>', '<br>' ); | |
| 644 | + $data_arr['popover_hints']['season_unavailable'] = '<strong>' . esc_html__( 'Season unavailable day', 'booking' ) . '</strong><hr>' | |
| 645 | + /* translators: 1: ... */ | |
| 646 | + . sprintf( __( 'Change this date status at %1$sBooking Calendar %2$s Availability %3$s Seasonal Availability page.', 'booking' ), '<br>', '>', '>' ); | |
| 647 | + $data_arr['popover_hints']['weekdays_unavailable'] = '<strong>' . esc_html__( 'Unavailable week day', 'booking' ) . '</strong><hr>' | |
| 648 | + /* translators: 1: ... */ | |
| 649 | + . sprintf( __( 'Change this date status at %1$sBooking Calendar %2$s Settings General page %3$s in "Availability" section.', 'booking' ), '<br>', '>', '<br>' ); | |
| 650 | + $data_arr['popover_hints']['before_after_unavailable'] = '<strong>' . esc_html__( 'Unavailable day, depends on today day', 'booking' ) . '</strong><hr>' | |
| 651 | + /* translators: 1: ... */ | |
| 652 | + . sprintf( __( 'Change this date status at %1$sBooking Calendar %2$s Settings General page %3$s in "Availability" section.', 'booking' ), '<br>', '>', '<br>' ); | |
| 573 | 653 | |
| 574 | 654 | |
| 575 | 655 | |
| 576 | 656 | $data_arr['popover_hints']['toolbar_text'] = '<span style="font-size: 1.05em;line-height: 1.8em;">'. |
| 577 | - sprintf( __('%sSelect days%s in calendar then select %sAvailable%s / %sUnavailable%s status and click %sApply%s availability button.' ,'booking') | |
| 657 | + /* translators: 1: ... */ | |
| 658 | + sprintf( __( '%1$sSelect days%2$s in calendar then select %3$sAvailable%4$s / %5$sUnavailable%6$s status and click %7$sApply%8$s availability button.', 'booking' ) | |
| 578 | 659 | , '<strong>', ' </strong>' |
| 579 | 660 | , '<strong> ', ' </strong>' |
| 580 | 661 | , '<strong> ', ' </strong>' |
| 581 | 662 | , '<strong> ', ' </strong>' |
| @@ -580,13 +661,15 @@ | ||
| 580 | 661 | , '<strong> ', ' </strong>' |
| 581 | 662 | , '<strong> ', ' </strong>' |
| 582 | 663 | ) |
| 583 | 664 | .'</span>'; |
| 584 | - $data_arr['popover_hints']['toolbar_text_available'] = sprintf( __( 'Set dates %s as %s available.', 'booking' ) | |
| 665 | + /* translators: 1: ... */ | |
| 666 | + $data_arr['popover_hints']['toolbar_text_available'] = sprintf( __( 'Set dates %1$s as %2$s available.', 'booking' ) | |
| 585 | 667 | , '_DATES_' |
| 586 | 668 | , '_HTML_' |
| 587 | 669 | ); |
| 588 | - $data_arr['popover_hints']['toolbar_text_unavailable'] = sprintf( __( 'Set dates %s as %s unavailable.', 'booking' ) | |
| 670 | + /* translators: 1: ... */ | |
| 671 | + $data_arr['popover_hints']['toolbar_text_unavailable'] = sprintf( __( 'Set dates %1$s as %2$s unavailable.', 'booking' ) | |
| 589 | 672 | , '_DATES_' |
| 590 | 673 | , '_HTML_' |
| 591 | 674 | ); |
| 592 | 675 | |
| @@ -604,11 +687,8 @@ | ||
| 604 | 687 | // Do not safe such elements |
| 605 | 688 | unset( $request_params_to_save['ui_clicked_element_id'] ); |
| 606 | 689 | unset( $request_params_to_save['do_action'] ); |
| 607 | 690 | unset( $request_params_to_save['dates_selection'] ); |
| 608 | - // Do not save "Do not change background color for partially booked days" option ! it must reflect from Booking > Settings General page and not from User options | |
| 609 | - unset( $request_params_to_save['calendar__timeslot_day_bg_as_available'] ); //FixIn: 9.5.5.4 | |
| 610 | - | |
| 611 | 691 | $is_success_update = $user_request->user_request_params__db_save( $request_params_to_save ); // Save to DB // - $request_params - serialized here automatically |
| 612 | 692 | } |
| 613 | 693 | |
| 614 | 694 | //---------------------------------------------------------------------------------------------------------- |
| @@ -614,8 +694,9 @@ | ||
| 614 | 694 | //---------------------------------------------------------------------------------------------------------- |
| 615 | 695 | // 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. |
| 616 | 696 | wp_send_json( array( |
| 617 | 697 | 'ajx_data' => $data_arr, |
| 698 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 618 | 699 | 'ajx_search_params' => $_REQUEST[ $request_prefix ], // $_REQUEST[ 'search_params' ] |
| 619 | 700 | 'ajx_cleaned_params' => $request_params |
| 620 | 701 | ) ); |
| 621 | 702 | } |
| @@ -627,8 +708,8 @@ | ||
| 627 | 708 | /** |
| 628 | 709 | * Just for loading CSS and JavaScript files |
| 629 | 710 | */ |
| 630 | 711 | if ( true ) { |
| 631 | - $ajx_availability_loading = new WPBC_AJX__Availability; | |
| 632 | - $ajx_availability_loading->init_load_css_js_tpl(); | |
| 633 | - $ajx_availability_loading->define_ajax_hook(); | |
| 634 | -} | |
| 712 | + $wpbc_ajx_availability_loading = new WPBC_AJX__Availability; | |
| 713 | + $wpbc_ajx_availability_loading->init_load_css_js_tpl(); | |
| 714 | + $wpbc_ajx_availability_loading->define_ajax_hook(); | |
| 715 | +} | |