PluginProbe
Booking Calendar / 11.8.3
Booking Calendar v11.8.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
← All changes | core/admin/wpbc-sql.php +535 -303 10.1.311.8.3 View file →
@@ -1,4 +1,4 @@
1 1 <?php /**
2 2 * @version 1.0
3 3 * @package Booking Calendar
4 4 * @category Data Engine for Booking Listing / Calendar Overview pages
@@ -23,15 +23,23 @@
23 23 //if ( ( isset( $_GET[ 'page' ] ) ) && ( $_GET[ 'page' ] == 'wpbc' ) ) {
24 24
25 25 if ( wpbc_is_bookings_page() ) { // We are inside of this page. Menu item selected.
26 26
27 - if ( ( isset( $_REQUEST['view_mode'] ) ) && ( 'vm_booking_listing' === $_REQUEST['view_mode'] ) ) { //FixIn: 9.2.0
27 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
28 + $requested_tab = isset( $_REQUEST['tab'] ) ? sanitize_key( wp_unslash( $_REQUEST['tab'] ) ) : '';
29 + if ( ( '' !== $requested_tab ) && ( ! in_array( $requested_tab, array( 'vm_booking_listing', 'vm_calendar' ), true ) ) ) { // FixIn: Add Booking lives as its own Bookings tab.
28 30 return;
29 31 }
30 32
33 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
34 + if ( 'vm_booking_listing' === $requested_tab ) { //FixIn: 9.2.0
35 + return;
36 + }
37 +
31 38 $booking_default_view_mode = wpbc_get_default_saved_view_mode_for_wpbc_page();
32 - if ( ! isset( $_REQUEST['view_mode'] ) ) {
33 - $_REQUEST['view_mode'] = $booking_default_view_mode; // Set to REQUEST
39 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
40 + if ( ! isset( $_REQUEST['tab'] ) ) {
41 + $_REQUEST['tab'] = $booking_default_view_mode; // Set to REQUEST
34 42 }
35 43
36 44 // Get saved filters set, (if its not set in request yet), like "tab" & "view_mode" and overload $_REQUEST
37 45 wpbc_set_default_saved_params_to_request_for_booking_listing( 'default' );
@@ -50,21 +58,23 @@
50 58 * @return string = 'vm_calendar' | 'vm_booking_listing'
51 59 */
52 60 function wpbc_get_default_saved_view_mode_for_wpbc_page() {
53 61
54 - if ( ! isset( $_REQUEST['view_mode'] ) ) {
62 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
63 + if ( ! isset( $_REQUEST['tab'] ) ) {
55 64 $booking_default_view_mode = get_bk_option( 'booking_listing_default_view_mode' );
56 65 } else {
57 - $booking_default_view_mode = $_REQUEST['view_mode'];
66 + $booking_default_view_mode = sanitize_text_field( wp_unslash( $_REQUEST['tab'] ) ); /* phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing */ /* FixIn: sanitize_unslash */
58 67 }
59 -//$booking_default_view_mode='vm_listing'; //TODO:2023-05-20 remove it!!!!!!
60 - if ( ! in_array( $booking_default_view_mode, array( 'vm_calendar', 'vm_booking_listing' ) ) ) { //FixIn: 9.2.1 //FixIn: 9.6.3.5
61 - $booking_default_view_mode = 'vm_booking_listing';
68 +
69 + // TODO:2023-05-20 remove it!!. 'vm_booking_listing';.
70 + if ( ! in_array( $booking_default_view_mode, array( 'vm_calendar', 'vm_booking_listing' ), true ) ) {
71 + $booking_default_view_mode = 'vm_booking_listing'; // FixIn: 9.2.1 // FixIn: 9.6.3.5.
62 72 }
63 73
64 - $booking_default_view_mode = ( 'vm_listing' == $booking_default_view_mode ) ? 'vm_booking_listing' : $booking_default_view_mode; //FixIn: 9.6.3.5
74 + $booking_default_view_mode = ( 'vm_listing' === $booking_default_view_mode ) ? 'vm_booking_listing' : $booking_default_view_mode; // FixIn: 9.6.3.5.
65 75
66 - return $booking_default_view_mode; // 'vm_calendar' / 'vm_booking_listing' ;
76 + return $booking_default_view_mode; // 'vm_calendar' / 'vm_booking_listing'.
67 77 }
68 78
69 79
70 80 /**
@@ -74,47 +84,41 @@
74 84 *
75 85 * @param string $filter_name - name of saved filter set. Currntly is using only one "Default"
76 86 */
77 87 function wpbc_set_default_saved_params_to_request_for_booking_listing( $filter_name ) {
78 -//debuge($_REQUEST);
79 - // Exclude some parameters from the saved Default parameters - the values of these parameters are loading from General Booking Settings page or from the request.
80 - $exclude_options_from_saved_params = array(
81 - 'tab' // Default
82 - , 'page' // From plugin
83 - , 'view_mode' // Default
84 - , 'wh_booking_type' // Default
85 - , 'view_days_num' // Default
86 - , 'blank_field__this_field_only_for_formatting_buttons' // Skip this, this parameter for formating purpose in toolbar
87 - );
88 - $wpdevbk_filter_params = array();
89 88
89 + // Exclude some parameters from the saved Default parameters - the values of these parameters are loading from General Booking Settings page or from the request.
90 + $exclude_options_from_saved_params = array(
91 + 'tab', // Default.
92 + 'page', // From plugin.
93 + 'wh_booking_type', // Default.
94 + 'view_days_num', // Default.
95 + 'blank_field__this_field_only_for_formatting_buttons', // Skip this, this parameter for formating purpose in toolbar.
96 + );
90 97
91 - // Get here default View mode saved in a General Booking Settings page
92 - $booking_default_view_mode = wpbc_get_default_saved_view_mode_for_wpbc_page();
93 - if ( !isset( $_REQUEST['view_mode'] ) )
94 - $wpdevbk_filter_params['view_mode'] = $booking_default_view_mode; // 'vm_calendar' / 'vm_booking_listing' ;
95 - $_REQUEST['view_mode'] = $booking_default_view_mode; // Set to REQUEST
96 -
97 -// if ( !isset( $_REQUEST['view_mode'] ) ) {
98 -// $booking_default_view_mode = get_bk_option( 'booking_listing_default_view_mode' );
99 -// if ( $booking_default_view_mode !== false ) {
100 -// $wpdevbk_filter_params['view_mode'] = $booking_default_view_mode; // 'vm_calendar' / 'vm_booking_listing' ;
101 -// $_REQUEST['view_mode'] = $booking_default_view_mode; // Set to REQUEST
102 -// } else
103 -// $_REQUEST['view_mode'] = 'vm_booking_listing';
104 -// }
98 + $wpdevbk_filter_params = array();
105 99
106 - // Get here default view_days_num
107 - if ( !isset( $_REQUEST['view_days_num'] ) ) {
108 - $booking_view_days_num = get_bk_option( 'booking_view_days_num' );
109 - if ( $booking_view_days_num !== false ) {
110 - $wpdevbk_filter_params['view_days_num'] = $booking_view_days_num; // '30'
111 - $_REQUEST['view_days_num'] = $booking_view_days_num;
112 - } else
113 - $_REQUEST['view_days_num'] = '365';
114 - }
100 + // Get here default View mode saved in a General Booking Settings page.
101 + $booking_default_view_mode = wpbc_get_default_saved_view_mode_for_wpbc_page();
102 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
103 + if ( ! isset( $_REQUEST['tab'] ) ) {
104 + $wpdevbk_filter_params['tab'] = $booking_default_view_mode;
105 + }
106 + // 'vm_calendar' / 'vm_booking_listing' ;.
107 + $_REQUEST['tab'] = $booking_default_view_mode;
115 108
116 109
110 + // Get here default view_days_num.
111 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
112 + if ( ! isset( $_REQUEST['view_days_num'] ) ) {
113 + $booking_view_days_num = get_bk_option( 'booking_view_days_num' );
114 + if ( false !== $booking_view_days_num ) {
115 + $wpdevbk_filter_params['view_days_num'] = $booking_view_days_num; // '30'.
116 + $_REQUEST['view_days_num'] = $booking_view_days_num;
117 + } else {
118 + $_REQUEST['view_days_num'] = '365';
119 + }
120 + }
117 121 }
118 122
119 123
120 124
@@ -121,20 +125,22 @@
121 125 /**
122 126 * Clean Request Parameters
123 127 *
124 128 */
125 -function wpbc_check_request_paramters() { //FixIn:6.2.1.4
129 +function wpbc_check_request_paramters() { // FixIn: 6.2.1.4.
126 130
127 131 //debuge($_REQUEST);
128 132 $clean_params = array();
129 133
130 134 $clean_params['wh_booking_id'] = 'digit_or_csd';
131 - if ( ( ! empty( $_REQUEST['wh_booking_type'] ) ) && ( 'lost' == $_REQUEST['wh_booking_type'] ) ) { //FixIn: 8.5.2.19
135 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
136 + if ( ( ! empty( $_REQUEST['wh_booking_type'] ) ) && ( 'lost' == $_REQUEST['wh_booking_type'] ) ) { // FixIn: 8.5.2.19.
132 137 $clean_params['wh_booking_type'] = 'checked_skip_it';
133 138 } else {
134 139 $clean_params['wh_booking_type'] = 'digit_or_csd';
135 140 }
136 - if ( ( ! empty( $_REQUEST['booking_type'] ) ) && ( 'lost' == $_REQUEST['booking_type'] ) ) { //FixIn: 8.9.2.1
141 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
142 + if ( ( ! empty( $_REQUEST['booking_type'] ) ) && ( 'lost' == $_REQUEST['booking_type'] ) ) { // FixIn: 8.9.2.1.
137 143 $clean_params['booking_type'] = 'checked_skip_it';
138 144 } else {
139 145 $clean_params['booking_type'] = 'digit_or_csd';
140 146 }
@@ -171,9 +177,9 @@
171 177 $clean_params['page_num'] = 'd'; // '' | '1' ... // does not exist in 6.2.1.4
172 178 $clean_params['page_items_count'] = 'd'; // '' | '1' ... // does not exist in 6.2.1.4
173 179 $clean_params['view_days_num'] = 'd'; // '' | '1' ... // does not exist in 6.2.1.4
174 180
175 - //FixIn: 8.9.2.1
181 + // FixIn: 8.9.2.1.
176 182 $clean_params['scroll_start_date'] = 'digit_or_date';
177 183 $clean_params['scroll_day'] = 'd';
178 184 $clean_params['scroll_month'] = 'd';
179 185 $clean_params['limit_hours'] = 'digit_or_csd';
@@ -184,8 +190,9 @@
184 190
185 191 // elements only listed in array::
186 192 if ( is_array( $clean_type ) ) { // check only values from the list in this array
187 193
194 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
188 195 if ( ( isset( $_REQUEST[ $request_key ] ) ) && ( ! in_array( $_REQUEST[ $request_key ], $clean_type ) ) )
189 196 $clean_type = 's';
190 197 else
191 198 $clean_type = 'checked_skip_it';
@@ -197,68 +204,83 @@
197 204
198 205 break;
199 206
200 207 case 'digit_or_date': // digit or comma separated digit
208 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
201 209 if ( isset( $_REQUEST[ $request_key ] ) ) {
202 - $_REQUEST[ $request_key ] = wpbc_clean_digit_or_date( $_REQUEST[ $request_key ] );
210 + $_REQUEST[ $request_key ] = wpbc_clean_digit_or_date( $_REQUEST[ $request_key ] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
203 211 }
212 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
204 213 if ( isset( $_GET[ $request_key ] ) ) {
205 - $_GET[ $request_key ] = wpbc_clean_digit_or_date( $_GET[ $request_key ] );
214 + $_GET[ $request_key ] = wpbc_clean_digit_or_date( $_GET[ $request_key ] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
206 215 }
216 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
207 217 if ( isset( $_POST[ $request_key ] ) ) {
208 - $_POST[ $request_key ] = wpbc_clean_digit_or_date( $_POST[ $request_key ] );
218 + $_POST[ $request_key ] = wpbc_clean_digit_or_date( $_POST[ $request_key ] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
209 219 }
210 220
211 221 break;
212 222
213 223 case 'digit_or_csd': // digit or comma separated digit
224 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
214 225 if ( isset( $_REQUEST[ $request_key ] ) ) {
215 - $_REQUEST[ $request_key ] = wpbc_clean_digit_or_csd( $_REQUEST[ $request_key ] );
226 + $_REQUEST[ $request_key ] = wpbc_clean_digit_or_csd( $_REQUEST[ $request_key ] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
216 227 }
228 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
217 229 if ( isset( $_GET[ $request_key ] ) ) {
218 - $_GET[ $request_key ] = wpbc_clean_digit_or_csd( $_GET[ $request_key ] );
230 + $_GET[ $request_key ] = wpbc_clean_digit_or_csd( $_GET[ $request_key ] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
219 231 }
232 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
220 233 if ( isset( $_POST[ $request_key ] ) ) {
221 - $_POST[ $request_key ] = wpbc_clean_digit_or_csd( $_POST[ $request_key ] );
234 + $_POST[ $request_key ] = wpbc_clean_digit_or_csd( $_POST[ $request_key ] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
222 235 }
223 236
224 237 break;
225 238
226 239 case 's': // string
240 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
227 241 if ( isset( $_REQUEST[ $request_key ] ) ) {
228 - $_REQUEST[ $request_key ] = wpbc_clean_like_string_for_db( $_REQUEST[ $request_key ] );
242 + $_REQUEST[ $request_key ] = wpbc_clean_like_string_for_db( $_REQUEST[ $request_key ] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
229 243 }
244 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
230 245 if ( isset( $_GET[ $request_key ] ) ) {
231 - $_GET[ $request_key ] = wpbc_clean_like_string_for_db( $_GET[ $request_key ] );
246 + $_GET[ $request_key ] = wpbc_clean_like_string_for_db( $_GET[ $request_key ] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
232 247 }
248 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
233 249 if ( isset( $_POST[ $request_key ] ) ) {
234 - $_POST[ $request_key ] = wpbc_clean_like_string_for_db( $_POST[ $request_key ] );
250 + $_POST[ $request_key ] = wpbc_clean_like_string_for_db( $_POST[ $request_key ] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
235 251 }
236 252
237 253 break;
238 254
239 255 case 'd': // digit
256 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
240 257 if ( ( isset( $_REQUEST[ $request_key ] ) ) && ( $_REQUEST[ $request_key ] !== '' ) ) {
241 - $_REQUEST[ $request_key ] = intval( $_REQUEST[ $request_key ] );
258 + $_REQUEST[ $request_key ] = intval( $_REQUEST[ $request_key ] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
242 259 }
260 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
243 261 if ( ( isset( $_GET[ $request_key ] ) ) && ( $_GET[ $request_key ] !== '' ) ) {
244 - $_GET[ $request_key ] = intval( $_GET[ $request_key ] );
262 + $_GET[ $request_key ] = intval( $_GET[ $request_key ] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
245 263 }
264 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
246 265 if ( ( isset( $_POST[ $request_key ] ) ) && ( $_POST[ $request_key ] !== '' ) ) {
247 - $_POST[ $request_key ] = intval( $_POST[ $request_key ] );
266 + $_POST[ $request_key ] = intval( $_POST[ $request_key ] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
248 267 }
249 268
250 269 break;
251 270
252 271 default:
272 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
253 273 if ( isset( $_REQUEST[ $request_key ] ) ) {
254 - $_REQUEST[ $request_key ] = intval( $_REQUEST[ $request_key ] );
274 + $_REQUEST[ $request_key ] = intval( $_REQUEST[ $request_key ] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
255 275 }
276 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
256 277 if ( isset( $_GET[ $request_key ] ) ) {
257 - $_GET[ $request_key ] = intval( $_GET[ $request_key ] );
278 + $_GET[ $request_key ] = intval( $_GET[ $request_key ] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
258 279 }
280 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
259 281 if ( isset( $_POST[ $request_key ] ) ) {
260 - $_POST[ $request_key ] = intval( $_POST[ $request_key ] );
282 + $_POST[ $request_key ] = intval( $_POST[ $request_key ] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
261 283 }
262 284 break;
263 285 }
264 286
@@ -268,9 +290,9 @@
268 290 //debuge($_REQUEST);
269 291 }
270 292
271 293
272 -//FixIn: 9.6.3.5
294 +// FixIn: 9.6.3.5.
273 295
274 296 /**
275 297 * Get array of cleaned (limited number) paramas from REQUEST
276 298 *
@@ -279,13 +301,14 @@
279 301 function wpbc_get_clean_paramas_from_request_for_timeline() {
280 302
281 303
282 304 // Reset
283 - $start_year = date("Y"); //2012
284 - $start_month = date("m"); //09
305 + $start_year = gmdate("Y"); //2012
306 + $start_month = gmdate("m"); //09
285 307 $start_day = 1;//date("d");//1; //31
308 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
286 309 if (! empty($_REQUEST['scroll_start_date'])) { // scroll_start_date=2013-07-01
287 - $scroll_start_date= explode('-',$_REQUEST['scroll_start_date']);
310 + $scroll_start_date = explode( '-', $_REQUEST['scroll_start_date'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
288 311
289 312 $start_year = $scroll_start_date[0]; //2012
290 313 $start_month = $scroll_start_date[1]; //09
291 314 $start_day = $scroll_start_date[2]; //date("d");//1; //31
@@ -293,11 +316,13 @@
293 316
294 317 $scroll_day = 0;
295 318 $scroll_month = 0;
296 319
297 - if (isset($_REQUEST['view_days_num'])) $view_days_num = $_REQUEST['view_days_num'];
320 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
321 + if (isset($_REQUEST['view_days_num'])) $view_days_num = sanitize_text_field( wp_unslash( $_REQUEST['view_days_num'] ) ); /* phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing */ /* FixIn: sanitize_unslash */
298 322 else $view_days_num = get_bk_option( 'booking_view_days_num');
299 323
324 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
300 325 if ((isset($_REQUEST['wh_booking_type'])) && ( strpos($_REQUEST['wh_booking_type'], ',') !== false ) )
301 326 $is_show_resources_matrix = true;
302 327 else $is_show_resources_matrix = false;
303 328
@@ -305,74 +330,80 @@
305 330
306 331 switch ($view_days_num) {
307 332
308 333 case '1':
309 - if (empty($_REQUEST['scroll_start_date'])) $start_day = date("d");
310 -
311 - if (isset($_REQUEST['scroll_day'])) $scroll_day = $_REQUEST['scroll_day'];
334 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
335 + if (empty($_REQUEST['scroll_start_date'])) $start_day = gmdate("d");
336 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
337 + if (isset($_REQUEST['scroll_day'])) $scroll_day = sanitize_text_field( wp_unslash( $_REQUEST['scroll_day'] ) ); /* phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing */ /* FixIn: sanitize_unslash */
312 338
313 339 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) + intval( $scroll_day ) ), intval( $start_year ) );
314 - $wh_booking_date = date("Y-m-d", $real_date); // '2012-11-29';
340 + $wh_booking_date = gmdate("Y-m-d", $real_date); // '2012-11-29';
315 341
316 342 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) + intval( $scroll_day ) ), intval( $start_year ) );
317 - $wh_booking_date2 = date("Y-m-d", $real_date); // '2013-12-3';
343 + $wh_booking_date2 = gmdate("Y-m-d", $real_date); // '2013-12-3';
318 344 break;
319 345
320 346 case '7':
321 - if (empty($_REQUEST['scroll_start_date'])) $start_day = date("d");
322 - $start_week_day_num = date("w");
323 - $start_day_weeek = get_bk_option( 'booking_start_day_weeek' ); //[0]:Sun .. [6]:Sut
347 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
348 + if (empty($_REQUEST['scroll_start_date'])) $start_day = gmdate("d");
349 + $start_week_day_num = gmdate("w");
350 + $start_day_weeek = esc_js(get_bk_option( 'booking_start_day_weeek' )); //[0]:Sun .. [6]:Sut
324 351 if ($start_week_day_num != $start_day_weeek) {
325 352 for ($d_inc = 1; $d_inc < 8; $d_inc++) { // Just get week back
326 353 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) - intval( $d_inc ) ), intval( $start_year ) );
327 - $start_week_day_num = date("w", $real_date);
354 + $start_week_day_num = gmdate("w", $real_date);
328 355 if ($start_week_day_num == $start_day_weeek) {
329 - $start_day = date("d", $real_date);
330 - $start_year = date("Y", $real_date);
331 - $start_month = date("m", $real_date);
356 + $start_day = gmdate("d", $real_date);
357 + $start_year = gmdate("Y", $real_date);
358 + $start_month = gmdate("m", $real_date);
332 359 $d_inc=9;
333 360 }
334 361 }
335 362 }
336 363
337 - if (isset($_REQUEST['scroll_day'])) $scroll_day = $_REQUEST['scroll_day'];
364 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
365 + if (isset($_REQUEST['scroll_day'])) $scroll_day = sanitize_text_field( wp_unslash( $_REQUEST['scroll_day'] ) ); /* phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing */ /* FixIn: sanitize_unslash */
338 366
339 367 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) + intval( $scroll_day ) ), intval( $start_year ) );
340 - $wh_booking_date = date("Y-m-d", $real_date); // '2012-12-01';
368 + $wh_booking_date = gmdate("Y-m-d", $real_date); // '2012-12-01';
341 369
342 370 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) + 7 + intval( $scroll_day ) ), intval( $start_year ) );
343 - $wh_booking_date2 = date("Y-m-d", $real_date); // '2012-12-7';
371 + $wh_booking_date2 = gmdate("Y-m-d", $real_date); // '2012-12-7';
344 372 break;
345 373
346 374 case '30':
347 - if (isset($_REQUEST['scroll_month'])) $scroll_month = $_REQUEST['scroll_month'];
375 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
376 + if (isset($_REQUEST['scroll_month'])) $scroll_month = sanitize_text_field( wp_unslash( $_REQUEST['scroll_month'] ) ); /* phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing */ /* FixIn: sanitize_unslash */
348 377
349 378 $real_date = mktime( 0, 0, 0, ( intval( $start_month ) + intval( $scroll_month ) ), intval( $start_day ), intval( $start_year ) );
350 - $wh_booking_date = date("Y-m-d", $real_date); // '2012-12-01';
379 + $wh_booking_date = gmdate("Y-m-d", $real_date); // '2012-12-01';
351 380
352 381 $real_date = mktime( 0, 0, 0, ( intval( $start_month ) + 1 + intval( $scroll_month ) ), ( intval( $start_day ) - 1 ), intval( $start_year ) );
353 - $wh_booking_date2 = date("Y-m-d", $real_date); // '2012-12-31';
382 + $wh_booking_date2 = gmdate("Y-m-d", $real_date); // '2012-12-31';
354 383 break;
355 384
356 385 case '60':
357 - if (isset($_REQUEST['scroll_month'])) $scroll_month = $_REQUEST['scroll_month'];
386 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
387 + if (isset($_REQUEST['scroll_month'])) $scroll_month = sanitize_text_field( wp_unslash( $_REQUEST['scroll_month'] ) ); /* phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing */ /* FixIn: sanitize_unslash */
358 388
359 389 $real_date = mktime( 0, 0, 0, ( intval( $start_month ) + intval( $scroll_month ) ), intval( $start_day ), intval( $start_year ) );
360 - $wh_booking_date = date("Y-m-d", $real_date); // '2012-12-01';
390 + $wh_booking_date = gmdate("Y-m-d", $real_date); // '2012-12-01';
361 391
362 392 $real_date = mktime( 0, 0, 0, ( intval( $start_month ) + 2 + intval( $scroll_month ) ), ( intval( $start_day ) - 1 ), intval( $start_year ) );
363 - $wh_booking_date2 = date("Y-m-d", $real_date); // '2013-02-31';
393 + $wh_booking_date2 = gmdate("Y-m-d", $real_date); // '2013-02-31';
364 394 break;
365 395
366 396 ////////////////////////////////////////////////////////////////////////////////
367 397 default: // 30 - default
368 - if (isset($_REQUEST['scroll_month'])) $scroll_month = $_REQUEST['scroll_month'];
398 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
399 + if (isset($_REQUEST['scroll_month'])) $scroll_month = sanitize_text_field( wp_unslash( $_REQUEST['scroll_month'] ) ); /* phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing */ /* FixIn: sanitize_unslash */
369 400
370 401 $real_date = mktime( 0, 0, 0, ( intval( $start_month ) + intval( $scroll_month ) ), intval( $start_day ), intval( $start_year ) );
371 - $wh_booking_date = date("Y-m-d", $real_date); // '2012-12-01';
402 + $wh_booking_date = gmdate("Y-m-d", $real_date); // '2012-12-01';
372 403
373 404 $real_date = mktime( 0, 0, 0, ( intval( $start_month ) + 1 + intval( $scroll_month ) ), ( intval( $start_day ) - 1 ), intval( $start_year ) );
374 - $wh_booking_date2 = date("Y-m-d", $real_date); // '2012-12-31';
405 + $wh_booking_date2 = gmdate("Y-m-d", $real_date); // '2012-12-31';
375 406 break;
376 407 }
377 408
378 409 } else { // Single resource
@@ -379,20 +410,21 @@
379 410
380 411 switch ($view_days_num) {
381 412 case '90':
382 413
383 - if (empty($_REQUEST['scroll_start_date'])) $start_day = date("d");
384 - $start_week_day_num = date("w");
385 - $start_day_weeek = get_bk_option( 'booking_start_day_weeek' ); //[0]:Sun .. [6]:Sut
414 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
415 + if (empty($_REQUEST['scroll_start_date'])) $start_day = gmdate("d");
416 + $start_week_day_num = gmdate("w");
417 + $start_day_weeek = esc_js(get_bk_option( 'booking_start_day_weeek' )); //[0]:Sun .. [6]:Sut
386 418
387 419 if ($start_week_day_num != $start_day_weeek) {
388 420 for ($d_inc = 1; $d_inc < 8; $d_inc++) { // Just get week back
389 421 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) - intval( $d_inc ) ), intval( $start_year ) );
390 - $start_week_day_num = date("w", $real_date);
422 + $start_week_day_num = gmdate("w", $real_date);
391 423 if ($start_week_day_num == $start_day_weeek) {
392 - $start_day = date("d", $real_date);
393 - $start_year = date("Y", $real_date);
394 - $start_month = date("m", $real_date);
424 + $start_day = gmdate("d", $real_date);
425 + $start_year = gmdate("Y", $real_date);
426 + $start_month = gmdate("m", $real_date);
395 427 $d_inc=9;
396 428 //break;
397 429 }
398 430 }
@@ -397,39 +429,43 @@
397 429 }
398 430 }
399 431 }
400 432
401 - if (isset($_REQUEST['scroll_day'])) $scroll_day = $_REQUEST['scroll_day'];
433 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
434 + if (isset($_REQUEST['scroll_day'])) $scroll_day = sanitize_text_field( wp_unslash( $_REQUEST['scroll_day'] ) ); /* phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing */ /* FixIn: sanitize_unslash */
402 435
403 436 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) + intval( $scroll_day ) ), intval( $start_year ) );
404 - $wh_booking_date = date("Y-m-d", $real_date); // '2012-12-01';
437 + $wh_booking_date = gmdate("Y-m-d", $real_date); // '2012-12-01';
405 438
406 439 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) + 7 * 12 + 7 + intval( $scroll_day ) ), intval( $start_year ) );
407 - $wh_booking_date2 = date("Y-m-d", $real_date); // '2013-12-31';
440 + $wh_booking_date2 = gmdate("Y-m-d", $real_date); // '2013-12-31';
408 441 break;
409 442
410 443 case '30':
411 - if (empty($_REQUEST['scroll_start_date'])) $start_day = date("d");
444 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
445 + if (empty($_REQUEST['scroll_start_date'])) $start_day = gmdate("d");
412 446
413 - if (isset($_REQUEST['scroll_day'])) $scroll_day = $_REQUEST['scroll_day'];
447 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
448 + if (isset($_REQUEST['scroll_day'])) $scroll_day = sanitize_text_field( wp_unslash( $_REQUEST['scroll_day'] ) ); /* phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing */ /* FixIn: sanitize_unslash */
414 449
415 450 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) + intval( $scroll_day ) ), intval( $start_year ) );
416 - $wh_booking_date = date("Y-m-d", $real_date); // '2012-12-01';
451 + $wh_booking_date = gmdate("Y-m-d", $real_date); // '2012-12-01';
417 452
418 453 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) + 31 + intval( $scroll_day ) ), intval( $start_year ) );
419 - $wh_booking_date2 = date("Y-m-d", $real_date); // '2013-12-31';
454 + $wh_booking_date2 = gmdate("Y-m-d", $real_date); // '2013-12-31';
420 455 break;
421 456
422 457 default: // 365
423 458
424 - if (isset($_REQUEST['scroll_month'])) $scroll_month = $_REQUEST['scroll_month'];
459 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
460 + if (isset($_REQUEST['scroll_month'])) $scroll_month = sanitize_text_field( wp_unslash( $_REQUEST['scroll_month'] ) ); /* phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing */ /* FixIn: sanitize_unslash */
425 461 else $scroll_month = 0;
426 462
427 463 $real_date = mktime( 0, 0, 0, ( intval( $start_month ) + intval( $scroll_month ) ), intval( $start_day ), intval( $start_year ) );
428 - $wh_booking_date = date("Y-m-d", $real_date); // '2012-12-01';
464 + $wh_booking_date = gmdate("Y-m-d", $real_date); // '2012-12-01';
429 465
430 466 $real_date = mktime( 0, 0, 0, ( intval( $start_month ) + intval( $scroll_month ) + 13 ), ( intval( $start_day ) - 1 ), intval( $start_year ) );
431 - $wh_booking_date2 = date("Y-m-d", $real_date); // '2013-12-31';
467 + $wh_booking_date2 = gmdate("Y-m-d", $real_date); // '2013-12-31';
432 468
433 469 break;
434 470 }
435 471 }
@@ -436,135 +472,148 @@
436 472
437 473
438 474 $or_sort = '' ;
439 475
440 - $args = array(
441 - 'wh_booking_type' => (isset($_REQUEST['wh_booking_type']))?$_REQUEST['wh_booking_type']:'',
442 - 'wh_approved' => '', // Any
443 - 'wh_booking_id' => '', // Any
444 - 'wh_is_new' => '', //(isset($_REQUEST['wh_is_new']))?$_REQUEST['wh_is_new']:'', // ?
445 - 'wh_pay_status' => 'all', //(isset($_REQUEST['wh_pay_status']))?$_REQUEST['wh_pay_status']:'', // ?
446 - 'wh_keyword' => '', //(isset($_REQUEST['wh_keyword']))?$_REQUEST['wh_keyword']:'', // ?
447 - 'wh_booking_date' => $wh_booking_date,
448 - 'wh_booking_date2' => $wh_booking_date2,
449 - 'wh_modification_date' => '3', //(isset($_REQUEST['wh_modification_date']))?$_REQUEST['wh_modification_date']:'', // ?
450 - 'wh_modification_date2' => '', //(isset($_REQUEST['wh_modification_date2']))?$_REQUEST['wh_modification_date2']:'', // ?
451 - 'wh_cost' => '', //(isset($_REQUEST['wh_cost']))?$_REQUEST['wh_cost']:'', // ?
452 - 'wh_cost2' => '', //(isset($_REQUEST['wh_cost2']))?$_REQUEST['wh_cost2']:'', // ?
453 - 'or_sort' => $or_sort,
454 - 'page_num' => '1',
455 - 'page_items_count' => '100000'
476 + $args = array(
477 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
478 + 'wh_booking_type' => ( isset( $_REQUEST['wh_booking_type'] ) ) ? $_REQUEST['wh_booking_type'] : '',
479 + 'wh_approved' => '', // Any.
480 + 'wh_booking_id' => '', // Any.
481 + 'wh_is_new' => '', // (isset($_REQUEST['wh_is_new']))?$_REQUEST['wh_is_new']:'', ?.
482 + 'wh_pay_status' => 'all', // (isset($_REQUEST['wh_pay_status']))?$_REQUEST['wh_pay_status']:'', // ?.
483 + 'wh_keyword' => '', // (isset($_REQUEST['wh_keyword']))?$_REQUEST['wh_keyword']:'', // ?.
484 + 'wh_booking_date' => $wh_booking_date,
485 + 'wh_booking_date2' => $wh_booking_date2,
486 + 'wh_modification_date' => '3', // (isset($_REQUEST['wh_modification_date']))?$_REQUEST['wh_modification_date']:'', // ?
487 + 'wh_modification_date2' => '', // (isset($_REQUEST['wh_modification_date2']))?$_REQUEST['wh_modification_date2']:'', // ?
488 + 'wh_cost' => '', // (isset($_REQUEST['wh_cost']))?$_REQUEST['wh_cost']:'', // ?
489 + 'wh_cost2' => '', // (isset($_REQUEST['wh_cost2']))?$_REQUEST['wh_cost2']:'', // ?
490 + 'or_sort' => $or_sort,
491 + 'page_num' => '1',
492 + 'page_items_count' => '100000',
456 493 );
457 494
458 - return $args;
495 + return $args;
459 496 }
460 497
461 498
462 499 /** Set initial $_REQUEST['view_days_num'] depend on from selected booking resources */
463 500 function wpbc_set_request_params_for_timeline() {
464 -
465 - if ( (isset( $_REQUEST['wh_booking_type'] )) && ( strpos( $_REQUEST['wh_booking_type'], ',' ) !== false ) )
466 - $is_show_resources_matrix = true;
467 - else
468 - $is_show_resources_matrix = false;
469 501
470 - if ( !isset( $_REQUEST['view_days_num'] ) )
471 - $_REQUEST['view_days_num'] = get_bk_option( 'booking_view_days_num' );
472 -
473 - //We do not have the Year (365) and (90) view modes in the Matrix mode so we are set to the closest variant. And the same backward.
474 - if ( ($is_show_resources_matrix ) ) { // Switching from the Single to Matrix mode.
475 - if ( $_REQUEST['view_days_num'] == '365' ) {
476 - $_REQUEST['view_days_num'] = 60;
477 - }
478 - if ( $_REQUEST['view_days_num'] == '90' ) {
479 - $_REQUEST['view_days_num'] = 7;
480 - }
481 - } else { // Switching from the Matrix to Single mode.
482 - if ( $_REQUEST['view_days_num'] == '60' ) {
483 - $_REQUEST['view_days_num'] = 365;
484 - }
485 - if ( ($_REQUEST['view_days_num'] == '7') || ($_REQUEST['view_days_num'] == '1') ) {
486 - $_REQUEST['view_days_num'] = 30;
487 - }
488 - }
502 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
503 + if ( ( isset( $_REQUEST['wh_booking_type'] ) ) && ( strpos( $_REQUEST['wh_booking_type'], ',' ) !== false ) ) {
504 + $is_show_resources_matrix = true;
505 + } else {
506 + $is_show_resources_matrix = false;
507 + }
508 +
509 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
510 + if ( ! isset( $_REQUEST['view_days_num'] ) ) {
511 + $_REQUEST['view_days_num'] = get_bk_option( 'booking_view_days_num' );
512 + }
513 +
514 + // We do not have the Year (365) and (90) view modes in the Matrix mode so we are set to the closest variant. And the same backward.
515 + if ( ( $is_show_resources_matrix ) ) { // Switching from the Single to Matrix mode.
516 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
517 + if ( isset( $_REQUEST['view_days_num'] ) && ( $_REQUEST['view_days_num'] == '365' ) ) {
518 + $_REQUEST['view_days_num'] = 60;
519 + }
520 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
521 + if ( isset( $_REQUEST['view_days_num'] ) && ( $_REQUEST['view_days_num'] == '90' ) ) {
522 + $_REQUEST['view_days_num'] = 7;
523 + }
524 + } else { // Switching from the Matrix to Single mode.
525 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
526 + if ( isset( $_REQUEST['view_days_num'] ) && ( $_REQUEST['view_days_num'] == '60' ) ) {
527 + $_REQUEST['view_days_num'] = 365;
528 + }
529 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
530 + if ( ( $_REQUEST['view_days_num'] == '7' ) || ( $_REQUEST['view_days_num'] == '1' ) ) {
531 + $_REQUEST['view_days_num'] = 30;
532 + }
533 + }
489 534 }
490 535
491 536
492 537 /** Define default booking resource to $_GET request and check if user can be here in MU version. */
493 -function wpbc_set_default_resource_to__get() {
494 -
495 - if ( isset( $_GET['booking_type'] ) ) {
496 -
497 - // Check if User can be here in MultiUser version for this booking resource (is this user owner of this resource or not)
498 - if ( class_exists( 'wpdev_bk_multiuser' ) ) {
499 -
500 - $default_booking_resource = $_GET['booking_type'];
501 -
502 - // Check if this MU user activated or superadmin, otherwise show warning
503 - if ( ! wpbc_is_mu_user_can_be_here('activated_user') )
504 - return false;
538 +function wpbc_set_default_resource_to__get() {
505 539
506 - // Check if this MU user owner of this resource or superadmin, otherwise show warning
507 - if ( ! wpbc_is_mu_user_can_be_here( 'resource_owner', $default_booking_resource ) )
508 - return false;
509 - }
510 -
511 - } else { // Set default booking resource to $_GET
512 -
513 - // Get ID of default booking resource, or return false (in case if user have no access to this resource and show some warnings).
514 - $default_booking_resource = wpbc_get_default_resource();
540 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
541 + if ( isset( $_GET['booking_type'] ) ) {
515 542
516 - if ( empty( $default_booking_resource ) ) {
543 + // Check if User can be here in MultiUser version for this booking resource (is this user owner of this resource or not).
544 + if ( class_exists( 'wpdev_bk_multiuser' ) ) {
517 545
518 - return false; // User can not be here, Warnings have shown
546 + $default_booking_resource = sanitize_text_field( wp_unslash( $_GET['booking_type'] ) ); /* phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing */ /* FixIn: sanitize_unslash */
519 547
520 - } else {
521 -
522 - $_GET['booking_type'] = $default_booking_resource;
523 - }
548 + // Check if this MU user activated or superadmin, otherwise show warning.
549 + if ( ! wpbc_is_mu_user_can_be_here( 'activated_user' ) ) {
550 + return false;
551 + }
524 552
525 - // Check if this resource parent and has some additional childs, if yes then assign $_GET['parent_res'] = 1 only in case, if its for loading default booking resource.
526 - make_bk_action( 'check_if_bk_res_parent_with_childs_set_parent_res', $default_booking_resource );
527 - }
528 -
529 -
530 - return true;
553 + // Check if this MU user owner of this resource or superadmin, otherwise show warning.
554 + if ( ! wpbc_is_mu_user_can_be_here( 'resource_owner', $default_booking_resource ) ) {
555 + return false;
556 + }
557 + }
558 + } else { // Set default booking resource to $_GET.
559 +
560 + // Get ID of default booking resource, or return false (in case if user have no access to this resource and show some warnings).
561 + $default_booking_resource = wpbc_get_default_resource();
562 +
563 + if ( empty( $default_booking_resource ) ) {
564 +
565 + return false; // User can not be here, Warnings have shown.
566 +
567 + } else {
568 +
569 + $_GET['booking_type'] = $default_booking_resource;
570 + }
571 +
572 + // Check if this resource parent and has some additional childs, if yes then assign $_ GET['parent_res'] = 1 only in case, if its for loading default booking resource.
573 + make_bk_action( 'check_if_bk_res_parent_with_childs_set_parent_res', $default_booking_resource );
574 + }
575 +
576 + return true;
531 577 }
532 578
533 579
534 580 /**
535 - * Get ID of default booking resource, or return false (in case if user have no access to this resource and show some warnings).
536 - *
581 + * Get ID of default booking resource, or return false (in case if user have no access to this resource and show some warnings).
582 + *
537 583 * @return boolean|int
538 584 */
539 -function wpbc_get_default_resource() {
585 +function wpbc_get_default_resource() {
540 586
541 - if ( ! class_exists( 'wpdev_bk_personal' ) )
542 - return 1; // Free, i.e., default 1
543 -
544 - // Get assigned default booking resource from General Booking Settings page
545 - $default_booking_resource = get_bk_option( 'booking_default_booking_resource' ); // If empty, i.e., "" - its all resources - no default booking resource
546 -
547 - if ( empty( $default_booking_resource ) ) { //We do not have default resource
548 -
549 - // Get first resource in a list
550 - // If its MU, then for superadmin get first resource in a list OR if user DO NOT have resources get FIRST resource in LIST FROM ALL resources
551 - $default_booking_resource = get__default_type();
552 - }
587 + if ( ! class_exists( 'wpdev_bk_personal' ) ) {
588 + return 1;
589 + } // Free, i.e., default 1.
553 590
554 - //MU
555 - if ( class_exists( 'wpdev_bk_multiuser' ) ) {
591 + // Get assigned default booking resource from General Booking Settings page.
592 + $default_booking_resource = get_bk_option( 'booking_default_booking_resource' ); // If empty, i.e., "" - its all resources - no default booking resource.
556 593
557 - // Check if this MU user activated or superadmin, otherwise show warning
558 - if ( ! wpbc_is_mu_user_can_be_here('activated_user') )
559 - return false;
560 -
561 - // Check if this MU user owner of this resource or superadmin, otherwise show warning
562 - if ( ! wpbc_is_mu_user_can_be_here( 'resource_owner', $default_booking_resource ) )
563 - return false;
564 - }
565 -
566 - return $default_booking_resource;
594 + if ( empty( $default_booking_resource ) ) { // We do not have default resource.
595 +
596 + // Get first resource in a list.
597 + // If its MU, then for superadmin get first resource in a list OR if user DO NOT have resources get FIRST resource in LIST FROM ALL resources.
598 + $default_booking_resource = get__default_type();
599 + }
600 +
601 + // MU.
602 + if ( class_exists( 'wpdev_bk_multiuser' ) ) {
603 +
604 + // Check if this MU user activated or superadmin, otherwise show warning.
605 + if ( ! wpbc_is_mu_user_can_be_here( 'activated_user' ) ) {
606 + return false;
607 + }
608 +
609 + // Check if this MU user owner of this resource or superadmin, otherwise show warning.
610 + if ( ! wpbc_is_mu_user_can_be_here( 'resource_owner', $default_booking_resource ) ) {
611 + return false;
612 + }
613 + }
614 +
615 + return $default_booking_resource;
567 616 }
568 617
569 618
570 619 /** Get list of all booking resources.
@@ -595,9 +644,9 @@
595 644 $resource_objects = $resources_cache->get_resources();
596 645 // $resource_objects = $resources_cache->get_single_parent_resources();
597 646
598 647 //$resource_options = $params['resources'];
599 - $resource_options = array(); //FixIn: 8.2.1.12
648 + $resource_options = array(); // FixIn: 8.2.1.12.
600 649
601 650 foreach ( $resource_objects as $br ) {
602 651
603 652 $br_option = array();
@@ -706,15 +755,15 @@
706 755 , 'wh_cost' => ''
707 756 , 'wh_cost2' => ''
708 757 , 'or_sort' => ''
709 758 , 'page_num' => '1'
710 - , 'wh_trash' => '' //FixIn: 6.1.1.10
759 + , 'wh_trash' => '' // FixIn: 6.1.1.10.
711 760 , 'page_items_count' => ( ( empty( $num_per_page_check ) ) ? '10' : $num_per_page_check )
712 761 );
713 762
714 763 $r = wp_parse_args( $args, $defaults );
715 764
716 - $r = apply_filters( 'wpbc_request_params_for_get_booking_obj', $r ); //FixIn: 7.0.1.41
765 + $r = apply_filters( 'wpbc_request_params_for_get_booking_obj', $r ); // FixIn: 7.0.1.41.
717 766
718 767 extract( $r, EXTR_SKIP );
719 768
720 769 $page_start = ( $page_num - 1 ) * $page_items_count;
@@ -720,21 +769,21 @@
720 769 $page_start = ( $page_num - 1 ) * $page_items_count;
721 770
722 771 //debuge( $sql_start_select . $sql . $sql_where . $sql_order . $sql_limit );
723 772
724 - ////////////////////////////////////////////////////////////////////////////
773 + // -----------------------------------------------------------------------------------------------------------------
774 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
775 + $bookings_res = $wpdb->get_results( $sql_start_select . $sql . $sql_where . $sql_order . $sql_limit ); // Get Bookings.
725 776
777 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
778 + $bookings_count = $wpdb->get_results( $sql_start_count . $sql . $sql_where ); // Get Number of bookings.
726 779
727 - $bookings_res = $wpdb->get_results( $sql_start_select . $sql . $sql_where . $sql_order . $sql_limit ); // Get Bookings
728 -
729 - $bookings_count = $wpdb->get_results( $sql_start_count . $sql . $sql_where ); // Get Number of bookings
730 780 $bookings_count = ( ( count( $bookings_count ) > 0 ) ? $bookings_count[0]->count : 0 );
731 781
732 782 $booking_types = apply_bk_filter( 'wpdebk_get_keyed_all_bk_resources', array() ); // Get Resources
733 783
734 784
735 - ////////////////////////////////////////////////////////////////////////////
736 -
785 + // -----------------------------------------------------------------------------------------------------------------
737 786 $booking_id_list = array(); // ID list of ALL bookings
738 787 $bookings = array();
739 788 $short_days = array();
740 789 $short_days_type_id = array();
@@ -761,13 +810,13 @@
761 810 'booking_id' => $booking->booking_id
762 811 , 'resource_title' => (isset( $booking_types[$booking->booking_type] )) ? $booking_types[$booking->booking_type] : ''
763 812 )
764 813 );
765 -//debuge($cont);
766 - $search = array( "'(<br[ ]?[/]?>)+'si", "'(<[/]?p[ ]?>)+'si"/*, "'(<[/]?div[ ]?>)+'si"*/ ); //FixIn: 8.8.1.6
814 +
815 + $search = array( "'(<br[ ]?[/]?>)+'si", "'(<[/]?p[ ]?>)+'si"/*, "'(<[/]?div[ ]?>)+'si"*/ ); // FixIn: 8.8.1.6.
767 816 $replace = array( "&nbsp;&nbsp;", " &nbsp; ", " &nbsp; " );
768 817 $cont['content'] = preg_replace( $search, $replace, $cont['content'] );
769 -//debuge( htmlentities( $cont['content'] ) );die;
818 +
770 819 $bookings[$booking->booking_id]->form_show = $cont['content'];
771 820 unset( $cont['content'] );
772 821 $bookings[$booking->booking_id]->form_data = $cont;
773 822 }
@@ -773,27 +822,30 @@
773 822 }
774 823 $booking_id_list = implode( ",", $booking_id_list );
775 824 $booking_id_list = wpbc_clean_like_string_for_db( $booking_id_list );
776 825
777 - ////////////////////////////////////////////////////////////////////////////
778 -
779 - if ( ! empty( $booking_id_list ) ) { // Get Dates for all our Bookings
780 - $sql = "SELECT *
826 + // -----------
827 +
828 + if ( ! empty( $booking_id_list ) ) { // Get Dates for all our Bookings.
829 + $sql = "SELECT *
781 830 FROM {$wpdb->prefix}bookingdates as dt
782 831 WHERE dt.booking_id in ( {$booking_id_list} ) ";
783 832
784 - if ( class_exists( 'wpdev_bk_biz_l' ) )
785 - $sql .= " ORDER BY booking_id, type_id, booking_date ";
786 - else
787 - $sql .= " ORDER BY booking_id, booking_date ";
833 + if ( class_exists( 'wpdev_bk_biz_l' ) ) {
834 + $sql .= ' ORDER BY booking_id, type_id, booking_date ';
835 + } else {
836 + $sql .= ' ORDER BY booking_id, booking_date ';
837 + }
788 838
789 - $booking_dates = $wpdb->get_results( $sql );
790 - } else
791 - $booking_dates = array();
839 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
840 + $booking_dates = $wpdb->get_results( $sql );
792 841
842 + } else {
843 + $booking_dates = array();
844 + }
793 845
794 - ////////////////////////////////////////////////////////////////////////////
795 -
846 + // -------------
847 +
796 848 $last_booking_id = '';
797 849
798 850 foreach ( $booking_dates as $date ) { // Add Dates to Bookings array
799 851
@@ -857,14 +909,13 @@
857 909 $bookings[$last_booking_id]->dates_short = $short_days;
858 910 $bookings[$last_booking_id]->dates_short_id = $short_days_type_id;
859 911 }
860 912
861 -//debuge( 'Before filtering:', date('Y-m-d', time() +86400 ), $_REQUEST, $bookings ) ;
913 +//debuge( 'Before filtering:', gmdate('Y-m-d', time() +86400 ), $_REQUEST, $bookings ) ;
862 914
863 - ////////////////////////////////////////////////////////////////////////////
915 + // -----------------------------------------------------------------------------------------------------------------
864 916 // Filter some bookings
865 - ////////////////////////////////////////////////////////////////////////////
866 -
917 + // -----------------------------------------------------------------------------------------------------------------
867 918 // Showing only bookings that starting or ending during "Today" ( Today check in/out )
868 919 if ( (isset( $args['wh_booking_date'] )) && ($args['wh_booking_date'] == '9') ) {
869 920
870 921 $today_mysql_format = date_i18n( 'Y-m-d', time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) + 0 * DAY_IN_SECONDS ); // Today day with gmt offset
@@ -891,10 +942,10 @@
891 942
892 943
893 944 // If we selected the Dates as "Check In - Today/Tommorow", then show only the bookings, where check in date is Today
894 945 if ( (isset( $args['wh_booking_date'] )) && ($args['wh_booking_date'] == '7') ) {
895 - //$today_mysql_format = date('Y-m-d');
896 - //$today_mysql_format = date('Y-m-d', time() +86400 ); // 1 Day = 24*60*60 = 86400
946 + //$today_mysql_format = gmdate('Y-m-d');
947 + //$today_mysql_format = gmdate('Y-m-d', time() +86400 ); // 1 Day = 24*60*60 = 86400
897 948 $today_mysql_format = date_i18n( 'Y-m-d', time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) + DAY_IN_SECONDS ); // Tommorow day with gmt offset
898 949 foreach ( $bookings as $bc_id => $bc_value ) {
899 950 $check_in_date = $bc_value->dates_short[0];
900 951 $check_in_date = explode( ' ', $check_in_date );
@@ -906,37 +957,38 @@
906 957 }
907 958 }
908 959
909 960
910 - // If we selected the Dates as "Check Out - Tomorow", then show only the bookings, where check out date is Tomorrow
911 - if ( (isset( $args['wh_booking_date'] )) && ($args['wh_booking_date'] == '8') ) {
912 - //$tomorrow_mysql_format = date('Y-m-d', time() +86400 ); // 1 Day = 24*60*60 = 86400
913 - $tomorrow_mysql_format = date_i18n( 'Y-m-d', time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) + DAY_IN_SECONDS ); // Tommorow day with gmt offset
914 - foreach ( $bookings as $bc_id => $bc_value ) {
915 - if ( count( $bc_value->dates_short ) == 1 )
916 - $check_out_date = $bc_value->dates_short[0];
917 - else
918 - $check_out_date = $bc_value->dates_short[2];
919 - $check_out_date = explode( ' ', $check_out_date );
920 - $check_out_date = $check_out_date[0]; // 2014-02-25
921 - if ( $tomorrow_mysql_format != $check_out_date ) {
922 - unset( $bookings[$bc_id] );
923 - $bookings_count--;
924 - }
925 - }
926 - }
927 -
928 -
929 - $return_booking_structure = array(
930 - 'bookings' => $bookings
931 - , 'resources' => $booking_types
932 - , 'bookings_count' => $bookings_count
933 - , 'page_num' => $page_num
934 - , 'count_per_page' => $page_items_count
935 - );
936 -//debuge( $return_booking_structure );
961 + // If we selected the Dates as "Check Out - Tomorow", then show only the bookings, where check out date is Tomorrow .
962 + if ( ( isset( $args['wh_booking_date'] ) ) && ( 8 === intval( $args['wh_booking_date'] ) ) ) {
937 963
938 - return $return_booking_structure;
964 + $tomorrow_mysql_format = date_i18n( 'Y-m-d', time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) + DAY_IN_SECONDS ); // Tommorow day with gmt offset.
965 + foreach ( $bookings as $bc_id => $bc_value ) {
966 + if ( count( $bc_value->dates_short ) === 1 ) {
967 + $check_out_date = $bc_value->dates_short[0];
968 + } else {
969 + $check_out_date = $bc_value->dates_short[2];
970 + }
971 + $check_out_date = explode( ' ', $check_out_date );
972 + $check_out_date = $check_out_date[0]; // 2014-02-25
973 + if ( $tomorrow_mysql_format !== $check_out_date ) {
974 + unset( $bookings[ $bc_id ] );
975 + --$bookings_count;
976 + }
977 + }
978 + }
979 +
980 +
981 + $return_booking_structure = array(
982 + 'bookings' => $bookings,
983 + 'resources' => $booking_types,
984 + 'bookings_count' => $bookings_count,
985 + 'page_num' => $page_num,
986 + 'count_per_page' => $page_items_count,
987 + );
988 +
989 +
990 + return $return_booking_structure;
939 991 }
940 992
941 993
942 994 ////////////////////////////////////////////////////////////////////////////////
@@ -969,10 +1021,10 @@
969 1021 , 'wh_cost' => ''
970 1022 , 'wh_cost2' => ''
971 1023 , 'or_sort' => ''
972 1024 , 'page_num' => '1'
973 - , 'wh_trash' => '' //FixIn: 6.1.1.10
974 - , 'wh_sync_gid' => '' // '' | 'imported' | 'plugin' //FixIn: 8.8.3.19
1025 + , 'wh_trash' => '' // FixIn: 6.1.1.10.
1026 + , 'wh_sync_gid' => '' // '' | 'imported' | 'plugin' // FixIn: 8.8.3.19.
975 1027 , 'page_items_count' => $num_per_page_check
976 1028 );
977 1029 $r = wp_parse_args( $args, $defaults );
978 1030 extract( $r, EXTR_SKIP );
@@ -1010,9 +1062,9 @@
1010 1062 SELECT *
1011 1063 FROM {$wpdb->prefix}bookingdates as dt
1012 1064 WHERE bk.booking_id = dt.booking_id ";
1013 1065
1014 - if ( 'lost' == $wh_booking_type ) { //FixIn: 8.5.2.19
1066 + if ( 'lost' == $wh_booking_type ) { // FixIn: 8.5.2.19.
1015 1067
1016 1068 $sql_where.= " AND bk.booking_type NOT IN ( SELECT DISTINCT booking_type_id FROM {$wpdb->prefix}bookingtypes ) ";
1017 1069 $sql_where.= " ) ";
1018 1070 $wh_booking_type = '';
@@ -1025,11 +1077,11 @@
1025 1077 $sql_where .= wpbc_set_sql_where_for_dates( $wh_booking_date, $wh_booking_date2 );
1026 1078
1027 1079 $sql_where.= " ) ";
1028 1080
1029 - $sql_where .= " {$trash_bookings} "; //FixIn: 6.1.1.10
1081 + $sql_where .= " {$trash_bookings} "; // FixIn: 6.1.1.10.
1030 1082
1031 - //FixIn: 8.8.3.19
1083 + // FixIn: 8.8.3.19.
1032 1084 if ( 'imported' === $wh_sync_gid ) {
1033 1085 $sql_where .= " AND bk.sync_gid != '' ";
1034 1086 }
1035 1087 if ( 'plugin' === $wh_sync_gid ) {
@@ -1050,9 +1102,9 @@
1050 1102 }
1051 1103
1052 1104 } else {
1053 1105
1054 - //FixIn: 8.7.7.10
1106 + // FixIn: 8.7.7.10.
1055 1107 if ( strpos( $wh_booking_id, '<' ) !== false ) {
1056 1108 $wh_booking_id = str_replace( '<', '', $wh_booking_id );
1057 1109 $wh_booking_id = intval( $wh_booking_id );
1058 1110 $sql_where = " WHERE bk.booking_id < " . $wh_booking_id . " ";
@@ -1064,15 +1116,20 @@
1064 1116 $sql_where = " WHERE bk.booking_id > " . $wh_booking_id . " ";
1065 1117
1066 1118 }
1067 1119
1068 - else if ( strpos( $wh_booking_id, ',' ) !== false ) {
1069 - $sql_where = " WHERE bk.booking_id IN (" . $wh_booking_id . ") ";
1120 + else if ( strpos( $wh_booking_id, ',' ) !== false ) {
1121 + $booking_ids = array_filter( array_map( 'absint', explode( ',', $wh_booking_id ) ) );
1122 + $booking_ids = array_values( array_unique( $booking_ids ) );
1123 + $sql_where = empty( $booking_ids )
1124 + ? ' WHERE bk.booking_id = -1 '
1125 + : ' WHERE bk.booking_id IN (' . implode( ',', $booking_ids ) . ') ';
1126 +
1127 + } else {
1128 + $booking_id = ( '-1' === (string) $wh_booking_id ) ? -1 : absint( $wh_booking_id );
1129 + $sql_where = ' WHERE bk.booking_id = ' . $booking_id . ' ';
1130 + }
1070 1131
1071 - } else {
1072 - $sql_where = " WHERE bk.booking_id = " . $wh_booking_id . " ";
1073 - }
1074 -
1075 1132 // Check if searching booking is belonging to specific user in Booking Calendar MultiUser version
1076 1133 $sql_where = apply_bk_filter('update_where_sql_for_getting_bookings_in_multiuser', $sql_where );
1077 1134
1078 1135 }
@@ -1119,44 +1176,42 @@
1119 1176 else { $and_pre = ''; $and_suf = ' AND '; }
1120 1177
1121 1178 // Actual
1122 1179 if ( ( ( $wh_booking_date === '' ) && ( $wh_booking_date2 === '' ) ) || ($wh_booking_date === '0') ) {
1123 - $sql_where = $and_pre."( ".$pref."booking_date >= ( CURDATE() - INTERVAL '00:00:01' HOUR_SECOND ) ) ".$and_suf ; //FixIn: 8.5.2.14
1180 + $sql_where = $and_pre."( ".$pref."booking_date >= (" . wpbc_sql_date_math_expr_explicit( "- INTERVAL '00:00:01' HOUR_SECOND", 'curdate' ) . ") ) ".$and_suf ; // FixIn: 8.5.2.14.
1124 1181
1125 - } else if ($wh_booking_date === '1') { // Today //FixIn: 7.1.2.8
1126 - $sql_where = $and_pre."( ".$pref."booking_date <= ( CURDATE() + INTERVAL '23:59:59' HOUR_SECOND ) ) ".$and_suf ;
1127 - $sql_where .= $and_pre."( ".$pref."booking_date >= ( CURDATE() - INTERVAL '00:00:01' HOUR_SECOND ) ) ".$and_suf ; //FixIn: 8.4.7.21
1182 + } else if ($wh_booking_date === '1') { // Today // FixIn: 7.1.2.8.
1183 + $sql_where = $and_pre."( ".$pref."booking_date <= (" . wpbc_sql_date_math_expr_explicit( "+ INTERVAL '23:59:59' HOUR_SECOND", 'curdate' ) . ") ) ".$and_suf ;
1184 + $sql_where .= $and_pre."( ".$pref."booking_date >= (" . wpbc_sql_date_math_expr_explicit( "- INTERVAL '00:00:01' HOUR_SECOND", 'curdate' ) . ") ) ".$and_suf ; // FixIn: 8.4.7.21.
1128 1185
1129 1186
1130 1187 } else if ($wh_booking_date === '2') { // Previous
1131 - $sql_where = $and_pre."( ".$pref."booking_date <= ( CURDATE() - INTERVAL '00:00:01' HOUR_SECOND ) ) ".$and_suf ; //FixIn: 8.5.2.16
1188 + $sql_where = $and_pre."( ".$pref."booking_date <= (" . wpbc_sql_date_math_expr_explicit( "- INTERVAL '00:00:01' HOUR_SECOND", 'curdate' ) . ") ) ".$and_suf ; // FixIn: 8.5.2.16.
1132 1189
1133 1190 } else if ($wh_booking_date === '3') { // All
1134 1191 $sql_where = '';
1135 1192
1136 1193 } else if ($wh_booking_date === '4') { // Next
1137 - $sql_where = $and_pre."( ".$pref."booking_date <= ( CURDATE() + INTERVAL ". $wh_booking_date2 . " DAY ) ) ".$and_suf ;
1138 - // $sql_where .= $and_pre."( ".$pref."booking_date >= ( CURDATE() - INTERVAL 1 DAY ) ) ".$and_suf ;
1139 - $sql_where .= $and_pre."( ".$pref."booking_date > ( CURDATE() ) ) ".$and_suf ; //FixIn: 8.0.1.1
1194 + $sql_where = $and_pre."( ".$pref."booking_date <= (" . wpbc_sql_date_math_expr_explicit( "+ INTERVAL ". $wh_booking_date2 . " DAY", 'curdate' ) . ") ) ".$and_suf ;
1195 + // $sql_where .= $and_pre."( ".$pref."booking_date >= (" . wpbc_sql_date_math_expr_explicit( "- INTERVAL 1 DAY", 'curdate' ) . ") ) ".$and_suf ;
1196 + $sql_where .= $and_pre."( ".$pref."booking_date > ( " . wpbc_sql_date_math_expr_explicit('', 'curdate') . " ) ) ".$and_suf ; // FixIn: 8.0.1.1.
1140 1197
1141 1198 } else if ($wh_booking_date === '5') { // Prior
1142 1199 $wh_booking_date2 = str_replace('-', '', $wh_booking_date2);
1143 - $sql_where = $and_pre."( ".$pref."booking_date >= ( CURDATE() - INTERVAL ". $wh_booking_date2 . " DAY ) ) ".$and_suf ;
1144 - $sql_where .= $and_pre."( ".$pref."booking_date <= ( CURDATE() + INTERVAL 1 DAY ) ) ".$and_suf ;
1200 + $sql_where = $and_pre."( ".$pref."booking_date >= (" . wpbc_sql_date_math_expr_explicit( "- INTERVAL ". $wh_booking_date2 . " DAY", 'curdate' ) . ") ) ".$and_suf ;
1201 + $sql_where .= $and_pre."( ".$pref."booking_date <= (" . wpbc_sql_date_math_expr_explicit( "+ INTERVAL 1 DAY", 'curdate' ) . ") ) ".$and_suf ;
1145 1202
1146 1203 } else if ($wh_booking_date === '7') { // Check In date - Today/Tomorrow
1147 - // $sql_where = $and_pre."( ".$pref."booking_date <= ( CURDATE() + INTERVAL '23:59:59' HOUR_SECOND ) ) ".$and_suf ;
1148 - // $sql_where .= $and_pre."( ".$pref."booking_date >= ( CURDATE() ) ) ".$and_suf ;
1149 - $sql_where = $and_pre."( ".$pref."booking_date <= ( CURDATE() + INTERVAL '1 23:59:59' DAY_SECOND ) ) ".$and_suf ;
1150 - $sql_where .= $and_pre."( ".$pref."booking_date >= ( CURDATE() + INTERVAL 1 DAY ) ) ".$and_suf ;
1204 + $sql_where = $and_pre."( ".$pref."booking_date <= ( " . wpbc_sql_date_math_expr_explicit( "+ INTERVAL '47:59:59' HOUR_SECOND", 'curdate' ) . " ) ) ".$and_suf ;
1205 + $sql_where .= $and_pre."( ".$pref."booking_date >= (" . wpbc_sql_date_math_expr_explicit( "+ INTERVAL 1 DAY", 'curdate' ) . ") ) ".$and_suf ;
1151 1206
1152 1207 } else if ($wh_booking_date === '8') { // Check Out date - Tomorrow
1153 - $sql_where = $and_pre."( ".$pref."booking_date <= ( CURDATE() + INTERVAL '1 23:59:59' DAY_SECOND ) ) ".$and_suf ;
1154 - $sql_where .= $and_pre."( ".$pref."booking_date >= ( CURDATE() + INTERVAL 1 DAY ) ) ".$and_suf ;
1208 + $sql_where = $and_pre."( ".$pref."booking_date <= ( " . wpbc_sql_date_math_expr_explicit( "+ INTERVAL '47:59:59' HOUR_SECOND", 'curdate' ) . " ) ) ".$and_suf ;
1209 + $sql_where .= $and_pre."( ".$pref."booking_date >= (" . wpbc_sql_date_math_expr_explicit( "+ INTERVAL 1 DAY", 'curdate' ) . ") ) ".$and_suf ;
1155 1210
1156 1211 } else if ($wh_booking_date === '9') { // Today check in/out
1157 - $sql_where = $and_pre."( ".$pref."booking_date <= ( CURDATE() + INTERVAL 1 DAY ) ) ".$and_suf ;
1158 - $sql_where .= $and_pre."( ".$pref."booking_date >= ( CURDATE() - INTERVAL 1 DAY ) ) ".$and_suf ;
1212 + $sql_where = $and_pre."( ".$pref."booking_date <= (" . wpbc_sql_date_math_expr_explicit( "+ INTERVAL 1 DAY", 'curdate' ) . ") ) ".$and_suf ;
1213 + $sql_where .= $and_pre."( ".$pref."booking_date >= (" . wpbc_sql_date_math_expr_explicit( "- INTERVAL 1 DAY", 'curdate' ) . ") ) ".$and_suf ;
1159 1214
1160 1215 } else { // Fixed
1161 1216
1162 1217 if ( $wh_booking_date !== '' )
@@ -1189,10 +1244,10 @@
1189 1244 if ($pref == 'bk.') { $and_pre = ' AND '; $and_suf = ''; }
1190 1245 else { $and_pre = ''; $and_suf = ' AND '; }
1191 1246
1192 1247 if ($wh_modification_date === '1') { // Today
1193 - $sql_where = $and_pre."( ".$pref."modification_date <= ( CURDATE() + INTERVAL '23:59:59' HOUR_SECOND ) ) ".$and_suf ; //FixIn: 8.4.7.22
1194 - $sql_where .= $and_pre."( ".$pref."modification_date >= ( CURDATE() - INTERVAL '00:00:01' HOUR_SECOND ) ) ".$and_suf ; //FixIn: 8.4.7.22
1248 + $sql_where = $and_pre."( ".$pref."modification_date <= (" . wpbc_sql_date_math_expr_explicit( "+ INTERVAL '23:59:59' HOUR_SECOND", 'curdate' ) . ") ) ".$and_suf ; // FixIn: 8.4.7.22.
1249 + $sql_where .= $and_pre."( ".$pref."modification_date >= (" . wpbc_sql_date_math_expr_explicit( "- INTERVAL '00:00:01' HOUR_SECOND", 'curdate' ) . ") ) ".$and_suf ; // FixIn: 8.4.7.22.
1195 1250
1196 1251 } else if ($wh_modification_date === '3') { // All
1197 1252 $sql_where = '';
1198 1253
@@ -1197,10 +1252,10 @@
1197 1252 $sql_where = '';
1198 1253
1199 1254 } else if ($wh_modification_date === '5') { // Prior
1200 1255 $wh_modification_date2 = str_replace('-', '', $wh_modification_date2);
1201 - $sql_where = $and_pre."( ".$pref."modification_date >= ( CURDATE() - INTERVAL ". $wh_modification_date2 . " DAY ) ) ".$and_suf ;
1202 - $sql_where .= $and_pre."( ".$pref."modification_date <= ( CURDATE() + INTERVAL 1 DAY ) ) ".$and_suf ;
1256 + $sql_where = $and_pre."( ".$pref."modification_date >= (" . wpbc_sql_date_math_expr_explicit( "- INTERVAL ". $wh_modification_date2 . " DAY", 'curdate' ) . ") ) ".$and_suf ;
1257 + $sql_where .= $and_pre."( ".$pref."modification_date <= (" . wpbc_sql_date_math_expr_explicit( "+ INTERVAL 1 DAY", 'curdate' ) . ") ) ".$and_suf ;
1203 1258
1204 1259 } else { // Fixed
1205 1260
1206 1261 if ( $wh_modification_date !== '' )
@@ -1210,5 +1265,182 @@
1210 1265 $sql_where.= $and_pre."( ".$pref."modification_date <= '" . $wh_modification_date2 . "' ) ".$and_suf;
1211 1266 }
1212 1267
1213 1268 return $sql_where;
1269 +}
1270 +
1271 +
1272 +/**
1273 + * Generate SQL-compatible datetime/date expression based on explicit base function and optional interval.
1274 + *
1275 + * @param string $mysql_expr - MySQL-style interval expression. Examples: "- INTERVAL '00:00:01' HOUR_SECOND", "+ INTERVAL 5 DAY", etc.
1276 + * @param string $base_func - 'curdate'|'now' Either 'curdate' (default) for CURDATE() / date('now'), or 'now' for NOW() / datetime('now').
1277 + *
1278 + * @return string SQL expression (unquoted), adapted for MySQL or SQLite.
1279 + *
1280 + * Exmaples:
1281 + * wpbc_sql_date_math_expr_explicit("- INTERVAL '00:00:01' HOUR_SECOND", 'curdate') | MySQL: CURDATE() - INTERVAL '00:00:01' HOUR_SECOND # SQLite: datetime('now', '-1 seconds') (auto-upgraded)
1282 + * wpbc_sql_date_math_expr_explicit("+ INTERVAL 2 DAY", 'curdate') | MySQL: CURDATE() + INTERVAL 2 DAY # SQLite: date('now', '+2 days')
1283 + * wpbc_sql_date_math_expr_explicit('', 'now'); | MySQL: NOW() # SQLite: datetime('now') |.
1284 + * wpbc_sql_date_math_expr_explicit(); | MySQL: CURDATE() # SQLite: date('now')
1285 + * wpbc_sql_date_math_expr_explicit("+ INTERVAL 30 MINUTE", 'curdate') | MySQL: CURDATE() + INTERVAL 30 MINUTE # SQLite: datetime('now', '+1800 seconds') (auto-upgraded)
1286 + */
1287 +function wpbc_sql_date_math_expr_explicit( $mysql_expr = '', $base_func = 'curdate' ) {
1288 + global $wpdb;
1289 +
1290 + $is_sqlite = ( get_class( $wpdb ) === 'WP_SQLite_DB' );
1291 + $original_base_func = strtolower( $base_func );
1292 + $base_func = $original_base_func;
1293 +
1294 + // Fallback if invalid.
1295 + if ( ! in_array( $base_func, array( 'curdate', 'now' ), true ) ) {
1296 + $base_func = 'curdate';
1297 + }
1298 +
1299 + // Promote to datetime() if base is 'curdate' and delta is time-based.
1300 + $has_time_delta = ( false !== stripos( $mysql_expr, 'HOUR' ) ||
1301 + false !== stripos( $mysql_expr, 'MINUTE' ) ||
1302 + false !== stripos( $mysql_expr, 'SECOND' ) ||
1303 + false !== strpos( $mysql_expr, ':' ) );
1304 +
1305 + if ( $is_sqlite && 'curdate' === $base_func && $has_time_delta ) {
1306 + $base_func = 'now'; // auto-promote for SQLite.
1307 + }
1308 +
1309 + $mysql_base_func = ( 'curdate' === $base_func ) ? 'CURDATE()' : 'NOW()';
1310 + $sqlite_base_func = ( 'curdate' === $base_func ) ? 'date' : 'datetime';
1311 +
1312 + if ( empty( $mysql_expr ) ) {
1313 + return $is_sqlite ? "{$sqlite_base_func}('now')" : $mysql_base_func;
1314 + }
1315 +
1316 + if ( ! $is_sqlite ) {
1317 + return "{$mysql_base_func} {$mysql_expr}";
1318 + }
1319 +
1320 + $modifiers = wpbc__convert_mysql_interval_to_sqlite_modifiers( $mysql_expr );
1321 +
1322 + // Fix: anchor to midnight if original func was 'curdate' with time math.
1323 + if ( 'curdate' === $original_base_func && $has_time_delta ) {
1324 + return "datetime('now','start of day'{$modifiers})";
1325 + }
1326 +
1327 + return "{$sqlite_base_func}('now'{$modifiers})";
1328 +}
1329 +
1330 +
1331 +
1332 +/**
1333 + * Convert MySQL-style interval expression to SQLite-compatible modifier(s)
1334 + *
1335 + * @param string $expr - expression.
1336 + *
1337 + * @return string
1338 + *
1339 + * Supports:
1340 + * - INTERVAL 5 DAY
1341 + * - INTERVAL '00:00:01' HOUR_SECOND
1342 + * - Multiple modifiers if needed (returns ', '+X unit', '+Y unit'...')
1343 + */
1344 +function wpbc__convert_mysql_interval_to_sqlite_modifiers( $expr ) {
1345 +
1346 + $expr = trim( $expr );
1347 +
1348 + if ( preg_match( '/([+-])?\s*INTERVAL\s+(\'?)([^\'\s]+)\2\s+([A-Z_]+)/i', $expr, $m ) ) {
1349 + $sign = ( '-' === $m[1] ) ? '-' : '+';
1350 + $value = $m[3];
1351 + $type = strtoupper( $m[4] );
1352 +
1353 + switch ( $type ) {
1354 + case 'DAY':
1355 + return ", '{$sign}{$value} days'";
1356 +
1357 + case 'HOUR_SECOND':
1358 + case 'SECOND':
1359 + $seconds = 0;
1360 + if ( strpos( $value, ':' ) !== false ) {
1361 + $parts = array_map( 'intval', explode( ':', $value ) );
1362 + if ( count( $parts ) === 3 ) {
1363 + $seconds = $parts[0] * 3600 + $parts[1] * 60 + $parts[2];
1364 + } elseif ( count( $parts ) === 2 ) {
1365 + $seconds = $parts[0] * 60 + $parts[1];
1366 + }
1367 + } else {
1368 + $seconds = intval( $value );
1369 + }
1370 +
1371 + return ", '{$sign}{$seconds} seconds'";
1372 +
1373 + default:
1374 + return ", '{$sign}{$value} " . strtolower( $type ) . "'";
1375 + }
1376 + }
1377 +
1378 + return '';
1379 +}
1380 +
1381 +// FixIn: 10.14.9.1.
1382 +/**
1383 + * Sanitize and validate "dates_to_check" parameter.
1384 + *
1385 + * Accepts scalar or array, normalizes to array of 'Y-m-d' strings
1386 + * that match /^\d{4}-\d{2}-\d{2}$/.
1387 + *
1388 + * @param mixed $dates_to_check Raw dates_to_check parameter.
1389 + *
1390 + * @return array Sanitized, validated dates.
1391 + */
1392 +function wpbc_sanitize_dates_to_check( $dates_to_check ) {
1393 +
1394 + if ( ! is_array( $dates_to_check ) ) {
1395 + $dates_to_check = array( $dates_to_check );
1396 + }
1397 +
1398 + $sanitized_dates = array();
1399 +
1400 + foreach ( $dates_to_check as $maybe_date ) {
1401 +
1402 + // Basic text cleanup.
1403 + $maybe_date = sanitize_text_field( $maybe_date );
1404 +
1405 + // Strict format: YYYY-MM-DD only.
1406 + if ( preg_match( '/^\d{4}-\d{2}-\d{2}$/', $maybe_date ) ) {
1407 + $sanitized_dates[] = $maybe_date;
1408 + }
1409 + }
1410 +
1411 + return $sanitized_dates;
1412 +}
1413 +
1414 +
1415 +// FixIn: 10.14.17.1.
1416 +/**
1417 + * Sanitize and validate dates and times parameter.
1418 + *
1419 + * Accepts scalar or array, normalizes to array of 'Y-m-d H:i:s' strings
1420 + * that match /^\d{4}-\d{2}-\d{2}$/.
1421 + *
1422 + * @param mixed $dates_to_check Raw dates_to_check parameter.
1423 + *
1424 + * @return array Sanitized, validated dates.
1425 + */
1426 +function wpbc_sanitize_date_ymdhis_to_check( $dates_to_check ) {
1427 +
1428 + if ( ! is_array( $dates_to_check ) ) {
1429 + $dates_to_check = array( $dates_to_check );
1430 + }
1431 +
1432 + $sanitized_dates = array();
1433 +
1434 + foreach ( $dates_to_check as $maybe_date ) {
1435 +
1436 + // Basic text cleanup.
1437 + $maybe_date = sanitize_text_field( $maybe_date );
1438 +
1439 + // Strict format: YYYY-MM-DD only.
1440 + if ( preg_match( '/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/', $maybe_date ) ) {
1441 + $sanitized_dates[] = $maybe_date;
1442 + }
1443 + }
1444 +
1445 + return $sanitized_dates;
1214 1446 }