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

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

1,215 lines 57.7 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 if ( ( isset( $_REQUEST['view_mode'] ) ) && ( 'vm_booking_listing' === $_REQUEST['view_mode'] ) ) { //FixIn: 9.2.0
28 return;
29 }
30
31 $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
34 }
35
36 // Get saved filters set, (if its not set in request yet), like "tab" & "view_mode" and overload $_REQUEST
37 wpbc_set_default_saved_params_to_request_for_booking_listing( 'default' );
38 }
39 }
40 // We are set 9 to execute earlier than hook in WPBC_Admin_Menus
41 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
42
43 ////////////////////////////////////////////////////////////////////////////////
44 // R e q u e s t S u p p o r t
45 ////////////////////////////////////////////////////////////////////////////////
46
47 /**
48 * Get here default View mode saved in a General Booking Settings page or From REQUEST view_mode
49 *
50 * @return string = 'vm_calendar' | 'vm_booking_listing'
51 */
52 function wpbc_get_default_saved_view_mode_for_wpbc_page() {
53
54 if ( ! isset( $_REQUEST['view_mode'] ) ) {
55 $booking_default_view_mode = get_bk_option( 'booking_listing_default_view_mode' );
56 } else {
57 $booking_default_view_mode = $_REQUEST['view_mode'];
58 }
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';
62 }
63
64 $booking_default_view_mode = ( 'vm_listing' == $booking_default_view_mode ) ? 'vm_booking_listing' : $booking_default_view_mode; //FixIn: 9.6.3.5
65
66 return $booking_default_view_mode; // 'vm_calendar' / 'vm_booking_listing' ;
67 }
68
69
70 /**
71 * Get from SETTINGS (if its not set in request yet) the "tab" & "view_mode" and set to $_REQUEST
72 If we have the "saved" filter set so LOAD it and set to REQUEST, if REQUEST was not set previously
73 & skip "wh_booking_type" from the saved filter set
74 *
75 * @param string $filter_name - name of saved filter set. Currntly is using only one "Default"
76 */
77 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
90
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 // }
105
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 }
115
116
117 }
118
119
120
121 /**
122 * Clean Request Parameters
123 *
124 */
125 function wpbc_check_request_paramters() { //FixIn:6.2.1.4
126
127 //debuge($_REQUEST);
128 $clean_params = array();
129
130 $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
132 $clean_params['wh_booking_type'] = 'checked_skip_it';
133 } else {
134 $clean_params['wh_booking_type'] = 'digit_or_csd';
135 }
136 if ( ( ! empty( $_REQUEST['booking_type'] ) ) && ( 'lost' == $_REQUEST['booking_type'] ) ) { //FixIn: 8.9.2.1
137 $clean_params['booking_type'] = 'checked_skip_it';
138 } else {
139 $clean_params['booking_type'] = 'digit_or_csd';
140 }
141
142 $clean_params['wh_approved'] = 'digit_or_csd'; // '0' | '1' | ''
143
144 $clean_params['wh_booking_date'] = 'digit_or_date'; // number | date 2016-07-20
145 $clean_params['wh_booking_date2'] = 'digit_or_date'; // number | date 2016-07-20
146 $clean_params['wh_booking_datenext'] = 'd'; // '1' | '2' ....
147 $clean_params['wh_booking_dateprior'] = 'd'; // '1' | '2' ....
148 $clean_params['wh_booking_datefixeddates'] = 'digit_or_date'; // number | date 2016-07-20
149 $clean_params['wh_booking_date2fixeddates'] = 'digit_or_date'; // number | date 2016-07-20
150
151 $clean_params['wh_is_new'] = 'd'; // '1' | ''
152
153 $clean_params['wh_modification_date'] = 'digit_or_date'; // number | date 2016-07-20
154 $clean_params['wh_modification_date2'] = 'digit_or_date'; // number | date 2016-07-20
155 $clean_params['wh_modification_dateprior'] = 'd'; // '1' | '2' ....
156 $clean_params['wh_modification_datefixeddates'] = 'digit_or_date'; // number | date 2016-07-20
157 $clean_params['wh_modification_date2fixeddates']= 'digit_or_date'; // number | date 2016-07-20
158
159 $clean_params['wh_keyword'] = 's'; //string
160
161 $clean_params['wh_pay_statuscustom'] = 's'; //string !!! LIKE !!!
162 $clean_params['wh_pay_status'] = array('all', 'group_ok', 'group_unknown', 'group_pending', 'group_failed');
163
164 $clean_params['wh_cost'] = 'd'; // '1' | ''
165 $clean_params['wh_cost2'] = 'd'; // '1' | ''
166
167 $clean_params['or_sort'] = array('', 'sort_date', 'booking_type', 'cost', 'booking_id_asc', 'sort_date_asc', 'booking_type_asc', 'cost_asc');
168 $clean_params['wh_trash'] = array('0' , 'trash', 'any');
169
170
171 $clean_params['page_num'] = 'd'; // '' | '1' ... // does not exist in 6.2.1.4
172 $clean_params['page_items_count'] = 'd'; // '' | '1' ... // does not exist in 6.2.1.4
173 $clean_params['view_days_num'] = 'd'; // '' | '1' ... // does not exist in 6.2.1.4
174
175 //FixIn: 8.9.2.1
176 $clean_params['scroll_start_date'] = 'digit_or_date';
177 $clean_params['scroll_day'] = 'd';
178 $clean_params['scroll_month'] = 'd';
179 $clean_params['limit_hours'] = 'digit_or_csd';
180 $clean_params['only_booked_resources'] = 'd';
181
182
183 foreach ( $clean_params as $request_key => $clean_type ) {
184
185 // elements only listed in array::
186 if ( is_array( $clean_type ) ) { // check only values from the list in this array
187
188 if ( ( isset( $_REQUEST[ $request_key ] ) ) && ( ! in_array( $_REQUEST[ $request_key ], $clean_type ) ) )
189 $clean_type = 's';
190 else
191 $clean_type = 'checked_skip_it';
192 }
193
194 switch ( $clean_type ) {
195
196 case 'checked_skip_it':
197
198 break;
199
200 case 'digit_or_date': // digit or comma separated digit
201 if ( isset( $_REQUEST[ $request_key ] ) ) {
202 $_REQUEST[ $request_key ] = wpbc_clean_digit_or_date( $_REQUEST[ $request_key ] );
203 }
204 if ( isset( $_GET[ $request_key ] ) ) {
205 $_GET[ $request_key ] = wpbc_clean_digit_or_date( $_GET[ $request_key ] );
206 }
207 if ( isset( $_POST[ $request_key ] ) ) {
208 $_POST[ $request_key ] = wpbc_clean_digit_or_date( $_POST[ $request_key ] );
209 }
210
211 break;
212
213 case 'digit_or_csd': // digit or comma separated digit
214 if ( isset( $_REQUEST[ $request_key ] ) ) {
215 $_REQUEST[ $request_key ] = wpbc_clean_digit_or_csd( $_REQUEST[ $request_key ] );
216 }
217 if ( isset( $_GET[ $request_key ] ) ) {
218 $_GET[ $request_key ] = wpbc_clean_digit_or_csd( $_GET[ $request_key ] );
219 }
220 if ( isset( $_POST[ $request_key ] ) ) {
221 $_POST[ $request_key ] = wpbc_clean_digit_or_csd( $_POST[ $request_key ] );
222 }
223
224 break;
225
226 case 's': // string
227 if ( isset( $_REQUEST[ $request_key ] ) ) {
228 $_REQUEST[ $request_key ] = wpbc_clean_like_string_for_db( $_REQUEST[ $request_key ] );
229 }
230 if ( isset( $_GET[ $request_key ] ) ) {
231 $_GET[ $request_key ] = wpbc_clean_like_string_for_db( $_GET[ $request_key ] );
232 }
233 if ( isset( $_POST[ $request_key ] ) ) {
234 $_POST[ $request_key ] = wpbc_clean_like_string_for_db( $_POST[ $request_key ] );
235 }
236
237 break;
238
239 case 'd': // digit
240 if ( ( isset( $_REQUEST[ $request_key ] ) ) && ( $_REQUEST[ $request_key ] !== '' ) ) {
241 $_REQUEST[ $request_key ] = intval( $_REQUEST[ $request_key ] );
242 }
243 if ( ( isset( $_GET[ $request_key ] ) ) && ( $_GET[ $request_key ] !== '' ) ) {
244 $_GET[ $request_key ] = intval( $_GET[ $request_key ] );
245 }
246 if ( ( isset( $_POST[ $request_key ] ) ) && ( $_POST[ $request_key ] !== '' ) ) {
247 $_POST[ $request_key ] = intval( $_POST[ $request_key ] );
248 }
249
250 break;
251
252 default:
253 if ( isset( $_REQUEST[ $request_key ] ) ) {
254 $_REQUEST[ $request_key ] = intval( $_REQUEST[ $request_key ] );
255 }
256 if ( isset( $_GET[ $request_key ] ) ) {
257 $_GET[ $request_key ] = intval( $_GET[ $request_key ] );
258 }
259 if ( isset( $_POST[ $request_key ] ) ) {
260 $_POST[ $request_key ] = intval( $_POST[ $request_key ] );
261 }
262 break;
263 }
264
265
266 }
267
268 //debuge($_REQUEST);
269 }
270
271
272 //FixIn: 9.6.3.5
273
274 /**
275 * Get array of cleaned (limited number) paramas from REQUEST
276 *
277 * @return array
278 */
279 function wpbc_get_clean_paramas_from_request_for_timeline() {
280
281
282 // Reset
283 $start_year = date("Y"); //2012
284 $start_month = date("m"); //09
285 $start_day = 1;//date("d");//1; //31
286 if (! empty($_REQUEST['scroll_start_date'])) { // scroll_start_date=2013-07-01
287 $scroll_start_date= explode('-',$_REQUEST['scroll_start_date']);
288
289 $start_year = $scroll_start_date[0]; //2012
290 $start_month = $scroll_start_date[1]; //09
291 $start_day = $scroll_start_date[2]; //date("d");//1; //31
292 }
293
294 $scroll_day = 0;
295 $scroll_month = 0;
296
297 if (isset($_REQUEST['view_days_num'])) $view_days_num = $_REQUEST['view_days_num'];
298 else $view_days_num = get_bk_option( 'booking_view_days_num');
299
300 if ((isset($_REQUEST['wh_booking_type'])) && ( strpos($_REQUEST['wh_booking_type'], ',') !== false ) )
301 $is_show_resources_matrix = true;
302 else $is_show_resources_matrix = false;
303
304 if ($is_show_resources_matrix) {
305
306 switch ($view_days_num) {
307
308 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'];
312
313 $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';
315
316 $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';
318 break;
319
320 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
324 if ($start_week_day_num != $start_day_weeek) {
325 for ($d_inc = 1; $d_inc < 8; $d_inc++) { // Just get week back
326 $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);
328 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);
332 $d_inc=9;
333 }
334 }
335 }
336
337 if (isset($_REQUEST['scroll_day'])) $scroll_day = $_REQUEST['scroll_day'];
338
339 $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';
341
342 $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';
344 break;
345
346 case '30':
347 if (isset($_REQUEST['scroll_month'])) $scroll_month = $_REQUEST['scroll_month'];
348
349 $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';
351
352 $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';
354 break;
355
356 case '60':
357 if (isset($_REQUEST['scroll_month'])) $scroll_month = $_REQUEST['scroll_month'];
358
359 $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';
361
362 $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';
364 break;
365
366 ////////////////////////////////////////////////////////////////////////////////
367 default: // 30 - default
368 if (isset($_REQUEST['scroll_month'])) $scroll_month = $_REQUEST['scroll_month'];
369
370 $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';
372
373 $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';
375 break;
376 }
377
378 } else { // Single resource
379
380 switch ($view_days_num) {
381 case '90':
382
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
386
387 if ($start_week_day_num != $start_day_weeek) {
388 for ($d_inc = 1; $d_inc < 8; $d_inc++) { // Just get week back
389 $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);
391 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);
395 $d_inc=9;
396 //break;
397 }
398 }
399 }
400
401 if (isset($_REQUEST['scroll_day'])) $scroll_day = $_REQUEST['scroll_day'];
402
403 $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';
405
406 $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';
408 break;
409
410 case '30':
411 if (empty($_REQUEST['scroll_start_date'])) $start_day = date("d");
412
413 if (isset($_REQUEST['scroll_day'])) $scroll_day = $_REQUEST['scroll_day'];
414
415 $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';
417
418 $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';
420 break;
421
422 default: // 365
423
424 if (isset($_REQUEST['scroll_month'])) $scroll_month = $_REQUEST['scroll_month'];
425 else $scroll_month = 0;
426
427 $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';
429
430 $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';
432
433 break;
434 }
435 }
436
437
438 $or_sort = '' ;
439
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'
456 );
457
458 return $args;
459 }
460
461
462 /** Set initial $_REQUEST['view_days_num'] depend on from selected booking resources */
463 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
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 }
489 }
490
491
492 /** 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;
505
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();
515
516 if ( empty( $default_booking_resource ) ) {
517
518 return false; // User can not be here, Warnings have shown
519
520 } else {
521
522 $_GET['booking_type'] = $default_booking_resource;
523 }
524
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;
531 }
532
533
534 /**
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 *
537 * @return boolean|int
538 */
539 function wpbc_get_default_resource() {
540
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 }
553
554 //MU
555 if ( class_exists( 'wpdev_bk_multiuser' ) ) {
556
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;
567 }
568
569
570 /** Get list of all booking resources.
571 *
572 * @return array (
573 [1] => Array (
574 [title] => Default [parent resource]
575 [attr] => Array (
576 [class] => wpbc_parent_resource
577 )
578 )
579 [5] => Array (
580 [title] => Default-1
581 [attr] => Array (
582 [class] => wpbc_child_resource
583 )
584 )
585 [6] => Array ( ...
586 */
587 function wpbc_get_all_booking_resources_list(){ //FixIn: 8.1.3.5.2
588
589 if ( ! class_exists( 'wpdev_bk_personal' ) ) {
590 return array();
591 }
592
593 $resources_cache = wpbc_br_cache(); // Get booking resources from cache
594
595 $resource_objects = $resources_cache->get_resources();
596 // $resource_objects = $resources_cache->get_single_parent_resources();
597
598 //$resource_options = $params['resources'];
599 $resource_options = array(); //FixIn: 8.2.1.12
600
601 foreach ( $resource_objects as $br ) {
602
603 $br_option = array();
604 $br_option['title'] = wpbc_lang( $br['title'] );
605
606 if ( ( isset( $br['parent'] ) ) && ( $br['parent'] == 0 ) && ( isset( $br['count'] ) ) && ( $br['count'] > 1 ) ) {
607 $br_option['title'] .= ' [' . __( 'parent resource', 'booking' ) . ']';
608 }
609
610 $br_option['attr'] = array();
611 $br_option['attr']['class'] = 'wpbc_single_resource';
612 if ( isset( $br['parent'] ) ) {
613 if ( $br['parent'] == 0 ) {
614 if ( ( isset( $br['count'] ) ) && ( $br['count'] > 1 ) ) {
615 $br_option['attr']['class'] = 'wpbc_parent_resource';
616 }
617 } else {
618 $br_option['attr']['class'] = 'wpbc_child_resource';
619 }
620 }
621
622 $sufix = '';
623
624 $resource_options[ $br['id'] . $sufix ] = $br_option;
625
626 if ( $resource_options[ $br['id'] ]['attr']['class'] === 'wpbc_child_resource' ) {
627 $resource_options[ $br['id'] ]['title'] = ' &nbsp;&nbsp;&nbsp; ' . $resource_options[ $br['id'] ]['title'];
628 }
629 }
630
631 return $resource_options;
632 }
633
634 ////////////////////////////////////////////////////////////////////////////////
635 // S u p p o r t
636 ////////////////////////////////////////////////////////////////////////////////
637
638 /**
639 * Check if current WP user can be here
640 * Checking if the user activated, and booking resource belong to specific user
641 *
642 * @param string $check_condition 'activated_user' | 'resource_owner' | 'only_super_admin'
643 * @param string $booking_resource - Optional. ID of booking resource for 'resource_owner' condition
644 * @return boolean
645 */
646 function wpbc_is_mu_user_can_be_here( $check_condition, $booking_resource = '' ) {
647
648 $is_can = true;
649
650 if ( $check_condition == 'activated_user' )
651 $is_can = apply_bk_filter( 'multiuser_is_user_can_be_here', true, 'check_for_active_users' );
652
653 if ( $check_condition == 'only_super_admin' )
654 $is_can = apply_bk_filter( 'multiuser_is_user_can_be_here', true, 'only_super_admin' );
655
656 if ( $check_condition == 'resource_owner' )
657 $is_can = apply_bk_filter( 'multiuser_is_user_can_be_here', true, $booking_resource );
658
659 return $is_can;
660
661 }
662
663
664 ////////////////////////////////////////////////////////////////////////////////
665 // E n g i n e B o o k i n g L i s t i n g
666 ////////////////////////////////////////////////////////////////////////////////
667
668 /**
669 * E n g i n e for getting Bookings objects for Booking Listing pages
670 *
671 * @param array $args - Request paramters from filters
672 * @return array(
673 'bookings' => $bookings
674 , 'resources' => $booking_types
675 , 'bookings_count' => $bookings_count
676 , 'page_num' => $page_num
677 , 'count_per_page' => $page_items_count
678 );
679 */
680 function wpbc_get_bookings_objects( $args ){
681
682 global $wpdb;
683
684 // Initial variables //////////////////////////////////////////////////////
685
686 $sql_boking_listing = wpbc_get_sql_for_booking_listing( $args );
687 $sql_start_count = $sql_boking_listing[ 'sql_start_count' ];
688 $sql_start_select = $sql_boking_listing[ 'sql_start_select' ];
689 $sql = $sql_boking_listing[ 'sql' ];
690 $sql_where = $sql_boking_listing[ 'where' ];
691 $sql_order = $sql_boking_listing[ 'order' ];
692 $sql_limit = $sql_boking_listing[ 'limit' ];
693
694 $num_per_page_check = 10;
695 $defaults = array(
696 'wh_booking_type' => ''
697 , 'wh_approved' => ''
698 , 'wh_booking_id' => ''
699 , 'wh_is_new' => ''
700 , 'wh_pay_status' => ''
701 , 'wh_keyword' => ''
702 , 'wh_booking_date' => ''
703 , 'wh_booking_date2' => ''
704 , 'wh_modification_date' => ''
705 , 'wh_modification_date2' => ''
706 , 'wh_cost' => ''
707 , 'wh_cost2' => ''
708 , 'or_sort' => ''
709 , 'page_num' => '1'
710 , 'wh_trash' => '' //FixIn: 6.1.1.10
711 , 'page_items_count' => ( ( empty( $num_per_page_check ) ) ? '10' : $num_per_page_check )
712 );
713
714 $r = wp_parse_args( $args, $defaults );
715
716 $r = apply_filters( 'wpbc_request_params_for_get_booking_obj', $r ); //FixIn: 7.0.1.41
717
718 extract( $r, EXTR_SKIP );
719
720 $page_start = ( $page_num - 1 ) * $page_items_count;
721
722 //debuge( $sql_start_select . $sql . $sql_where . $sql_order . $sql_limit );
723
724 ////////////////////////////////////////////////////////////////////////////
725
726
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 $bookings_count = ( ( count( $bookings_count ) > 0 ) ? $bookings_count[0]->count : 0 );
731
732 $booking_types = apply_bk_filter( 'wpdebk_get_keyed_all_bk_resources', array() ); // Get Resources
733
734
735 ////////////////////////////////////////////////////////////////////////////
736
737 $booking_id_list = array(); // ID list of ALL bookings
738 $bookings = array();
739 $short_days = array();
740 $short_days_type_id = array();
741
742 foreach ( $bookings_res as $booking ) {
743
744 if ( ! in_array( $booking->booking_id, $booking_id_list ) )
745 $booking_id_list[] = $booking->booking_id;
746
747 $bookings[$booking->booking_id] = $booking;
748 $bookings[$booking->booking_id]->dates = array();
749 $bookings[$booking->booking_id]->dates_short = array();
750
751 $bk_list_type = (isset( $booking->booking_type )) ? $booking->booking_type : '1';
752
753 if ( ( isset( $booking->sync_gid ) ) && (!empty( $booking->sync_gid )) ) {
754 $booking->form .= "~text^sync_gid{$booking->booking_type}^{$booking->sync_gid}";
755 }
756
757 $cont = wpbc__legacy__get_form_content_arr( $booking->form
758 , $bk_list_type
759 , ''
760 , array(
761 'booking_id' => $booking->booking_id
762 , 'resource_title' => (isset( $booking_types[$booking->booking_type] )) ? $booking_types[$booking->booking_type] : ''
763 )
764 );
765 //debuge($cont);
766 $search = array( "'(<br[ ]?[/]?>)+'si", "'(<[/]?p[ ]?>)+'si"/*, "'(<[/]?div[ ]?>)+'si"*/ ); //FixIn: 8.8.1.6
767 $replace = array( "&nbsp;&nbsp;", " &nbsp; ", " &nbsp; " );
768 $cont['content'] = preg_replace( $search, $replace, $cont['content'] );
769 //debuge( htmlentities( $cont['content'] ) );die;
770 $bookings[$booking->booking_id]->form_show = $cont['content'];
771 unset( $cont['content'] );
772 $bookings[$booking->booking_id]->form_data = $cont;
773 }
774 $booking_id_list = implode( ",", $booking_id_list );
775 $booking_id_list = wpbc_clean_like_string_for_db( $booking_id_list );
776
777 ////////////////////////////////////////////////////////////////////////////
778
779 if ( ! empty( $booking_id_list ) ) { // Get Dates for all our Bookings
780 $sql = "SELECT *
781 FROM {$wpdb->prefix}bookingdates as dt
782 WHERE dt.booking_id in ( {$booking_id_list} ) ";
783
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 ";
788
789 $booking_dates = $wpdb->get_results( $sql );
790 } else
791 $booking_dates = array();
792
793
794 ////////////////////////////////////////////////////////////////////////////
795
796 $last_booking_id = '';
797
798 foreach ( $booking_dates as $date ) { // Add Dates to Bookings array
799
800 $bookings[ $date->booking_id ]->dates[] = $date;
801
802 if ( $date->booking_id != $last_booking_id ) {
803 if ( !empty( $last_booking_id ) ) {
804 if ( $last_show_day != $dte ) {
805 $short_days[] = $dte;
806 $short_days_type_id[] = $last_day_id;
807 }
808
809 $bookings[$last_booking_id]->dates_short = $short_days;
810 $bookings[$last_booking_id]->dates_short_id = $short_days_type_id;
811 }
812 $last_day = '';
813 $last_day_id = '';
814 $last_show_day = '';
815 $short_days = array();
816 $short_days_type_id = array();
817 }
818
819 $last_booking_id = $date->booking_id;
820 $dte = $date->booking_date;
821
822 if ( empty( $last_day ) ) { // First date
823 $short_days[] = $dte;
824 $short_days_type_id[] = (isset( $date->type_id )) ? $date->type_id : '';
825 $last_show_day = $dte;
826 } else { // All other days
827 //if ( wpbc_is_next_day( $dte, $last_day ) ) {
828 $next_day_if__check_in__then__check_out = true;
829 if ( wpbc_is_less_than_next_day( $dte, $last_day, $next_day_if__check_in__then__check_out ) ) {
830 if ( $last_show_day != '-' ) {
831 $short_days[] = '-';
832 $short_days_type_id[] = '';
833 }
834 $last_show_day = '-';
835 } else {
836 if ( $last_show_day != $last_day ) {
837 $short_days[] = $last_day;
838 $short_days_type_id[] = $last_day_id;
839 }
840 $short_days[] = ',';
841 $short_days_type_id[] = '';
842 $short_days[] = $dte;
843 $short_days_type_id[] = (isset( $date->type_id )) ? $date->type_id : '';
844 $last_show_day = $dte;
845 }
846 }
847 $last_day = $dte;
848 $last_day_id = (isset( $date->type_id )) ? $date->type_id : '';
849 }
850
851 if ( isset( $dte ) )
852 if ( $last_show_day != $dte ) {
853 $short_days[] = $dte;
854 $short_days_type_id[] = (isset( $date->type_id )) ? $date->type_id : '';
855 }
856 if ( isset( $bookings[$last_booking_id] ) ) {
857 $bookings[$last_booking_id]->dates_short = $short_days;
858 $bookings[$last_booking_id]->dates_short_id = $short_days_type_id;
859 }
860
861 //debuge( 'Before filtering:', date('Y-m-d', time() +86400 ), $_REQUEST, $bookings ) ;
862
863 ////////////////////////////////////////////////////////////////////////////
864 // Filter some bookings
865 ////////////////////////////////////////////////////////////////////////////
866
867 // Showing only bookings that starting or ending during "Today" ( Today check in/out )
868 if ( (isset( $args['wh_booking_date'] )) && ($args['wh_booking_date'] == '9') ) {
869
870 $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
871
872 foreach ( $bookings as $bc_id => $bc_value ) {
873
874 $check_in_date = $bc_value->dates_short[0];
875 $check_in_date = explode( ' ', $check_in_date );
876 $check_in_date = $check_in_date[0]; // 2014-02-25
877
878 if ( count( $bc_value->dates_short ) == 1 )
879 $check_out_date = $bc_value->dates_short[0];
880 else
881 $check_out_date = $bc_value->dates_short[2];
882 $check_out_date = explode( ' ', $check_out_date );
883 $check_out_date = $check_out_date[0]; // 2014-02-25
884
885 if ( ( $today_mysql_format != $check_in_date ) && ( $today_mysql_format != $check_out_date ) ) {
886 unset( $bookings[$bc_id] );
887 $bookings_count--;
888 }
889 }
890 }
891
892
893 // If we selected the Dates as "Check In - Today/Tommorow", then show only the bookings, where check in date is Today
894 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
897 $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 foreach ( $bookings as $bc_id => $bc_value ) {
899 $check_in_date = $bc_value->dates_short[0];
900 $check_in_date = explode( ' ', $check_in_date );
901 $check_in_date = $check_in_date[0]; // 2014-02-25
902 if ( $today_mysql_format != $check_in_date ) {
903 unset( $bookings[$bc_id] );
904 $bookings_count--;
905 }
906 }
907 }
908
909
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 );
937
938 return $return_booking_structure;
939 }
940
941
942 ////////////////////////////////////////////////////////////////////////////////
943 // S Q L
944 ////////////////////////////////////////////////////////////////////////////////
945
946 /**
947 * Get S Q L for bookings at Booking Listing page
948 *
949 * @param array $args - Request paramters from filters
950 * @return array - Get array with SQL for getting bookings
951 */
952 function wpbc_get_sql_for_booking_listing( $args ){
953
954 global $wpdb;
955
956 $num_per_page_check = 10;
957
958 $defaults = array(
959 'wh_booking_type' => ''
960 , 'wh_approved' => ''
961 , 'wh_booking_id' => ''
962 , 'wh_is_new' => ''
963 , 'wh_pay_status' => ''
964 , 'wh_keyword' => ''
965 , 'wh_booking_date' => ''
966 , 'wh_booking_date2' => ''
967 , 'wh_modification_date' => ''
968 , 'wh_modification_date2' => ''
969 , 'wh_cost' => ''
970 , 'wh_cost2' => ''
971 , 'or_sort' => ''
972 , 'page_num' => '1'
973 , 'wh_trash' => '' //FixIn: 6.1.1.10
974 , 'wh_sync_gid' => '' // '' | 'imported' | 'plugin' //FixIn: 8.8.3.19
975 , 'page_items_count' => $num_per_page_check
976 );
977 $r = wp_parse_args( $args, $defaults );
978 extract( $r, EXTR_SKIP );
979
980 $page_start = ( $page_num - 1 ) * $page_items_count;
981
982
983 $posible_sorts = array( 'booking_id_asc', 'sort_date', 'sort_date_asc', 'booking_type', 'booking_type_asc', 'cost', 'cost_asc' );
984
985 if ( ($or_sort == '') || ($or_sort == 'id') || ( !in_array( $or_sort, $posible_sorts ) ) )
986 $or_sort = 'booking_id';
987
988
989 ////////////////////////////////////////////////////////////////////////
990 // S Q L
991 ////////////////////////////////////////////////////////////////////////
992 $sql_start_select = " SELECT * ";
993 $sql_start_count = " SELECT COUNT(*) as count";
994 $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
995
996 //debuge($wh_trash);
997 //FixIn: 6.1.1.10 - check also below usage of {$trash_bookings}
998 $trash_bookings = " AND bk.trash = 0 ";
999 if ( isset( $wh_trash ) ) {
1000
1001 if ( $wh_trash == "trash" ) $trash_bookings = " AND bk.trash = 1 ";
1002 else if ( $wh_trash == "any" ) $trash_bookings = '';
1003 }
1004 //debuge($trash_bookings);
1005
1006 if ( empty( $wh_booking_id ) ) {
1007
1008 $sql_where = " WHERE " . // Date (single) connection (Its required for the correct Pages in SQL: LIMIT Keyword)
1009 " EXISTS (
1010 SELECT *
1011 FROM {$wpdb->prefix}bookingdates as dt
1012 WHERE bk.booking_id = dt.booking_id ";
1013
1014 if ( 'lost' == $wh_booking_type ) { //FixIn: 8.5.2.19
1015
1016 $sql_where.= " AND bk.booking_type NOT IN ( SELECT DISTINCT booking_type_id FROM {$wpdb->prefix}bookingtypes ) ";
1017 $sql_where.= " ) ";
1018 $wh_booking_type = '';
1019
1020 } else {
1021
1022 if ( $wh_approved !== '' )
1023 $sql_where.= " AND approved = $wh_approved "; // Approved or Pending
1024
1025 $sql_where .= wpbc_set_sql_where_for_dates( $wh_booking_date, $wh_booking_date2 );
1026
1027 $sql_where.= " ) ";
1028
1029 $sql_where .= " {$trash_bookings} "; //FixIn: 6.1.1.10
1030
1031 //FixIn: 8.8.3.19
1032 if ( 'imported' === $wh_sync_gid ) {
1033 $sql_where .= " AND bk.sync_gid != '' ";
1034 }
1035 if ( 'plugin' === $wh_sync_gid ) {
1036 $sql_where .= " AND bk.sync_gid = '' ";
1037 }
1038
1039 if ( $wh_is_new !== '' )
1040 $sql_where .= " AND bk.is_new = " . $wh_is_new . " ";
1041
1042 $sql_where .= apply_bk_filter( 'get_bklist_sql_keyword', '', $wh_keyword ); // P
1043
1044 $sql_where .= wpbc_set_sql_where_for_modification_date( $wh_modification_date, $wh_modification_date2 );
1045
1046 $sql_where .= apply_bk_filter( 'get_bklist_sql_paystatus', '', $wh_pay_status ); // BS
1047 $sql_where .= apply_bk_filter( 'get_bklist_sql_cost', '', $wh_cost, $wh_cost2 ); // BS
1048
1049 $sql_where .= apply_bk_filter( 'get_bklist_sql_resources', '', $wh_booking_type, $wh_approved, $wh_booking_date, $wh_booking_date2 ); // P || BL
1050 }
1051
1052 } else {
1053
1054 //FixIn: 8.7.7.10
1055 if ( strpos( $wh_booking_id, '<' ) !== false ) {
1056 $wh_booking_id = str_replace( '<', '', $wh_booking_id );
1057 $wh_booking_id = intval( $wh_booking_id );
1058 $sql_where = " WHERE bk.booking_id < " . $wh_booking_id . " ";
1059 }
1060
1061 else if ( strpos( $wh_booking_id, '>' ) !== false ) {
1062 $wh_booking_id = str_replace( '>', '', $wh_booking_id );
1063 $wh_booking_id = intval( $wh_booking_id );
1064 $sql_where = " WHERE bk.booking_id > " . $wh_booking_id . " ";
1065
1066 }
1067
1068 else if ( strpos( $wh_booking_id, ',' ) !== false ) {
1069 $sql_where = " WHERE bk.booking_id IN (" . $wh_booking_id . ") ";
1070
1071 } else {
1072 $sql_where = " WHERE bk.booking_id = " . $wh_booking_id . " ";
1073 }
1074
1075 // Check if searching booking is belonging to specific user in Booking Calendar MultiUser version
1076 $sql_where = apply_bk_filter('update_where_sql_for_getting_bookings_in_multiuser', $sql_where );
1077
1078 }
1079
1080 if ( strpos( $or_sort, '_asc' ) !== false ) { // Order
1081 $or_sort = str_replace( '_asc', '', $or_sort );
1082 $sql_order = " ORDER BY " . $or_sort . " ASC ";
1083 } else
1084 $sql_order = " ORDER BY " . $or_sort . " DESC ";
1085
1086
1087 $sql_limit = $wpdb->prepare( " LIMIT %d, %d ", $page_start, $page_items_count );
1088
1089 $return_res = array(
1090 'sql_start_count' => $sql_start_count
1091 , 'sql_start_select' => $sql_start_select
1092 , 'sql' => $sql
1093 , 'where' => $sql_where
1094 , 'order' => $sql_order
1095 , 'limit' => $sql_limit
1096 );
1097
1098 //debuge($return_res);
1099 return $return_res;
1100 }
1101
1102
1103 ////////////////////////////////////////////////////////////////////////////////
1104 // S Q L W H E R E
1105 ////////////////////////////////////////////////////////////////////////////////
1106
1107 /**
1108 * Get SQL W H E R E conditions for D a t e s of bookings
1109 *
1110 * @param string $wh_booking_date - Parameter from Booking Listing request (usually its number)
1111 * @param string $wh_booking_date2 - Parameter from Booking Listing request (usually its number)
1112 * @param string $pref - Optional. Prefix for table.
1113 * @return string - WHERE conditions for SQL
1114 */
1115 function wpbc_set_sql_where_for_dates( $wh_booking_date, $wh_booking_date2, $pref = 'dt.' ) {
1116
1117 $sql_where= '';
1118 if ($pref == 'dt.') { $and_pre = ' AND '; $and_suf = ''; }
1119 else { $and_pre = ''; $and_suf = ' AND '; }
1120
1121 // Actual
1122 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
1124
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
1128
1129
1130 } 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
1132
1133 } else if ($wh_booking_date === '3') { // All
1134 $sql_where = '';
1135
1136 } 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
1140
1141 } else if ($wh_booking_date === '5') { // Prior
1142 $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 ;
1145
1146 } 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 ;
1151
1152 } 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 ;
1155
1156 } 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 ;
1159
1160 } else { // Fixed
1161
1162 if ( $wh_booking_date !== '' )
1163 if ( strpos($wh_booking_date,':')===false ) // we are do not have the time in this date, so set it
1164 $sql_where.= $and_pre."( ".$pref."booking_date >= '" . $wh_booking_date . " 00:00:00' ) ".$and_suf;
1165 else $sql_where.= $and_pre."( ".$pref."booking_date >= '" . $wh_booking_date . "' ) ".$and_suf;
1166
1167 if ( $wh_booking_date2 !== '' )
1168 if ( strpos($wh_booking_date2,':')===false ) // we are do not have the time in this date, so set it
1169 $sql_where.= $and_pre."( ".$pref."booking_date <= '" . $wh_booking_date2 . " 23:59:59' ) ".$and_suf;
1170 else $sql_where.= $and_pre."( ".$pref."booking_date <= '" . $wh_booking_date2 . "' ) ".$and_suf;
1171 }
1172
1173 return $sql_where;
1174 }
1175
1176
1177 /**
1178 * 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
1179 *
1180 * @param type $wh_modification_date - Parameter from Booking Listing request (usually its number)
1181 * @param type $wh_modification_date2 - Parameter from Booking Listing request (usually its number)
1182 * @param string $pref - Optional. Prefix for table.
1183 * @return string - WHERE conditions for SQL
1184 */
1185 function wpbc_set_sql_where_for_modification_date( $wh_modification_date, $wh_modification_date2, $pref = 'bk.' ) {
1186
1187 $sql_where = '';
1188
1189 if ($pref == 'bk.') { $and_pre = ' AND '; $and_suf = ''; }
1190 else { $and_pre = ''; $and_suf = ' AND '; }
1191
1192 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
1195
1196 } else if ($wh_modification_date === '3') { // All
1197 $sql_where = '';
1198
1199 } else if ($wh_modification_date === '5') { // Prior
1200 $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 ;
1203
1204 } else { // Fixed
1205
1206 if ( $wh_modification_date !== '' )
1207 $sql_where.= $and_pre."( ".$pref."modification_date >= '" . $wh_modification_date . "' ) ".$and_suf;
1208
1209 if ( $wh_modification_date2 !== '' )
1210 $sql_where.= $and_pre."( ".$pref."modification_date <= '" . $wh_modification_date2 . "' ) ".$and_suf;
1211 }
1212
1213 return $sql_where;
1214 }
1215