| 1 |
<?php /** |
| 2 |
* @version 1.0 |
| 3 |
* @description Ajax and Requests Structure for WPBC_AJX__Customize_Plugin__Ajax_Request |
| 4 |
* @category Customize_Plugin Class |
| 5 |
* @author wpdevelop |
| 6 |
* |
| 7 |
* @web-site http://oplugins.com/ |
| 8 |
* @email info@oplugins.com |
| 9 |
* |
| 10 |
* @modified 2023-06-23 |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 14 |
|
| 15 |
|
| 16 |
class WPBC_AJX__Customize_Plugin__Ajax_Request { |
| 17 |
|
| 18 |
|
| 19 |
// <editor-fold defaultstate="collapsed" desc=" /// R e q u e s t /// " > |
| 20 |
|
| 21 |
/** |
| 22 |
* Get params names for escaping and/or default value of such params |
| 23 |
* |
| 24 |
* @return array array ( 'resource_id' => array( 'validate' => 'digit_or_csd', 'default' => array( '1' ) ) |
| 25 |
* , ... ) |
| 26 |
*/ |
| 27 |
static public function request_rules_structure(){ |
| 28 |
|
| 29 |
$default_resource_id = wpbc_get_default_resource(); |
| 30 |
|
| 31 |
$days_selection_arr = self::get_days_selection_parameters_arr(); |
| 32 |
$unavailable_weekdays_arr = self::get_calendar_unavailable_weekdays(); |
| 33 |
|
| 34 |
return array( |
| 35 |
'do_action' => array( |
| 36 |
'validate' => array( |
| 37 |
'none', |
| 38 |
'save_calendar_skin', |
| 39 |
'save_calendar_dates_selection', |
| 40 |
'save_calendar_weekdays_availability', |
| 41 |
'save_calendar_additional', |
| 42 |
|
| 43 |
'make_reset' |
| 44 |
), |
| 45 |
'default' => 'none' |
| 46 |
) |
| 47 |
|
| 48 |
, 'customize_plugin__booking_skin' => array( 'validate' => 's', 'default' => '/css/skins/green-01.css' ) // get_bk_option( 'booking_skin' ) |
| 49 |
|
| 50 |
, 'current_step' => array( 'validate' => array( 'calendar_skin', 'calendar_size', 'calendar_dates_selection', 'calendar_weekdays_availability', 'calendar_additional' |
| 51 |
, 'form_structure', 'form_times', 'form_legend' |
| 52 |
, 'emails_active' |
| 53 |
, 'payments_active' |
| 54 |
, 'publish_resource' ) |
| 55 |
, 'default' => 'calendar_skin' ) |
| 56 |
|
| 57 |
, '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 |
| 58 |
, 'dates_selection' => array( 'validate' => 's', 'default' => '' ) |
| 59 |
, 'dates_customize_plugin' => array( 'validate' => array( 'unavailable', 'available' ), 'default' => 'unavailable' ) |
| 60 |
|
| 61 |
, 'ui_clicked_element_id' => array( 'validate' => 's', 'default' => '' ) |
| 62 |
//, 'ui_usr__customize_plugin_selected_toolbar' => array( 'validate' => array( 'info', 'calendar_settings' ), 'default' => 'info' ) |
| 63 |
|
| 64 |
// Calendar settings |
| 65 |
, 'calendar__start_year' => array( 'validate' => 'd', 'default' => 0 ) |
| 66 |
, 'calendar__start_month' => array( 'validate' => 'd', 'default' => 0 ) |
| 67 |
|
| 68 |
, 'calendar__view__visible_months' => array( 'validate' => 'd', 'default' => 2 ) |
| 69 |
|
| 70 |
, 'calendar__view__months_in_row' => array( 'validate' => 'd', 'default' => '' ) |
| 71 |
, 'calendar__view__width' => array( 'validate' => 's', 'default' => '' ) |
| 72 |
, 'calendar__view__cell_height' => array( 'validate' => 's', 'default' => '' ) // '48px' || '' |
| 73 |
|
| 74 |
, 'calendar__timeslot_day_bg_as_available' => array( 'validate' => 's' |
| 75 |
, 'default' => ('On' === get_bk_option( 'booking_timeslot_day_bg_as_available' ) ) ? ' wpbc_timeslot_day_bg_as_available' : '' ) |
| 76 |
// Modes :: Selection of Days |
| 77 |
, 'calendar__days_selection_mode' => array( 'validate' => array( 'single', 'multiple', 'dynamic', 'fixed' ) |
| 78 |
, 'default' => $days_selection_arr['calendar__days_selection_mode'] ) |
| 79 |
, 'calendar__bk_1click_mode_days_num' => array( 'validate' => 'd', 'default' => $days_selection_arr['calendar__bk_1click_mode_days_num'] ) /* Number of days selection with 1 mouse click */ |
| 80 |
, 'calendar__bk_1click_mode_days_start' => array( 'validate' => 's', 'default' => $days_selection_arr['calendar__bk_1click_mode_days_start'] ) /* { -1 - Any | 0 - Su, 1 - Mo, 2 - Tu, 3 - We, 4 - Th, 5 - Fr, 6 - Sat } */ |
| 81 |
, 'calendar__bk_2clicks_mode_days_min' => array( 'validate' => 'd', 'default' => $days_selection_arr['calendar__bk_2clicks_mode_days_min'] ) /* Min. Number of days selection with 2 mouse clicks */ |
| 82 |
, 'calendar__bk_2clicks_mode_days_max' => array( 'validate' => 'd', 'default' => $days_selection_arr['calendar__bk_2clicks_mode_days_max'] ) /* Max. Number of days selection with 2 mouse clicks */ |
| 83 |
, 'calendar__bk_2clicks_mode_days_specific' => array( 'validate' => 's', 'default' => $days_selection_arr['calendar__bk_2clicks_mode_days_specific'] ) /* Example: '5,7' */ |
| 84 |
, 'calendar__bk_2clicks_mode_days_start' => array( 'validate' => 's', 'default' => $days_selection_arr['calendar__bk_2clicks_mode_days_start'] ) /* { -1 - Any | 0 - Su, 1 - Mo, 2 - Tu, 3 - We, 4 - Th, 5 - Fr, 6 - Sat } */ |
| 85 |
|
| 86 |
, 'calendar__booking_max_monthes_in_calendar' => array( 'validate' => 's', 'default' => get_bk_option( 'booking_max_monthes_in_calendar' ) ) |
| 87 |
, 'calendar__booking_start_day_weeek' => array( 'validate' => array( '0','1','2','3','4','5','6' ), 'default' => get_bk_option( 'booking_start_day_weeek' ) ) |
| 88 |
|
| 89 |
// Unavailable Weekdays & more... |
| 90 |
, 'availability__user_unavilable_days' => array( 'validate' => 's', 'default' => $unavailable_weekdays_arr['user_unavilable_days'] ) |
| 91 |
, 'availability__block_some_dates_from_today' => array( 'validate' => 'd', 'default' => $unavailable_weekdays_arr['block_some_dates_from_today'] ) |
| 92 |
, 'availability__wpbc_available_days_num_from_today' => array( 'validate' => 'd', 'default' => $unavailable_weekdays_arr['wpbc_available_days_num_from_today'] ) |
| 93 |
|
| 94 |
, 'availability__booking_unavailable_extra_in_out' => array( 'validate' => array( '', 'm', 'd' ), 'default' => $unavailable_weekdays_arr[ 'booking_unavailable_extra_in_out' ] ) |
| 95 |
, 'availability__booking_unavailable_extra_minutes_in' => array( 'validate' => 's', 'default' => $unavailable_weekdays_arr['booking_unavailable_extra_minutes_in'] ) |
| 96 |
, 'availability__booking_unavailable_extra_minutes_out' => array( 'validate' => 's', 'default' => $unavailable_weekdays_arr['booking_unavailable_extra_minutes_out'] ) |
| 97 |
, 'availability__booking_unavailable_extra_days_in' => array( 'validate' => 's', 'default' => $unavailable_weekdays_arr['booking_unavailable_extra_days_in'] ) |
| 98 |
, 'availability__booking_unavailable_extra_days_out' => array( 'validate' => 's', 'default' => $unavailable_weekdays_arr['booking_unavailable_extra_days_out'] ) |
| 99 |
|
| 100 |
); |
| 101 |
|
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
/** |
| 106 |
* Get default params |
| 107 |
* |
| 108 |
* @return array array ( 'ui_wh_modification_date_radio' => 0 |
| 109 |
* , ... ) |
| 110 |
*/ |
| 111 |
static public function get__request_values__default() { |
| 112 |
|
| 113 |
$request_rules_structure = self::request_rules_structure(); |
| 114 |
|
| 115 |
$default_params_arr = array(); |
| 116 |
|
| 117 |
$structure_type = 'default'; |
| 118 |
|
| 119 |
foreach ( $request_rules_structure as $key => $value ) { |
| 120 |
$default_params_arr[ $key ] = $value[ $structure_type ]; |
| 121 |
} |
| 122 |
|
| 123 |
return $default_params_arr; |
| 124 |
} |
| 125 |
|
| 126 |
// </editor-fold> |
| 127 |
|
| 128 |
|
| 129 |
// <editor-fold defaultstate="collapsed" desc=" Support functions " > |
| 130 |
|
| 131 |
/** |
| 132 |
* Generate shortcode for booking form, from the parameters |
| 133 |
* |
| 134 |
* @param array $request_params array( |
| 135 |
'resource_id' => 1 |
| 136 |
, 'calendar__view__visible_months' => $request_params['calendar__view__visible_months'] |
| 137 |
, 'calendar__view__months_in_row' => $request_params['calendar__view__months_in_row'] |
| 138 |
, 'calendar__view__width' => $request_params['calendar__view__width'] |
| 139 |
, 'calendar__view__cell_height' => $request_params['calendar__view__cell_height'] // '48px' || '' |
| 140 |
) |
| 141 |
* |
| 142 |
* @return string |
| 143 |
*/ |
| 144 |
public function get_shortcode__from_request__booking_form( $request_params = array() ){ |
| 145 |
|
| 146 |
$shortcode__booking_form_arr = array(); |
| 147 |
$shortcode__booking_form_arr[] = "[booking"; |
| 148 |
if ( ( ! empty( $request_params['resource_id'] ) ) && ( $request_params['resource_id'] > 1 ) ) { |
| 149 |
$shortcode__booking_form_arr[] = "type={$request_params['resource_id']}"; |
| 150 |
} |
| 151 |
if ( ( ! empty( $request_params['calendar__view__visible_months'] ) ) && ( $request_params['calendar__view__visible_months'] > 1 ) ) { |
| 152 |
$shortcode__booking_form_arr[] = "nummonths={$request_params['calendar__view__visible_months']}"; |
| 153 |
} |
| 154 |
if ( |
| 155 |
( ! empty( $request_params['calendar__view__months_in_row'] ) ) |
| 156 |
|| ( ! empty( $request_params['calendar__view__width'] ) ) |
| 157 |
|| ( ! empty( $request_params['calendar__view__cell_height'] ) ) |
| 158 |
) { |
| 159 |
$shortcode__booking_form_arr[] = "options='{calendar"; |
| 160 |
if ( ! empty( $request_params['calendar__view__months_in_row'] ) ) { |
| 161 |
$shortcode__booking_form_arr[] = "months_num_in_row={$request_params['calendar__view__months_in_row']}"; |
| 162 |
} |
| 163 |
if ( ! empty( $request_params['calendar__view__width'] ) ) { |
| 164 |
$shortcode__booking_form_arr[] = "width={$request_params['calendar__view__width']}"; |
| 165 |
} |
| 166 |
if ( ! empty( $request_params['calendar__view__cell_height'] ) ) { |
| 167 |
$shortcode__booking_form_arr[] = "cell_height={$request_params['calendar__view__cell_height']}"; |
| 168 |
} |
| 169 |
$shortcode__booking_form_arr[] = "}'"; |
| 170 |
} |
| 171 |
$shortcode__booking_form = implode( ' ', $shortcode__booking_form_arr ); |
| 172 |
$shortcode__booking_form .= ']'; |
| 173 |
|
| 174 |
return $shortcode__booking_form; |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
/** |
| 179 |
* Get days selection parameters, which saved in database |
| 180 |
* |
| 181 |
* @return array |
| 182 |
*/ |
| 183 |
static public function get_days_selection_parameters_arr(){ |
| 184 |
|
| 185 |
$specific_days_selection = ( function_exists( 'wpbc_get_specific_range_dates__as_comma_list' ) ) |
| 186 |
? wpbc_get_specific_range_dates__as_comma_list( get_bk_option( 'booking_range_selection_days_specific_num_dynamic' ) ) |
| 187 |
: ''; |
| 188 |
$data_arr = array(); |
| 189 |
// Modes :: Selection of Days |
| 190 |
$data_arr['calendar__days_selection_mode'] = ( 'range' === get_bk_option('booking_type_of_day_selections') ) |
| 191 |
? get_bk_option('booking_range_selection_type') |
| 192 |
: get_bk_option( 'booking_type_of_day_selections'); |
| 193 |
$data_arr['calendar__bk_1click_mode_days_num'] = intval( get_bk_option( 'booking_range_selection_days_count' ) ); /* Number of days selection with 1 mouse click */ |
| 194 |
$data_arr['calendar__bk_1click_mode_days_start'] = get_bk_option( 'booking_range_start_day' ); /* { -1 - Any | 0 - Su, 1 - Mo, 2 - Tu, 3 - We, 4 - Th, 5 - Fr, 6 - Sat } */ |
| 195 |
$data_arr['calendar__bk_2clicks_mode_days_min'] = intval( get_bk_option( 'booking_range_selection_days_count_dynamic' ) ); /* Min. Number of days selection with 2 mouse clicks */ |
| 196 |
$data_arr['calendar__bk_2clicks_mode_days_max'] = intval( get_bk_option( 'booking_range_selection_days_max_count_dynamic' ) ); /* Max. Number of days selection with 2 mouse clicks */ |
| 197 |
$data_arr['calendar__bk_2clicks_mode_days_specific'] = $specific_days_selection; /* Example: '5,7' */ |
| 198 |
$data_arr['calendar__bk_2clicks_mode_days_start'] = get_bk_option( 'booking_range_start_day_dynamic' ); /* { -1 - Any | 0 - Su, 1 - Mo, 2 - Tu, 3 - We, 4 - Th, 5 - Fr, 6 - Sat } */ |
| 199 |
|
| 200 |
return $data_arr; |
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
/** |
| 205 |
* Get unavailable weekdays, which saved in database |
| 206 |
* |
| 207 |
* @return array |
| 208 |
*/ |
| 209 |
static public function get_calendar_unavailable_weekdays(){ |
| 210 |
|
| 211 |
$data_arr = array(); |
| 212 |
|
| 213 |
$data_arr['user_unavilable_days'] = array(); |
| 214 |
foreach ( range( 0, 6 ) as $val ) { |
| 215 |
if ( 'On' == get_bk_option( 'booking_unavailable_day' . $val ) ) { |
| 216 |
$data_arr['user_unavilable_days'][] = $val; |
| 217 |
} |
| 218 |
} |
| 219 |
$data_arr['user_unavilable_days'] = implode( ',', $data_arr['user_unavilable_days'] ); |
| 220 |
|
| 221 |
// Unavailable days from Today |
| 222 |
$data_arr['block_some_dates_from_today'] = get_bk_option( 'booking_unavailable_days_num_from_today' ); |
| 223 |
$data_arr['wpbc_available_days_num_from_today'] = intval( get_bk_option( 'booking_available_days_num_from_today' ) ); |
| 224 |
|
| 225 |
$data_arr['booking_unavailable_extra_in_out'] = get_bk_option( 'booking_unavailable_extra_in_out' ); |
| 226 |
$data_arr['booking_unavailable_extra_minutes_in'] = get_bk_option( 'booking_unavailable_extra_minutes_in' ); |
| 227 |
$data_arr['booking_unavailable_extra_minutes_out'] = get_bk_option( 'booking_unavailable_extra_minutes_out' ); |
| 228 |
$data_arr['booking_unavailable_extra_days_in'] = get_bk_option( 'booking_unavailable_extra_days_in' ); |
| 229 |
$data_arr['booking_unavailable_extra_days_out'] = get_bk_option( 'booking_unavailable_extra_days_out' ); |
| 230 |
|
| 231 |
return $data_arr; |
| 232 |
} |
| 233 |
|
| 234 |
// </editor-fold> |
| 235 |
|
| 236 |
|
| 237 |
// <editor-fold defaultstate="collapsed" desc=" /// A J A X /// " > |
| 238 |
|
| 239 |
// A J A X ===================================================================================================== |
| 240 |
|
| 241 |
/** |
| 242 |
* Define HOOKs for start loading Ajax |
| 243 |
*/ |
| 244 |
public function define_ajax_hook(){ |
| 245 |
|
| 246 |
// Ajax Handlers. Note. "locale_for_ajax" rechecked in wpbc-ajax.php |
| 247 |
add_action( 'wp_ajax_' . 'WPBC_AJX_CUSTOMIZE_PLUGIN', array( $this, 'ajax_' . 'WPBC_AJX_CUSTOMIZE_PLUGIN' ) ); // Admin & Client (logged in usres) |
| 248 |
|
| 249 |
// Ajax Handlers for actions |
| 250 |
//add_action( 'wp_ajax_' . 'WPBC_AJX_BOOKING_ACTIONS', 'wpbc_ajax_' . 'WPBC_AJX_BOOKING_ACTIONS' ); |
| 251 |
|
| 252 |
// add_action( 'wp_ajax_nopriv_' . 'WPBC_AJX_BOOKING_LISTING', array( $this, 'ajax_' . 'WPBC_AJX_BOOKING_LISTING' ) ); // Client (not logged in) |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
/** |
| 257 |
* Ajax - Get Listing Data and Response to JS script |
| 258 |
*/ |
| 259 |
public function ajax_WPBC_AJX_CUSTOMIZE_PLUGIN() { |
| 260 |
|
| 261 |
if ( ! isset( $_POST['search_params'] ) || empty( $_POST['search_params'] ) ) { exit; } |
| 262 |
|
| 263 |
// Security ----------------------------------------------------------------------------------------------- // in Ajax Post: 'nonce': wpbc_ajx_booking_listing.get_secure_param( 'nonce' ), |
| 264 |
$action_name = 'wpbc_ajx_customize_plugin_ajx' . '_wpbcnonce'; |
| 265 |
$nonce_post_key = 'nonce'; |
| 266 |
$result_check = check_ajax_referer( $action_name, $nonce_post_key ); |
| 267 |
|
| 268 |
$user_id = ( isset( $_REQUEST['wpbc_ajx_user_id'] ) ) ? intval( $_REQUEST['wpbc_ajx_user_id'] ) : wpbc_get_current_user_id(); |
| 269 |
|
| 270 |
/** |
| 271 |
* SQL --------------------------------------------------------------------------- |
| 272 |
* |
| 273 |
* in Ajax Post: 'search_params': wpbc_ajx_booking_listing.search_get_all_params() |
| 274 |
* |
| 275 |
* Use prefix "search_params", if Ajax sent - |
| 276 |
* $_REQUEST['search_params']['page_num'], $_REQUEST['search_params']['page_items_count'],.. |
| 277 |
*/ |
| 278 |
|
| 279 |
$user_request = new WPBC_AJX__REQUEST( array( |
| 280 |
'db_option_name' => 'booking_customize_plugin_request_params', |
| 281 |
'user_id' => $user_id, |
| 282 |
'request_rules_structure' => WPBC_AJX__Customize_Plugin__Ajax_Request::request_rules_structure() |
| 283 |
) |
| 284 |
); |
| 285 |
$request_prefix = 'search_params'; |
| 286 |
$request_params = $user_request->get_sanitized__in_request__value_or_default( $request_prefix ); // NOT Direct: $_REQUEST['search_params']['resource_id'] |
| 287 |
|
| 288 |
//---------------------------------------------------------------------------------------------------------- |
| 289 |
|
| 290 |
$data_arr = array(); |
| 291 |
$data_arr['ajx_after_action_message'] = ''; |
| 292 |
$data_arr['ajx_after_action_result'] = 1; |
| 293 |
|
| 294 |
$data_arr['calendar_settings'] = array( |
| 295 |
'booking_change_over_days_triangles' => get_bk_option( 'booking_change_over_days_triangles' ) |
| 296 |
, 'booking_range_selection_time_is_active' => get_bk_option( 'booking_range_selection_time_is_active' ) |
| 297 |
|
| 298 |
, 'calendar__view__visible_months' => $request_params['calendar__view__visible_months'] |
| 299 |
|
| 300 |
, 'calendar__view__months_in_row' => $request_params['calendar__view__months_in_row'] |
| 301 |
, 'calendar__view__width' => $request_params['calendar__view__width'] |
| 302 |
, 'calendar__view__cell_height' => $request_params['calendar__view__cell_height'] // '48px' || '' |
| 303 |
|
| 304 |
, 'calendar__booking_max_monthes_in_calendar' => $request_params['calendar__booking_max_monthes_in_calendar'] |
| 305 |
, 'calendar__booking_start_day_weeek' => $request_params['calendar__booking_start_day_weeek'] |
| 306 |
|
| 307 |
, 'calendar_unavailable' => array() |
| 308 |
, 'calendar_dates_additional_info' => array() |
| 309 |
); |
| 310 |
|
| 311 |
// Shortcode (for this configuration) |
| 312 |
$data_arr['calendar_settings']['shortcode__booking_form'] = $this->get_shortcode__from_request__booking_form( $request_params ); |
| 313 |
|
| 314 |
|
| 315 |
$data_arr['customize_steps'] = array(); |
| 316 |
$data_arr['customize_steps']['action'] = 'none'; |
| 317 |
|
| 318 |
$top_tab_slug = explode( '_', $request_params['current_step'] ); |
| 319 |
$top_tab_slug = ( ! empty( $top_tab_slug ) ) ? $top_tab_slug[0] : 'calendar'; |
| 320 |
|
| 321 |
|
| 322 |
// sub Tabs ----------------------------------------------------------------------------------------------- |
| 323 |
switch ( $top_tab_slug ) { |
| 324 |
case 'calendar': |
| 325 |
$data_arr['customize_steps']['steps_arr'] = array( |
| 326 |
'calendar_skin' => array( 'class' => 'wpbc_option_step', 'html' => __( 'Calendar Skin', 'booking' ) ), |
| 327 |
'calendar_size' => array( 'class' => 'wpbc_option_step', 'html' => __( 'Calendar size', 'booking' ) ), |
| 328 |
'calendar_dates_selection' => array( 'class' => 'wpbc_option_step', 'html' => __( 'Dates selection', 'booking' ) ), |
| 329 |
'calendar_weekdays_availability' => array( 'class' => 'wpbc_option_step', 'html' => __( 'Unavailable weekdays', 'booking' ) ), |
| 330 |
'calendar_additional' => array( 'class' => 'wpbc_option_step', 'html' => __( 'Additional Settings', 'booking' ) ), |
| 331 |
); |
| 332 |
break; |
| 333 |
case 'form': |
| 334 |
$data_arr['customize_steps']['steps_arr'] = array( |
| 335 |
'form_structure' => array( 'class' => 'wpbc_option_step', 'html' => __( 'Form Structure', 'booking' ) ), |
| 336 |
'form_times' => array( 'class' => 'wpbc_option_step', 'html' => __( 'Booked Times', 'booking' ) ), |
| 337 |
'form_legend' => array( 'class' => 'wpbc_option_step', 'html' => __( 'Legend', 'booking' ) ) |
| 338 |
); |
| 339 |
break; |
| 340 |
default: |
| 341 |
$data_arr['customize_steps']['steps_arr'] = array(); |
| 342 |
} |
| 343 |
|
| 344 |
|
| 345 |
// Steps: Current, Prior, Next & future action ---------------------------------------------------------- |
| 346 |
switch ( $request_params['current_step'] ) { |
| 347 |
case 'calendar_skin': |
| 348 |
|
| 349 |
$data_arr['customize_steps']['action'] = 'save_calendar_skin'; |
| 350 |
|
| 351 |
$data_arr['customize_steps']['current'] = $request_params['current_step']; |
| 352 |
$data_arr['customize_steps']['prior'] = ''; |
| 353 |
$data_arr['customize_steps']['next'] = 'calendar_size'; |
| 354 |
|
| 355 |
break; |
| 356 |
case 'calendar_size': |
| 357 |
|
| 358 |
$data_arr['customize_steps']['action'] = 'none'; |
| 359 |
|
| 360 |
$data_arr['customize_steps']['current'] = $request_params['current_step']; |
| 361 |
$data_arr['customize_steps']['prior'] = 'calendar_skin'; |
| 362 |
$data_arr['customize_steps']['next'] = 'calendar_dates_selection'; |
| 363 |
|
| 364 |
break; |
| 365 |
case 'calendar_dates_selection': |
| 366 |
|
| 367 |
$data_arr['customize_steps']['action'] = 'save_calendar_dates_selection'; |
| 368 |
|
| 369 |
$data_arr['customize_steps']['current'] = $request_params['current_step']; |
| 370 |
$data_arr['customize_steps']['prior'] = 'calendar_size'; |
| 371 |
$data_arr['customize_steps']['next'] = 'calendar_weekdays_availability'; |
| 372 |
|
| 373 |
break; |
| 374 |
case 'calendar_weekdays_availability': |
| 375 |
|
| 376 |
$data_arr['customize_steps']['action'] = 'save_calendar_weekdays_availability'; |
| 377 |
|
| 378 |
$data_arr['customize_steps']['current'] = $request_params['current_step']; |
| 379 |
$data_arr['customize_steps']['prior'] = 'calendar_dates_selection'; |
| 380 |
$data_arr['customize_steps']['next'] = 'calendar_additional'; |
| 381 |
|
| 382 |
break; |
| 383 |
case 'calendar_additional': |
| 384 |
|
| 385 |
$data_arr['customize_steps']['action'] = 'save_calendar_additional'; |
| 386 |
|
| 387 |
$data_arr['customize_steps']['current'] = $request_params['current_step']; |
| 388 |
$data_arr['customize_steps']['prior'] = 'calendar_weekdays_availability'; |
| 389 |
$data_arr['customize_steps']['next'] = 'form_structure'; |
| 390 |
|
| 391 |
break; |
| 392 |
case 2: |
| 393 |
|
| 394 |
break; |
| 395 |
default: |
| 396 |
// Default |
| 397 |
} |
| 398 |
|
| 399 |
|
| 400 |
// Actions ================================================================================================= |
| 401 |
|
| 402 |
if ( 'save_calendar_additional' == $request_params['do_action'] ) { |
| 403 |
|
| 404 |
$is_updated = update_bk_option( 'booking_max_monthes_in_calendar', $request_params['calendar__booking_max_monthes_in_calendar'] ); |
| 405 |
$is_updated = update_bk_option( 'booking_start_day_weeek', $request_params['calendar__booking_start_day_weeek'] ); |
| 406 |
} |
| 407 |
|
| 408 |
if ( 'save_calendar_weekdays_availability' == $request_params['do_action'] ) { |
| 409 |
|
| 410 |
// Update Weekdays Unavailability |
| 411 |
$request_el_arr = $request_params['availability__user_unavilable_days']; |
| 412 |
|
| 413 |
foreach ( range( 0, 6 ) as $val ) { |
| 414 |
if ( false !== strpos( $request_el_arr, $val ) ) { |
| 415 |
$is_updated = update_bk_option( 'booking_unavailable_day' . $val , 'On'); |
| 416 |
} else{ |
| 417 |
$is_updated = update_bk_option( 'booking_unavailable_day' . $val , 'Off'); |
| 418 |
} |
| 419 |
} |
| 420 |
|
| 421 |
$is_updated = update_bk_option( 'booking_unavailable_days_num_from_today', $request_params['availability__block_some_dates_from_today'] ); |
| 422 |
if ( class_exists( 'wpdev_bk_biz_m' ) ) { |
| 423 |
$is_updated = update_bk_option( 'booking_available_days_num_from_today', $request_params['availability__wpbc_available_days_num_from_today'] ); |
| 424 |
|
| 425 |
$is_updated = update_bk_option( 'booking_unavailable_extra_in_out', $request_params['availability__booking_unavailable_extra_in_out'] ); |
| 426 |
$is_updated = update_bk_option( 'booking_unavailable_extra_minutes_in', $request_params['availability__booking_unavailable_extra_minutes_in'] ); |
| 427 |
$is_updated = update_bk_option( 'booking_unavailable_extra_minutes_out', $request_params['availability__booking_unavailable_extra_minutes_out'] ); |
| 428 |
$is_updated = update_bk_option( 'booking_unavailable_extra_days_in', $request_params['availability__booking_unavailable_extra_days_in'] ); |
| 429 |
$is_updated = update_bk_option( 'booking_unavailable_extra_days_out', $request_params['availability__booking_unavailable_extra_days_out'] ); |
| 430 |
} |
| 431 |
} |
| 432 |
|
| 433 |
|
| 434 |
if ( 'save_calendar_dates_selection' == $request_params['do_action'] ) { |
| 435 |
|
| 436 |
if ( ( 'dynamic' == $request_params['calendar__days_selection_mode'] ) || ( 'fixed' == $request_params['calendar__days_selection_mode'] ) ) { |
| 437 |
$is_updated = update_bk_option( 'booking_type_of_day_selections', 'range' ); // 'single', 'multiple', 'range |
| 438 |
$is_updated = update_bk_option( 'booking_range_selection_type', $request_params['calendar__days_selection_mode'] ); // 'dynamic', 'fixed' |
| 439 |
} else { |
| 440 |
$is_updated = update_bk_option( 'booking_type_of_day_selections', $request_params['calendar__days_selection_mode'] ); |
| 441 |
} |
| 442 |
$is_updated = update_bk_option( 'booking_range_selection_days_count', max( intval( $request_params['calendar__bk_1click_mode_days_num'] ), 1 ) ); //max() :: If user set 0, then get minimum 1 value |
| 443 |
$is_updated = update_bk_option( 'booking_range_start_day', $request_params['calendar__bk_1click_mode_days_start'] ); |
| 444 |
|
| 445 |
$is_updated = update_bk_option( 'booking_range_selection_days_count_dynamic', max( intval( $request_params['calendar__bk_2clicks_mode_days_min'] ), 1 ) ); //max() :: If user set 0, then get minimum 1 value |
| 446 |
$is_updated = update_bk_option( 'booking_range_selection_days_max_count_dynamic', max( intval( $request_params['calendar__bk_2clicks_mode_days_max'] ), 1 ) ); |
| 447 |
|
| 448 |
if ( false !== strpos( $request_params['calendar__bk_2clicks_mode_days_specific'], '-' ) ) { |
| 449 |
|
| 450 |
// Replace 5,7-10,23 to 5,7,8,9,10,23 |
| 451 |
$request_params['calendar__bk_2clicks_mode_days_specific'] = ( function_exists( 'wpbc_get_specific_range_dates__as_comma_list' ) ) |
| 452 |
? wpbc_get_specific_range_dates__as_comma_list( $request_params['calendar__bk_2clicks_mode_days_specific'] ) |
| 453 |
: ''; |
| 454 |
} |
| 455 |
// Check to have only digits and comma |
| 456 |
$request_params['calendar__bk_2clicks_mode_days_specific'] = wpbc_sanitize_digit_or_csd( $request_params['calendar__bk_2clicks_mode_days_specific'] ); |
| 457 |
|
| 458 |
$is_updated = update_bk_option( 'booking_range_selection_days_specific_num_dynamic', $request_params['calendar__bk_2clicks_mode_days_specific'] ); |
| 459 |
|
| 460 |
$calendar__bk_2clicks_mode_days_start = $request_params['calendar__bk_2clicks_mode_days_start']; |
| 461 |
if ( |
| 462 |
( false !== strpos( $calendar__bk_2clicks_mode_days_start, '-1' ) ) |
| 463 |
|| ( false !== strpos( $calendar__bk_2clicks_mode_days_start, '0,1,2,3,4,5,6' ) ) |
| 464 |
){ |
| 465 |
$calendar__bk_2clicks_mode_days_start = '-1'; |
| 466 |
} |
| 467 |
$is_updated = update_bk_option( 'booking_range_start_day_dynamic', $calendar__bk_2clicks_mode_days_start ); |
| 468 |
|
| 469 |
$data_arr['ajx_after_action_message'] = __('Dates selection','booking') . ' - ' . __('Saved', 'booking') ; |
| 470 |
$data_arr['ajx_after_action_result'] = 1; |
| 471 |
} |
| 472 |
|
| 473 |
if ( 'save_calendar_skin' == $request_params['do_action'] ) { |
| 474 |
|
| 475 |
$is_updated = update_bk_option( 'booking_skin', $request_params['customize_plugin__booking_skin'] ); |
| 476 |
|
| 477 |
$data_arr['ajx_after_action_message'] = __('Calendar Skin','booking') . ' - ' . __('Saved', 'booking') ; |
| 478 |
$data_arr['ajx_after_action_result'] = 1; |
| 479 |
} |
| 480 |
|
| 481 |
|
| 482 |
// Get actual data for templates ========================================================================== |
| 483 |
|
| 484 |
// Modes :: Selection of Days |
| 485 |
$days_selection_arr = self::get_days_selection_parameters_arr(); |
| 486 |
$data_arr['calendar_settings']['calendar__days_selection_mode'] = $days_selection_arr['calendar__days_selection_mode']; /* 'single', 'multiple', 'dynamic', 'fixed' */ |
| 487 |
$data_arr['calendar_settings']['calendar__bk_1click_mode_days_num'] = $days_selection_arr['calendar__bk_1click_mode_days_num']; /* Number of days selection with 1 mouse click */ |
| 488 |
$data_arr['calendar_settings']['calendar__bk_1click_mode_days_start'] = $days_selection_arr['calendar__bk_1click_mode_days_start']; /* { -1 - Any | 0 - Su, 1 - Mo, 2 - Tu, 3 - We, 4 - Th, 5 - Fr, 6 - Sat } */ |
| 489 |
$data_arr['calendar_settings']['calendar__bk_2clicks_mode_days_min'] = $days_selection_arr['calendar__bk_2clicks_mode_days_min']; /* Min. Number of days selection with 2 mouse clicks */ |
| 490 |
$data_arr['calendar_settings']['calendar__bk_2clicks_mode_days_max'] = $days_selection_arr['calendar__bk_2clicks_mode_days_max']; /* Max. Number of days selection with 2 mouse clicks */ |
| 491 |
$data_arr['calendar_settings']['calendar__bk_2clicks_mode_days_specific'] = $days_selection_arr['calendar__bk_2clicks_mode_days_specific']; /* Example: '5,7' */ |
| 492 |
$data_arr['calendar_settings']['calendar__bk_2clicks_mode_days_start'] = $days_selection_arr['calendar__bk_2clicks_mode_days_start']; /* { -1 - Any | 0 - Su, 1 - Mo, 2 - Tu, 3 - We, 4 - Th, 5 - Fr, 6 - Sat } */ |
| 493 |
|
| 494 |
// Weekdays |
| 495 |
$unavailable_weekdays_arr = self::get_calendar_unavailable_weekdays(); |
| 496 |
$data_arr['calendar_settings']['calendar_unavailable']['user_unavilable_days'] = $unavailable_weekdays_arr['user_unavilable_days']; |
| 497 |
|
| 498 |
// UNAVAILABLE Today days |
| 499 |
$data_arr['calendar_settings']['calendar_unavailable']['block_some_dates_from_today'] = $unavailable_weekdays_arr['block_some_dates_from_today']; |
| 500 |
// Hints |
| 501 |
$last_unavailable_date = ''; |
| 502 |
$data_arr['calendar_settings']['calendar_unavailable']['block_some_dates_from_today__hint'] = ': <span style="text-transform: lowercase;font-size:0.9em;">' . __( 'None', 'booking' ) . '</span>'; |
| 503 |
|
| 504 |
if ( 1 == $unavailable_weekdays_arr['block_some_dates_from_today'] ){ |
| 505 |
$last_unavailable_date = wp_date( 'Y-m-d 00:00:00' ); |
| 506 |
$data_arr['calendar_settings']['calendar_unavailable']['block_some_dates_from_today__hint'] = ': ' . wp_date( 'd M', strtotime( $last_unavailable_date ) ); |
| 507 |
} |
| 508 |
if ( $unavailable_weekdays_arr['block_some_dates_from_today'] > 1 ){ |
| 509 |
$last_unavailable_date = wp_date( 'Y-m-d 00:00:00', strtotime( '+' . ( $unavailable_weekdays_arr['block_some_dates_from_today'] - 1 ) . ' days' ) ); |
| 510 |
$data_arr['calendar_settings']['calendar_unavailable']['block_some_dates_from_today__hint'] = ': ' . wp_date( 'd M' ) . ' - ' . wp_date( 'd M', strtotime( $last_unavailable_date ) ); |
| 511 |
} |
| 512 |
// AVAILABLE Today days |
| 513 |
$data_arr['calendar_settings']['calendar_unavailable']['wpbc_available_days_num_from_today'] = $unavailable_weekdays_arr['wpbc_available_days_num_from_today']; |
| 514 |
// Hints |
| 515 |
$start_available_date = ( '' == $last_unavailable_date ) ? wp_date( 'Y-m-d 00:00:00' ) : wp_date( 'Y-m-d 00:00:00', strtotime( '+1 day', strtotime( $last_unavailable_date ) ) ); |
| 516 |
|
| 517 |
if ( empty( $unavailable_weekdays_arr['wpbc_available_days_num_from_today'] ) ) { |
| 518 |
$last_available_date = ''; |
| 519 |
} else { |
| 520 |
$last_available_date = wp_date( 'Y-m-d 00:00:00', strtotime( '+' . ( $unavailable_weekdays_arr['wpbc_available_days_num_from_today'] ) . ' days' ) ); |
| 521 |
} |
| 522 |
|
| 523 |
if ( ! empty( $unavailable_weekdays_arr['wpbc_available_days_num_from_today'] ) ) { |
| 524 |
|
| 525 |
if ( strtotime($start_available_date) < strtotime($last_available_date) ) { |
| 526 |
|
| 527 |
$data_arr['calendar_settings']['calendar_unavailable']['wpbc_available_days_num_from_today__hint'] = ': ' |
| 528 |
. wp_date( 'd M, Y', strtotime( $start_available_date ) ) |
| 529 |
. ' - ' |
| 530 |
. wp_date( 'd M, Y', strtotime( $last_available_date ) ); |
| 531 |
} else if ( strtotime($start_available_date) == strtotime($last_available_date) ) { |
| 532 |
$data_arr['calendar_settings']['calendar_unavailable']['wpbc_available_days_num_from_today__hint'] = ': ' . wp_date( 'd M, Y', strtotime( $start_available_date ) ) ; |
| 533 |
}else{ |
| 534 |
$data_arr['calendar_settings']['calendar_unavailable']['wpbc_available_days_num_from_today__hint'] = ': <span style="text-transform: uppercase;font-size:1.1em;">' . __( 'None', 'booking' ) . '</span>' |
| 535 |
. ' - <span style="text-transform: lowercase;font-size:0.9em;">'. wp_date( 'd M, Y', strtotime( $start_available_date ) ) |
| 536 |
. ' > ' |
| 537 |
. wp_date( 'd M, Y', strtotime( $last_available_date ) ) .'</span>'; |
| 538 |
} |
| 539 |
} else { |
| 540 |
$data_arr['calendar_settings']['calendar_unavailable']['wpbc_available_days_num_from_today__hint'] = ': ' . wp_date( 'd M, Y', strtotime( $start_available_date ) ) . ' - ...'; |
| 541 |
} |
| 542 |
|
| 543 |
$data_arr['calendar_settings']['calendar_unavailable']['booking_unavailable_extra_in_out'] = $unavailable_weekdays_arr['booking_unavailable_extra_in_out']; |
| 544 |
$data_arr['calendar_settings']['calendar_unavailable']['booking_unavailable_extra_minutes_in'] = $unavailable_weekdays_arr['booking_unavailable_extra_minutes_in']; |
| 545 |
$data_arr['calendar_settings']['calendar_unavailable']['booking_unavailable_extra_minutes_out'] = $unavailable_weekdays_arr['booking_unavailable_extra_minutes_out']; |
| 546 |
$data_arr['calendar_settings']['calendar_unavailable']['booking_unavailable_extra_days_in'] = $unavailable_weekdays_arr['booking_unavailable_extra_days_in']; |
| 547 |
$data_arr['calendar_settings']['calendar_unavailable']['booking_unavailable_extra_days_out'] = $unavailable_weekdays_arr['booking_unavailable_extra_days_out']; |
| 548 |
|
| 549 |
|
| 550 |
// <editor-fold defaultstate="collapsed" desc=" Dates | Resources for calendar " > |
| 551 |
|
| 552 |
$data_arr['calendar_settings']['calendar_dates_rates'] = apply_filters( 'wpbc_get_calendar_dates_rates_arr', array(), $request_params['resource_id'] ); |
| 553 |
|
| 554 |
if ( ( 'On' == get_bk_option( 'booking_is_show_booked_data_in_tooltips' ) ) && ( function_exists( 'wpbc_get_additional_booking_info_to_dates_arr' ) ) ) { |
| 555 |
$data_arr['calendar_settings']['calendar_dates_additional_info'] = wpbc_get_additional_booking_info_to_dates_arr( $request_params['resource_id'] ); |
| 556 |
} |
| 557 |
|
| 558 |
$data_arr['calendar_settings']['booked_dates'] = wpbc__sql__get_booked_dates( array( |
| 559 |
'resource_id' => $request_params['resource_id'] |
| 560 |
) ); |
| 561 |
|
| 562 |
$data_arr['season_customize_plugin'] = wpbc__sql__get_season_availability( array( |
| 563 |
'resource_id' => $request_params['resource_id'] |
| 564 |
) ); |
| 565 |
|
| 566 |
$data_arr['resource_unavailable_dates'] = wpbc_resource__get_unavailable_dates($request_params['resource_id']); |
| 567 |
|
| 568 |
|
| 569 |
//---------------------------------------------------------------------------------------------------------- |
| 570 |
|
| 571 |
// Get booking resources (sql) |
| 572 |
$resources_arr = wpbc_ajx_get_all_booking_resources_arr(); /** |
| 573 |
* Array ( [0] => Array ( [booking_type_id] => 1 |
| 574 |
[title] => Standard |
| 575 |
[users] => 1 |
| 576 |
[import] => |
| 577 |
[export] => |
| 578 |
[cost] => 25 |
| 579 |
[default_form] => standard |
| 580 |
[prioritet] => 0 |
| 581 |
[parent] => 0 |
| 582 |
[visitors] => 2 |
| 583 |
), ... */ |
| 584 |
|
| 585 |
$resources_arr_sorted = wpbc_ajx_get_sorted_booking_resources_arr( $resources_arr ); |
| 586 |
|
| 587 |
$data_arr['ajx_booking_resources'] = $resources_arr_sorted; |
| 588 |
|
| 589 |
//---------------------------------------------------------------------------------------------------------- |
| 590 |
|
| 591 |
$data_arr['ajx_nonce_calendar'] = wp_nonce_field( 'CALCULATE_THE_COST', 'wpbc_nonce' . 'CALCULATE_THE_COST' . $request_params['resource_id'], true, false ); |
| 592 |
|
| 593 |
$data_arr['popover_hints'] = array(); |
| 594 |
|
| 595 |
$data_arr['popover_hints']['season_unavailable'] = '<strong>' . __( 'Season unavailable day', 'booking' ) . '</strong><hr>' |
| 596 |
. sprintf( __( 'Change this date status at %sBooking %s Availability %s Season Availability page.', 'booking' ), '<br>', '>', '>' ); |
| 597 |
$data_arr['popover_hints']['weekdays_unavailable'] = '<strong>' . __( 'Unavailable week day', 'booking' ) . '</strong><hr>' |
| 598 |
. sprintf( __( 'Change this date status at %sBooking %s Settings General page %s in "Availability" section.', 'booking' ), '<br>', '>', '<br>' ); |
| 599 |
$data_arr['popover_hints']['before_after_unavailable'] = '<strong>' . __( 'Unavailable day, depends on today day', 'booking' ) . '</strong><hr>' |
| 600 |
. sprintf( __( 'Change this date status at %sBooking %s Settings General page %s in "Availability" section.', 'booking' ), '<br>', '>', '<br>' ); |
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
$data_arr['popover_hints']['toolbar_text'] = '<span style="font-size: 1.05em;line-height: 1.8em;">'. |
| 605 |
sprintf( __('%sSelect days%s in calendar then select %sAvailable%s / %sUnavailable%s status and click %sApply%s customize_plugin button.' ,'booking') |
| 606 |
, '<strong>', ' </strong>' |
| 607 |
, '<strong> ', ' </strong>' |
| 608 |
, '<strong> ', ' </strong>' |
| 609 |
, '<strong> ', ' </strong>' |
| 610 |
) |
| 611 |
.'</span>'; |
| 612 |
$data_arr['popover_hints']['toolbar_text_available'] = sprintf( __( 'Set dates %s as %s available.', 'booking' ) |
| 613 |
, '_DATES_' |
| 614 |
, '_HTML_' |
| 615 |
); |
| 616 |
$data_arr['popover_hints']['toolbar_text_unavailable'] = sprintf( __( 'Set dates %s as %s unavailable.', 'booking' ) |
| 617 |
, '_DATES_' |
| 618 |
, '_HTML_' |
| 619 |
); |
| 620 |
// </editor-fold> |
| 621 |
|
| 622 |
|
| 623 |
// Clear here DATES selection in $request_params['dates_selection'] to not save such selection |
| 624 |
|
| 625 |
if ( 'make_reset' === $request_params['do_action'] ) { |
| 626 |
|
| 627 |
$is_reseted = $user_request->user_request_params__db_delete(); // Delete from DB |
| 628 |
|
| 629 |
$request_params['do_action'] = $is_reseted ? 'reset_done' : 'reset_error'; |
| 630 |
} else { |
| 631 |
|
| 632 |
$request_params_to_save = $request_params; |
| 633 |
|
| 634 |
// Do not safe such elements |
| 635 |
unset( $request_params_to_save['ui_clicked_element_id'] ); |
| 636 |
unset( $request_params_to_save['do_action'] ); |
| 637 |
unset( $request_params_to_save['dates_selection'] ); |
| 638 |
// 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 |
| 639 |
unset( $request_params_to_save['calendar__timeslot_day_bg_as_available'] ); //FixIn: 9.5.5.4 |
| 640 |
|
| 641 |
$is_success_update = $user_request->user_request_params__db_save( $request_params_to_save ); // Save to DB // - $request_params - serialized here automatically |
| 642 |
} |
| 643 |
|
| 644 |
//---------------------------------------------------------------------------------------------------------- |
| 645 |
// 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. |
| 646 |
wp_send_json( array( |
| 647 |
'ajx_data' => $data_arr, |
| 648 |
'ajx_search_params' => $_REQUEST[ $request_prefix ], // $_REQUEST[ 'search_params' ] |
| 649 |
'ajx_cleaned_params' => $request_params |
| 650 |
) ); |
| 651 |
} |
| 652 |
|
| 653 |
// </editor-fold> |
| 654 |
|
| 655 |
} |
| 656 |
|
| 657 |
/** |
| 658 |
* Just for loading CSS and JavaScript files |
| 659 |
*/ |
| 660 |
if ( true ) { |
| 661 |
$ajx_customize_plugin_loading = new WPBC_AJX__Customize_Plugin__Ajax_Request; |
| 662 |
$ajx_customize_plugin_loading->define_ajax_hook(); |
| 663 |
} |