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