PluginProbe
Booking Calendar / 10.10
Booking Calendar v10.10
11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 10.11.2 10.11.3 All 202 releases
booking / core / admin / wpbc-sql.php

wpbc-sql.php in Booking Calendar 10.10, at core/admin/wpbc-sql.php

1,268 lines 67.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php /**
2 * @version 1.0
3 * @package Booking Calendar
4 * @category Data Engine for Booking Listing / Calendar Overview pages
5 * @author wpdevelop
6 *
7 * @web-site https://wpbookingcalendar.com/
8 * @email info@wpbookingcalendar.com
9 *
10 * @modified 2015-12-08
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) exit; // Exit, if accessed directly
14
15
16 /** Trick here to overload default REQUST parameters before page is loading */
17 function wpbc_define_listing_page_parameters( $page_tag ) {
18
19 // $page_tag - here can be all defined in plugin menu pages
20 // So we need to check activated page. By default its inside of $_GET['page'],
21
22 // Execute it only for Booking Listing & Timeline admin pages.
23 //if ( ( isset( $_GET[ 'page' ] ) ) && ( $_GET[ 'page' ] == 'wpbc' ) ) {
24
25 if ( wpbc_is_bookings_page() ) { // We are inside of this page. Menu item selected.
26
27 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
28 if ( ( isset( $_REQUEST['view_mode'] ) ) && ( 'vm_booking_listing' === $_REQUEST['view_mode'] ) ) { //FixIn: 9.2.0
29 return;
30 }
31
32 $booking_default_view_mode = wpbc_get_default_saved_view_mode_for_wpbc_page();
33 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
34 if ( ! isset( $_REQUEST['view_mode'] ) ) {
35 $_REQUEST['view_mode'] = $booking_default_view_mode; // Set to REQUEST
36 }
37
38 // Get saved filters set, (if its not set in request yet), like "tab" & "view_mode" and overload $_REQUEST
39 wpbc_set_default_saved_params_to_request_for_booking_listing( 'default' );
40 }
41 }
42 // We are set 9 to execute earlier than hook in WPBC_Admin_Menus
43 add_action('wpbc_define_nav_tabs', 'wpbc_define_listing_page_parameters', 1 ); // This Hook fire in the class WPBC_Admin_Menus for showing page content of specific menu
44
45 ////////////////////////////////////////////////////////////////////////////////
46 // R e q u e s t S u p p o r t
47 ////////////////////////////////////////////////////////////////////////////////
48
49 /**
50 * Get here default View mode saved in a General Booking Settings page or From REQUEST view_mode
51 *
52 * @return string = 'vm_calendar' | 'vm_booking_listing'
53 */
54 function wpbc_get_default_saved_view_mode_for_wpbc_page() {
55
56 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
57 if ( ! isset( $_REQUEST['view_mode'] ) ) {
58 $booking_default_view_mode = get_bk_option( 'booking_listing_default_view_mode' );
59 } else {
60 $booking_default_view_mode = sanitize_text_field( wp_unslash( $_REQUEST['view_mode'] ) ); /* phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing */ /* FixIn: sanitize_unslash */
61 }
62 //$booking_default_view_mode='vm_listing'; //TODO:2023-05-20 remove it!!!!!!
63 if ( ! in_array( $booking_default_view_mode, array( 'vm_calendar', 'vm_booking_listing' ) ) ) { //FixIn: 9.2.1 // FixIn: 9.6.3.5.
64 $booking_default_view_mode = 'vm_booking_listing';
65 }
66
67 $booking_default_view_mode = ( 'vm_listing' == $booking_default_view_mode ) ? 'vm_booking_listing' : $booking_default_view_mode; // FixIn: 9.6.3.5.
68
69 return $booking_default_view_mode; // 'vm_calendar' / 'vm_booking_listing' ;
70 }
71
72
73 /**
74 * Get from SETTINGS (if its not set in request yet) the "tab" & "view_mode" and set to $_REQUEST
75 If we have the "saved" filter set so LOAD it and set to REQUEST, if REQUEST was not set previously
76 & skip "wh_booking_type" from the saved filter set
77 *
78 * @param string $filter_name - name of saved filter set. Currntly is using only one "Default"
79 */
80 function wpbc_set_default_saved_params_to_request_for_booking_listing( $filter_name ) {
81 //debuge($_REQUEST);
82 // Exclude some parameters from the saved Default parameters - the values of these parameters are loading from General Booking Settings page or from the request.
83 $exclude_options_from_saved_params = array(
84 'tab' // Default
85 , 'page' // From plugin
86 , 'view_mode' // Default
87 , 'wh_booking_type' // Default
88 , 'view_days_num' // Default
89 , 'blank_field__this_field_only_for_formatting_buttons' // Skip this, this parameter for formating purpose in toolbar
90 );
91 $wpdevbk_filter_params = array();
92
93
94 // Get here default View mode saved in a General Booking Settings page
95 $booking_default_view_mode = wpbc_get_default_saved_view_mode_for_wpbc_page();
96 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
97 if ( !isset( $_REQUEST['view_mode'] ) )
98 $wpdevbk_filter_params['view_mode'] = $booking_default_view_mode; // 'vm_calendar' / 'vm_booking_listing' ;
99 $_REQUEST['view_mode'] = $booking_default_view_mode; // Set to REQUEST
100
101 // if ( !isset( $_REQUEST['view_mode'] ) ) {
102 // $booking_default_view_mode = get_bk_option( 'booking_listing_default_view_mode' );
103 // if ( $booking_default_view_mode !== false ) {
104 // $wpdevbk_filter_params['view_mode'] = $booking_default_view_mode; // 'vm_calendar' / 'vm_booking_listing' ;
105 // $_REQUEST['view_mode'] = $booking_default_view_mode; // Set to REQUEST
106 // } else
107 // $_REQUEST['view_mode'] = 'vm_booking_listing';
108 // }
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 ( $booking_view_days_num !== false ) {
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
121
122 }
123
124
125
126 /**
127 * Clean Request Parameters
128 *
129 */
130 function wpbc_check_request_paramters() { // FixIn: 6.2.1.4.
131
132 //debuge($_REQUEST);
133 $clean_params = array();
134
135 $clean_params['wh_booking_id'] = 'digit_or_csd';
136 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
137 if ( ( ! empty( $_REQUEST['wh_booking_type'] ) ) && ( 'lost' == $_REQUEST['wh_booking_type'] ) ) { // FixIn: 8.5.2.19.
138 $clean_params['wh_booking_type'] = 'checked_skip_it';
139 } else {
140 $clean_params['wh_booking_type'] = 'digit_or_csd';
141 }
142 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
143 if ( ( ! empty( $_REQUEST['booking_type'] ) ) && ( 'lost' == $_REQUEST['booking_type'] ) ) { // FixIn: 8.9.2.1.
144 $clean_params['booking_type'] = 'checked_skip_it';
145 } else {
146 $clean_params['booking_type'] = 'digit_or_csd';
147 }
148
149 $clean_params['wh_approved'] = 'digit_or_csd'; // '0' | '1' | ''
150
151 $clean_params['wh_booking_date'] = 'digit_or_date'; // number | date 2016-07-20
152 $clean_params['wh_booking_date2'] = 'digit_or_date'; // number | date 2016-07-20
153 $clean_params['wh_booking_datenext'] = 'd'; // '1' | '2' ....
154 $clean_params['wh_booking_dateprior'] = 'd'; // '1' | '2' ....
155 $clean_params['wh_booking_datefixeddates'] = 'digit_or_date'; // number | date 2016-07-20
156 $clean_params['wh_booking_date2fixeddates'] = 'digit_or_date'; // number | date 2016-07-20
157
158 $clean_params['wh_is_new'] = 'd'; // '1' | ''
159
160 $clean_params['wh_modification_date'] = 'digit_or_date'; // number | date 2016-07-20
161 $clean_params['wh_modification_date2'] = 'digit_or_date'; // number | date 2016-07-20
162 $clean_params['wh_modification_dateprior'] = 'd'; // '1' | '2' ....
163 $clean_params['wh_modification_datefixeddates'] = 'digit_or_date'; // number | date 2016-07-20
164 $clean_params['wh_modification_date2fixeddates']= 'digit_or_date'; // number | date 2016-07-20
165
166 $clean_params['wh_keyword'] = 's'; //string
167
168 $clean_params['wh_pay_statuscustom'] = 's'; //string !!! LIKE !!!
169 $clean_params['wh_pay_status'] = array('all', 'group_ok', 'group_unknown', 'group_pending', 'group_failed');
170
171 $clean_params['wh_cost'] = 'd'; // '1' | ''
172 $clean_params['wh_cost2'] = 'd'; // '1' | ''
173
174 $clean_params['or_sort'] = array('', 'sort_date', 'booking_type', 'cost', 'booking_id_asc', 'sort_date_asc', 'booking_type_asc', 'cost_asc');
175 $clean_params['wh_trash'] = array('0' , 'trash', 'any');
176
177
178 $clean_params['page_num'] = 'd'; // '' | '1' ... // does not exist in 6.2.1.4
179 $clean_params['page_items_count'] = 'd'; // '' | '1' ... // does not exist in 6.2.1.4
180 $clean_params['view_days_num'] = 'd'; // '' | '1' ... // does not exist in 6.2.1.4
181
182 // FixIn: 8.9.2.1.
183 $clean_params['scroll_start_date'] = 'digit_or_date';
184 $clean_params['scroll_day'] = 'd';
185 $clean_params['scroll_month'] = 'd';
186 $clean_params['limit_hours'] = 'digit_or_csd';
187 $clean_params['only_booked_resources'] = 'd';
188
189
190 foreach ( $clean_params as $request_key => $clean_type ) {
191
192 // elements only listed in array::
193 if ( is_array( $clean_type ) ) { // check only values from the list in this array
194
195 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
196 if ( ( isset( $_REQUEST[ $request_key ] ) ) && ( ! in_array( $_REQUEST[ $request_key ], $clean_type ) ) )
197 $clean_type = 's';
198 else
199 $clean_type = 'checked_skip_it';
200 }
201
202 switch ( $clean_type ) {
203
204 case 'checked_skip_it':
205
206 break;
207
208 case 'digit_or_date': // digit or comma separated digit
209 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
210 if ( isset( $_REQUEST[ $request_key ] ) ) {
211 $_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
212 }
213 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
214 if ( isset( $_GET[ $request_key ] ) ) {
215 $_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
216 }
217 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
218 if ( isset( $_POST[ $request_key ] ) ) {
219 $_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
220 }
221
222 break;
223
224 case 'digit_or_csd': // digit or comma separated digit
225 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
226 if ( isset( $_REQUEST[ $request_key ] ) ) {
227 $_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
228 }
229 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
230 if ( isset( $_GET[ $request_key ] ) ) {
231 $_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
232 }
233 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
234 if ( isset( $_POST[ $request_key ] ) ) {
235 $_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
236 }
237
238 break;
239
240 case 's': // string
241 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
242 if ( isset( $_REQUEST[ $request_key ] ) ) {
243 $_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
244 }
245 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
246 if ( isset( $_GET[ $request_key ] ) ) {
247 $_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
248 }
249 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
250 if ( isset( $_POST[ $request_key ] ) ) {
251 $_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
252 }
253
254 break;
255
256 case 'd': // digit
257 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
258 if ( ( isset( $_REQUEST[ $request_key ] ) ) && ( $_REQUEST[ $request_key ] !== '' ) ) {
259 $_REQUEST[ $request_key ] = intval( $_REQUEST[ $request_key ] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
260 }
261 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
262 if ( ( isset( $_GET[ $request_key ] ) ) && ( $_GET[ $request_key ] !== '' ) ) {
263 $_GET[ $request_key ] = intval( $_GET[ $request_key ] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
264 }
265 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
266 if ( ( isset( $_POST[ $request_key ] ) ) && ( $_POST[ $request_key ] !== '' ) ) {
267 $_POST[ $request_key ] = intval( $_POST[ $request_key ] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
268 }
269
270 break;
271
272 default:
273 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
274 if ( isset( $_REQUEST[ $request_key ] ) ) {
275 $_REQUEST[ $request_key ] = intval( $_REQUEST[ $request_key ] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
276 }
277 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
278 if ( isset( $_GET[ $request_key ] ) ) {
279 $_GET[ $request_key ] = intval( $_GET[ $request_key ] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
280 }
281 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
282 if ( isset( $_POST[ $request_key ] ) ) {
283 $_POST[ $request_key ] = intval( $_POST[ $request_key ] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
284 }
285 break;
286 }
287
288
289 }
290
291 //debuge($_REQUEST);
292 }
293
294
295 // FixIn: 9.6.3.5.
296
297 /**
298 * Get array of cleaned (limited number) paramas from REQUEST
299 *
300 * @return array
301 */
302 function wpbc_get_clean_paramas_from_request_for_timeline() {
303
304
305 // Reset
306 $start_year = gmdate("Y"); //2012
307 $start_month = gmdate("m"); //09
308 $start_day = 1;//date("d");//1; //31
309 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
310 if (! empty($_REQUEST['scroll_start_date'])) { // scroll_start_date=2013-07-01
311 $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
312
313 $start_year = $scroll_start_date[0]; //2012
314 $start_month = $scroll_start_date[1]; //09
315 $start_day = $scroll_start_date[2]; //date("d");//1; //31
316 }
317
318 $scroll_day = 0;
319 $scroll_month = 0;
320
321 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
322 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 */
323 else $view_days_num = get_bk_option( 'booking_view_days_num');
324
325 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
326 if ((isset($_REQUEST['wh_booking_type'])) && ( strpos($_REQUEST['wh_booking_type'], ',') !== false ) )
327 $is_show_resources_matrix = true;
328 else $is_show_resources_matrix = false;
329
330 if ($is_show_resources_matrix) {
331
332 switch ($view_days_num) {
333
334 case '1':
335 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
336 if (empty($_REQUEST['scroll_start_date'])) $start_day = gmdate("d");
337 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
338 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 */
339
340 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) + intval( $scroll_day ) ), intval( $start_year ) );
341 $wh_booking_date = gmdate("Y-m-d", $real_date); // '2012-11-29';
342
343 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) + intval( $scroll_day ) ), intval( $start_year ) );
344 $wh_booking_date2 = gmdate("Y-m-d", $real_date); // '2013-12-3';
345 break;
346
347 case '7':
348 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
349 if (empty($_REQUEST['scroll_start_date'])) $start_day = gmdate("d");
350 $start_week_day_num = gmdate("w");
351 $start_day_weeek = esc_js(get_bk_option( 'booking_start_day_weeek' )); //[0]:Sun .. [6]:Sut
352 if ($start_week_day_num != $start_day_weeek) {
353 for ($d_inc = 1; $d_inc < 8; $d_inc++) { // Just get week back
354 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) - intval( $d_inc ) ), intval( $start_year ) );
355 $start_week_day_num = gmdate("w", $real_date);
356 if ($start_week_day_num == $start_day_weeek) {
357 $start_day = gmdate("d", $real_date);
358 $start_year = gmdate("Y", $real_date);
359 $start_month = gmdate("m", $real_date);
360 $d_inc=9;
361 }
362 }
363 }
364
365 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
366 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 */
367
368 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) + intval( $scroll_day ) ), intval( $start_year ) );
369 $wh_booking_date = gmdate("Y-m-d", $real_date); // '2012-12-01';
370
371 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) + 7 + intval( $scroll_day ) ), intval( $start_year ) );
372 $wh_booking_date2 = gmdate("Y-m-d", $real_date); // '2012-12-7';
373 break;
374
375 case '30':
376 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
377 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 */
378
379 $real_date = mktime( 0, 0, 0, ( intval( $start_month ) + intval( $scroll_month ) ), intval( $start_day ), intval( $start_year ) );
380 $wh_booking_date = gmdate("Y-m-d", $real_date); // '2012-12-01';
381
382 $real_date = mktime( 0, 0, 0, ( intval( $start_month ) + 1 + intval( $scroll_month ) ), ( intval( $start_day ) - 1 ), intval( $start_year ) );
383 $wh_booking_date2 = gmdate("Y-m-d", $real_date); // '2012-12-31';
384 break;
385
386 case '60':
387 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
388 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 */
389
390 $real_date = mktime( 0, 0, 0, ( intval( $start_month ) + intval( $scroll_month ) ), intval( $start_day ), intval( $start_year ) );
391 $wh_booking_date = gmdate("Y-m-d", $real_date); // '2012-12-01';
392
393 $real_date = mktime( 0, 0, 0, ( intval( $start_month ) + 2 + intval( $scroll_month ) ), ( intval( $start_day ) - 1 ), intval( $start_year ) );
394 $wh_booking_date2 = gmdate("Y-m-d", $real_date); // '2013-02-31';
395 break;
396
397 ////////////////////////////////////////////////////////////////////////////////
398 default: // 30 - default
399 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
400 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 */
401
402 $real_date = mktime( 0, 0, 0, ( intval( $start_month ) + intval( $scroll_month ) ), intval( $start_day ), intval( $start_year ) );
403 $wh_booking_date = gmdate("Y-m-d", $real_date); // '2012-12-01';
404
405 $real_date = mktime( 0, 0, 0, ( intval( $start_month ) + 1 + intval( $scroll_month ) ), ( intval( $start_day ) - 1 ), intval( $start_year ) );
406 $wh_booking_date2 = gmdate("Y-m-d", $real_date); // '2012-12-31';
407 break;
408 }
409
410 } else { // Single resource
411
412 switch ($view_days_num) {
413 case '90':
414
415 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
416 if (empty($_REQUEST['scroll_start_date'])) $start_day = gmdate("d");
417 $start_week_day_num = gmdate("w");
418 $start_day_weeek = esc_js(get_bk_option( 'booking_start_day_weeek' )); //[0]:Sun .. [6]:Sut
419
420 if ($start_week_day_num != $start_day_weeek) {
421 for ($d_inc = 1; $d_inc < 8; $d_inc++) { // Just get week back
422 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) - intval( $d_inc ) ), intval( $start_year ) );
423 $start_week_day_num = gmdate("w", $real_date);
424 if ($start_week_day_num == $start_day_weeek) {
425 $start_day = gmdate("d", $real_date);
426 $start_year = gmdate("Y", $real_date);
427 $start_month = gmdate("m", $real_date);
428 $d_inc=9;
429 //break;
430 }
431 }
432 }
433
434 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
435 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 */
436
437 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) + intval( $scroll_day ) ), intval( $start_year ) );
438 $wh_booking_date = gmdate("Y-m-d", $real_date); // '2012-12-01';
439
440 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) + 7 * 12 + 7 + intval( $scroll_day ) ), intval( $start_year ) );
441 $wh_booking_date2 = gmdate("Y-m-d", $real_date); // '2013-12-31';
442 break;
443
444 case '30':
445 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
446 if (empty($_REQUEST['scroll_start_date'])) $start_day = gmdate("d");
447
448 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
449 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 */
450
451 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) + intval( $scroll_day ) ), intval( $start_year ) );
452 $wh_booking_date = gmdate("Y-m-d", $real_date); // '2012-12-01';
453
454 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) + 31 + intval( $scroll_day ) ), intval( $start_year ) );
455 $wh_booking_date2 = gmdate("Y-m-d", $real_date); // '2013-12-31';
456 break;
457
458 default: // 365
459
460 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
461 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 */
462 else $scroll_month = 0;
463
464 $real_date = mktime( 0, 0, 0, ( intval( $start_month ) + intval( $scroll_month ) ), intval( $start_day ), intval( $start_year ) );
465 $wh_booking_date = gmdate("Y-m-d", $real_date); // '2012-12-01';
466
467 $real_date = mktime( 0, 0, 0, ( intval( $start_month ) + intval( $scroll_month ) + 13 ), ( intval( $start_day ) - 1 ), intval( $start_year ) );
468 $wh_booking_date2 = gmdate("Y-m-d", $real_date); // '2013-12-31';
469
470 break;
471 }
472 }
473
474
475 $or_sort = '' ;
476
477 $args = array(
478 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
479 'wh_booking_type' => ( isset( $_REQUEST['wh_booking_type'] ) ) ? $_REQUEST['wh_booking_type'] : '',
480 'wh_approved' => '', // Any.
481 'wh_booking_id' => '', // Any.
482 'wh_is_new' => '', // (isset($_REQUEST['wh_is_new']))?$_REQUEST['wh_is_new']:'', ?.
483 'wh_pay_status' => 'all', // (isset($_REQUEST['wh_pay_status']))?$_REQUEST['wh_pay_status']:'', // ?.
484 'wh_keyword' => '', // (isset($_REQUEST['wh_keyword']))?$_REQUEST['wh_keyword']:'', // ?.
485 'wh_booking_date' => $wh_booking_date,
486 'wh_booking_date2' => $wh_booking_date2,
487 'wh_modification_date' => '3', // (isset($_REQUEST['wh_modification_date']))?$_REQUEST['wh_modification_date']:'', // ?
488 'wh_modification_date2' => '', // (isset($_REQUEST['wh_modification_date2']))?$_REQUEST['wh_modification_date2']:'', // ?
489 'wh_cost' => '', // (isset($_REQUEST['wh_cost']))?$_REQUEST['wh_cost']:'', // ?
490 'wh_cost2' => '', // (isset($_REQUEST['wh_cost2']))?$_REQUEST['wh_cost2']:'', // ?
491 'or_sort' => $or_sort,
492 'page_num' => '1',
493 'page_items_count' => '100000',
494 );
495
496 return $args;
497 }
498
499
500 /** Set initial $_REQUEST['view_days_num'] depend on from selected booking resources */
501 function wpbc_set_request_params_for_timeline() {
502
503 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
504 if ( ( isset( $_REQUEST['wh_booking_type'] ) ) && ( strpos( $_REQUEST['wh_booking_type'], ',' ) !== false ) ) {
505 $is_show_resources_matrix = true;
506 } else {
507 $is_show_resources_matrix = false;
508 }
509
510 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
511 if ( ! isset( $_REQUEST['view_days_num'] ) ) {
512 $_REQUEST['view_days_num'] = get_bk_option( 'booking_view_days_num' );
513 }
514
515 // 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.
516 if ( ( $is_show_resources_matrix ) ) { // Switching from the Single to Matrix mode.
517 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
518 if ( isset( $_REQUEST['view_days_num'] ) && ( $_REQUEST['view_days_num'] == '365' ) ) {
519 $_REQUEST['view_days_num'] = 60;
520 }
521 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
522 if ( isset( $_REQUEST['view_days_num'] ) && ( $_REQUEST['view_days_num'] == '90' ) ) {
523 $_REQUEST['view_days_num'] = 7;
524 }
525 } else { // Switching from the Matrix to Single mode.
526 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
527 if ( isset( $_REQUEST['view_days_num'] ) && ( $_REQUEST['view_days_num'] == '60' ) ) {
528 $_REQUEST['view_days_num'] = 365;
529 }
530 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
531 if ( ( $_REQUEST['view_days_num'] == '7' ) || ( $_REQUEST['view_days_num'] == '1' ) ) {
532 $_REQUEST['view_days_num'] = 30;
533 }
534 }
535 }
536
537
538 /** Define default booking resource to $_GET request and check if user can be here in MU version. */
539 function wpbc_set_default_resource_to__get() {
540
541 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
542 if ( isset( $_GET['booking_type'] ) ) {
543
544 // Check if User can be here in MultiUser version for this booking resource (is this user owner of this resource or not).
545 if ( class_exists( 'wpdev_bk_multiuser' ) ) {
546
547 $default_booking_resource = sanitize_text_field( wp_unslash( $_GET['booking_type'] ) ); /* phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing */ /* FixIn: sanitize_unslash */
548
549 // Check if this MU user activated or superadmin, otherwise show warning.
550 if ( ! wpbc_is_mu_user_can_be_here( 'activated_user' ) ) {
551 return false;
552 }
553
554 // Check if this MU user owner of this resource or superadmin, otherwise show warning.
555 if ( ! wpbc_is_mu_user_can_be_here( 'resource_owner', $default_booking_resource ) ) {
556 return false;
557 }
558 }
559 } else { // Set default booking resource to $_GET.
560
561 // Get ID of default booking resource, or return false (in case if user have no access to this resource and show some warnings).
562 $default_booking_resource = wpbc_get_default_resource();
563
564 if ( empty( $default_booking_resource ) ) {
565
566 return false; // User can not be here, Warnings have shown.
567
568 } else {
569
570 $_GET['booking_type'] = $default_booking_resource;
571 }
572
573 // 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.
574 make_bk_action( 'check_if_bk_res_parent_with_childs_set_parent_res', $default_booking_resource );
575 }
576
577 return true;
578 }
579
580
581 /**
582 * Get ID of default booking resource, or return false (in case if user have no access to this resource and show some warnings).
583 *
584 * @return boolean|int
585 */
586 function wpbc_get_default_resource() {
587
588 if ( ! class_exists( 'wpdev_bk_personal' ) ) {
589 return 1;
590 } // Free, i.e., default 1.
591
592 // Get assigned default booking resource from General Booking Settings page.
593 $default_booking_resource = get_bk_option( 'booking_default_booking_resource' ); // If empty, i.e., "" - its all resources - no default booking resource.
594
595 if ( empty( $default_booking_resource ) ) { // We do not have default resource.
596
597 // Get first resource in a list.
598 // 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.
599 $default_booking_resource = get__default_type();
600 }
601
602 // MU.
603 if ( class_exists( 'wpdev_bk_multiuser' ) ) {
604
605 // Check if this MU user activated or superadmin, otherwise show warning.
606 if ( ! wpbc_is_mu_user_can_be_here( 'activated_user' ) ) {
607 return false;
608 }
609
610 // Check if this MU user owner of this resource or superadmin, otherwise show warning.
611 if ( ! wpbc_is_mu_user_can_be_here( 'resource_owner', $default_booking_resource ) ) {
612 return false;
613 }
614 }
615
616 return $default_booking_resource;
617 }
618
619
620 /** Get list of all booking resources.
621 *
622 * @return array (
623 [1] => Array (
624 [title] => Default [parent resource]
625 [attr] => Array (
626 [class] => wpbc_parent_resource
627 )
628 )
629 [5] => Array (
630 [title] => Default-1
631 [attr] => Array (
632 [class] => wpbc_child_resource
633 )
634 )
635 [6] => Array ( ...
636 */
637 function wpbc_get_all_booking_resources_list(){ //FixIn: 8.1.3.5.2
638
639 if ( ! class_exists( 'wpdev_bk_personal' ) ) {
640 return array();
641 }
642
643 $resources_cache = wpbc_br_cache(); // Get booking resources from cache
644
645 $resource_objects = $resources_cache->get_resources();
646 // $resource_objects = $resources_cache->get_single_parent_resources();
647
648 //$resource_options = $params['resources'];
649 $resource_options = array(); // FixIn: 8.2.1.12.
650
651 foreach ( $resource_objects as $br ) {
652
653 $br_option = array();
654 $br_option['title'] = wpbc_lang( $br['title'] );
655
656 if ( ( isset( $br['parent'] ) ) && ( $br['parent'] == 0 ) && ( isset( $br['count'] ) ) && ( $br['count'] > 1 ) ) {
657 $br_option['title'] .= ' [' . __( 'parent resource', 'booking' ) . ']';
658 }
659
660 $br_option['attr'] = array();
661 $br_option['attr']['class'] = 'wpbc_single_resource';
662 if ( isset( $br['parent'] ) ) {
663 if ( $br['parent'] == 0 ) {
664 if ( ( isset( $br['count'] ) ) && ( $br['count'] > 1 ) ) {
665 $br_option['attr']['class'] = 'wpbc_parent_resource';
666 }
667 } else {
668 $br_option['attr']['class'] = 'wpbc_child_resource';
669 }
670 }
671
672 $sufix = '';
673
674 $resource_options[ $br['id'] . $sufix ] = $br_option;
675
676 if ( $resource_options[ $br['id'] ]['attr']['class'] === 'wpbc_child_resource' ) {
677 $resource_options[ $br['id'] ]['title'] = ' &nbsp;&nbsp;&nbsp; ' . $resource_options[ $br['id'] ]['title'];
678 }
679 }
680
681 return $resource_options;
682 }
683
684 ////////////////////////////////////////////////////////////////////////////////
685 // S u p p o r t
686 ////////////////////////////////////////////////////////////////////////////////
687
688 /**
689 * Check if current WP user can be here
690 * Checking if the user activated, and booking resource belong to specific user
691 *
692 * @param string $check_condition 'activated_user' | 'resource_owner' | 'only_super_admin'
693 * @param string $booking_resource - Optional. ID of booking resource for 'resource_owner' condition
694 * @return boolean
695 */
696 function wpbc_is_mu_user_can_be_here( $check_condition, $booking_resource = '' ) {
697
698 $is_can = true;
699
700 if ( $check_condition == 'activated_user' )
701 $is_can = apply_bk_filter( 'multiuser_is_user_can_be_here', true, 'check_for_active_users' );
702
703 if ( $check_condition == 'only_super_admin' )
704 $is_can = apply_bk_filter( 'multiuser_is_user_can_be_here', true, 'only_super_admin' );
705
706 if ( $check_condition == 'resource_owner' )
707 $is_can = apply_bk_filter( 'multiuser_is_user_can_be_here', true, $booking_resource );
708
709 return $is_can;
710
711 }
712
713
714 ////////////////////////////////////////////////////////////////////////////////
715 // E n g i n e B o o k i n g L i s t i n g
716 ////////////////////////////////////////////////////////////////////////////////
717
718 /**
719 * E n g i n e for getting Bookings objects for Booking Listing pages
720 *
721 * @param array $args - Request paramters from filters
722 * @return array(
723 'bookings' => $bookings
724 , 'resources' => $booking_types
725 , 'bookings_count' => $bookings_count
726 , 'page_num' => $page_num
727 , 'count_per_page' => $page_items_count
728 );
729 */
730 function wpbc_get_bookings_objects( $args ){
731
732 global $wpdb;
733
734 // Initial variables //////////////////////////////////////////////////////
735
736 $sql_boking_listing = wpbc_get_sql_for_booking_listing( $args );
737 $sql_start_count = $sql_boking_listing[ 'sql_start_count' ];
738 $sql_start_select = $sql_boking_listing[ 'sql_start_select' ];
739 $sql = $sql_boking_listing[ 'sql' ];
740 $sql_where = $sql_boking_listing[ 'where' ];
741 $sql_order = $sql_boking_listing[ 'order' ];
742 $sql_limit = $sql_boking_listing[ 'limit' ];
743
744 $num_per_page_check = 10;
745 $defaults = array(
746 'wh_booking_type' => ''
747 , 'wh_approved' => ''
748 , 'wh_booking_id' => ''
749 , 'wh_is_new' => ''
750 , 'wh_pay_status' => ''
751 , 'wh_keyword' => ''
752 , 'wh_booking_date' => ''
753 , 'wh_booking_date2' => ''
754 , 'wh_modification_date' => ''
755 , 'wh_modification_date2' => ''
756 , 'wh_cost' => ''
757 , 'wh_cost2' => ''
758 , 'or_sort' => ''
759 , 'page_num' => '1'
760 , 'wh_trash' => '' // FixIn: 6.1.1.10.
761 , 'page_items_count' => ( ( empty( $num_per_page_check ) ) ? '10' : $num_per_page_check )
762 );
763
764 $r = wp_parse_args( $args, $defaults );
765
766 $r = apply_filters( 'wpbc_request_params_for_get_booking_obj', $r ); // FixIn: 7.0.1.41.
767
768 extract( $r, EXTR_SKIP );
769
770 $page_start = ( $page_num - 1 ) * $page_items_count;
771
772 //debuge( $sql_start_select . $sql . $sql_where . $sql_order . $sql_limit );
773
774 // -----------------------------------------------------------------------------------------------------------------
775 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
776 $bookings_res = $wpdb->get_results( $sql_start_select . $sql . $sql_where . $sql_order . $sql_limit ); // Get Bookings.
777
778 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
779 $bookings_count = $wpdb->get_results( $sql_start_count . $sql . $sql_where ); // Get Number of bookings.
780
781 $bookings_count = ( ( count( $bookings_count ) > 0 ) ? $bookings_count[0]->count : 0 );
782
783 $booking_types = apply_bk_filter( 'wpdebk_get_keyed_all_bk_resources', array() ); // Get Resources
784
785
786 // -----------------------------------------------------------------------------------------------------------------
787 $booking_id_list = array(); // ID list of ALL bookings
788 $bookings = array();
789 $short_days = array();
790 $short_days_type_id = array();
791
792 foreach ( $bookings_res as $booking ) {
793
794 if ( ! in_array( $booking->booking_id, $booking_id_list ) )
795 $booking_id_list[] = $booking->booking_id;
796
797 $bookings[$booking->booking_id] = $booking;
798 $bookings[$booking->booking_id]->dates = array();
799 $bookings[$booking->booking_id]->dates_short = array();
800
801 $bk_list_type = (isset( $booking->booking_type )) ? $booking->booking_type : '1';
802
803 if ( ( isset( $booking->sync_gid ) ) && (!empty( $booking->sync_gid )) ) {
804 $booking->form .= "~text^sync_gid{$booking->booking_type}^{$booking->sync_gid}";
805 }
806
807 $cont = wpbc__legacy__get_form_content_arr( $booking->form
808 , $bk_list_type
809 , ''
810 , array(
811 'booking_id' => $booking->booking_id
812 , 'resource_title' => (isset( $booking_types[$booking->booking_type] )) ? $booking_types[$booking->booking_type] : ''
813 )
814 );
815
816 $search = array( "'(<br[ ]?[/]?>)+'si", "'(<[/]?p[ ]?>)+'si"/*, "'(<[/]?div[ ]?>)+'si"*/ ); // FixIn: 8.8.1.6.
817 $replace = array( "&nbsp;&nbsp;", " &nbsp; ", " &nbsp; " );
818 $cont['content'] = preg_replace( $search, $replace, $cont['content'] );
819
820 $bookings[$booking->booking_id]->form_show = $cont['content'];
821 unset( $cont['content'] );
822 $bookings[$booking->booking_id]->form_data = $cont;
823 }
824 $booking_id_list = implode( ",", $booking_id_list );
825 $booking_id_list = wpbc_clean_like_string_for_db( $booking_id_list );
826
827 // -----------
828
829 if ( ! empty( $booking_id_list ) ) { // Get Dates for all our Bookings.
830 $sql = "SELECT *
831 FROM {$wpdb->prefix}bookingdates as dt
832 WHERE dt.booking_id in ( {$booking_id_list} ) ";
833
834 if ( class_exists( 'wpdev_bk_biz_l' ) ) {
835 $sql .= ' ORDER BY booking_id, type_id, booking_date ';
836 } else {
837 $sql .= ' ORDER BY booking_id, booking_date ';
838 }
839
840 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
841 $booking_dates = $wpdb->get_results( $sql );
842
843 } else {
844 $booking_dates = array();
845 }
846
847 // -------------
848
849 $last_booking_id = '';
850
851 foreach ( $booking_dates as $date ) { // Add Dates to Bookings array
852
853 $bookings[ $date->booking_id ]->dates[] = $date;
854
855 if ( $date->booking_id != $last_booking_id ) {
856 if ( !empty( $last_booking_id ) ) {
857 if ( $last_show_day != $dte ) {
858 $short_days[] = $dte;
859 $short_days_type_id[] = $last_day_id;
860 }
861
862 $bookings[$last_booking_id]->dates_short = $short_days;
863 $bookings[$last_booking_id]->dates_short_id = $short_days_type_id;
864 }
865 $last_day = '';
866 $last_day_id = '';
867 $last_show_day = '';
868 $short_days = array();
869 $short_days_type_id = array();
870 }
871
872 $last_booking_id = $date->booking_id;
873 $dte = $date->booking_date;
874
875 if ( empty( $last_day ) ) { // First date
876 $short_days[] = $dte;
877 $short_days_type_id[] = (isset( $date->type_id )) ? $date->type_id : '';
878 $last_show_day = $dte;
879 } else { // All other days
880 //if ( wpbc_is_next_day( $dte, $last_day ) ) {
881 $next_day_if__check_in__then__check_out = true;
882 if ( wpbc_is_less_than_next_day( $dte, $last_day, $next_day_if__check_in__then__check_out ) ) {
883 if ( $last_show_day != '-' ) {
884 $short_days[] = '-';
885 $short_days_type_id[] = '';
886 }
887 $last_show_day = '-';
888 } else {
889 if ( $last_show_day != $last_day ) {
890 $short_days[] = $last_day;
891 $short_days_type_id[] = $last_day_id;
892 }
893 $short_days[] = ',';
894 $short_days_type_id[] = '';
895 $short_days[] = $dte;
896 $short_days_type_id[] = (isset( $date->type_id )) ? $date->type_id : '';
897 $last_show_day = $dte;
898 }
899 }
900 $last_day = $dte;
901 $last_day_id = (isset( $date->type_id )) ? $date->type_id : '';
902 }
903
904 if ( isset( $dte ) )
905 if ( $last_show_day != $dte ) {
906 $short_days[] = $dte;
907 $short_days_type_id[] = (isset( $date->type_id )) ? $date->type_id : '';
908 }
909 if ( isset( $bookings[$last_booking_id] ) ) {
910 $bookings[$last_booking_id]->dates_short = $short_days;
911 $bookings[$last_booking_id]->dates_short_id = $short_days_type_id;
912 }
913
914 //debuge( 'Before filtering:', gmdate('Y-m-d', time() +86400 ), $_REQUEST, $bookings ) ;
915
916 // -----------------------------------------------------------------------------------------------------------------
917 // Filter some bookings
918 // -----------------------------------------------------------------------------------------------------------------
919 // Showing only bookings that starting or ending during "Today" ( Today check in/out )
920 if ( (isset( $args['wh_booking_date'] )) && ($args['wh_booking_date'] == '9') ) {
921
922 $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
923
924 foreach ( $bookings as $bc_id => $bc_value ) {
925
926 $check_in_date = $bc_value->dates_short[0];
927 $check_in_date = explode( ' ', $check_in_date );
928 $check_in_date = $check_in_date[0]; // 2014-02-25
929
930 if ( count( $bc_value->dates_short ) == 1 )
931 $check_out_date = $bc_value->dates_short[0];
932 else
933 $check_out_date = $bc_value->dates_short[2];
934 $check_out_date = explode( ' ', $check_out_date );
935 $check_out_date = $check_out_date[0]; // 2014-02-25
936
937 if ( ( $today_mysql_format != $check_in_date ) && ( $today_mysql_format != $check_out_date ) ) {
938 unset( $bookings[$bc_id] );
939 $bookings_count--;
940 }
941 }
942 }
943
944
945 // If we selected the Dates as "Check In - Today/Tommorow", then show only the bookings, where check in date is Today
946 if ( (isset( $args['wh_booking_date'] )) && ($args['wh_booking_date'] == '7') ) {
947 //$today_mysql_format = gmdate('Y-m-d');
948 //$today_mysql_format = gmdate('Y-m-d', time() +86400 ); // 1 Day = 24*60*60 = 86400
949 $today_mysql_format = date_i18n( 'Y-m-d', time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) + DAY_IN_SECONDS ); // Tommorow day with gmt offset
950 foreach ( $bookings as $bc_id => $bc_value ) {
951 $check_in_date = $bc_value->dates_short[0];
952 $check_in_date = explode( ' ', $check_in_date );
953 $check_in_date = $check_in_date[0]; // 2014-02-25
954 if ( $today_mysql_format != $check_in_date ) {
955 unset( $bookings[$bc_id] );
956 $bookings_count--;
957 }
958 }
959 }
960
961
962 // If we selected the Dates as "Check Out - Tomorow", then show only the bookings, where check out date is Tomorrow .
963 if ( ( isset( $args['wh_booking_date'] ) ) && ( 8 === intval( $args['wh_booking_date'] ) ) ) {
964
965 $tomorrow_mysql_format = date_i18n( 'Y-m-d', time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) + DAY_IN_SECONDS ); // Tommorow day with gmt offset.
966 foreach ( $bookings as $bc_id => $bc_value ) {
967 if ( count( $bc_value->dates_short ) === 1 ) {
968 $check_out_date = $bc_value->dates_short[0];
969 } else {
970 $check_out_date = $bc_value->dates_short[2];
971 }
972 $check_out_date = explode( ' ', $check_out_date );
973 $check_out_date = $check_out_date[0]; // 2014-02-25
974 if ( $tomorrow_mysql_format !== $check_out_date ) {
975 unset( $bookings[ $bc_id ] );
976 --$bookings_count;
977 }
978 }
979 }
980
981
982 $return_booking_structure = array(
983 'bookings' => $bookings,
984 'resources' => $booking_types,
985 'bookings_count' => $bookings_count,
986 'page_num' => $page_num,
987 'count_per_page' => $page_items_count,
988 );
989
990
991 return $return_booking_structure;
992 }
993
994
995 ////////////////////////////////////////////////////////////////////////////////
996 // S Q L
997 ////////////////////////////////////////////////////////////////////////////////
998
999 /**
1000 * Get S Q L for bookings at Booking Listing page
1001 *
1002 * @param array $args - Request paramters from filters
1003 * @return array - Get array with SQL for getting bookings
1004 */
1005 function wpbc_get_sql_for_booking_listing( $args ){
1006
1007 global $wpdb;
1008
1009 $num_per_page_check = 10;
1010
1011 $defaults = array(
1012 'wh_booking_type' => ''
1013 , 'wh_approved' => ''
1014 , 'wh_booking_id' => ''
1015 , 'wh_is_new' => ''
1016 , 'wh_pay_status' => ''
1017 , 'wh_keyword' => ''
1018 , 'wh_booking_date' => ''
1019 , 'wh_booking_date2' => ''
1020 , 'wh_modification_date' => ''
1021 , 'wh_modification_date2' => ''
1022 , 'wh_cost' => ''
1023 , 'wh_cost2' => ''
1024 , 'or_sort' => ''
1025 , 'page_num' => '1'
1026 , 'wh_trash' => '' // FixIn: 6.1.1.10.
1027 , 'wh_sync_gid' => '' // '' | 'imported' | 'plugin' // FixIn: 8.8.3.19.
1028 , 'page_items_count' => $num_per_page_check
1029 );
1030 $r = wp_parse_args( $args, $defaults );
1031 extract( $r, EXTR_SKIP );
1032
1033 $page_start = ( $page_num - 1 ) * $page_items_count;
1034
1035
1036 $posible_sorts = array( 'booking_id_asc', 'sort_date', 'sort_date_asc', 'booking_type', 'booking_type_asc', 'cost', 'cost_asc' );
1037
1038 if ( ($or_sort == '') || ($or_sort == 'id') || ( !in_array( $or_sort, $posible_sorts ) ) )
1039 $or_sort = 'booking_id';
1040
1041
1042 ////////////////////////////////////////////////////////////////////////
1043 // S Q L
1044 ////////////////////////////////////////////////////////////////////////
1045 $sql_start_select = " SELECT * ";
1046 $sql_start_count = " SELECT COUNT(*) as count";
1047 $sql = " FROM {$wpdb->prefix}booking as bk"; // GET ONLY ROWS OF THE B o o k i n g s - So we can limit the requests
1048
1049 //debuge($wh_trash);
1050 //FixIn: 6.1.1.10 - check also below usage of {$trash_bookings}
1051 $trash_bookings = " AND bk.trash = 0 ";
1052 if ( isset( $wh_trash ) ) {
1053
1054 if ( $wh_trash == "trash" ) $trash_bookings = " AND bk.trash = 1 ";
1055 else if ( $wh_trash == "any" ) $trash_bookings = '';
1056 }
1057 //debuge($trash_bookings);
1058
1059 if ( empty( $wh_booking_id ) ) {
1060
1061 $sql_where = " WHERE " . // Date (single) connection (Its required for the correct Pages in SQL: LIMIT Keyword)
1062 " EXISTS (
1063 SELECT *
1064 FROM {$wpdb->prefix}bookingdates as dt
1065 WHERE bk.booking_id = dt.booking_id ";
1066
1067 if ( 'lost' == $wh_booking_type ) { // FixIn: 8.5.2.19.
1068
1069 $sql_where.= " AND bk.booking_type NOT IN ( SELECT DISTINCT booking_type_id FROM {$wpdb->prefix}bookingtypes ) ";
1070 $sql_where.= " ) ";
1071 $wh_booking_type = '';
1072
1073 } else {
1074
1075 if ( $wh_approved !== '' )
1076 $sql_where.= " AND approved = $wh_approved "; // Approved or Pending
1077
1078 $sql_where .= wpbc_set_sql_where_for_dates( $wh_booking_date, $wh_booking_date2 );
1079
1080 $sql_where.= " ) ";
1081
1082 $sql_where .= " {$trash_bookings} "; // FixIn: 6.1.1.10.
1083
1084 // FixIn: 8.8.3.19.
1085 if ( 'imported' === $wh_sync_gid ) {
1086 $sql_where .= " AND bk.sync_gid != '' ";
1087 }
1088 if ( 'plugin' === $wh_sync_gid ) {
1089 $sql_where .= " AND bk.sync_gid = '' ";
1090 }
1091
1092 if ( $wh_is_new !== '' )
1093 $sql_where .= " AND bk.is_new = " . $wh_is_new . " ";
1094
1095 $sql_where .= apply_bk_filter( 'get_bklist_sql_keyword', '', $wh_keyword ); // P
1096
1097 $sql_where .= wpbc_set_sql_where_for_modification_date( $wh_modification_date, $wh_modification_date2 );
1098
1099 $sql_where .= apply_bk_filter( 'get_bklist_sql_paystatus', '', $wh_pay_status ); // BS
1100 $sql_where .= apply_bk_filter( 'get_bklist_sql_cost', '', $wh_cost, $wh_cost2 ); // BS
1101
1102 $sql_where .= apply_bk_filter( 'get_bklist_sql_resources', '', $wh_booking_type, $wh_approved, $wh_booking_date, $wh_booking_date2 ); // P || BL
1103 }
1104
1105 } else {
1106
1107 // FixIn: 8.7.7.10.
1108 if ( strpos( $wh_booking_id, '<' ) !== false ) {
1109 $wh_booking_id = str_replace( '<', '', $wh_booking_id );
1110 $wh_booking_id = intval( $wh_booking_id );
1111 $sql_where = " WHERE bk.booking_id < " . $wh_booking_id . " ";
1112 }
1113
1114 else if ( strpos( $wh_booking_id, '>' ) !== false ) {
1115 $wh_booking_id = str_replace( '>', '', $wh_booking_id );
1116 $wh_booking_id = intval( $wh_booking_id );
1117 $sql_where = " WHERE bk.booking_id > " . $wh_booking_id . " ";
1118
1119 }
1120
1121 else if ( strpos( $wh_booking_id, ',' ) !== false ) {
1122 $sql_where = " WHERE bk.booking_id IN (" . $wh_booking_id . ") ";
1123
1124 } else {
1125 $sql_where = " WHERE bk.booking_id = " . $wh_booking_id . " ";
1126 }
1127
1128 // Check if searching booking is belonging to specific user in Booking Calendar MultiUser version
1129 $sql_where = apply_bk_filter('update_where_sql_for_getting_bookings_in_multiuser', $sql_where );
1130
1131 }
1132
1133 if ( strpos( $or_sort, '_asc' ) !== false ) { // Order
1134 $or_sort = str_replace( '_asc', '', $or_sort );
1135 $sql_order = " ORDER BY " . $or_sort . " ASC ";
1136 } else
1137 $sql_order = " ORDER BY " . $or_sort . " DESC ";
1138
1139
1140 $sql_limit = $wpdb->prepare( " LIMIT %d, %d ", $page_start, $page_items_count );
1141
1142 $return_res = array(
1143 'sql_start_count' => $sql_start_count
1144 , 'sql_start_select' => $sql_start_select
1145 , 'sql' => $sql
1146 , 'where' => $sql_where
1147 , 'order' => $sql_order
1148 , 'limit' => $sql_limit
1149 );
1150
1151 //debuge($return_res);
1152 return $return_res;
1153 }
1154
1155
1156 ////////////////////////////////////////////////////////////////////////////////
1157 // S Q L W H E R E
1158 ////////////////////////////////////////////////////////////////////////////////
1159
1160 /**
1161 * Get SQL W H E R E conditions for D a t e s of bookings
1162 *
1163 * @param string $wh_booking_date - Parameter from Booking Listing request (usually its number)
1164 * @param string $wh_booking_date2 - Parameter from Booking Listing request (usually its number)
1165 * @param string $pref - Optional. Prefix for table.
1166 * @return string - WHERE conditions for SQL
1167 */
1168 function wpbc_set_sql_where_for_dates( $wh_booking_date, $wh_booking_date2, $pref = 'dt.' ) {
1169
1170 $sql_where= '';
1171 if ($pref == 'dt.') { $and_pre = ' AND '; $and_suf = ''; }
1172 else { $and_pre = ''; $and_suf = ' AND '; }
1173
1174 // Actual
1175 if ( ( ( $wh_booking_date === '' ) && ( $wh_booking_date2 === '' ) ) || ($wh_booking_date === '0') ) {
1176 $sql_where = $and_pre."( ".$pref."booking_date >= ( CURDATE() - INTERVAL '00:00:01' HOUR_SECOND ) ) ".$and_suf ; // FixIn: 8.5.2.14.
1177
1178 } else if ($wh_booking_date === '1') { // Today // FixIn: 7.1.2.8.
1179 $sql_where = $and_pre."( ".$pref."booking_date <= ( CURDATE() + INTERVAL '23:59:59' HOUR_SECOND ) ) ".$and_suf ;
1180 $sql_where .= $and_pre."( ".$pref."booking_date >= ( CURDATE() - INTERVAL '00:00:01' HOUR_SECOND ) ) ".$and_suf ; // FixIn: 8.4.7.21.
1181
1182
1183 } else if ($wh_booking_date === '2') { // Previous
1184 $sql_where = $and_pre."( ".$pref."booking_date <= ( CURDATE() - INTERVAL '00:00:01' HOUR_SECOND ) ) ".$and_suf ; // FixIn: 8.5.2.16.
1185
1186 } else if ($wh_booking_date === '3') { // All
1187 $sql_where = '';
1188
1189 } else if ($wh_booking_date === '4') { // Next
1190 $sql_where = $and_pre."( ".$pref."booking_date <= ( CURDATE() + INTERVAL ". $wh_booking_date2 . " DAY ) ) ".$and_suf ;
1191 // $sql_where .= $and_pre."( ".$pref."booking_date >= ( CURDATE() - INTERVAL 1 DAY ) ) ".$and_suf ;
1192 $sql_where .= $and_pre."( ".$pref."booking_date > ( CURDATE() ) ) ".$and_suf ; // FixIn: 8.0.1.1.
1193
1194 } else if ($wh_booking_date === '5') { // Prior
1195 $wh_booking_date2 = str_replace('-', '', $wh_booking_date2);
1196 $sql_where = $and_pre."( ".$pref."booking_date >= ( CURDATE() - INTERVAL ". $wh_booking_date2 . " DAY ) ) ".$and_suf ;
1197 $sql_where .= $and_pre."( ".$pref."booking_date <= ( CURDATE() + INTERVAL 1 DAY ) ) ".$and_suf ;
1198
1199 } else if ($wh_booking_date === '7') { // Check In date - Today/Tomorrow
1200 // $sql_where = $and_pre."( ".$pref."booking_date <= ( CURDATE() + INTERVAL '23:59:59' HOUR_SECOND ) ) ".$and_suf ;
1201 // $sql_where .= $and_pre."( ".$pref."booking_date >= ( CURDATE() ) ) ".$and_suf ;
1202 $sql_where = $and_pre."( ".$pref."booking_date <= ( CURDATE() + INTERVAL '1 23:59:59' DAY_SECOND ) ) ".$and_suf ;
1203 $sql_where .= $and_pre."( ".$pref."booking_date >= ( CURDATE() + INTERVAL 1 DAY ) ) ".$and_suf ;
1204
1205 } else if ($wh_booking_date === '8') { // Check Out date - Tomorrow
1206 $sql_where = $and_pre."( ".$pref."booking_date <= ( CURDATE() + INTERVAL '1 23:59:59' DAY_SECOND ) ) ".$and_suf ;
1207 $sql_where .= $and_pre."( ".$pref."booking_date >= ( CURDATE() + INTERVAL 1 DAY ) ) ".$and_suf ;
1208
1209 } else if ($wh_booking_date === '9') { // Today check in/out
1210 $sql_where = $and_pre."( ".$pref."booking_date <= ( CURDATE() + INTERVAL 1 DAY ) ) ".$and_suf ;
1211 $sql_where .= $and_pre."( ".$pref."booking_date >= ( CURDATE() - INTERVAL 1 DAY ) ) ".$and_suf ;
1212
1213 } else { // Fixed
1214
1215 if ( $wh_booking_date !== '' )
1216 if ( strpos($wh_booking_date,':')===false ) // we are do not have the time in this date, so set it
1217 $sql_where.= $and_pre."( ".$pref."booking_date >= '" . $wh_booking_date . " 00:00:00' ) ".$and_suf;
1218 else $sql_where.= $and_pre."( ".$pref."booking_date >= '" . $wh_booking_date . "' ) ".$and_suf;
1219
1220 if ( $wh_booking_date2 !== '' )
1221 if ( strpos($wh_booking_date2,':')===false ) // we are do not have the time in this date, so set it
1222 $sql_where.= $and_pre."( ".$pref."booking_date <= '" . $wh_booking_date2 . " 23:59:59' ) ".$and_suf;
1223 else $sql_where.= $and_pre."( ".$pref."booking_date <= '" . $wh_booking_date2 . "' ) ".$and_suf;
1224 }
1225
1226 return $sql_where;
1227 }
1228
1229
1230 /**
1231 * Get SQL W H E R E conditions for M o d i f i c a t i o n D a t e of bookings
1232 *
1233 * @param type $wh_modification_date - Parameter from Booking Listing request (usually its number)
1234 * @param type $wh_modification_date2 - Parameter from Booking Listing request (usually its number)
1235 * @param string $pref - Optional. Prefix for table.
1236 * @return string - WHERE conditions for SQL
1237 */
1238 function wpbc_set_sql_where_for_modification_date( $wh_modification_date, $wh_modification_date2, $pref = 'bk.' ) {
1239
1240 $sql_where = '';
1241
1242 if ($pref == 'bk.') { $and_pre = ' AND '; $and_suf = ''; }
1243 else { $and_pre = ''; $and_suf = ' AND '; }
1244
1245 if ($wh_modification_date === '1') { // Today
1246 $sql_where = $and_pre."( ".$pref."modification_date <= ( CURDATE() + INTERVAL '23:59:59' HOUR_SECOND ) ) ".$and_suf ; // FixIn: 8.4.7.22.
1247 $sql_where .= $and_pre."( ".$pref."modification_date >= ( CURDATE() - INTERVAL '00:00:01' HOUR_SECOND ) ) ".$and_suf ; // FixIn: 8.4.7.22.
1248
1249 } else if ($wh_modification_date === '3') { // All
1250 $sql_where = '';
1251
1252 } else if ($wh_modification_date === '5') { // Prior
1253 $wh_modification_date2 = str_replace('-', '', $wh_modification_date2);
1254 $sql_where = $and_pre."( ".$pref."modification_date >= ( CURDATE() - INTERVAL ". $wh_modification_date2 . " DAY ) ) ".$and_suf ;
1255 $sql_where .= $and_pre."( ".$pref."modification_date <= ( CURDATE() + INTERVAL 1 DAY ) ) ".$and_suf ;
1256
1257 } else { // Fixed
1258
1259 if ( $wh_modification_date !== '' )
1260 $sql_where.= $and_pre."( ".$pref."modification_date >= '" . $wh_modification_date . "' ) ".$and_suf;
1261
1262 if ( $wh_modification_date2 !== '' )
1263 $sql_where.= $and_pre."( ".$pref."modification_date <= '" . $wh_modification_date2 . "' ) ".$and_suf;
1264 }
1265
1266 return $sql_where;
1267 }
1268