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

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

727 lines 31.8 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-general_ui_js_css'
50 , wpbc_plugin_url( '/includes/_general_ui_js_css/_out/wpbc_main_ui_funcs.js' )
51 , array( 'wpbc_all' ), WP_BK_VERSION_NUM, $in_footer ); //FixIn: 9.8.1
52
53 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.
54 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 ) );
55 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 ) );
56 /**
57 *
58 * wp_localize_script( 'wpbc_all', 'wpbc_live_request_obj'
59 * , array(
60 * 'ajx_booking' => '',
61 * 'reminders' => ''
62 * )
63 * );
64 */
65 }
66 }
67
68
69 /** CSS */
70 public function enqueue_css_files( $where_to_load ) {
71
72 if ( ( is_admin() ) && ( in_array( $where_to_load, array( 'admin', 'both' ) ) ) ) {
73
74 wp_enqueue_style( 'wpbc-ajx_availability_page'
75 , trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/availability_page.css' //, wpbc_plugin_url( '/includes/listing_ajx_booking/o-ajx_booking-listing.css' )
76 , array(), WP_BK_VERSION_NUM );
77 }
78 }
79
80 // </editor-fold>
81
82
83 // <editor-fold defaultstate="collapsed" desc=" /// R e q u e s t /// " >
84
85 /**
86 * Get params names for escaping and/or default value of such params
87 *
88 * @return array array ( 'resource_id' => array( 'validate' => 'digit_or_csd', 'default' => array( '1' ) )
89 * , ... )
90 */
91 static public function request_rules_structure(){
92
93 $default_resource_id = wpbc_get_default_resource();
94
95 return array(
96 'do_action' => array( 'validate' => array( 'none', 'set_availability', 'make_reset', 'erase_availability', 'change_month_number_in_row' ), 'default' => 'none' ) // FixIn: 10.8.1.5.
97
98 , '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
99 , 'dates_selection' => array( 'validate' => 's', 'default' => '' )
100 , 'dates_availability' => array( 'validate' => array( 'unavailable', 'available' ), 'default' => 'unavailable' )
101
102 , 'ui_clicked_element_id' => array( 'validate' => 's', 'default' => '' )
103 , 'ui_usr__availability_selected_toolbar' => array( 'validate' => array( 'info', 'calendar_settings' ), 'default' => 'info' )
104
105 // Calendar settings
106 , 'calendar__start_week_day' => array( 'validate' => array( '0','1','2','3','4','5','6' ), 'default' => intval(get_bk_option( 'booking_start_day_weeek' )) )
107 , 'calendar__days_selection_mode' => array( 'validate' => array( 'multiple', 'dynamic' ), 'default' => 'dynamic' )
108 , 'calendar__view__visible_months' => array( 'validate' => 'd', 'default' => 12 )
109 , 'calendar__view__months_in_row' => array( 'validate' => 'd', 'default' => 3 ) // FixIn: 10.8.1.5.
110 , 'calendar__view__width' => array( 'validate' => 's', 'default' => '100%' )
111 , 'calendar__view__max_width' => array( 'validate' => 's', 'default' => '' ) // default '' it's will be set as 341px,
112 , 'calendar__view__cell_height' => array( 'validate' => 's', 'default' => '38px' ) // '48px' || ''
113
114 // , 'calendar__view__visible_months' => array( 'validate' => 'd', 'default' => 1 )
115 // , 'calendar__view__months_in_row' => array( 'validate' => 'd', 'default' => 1 )
116 // , 'calendar__view__width' => array( 'validate' => 's', 'default' => '300px' )
117 // , 'calendar__view__max_width' => array( 'validate' => 's', 'default' => '300px' ) // default '' it's will be set as 341px,
118 // , 'calendar__view__cell_height' => array( 'validate' => 's', 'default' => '48px' ) // '45px' || ''
119
120 , 'calendar__timeslot_day_bg_as_available' => array( 'validate' => 's'
121 , 'default' => ('On' === get_bk_option( 'booking_timeslot_day_bg_as_available' ) ) ? ' wpbc_timeslot_day_bg_as_available' : '' )
122
123 );
124
125 }
126
127
128 /**
129 * Get default params
130 *
131 * @return array array ( 'ui_wh_modification_date_radio' => 0
132 * , ... )
133 */
134 static public function get__request_values__default() {
135
136 $request_rules_structure = self::request_rules_structure();
137
138 $default_params_arr = array();
139
140 $structure_type = 'default';
141
142 foreach ( $request_rules_structure as $key => $value ) {
143 $default_params_arr[ $key ] = $value[ $structure_type ];
144 }
145
146 return $default_params_arr;
147 }
148
149 // </editor-fold>
150
151
152
153 // <editor-fold defaultstate="collapsed" desc=" /// Templates /// " >
154
155 // Templates ===================================================================================================
156
157 /**
158 * Templates at footer of page
159 *
160 * @param $page string
161 */
162 public function hook__page_footer_tmpl( $page ){
163
164 // page=wpbc&view_mode=vm_booking_listing
165 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
166 $this->template__main_page_content();
167
168 $this->template_toolbar_select_booking_resource();
169 $this->template_toolbar_select_month_number_in_row(); // FixIn: 10.8.1.5.
170 $this->template__widget_available_unavailable();
171 $this->template__widget_calendar_legend();
172 }
173 }
174
175
176 /**
177 * Template
178 *
179 * Help Tips:
180 *
181 * <script type="text/html" id="tmpl-template_name_a">
182 * Escaped: {{data.test_key}}
183 * HTML: {{{data.test_key}}}
184 * JS: <# if (true) { alert( 1 ); } #>
185 * </script>
186 *
187 * var template__var = wp.template( 'template_name_a' );
188 *
189 * jQuery( '.content' ).html( template__var( { 'test_key' => '<strong>Data</strong>' } ) );
190 *
191 * @return void
192 */
193 private function template__main_page_content() {
194 ?><script type="text/html" id="tmpl-wpbc_ajx_availability_main_page_content">
195 <div class="wpbc_ajx_avy__container">
196 <div class="wpbc_ajx_avy__section_left">
197 <?php
198 $is_booking_change_over_days_triangles = get_bk_option( 'booking_change_over_days_triangles' );
199 $is_booking_change_over_days_triangles = ( $is_booking_change_over_days_triangles !== 'Off' ) ? "wpbc_change_over_triangle" : '';
200 ?>
201 <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>
202 </div>
203 <div class="wpbc_ajx_avy__section_right">
204 <div class="wpbc_widgets">
205 <# <?php if (0) { ?><script type="text/javascript"><?php } ?>
206
207 var wpbc_ajx_select_booking_resource = wp.template( 'wpbc_ajx_select_booking_resource' );
208 jQuery( '#wpbc_hidden_template__select_booking_resource').html( wpbc_ajx_select_booking_resource( data ) );
209
210 var wpbc_widget__available_unavailable = wp.template( 'wpbc_ajx_widget_available_unavailable' );
211 var wpbc_widget__calendar_legend = wp.template( 'wpbc_ajx_widget_calendar_legend' );
212
213 // FixIn: 10.8.1.5.
214 var wpbc_ajx_select_month_number_in_row = wp.template( 'wpbc_ajx_select_month_number_in_row' );
215 jQuery( '#wpbc_template__select_month_number_in_row').html( wpbc_ajx_select_month_number_in_row( data ) );
216
217 <?php if (0) { ?></script><?php } ?>
218 #>
219
220 {{{ wpbc_widget__available_unavailable( data.ajx_cleaned_params ) }}}
221 {{{ wpbc_widget__calendar_legend( { } ) }}}
222
223 </div>
224 </div>
225 </div>
226 </script><?php
227 }
228
229
230 private function template__widget_available_unavailable(){
231
232 ?><script type="text/html" id="tmpl-wpbc_ajx_widget_available_unavailable">
233 <div class="wpbc_widget wpbc_widget_available_unavailable">
234 <div class="wpbc_widget_header">
235 <span class="wpbc_widget_header_text"><?php esc_html_e('Apply availability', 'booking'); ?></span>
236 <a href="/" class="wpbc_widget_header_settings_link"><i class="menu_icon icon-1x wpbc_icn_settings"></i></a>
237 </div>
238 <div class="wpbc_widget_content wpbc_ajx_toolbar" style="margin:0 0 20px;">
239 <div class="ui_container" >
240 <div class="ui_group ui_group__available_unavailable"><?php
241
242 // Available Radio
243 ?><div class="ui_element ui_nowrap"><?php
244 wpbc_ajx_avy__ui__available_radio();
245 ?></div><?php
246
247
248 // Unavailable Radio
249 ?><div class="ui_element ui_nowrap"><?php
250 wpbc_ajx_avy__ui__unavailable_radio();
251 ?></div><?php
252
253 // Set checked specific Radio button, depends on last action from user
254 ?><# <?php if (0) { ?><script type="text/javascript"><?php } ?>
255
256 jQuery( document ).ready( function (){
257
258 //Helper, if we click on button side, and not at radio button or label, then make radio checked.
259 jQuery( '.ui_btn_avy__set_days_availability__available__outer_button' ).on( 'click', function (){
260 jQuery( '#ui_btn_avy__set_days_availability__available' ).prop( "checked", true ).trigger( 'change' );
261 } );
262 jQuery( '.ui_btn_avy__set_days_availability__unavailable__outer_button' ).on( 'click', function (){
263 jQuery( '#ui_btn_avy__set_days_availability__unavailable' ).prop( "checked", true ).trigger( 'change' );
264 } );
265
266 // Set checked or not, specific radio buttons
267 if ( 'unavailable' == data.dates_availability ){
268 jQuery( '#ui_btn_avy__set_days_availability__unavailable' ).prop( 'checked', true );//.trigger( 'change' );
269 }
270 if ( 'available' == data.dates_availability ){
271 jQuery( '#ui_btn_avy__set_days_availability__available' ).prop( 'checked', true );//.trigger( 'change' );
272 }
273 } );
274
275 <?php if (0) { ?></script><?php } ?> #><?php
276
277
278 // Apply Button
279 ?><div class="ui_element"><?php
280 wpbc_ajx_avy__ui__availability_apply_btn();
281 ?></div>
282
283 </div>
284 </div>
285 </div>
286 </div>
287 </script><?php
288 }
289
290
291 private function template__widget_calendar_legend(){
292
293 ?><script type="text/html" id="tmpl-wpbc_ajx_widget_calendar_legend">
294 <div class="wpbc_widget wpbc_widget_calendar_legend">
295 <div class="wpbc_widget_header">
296 <span class="wpbc_widget_header_text"><?php esc_html_e('Calendar Legend', 'booking'); ?></span>
297 <a href="/" class="wpbc_widget_header_settings_link"><i class="menu_icon icon-1x wpbc_icn_settings"></i></a>
298 </div>
299 <div class="wpbc_widget_content wpbc_ajx_toolbar" style="margin:0 0 20px;">
300 <div class="ui_container" >
301 <div class="ui_group ui_group__available_unavailable"><?php
302
303 ?><div class="ui_element ui_nowrap"><?php
304
305 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
306 echo wpbc_replace_shortcodes_in_booking_form__legend_items(
307 '[legend_items'
308 . ' items="resource_unavailable"'
309 . ' titles="resource_unavailable={'
310 . htmlspecialchars( __( "Resource unavailable days", 'booking' ), ENT_QUOTES)
311 . '}"'
312 . ' text_for_day_cell="' . gmdate( 'd' ) . '"'
313 . ' unavailable_day_cell_tag="a"'
314 .']'
315 );
316 ?></div><?php
317
318 ?><div style="border-top:1px solid #d3d3d3;width:100%;margin: 10px 0 -5px;"></div><?php
319
320 ?><div class="ui_element ui_nowrap"><?php
321 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
322 echo wpbc_replace_shortcodes_in_booking_form__legend_items(
323 '[legend_items'
324 . ' items="unavailable,available,pending,approved,partially"'
325 . ' titles="'
326 //.' unavailable={' . htmlspecialchars( __( "Unavailable", 'booking' ), ENT_QUOTES ) . '}'
327 //.' pending={' . htmlspecialchars( __( "Pending", 'booking' ), ENT_QUOTES ) . '}'
328 .'"'
329 . ' text_for_day_cell="' . gmdate( 'd' ) . '"'
330 . ' unavailable_day_cell_tag="span"'
331 .']'
332 );
333
334 ?></div><?php
335
336 ?>
337 </div>
338 </div>
339 </div>
340 </div>
341 <style type="text/css">
342 .wpbc_ajx_toolbar .ui_container .ui_group .ui_element > .block_hints.datepick {
343 height: auto;
344 margin: 8px 0 0 !important;
345 }
346 </style>
347 </script><?php
348 }
349
350
351 private function template_toolbar_select_booking_resource(){
352
353 // Template
354 ?><script type="text/html" id="tmpl-wpbc_ajx_select_booking_resource"><?php
355
356 if ( ! class_exists('wpdev_bk_personal') ) {
357 echo '</script>';
358 return false;
359 }
360 /*
361 ?><# console.log( ' == TEMPLATE PARAMS "wpbc_ajx_change_booking_resource" == ', data ); #><?php
362 */
363 $booking_action = 'select_booking_resource';
364
365 $el_id = 'ui_btn_' . $booking_action;
366
367 if ( ! wpbc_is_user_can( $booking_action, wpbc_get_current_user_id() ) ) {
368 echo '</script>';
369 return false;
370 }
371
372
373 ?><div class="ui_element"><?php
374
375 wpbc_flex_label(
376 array(
377 'id' => $el_id
378 , 'label' => '<span class="" style="font-weight:600;">' . esc_html__( 'Booking resource', 'booking' ) . ':</span>'
379 )
380 );
381
382 ?><select class="wpbc_ui_control wpbc_ui_select change_booking_resource_selectbox"
383 id="<?php echo esc_attr( $el_id ); ?>" name="<?php echo esc_attr( $el_id ); ?>"
384
385 <?php /* ?>onfocus="javascript:console.log( 'ON FOCUS:', jQuery( this ).val(), 'in element:' , jQuery( this ) );"<?php /**/ ?>
386
387 onchange="javascript:wpbc_admin_show_message_processing( '' );wpbc_ajx_availability__send_request_with_params( {
388 'resource_id': jQuery( this ).val()
389 , 'dates_availability': jQuery( '.wpbc_radio__set_days_availability:checked' ).val()
390 , 'dates_selection': ''
391 , 'do_action': 'change_booking_resource'
392 } );"
393 ><#
394 _.each( data.ajx_data.ajx_booking_resources, function ( p_resource, p_resource_id, p_data ){
395 #><option value="{{p_resource.booking_type_id}}"
396 <#
397 if ( data.ajx_cleaned_params.resource_id == p_resource.booking_type_id ) {
398 #> selected="SELECTED" <#
399 }
400 #>
401 style="<#
402 if( undefined != p_resource.parent ) {
403 if( '0' == p_resource.parent ) {
404 #>font-weight:600;<#
405 } else {
406 #>font-size:0.95em;padding-left:20px;<#
407 }
408 }
409 #>"
410 ><#
411 if( undefined != p_resource.parent ) {
412 if( '0' != p_resource.parent ) {
413 #>&nbsp;&nbsp;&nbsp;<#
414 }
415 }
416 #>{{p_resource.title}}</option><#
417 });
418 #>
419 </select><?php
420
421 ?></div>
422
423 <div class="ui_element"><?php
424
425 ?><div class="wpbc_ui_separtor" style="margin-left: 8px;"></div><?php
426
427 ?></div><?php
428
429 ?></script><?php
430 }
431
432
433
434 private function template_toolbar_select_month_number_in_row(){ // FixIn: 10.8.1.5.
435
436 // Template
437 ?><script type="text/html" id="tmpl-wpbc_ajx_select_month_number_in_row"><?php
438
439 /*
440 ?><# console.log( ' == TEMPLATE PARAMS "wpbc_ajx_change_month_number_in_row" == ', data ); #><?php
441 */
442 $booking_action = 'select_month_number_in_row';
443
444 $el_id = 'ui_btn_' . $booking_action;
445
446 ?><div class="ui_element"><?php
447 ?><div class="wpbc_ui_separtor" style="margin-left: 8px;"></div><?php
448 ?></div><?php
449
450 ?><div class="ui_element"><?php
451
452 wpbc_flex_label(
453 array(
454 'id' => $el_id
455 , 'label' => '<span class="" style="font-weight:600;">' . esc_html__( 'Number of months in a row', 'booking' ) . ':</span>'
456 )
457 );
458
459 ?><select class="wpbc_ui_control wpbc_ui_select change_month_number_in_row_selectbox"
460 id="<?php echo esc_attr( $el_id ); ?>" name="<?php echo esc_attr( $el_id ); ?>"
461
462 <?php /* ?>onfocus="javascript:console.log( 'ON FOCUS:', jQuery( this ).val(), 'in element:' , jQuery( this ) );"<?php /**/ ?>
463
464 onchange="javascript:wpbc_admin_show_message_processing( '' );wpbc_ajx_availability__send_request_with_params( {
465 'calendar__view__months_in_row': jQuery( '.change_month_number_in_row_selectbox option:selected' ).val()
466 , 'do_action': 'change_month_number_in_row'
467 } );"
468 ><#
469 for (var month_index = 2; month_index < 7; month_index++ ){
470 #><option value="{{month_index}}"
471 <#
472 if ( data.ajx_cleaned_params.calendar__view__months_in_row == month_index ) {
473 #> selected="SELECTED" <#
474 }
475 #>
476 >{{month_index}}</option><#
477 }
478 #>
479 </select><?php
480
481 ?></div><?php
482
483 ?></script><?php
484 }
485
486 // </editor-fold>
487
488
489
490 // <editor-fold defaultstate="collapsed" desc=" /// A J A X /// " >
491
492 // A J A X =====================================================================================================
493
494 /**
495 * Define HOOKs for start loading Ajax
496 */
497 public function define_ajax_hook(){
498
499 // Ajax Handlers. Note. "locale_for_ajax" rechecked in wpbc-ajax.php
500 add_action( 'wp_ajax_' . 'WPBC_AJX_AVAILABILITY', array( $this, 'ajax_' . 'WPBC_AJX_AVAILABILITY' ) ); // Admin & Client (logged in usres)
501
502 // Ajax Handlers for actions
503 //add_action( 'wp_ajax_' . 'WPBC_AJX_BOOKING_ACTIONS', 'wpbc_ajax_' . 'WPBC_AJX_BOOKING_ACTIONS' );
504
505 // add_action( 'wp_ajax_nopriv_' . 'WPBC_AJX_BOOKING_LISTING', array( $this, 'ajax_' . 'WPBC_AJX_BOOKING_LISTING' ) ); // Client (not logged in)
506 }
507
508
509
510 /**
511 * Ajax - Get Listing Data and Response to JS script
512 */
513 public function ajax_WPBC_AJX_AVAILABILITY() {
514
515 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
516 if ( ! isset( $_POST['search_params'] ) || empty( $_POST['search_params'] ) ) { exit; }
517
518 // Security ----------------------------------------------------------------------------------------------- // in Ajax Post: 'nonce': wpbc_ajx_booking_listing.get_secure_param( 'nonce' ),
519 $action_name = 'wpbc_ajx_availability_ajx' . '_wpbcnonce';
520 $nonce_post_key = 'nonce';
521 $result_check = check_ajax_referer( $action_name, $nonce_post_key );
522
523 $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
524
525 /**
526 * SQL ---------------------------------------------------------------------------
527 *
528 * in Ajax Post: 'search_params': wpbc_ajx_booking_listing.search_get_all_params()
529 *
530 * Use prefix "search_params", if Ajax sent -
531 * $_REQUEST['search_params']['page_num'], $_REQUEST['search_params']['page_items_count'],..
532 */
533
534 $user_request = new WPBC_AJX__REQUEST( array(
535 'db_option_name' => 'booking_availability_request_params',
536 'user_id' => $user_id,
537 'request_rules_structure' => WPBC_AJX__Availability::request_rules_structure()
538 )
539 );
540 $request_prefix = 'search_params';
541 $request_params = $user_request->get_sanitized__in_request__value_or_default( $request_prefix ); // NOT Direct: $_REQUEST['search_params']['resource_id']
542
543 //----------------------------------------------------------------------------------------------------------
544 // Get booking resources (sql)
545 $resources_arr = wpbc_ajx_get_all_booking_resources_arr(); /**
546 * Array ( [0] => Array ( [booking_type_id] => 1
547 [title] => Standard
548 [users] => 1
549 [import] =>
550 [export] =>
551 [cost] => 25
552 [default_form] => standard
553 [prioritet] => 0
554 [parent] => 0
555 [visitors] => 2
556 ), ... */
557
558 $resources_arr_sorted = wpbc_ajx_get_sorted_booking_resources_arr( $resources_arr );
559
560 // FixIn: 10.3.0.7.
561 // 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.
562 $is_resource_exist = false;
563 foreach ( $resources_arr_sorted as $resource_index => $resource_value_arr ) {
564 if ( intval( $resource_value_arr['booking_type_id'] ) === intval( $request_params['resource_id'] ) ) {
565 $is_resource_exist = true;
566 break; // All good
567 }
568 }
569 if ( ! $is_resource_exist ) {
570 if ( count( $resources_arr_sorted ) > 0 ) {
571 $request_params['resource_id'] = intval( $resources_arr_sorted[0]['booking_type_id'] );
572 }
573 }
574
575
576 $data_arr = array();
577 $data_arr['ajx_after_action_message'] = '';
578 $data_arr['ajx_after_action_result'] = 1;
579
580 if ( 'set_availability' == $request_params['do_action'] ) {
581
582 // Dates -- update status in DB
583 $row_number = wpbc_availability__update_dates_status__sql( array(
584 'resource_id' => $request_params['resource_id'], // int
585 'prop_name' => 'date_status', // 'rate', 'allow_start_day_selection', 'allow_days_number_to_select', 'availability_count', ...
586 'prop_value' => $request_params['dates_availability'], // 'available', 'unavailable' , 'pending', 'approved'
587 'dates_selection' => $request_params['dates_selection'] // '2023-04-04 | 2023-04-07'
588 ) );
589
590 if ( false !== $row_number ) {
591 if ( 'available' == $request_params['dates_availability'] ) {
592 /* translators: 1: ... */
593 $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' )
594 , '<strong>' . $row_number . '</strong>'
595 , '<strong style="color:#11be4c;">', '</strong>' );
596 } else {
597 /* translators: 1: ... */
598 $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' )
599 , '<strong>' . $row_number . '</strong>'
600 , '<strong style="color:#e43939;">', '</strong>' );
601 }
602 $data_arr['ajx_after_action_result'] = ( $row_number > 0 ) ? 1 : 0;
603 }
604 }
605
606 if ( 'erase_availability' == $request_params['do_action'] ) {
607 //TODO: Make new fucntion here to delete all items from DB relative to this booking resource 2023-02-06 14:42
608 // Dates -- update status in DB
609 $row_number = wpbc_availability__delete_dates_status__sql( array(
610 'resource_id' => $request_params['resource_id'], // int
611 'prop_name' => 'date_status', // 'rate', 'allow_start_day_selection', 'allow_days_number_to_select', 'availability_count', ...
612 //'prop_value' => $request_params['dates_availability'], // 'available', 'unavailable' , 'pending', 'approved'
613 'dates_selection' => 'all' // '2023-04-04 | 2023-04-07'
614 ) );
615 $data_arr['ajx_after_action_message'] = ( $row_number > 0 )
616 /* translators: 1: ... */
617 ? sprintf( __( 'All %s unavailable dates has been removed', 'booking' ), '<strong>' . $row_number . '</strong>' )
618 : sprintf( __( 'No unavailable dates.', 'booking' ), $row_number );
619 $data_arr['ajx_after_action_result'] = ( $row_number > 0 ) ? 1 : 0;
620
621 }
622
623 // FixIn: 10.8.1.5.
624 if ( 'change_month_number_in_row' == $request_params['do_action'] ) {
625 // $request_params['calendar__view__months_in_row']; // Saving this parameter
626 /* translators: 1: ... */
627 $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>' );
628 $data_arr['ajx_after_action_result'] = 1;
629 }
630
631 $data_arr['booked_dates'] = wpbc__sql__get_booked_dates( array(
632 'resource_id' => $request_params['resource_id']
633 ) );
634
635 $data_arr['season_availability'] = wpbc__sql__get_season_availability( array(
636 'resource_id' => $request_params['resource_id']
637 ) );
638
639 $data_arr['resource_unavailable_dates'] = wpbc_resource__get_unavailable_dates($request_params['resource_id']);
640
641
642 //----------------------------------------------------------------------------------------------------------
643
644
645 $data_arr['ajx_booking_resources'] = $resources_arr_sorted;
646
647 //----------------------------------------------------------------------------------------------------------
648
649 $data_arr['ajx_nonce_calendar'] = wp_nonce_field( 'CALCULATE_THE_COST', 'wpbc_nonce' . 'CALCULATE_THE_COST' . $request_params['resource_id'], true, false );
650
651 $data_arr['popover_hints'] = array();
652
653 $data_arr['popover_hints']['season_unavailable'] = '<strong>' . esc_html__( 'Season unavailable day', 'booking' ) . '</strong><hr>'
654 /* translators: 1: ... */
655 . sprintf( __( 'Change this date status at %1$sBooking Calendar %2$s Availability %3$s Season Availability page.', 'booking' ), '<br>', '&gt;', '&gt;' );
656 $data_arr['popover_hints']['weekdays_unavailable'] = '<strong>' . esc_html__( 'Unavailable week day', 'booking' ) . '</strong><hr>'
657 /* translators: 1: ... */
658 . sprintf( __( 'Change this date status at %1$sBooking Calendar %2$s Settings General page %3$s in "Availability" section.', 'booking' ), '<br>', '&gt;', '<br>' );
659 $data_arr['popover_hints']['before_after_unavailable'] = '<strong>' . esc_html__( 'Unavailable day, depends on today day', 'booking' ) . '</strong><hr>'
660 /* translators: 1: ... */
661 . sprintf( __( 'Change this date status at %1$sBooking Calendar %2$s Settings General page %3$s in "Availability" section.', 'booking' ), '<br>', '&gt;', '<br>' );
662
663
664
665 $data_arr['popover_hints']['toolbar_text'] = '<span style="font-size: 1.05em;line-height: 1.8em;">'.
666 /* translators: 1: ... */
667 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' )
668 , '<strong>', '&nbsp;</strong>'
669 , '<strong>&nbsp;', '&nbsp;</strong>'
670 , '<strong>&nbsp;', '&nbsp;</strong>'
671 , '<strong>&nbsp;', '&nbsp;</strong>'
672 )
673 .'</span>';
674 /* translators: 1: ... */
675 $data_arr['popover_hints']['toolbar_text_available'] = sprintf( __( 'Set dates %1$s as %2$s available.', 'booking' )
676 , '_DATES_'
677 , '_HTML_'
678 );
679 /* translators: 1: ... */
680 $data_arr['popover_hints']['toolbar_text_unavailable'] = sprintf( __( 'Set dates %1$s as %2$s unavailable.', 'booking' )
681 , '_DATES_'
682 , '_HTML_'
683 );
684
685 // Clear here DATES selection in $request_params['dates_selection'] to not save such selection
686
687 if ( 'make_reset' === $request_params['do_action'] ) {
688
689 $is_reseted = $user_request->user_request_params__db_delete(); // Delete from DB
690
691 $request_params['do_action'] = $is_reseted ? 'reset_done' : 'reset_error';
692 } else {
693
694 $request_params_to_save = $request_params;
695
696 // Do not safe such elements
697 unset( $request_params_to_save['ui_clicked_element_id'] );
698 unset( $request_params_to_save['do_action'] );
699 unset( $request_params_to_save['dates_selection'] );
700 // 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
701 unset( $request_params_to_save['calendar__timeslot_day_bg_as_available'] ); // FixIn: 9.5.5.4.
702
703 $is_success_update = $user_request->user_request_params__db_save( $request_params_to_save ); // Save to DB // - $request_params - serialized here automatically
704 }
705
706 //----------------------------------------------------------------------------------------------------------
707 // 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.
708 wp_send_json( array(
709 'ajx_data' => $data_arr,
710 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
711 'ajx_search_params' => $_REQUEST[ $request_prefix ], // $_REQUEST[ 'search_params' ]
712 'ajx_cleaned_params' => $request_params
713 ) );
714 }
715
716 // </editor-fold>
717
718 }
719
720 /**
721 * Just for loading CSS and JavaScript files
722 */
723 if ( true ) {
724 $ajx_availability_loading = new WPBC_AJX__Availability;
725 $ajx_availability_loading->init_load_css_js_tpl();
726 $ajx_availability_loading->define_ajax_hook();
727 }