PluginProbe
Booking Calendar / 11.7
Booking Calendar v11.7
11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 10.11.2 10.11.3 10.11.4 All 201 releases
booking / includes / page-availability / availability__class.php

availability__class.php in Booking Calendar 11.7, at includes/page-availability/availability__class.php

716 lines 31.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php /**
2 * @version 1.0
3 * @description WPBC_AJX__Availability
4 * @category WPBC_AJX__Availability Class
5 * @author wpdevelop
6 *
7 * @web-site http://oplugins.com/
8 * @email info@oplugins.com
9 *
10 * @modified 2022-10-24
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
14
15
16 class WPBC_AJX__Availability {
17
18 // <editor-fold defaultstate="collapsed" desc=" /// JS | CSS files | Tpl loading /// " >
19
20 /**
21 * Define HOOKs for loading CSS and JavaScript files
22 */
23 public function init_load_css_js_tpl() {
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 */
26 // Load only at specific Page
27 if ( strpos( $server_request_uri, 'page=wpbc-availability' ) !== false ) {
28
29 add_action( 'wpbc_enqueue_js_files', array( $this, 'js_load_files' ), 50 );
30 add_action( 'wpbc_enqueue_css_files', array( $this, 'enqueue_css_files' ), 50 );
31
32 add_action( 'wpbc_hook_settings_page_footer', array( $this, 'hook__page_footer_tmpl' ) );
33 }
34 }
35
36
37 /** JS */
38 public function js_load_files( $where_to_load ) {
39
40 $in_footer = true;
41
42 if ( wpbc_is_availability_page() )
43 if ( ( is_admin() ) && ( in_array( $where_to_load, array( 'admin', 'both' ) ) ) ) {
44
45 wp_enqueue_script( 'wpbc-ajx_availability_page'
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
48
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 ) );
52 /**
53 *
54 * wp_localize_script( 'wpbc_all', 'wpbc_live_request_obj'
55 * , array(
56 * 'ajx_booking' => '',
57 * 'reminders' => ''
58 * )
59 * );
60 */
61 }
62 }
63
64
65 /** CSS */
66 public function enqueue_css_files( $where_to_load ) {
67
68 if ( ( is_admin() ) && ( in_array( $where_to_load, array( 'admin', 'both' ) ) ) ) {
69
70 wp_enqueue_style( 'wpbc-ajx_availability_page'
71 , trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/availability_page.css' //, wpbc_plugin_url( '/includes/listing_ajx_booking/o-ajx_booking-listing.css' )
72 , array(), WP_BK_VERSION_NUM );
73 }
74 }
75
76 // </editor-fold>
77
78
79 // <editor-fold defaultstate="collapsed" desc=" /// R e q u e s t /// " >
80
81 /**
82 * Get params names for escaping and/or default value of such params
83 *
84 * @return array array ( 'resource_id' => array( 'validate' => 'digit_or_csd', 'default' => array( '1' ) )
85 * , ... )
86 */
87 static public function request_rules_structure(){
88
89 $default_resource_id = wpbc_get_default_resource();
90
91 return array(
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.
93
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
95 , 'dates_selection' => array( 'validate' => 's', 'default' => '' )
96 , 'dates_availability' => array( 'validate' => array( 'unavailable', 'available' ), 'default' => 'unavailable' )
97
98 , 'ui_clicked_element_id' => array( 'validate' => 's', 'default' => '' )
99 , 'ui_usr__availability_selected_toolbar' => array( 'validate' => array( 'info', 'calendar_settings' ), 'default' => 'info' )
100
101 // Calendar settings
102 , 'calendar__start_week_day' => array( 'validate' => array( '0','1','2','3','4','5','6' ), 'default' => intval(get_bk_option( 'booking_start_day_weeek' )) )
103 , 'calendar__days_selection_mode' => array( 'validate' => array( 'multiple', 'dynamic' ), 'default' => 'dynamic' )
104 , 'calendar__view__visible_months' => array( 'validate' => 'd', 'default' => 12 )
105 , 'calendar__view__months_in_row' => array( 'validate' => 'd', 'default' => 3 ) // FixIn: 10.8.1.5.
106 , 'calendar__view__width' => array( 'validate' => 's', 'default' => '100%' )
107 , 'calendar__view__max_width' => array( 'validate' => 's', 'default' => '' ) // default '' it's will be set as 341px,
108 , 'calendar__view__cell_height' => array( 'validate' => 's', 'default' => '38px' ) // '48px' || ''
109
110 // , 'calendar__view__visible_months' => array( 'validate' => 'd', 'default' => 1 )
111 // , 'calendar__view__months_in_row' => array( 'validate' => 'd', 'default' => 1 )
112 // , 'calendar__view__width' => array( 'validate' => 's', 'default' => '300px' )
113 // , 'calendar__view__max_width' => array( 'validate' => 's', 'default' => '300px' ) // default '' it's will be set as 341px,
114 // , 'calendar__view__cell_height' => array( 'validate' => 's', 'default' => '48px' ) // '45px' || ''
115
116 );
117
118 }
119
120
121 /**
122 * Get default params
123 *
124 * @return array array ( 'ui_wh_modification_date_radio' => 0
125 * , ... )
126 */
127 static public function get__request_values__default() {
128
129 $request_rules_structure = self::request_rules_structure();
130
131 $default_params_arr = array();
132
133 $structure_type = 'default';
134
135 foreach ( $request_rules_structure as $key => $value ) {
136 $default_params_arr[ $key ] = $value[ $structure_type ];
137 }
138
139 return $default_params_arr;
140 }
141
142 // </editor-fold>
143
144
145
146 // <editor-fold defaultstate="collapsed" desc=" /// Templates /// " >
147
148 // Templates ===================================================================================================
149
150 /**
151 * Templates at footer of page
152 *
153 * @param $page string
154 */
155 public function hook__page_footer_tmpl( $page ){
156
157 // page=wpbc&tab=vm_booking_listing
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
159 $this->template__main_page_content();
160
161 $this->template_toolbar_select_booking_resource();
162 $this->template_toolbar_select_month_number_in_row(); // FixIn: 10.8.1.5.
163 $this->template__widget_available_unavailable();
164 $this->template__widget_calendar_legend();
165 }
166 }
167
168
169 /**
170 * Template
171 *
172 * Help Tips:
173 *
174 * <script type="text/html" id="tmpl-template_name_a">
175 * Escaped: {{data.test_key}}
176 * HTML: {{{data.test_key}}}
177 * JS: <# if (true) { alert( 1 ); } #>
178 * </script>
179 *
180 * var template__var = wp.template( 'template_name_a' );
181 *
182 * jQuery( '.content' ).html( template__var( { 'test_key' => '<strong>Data</strong>' } ) );
183 *
184 * @return void
185 */
186 private function template__main_page_content() {
187 ?><script type="text/html" id="tmpl-wpbc_ajx_availability_main_page_content">
188 <div class="wpbc_ajx_avy__container">
189 <div class="wpbc_ajx_avy__section_left">
190 <?php
191 $is_booking_change_over_days_triangles = get_bk_option( 'booking_change_over_days_triangles' );
192 $is_booking_change_over_days_triangles = ( $is_booking_change_over_days_triangles !== 'Off' ) ? "wpbc_change_over_triangle" : '';
193 ?>
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>
195 </div>
196 <div class="wpbc_ajx_avy__section_right">
197 <div class="wpbc_widgets">
198 <# <?php if (0) { ?><script type="text/javascript"><?php } ?>
199
200 var wpbc_ajx_select_booking_resource = wp.template( 'wpbc_ajx_select_booking_resource' );
201 jQuery( '#wpbc_hidden_template__select_booking_resource').html( wpbc_ajx_select_booking_resource( data ) );
202
203 var wpbc_widget__available_unavailable = wp.template( 'wpbc_ajx_widget_available_unavailable' );
204 var wpbc_widget__calendar_legend = wp.template( 'wpbc_ajx_widget_calendar_legend' );
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
210 <?php if (0) { ?></script><?php } ?>
211 #>
212
213 {{{ wpbc_widget__available_unavailable( data.ajx_cleaned_params ) }}}
214 {{{ wpbc_widget__calendar_legend( { } ) }}}
215
216 </div>
217 </div>
218 </div>
219 </script><?php
220 }
221
222
223 private function template__widget_available_unavailable(){
224
225 ?><script type="text/html" id="tmpl-wpbc_ajx_widget_available_unavailable">
226 <div class="wpbc_widget wpbc_widget_available_unavailable">
227 <div class="wpbc_widget_header">
228 <span class="wpbc_widget_header_text"><?php esc_html_e('Apply availability', 'booking'); ?></span>
229 <a href="/" class="wpbc_widget_header_settings_link"><i class="menu_icon icon-1x wpbc_icn_settings"></i></a>
230 </div>
231 <div class="wpbc_widget_content wpbc_ajx_toolbar" style="margin:0 0 20px;">
232 <div class="ui_container" >
233 <div class="ui_group ui_group__available_unavailable"><?php
234
235 // Available Radio
236 ?><div class="ui_element ui_nowrap"><?php
237 wpbc_ajx_avy__ui__available_radio();
238 ?></div><?php
239
240
241 // Unavailable Radio
242 ?><div class="ui_element ui_nowrap"><?php
243 wpbc_ajx_avy__ui__unavailable_radio();
244 ?></div><?php
245
246 // Set checked specific Radio button, depends on last action from user
247 ?><# <?php if (0) { ?><script type="text/javascript"><?php } ?>
248
249 jQuery( document ).ready( function (){
250
251 //Helper, if we click on button side, and not at radio button or label, then make radio checked.
252 jQuery( '.ui_btn_avy__set_days_availability__available__outer_button' ).on( 'click', function (){
253 jQuery( '#ui_btn_avy__set_days_availability__available' ).prop( "checked", true ).trigger( 'change' );
254 } );
255 jQuery( '.ui_btn_avy__set_days_availability__unavailable__outer_button' ).on( 'click', function (){
256 jQuery( '#ui_btn_avy__set_days_availability__unavailable' ).prop( "checked", true ).trigger( 'change' );
257 } );
258
259 // Set checked or not, specific radio buttons
260 if ( 'unavailable' == data.dates_availability ){
261 jQuery( '#ui_btn_avy__set_days_availability__unavailable' ).prop( 'checked', true );//.trigger( 'change' );
262 }
263 if ( 'available' == data.dates_availability ){
264 jQuery( '#ui_btn_avy__set_days_availability__available' ).prop( 'checked', true );//.trigger( 'change' );
265 }
266 } );
267
268 <?php if (0) { ?></script><?php } ?> #><?php
269
270
271 // Apply Button
272 ?><div class="ui_element"><?php
273 wpbc_ajx_avy__ui__availability_apply_btn();
274 ?></div>
275
276 </div>
277 </div>
278 </div>
279 </div>
280 </script><?php
281 }
282
283
284 private function template__widget_calendar_legend(){
285
286 ?><script type="text/html" id="tmpl-wpbc_ajx_widget_calendar_legend">
287 <div class="wpbc_widget wpbc_widget_calendar_legend">
288 <div class="wpbc_widget_header">
289 <span class="wpbc_widget_header_text"><?php esc_html_e('Calendar Legend', 'booking'); ?></span>
290 <a href="/" class="wpbc_widget_header_settings_link"><i class="menu_icon icon-1x wpbc_icn_settings"></i></a>
291 </div>
292 <div class="wpbc_widget_content wpbc_ajx_toolbar" style="margin:0 0 20px;">
293 <div class="ui_container" >
294 <div class="ui_group ui_group__available_unavailable"><?php
295
296 ?><div class="ui_element ui_nowrap"><?php
297
298 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
299 echo wpbc_replace_shortcodes_in_booking_form__legend_items(
300 '[legend_items'
301 . ' items="resource_unavailable"'
302 . ' titles="resource_unavailable={'
303 . htmlspecialchars( __( "Resource unavailable days", 'booking' ), ENT_QUOTES)
304 . '}"'
305 . ' text_for_day_cell="' . gmdate( 'd' ) . '"'
306 . ' unavailable_day_cell_tag="a"'
307 .']'
308 );
309 ?></div><?php
310
311 ?><div style="border-top:1px solid #d3d3d3;width:100%;margin: 10px 0 -5px;"></div><?php
312
313 ?><div class="ui_element ui_nowrap"><?php
314 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
315 echo wpbc_replace_shortcodes_in_booking_form__legend_items(
316 '[legend_items'
317 . ' items="unavailable,available,pending,approved,partially"'
318 . ' titles="'
319 //.' unavailable={' . htmlspecialchars( __( "Unavailable", 'booking' ), ENT_QUOTES ) . '}'
320 //.' pending={' . htmlspecialchars( __( "Pending", 'booking' ), ENT_QUOTES ) . '}'
321 .'"'
322 . ' text_for_day_cell="' . gmdate( 'd' ) . '"'
323 . ' unavailable_day_cell_tag="span"'
324 .']'
325 );
326
327 ?></div><?php
328
329 ?>
330 </div>
331 </div>
332 </div>
333 </div>
334 <style type="text/css">
335 .wpbc_ajx_toolbar .ui_container .ui_group .ui_element > .block_hints.datepick {
336 height: auto;
337 margin: 8px 0 0 !important;
338 }
339 </style>
340 </script><?php
341 }
342
343
344 private function template_toolbar_select_booking_resource(){
345
346 // Template
347 ?><script type="text/html" id="tmpl-wpbc_ajx_select_booking_resource"><?php
348
349 if ( ! class_exists('wpdev_bk_personal') ) {
350 echo '</script>';
351 return false;
352 }
353
354 $booking_action = 'select_booking_resource';
355
356 $el_id = 'ui_btn_' . $booking_action;
357
358 if ( ! wpbc_is_user_can( $booking_action, wpbc_get_current_user_id() ) ) {
359 echo '</script>';
360 return false;
361 }
362
363
364 ?><div class="ui_element"><?php
365
366 wpbc_flex_label(
367 array(
368 'id' => $el_id
369 , 'label' => '<span class="" style="font-weight:600;">' . esc_html__( 'Booking resource', 'booking' ) . ':</span>'
370 )
371 );
372
373 ?><select class="wpbc_ui_control wpbc_ui_select change_booking_resource_selectbox"
374 id="<?php echo esc_attr( $el_id ); ?>" name="<?php echo esc_attr( $el_id ); ?>"
375
376 <?php /* ?>onfocus="javascript:console.log( 'ON FOCUS:', jQuery( this ).val(), 'in element:' , jQuery( this ) );"<?php /**/ ?>
377
378 onchange="javascript:wpbc_admin_show_message_processing( '' );wpbc_ajx_availability__send_request_with_params( {
379 'resource_id': jQuery( this ).val()
380 , 'dates_availability': jQuery( '.wpbc_radio__set_days_availability:checked' ).val()
381 , 'dates_selection': ''
382 , 'do_action': 'change_booking_resource'
383 } );"
384 ><#
385 _.each( data.ajx_data.ajx_booking_resources, function ( p_resource, p_resource_id, p_data ){
386 #><option value="{{p_resource.booking_type_id}}"
387 <#
388 if ( data.ajx_cleaned_params.resource_id == p_resource.booking_type_id ) {
389 #> selected="SELECTED" <#
390 }
391 #>
392 style="<#
393 if( undefined != p_resource.parent ) {
394 if( '0' == p_resource.parent ) {
395 #>font-weight:600;<#
396 } else {
397 #>font-size:0.95em;padding-left:20px;<#
398 }
399 }
400 #>"
401 ><#
402 if( undefined != p_resource.parent ) {
403 if( '0' != p_resource.parent ) {
404 #>&nbsp;&nbsp;&nbsp;<#
405 }
406 }
407 #>{{p_resource.title}}</option><#
408 });
409 #>
410 </select><?php
411
412 ?></div>
413
414 <div class="ui_element"><?php
415
416 ?><div class="wpbc_ui_separtor" style="margin-left: 8px;"></div><?php
417
418 ?></div><?php
419
420 ?></script><?php
421 }
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
477 // </editor-fold>
478
479
480
481 // <editor-fold defaultstate="collapsed" desc=" /// A J A X /// " >
482
483 // A J A X =====================================================================================================
484
485 /**
486 * Define HOOKs for start loading Ajax
487 */
488 public function define_ajax_hook(){
489
490 // Ajax Handlers. Note. "locale_for_ajax" rechecked in wpbc-ajax.php
491 add_action( 'wp_ajax_' . 'WPBC_AJX_AVAILABILITY', array( $this, 'ajax_' . 'WPBC_AJX_AVAILABILITY' ) ); // Admin & Client (logged in usres)
492
493 // Ajax Handlers for actions
494 //add_action( 'wp_ajax_' . 'WPBC_AJX_BOOKING_ACTIONS', 'wpbc_ajax_' . 'WPBC_AJX_BOOKING_ACTIONS' );
495
496 // add_action( 'wp_ajax_nopriv_' . 'WPBC_AJX_BOOKING_LISTING', array( $this, 'ajax_' . 'WPBC_AJX_BOOKING_LISTING' ) ); // Client (not logged in)
497 }
498
499
500
501 /**
502 * Ajax - Get Listing Data and Response to JS script
503 */
504 public function ajax_WPBC_AJX_AVAILABILITY() {
505
506 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
507 if ( ! isset( $_POST['search_params'] ) || empty( $_POST['search_params'] ) ) { exit; }
508
509 // Security ----------------------------------------------------------------------------------------------- // in Ajax Post: 'nonce': wpbc_ajx_booking_listing.get_secure_param( 'nonce' ),
510 $action_name = 'wpbc_ajx_availability_ajx' . '_wpbcnonce';
511 $nonce_post_key = 'nonce';
512 $result_check = check_ajax_referer( $action_name, $nonce_post_key );
513
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
515
516 /**
517 * SQL ---------------------------------------------------------------------------
518 *
519 * in Ajax Post: 'search_params': wpbc_ajx_booking_listing.search_get_all_params()
520 *
521 * Use prefix "search_params", if Ajax sent -
522 * $_REQUEST['search_params']['page_num'], $_REQUEST['search_params']['page_items_count'],..
523 */
524
525 $user_request = new WPBC_AJX__REQUEST( array(
526 'db_option_name' => 'booking_availability_request_params',
527 'user_id' => $user_id,
528 'request_rules_structure' => WPBC_AJX__Availability::request_rules_structure()
529 )
530 );
531 $request_prefix = 'search_params';
532 $request_params = $user_request->get_sanitized__in_request__value_or_default( $request_prefix ); // NOT Direct: $_REQUEST['search_params']['resource_id']
533
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 ), ... */
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
567 $data_arr = array();
568 $data_arr['ajx_after_action_message'] = '';
569 $data_arr['ajx_after_action_result'] = 1;
570
571 if ( 'set_availability' == $request_params['do_action'] ) {
572
573 // Dates -- update status in DB
574 $row_number = wpbc_availability__update_dates_status__sql( array(
575 'resource_id' => $request_params['resource_id'], // int
576 'prop_name' => 'date_status', // 'rate', 'allow_start_day_selection', 'allow_days_number_to_select', 'availability_count', ...
577 'prop_value' => $request_params['dates_availability'], // 'available', 'unavailable' , 'pending', 'approved'
578 'dates_selection' => $request_params['dates_selection'] // '2023-04-04 | 2023-04-07'
579 ) );
580
581 if ( false !== $row_number ) {
582 if ( 'available' == $request_params['dates_availability'] ) {
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' )
585 , '<strong>' . $row_number . '</strong>'
586 , '<strong style="color:#11be4c;">', '</strong>' );
587 } else {
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' )
590 , '<strong>' . $row_number . '</strong>'
591 , '<strong style="color:#e43939;">', '</strong>' );
592 }
593 $data_arr['ajx_after_action_result'] = ( $row_number > 0 ) ? 1 : 0;
594 }
595 }
596
597 if ( 'erase_availability' == $request_params['do_action'] ) {
598 //TODO: Make new fucntion here to delete all items from DB relative to this booking resource 2023-02-06 14:42
599 // Dates -- update status in DB
600 $row_number = wpbc_availability__delete_dates_status__sql( array(
601 'resource_id' => $request_params['resource_id'], // int
602 'prop_name' => 'date_status', // 'rate', 'allow_start_day_selection', 'allow_days_number_to_select', 'availability_count', ...
603 //'prop_value' => $request_params['dates_availability'], // 'available', 'unavailable' , 'pending', 'approved'
604 'dates_selection' => 'all' // '2023-04-04 | 2023-04-07'
605 ) );
606 $data_arr['ajx_after_action_message'] = ( $row_number > 0 )
607 /* translators: 1: ... */
608 ? sprintf( __( 'All %s unavailable dates has been removed', 'booking' ), '<strong>' . $row_number . '</strong>' )
609 : sprintf( __( 'No unavailable dates.', 'booking' ), $row_number );
610 $data_arr['ajx_after_action_result'] = ( $row_number > 0 ) ? 1 : 0;
611
612 }
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 }
621
622 $data_arr['booked_dates'] = wpbc__sql__get_booked_dates( array(
623 'resource_id' => $request_params['resource_id']
624 ) );
625
626 $data_arr['season_availability'] = wpbc__sql__get_season_availability( array(
627 'resource_id' => $request_params['resource_id']
628 ) );
629
630 $data_arr['resource_unavailable_dates'] = wpbc_resource__get_unavailable_dates($request_params['resource_id']);
631
632
633 //----------------------------------------------------------------------------------------------------------
634
635
636 $data_arr['ajx_booking_resources'] = $resources_arr_sorted;
637
638 //----------------------------------------------------------------------------------------------------------
639
640 $data_arr['ajx_nonce_calendar'] = wp_nonce_field( 'CALCULATE_THE_COST', 'wpbc_nonce' . 'CALCULATE_THE_COST' . $request_params['resource_id'], true, false );
641
642 $data_arr['popover_hints'] = array();
643
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 Season Availability page.', 'booking' ), '<br>', '&gt;', '&gt;' );
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>', '&gt;', '<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>', '&gt;', '<br>' );
653
654
655
656 $data_arr['popover_hints']['toolbar_text'] = '<span style="font-size: 1.05em;line-height: 1.8em;">'.
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' )
659 , '<strong>', '&nbsp;</strong>'
660 , '<strong>&nbsp;', '&nbsp;</strong>'
661 , '<strong>&nbsp;', '&nbsp;</strong>'
662 , '<strong>&nbsp;', '&nbsp;</strong>'
663 )
664 .'</span>';
665 /* translators: 1: ... */
666 $data_arr['popover_hints']['toolbar_text_available'] = sprintf( __( 'Set dates %1$s as %2$s available.', 'booking' )
667 , '_DATES_'
668 , '_HTML_'
669 );
670 /* translators: 1: ... */
671 $data_arr['popover_hints']['toolbar_text_unavailable'] = sprintf( __( 'Set dates %1$s as %2$s unavailable.', 'booking' )
672 , '_DATES_'
673 , '_HTML_'
674 );
675
676 // Clear here DATES selection in $request_params['dates_selection'] to not save such selection
677
678 if ( 'make_reset' === $request_params['do_action'] ) {
679
680 $is_reseted = $user_request->user_request_params__db_delete(); // Delete from DB
681
682 $request_params['do_action'] = $is_reseted ? 'reset_done' : 'reset_error';
683 } else {
684
685 $request_params_to_save = $request_params;
686
687 // Do not safe such elements
688 unset( $request_params_to_save['ui_clicked_element_id'] );
689 unset( $request_params_to_save['do_action'] );
690 unset( $request_params_to_save['dates_selection'] );
691 $is_success_update = $user_request->user_request_params__db_save( $request_params_to_save ); // Save to DB // - $request_params - serialized here automatically
692 }
693
694 //----------------------------------------------------------------------------------------------------------
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.
696 wp_send_json( array(
697 'ajx_data' => $data_arr,
698 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
699 'ajx_search_params' => $_REQUEST[ $request_prefix ], // $_REQUEST[ 'search_params' ]
700 'ajx_cleaned_params' => $request_params
701 ) );
702 }
703
704 // </editor-fold>
705
706 }
707
708 /**
709 * Just for loading CSS and JavaScript files
710 */
711 if ( true ) {
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 }
716