PluginProbe
Booking Calendar / 10.1.3
Booking Calendar v10.1.3
11.8.3 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 All 203 releases
booking / includes / page-availability / availability__class.php

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

634 lines 27.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 // Load only at specific Page
26 if ( strpos( $_SERVER['REQUEST_URI'], 'page=wpbc-availability' ) !== false ) {
27
28 add_action( 'wpbc_enqueue_js_files', array( $this, 'js_load_files' ), 50 );
29 add_action( 'wpbc_enqueue_css_files', array( $this, 'enqueue_css_files' ), 50 );
30
31 add_action( 'wpbc_hook_settings_page_footer', array( $this, 'hook__page_footer_tmpl' ) );
32 }
33 }
34
35
36 /** JS */
37 public function js_load_files( $where_to_load ) {
38
39 $in_footer = true;
40
41 if ( wpbc_is_availability_page() )
42 if ( ( is_admin() ) && ( in_array( $where_to_load, array( 'admin', 'both' ) ) ) ) {
43
44 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
47
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 );
55 /**
56 *
57 * wp_localize_script( 'wpbc-global-vars', 'wpbc_live_request_obj'
58 * , array(
59 * 'ajx_booking' => '',
60 * 'reminders' => ''
61 * )
62 * );
63 */
64 }
65 }
66
67
68 /** CSS */
69 public function enqueue_css_files( $where_to_load ) {
70
71 if ( ( is_admin() ) && ( in_array( $where_to_load, array( 'admin', 'both' ) ) ) ) {
72
73 wp_enqueue_style( 'wpbc-ajx_availability_page'
74 , trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/availability_page.css' //, wpbc_plugin_url( '/includes/listing_ajx_booking/o-ajx_booking-listing.css' )
75 , array(), WP_BK_VERSION_NUM );
76 }
77 }
78
79 // </editor-fold>
80
81
82 // <editor-fold defaultstate="collapsed" desc=" /// R e q u e s t /// " >
83
84 /**
85 * Get params names for escaping and/or default value of such params
86 *
87 * @return array array ( 'resource_id' => array( 'validate' => 'digit_or_csd', 'default' => array( '1' ) )
88 * , ... )
89 */
90 static public function request_rules_structure(){
91
92 $default_resource_id = wpbc_get_default_resource();
93
94 return array(
95 'do_action' => array( 'validate' => array( 'none', 'set_availability', 'make_reset', 'erase_availability' ), 'default' => 'none' )
96
97 , '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 , 'dates_selection' => array( 'validate' => 's', 'default' => '' )
99 , 'dates_availability' => array( 'validate' => array( 'unavailable', 'available' ), 'default' => 'unavailable' )
100
101 , 'ui_clicked_element_id' => array( 'validate' => 's', 'default' => '' )
102 , 'ui_usr__availability_selected_toolbar' => array( 'validate' => array( 'info', 'calendar_settings' ), 'default' => 'info' )
103
104 // 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' ) )
106 , 'calendar__days_selection_mode' => array( 'validate' => array( 'multiple', 'dynamic' ), 'default' => 'dynamic' )
107 , 'calendar__view__visible_months' => array( 'validate' => 'd', 'default' => 12 )
108 , 'calendar__view__months_in_row' => array( 'validate' => 'd', 'default' => 4 )
109 , 'calendar__view__width' => array( 'validate' => 's', 'default' => '100%' )
110 , 'calendar__view__max_width' => array( 'validate' => 's', 'default' => '' ) // default '' it's will be set as 341px,
111 , 'calendar__view__cell_height' => array( 'validate' => 's', 'default' => '38px' ) // '48px' || ''
112
113 // , 'calendar__view__visible_months' => array( 'validate' => 'd', 'default' => 1 )
114 // , 'calendar__view__months_in_row' => array( 'validate' => 'd', 'default' => 1 )
115 // , 'calendar__view__width' => array( 'validate' => 's', 'default' => '300px' )
116 // , 'calendar__view__max_width' => array( 'validate' => 's', 'default' => '300px' ) // default '' it's will be set as 341px,
117 // , 'calendar__view__cell_height' => array( 'validate' => 's', 'default' => '48px' ) // '45px' || ''
118
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 );
123
124 }
125
126
127 /**
128 * Get default params
129 *
130 * @return array array ( 'ui_wh_modification_date_radio' => 0
131 * , ... )
132 */
133 static public function get__request_values__default() {
134
135 $request_rules_structure = self::request_rules_structure();
136
137 $default_params_arr = array();
138
139 $structure_type = 'default';
140
141 foreach ( $request_rules_structure as $key => $value ) {
142 $default_params_arr[ $key ] = $value[ $structure_type ];
143 }
144
145 return $default_params_arr;
146 }
147
148 // </editor-fold>
149
150
151
152 // <editor-fold defaultstate="collapsed" desc=" /// Templates /// " >
153
154 // Templates ===================================================================================================
155
156 /**
157 * Templates at footer of page
158 *
159 * @param $page string
160 */
161 public function hook__page_footer_tmpl( $page ){
162
163 // page=wpbc&view_mode=vm_booking_listing
164 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 $this->template__main_page_content();
166
167 $this->template_toolbar_select_booking_resource();
168
169 $this->template__widget_available_unavailable();
170 $this->template__widget_calendar_legend();
171 }
172 }
173
174
175 /**
176 * Template
177 *
178 * Help Tips:
179 *
180 * <script type="text/html" id="tmpl-template_name_a">
181 * Escaped: {{data.test_key}}
182 * HTML: {{{data.test_key}}}
183 * JS: <# if (true) { alert( 1 ); } #>
184 * </script>
185 *
186 * var template__var = wp.template( 'template_name_a' );
187 *
188 * jQuery( '.content' ).html( template__var( { 'test_key' => '<strong>Data</strong>' } ) );
189 *
190 * @return void
191 */
192 private function template__main_page_content() {
193 ?><script type="text/html" id="tmpl-wpbc_ajx_availability_main_page_content">
194 <div class="wpbc_ajx_avy__container">
195 <div class="wpbc_ajx_avy__section_left">
196 <?php
197 $is_booking_change_over_days_triangles = get_bk_option( 'booking_change_over_days_triangles' );
198 $is_booking_change_over_days_triangles = ( $is_booking_change_over_days_triangles !== 'Off' ) ? "wpbc_change_over_triangle" : '';
199 ?>
200 <div class="wpbc_ajx_avy__calendar <?php echo $is_booking_change_over_days_triangles; ?>"><?php _e('Calendar is loading...', 'booking'); ?></div>
201 </div>
202 <div class="wpbc_ajx_avy__section_right">
203 <div class="wpbc_widgets">
204 <# <?php if (0) { ?><script type="text/javascript"><?php } ?>
205
206 var wpbc_ajx_select_booking_resource = wp.template( 'wpbc_ajx_select_booking_resource' );
207 jQuery( '#wpbc_hidden_template__select_booking_resource').html( wpbc_ajx_select_booking_resource( data ) );
208
209 var wpbc_widget__available_unavailable = wp.template( 'wpbc_ajx_widget_available_unavailable' );
210 var wpbc_widget__calendar_legend = wp.template( 'wpbc_ajx_widget_calendar_legend' );
211
212 <?php if (0) { ?></script><?php } ?>
213 #>
214
215 {{{ wpbc_widget__available_unavailable( data.ajx_cleaned_params ) }}}
216 {{{ wpbc_widget__calendar_legend( { } ) }}}
217
218 </div>
219 </div>
220 </div>
221 </script><?php
222 }
223
224
225 private function template__widget_available_unavailable(){
226
227 ?><script type="text/html" id="tmpl-wpbc_ajx_widget_available_unavailable">
228 <div class="wpbc_widget wpbc_widget_available_unavailable">
229 <div class="wpbc_widget_header">
230 <span class="wpbc_widget_header_text"><?php _e('Apply availability', 'booking'); ?></span>
231 <a href="/" class="wpbc_widget_header_settings_link"><i class="menu_icon icon-1x wpbc_icn_settings"></i></a>
232 </div>
233 <div class="wpbc_widget_content wpbc_ajx_toolbar" style="margin:0 0 20px;">
234 <div class="ui_container" >
235 <div class="ui_group ui_group__available_unavailable"><?php
236
237 // Available Radio
238 ?><div class="ui_element ui_nowrap"><?php
239 wpbc_ajx_avy__ui__available_radio();
240 ?></div><?php
241
242
243 // Unavailable Radio
244 ?><div class="ui_element ui_nowrap"><?php
245 wpbc_ajx_avy__ui__unavailable_radio();
246 ?></div><?php
247
248 // Set checked specific Radio button, depends on last action from user
249 ?><# <?php if (0) { ?><script type="text/javascript"><?php } ?>
250
251 jQuery( document ).ready( function (){
252
253 //Helper, if we click on button side, and not at radio button or label, then make radio checked.
254 jQuery( '.ui_btn_avy__set_days_availability__available__outer_button' ).on( 'click', function (){
255 jQuery( '#ui_btn_avy__set_days_availability__available' ).prop( "checked", true ).trigger( 'change' );
256 } );
257 jQuery( '.ui_btn_avy__set_days_availability__unavailable__outer_button' ).on( 'click', function (){
258 jQuery( '#ui_btn_avy__set_days_availability__unavailable' ).prop( "checked", true ).trigger( 'change' );
259 } );
260
261 // Set checked or not, specific radio buttons
262 if ( 'unavailable' == data.dates_availability ){
263 jQuery( '#ui_btn_avy__set_days_availability__unavailable' ).prop( 'checked', true );//.trigger( 'change' );
264 }
265 if ( 'available' == data.dates_availability ){
266 jQuery( '#ui_btn_avy__set_days_availability__available' ).prop( 'checked', true );//.trigger( 'change' );
267 }
268 } );
269
270 <?php if (0) { ?></script><?php } ?> #><?php
271
272
273 // Apply Button
274 ?><div class="ui_element"><?php
275 wpbc_ajx_avy__ui__availability_apply_btn();
276 ?></div>
277
278 </div>
279 </div>
280 </div>
281 </div>
282 </script><?php
283 }
284
285
286 private function template__widget_calendar_legend(){
287
288 ?><script type="text/html" id="tmpl-wpbc_ajx_widget_calendar_legend">
289 <div class="wpbc_widget wpbc_widget_calendar_legend">
290 <div class="wpbc_widget_header">
291 <span class="wpbc_widget_header_text"><?php _e('Calendar Legend', 'booking'); ?></span>
292 <a href="/" class="wpbc_widget_header_settings_link"><i class="menu_icon icon-1x wpbc_icn_settings"></i></a>
293 </div>
294 <div class="wpbc_widget_content wpbc_ajx_toolbar" style="margin:0 0 20px;">
295 <div class="ui_container" >
296 <div class="ui_group ui_group__available_unavailable"><?php
297
298 ?><div class="ui_element ui_nowrap"><?php
299
300 //echo wpbc_replace_shortcodes_in_booking_form__legend_items( '[legend_items]' );
301 echo wpbc_replace_shortcodes_in_booking_form__legend_items(
302 '[legend_items'
303 . ' items="resource_unavailable"'
304 . ' titles="resource_unavailable={'
305 . htmlspecialchars( __( "Resource unavailable days", 'booking' ), ENT_QUOTES)
306 . '}"'
307 . ' text_for_day_cell="' . date( 'd' ) . '"'
308 . ' unavailable_day_cell_tag="a"'
309 .']'
310 );
311 ?></div><?php
312
313 ?><div style="border-top:1px solid #d3d3d3;width:100%;margin: 10px 0 -5px;"></div><?php
314
315 ?><div class="ui_element ui_nowrap"><?php
316 echo wpbc_replace_shortcodes_in_booking_form__legend_items(
317 '[legend_items'
318 . ' items="unavailable,available,pending,approved,partially"'
319 . ' titles="'
320 //.' unavailable={' . htmlspecialchars( __( "Unavailable", 'booking' ), ENT_QUOTES ) . '}'
321 //.' pending={' . htmlspecialchars( __( "Pending", 'booking' ), ENT_QUOTES ) . '}'
322 .'"'
323 . ' text_for_day_cell="' . date( 'd' ) . '"'
324 . ' unavailable_day_cell_tag="span"'
325 .']'
326 );
327
328 ?></div><?php
329
330 ?>
331 </div>
332 </div>
333 </div>
334 </div>
335 <style type="text/css">
336 .wpbc_ajx_toolbar .ui_container .ui_group .ui_element > .block_hints.datepick {
337 height: auto;
338 margin: 8px 0 0 !important;
339 }
340 </style>
341 </script><?php
342 }
343
344
345 private function template_toolbar_select_booking_resource(){
346
347 // Template
348 ?><script type="text/html" id="tmpl-wpbc_ajx_select_booking_resource"><?php
349
350 if ( ! class_exists('wpdev_bk_personal') ) {
351 echo '</script>';
352 return false;
353 }
354 /*
355 ?><# console.log( ' == TEMPLATE PARAMS "wpbc_ajx_change_booking_resource" == ', data ); #><?php
356 */
357 $booking_action = 'select_booking_resource';
358
359 $el_id = 'ui_btn_' . $booking_action;
360
361 if ( ! wpbc_is_user_can( $booking_action, wpbc_get_current_user_id() ) ) {
362 echo '</script>';
363 return false;
364 }
365
366
367 ?><div class="ui_element"><?php
368
369 wpbc_flex_label(
370 array(
371 'id' => $el_id
372 , 'label' => '<span class="" style="font-weight:600;">' . __( 'Booking resource', 'booking' ) . ':</span>'
373 )
374 );
375
376 ?><select class="wpbc_ui_control wpbc_ui_select change_booking_resource_selectbox"
377 id="<?php echo $el_id; ?>" name="<?php echo $el_id; ?>"
378
379 <?php /* ?>onfocus="javascript:console.log( 'ON FOCUS:', jQuery( this ).val(), 'in element:' , jQuery( this ) );"<?php /**/ ?>
380
381 onchange="javascript:wpbc_admin_show_message_processing( '' );wpbc_ajx_availability__send_request_with_params( {
382 'resource_id': jQuery( this ).val()
383 , 'dates_availability': jQuery( '.wpbc_radio__set_days_availability:checked' ).val()
384 , 'dates_selection': ''
385 , 'do_action': 'change_booking_resource'
386 } );"
387 ><#
388 _.each( data.ajx_data.ajx_booking_resources, function ( p_resource, p_resource_id, p_data ){
389 #><option value="{{p_resource.booking_type_id}}"
390 <#
391 if ( data.ajx_cleaned_params.resource_id == p_resource.booking_type_id ) {
392 #> selected="SELECTED" <#
393 }
394 #>
395 style="<#
396 if( undefined != p_resource.parent ) {
397 if( '0' == p_resource.parent ) {
398 #>font-weight:600;<#
399 } else {
400 #>font-size:0.95em;padding-left:20px;<#
401 }
402 }
403 #>"
404 ><#
405 if( undefined != p_resource.parent ) {
406 if( '0' != p_resource.parent ) {
407 #>&nbsp;&nbsp;&nbsp;<#
408 }
409 }
410 #>{{p_resource.title}}</option><#
411 });
412 #>
413 </select><?php
414
415 ?></div>
416
417 <div class="ui_element"><?php
418
419 ?><div class="wpbc_ui_separtor" style="margin-left: 8px;"></div><?php
420
421 ?></div><?php
422
423 ?></script><?php
424 }
425
426 // </editor-fold>
427
428
429
430 // <editor-fold defaultstate="collapsed" desc=" /// A J A X /// " >
431
432 // A J A X =====================================================================================================
433
434 /**
435 * Define HOOKs for start loading Ajax
436 */
437 public function define_ajax_hook(){
438
439 // Ajax Handlers. Note. "locale_for_ajax" rechecked in wpbc-ajax.php
440 add_action( 'wp_ajax_' . 'WPBC_AJX_AVAILABILITY', array( $this, 'ajax_' . 'WPBC_AJX_AVAILABILITY' ) ); // Admin & Client (logged in usres)
441
442 // Ajax Handlers for actions
443 //add_action( 'wp_ajax_' . 'WPBC_AJX_BOOKING_ACTIONS', 'wpbc_ajax_' . 'WPBC_AJX_BOOKING_ACTIONS' );
444
445 // add_action( 'wp_ajax_nopriv_' . 'WPBC_AJX_BOOKING_LISTING', array( $this, 'ajax_' . 'WPBC_AJX_BOOKING_LISTING' ) ); // Client (not logged in)
446 }
447
448
449
450 /**
451 * Ajax - Get Listing Data and Response to JS script
452 */
453 public function ajax_WPBC_AJX_AVAILABILITY() {
454
455 if ( ! isset( $_POST['search_params'] ) || empty( $_POST['search_params'] ) ) { exit; }
456
457 // Security ----------------------------------------------------------------------------------------------- // in Ajax Post: 'nonce': wpbc_ajx_booking_listing.get_secure_param( 'nonce' ),
458 $action_name = 'wpbc_ajx_availability_ajx' . '_wpbcnonce';
459 $nonce_post_key = 'nonce';
460 $result_check = check_ajax_referer( $action_name, $nonce_post_key );
461
462 $user_id = ( isset( $_REQUEST['wpbc_ajx_user_id'] ) ) ? intval( $_REQUEST['wpbc_ajx_user_id'] ) : wpbc_get_current_user_id();
463
464 /**
465 * SQL ---------------------------------------------------------------------------
466 *
467 * in Ajax Post: 'search_params': wpbc_ajx_booking_listing.search_get_all_params()
468 *
469 * Use prefix "search_params", if Ajax sent -
470 * $_REQUEST['search_params']['page_num'], $_REQUEST['search_params']['page_items_count'],..
471 */
472
473 $user_request = new WPBC_AJX__REQUEST( array(
474 'db_option_name' => 'booking_availability_request_params',
475 'user_id' => $user_id,
476 'request_rules_structure' => WPBC_AJX__Availability::request_rules_structure()
477 )
478 );
479 $request_prefix = 'search_params';
480 $request_params = $user_request->get_sanitized__in_request__value_or_default( $request_prefix ); // NOT Direct: $_REQUEST['search_params']['resource_id']
481
482 //----------------------------------------------------------------------------------------------------------
483
484 $data_arr = array();
485 $data_arr['ajx_after_action_message'] = '';
486 $data_arr['ajx_after_action_result'] = 1;
487
488 if ( 'set_availability' == $request_params['do_action'] ) {
489
490 // Dates -- update status in DB
491 $row_number = wpbc_availability__update_dates_status__sql( array(
492 'resource_id' => $request_params['resource_id'], // int
493 'prop_name' => 'date_status', // 'rate', 'allow_start_day_selection', 'allow_days_number_to_select', 'availability_count', ...
494 'prop_value' => $request_params['dates_availability'], // 'available', 'unavailable' , 'pending', 'approved'
495 'dates_selection' => $request_params['dates_selection'] // '2023-04-04 | 2023-04-07'
496 ) );
497
498 if ( false !== $row_number ) {
499 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' )
501 , '<strong>' . $row_number . '</strong>'
502 , '<strong style="color:#11be4c;">', '</strong>' );
503 } 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' )
505 , '<strong>' . $row_number . '</strong>'
506 , '<strong style="color:#e43939;">', '</strong>' );
507 }
508 $data_arr['ajx_after_action_result'] = ( $row_number > 0 ) ? 1 : 0;
509 }
510 }
511
512 if ( 'erase_availability' == $request_params['do_action'] ) {
513 //TODO: Make new fucntion here to delete all items from DB relative to this booking resource 2023-02-06 14:42
514 // Dates -- update status in DB
515 $row_number = wpbc_availability__delete_dates_status__sql( array(
516 'resource_id' => $request_params['resource_id'], // int
517 'prop_name' => 'date_status', // 'rate', 'allow_start_day_selection', 'allow_days_number_to_select', 'availability_count', ...
518 //'prop_value' => $request_params['dates_availability'], // 'available', 'unavailable' , 'pending', 'approved'
519 'dates_selection' => 'all' // '2023-04-04 | 2023-04-07'
520 ) );
521 $data_arr['ajx_after_action_message'] = ( $row_number > 0 )
522 ? sprintf( __( 'All %s unavailable dates has been removed', 'booking' ), '<strong>' . $row_number . '</strong>' )
523 : sprintf( __( 'No unavailable dates.', 'booking' ), $row_number );
524 $data_arr['ajx_after_action_result'] = ( $row_number > 0 ) ? 1 : 0;
525
526 }
527
528
529
530 $data_arr['booked_dates'] = wpbc__sql__get_booked_dates( array(
531 'resource_id' => $request_params['resource_id']
532 ) );
533
534 $data_arr['season_availability'] = wpbc__sql__get_season_availability( array(
535 'resource_id' => $request_params['resource_id']
536 ) );
537
538 $data_arr['resource_unavailable_dates'] = wpbc_resource__get_unavailable_dates($request_params['resource_id']);
539
540
541 //----------------------------------------------------------------------------------------------------------
542
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
557 $resources_arr_sorted = wpbc_ajx_get_sorted_booking_resources_arr( $resources_arr );
558
559 $data_arr['ajx_booking_resources'] = $resources_arr_sorted;
560
561 //----------------------------------------------------------------------------------------------------------
562
563 $data_arr['ajx_nonce_calendar'] = wp_nonce_field( 'CALCULATE_THE_COST', 'wpbc_nonce' . 'CALCULATE_THE_COST' . $request_params['resource_id'], true, false );
564
565 $data_arr['popover_hints'] = array();
566
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>', '&gt;', '&gt;' );
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>', '&gt;', '<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>', '&gt;', '<br>' );
573
574
575
576 $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')
578 , '<strong>', '&nbsp;</strong>'
579 , '<strong>&nbsp;', '&nbsp;</strong>'
580 , '<strong>&nbsp;', '&nbsp;</strong>'
581 , '<strong>&nbsp;', '&nbsp;</strong>'
582 )
583 .'</span>';
584 $data_arr['popover_hints']['toolbar_text_available'] = sprintf( __( 'Set dates %s as %s available.', 'booking' )
585 , '_DATES_'
586 , '_HTML_'
587 );
588 $data_arr['popover_hints']['toolbar_text_unavailable'] = sprintf( __( 'Set dates %s as %s unavailable.', 'booking' )
589 , '_DATES_'
590 , '_HTML_'
591 );
592
593 // Clear here DATES selection in $request_params['dates_selection'] to not save such selection
594
595 if ( 'make_reset' === $request_params['do_action'] ) {
596
597 $is_reseted = $user_request->user_request_params__db_delete(); // Delete from DB
598
599 $request_params['do_action'] = $is_reseted ? 'reset_done' : 'reset_error';
600 } else {
601
602 $request_params_to_save = $request_params;
603
604 // Do not safe such elements
605 unset( $request_params_to_save['ui_clicked_element_id'] );
606 unset( $request_params_to_save['do_action'] );
607 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 $is_success_update = $user_request->user_request_params__db_save( $request_params_to_save ); // Save to DB // - $request_params - serialized here automatically
612 }
613
614 //----------------------------------------------------------------------------------------------------------
615 // 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 wp_send_json( array(
617 'ajx_data' => $data_arr,
618 'ajx_search_params' => $_REQUEST[ $request_prefix ], // $_REQUEST[ 'search_params' ]
619 'ajx_cleaned_params' => $request_params
620 ) );
621 }
622
623 // </editor-fold>
624
625 }
626
627 /**
628 * Just for loading CSS and JavaScript files
629 */
630 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 }