PluginProbe
Booking Calendar / 11.5
Booking Calendar v11.5
11.9 11.8.4 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 All 205 releases
booking / core / timeline / v2 / wpbc-class-timeline_v2.php

wpbc-class-timeline_v2.php in Booking Calendar 11.5, at core/timeline/v2/wpbc-class-timeline_v2.php

3,684 lines 170.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php /**
2 * @version 1.1
3 * @package Booking Calendar
4 * @category Timeline for Admin Panel
5 * @author wpdevelop
6 *
7 * @web-site https://wpbookingcalendar.com/
8 * @email [email protected]
9 *
10 * @modified 2016-01-18
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
14
15
16 class WPBC_TimelineFlex {
17
18
19 public $bookings; // Booking objects from external function
20 public $booking_types; // Resources objects from external function
21
22 public $dates_array; // Dates for Timeline format
23 public $time_array_new; // Times for Timeline format
24
25 public $request_args; // Parsed paramaters
26
27 private $is_frontend; // Client ot Admin sides.
28
29 public $timeline_titles;
30
31 private $week_days_titles;
32 private $current_user_id;
33
34 private $html_client_id; // ID of border element at client side.
35 public $options; // FixIn: 7.0.1.50.
36
37 private $data_in_previous_cell; // FixIn: 8.5.2.6.
38
39 /**
40 * Exact booking scope resolved from a public booking hash.
41 *
42 * @var array|false
43 */
44 private $booking_hash_scope;
45
46 public function __construct(){// $bookings, $booking_types ) {
47
48 $this->reset_data_in_previous_cell();
49 $this->booking_hash_scope = false;
50
51 $this->options = array(); // FixIn: 7.0.1.50.
52
53 $this->html_client_id = false;
54
55 $this->current_user_id = 0;
56
57 $this->is_frontend = false;
58
59 // FixIn: 8.1.3.31.
60 $calendar_overview_start_time = get_bk_option( 'booking_calendar_overview_start_time' );
61 $calendar_overview_end_time = get_bk_option( 'booking_calendar_overview_end_time' );
62 $hours_limit = ( empty( $calendar_overview_start_time ) ? '0' : $calendar_overview_start_time )
63 . ','
64 . ( empty( $calendar_overview_end_time ) ? '24' : $calendar_overview_end_time );
65 $this->request_args = array(
66 'wh_booking_type' => '1'
67 , 'is_matrix' => false
68 , 'view_days_num' => '90'
69 , 'scroll_start_date' => ''
70 , 'scroll_day' => 0
71 , 'scroll_month' => 0
72 , 'wh_trash' => ''
73 , 'limit_hours' => $hours_limit // '0,24' //FixIn: 7.0.1.14 if ( ! ( ( $tt >= $start_hour_for_1day_view ) && ( $tt <= $end_hour_for_1day_view ) ) ) continue;
74 , 'only_booked_resources' => ( isset( $_REQUEST['only_booked_resources'] ) ) ? 1 : 0 /* phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing */
75 , 'booking_hash' => ( isset( $_REQUEST['booking_hash'] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST['booking_hash'] ) ) : '', /* phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing */
76
77 );
78
79 $this->timeline_titles = array(
80 'header_column1' => __('Resources', 'booking')
81 , 'header_column2' => __('Dates', 'booking')
82 , 'header_title' => __('Bookings', 'booking')
83 );
84
85
86 $this->week_days_titles = array(
87 'full' => array(
88 1 => __( 'Monday', 'booking' )
89 , 2 => __( 'Tuesday', 'booking' )
90 , 3 => __( 'Wednesday', 'booking' )
91 , 4 => __( 'Thursday', 'booking' )
92 , 5 => __( 'Friday', 'booking' )
93 , 6 => __( 'Saturday', 'booking' )
94 , 7 => __( 'Sunday', 'booking' )
95 )
96 , '3' => array( // FixIn: 7.0.1.11.
97 1 => __( 'Mon', 'booking' )
98 , 2 => __( 'Tue', 'booking' )
99 , 3 => __( 'Wed', 'booking' )
100 , 4 => __( 'Thu', 'booking' )
101 , 5 => __( 'Fri', 'booking' )
102 , 6 => __( 'Sat', 'booking' )
103 , 7 => __( 'Sun', 'booking' )
104 )
105 , '1' => array( //FixIn: 7.0.1.11 // FixIn: 8.7.7.14.
106 1 => mb_substr( __( 'Mon', 'booking' ), 0, -1 )
107 , 2 => mb_substr( __( 'Tue', 'booking' ), 0, -1 )
108 , 3 => mb_substr( __( 'Wed', 'booking' ), 0, -1 )
109 , 4 => mb_substr( __( 'Thu', 'booking' ), 0, -1 )
110 , 5 => mb_substr( __( 'Fri', 'booking' ), 0, -1 )
111 , 6 => mb_substr( __( 'Sat', 'booking' ), 0, -1 )
112 , 7 => mb_substr( __( 'Sun', 'booking' ), 0, -1 )
113 )
114 , 'short' => array(
115 1 => mb_substr( __( 'Mon', 'booking' ), 0, 1 )
116 , 2 => mb_substr( __( 'Tue', 'booking' ), 0, 1 )
117 , 3 => mb_substr( __( 'Wed', 'booking' ), 0, 1 )
118 , 4 => mb_substr( __( 'Thu', 'booking' ), 0, 1 )
119 , 5 => mb_substr( __( 'Fri', 'booking' ), 0, 1 )
120 , 6 => mb_substr( __( 'Sat', 'booking' ), 0, 1 )
121 , 7 => mb_substr( __( 'Sun', 'booking' ), 0, 1 )
122 )
123 );
124
125
126 }
127
128 /**
129 * Apply an exact booking and resource authorization scope to timeline SQL arguments.
130 *
131 * A booking hash is a bearer credential for one booking. It must never be
132 * converted into a customer-data keyword or used to broaden the query. Invalid
133 * hashes deliberately select an impossible booking ID so processing fails closed.
134 *
135 * @param array $query_args Clean timeline query arguments.
136 * @param string $booking_hash Public booking hash supplied by the timeline request.
137 * @return array Query arguments restricted to the authorized booking, when applicable.
138 */
139 private function wpbc_apply_booking_hash_scope_to_query_args( $query_args, $booking_hash ) {
140 $this->booking_hash_scope = false;
141 $booking_hash = sanitize_text_field( (string) $booking_hash );
142
143 if ( empty( $booking_hash ) ) {
144 return $query_args;
145 }
146
147 $this->request_args['only_booked_resources'] = 1;
148 $booking_scope = wpbc_hash__get_booking_id__resource_id( $booking_hash );
149
150 if ( empty( $booking_scope ) || count( $booking_scope ) < 2 ) {
151 $query_args['wh_booking_id'] = '-1';
152 return $query_args;
153 }
154
155 $booking_id = absint( $booking_scope[0] );
156 $resource_id = absint( $booking_scope[1] );
157 $booking_row = wpbc_db_get_booking_details( $booking_id );
158
159 if ( empty( $booking_id ) || empty( $resource_id ) || empty( $booking_row ) || $resource_id !== absint( $booking_row->booking_type ) ) {
160 $query_args['wh_booking_id'] = '-1';
161 return $query_args;
162 }
163
164 $this->booking_hash_scope = array(
165 'booking_id' => $booking_id,
166 'resource_id' => $resource_id,
167 );
168 $query_args['wh_booking_id'] = (string) $booking_id;
169 $query_args['wh_booking_type'] = (string) $resource_id;
170
171 return $query_args;
172 }
173
174 /**
175 * Verify that a returned booking remains inside the resolved hash scope.
176 *
177 * This rendering-layer check is intentionally independent of the SQL restriction
178 * so a future query regression cannot expose another booking's popover data.
179 * Timelines without a booking hash retain their configured public presentation.
180 *
181 * @param int $booking_id Booking ID about to be rendered.
182 * @param array $bookings Booking objects keyed by booking ID.
183 * @return bool True when popover rendering is authorized for this row.
184 */
185 private function wpbc_is_booking_authorized_for_hash( $booking_id, $bookings ) {
186 if ( empty( $this->request_args['booking_hash'] ) ) {
187 return true;
188 }
189
190 $booking_id = absint( $booking_id );
191 if ( empty( $this->booking_hash_scope ) || $booking_id !== $this->booking_hash_scope['booking_id'] || empty( $bookings[ $booking_id ] ) ) {
192 return false;
193 }
194
195 return $this->booking_hash_scope['resource_id'] === absint( $bookings[ $booking_id ]->booking_type );
196 }
197
198
199 /**
200 * Rezet data in previos cell
201 */
202 private function reset_data_in_previous_cell(){
203
204 $this->data_in_previous_cell = array(
205 'bookings_in_cell' => array(),
206 'previous_month' => ''
207 );
208
209 }
210
211 // -----------------------------------------------------------------------------------------------------------------
212 /**
213 * Init Timeline From page shortcode
214 *
215 * @param array $attr = array(
216 'wh_booking_type' => ''
217 , 'is_matrix' => false
218 , 'view_days_num' => '30'
219 , 'scroll_start_date' => ''
220 , 'scroll_day' => 0
221 , 'scroll_month' => 0
222 );
223 */
224 public function client_init( $attr ) {
225
226 $this->is_frontend = true;
227
228 // FixIn: 7.0.1.50.
229 if ( isset( $attr['options'] ) ) {
230
231 $shortcode_param__options = $attr['options'];
232 $shortcode_param__options = html_entity_decode( $shortcode_param__options ); // FixIn: 9.8.15.6.
233 $custom_params = array();
234 if (! empty($shortcode_param__options)) {
235 $param ='\s*([^\s]+)=[\'"]{1}([^\'"]+)[\'"]{1}\s*'; // Find all possible options
236 $pattern_to_search='%\s*{([^\s]+)' . $param .'}\s*[,]?\s*%';
237 preg_match_all($pattern_to_search, $shortcode_param__options, $matches, PREG_SET_ORDER);
238 //debuge($matches);
239 /**
240 * [bookingtimeline ... options='{resource_link 3="http://beta/resource-apartment3-id3/"},{resource_link 4="http://beta/resource-3-id4/"}' ... ]
241 [0] => {resource_link 3="http://beta/resource-apartment3-id3/"},
242 [1] => resource_link // Name
243 [2] => 3 // ID
244 [3] => http://beta/resource-apartment3-id3/ // Value
245 */
246 foreach ( $matches as $matche_value ) {
247
248 if ( ! isset( $this->options[ $matche_value[1] ] ) ) {
249 $this->options[ $matche_value[1] ] = array();
250 }
251 $this->options[ $matche_value[1] ][ $matche_value[2] ] = $matche_value[3];
252 }
253 }
254
255 //debuge($this->options);
256 }
257 // FixIn: 7.0.1.50.
258
259
260 //Ovverride some parameters
261 //if ( isset( $attr['resource_id'] ) ) { $attr['type'] = $attr['resource_id']; }
262 if ( isset( $attr['type'] ) ) {
263 $attr['wh_booking_type'] = $attr['type']; //Instead of 'wh_booking_type' paramter in shortcode is used 'type' parameter
264 }
265
266 // Get paramaters from shortcode paramaters
267 $this->define_request_view_params_from_params( $attr );
268
269 if ( ! $this->request_args['is_matrix'] )
270 $this->timeline_titles['header_column1'] = '';
271
272 //Override any possible titles from shortcode paramaters
273 $this->timeline_titles = wp_parse_args( $attr, $this->timeline_titles );
274
275 // Get clean parameters to request booking data
276 $args = $this->wpbc_get_clean_paramas_from_request_for_timeline();
277
278
279 // A public booking hash authorizes only its exact booking and resource.
280 $args = $this->wpbc_apply_booking_hash_scope_to_query_args( $args, $this->request_args['booking_hash'] );
281
282
283 // Get booking data
284 $bk_listing = wpbc_get_bookings_objects( $args );
285 $this->bookings = $bk_listing['bookings'];
286 $this->booking_types = $bk_listing['resources'];
287
288 //Get Dates and Times for Timeline format
289 //debuge($this->bookings[84]);
290 $bookings_date_time = $this->wpbc_get_dates_and_times_for_timeline( $this->bookings );
291 $this->dates_array = $bookings_date_time[0];
292 $this->time_array_new = $bookings_date_time[1];
293 //debuge($this->time_array_new['2017-01-13']);
294
295
296 //$milliseconds = round(microtime(true) * 1000); //FixIn: 7.0.Beta.18
297 $milliseconds = wp_rand( 10000, 99999 );
298
299 $this->html_client_id = 'wpbc_timeline_' . $milliseconds;
300
301 return $this->html_client_id;
302 }
303
304
305 /**
306 * Init parameters after Ajax Navigation actions
307 *
308 * @param array $attr
309 * @return string html_client_id - exist from input parameters
310 */
311 public function ajax_init( $attr ) {
312
313 if ( ! defined( 'WPBC_TIMELINE_AJAX' ) ) { define( 'WPBC_TIMELINE_AJAX', true ); } // FixIn: 8.4.7.13.
314
315 // FixIn: 10.14.14.2.
316 $is_frontend = (bool) $attr['is_frontend'];
317
318 // Not front-end (or possibly changed parameter by attacker to see the bookings).
319 if ( ! $is_frontend ) {
320
321 // If this is not front-end -- admin side, then allow do this only for logged in users, with minimum user role, defined in the settings.
322 // Get minimum user role to access the Timeline in admin panel (Booking Listing and Timeline Overview (Calendar Overview).
323 $curr_user_role = get_bk_option( 'booking_user_role_booking' );
324
325 // Get current user.
326 $current_user = wpbc_get_current_user();
327 $user_role_map = array(
328 'administrator' => 10,
329 'editor' => 7,
330 'author' => 2,
331 'contributor' => 1,
332 'subscriber' => 0,
333 );
334
335 $level = 0;
336 if ( isset( $user_role_map[ $curr_user_role ] ) ) {
337 $level = $user_role_map[ $curr_user_role ];
338 }
339
340 if ( empty( $current_user ) || empty( $current_user->user_level ) || ( $current_user->user_level < $level ) ) {
341 // Security Fix: Enforce frontend mode for non-admins.
342 $attr['is_frontend'] = 1;
343 }
344 }
345
346 $this->is_frontend = (bool) $attr['is_frontend'];
347
348 //Ovverride some parameters
349 //if ( isset( $attr['resource_id'] ) ) { $attr['type'] = $attr['resource_id']; }
350 if ( isset( $attr['type'] ) ) {
351 $attr['wh_booking_type'] = $attr['type']; //Instead of 'wh_booking_type' paramter in shortcode is used 'type' parameter
352 }
353 //debuge($this->request_args, $attr);
354 // Get paramaters from shortcode paramaters
355 $this->define_request_view_params_from_params( $attr );
356
357 //debuge($this->request_args);
358 if ( ! $this->request_args['is_matrix'] ) {
359
360 switch ( $this->request_args['view_days_num'] ) {
361 case '90':
362 case '30':
363 if ( isset( $this->request_args['scroll_day'] ) ) $scroll_day = intval( $this->request_args['scroll_day'] );
364 else $scroll_day = 0;
365
366 // FixIn: 8.9.4.3.
367 // Here we need to define number of days to scroll depends from selected number of days to show.
368 $days_num_to_scroll = intval( get_bk_option( 'booking_timeline__month_mode__days_number_show' ) );
369 if ( empty( $days_num_to_scroll ) ) {
370 $days_num_to_scroll = 7;
371 }
372
373 if ( $attr['nav_step'] == '-1' ) {
374 $this->request_args['scroll_day'] = intval( $scroll_day - $days_num_to_scroll );
375 }
376 if ( $attr['nav_step'] == '1' ) {
377 $this->request_args['scroll_day'] = intval( $scroll_day + $days_num_to_scroll );
378 }
379
380 /*
381 * From Admin panel:
382 *
383 // Here we need to define number of days to scroll depends from selected number of days to show.
384 $days_num_to_scroll = intval( get_bk_option( 'booking_calendar_overview__day_mode__days_number_show' ) );
385 if ( empty( $days_num_to_scroll ) ) {
386 $days_num_to_scroll = 7;
387 }
388
389 $scroll_params = array( '&scroll_day='.intval( $scroll_day - $days_num_to_scroll * 2 ),
390 '&scroll_day='.intval( $scroll_day - $days_num_to_scroll ),
391 '&scroll_day=0',
392 '&scroll_day='.intval( $scroll_day + $days_num_to_scroll ),
393 '&scroll_day='.intval( $scroll_day + $days_num_to_scroll *2 ) );
394 $scroll_titles = array( __( 'Previous', 'booking' ) . ' ' . ( 2 * $days_num_to_scroll ) . ' ' . __( 'days', 'booking' ),
395 __( 'Previous', 'booking' ) . ' ' . $days_num_to_scroll . ' ' . __( 'days', 'booking' ),
396 __('Current week' ,'booking'),
397 __( 'Next', 'booking' ) . ' ' . $days_num_to_scroll . ' ' . __( 'days', 'booking' ),
398 __( 'Next', 'booking' ) . ' ' . ( 2 * $days_num_to_scroll ) . ' ' . __( 'days', 'booking' ) );
399 */
400 break;
401 default: // 365
402 if ( !isset( $this->request_args['scroll_month'] ) ) $this->request_args['scroll_month'] = 0;
403 $scroll_month = intval( $this->request_args['scroll_month'] );
404
405 if ( $attr['nav_step'] == '-1' ) $this->request_args['scroll_month'] = intval( $scroll_month - 1 );
406 if ( $attr['nav_step'] == '1' ) $this->request_args['scroll_month'] = intval( $scroll_month + 1 );
407 /*
408 $scroll_params = array( '&scroll_month='.intval($scroll_month-3),
409 '&scroll_month='.intval($scroll_month-1),
410 '&scroll_month=0',
411 '&scroll_month='.intval($scroll_month+1 ),
412 '&scroll_month='.intval($scroll_month+3) );
413 $scroll_titles = array( __('Previous 3 months' ,'booking'),
414 __('Previous month' ,'booking'),
415 __('Current month' ,'booking'),
416 __('Next month' ,'booking'),
417 __('Next 3 months' ,'booking') );*/
418 break;
419 }
420 } else { // Matrix
421
422 switch ( $this->request_args['view_days_num'] ) {
423 case '1': //Day
424 if ( isset( $this->request_args['scroll_day'] ) ) $scroll_day = intval( $this->request_args['scroll_day'] );
425 else $scroll_day = 0;
426
427 if ( $attr['nav_step'] == '-1' ) $this->request_args['scroll_day'] = intval( $scroll_day - 1 );
428 if ( $attr['nav_step'] == '1' ) $this->request_args['scroll_day'] = intval( $scroll_day + 1 );
429 /*
430 $scroll_params = array( '&scroll_day='.intval($scroll_day-7),
431 '&scroll_day='.intval($scroll_day-1),
432 '&scroll_day=0',
433 '&scroll_day='.intval($scroll_day+1 ),
434 '&scroll_day='.intval($scroll_day+7) );
435 $scroll_titles = array( __('Previous 7 days' ,'booking'),
436 __('Previous day' ,'booking'),
437 __('Current day' ,'booking'),
438 __('Next day' ,'booking'),
439 __('Next 7 days' ,'booking') );*/
440 break;
441
442 case '7': //Week
443
444 if ( isset( $this->request_args['scroll_day'] ) ) $scroll_day = intval( $this->request_args['scroll_day'] );
445 else $scroll_day = 0;
446
447 if ( $attr['nav_step'] == '-1' ) $this->request_args['scroll_day'] = intval( $scroll_day - 7 );
448 if ( $attr['nav_step'] == '1' ) $this->request_args['scroll_day'] = intval( $scroll_day + 7 );
449 /*
450 $scroll_params = array( '&scroll_day='.intval($scroll_day-4*7),
451 '&scroll_day='.intval($scroll_day-7),
452 '&scroll_day=0',
453 '&scroll_day='.intval($scroll_day+7 ),
454 '&scroll_day='.intval($scroll_day+4*7) );
455 $scroll_titles = array( __('Previous 4 weeks' ,'booking'),
456 __('Previous week' ,'booking'),
457 __('Current week' ,'booking'),
458 __('Next week' ,'booking'),
459 __('Next 4 weeks' ,'booking') );*/
460 break;
461
462 case '30':
463 case '60':
464 case '90': //3 months
465
466 if ( !isset( $this->request_args['scroll_month'] ) ) $this->request_args['scroll_month'] = 0;
467 $scroll_month = intval( $this->request_args['scroll_month'] );
468
469 if ( $attr['nav_step'] == '-1' ) $this->request_args['scroll_month'] = intval( $scroll_month - 1 );
470 if ( $attr['nav_step'] == '1' ) $this->request_args['scroll_month'] = intval( $scroll_month + 1 );
471 /*
472 $scroll_params = array( '&scroll_month='.intval($scroll_month-3),
473 '&scroll_month='.intval($scroll_month-1),
474 '&scroll_month=0',
475 '&scroll_month='.intval($scroll_month+1 ),
476 '&scroll_month='.intval($scroll_month+3) );
477 $scroll_titles = array( __('Previous 3 months' ,'booking'),
478 __('Previous month' ,'booking'),
479 __('Current month' ,'booking'),
480 __('Next month' ,'booking'),
481 __('Next 3 months' ,'booking') );*/
482 break;
483
484 default: // 30, 60, 90...
485 if ( !isset( $this->request_args['scroll_month'] ) ) $this->request_args['scroll_month'] = 0;
486 $scroll_month = intval( $this->request_args['scroll_month'] );
487
488 if ( $attr['nav_step'] == '-1' ) $this->request_args['scroll_month'] = intval( $scroll_month - 1 );
489 if ( $attr['nav_step'] == '1' ) $this->request_args['scroll_month'] = intval( $scroll_month + 1 );
490 /*
491 $scroll_params = array( '&scroll_month='.intval($scroll_month-3),
492 '&scroll_month='.intval($scroll_month-1),
493 '&scroll_month=0',
494 '&scroll_month='.intval($scroll_month+1 ),
495 '&scroll_month='.intval($scroll_month+3) );
496 $scroll_titles = array( __('Previous 3 months' ,'booking'),
497 __('Previous month' ,'booking'),
498 __('Current month' ,'booking'),
499 __('Next month' ,'booking'),
500 __('Next 3 months' ,'booking') );
501 */
502 break;
503 }
504 }
505
506 // Titles
507 if ( ! $this->request_args['is_matrix'] )
508 $this->timeline_titles['header_column1'] = '';
509
510 //Override any possible titles from shortcode paramaters
511 $this->timeline_titles = wp_parse_args( $attr, $this->timeline_titles );
512
513
514 // Get clean parameters to request booking data
515 $args = $this->wpbc_get_clean_paramas_from_request_for_timeline();
516
517
518 // Apply the same exact-booking scope to every unauthenticated navigation request.
519 $booking_hash = isset( $attr['booking_hash'] ) ? $attr['booking_hash'] : '';
520 $args = $this->wpbc_apply_booking_hash_scope_to_query_args( $args, $booking_hash );
521
522
523 // Get booking data
524 $bk_listing = wpbc_get_bookings_objects( $args );
525
526 $this->bookings = $bk_listing['bookings'];
527 $this->booking_types = $bk_listing['resources'];
528
529 //Get Dates and Times for Timeline format
530 $bookings_date_time = $this->wpbc_get_dates_and_times_for_timeline( $this->bookings );
531 $this->dates_array = $bookings_date_time[0];
532 $this->time_array_new = $bookings_date_time[1];
533
534
535 $this->html_client_id = $attr['html_client_id'];
536
537 return $this->html_client_id;
538 }
539
540
541 /**
542 * Define initial REQUEST parameters for Admin Panel and Get bookings and resources
543 */
544 public function admin_init() {
545
546 // User ////////////////////////////////////////////////////////////////
547 $user = wpbc_get_current_user();
548 $this->current_user_id = $user->ID;
549
550 $this->is_frontend = false;
551
552 // Get paramaters from REQUEST
553 $this->define_request_view_params();
554
555 if ( ! $this->request_args['is_matrix'] )
556 $this->timeline_titles['header_column1'] = '';
557
558 // debuge($this->request_args);
559
560 // Get clean parameters to request booking data
561 $args = $this->wpbc_get_clean_paramas_from_request_for_timeline();
562
563 // Get booking data
564 $bk_listing = wpbc_get_bookings_objects( $args );
565 $this->bookings = $bk_listing['bookings'];
566 $this->booking_types = $bk_listing['resources'];
567
568 //Get Dates and Times for Timeline format
569 $bookings_date_time = $this->wpbc_get_dates_and_times_for_timeline( $this->bookings );
570 $this->dates_array = $bookings_date_time[0];
571 $this->time_array_new = $bookings_date_time[1];
572 }
573
574
575 public function client_navigation( $param ) {
576 ?>
577 <script type="text/javascript">
578 wpbc_timeline_obj["<?php echo esc_js( $this->html_client_id ); ?>"] = {
579 is_frontend : "<?php echo esc_js( $this->is_frontend ? '1' : '0' ); ?>",
580 html_client_id : "<?php echo esc_js( $this->html_client_id ); ?>",
581 wh_booking_type : "<?php echo esc_js( $this->request_args['wh_booking_type'] ); ?>",
582 is_matrix : "<?php echo esc_js( $this->request_args['is_matrix'] ? '1' : '0' ); ?>",
583 view_days_num : "<?php echo esc_js( $this->request_args['view_days_num'] ); ?>",
584 scroll_start_date : "<?php echo esc_js( $this->request_args['scroll_start_date'] ); ?>",
585 scroll_day : "<?php echo esc_js( $this->request_args['scroll_day'] ); ?>",
586 scroll_month : "<?php echo esc_js( $this->request_args['scroll_month'] ); ?>",
587 'header_column1' : "<?php echo esc_js( $this->timeline_titles['header_column1'] ); ?>",
588 'header_column2' : "<?php echo esc_js( $this->timeline_titles['header_column2'] ); ?>",
589 'header_title' : "<?php echo esc_js( $this->timeline_titles['header_title'] ); ?>",
590 'wh_trash' : "<?php echo esc_js( $this->request_args['wh_trash'] ); ?>",
591 'limit_hours' : "<?php echo esc_js( $this->request_args['limit_hours'] ); ?>",
592 'only_booked_resources': "<?php echo esc_js( $this->request_args['only_booked_resources'] ); ?>",
593 'options' : '<?php echo wp_json_encode( $this->options ); ?>',
594 'booking_hash' : "<?php echo esc_js( $this->request_args['booking_hash'] ); ?>"
595 };
596 </script>
597 <div class="flex_tl_nav">
598 <div class="flex_tl_prev" href="javascript:void(0)"
599 onclick="javascript:wpbc_flextimeline_nav( wpbc_timeline_obj['<?php echo esc_js( $this->html_client_id ); ?>'], -1 );">
600 <a>&laquo;</a></div>
601 <div class="flex_tl_title"><?php echo esc_html( $param['title'] ); ?></div>
602 <div class="flex_tl_next" href="javascript:void(0)"
603 onclick="javascript:wpbc_flextimeline_nav( wpbc_timeline_obj['<?php echo esc_js( $this->html_client_id ); ?>'], 1 );">
604 <a>&raquo;</a></div>
605 </div>
606 <?php
607 }
608
609 // -----------------------------------------------------------------------------------------------------------------
610 // S u p p o r t
611 // -----------------------------------------------------------------------------------------------------------------
612 /**
613 * Get array of cleaned (limited number) paramas from request for getting bookings by "wpbc_get_bookings_objects"
614 *
615 * @return array
616 */
617 public function wpbc_get_clean_paramas_from_request_for_timeline() {
618
619 //Replacing in this file from gmdate( to date_i18n( to wpbc_datetime__no_wp_timezone( // FixIn: 9.9.0.18.
620 $start_year = intval( wpbc_datetime__no_wp_timezone( "Y" ) );
621 $start_month = intval( wpbc_datetime__no_wp_timezone( "m" ) );
622 $start_day = 1;
623 //debuge( '1.( $start_year, $start_month, $start_day , $this->request_args ', $start_year, $start_month, $start_day , $this->request_args );
624 if ( ! empty( $this->request_args['scroll_start_date'] ) ) { // scroll_start_date=2013-07-01
625
626 list( $start_year, $start_month, $start_day ) = explode( '-', $this->request_args['scroll_start_date'] );
627 $start_year = intval( $start_year );
628 $start_month = intval( $start_month );
629 $start_day = intval( $start_day );
630 }
631 //debuge( '2.( $start_year, $start_month, $start_day )', $start_year, $start_month, $start_day );
632 $scroll_day = 0;
633 $scroll_month = 0;
634
635 if ( ( isset( $this->request_args['view_days_num'] ) )
636 //&& ($this->request_args['view_days_num'] != '30')
637 )
638 $view_days_num = $this->request_args['view_days_num'];
639 else
640 $view_days_num = get_bk_option( 'booking_view_days_num' );
641
642 $view_days_num = intval( $view_days_num );
643 //debuge( '2.1( $view_days_num )', $view_days_num );
644 $is_matrix = (bool) $this->request_args['is_matrix'];
645
646 if ( $is_matrix ) {
647
648 switch ( $view_days_num ) {
649
650 case '1':
651 if ( empty( $this->request_args['scroll_start_date'] ) )
652 $start_day = intval( wpbc_datetime__no_wp_timezone( "d" ) ); // Today date
653
654 if ( isset( $this->request_args['scroll_day'] ) )
655 $scroll_day = intval( $this->request_args['scroll_day'] );
656
657 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) + intval( $scroll_day ) ), intval( $start_year ) );
658 $wh_booking_date = wpbc_datetime__no_wp_timezone( "Y-m-d", $real_date );
659
660 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) + intval( $scroll_day ) ), intval( $start_year ) );
661 $wh_booking_date2 = wpbc_datetime__no_wp_timezone( "Y-m-d", $real_date );
662 break;
663
664 case '7':
665 if ( empty( $this->request_args['scroll_start_date'] ) )
666 $start_day = intval( wpbc_datetime__no_wp_timezone( "d" ) ); //Today date
667 $start_week_day_num = intval( wpbc_datetime__no_wp_timezone( "w" ) );
668 $start_day_weeek = intval( get_bk_option( 'booking_start_day_weeek' ) ); //[0]:Sun .. [6]:Sut
669 if ( $start_week_day_num != $start_day_weeek ) {
670 for ( $d_inc = 1; $d_inc < 8; $d_inc++ ) { // Just get week back
671 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) - intval( $d_inc ) ), intval( $start_year ) );
672 $start_week_day_num = intval( wpbc_datetime__no_wp_timezone( "w", $real_date ) );
673 if ( $start_week_day_num == $start_day_weeek ) {
674 $start_day = intval( wpbc_datetime__no_wp_timezone( "d", $real_date ) );
675 $start_year = intval( wpbc_datetime__no_wp_timezone( "Y", $real_date ) );
676 $start_month = intval( wpbc_datetime__no_wp_timezone( "m", $real_date ) );
677 $d_inc = 9;
678 }
679 }
680 }
681
682 if ( isset( $this->request_args['scroll_day'] ) )
683 $scroll_day = intval( $this->request_args['scroll_day'] );
684
685 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) + intval( $scroll_day ) ), intval( $start_year ) );
686 $wh_booking_date = wpbc_datetime__no_wp_timezone( "Y-m-d", $real_date );
687
688 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) + 7 + intval( $scroll_day ) ), intval( $start_year ) );
689 $wh_booking_date2 = wpbc_datetime__no_wp_timezone( "Y-m-d", $real_date );
690 break;
691
692 case '30':
693 if ( isset( $this->request_args['scroll_month'] ) )
694 $scroll_month = intval( $this->request_args['scroll_month'] );
695
696 //debuge('3.$scroll_month, $start_month, $start_day, $start_year', $scroll_month, $start_month, $start_day, $start_year );
697 $real_date = mktime( 0, 0, 0, ( intval( $start_month ) + intval( $scroll_month ) ), intval( $start_day ), intval( $start_year ) );
698 //debuge('4.$real_date',$real_date);
699 $wh_booking_date = wpbc_datetime__no_wp_timezone( "Y-m-d", $real_date );
700 //debuge('5.$wh_booking_date',$wh_booking_date);
701 $real_date = mktime( 0, 0, 0, ( intval( $start_month ) + 1 + intval( $scroll_month ) ), ( intval( $start_day ) - 1 ), intval( $start_year ) );
702 //debuge('6.$real_date',$real_date);
703 $wh_booking_date2 = wpbc_datetime__no_wp_timezone( "Y-m-d", $real_date );
704 //debuge('7.$wh_booking_date2', $wh_booking_date2);
705 break;
706
707 case '60':
708 if ( isset( $this->request_args['scroll_month'] ) )
709 $scroll_month = intval( $this->request_args['scroll_month'] );
710
711 $real_date = mktime( 0, 0, 0, ( intval( $start_month ) + intval( $scroll_month ) ), intval( $start_day ), intval( $start_year ) );
712 $wh_booking_date = wpbc_datetime__no_wp_timezone( "Y-m-d", $real_date ); // '2012-12-01';
713
714 $real_date = mktime( 0, 0, 0, ( intval( $start_month ) + 2 + intval( $scroll_month ) ), ( intval( $start_day ) - 1 ), intval( $start_year ) );
715 $wh_booking_date2 = wpbc_datetime__no_wp_timezone( "Y-m-d", $real_date ); // '2013-02-31';
716 break;
717
718 ////////////////////////////////////////////////////////////////////////////////
719 default: // 30 - default
720 if ( isset( $this->request_args['scroll_month'] ) )
721 $scroll_month = intval( $this->request_args['scroll_month'] );
722
723 $real_date = mktime( 0, 0, 0, ( intval( $start_month ) + intval( $scroll_month ) ), intval( $start_day ), intval( $start_year ) );
724 $wh_booking_date = wpbc_datetime__no_wp_timezone( "Y-m-d", $real_date ); // '2012-12-01';
725
726 $real_date = mktime( 0, 0, 0, ( intval( $start_month ) + 1 + intval( $scroll_month ) ), ( intval( $start_day ) - 1 ), intval( $start_year ) );
727 $wh_booking_date2 = wpbc_datetime__no_wp_timezone( "Y-m-d", $real_date ); // '2012-12-31';
728 break;
729 }
730
731 } else { // Single resource
732
733 switch ( $view_days_num ) {
734
735 case '90':
736
737 if ( empty( $this->request_args['scroll_start_date'] ) )
738 $start_day = intval( wpbc_datetime__no_wp_timezone( "d" ) ); //Today Date
739 $start_week_day_num = intval( wpbc_datetime__no_wp_timezone( "w" ) );
740 $start_day_weeek = intval( get_bk_option( 'booking_start_day_weeek' ) ); //[0]:Sun .. [6]:Sut
741
742 if ( $start_week_day_num != $start_day_weeek ) {
743 for ( $d_inc = 1; $d_inc < 8; $d_inc++ ) { // Just get week back
744 $real_date = mktime( 0, 0, 0, intval($start_month), (intval($start_day) - intval($d_inc) ), intval($start_year) );
745 $start_week_day_num = intval( wpbc_datetime__no_wp_timezone( "w", $real_date ) );
746 if ( $start_week_day_num == $start_day_weeek ) {
747 $start_day = intval( wpbc_datetime__no_wp_timezone( "d", $real_date ) );
748 $start_year = intval( wpbc_datetime__no_wp_timezone( "Y", $real_date ) );
749 $start_month = intval( wpbc_datetime__no_wp_timezone( "m", $real_date ) );
750 $d_inc = 9;
751 }
752 }
753 }
754
755 if ( isset( $this->request_args['scroll_day'] ) )
756 $scroll_day = intval( $this->request_args['scroll_day'] );
757
758 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) + intval( $scroll_day ) ), intval( $start_year ) );
759 $wh_booking_date = wpbc_datetime__no_wp_timezone( "Y-m-d", $real_date ); // '2012-12-01';
760
761 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) + 7 * 12 + 7 + intval( $scroll_day ) ), intval( $start_year ) );
762 $wh_booking_date2 = wpbc_datetime__no_wp_timezone( "Y-m-d", $real_date ); // '2013-12-31';
763 break;
764
765 case '30':
766 if ( empty( $this->request_args['scroll_start_date'] ) )
767 $start_day = intval( wpbc_datetime__no_wp_timezone( "d" ) ); //Today Date
768
769 if ( isset( $this->request_args['scroll_day'] ) )
770 $scroll_day = intval( $this->request_args['scroll_day'] );
771
772 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) + intval( $scroll_day ) ), intval( $start_year ) );
773 $wh_booking_date = wpbc_datetime__no_wp_timezone( "Y-m-d", $real_date ); // '2012-12-01';
774
775 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) + 31 + intval( $scroll_day ) ), intval( $start_year ) );
776 $wh_booking_date2 = wpbc_datetime__no_wp_timezone( "Y-m-d", $real_date ); // '2013-12-31';
777 break;
778
779 default: // 365
780
781 if ( isset( $this->request_args['scroll_month'] ) )
782 $scroll_month = intval( $this->request_args['scroll_month'] );
783 else
784 $scroll_month = 0;
785
786 $real_date = mktime( 0, 0, 0, ( intval( $start_month ) + intval( $scroll_month ) ), intval( $start_day ), intval( $start_year ) );
787 $wh_booking_date = wpbc_datetime__no_wp_timezone( "Y-m-d", $real_date ); // '2012-12-01';
788
789 $real_date = mktime( 0, 0, 0, ( intval( $start_month ) + intval( $scroll_month ) + 13 ), ( intval( $start_day ) - 1 ), intval( $start_year ) );
790 $wh_booking_date2 = wpbc_datetime__no_wp_timezone( "Y-m-d", $real_date ); // '2013-12-31';
791
792 break;
793 }
794 }
795
796 $or_sort = '';
797
798 $args = array(
799 'wh_booking_type' => $this->request_args['wh_booking_type'],
800 'wh_approved' => '',
801 'wh_booking_id' => '',
802 'wh_is_new' => '',
803 'wh_pay_status' => 'all',
804 'wh_keyword' => '',
805 'wh_booking_date' => $wh_booking_date,
806 'wh_booking_date2' => $wh_booking_date2,
807 'wh_modification_date' => '3',
808 'wh_modification_date2' => '',
809 'wh_cost' => '',
810 'wh_cost2' => '',
811 'or_sort' => $or_sort,
812 'page_num' => '1',
813 'wh_trash' => $this->request_args['wh_trash'],
814 'limit_hours' => $this->request_args['limit_hours'],
815 'only_booked_resources' => $this->request_args['only_booked_resources'], // FixIn: 7.0.1.51.
816 'page_items_count' => '100000'
817 );
818 //debuge('8.',$args);
819 return $args;
820 }
821
822
823 /**
824 * Define View Params from $_REQUEST
825 */
826 public function define_request_view_params() {
827
828 // All other sanitizing and escaping are inside of this function wpbc_check_request_paramters(), which executing before. // FixIn: 8.9.2.1.
829
830 // Used once for comma seperated resources only.
831 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
832 if ( isset( $_REQUEST['wh_booking_type'] ) ) {
833 $this->request_args['wh_booking_type'] = wpbc_clean_digit_or_csd( $_REQUEST['wh_booking_type'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized // FixIn: 8.9.2.1.
834 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
835 } elseif ( isset( $_GET['booking_type'] ) ) {
836 $this->request_args['wh_booking_type'] = wpbc_clean_digit_or_csd( $_GET['booking_type'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized // FixIn: 8.9.2.1.
837 }
838 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
839 if ( ( isset( $_REQUEST['wh_booking_type'] ) ) && ( strpos( $_REQUEST['wh_booking_type'], ',' ) !== false ) ) {
840 $this->request_args['is_matrix'] = true;
841 }
842 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
843 if ( isset( $_REQUEST['view_days_num'] ) ) {
844 $this->request_args['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 */
845 }
846 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
847 if ( isset( $_REQUEST['scroll_start_date'] ) ) {
848 $this->request_args['scroll_start_date'] = sanitize_text_field( wp_unslash( $_REQUEST['scroll_start_date'] ) ); /* phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing */ /* FixIn: sanitize_unslash */
849 }
850 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
851 if ( isset( $_REQUEST['scroll_day'] ) ) {
852 $this->request_args['scroll_day'] = sanitize_text_field( wp_unslash( $_REQUEST['scroll_day'] ) ); /* phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing */ /* FixIn: sanitize_unslash */
853 }
854 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
855 if ( isset( $_REQUEST['scroll_month'] ) ) {
856 $this->request_args['scroll_month'] = sanitize_text_field( wp_unslash( $_REQUEST['scroll_month'] ) ); /* phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing */ /* FixIn: sanitize_unslash */
857 }
858 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
859 if ( isset( $_REQUEST['wh_trash'] ) ) {
860 $this->request_args['wh_trash'] = sanitize_text_field( wp_unslash( $_REQUEST['wh_trash'] ) ); /* phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing */ /* FixIn: sanitize_unslash */
861 }
862 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
863 if ( isset( $_REQUEST['limit_hours'] ) ) {
864 $this->request_args['limit_hours'] = sanitize_text_field( wp_unslash( $_REQUEST['limit_hours'] ) ); /* phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing */ /* FixIn: sanitize_unslash */
865 } // FixIn: 7.0.1.14.
866 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
867 if ( isset( $_REQUEST['only_booked_resources'] ) ) {
868 $this->request_args['only_booked_resources'] = 1;
869 } //$_REQUEST['only_booked_resources']; // FixIn: 7.0.1.51.
870 }
871
872
873 /**
874 * Define Request View Params
875 *
876 * @param array $param = = array(
877 * 'wh_booking_type' => ''
878 * , 'is_matrix' => false
879 * , 'view_days_num' => '30'
880 * , 'scroll_start_date' => ''
881 * , 'scroll_day' => 0
882 * , 'scroll_month' => 0
883 * );
884 */
885 public function define_request_view_params_from_params( $param ) {
886 //debuge( $param , $this->options , maybe_unserialize( wp_unslash( $param['options'] ) ) );die;
887 if ( isset( $param['wh_booking_type'] ) ) {
888 $this->request_args['wh_booking_type'] = $param['wh_booking_type'];
889 } // Used once for comma seperated resources only.
890
891 if ( ( isset( $param['wh_booking_type'] ) ) && ( strpos( $param['wh_booking_type'], ',' ) !== false ) ) {
892 $this->request_args['is_matrix'] = true;
893 }
894 if ( isset( $param['view_days_num'] ) ) {
895 $this->request_args['view_days_num'] = $param['view_days_num'];
896 }
897 if ( isset( $param['scroll_start_date'] ) ) {
898 $this->request_args['scroll_start_date'] = $param['scroll_start_date'];
899 }
900 if ( isset( $param['scroll_day'] ) ) {
901 $this->request_args['scroll_day'] = $param['scroll_day'];
902 }
903 if ( isset( $param['scroll_month'] ) ) {
904 $this->request_args['scroll_month'] = $param['scroll_month'];
905 }
906 if ( isset( $param['wh_trash'] ) ) {
907 $this->request_args['wh_trash'] = $param['wh_trash'];
908 }
909 if ( isset( $param['limit_hours'] ) ) {
910 $this->request_args['limit_hours'] = $param['limit_hours'];
911 } // FixIn: 7.0.1.14.
912 if ( isset( $param['only_booked_resources'] ) ) {
913 $this->request_args['only_booked_resources'] = $param['only_booked_resources'];
914 } // FixIn: 7.0.1.14.
915 if ( isset( $param['booking_hash'] ) ) {
916 $this->request_args['booking_hash'] = $param['booking_hash'];
917 } // FixIn: 8.1.3.5.
918 if ( ( empty( $this->options ) ) && ( isset( $param['options'] ) ) ) {
919 $this->options = json_decode( wp_unslash( $param['options'] ), true ); // FixIn: 9.2.1.8.
920 }
921
922 }
923
924
925 /**
926 * Get D A T E S and T I M E S from B o o k i n g s
927 *
928 * @param array $bookings - Booking input array
929 * @return array - array( $dates_array, $time_array_new )
930 */
931 public function wpbc_get_dates_and_times_for_timeline( $bookings ) {
932
933 // Generate: Array ( [0] => array(), [3600] => array(), [7200] => array(), ..... [43200] => array(),.... [82800] => array() )
934 $fixed_time_hours_array = array();
935 for ( $tt = 0; $tt < 24; $tt++ ) {
936 $fixed_time_hours_array[$tt * 60 * 60] = array();
937 }
938 //debuge($bookings);
939 // Dates array: { '2012-12-24' => array( Booking ID 1, Booking ID 2, ....), ... }
940 $dates_array = $time_array = array();
941 foreach ( $bookings as $bk ) {
942
943
944 /**
945 * Check situation , while we are having end time but do not have start time, like here:
946 * $bk->dates = Array(
947 [0] => stdClass Object (
948 [booking_id] => 911
949 [booking_date] => 2019-07-22 00:00:00
950 [approved] => 1
951 [type_id] => )
952
953 [1] => stdClass Object (
954 [booking_id] => 911
955 [booking_date] => 2019-07-23 00:00:00
956 [approved] => 1
957 [type_id] => )
958
959 [2] => stdClass Object (
960 [booking_id] => 911
961 [booking_date] => 2019-07-24 15:00:02
962 [approved] => 1
963 [type_id] => )
964 )
965 *
966 * So we need to add the new Start time before End time, like this:
967 *
968 [0] => stdClass Object (
969 [booking_id] => 911
970 [booking_date] => 2019-07-22 00:00:00
971 [approved] => 1
972 [type_id] => )
973
974 [1] => stdClass Object (
975 [booking_id] => 911
976 [booking_date] => 2019-07-23 00:00:00
977 [approved] => 1
978 [type_id] => )
979 [2] => stdClass Object (
980 [booking_id] => 911
981 [booking_date] => 2019-07-24 00:00:01
982 [approved] => 1
983 [type_id] => )
984 [2] => stdClass Object (
985 [booking_id] => 911
986 [booking_date] => 2019-07-24 15:00:02
987 [approved] => 1
988 [type_id] => )
989 *
990 */
991 $dates_to_check = array();
992 $is_started = 0;
993 foreach ( $bk->dates as $dt ) {
994
995 $last_second = substr( $dt->booking_date, -1);
996
997 // Count start end end times started.
998 switch ( $last_second ) {
999 case '1': // Start
1000 $is_started++;
1001 break;
1002 case '2': // End
1003 case '8': // FixIn: 9.0.1.2.
1004 $is_started--;
1005 break;
1006 case '0': // Full
1007 default:
1008 }
1009
1010 // Its means that we have now end time, but was not having start time
1011 if ( $is_started < 0 ) {
1012 $is_started++;
1013 $my_temp_start_time = clone $dt;
1014
1015 $temp_time = explode( ' ' ,$my_temp_start_time->booking_date );
1016 $temp_time = $temp_time[0] . ' 00:00:01';
1017
1018 $my_temp_start_time->booking_date = $temp_time;
1019 // Add start time day
1020 $dates_to_check[] = $my_temp_start_time;
1021 }
1022 $dates_to_check[] = $dt;
1023 }
1024
1025 if ( 0 != $is_started ) {
1026 ?><div class="warning_check_in_out_not_equal"><?php
1027 // FixIn: 9.2.4.5.
1028 ?><div style="margin:0 10px 10px;font-weight:600;font-size:1.1em;"><?php
1029 echo( 'Warning! Structure of your booking dates has an issue.');
1030 ?></div><?php
1031 ?><div style="margin:0 10px 30px;font-weight:400;font-size:1.1em;"><?php
1032 printf( 'Number of check in times != check out times in a booking, or check-in time is older than the check-out time on the same date in the same booking.' );
1033 ?></div><?php
1034 ?><div style="margin:10px;font-weight:600;font-size:1.05em;color:#752;"><?php
1035 printf( 'To resolve this issue, you need to delete the following bookings and create new bookings with the same booking details.' );
1036 ?></div><?php
1037 $bookings_to_del = array();
1038 for( $day_i = 0; $day_i <= ( count( $dates_to_check ) - 1 ); $day_i++) {
1039 $bookings_to_del[] = $dates_to_check[$day_i]->booking_id;
1040 }
1041 $bookings_to_del = array_unique( $bookings_to_del );
1042 for ( $bk_i = 0; $bk_i <= ( count( $bookings_to_del ) - 1 ); $bk_i ++ ) {
1043 $booking_id__to_del = $bookings_to_del [ $bk_i ];
1044
1045 ?><div style="margin:10px;font-weight:600;font-size:1.05em;"><?php
1046
1047 echo wp_kses_post( sprintf( 'Delete booking with %s', htmlspecialchars_decode( '<strong></strong><a href="' . esc_url( wpbc_get_bookings_url() . '&tab=vm_booking_listing&wh_booking_id=' . $booking_id__to_del ) . '">' . 'ID = ' . $booking_id__to_del . '</a></strong>' ) ) );
1048
1049 ?></div><?php
1050 }
1051
1052 ?><div style="margin:50px;font-weight:600;font-size:1.05em;"></div><?php
1053
1054 debuge( $dates_to_check, $is_started) ;
1055
1056 ?></div><script type="text/javascript"> jQuery( '.warning_check_in_out_not_equal' ).animate( {opacity: 1}, 15000 ).toggle(1000); </script><?php
1057 }
1058
1059
1060 foreach ( $dates_to_check as $dt ) {
1061 //foreach ( $bk->dates as $dt ) {
1062
1063 // Transform from MySQL date to PHP date
1064 $dt->booking_date = trim( $dt->booking_date );
1065 $dta = explode( ' ', $dt->booking_date );
1066 $tms = $dta[1];
1067 // FixIn: 8.2.1.21.
1068 //if ( substr( $dta[1], - 1 ) == '2' ) { continue; }
1069 $tms = explode( ':', $tms ); // array('13','30','40')
1070 $dta = $dta[0];
1071 $dta = explode( '-', $dta ); // array('2012','12','30')
1072 $php_dt = mktime( intval( $tms[0] ), intval( $tms[1] ), intval( $tms[2] ), intval( $dta[1] ), intval( $dta[2] ), intval( $dta[0] ) );
1073
1074 if ( ( isset( $dt->type_id ) ) && (!empty( $dt->type_id )) )
1075 $date_bk_res_id = $dt->type_id;
1076 else
1077 $date_bk_res_id = $bk->booking_type;
1078
1079 //FixIn: 9.9.0.18 - booking
1080 $my_date = wpbc_datetime__no_wp_timezone( "Y-m-d", $php_dt ); // '2012-12-01';
1081
1082 if ( !isset( $dates_array[$my_date] ) ) {
1083 $dates_array[$my_date] = array( array( 'id' => $bk->booking_id, 'resource' => $date_bk_res_id ) );
1084 } else {
1085 $dates_array[$my_date][] = array( 'id' => $bk->booking_id, 'resource' => $date_bk_res_id );
1086 }
1087
1088 //FixIn: 9.9.0.18 - booking
1089 $my_time = wpbc_datetime__no_wp_timezone( "H:i:s", $php_dt ); // '21:55:01';
1090
1091 $my_time_index = explode( ':', $my_time );
1092 $my_time_index = (int) ($my_time_index[0] * 60 * 60 + $my_time_index[1] * 60 + $my_time_index[2]);
1093
1094 $my_time = strtotime( $my_time ); // FixIn: 8.1.1.6.
1095
1096 if ( !isset( $time_array[$my_date] ) ) {
1097 $time_array[$my_date] = array( $my_time_index => array( $my_time => array( 'id' => $bk->booking_id, 'resource' => $date_bk_res_id ) ) );
1098 } else {
1099
1100 if ( !isset( $time_array[$my_date][$my_time_index] ) )
1101 $time_array[$my_date][$my_time_index] = array( $my_time => array( 'id' => $bk->booking_id, 'resource' => $date_bk_res_id ) );
1102 else {
1103 if ( !isset( $time_array[$my_date][$my_time_index][$my_time] ) )
1104 $time_array[$my_date][$my_time_index][$my_time] = array( 'id' => $bk->booking_id, 'resource' => $date_bk_res_id );
1105 else {
1106 $my_time_inc = 3;
1107 while ( isset( $time_array[$my_date][$my_time_index][$my_time + $my_time_inc] ) ) {
1108 $my_time_inc++;
1109 }
1110 //Just in case if we are have the booking in the same time, so we are
1111 $time_array[$my_date][$my_time_index][($my_time + $my_time_inc)] = array( 'id' => $bk->booking_id, 'resource' => $date_bk_res_id );
1112 }
1113 }
1114 }
1115 }
1116 }
1117
1118
1119 //debuge($time_array);
1120 // Sorting ..........
1121 foreach ( $time_array as $key => $value_t ) { // Sort the times from lower to higher
1122 ksort( $value_t );
1123 $time_array[$key] = $value_t;
1124 }
1125 ksort( $time_array ); // Sort array by dates from lower to higher.
1126 /* $time_array:
1127 $key_date $value_t
1128 [2012-12-13] => Array ( $tt_index $times_bk_id_array
1129 [44401] => Array ( [12:20:01] => 19)
1130 ),
1131 [2012-12-14] => Array (
1132 [10802] => Array([03:00:02] => 19),
1133 [43801] => Array([12:10:01] => 2)
1134 ),
1135 .... */
1136
1137 //debuge($time_array);
1138
1139 $time_array_new = array();
1140 foreach ( $time_array as $key_date => $value_t ) { // fill the $time_array_new - by bookings of full dates....
1141 $new_times_array = $fixed_time_hours_array; // Array ( [0] => Array, [3600] => Array, [7200] => Array .....
1142
1143 foreach ( $value_t as $tt_index => $times_bk_id_array ) { // [44401] => Array ( [12:20:01] => 19 ), .....
1144 $tt_index_round = floor( ($tt_index / 60) / 60 ) * 60 * 60; // 14400, 18000,
1145 $is_bk_for_full_date = $tt_index % 10; // 0, 1, 2
1146
1147 switch ( $is_bk_for_full_date ) {
1148 case 0: // Full date - fill every time slot
1149 foreach ( $new_times_array as $round_time_slot => $bk_id_array ) {
1150 $new_times_array[$round_time_slot] = array_merge( $bk_id_array, array_values( $times_bk_id_array ) );
1151 }
1152 //debuge('$time_array[$key_date][$tt_index]',$time_array[$key_date][$tt_index], $round_time_slot);
1153 unset( $time_array[$key_date][$tt_index] );
1154 break;
1155
1156 case 1: break;
1157 case 2: break;
1158 default: break;
1159 }
1160 }
1161 if ( count( $time_array[$key_date] ) == 0 )
1162 unset( $time_array[$key_date] );
1163
1164 $time_array_new[$key_date] = $new_times_array;
1165 }
1166 //$time_array_new - Array filled by bookings FOR FULL DAY booking only
1167
1168 //debuge($time_array_new);
1169
1170
1171 foreach ( $time_array as $key_date => $value_t ) {
1172 $new_times_array_for_day_start = $new_times_array_for_day_end = array();
1173 foreach ( $value_t as $tt_index => $times_bk_id_array ) { // [44401] => Array ( [12:20:01] => 19 ), .....
1174 $tt_index_round = floor( ($tt_index / 60) / 60 ) * 60 * 60; // 14400, 18000,
1175 //debuge($tt_index, $tt_index_round);
1176 $is_bk_for_full_date = $tt_index % 10; // 0, 1, 2
1177
1178 if ( $is_bk_for_full_date == 1 ) {
1179 if ( !isset( $new_times_array_for_day_start[$tt_index_round] ) )
1180 $new_times_array_for_day_start[$tt_index_round] = array();
1181 $new_times_array_for_day_start[$tt_index_round] = array_merge( $new_times_array_for_day_start[$tt_index_round], array_values( $times_bk_id_array ) );
1182 }
1183 if ( $is_bk_for_full_date == 2 ) {
1184
1185 // Its mean that the booking is finished exactly at the beginig of this hour,
1186 // so we will not fill the end of booking in this hour, but in previous
1187 if ( ($tt_index_round - $tt_index) == -2 ) {
1188 $tt_index_round = $tt_index_round - 60 * 60;
1189 }
1190
1191 if ( !isset( $new_times_array_for_day_end[$tt_index_round] ) )
1192 $new_times_array_for_day_end[$tt_index_round] = array();
1193 $new_times_array_for_day_end[$tt_index_round] = array_merge( $new_times_array_for_day_end[$tt_index_round], array_values( $times_bk_id_array ) );
1194 }
1195 }
1196 $time_array[$key_date] = array( 'start' => $new_times_array_for_day_start, 'end' => $new_times_array_for_day_end );
1197 }
1198
1199 //debuge($time_array);
1200 //$time_array['2019-07-24']['start'][0] = $time_array['2019-07-24']['end'][82800];
1201
1202 /* $time_array
1203 [2012-12-24] => Array
1204 (
1205 [start] => Array (
1206 [68400] => Array ( [0] => 15 ) )
1207 [end] => Array (
1208 [64800] => Array ( [0] => 6 ) )
1209
1210 ) */
1211 $fill_this_date = array();
1212 //debuge($time_array_new['2017-01-13']);
1213
1214 //debuge($time_array_new);
1215 // Fil specific times based on start and end times
1216 foreach ( $time_array_new as $ddate => $ttime_round_array ) {
1217 foreach ( $ttime_round_array as $ttime_round => $bk_id_array ) { // [3600] => Array( [0] => Array ( [id] => 214 [resource] => 9 ), [1] => Array ( [id] => 154 [resource] => 7
1218
1219 //if ('2019-11-27' == $ddate ) {
1220 //debuge( ' $fill_this_date', $dates_array[ $ddate ], $fill_this_date );
1221 //}
1222
1223 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1224 /**
1225 * Search for situation, when at some previous date was started some booking at specific start time, like:
1226 * Booking #77: "October 30 18:00; December 4; December 25 20:00"
1227 * This booking exist in $fill_this_date - array ( [0] => array( [id] => 77, [resource] => 1 ) )
1228 *
1229 * but at current date "November 6" (where start other Booking #76: November 6 18:00; November 13; November 27 20:00"
1230 * this booking #77 does not exist at all !!!
1231 * so we nee to remove this booking(s) from array $fill_this_date
1232 */
1233 // FixIn: 8.7.1.1.
1234 if(1){
1235 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1236 // Search to remove
1237 $remove_arr_keys = array();
1238 foreach ( $fill_this_date as $is_remove_key => $is_remove_value ) {
1239 /**
1240 * Remove elements from $fill_this_date
1241 * if such elements does not exist in $dates_array[$ddate]
1242 */
1243 if ( ! in_array( $is_remove_value, $dates_array[ $ddate ] ) ) {
1244 $remove_arr_keys[] = $is_remove_key;
1245 //if ($is_remove_value['id']==76) {
1246 //debuge('$ddate,$ttime_round_array',$ddate);
1247 //}
1248 }
1249 }
1250 // Removing
1251 foreach ( $remove_arr_keys as $is_remove_key ) {
1252 unset($fill_this_date[$is_remove_key]); // Remove item at index 1 which is 'for'
1253 }
1254 $fill_this_date = array_values($fill_this_date); // Re-index the array elements
1255 }
1256 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1257
1258 //if ('2019-11-27' == $ddate ) {
1259 //debuge( 'updated $fill_this_date', $fill_this_date );
1260 //}
1261
1262
1263 if ( isset( $time_array[$ddate] ) ) {
1264
1265 if ( isset( $time_array[$ddate]['start'][$ttime_round] ) ) // array
1266 $fill_this_date = array_merge( $fill_this_date, array_values( $time_array[$ddate]['start'][$ttime_round] ) );
1267
1268 //debuge($fill_this_date);
1269
1270 $time_array_new[$ddate][$ttime_round] = array_merge( $time_array_new[$ddate][$ttime_round], $fill_this_date );
1271 //debuge('$ttime_round',$ttime_round);
1272 //debuge($ddate, $ttime_round, $time_array_new[$ddate][$ttime_round]);
1273
1274 //FixIn: 7.0.1.16 - advanced checking about delettion of times in $time_array[$ddate]['end']
1275
1276 // End array checking for deleting.
1277 if ( isset( $time_array[$ddate]['end'][$ttime_round] ) ) // array
1278 foreach ( $time_array[$ddate]['end'][$ttime_round] as $toDelete ) {
1279 //debuge($ddate, $ttime_round, $fill_this_date);
1280 //if ( $ddate == '2019-07-24' ) {
1281 // debuge('$toDelete, $fill_this_date',$toDelete, $fill_this_date);
1282 //}
1283 //debuge($toDelete);
1284 $fill_this_date_keys_to_delete = array();
1285 foreach ( $fill_this_date as $fill_this_date_key => $check_element_array ) { // [0] => Array ( [id] => 54 [resource] => 5 )
1286 //debuge($ddate,'$toDelete, $check_element_array', $toDelete, $check_element_array);
1287 if ( // Check if arrays equals - identical
1288 ( is_array( $toDelete ) && is_array( $check_element_array ) )
1289 && ( count( $toDelete ) == count( $check_element_array ) )
1290 && ( array_diff( $toDelete, $check_element_array ) === array_diff( $check_element_array, $toDelete ) )
1291 ) {
1292 $fill_this_date_keys_to_delete[] = $fill_this_date_key; // $toDelete element exist so save key in original array
1293 }
1294 }
1295
1296
1297 //FixIn: on 2019-07-24 14:22
1298 /**
1299 // Fix, when we are having END time but was not having START time (usually when first booking
1300 // was booked for entire day, and last day booking, have the end time.
1301 // So in this case at day with end time we need to fill all "round times" with End time data
1302 */
1303 // FixIn: 8.7.1.1.
1304 if(1)
1305 if ( empty( $fill_this_date_keys_to_delete ) ) {
1306 // Fill the date by data $toDelete
1307 foreach ( $time_array_new[ $ddate ] as $time_round_refill => $time_array_new_value_refill ) {
1308
1309 if ( $time_round_refill <= $ttime_round ) {
1310 // Refill
1311 $time_array_new[ $ddate ][ $time_round_refill ][] = $toDelete;
1312 }
1313 }
1314 }
1315
1316
1317 //debuge(' $fill_this_date_keys_to_delete ',$fill_this_date_keys_to_delete );
1318 $fill_this_date_new = array();
1319 foreach ( $fill_this_date as $fill_this_date_key => $fill_this_date_value ) {
1320 if ( ! in_array( $fill_this_date_key, $fill_this_date_keys_to_delete ) ) {
1321 $fill_this_date_new[] = $fill_this_date_value;
1322 }
1323 }
1324 $fill_this_date = $fill_this_date_new; // Reassign cleared array (with deleted values)
1325
1326 //debuge($toDelete);
1327 if ( !empty( $fill_this_date ) ) {
1328 // $fill_this_date = array_diff( $fill_this_date, array( $toDelete ) );
1329
1330 //if ( $ddate == '2017-01-13' ) {
1331 // debuge('AFTER:: $toDelete, $fill_this_date',$toDelete, $fill_this_date);
1332 //}
1333 }
1334 }
1335 }
1336 }
1337 }
1338 //debuge( '$dates_array, $time_array_new',$dates_array, $time_array_new );
1339 return array( $dates_array, $time_array_new );
1340 }
1341
1342
1343 // -----------------------------------------------------------------------------------------------------------------
1344 // C a l e n d a r T i m e l i n e ///////////////////////////////
1345 // -----------------------------------------------------------------------------------------------------------------
1346 private function wpbc_dates_only_of_specific_resource( $booked_dates_array, $resource_id, $bookings ) {
1347
1348 foreach ( $booked_dates_array as $key => $value ) {
1349
1350 $new_array = array();
1351 foreach ( $value as $bk_id ) {
1352 if ( $bk_id['resource'] == $resource_id ) {
1353 $new_array[] = $bk_id['id'];
1354 }
1355 }
1356 if ( !empty( $new_array ) )
1357 $booked_dates_array[$key] = $new_array;
1358 else
1359 unset( $booked_dates_array[$key] );
1360 }
1361 return $booked_dates_array;
1362 }
1363
1364
1365 private function wpbc_times_only_of_specific_resource( $time_array_new, $resource_id, $bookings ) {
1366
1367 foreach ( $time_array_new as $date_key => $times_array ) {
1368
1369 foreach ( $times_array as $time_key => $value ) {
1370
1371 $new_array = array();
1372 foreach ( $value as $bk_id ) {
1373
1374 if ( $bk_id['resource'] == $resource_id ) {
1375 $new_array[] = $bk_id['id'];
1376 }
1377 }
1378 $time_array_new[$date_key][$time_key] = $new_array;
1379 }
1380 }
1381 return $time_array_new;
1382 }
1383
1384
1385 private function wpbc_write_bk_id_css_classes( $prefix, $previous_booking_id ) {
1386
1387 if ( (!isset( $previous_booking_id )) || (empty( $previous_booking_id )) )
1388 return '';
1389
1390 if ( is_string( $previous_booking_id ) )
1391 $bk_id_array = explode( ',', $previous_booking_id );
1392 else if ( is_array( $previous_booking_id ) )
1393 $bk_id_array = $previous_booking_id;
1394 else // Some Unknown situation
1395 return '';
1396
1397 $bk_id_array = array_unique( $bk_id_array );
1398
1399 // If we are have several bookings, so add this special class
1400 if ( count( $bk_id_array ) > 1 )
1401 $css_class = 'here_several_bk_id ';
1402 else
1403 $css_class = '';
1404
1405 foreach ( $bk_id_array as $bk_id ) {
1406 $css_class .= $prefix . $bk_id . ' ';
1407 }
1408
1409 return $css_class;
1410 }
1411
1412
1413 // -----------------------------------------------------------------------------------------------------------------
1414 // Header
1415 // -----------------------------------------------------------------------------------------------------------------
1416 /** Header */
1417 public function wpbc_show_timeline_header_row( $start_date = false ) {
1418
1419 $current_resource_id = '';
1420 $is_matrix = $this->request_args['is_matrix'];
1421 $view_days_num = $this->request_args['view_days_num'];
1422 $start_hour_for_1day_view = 0; // FixIn: 7.0.1.14.
1423 $end_hour_for_1day_view = 24;
1424 $limit_hours = 24;
1425
1426 if ( $is_matrix ) {
1427
1428 // MATRIX VIEW
1429 switch ( $view_days_num ) {
1430 case '1':
1431 $days_num = 1;
1432 $dwa = $this->week_days_titles['full'];
1433 $time_selles_num = 24;
1434 if ( isset( $this->request_args[ 'limit_hours' ] ) ) { // FixIn: 7.0.1.14.
1435 $limit_hours = explode(',',$this->request_args[ 'limit_hours' ]);
1436 $start_hour_for_1day_view = intval( $limit_hours[0] );
1437 $end_hour_for_1day_view = intval( $limit_hours[1] );
1438 $limit_hours = $limit_hours[1] - $limit_hours[0];
1439 }
1440 break;
1441 case '7':
1442 $days_num = 7;
1443 //$dwa = $this->week_days_titles['3'];
1444 $dwa = $this->week_days_titles['1'];
1445 $time_selles_num = 1;
1446 break;
1447 case '30':
1448 $days_num = 31;
1449 $days_num = intval( wpbc_datetime__no_wp_timezone('t',$start_date) ); // num of days in the specific month, wchih relative to $real_date from header // FixIn: 7.0.1.47.
1450 $dwa = $this->week_days_titles['1'];
1451 $time_selles_num = 1;
1452 break;
1453 case '60':
1454 $days_num = 62;
1455 //$dwa = $this->week_days_titles['short'];
1456 $dwa = $this->week_days_titles['1'];
1457 $time_selles_num = 1;
1458 break;
1459 default: // 30
1460 $days_num = 31;
1461 $dwa = $this->week_days_titles['3'];
1462 $time_selles_num = 1;
1463 break;
1464 }
1465
1466 } else {
1467
1468 switch ( $view_days_num ) {
1469 case '90':
1470 $days_num = 7;
1471 $dwa = $this->week_days_titles['3'];
1472 $time_selles_num = 1;
1473 break;
1474 case '365':
1475 $days_num = 31; // FixIn: 8.7.6.5.
1476 //$days_num = intval( wpbc_datetime__no_wp_timezone('t',$start_date) ); // num of days in the specific month, wchih relative to $real_date from header // FixIn: 7.0.1.47.
1477 $dwa = $this->week_days_titles['3'];
1478 $time_selles_num = 1;
1479 break;
1480 default: // 30
1481 $days_num = 1;
1482 $dwa = $this->week_days_titles['full'];
1483 $time_selles_num = 24;
1484 if ( isset( $this->request_args[ 'limit_hours' ] ) ) { // FixIn: 7.0.1.14.
1485 $limit_hours = explode(',',$this->request_args[ 'limit_hours' ]);
1486 $start_hour_for_1day_view = intval( $limit_hours[0] );
1487 $end_hour_for_1day_view = intval( $limit_hours[1] );
1488 $limit_hours = $limit_hours[1] - $limit_hours[0];
1489 }
1490 break;
1491 }
1492 }
1493
1494 if ( $start_date === false ) {
1495
1496 if ( ! empty( $this->request_args['scroll_start_date'] ) )
1497 list( $start_year, $start_month, $start_day ) = explode( '-', $this->request_args['scroll_start_date'] ); // scroll_start_date=2013-07-01
1498 else
1499 list( $start_year, $start_month, $start_day ) = explode( '-', wpbc_datetime__no_wp_timezone( 'Y-n-j' ) );
1500
1501 } else {
1502 list( $start_year, $start_month, $start_day ) = explode( '-', wpbc_datetime__no_wp_timezone( 'Y-m-d', $start_date ) );
1503 }
1504
1505 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1506 // Month Line
1507 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1508 ?><div class="flex_tl_dates_bar flex_tl_dates_bar_month"><?php
1509 $previous_month = '';
1510 //Scroll months Firstly
1511 for ( $d_inc = 0; $d_inc < $days_num; $d_inc++ ) {
1512
1513 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) + intval( $d_inc ) ), intval( $start_year ) );
1514 $yy = wpbc_datetime__no_wp_timezone( "Y", $real_date ); //2012
1515 $mm = wpbc_datetime__no_wp_timezone( "m", $real_date ); //09
1516 $dd = wpbc_datetime__no_wp_timezone( "d", $real_date ); //31
1517 $ww = wpbc_datetime__no_wp_timezone( "N", $real_date ); //7
1518 $day_week = $dwa[$ww]; //Su
1519
1520 $month_title = '';
1521 $month_class = '';
1522
1523
1524 if ( ($view_days_num == 30) || ($view_days_num == 60) ) {
1525 if (( (intval($ww)-1) === intval(get_bk_option( 'booking_start_day_weeek' )) )){
1526 $month_class = ' new_month ';
1527 }
1528 } else {
1529 if(( $previous_month != $mm ) || ( 1 == $dd )){
1530 $month_class = ' new_month ';
1531 }
1532 }
1533 if ($month_class == ' new_month '){
1534 $previous_month = $mm;
1535 $month_title = wpbc_datetime__no_wp_timezone( "F", $real_date ); //09
1536 }
1537
1538 ?>
1539 <div class="<?php echo implode(' ', array(
1540 'flex_tl_day_cell',
1541 'flex_tl_day_cell_header',
1542 'flex_time_in_days_num_' . esc_attr( $view_days_num ),
1543 esc_attr( $month_class )
1544 )); ?>"
1545 ><?php
1546 // New Month !
1547 if ( $month_title != '' ) {
1548 ?>
1549 <div class="in_cell_month_year"><?php
1550
1551 if ( $is_matrix ) {
1552
1553 echo esc_attr( $dd . ' ' . $month_title . ', ' . $yy );
1554
1555 if ( '1' == $view_days_num ) {
1556 echo ' &nbsp; (' . esc_attr( $day_week ) . ')';
1557 }
1558
1559 } else {
1560 if ( '30' == $view_days_num ) {
1561 //echo '(' . esc_attr($day_week) . ') &nbsp; ' . esc_attr($dd) . ' ';
1562 }
1563 }
1564 ?></div><?php
1565 }
1566 ?> </div> <?php
1567 }
1568 ?>
1569 </div><?php
1570
1571
1572 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1573 // Dates / Times Line
1574 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1575 ?><div class="flex_tl_dates_bar <?php echo esc_attr( $is_matrix ? ' flex_tl_matrix_resources ' : ' flex_tl_single_resource ' ); ?>"
1576 id="timeline_scroller<?php echo esc_attr( $current_resource_id ); ?>"
1577 ><?php
1578 $previous_month = '';
1579
1580 $bk_admin_url_today = wpbc_get_params_in_url( wpbc_get_bookings_url( false, false ), array( 'scroll_month', 'scroll_day', 'scroll_start_date' ) );
1581
1582 for ( $d_inc = 0; $d_inc < $days_num; $d_inc++ ) {
1583
1584 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) + intval( $d_inc ) ), intval( $start_year ) );
1585
1586 if ( wpbc_datetime__no_wp_timezone( 'm.d.Y' ) == wpbc_datetime__no_wp_timezone( "m.d.Y", $real_date ) )
1587 $is_today = ' today_date ';
1588 else
1589 $is_today = '';
1590
1591 $yy = wpbc_datetime__no_wp_timezone( "Y", $real_date ); //2012
1592 $mm = wpbc_datetime__no_wp_timezone( "m", $real_date ); //09
1593 $dd = wpbc_datetime__no_wp_timezone( "d", $real_date ); //31
1594 $ww = wpbc_datetime__no_wp_timezone( "N", $real_date ); //7
1595 $day_week = $dwa[$ww]; //Su
1596
1597 $day_title = $dd . ' ' . $day_week;
1598 if ( $is_matrix ) {
1599 if ( $view_days_num == 1 ) {
1600 $day_title = '<div class="in_cell_day_num">' . esc_html__( 'Times', 'booking' ) . '</div>';
1601 }
1602 if ( $view_days_num == 7 ) {
1603 $day_title = '<div class="in_cell_day_num">' . $dd . '</div><div class="in_cell_day_week">' . $day_week . '</div>';
1604 }
1605 if ( $view_days_num == 30 ) {
1606 $day_title = '<div class="in_cell_day_num">' . $dd . '</div><div class="in_cell_day_week">' . $day_week . '</div>';
1607 }
1608 if ( $view_days_num == 60 ) {
1609 $day_title = '<div class="in_cell_day_num">' . $dd . '</div><div class="in_cell_day_week">' . $day_week . '</div>';
1610 }
1611 } else {
1612 if ( $view_days_num == 30 ) {
1613 $day_title = '<div class="in_cell_day_num">' . esc_html__( 'Times', 'booking' ) . '</div>';
1614 }
1615 if ( $view_days_num == 90 ) {
1616 $day_title = '<div class="in_cell_day_week">' . $day_week . '</div>';
1617 }
1618 if ( $view_days_num == 365 ) {
1619 $day_title = '<div class="in_cell_day_num">' . $dd . '</div>';
1620 }
1621 }
1622 $day_filter_id = $yy . '-' . $mm . '-' . $dd;
1623
1624 if ( ( $previous_month != $mm ) || ( 1 == $dd ) ) {
1625 $previous_month = $mm;
1626 $month_class = ' new_month ';
1627 } else {
1628 $month_class = '';
1629 }
1630
1631 ?>
1632 <div id="cell_<?php echo esc_attr( $current_resource_id . '_' . $day_filter_id ); ?>"
1633 class="<?php echo esc_attr( implode(' ', array(
1634 'flex_tl_day_cell',
1635 'flex_tl_day_cell_header',
1636 'flex_time_in_days_num_' . $view_days_num,
1637 'flex_tl_weekday' . $ww,
1638 $day_filter_id,
1639 $month_class
1640 ))); ?>"
1641 ><?php
1642
1643 if ( ( $is_matrix ) && ( ( $view_days_num == 30 ) || ( $view_days_num == 60 ) ) ) {
1644
1645 ?><div class="in_cell_date_container day_num<?php echo esc_attr( $d_inc ); ?>"><?php
1646
1647 if ( ! $this->is_frontend ) {
1648 ?><a href='<?php echo esc_url( $bk_admin_url_today . '&scroll_start_date=' . $yy . '-' . $mm . '-' . $dd ); ?>'><?php
1649 }
1650 echo wp_kses_post( $day_title );
1651
1652 if ( ! $this->is_frontend ) {
1653 ?></a><?php
1654 }
1655
1656 ?></div><?php
1657
1658 } else {
1659 ?>
1660 <div class="in_cell_date_container day_num<?php echo esc_attr( $d_inc ); ?>"><?php echo wp_kses_post( $day_title ); ?></div><?php
1661 }
1662
1663 ////////////////////////////////////////////////////////////////////////////////////////
1664 // T i m e c e l l s
1665 ////////////////////////////////////////////////////////////////////////////////////////
1666 $tm = floor( 24 / $time_selles_num );
1667 if ( $time_selles_num > 1 ) {
1668 ?><div class="<?php echo esc_attr( implode(' ', array(
1669 'in_cell_time_section_in_day',
1670 'flex_time_section_in_day_header',
1671 'flex_time_in_days_num_' . $view_days_num
1672 ) ) ); ?>"><?php
1673
1674 for ( $tt = 0; $tt < $time_selles_num; $tt++ ) { ?>
1675
1676 <?php if ( ( $tt < $start_hour_for_1day_view ) || ( $tt > $end_hour_for_1day_view ) ) { continue; } //FixIn: 7.0.1.14 ?>
1677
1678 <div class="<?php echo esc_attr( 'in_cell_time_hour time_hour' . ( $tt * $tm ) ); ?>" ><?php
1679
1680 $this->show_time_number_in_correct_format( $tt * $tm , $view_days_num );
1681
1682 ?></div><?php
1683 }
1684 ?></div><?php
1685 }
1686 ?></div><?php
1687
1688 }
1689 ?></div><?php
1690
1691 return $real_date ;
1692 }
1693
1694
1695 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1696 // Booking Row Support functions
1697 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1698
1699 /**
1700 * Define Init Row settings parameters
1701 *
1702 * @param $row_settings array
1703 *
1704 * @return array
1705 */
1706 private function get_init_row_settings( $row_settings ){
1707
1708 // Initial params
1709 $row_settings['is_matrix'] = $this->request_args['is_matrix'];
1710 $row_settings['start_hour_for_1day_view'] = 0;
1711 $row_settings['end_hour_for_1day_view'] = 24;
1712 $row_settings['limit_hours'] = 24;
1713 $row_settings['view_days_num'] = $this->request_args['view_days_num'];
1714
1715 // Single booking resource
1716 if ( ! $row_settings['is_matrix'] ) {
1717
1718 switch ($row_settings['view_days_num']) {
1719 case '90':
1720 $row_settings['days_num'] = 7;
1721 $row_settings['dwa'] = $this->week_days_titles['full'];
1722 $row_settings['time_selles_num'] = 1;
1723 break;
1724 case '365':
1725 $row_settings['days_num'] = 31;
1726 //$row_settings['days_num'] = intval( wpbc_datetime__no_wp_timezone('t',$row_settings['start_date']) ); // num of days in the specific month, wchih relative to $row_settings['real_date'] from header // FixIn: 7.0.1.47.
1727 $row_settings['dwa'] = $this->week_days_titles['1'];
1728 $row_settings['time_selles_num'] = 1;
1729 break;
1730 default: // 30
1731 $row_settings['days_num'] = 1;
1732 $row_settings['dwa'] = $this->week_days_titles['3'];
1733 $row_settings['time_selles_num'] = 24;//25;
1734
1735 if ( isset( $this->request_args[ 'limit_hours' ] ) ) { // FixIn: 7.0.1.14.
1736 $row_settings['limit_hours'] = explode(',',$this->request_args[ 'limit_hours' ]);
1737 $row_settings['start_hour_for_1day_view'] = intval( $row_settings['limit_hours'][0] );
1738 $row_settings['end_hour_for_1day_view'] = intval( $row_settings['limit_hours'][1] );
1739 $row_settings['limit_hours'] = $row_settings['limit_hours'][1] - $row_settings['limit_hours'][0];
1740 }
1741
1742 //$row_settings['view_days_num'] = 1;
1743 break;
1744 }
1745
1746 } else { // Multiple booking resources
1747
1748 //$row_settings['view_days_num'] = 365;
1749 switch ($row_settings['view_days_num']) {
1750 case '1':
1751 $row_settings['days_num'] = 1;
1752 $row_settings['dwa'] = $this->week_days_titles['full'];
1753 $row_settings['time_selles_num'] = 24;
1754
1755 if ( isset( $this->request_args[ 'limit_hours' ] ) ) { // FixIn: 7.0.1.14.
1756 $row_settings['limit_hours'] = explode(',',$this->request_args[ 'limit_hours' ]);
1757 $row_settings['start_hour_for_1day_view'] = intval( $row_settings['limit_hours'][0] );
1758 $row_settings['end_hour_for_1day_view'] = intval( $row_settings['limit_hours'][1] );
1759 $row_settings['limit_hours'] = $row_settings['limit_hours'][1] - $row_settings['limit_hours'][0];
1760 }
1761
1762 break;
1763 case '7':
1764 $row_settings['days_num'] = 7;
1765 $row_settings['dwa'] = $this->week_days_titles['full'];
1766 $row_settings['time_selles_num'] = 1;
1767 break;
1768 case '60':
1769 $row_settings['days_num'] = 62;
1770 $row_settings['dwa'] = $this->week_days_titles['1'];
1771 $row_settings['time_selles_num'] = 1;
1772 break;
1773 case 'old_365':
1774 $row_settings['days_num'] = 365;
1775 $row_settings['time_selles_num'] = 1;
1776 $row_settings['dwa'] = $this->week_days_titles['1'];
1777 break;
1778
1779 default: // 30
1780 $row_settings['days_num'] = 32;
1781 $row_settings['days_num'] = intval( wpbc_datetime__no_wp_timezone('t',$row_settings['start_date']) ); // num of days in the specific month, wchih relative to $row_settings['real_date'] from header // FixIn: 7.0.1.47.
1782 $row_settings['dwa'] = $this->week_days_titles['3'];
1783 $row_settings['time_selles_num'] = 1;//25;
1784 break;
1785 }
1786 }
1787
1788 return $row_settings;
1789 }
1790
1791
1792 /**
1793 * Show time in correct format - showing in Header, and in time CELLs
1794 *
1795 * @param $time_milliseconds
1796 * @param $view_days_num
1797 */
1798 private function show_time_number_in_correct_format( $time_milliseconds, $view_days_num ) {
1799
1800 // FixIn: 8.1.3.34.
1801 $bc_time_format = get_bk_option( 'booking_time_format' );
1802 if ( ! empty( $bc_time_format ) ) { // FixIn: 8.2.1.2.
1803 $time_show = wpbc_datetime__no_wp_timezone( str_replace( ':i', '', get_bk_option( 'booking_time_format' ) ), mktime( intval( $time_milliseconds ), 0, 0 ) );
1804 echo wp_kses_post( ( $view_days_num < 31 ) ? $time_show : '' );
1805 } else {
1806 echo wp_kses_post( ( $view_days_num < 31 ) ? ( ( ( $time_milliseconds ) < 10 ? '0' : '' ) . ( $time_milliseconds ) . '<sup>:00</sup>' ) : '' );
1807 }
1808 }
1809
1810
1811 /**
1812 * Is show Day View ( showing days || times )
1813 *
1814 * @param $row_settings
1815 *
1816 * @return bool
1817 */
1818 private function is_show_day_view( $row_settings ) {
1819 if (
1820 ( ( 30 == $row_settings['view_days_num'] ) && ( ! $row_settings['is_matrix'] ) ) // Day View for Single
1821 || ( ( 1 == $row_settings['view_days_num'] ) && ( $row_settings['is_matrix'] ) ) // Day View for Matrix
1822 ) {
1823 return true;
1824 } else {
1825 return false;
1826 }
1827 }
1828
1829
1830 /**
1831 * Check, if starting new booking (something changed) relative to previous CELL
1832 *
1833 * @param array $bookings_in_cell
1834 * @param array $previous_bookings_in_cell
1835 *
1836 * @return bool
1837 */
1838 private function is_start_new_booking_cell( $bookings_in_cell, $previous_bookings_in_cell ) {
1839
1840 $bookings_in_cell = implode( '|', $bookings_in_cell );
1841 $previous_bookings_in_cell = implode( '|', $previous_bookings_in_cell );
1842
1843 if ( $bookings_in_cell !== $previous_bookings_in_cell ) {
1844 return true;
1845 } else {
1846 return false;
1847 }
1848 }
1849
1850
1851 /**
1852 * Check method 2, if starting new booking (something changed) relative to previous CELL
1853 *
1854 * @param array $bookings_in_cell
1855 * @param array $previous_bookings_in_cell
1856 *
1857 * @return bool
1858 */
1859 private function is_start_new_booking_cell2( $bookings_in_cell, $previous_bookings_in_cell ) {
1860
1861 $bookings_in_cell = implode( '|', $bookings_in_cell );
1862 $previous_bookings_in_cell = implode( '|', $previous_bookings_in_cell );
1863
1864 $bookings_in_cell_arr = explode( '|', $bookings_in_cell );
1865 $previous_bookings_in_cell_arr = explode( '|', $previous_bookings_in_cell );
1866
1867 $is_check1 = empty( array_diff( $bookings_in_cell_arr, $previous_bookings_in_cell_arr ) );
1868 $is_check2 = empty( array_diff( $previous_bookings_in_cell_arr, $bookings_in_cell_arr ) );
1869
1870 return ( ( ! $is_check1 ) && ( ! $is_check2 ) );
1871 }
1872
1873 /**
1874 * Get Text for booking Title in PIPELINE
1875 *
1876 * @param $bk_id
1877 * @param $bookings
1878 *
1879 * @return string
1880 */
1881 private function get_booking_title_for_timeline( $bk_id, $bookings ){
1882
1883 $text_in_day_cell = '';
1884
1885 if ( $this->is_frontend ) $what_show_in_day_template = get_bk_option( 'booking_default_title_in_day_for_timeline_front_end' );
1886 else $what_show_in_day_template = get_bk_option( 'booking_default_title_in_day_for_calendar_view_mode' );
1887
1888 if ( function_exists( 'get_title_for_showing_in_day' ) ) {
1889 $text_in_day_cell .= esc_textarea( get_title_for_showing_in_day( $bk_id, $bookings, $what_show_in_day_template ) ); // FixIn: 7.1.1.2.
1890 } else {
1891 if ( ! $this->is_frontend ) {
1892 // Default Free // FixIn: 7.1.1.2.
1893 $text_in_day_cell .= $bk_id . ':' ;
1894 if ( isset( $bookings[ $bk_id ]->form_data['_all_fields_']['name'] ) ) {
1895 $text_in_day_cell .= ' ' . esc_textarea( $bookings[ $bk_id ]->form_data['_all_fields_']['name'] );
1896 }
1897 // FixIn: 10.0.0.24.
1898 if ( isset( $bookings[ $bk_id ]->form_data['_all_fields_']['secondname'] ) ) {
1899 $text_in_day_cell .= ' ' . esc_textarea( $bookings[ $bk_id ]->form_data['_all_fields_']['secondname'] );
1900 }
1901 if ( isset( $bookings[ $bk_id ]->form_data['_all_fields_']['lastname'] ) ) {
1902 $text_in_day_cell .= ' ' . esc_textarea( $bookings[ $bk_id ]->form_data['_all_fields_']['lastname'] );
1903 }
1904 }
1905 }
1906
1907 return $text_in_day_cell;
1908 }
1909
1910
1911 /**
1912 * Title, when mouse-over booking Pipeline (bar with background)
1913 *
1914 * @param $booking_id
1915 * @param $row_settings
1916 */
1917 private function show_booking_title_for_pipeline_bar( $booking_id, $row_settings ){
1918
1919 // FixIn: 8.7.1.4.
1920 $bk_title = '';
1921
1922 $is_date = wpbc_get_date_in_correct_format( wpbc_datetime__no_wp_timezone( "Y-m-d", $row_settings['real_date'] ) );
1923 if ( ( is_array( $is_date ) ) && ( ! empty( $is_date ) ) ) {
1924 $bk_title = $is_date[0];
1925 }
1926
1927 $bk_title .= " \n" . $this->get_booking_title_for_timeline( $booking_id, $row_settings['bookings'] );
1928
1929 $bk_title .= " \n" . wp_strip_all_tags( wpbc_get_short_dates_formated_to_show( $row_settings['bookings'][ $booking_id ]->dates_short ) ) ;
1930
1931 if ( function_exists( 'wpbc_is_11_5_features_enabled' ) && wpbc_is_11_5_features_enabled() ) {
1932 $bk_title = apply_filters( 'wpbc_timeline_booking_pipeline_title', $bk_title, $booking_id, $row_settings['bookings'] );
1933 }
1934
1935 ?><a href="javascript:void(0)"
1936 class="in_cell_date_booking_pipeline_a"
1937 title="<?php echo esc_attr( $bk_title ); ?>"
1938 ><?php
1939 ?><div class="in_cell_date_booking_pipeline_a_sizer"></div><?php
1940 ?></a><?php
1941 }
1942
1943
1944 /**
1945 * Show booking TITLE in PIPELINE
1946 *
1947 * @param $bookings_in_cell
1948 * @param $row_settings
1949 */
1950 private function show_booking_title_for_timeline( $bookings_in_cell, $row_settings ){
1951
1952 $bk_a_title_arr = array();
1953 $popup_content_arr = array();
1954 $popup_title_arr = array();
1955
1956 $is_show_popover_in_timeline = wpbc_is_show_popover_in_flex_timeline( $this->is_frontend, $this->request_args['booking_hash'] ); // FixIn: 8.1.3.5.
1957
1958 foreach ( $bookings_in_cell as $booking_id ) {
1959
1960 $bk_a_title = $this->get_booking_title_for_timeline( $booking_id, $row_settings['bookings'] );
1961 $bk_a_title = htmlspecialchars_decode( $bk_a_title, ENT_NOQUOTES ); // FixIn: 8.7.11.5.
1962 $bk_a_title_arr[] = $bk_a_title;
1963
1964 $title_in_day = $title = $title_hint = '';
1965
1966 $can_show_booking_popover = $is_show_popover_in_timeline && $this->wpbc_is_booking_authorized_for_hash( $booking_id, $row_settings['bookings'] );
1967 if ( $can_show_booking_popover ) {
1968 $popup_content = $this->wpbc_get_booking_info_4_popover( $booking_id, $row_settings['bookings'], $row_settings['booking_types'] );
1969
1970
1971 $popup_title_arr[] = $popup_content['title'];
1972 //FixIn: 9.7.4.1 - escape coded html/xss
1973 $popup_content_arr[] = '<div class="popover-title">' . esc_html($popup_content['title']) . '</div><div class="popover-content">' . esc_html( $popup_content['content'] ) . '</div>';
1974 }
1975 //$popup_content_arr[] = $bk_a_title . ': ' . wp_strip_all_tags( wpbc_get_short_dates_formated_to_show( $row_settings['bookings'][ $booking_id ]->dates_short ) ) ;
1976 }
1977
1978 // Title A link
1979 $bk_a_title__text = implode( ', ', $bk_a_title_arr );
1980
1981 if ( strlen( $bk_a_title__text ) > 20 ) {
1982 $bk_a_title__text = substr( $bk_a_title__text, 0, 20 ) . '...';
1983 }
1984 if ( count( $bookings_in_cell ) > 1 ) {
1985
1986 if ( ! $this->is_bookings_use_check_in_out( $bookings_in_cell, $row_settings['bookings'] ) ) {
1987 $bk_a_title__text = '<sup>[' . count( $bookings_in_cell ) . ']</sup> ' . $bk_a_title__text;
1988 } else {
1989 //return; // FixIn: 10.6.3.1.
1990 }
1991
1992 }
1993
1994
1995 if ( ! $this->is_frontend ) { $line_separator = '<div class=\'clear\'></div>'; }
1996 else { $line_separator = ''; }
1997 $popup_title_arr = implode( $line_separator, $popup_title_arr );
1998
1999 $line_separator = ''; // '<hr class="wpbc_tl_popover_booking_separator" />';
2000 $popup_content_arr = implode( $line_separator, $popup_content_arr );
2001
2002 // Booking CELL Title
2003 ?><a href="javascript:void(0)"
2004 class="<?php echo esc_attr( implode(' ', array(
2005 'in_cell_date_booking_title',
2006 ( ! empty( $popup_content_arr ) ) ? 'popover_bottom' : '',
2007 ( ! empty( $popup_content_arr ) ) ? 'popover_click' : '',
2008 ( count( $bookings_in_cell ) > 1 ) ? 'several_bookings_in_cell' : ''
2009 ))); ?>"
2010 <?php
2011 // FixIn: 8.9.3.3.
2012 if ( ! empty( $popup_content_arr ) ) { ?>
2013 data-content="<?php echo esc_html( str_replace( '"', "", $popup_content_arr ) ); ?>"
2014 data-original-title="<?php echo esc_html( str_replace( '"', "", $popup_title_arr ) ); ?>"
2015 <?php } ?>
2016 ><?php
2017 echo wp_kses_post( $bk_a_title__text );
2018 ?></a><?php
2019 }
2020
2021 /**
2022 * Check if some bookings used check in / out functionality
2023 *
2024 * @param $bookings_id_arr
2025 * @param $bookings_obj_arr
2026 *
2027 * @return false
2028 */
2029 function is_bookings_use_check_in_out( $bookings_id_arr, $bookings_obj_arr ) {
2030
2031 // -----------------------------------------------------------------------------------------------------
2032 // Is Check In/out ?
2033 // -----------------------------------------------------------------------------------------------------
2034 $is_use_check_in_out_time = ( get_bk_option( 'booking_range_selection_time_is_active' ) == 'On' );
2035
2036 if ( $is_use_check_in_out_time ) {
2037 foreach ( $bookings_id_arr as $booking_id ) {
2038
2039 if ( isset( $bookings_obj_arr[ $booking_id ] ) ) {
2040 foreach ( $bookings_obj_arr[ $booking_id ]->dates as $booking_date_obj ) {
2041 $booking_date_ymdhis = $booking_date_obj->booking_date;
2042
2043 $is_check_in_out__or_full = substr( $booking_date_ymdhis, - 1 ); // '1', '2' (not '0')
2044
2045 if ( '1' === $is_check_in_out__or_full ) {
2046 return true;
2047 }
2048 if ( '2' === $is_check_in_out__or_full ) {
2049 return true;
2050 }
2051 }
2052 }
2053 }
2054 }
2055 return false;
2056 }
2057
2058
2059 /**
2060 * Get array of CSS classes for booking bar
2061 * @param int $booking_id
2062 * @param array $bookings
2063 *
2064 * @return array
2065 */
2066 function get_booking_class_arr( $booking_id, $row_settings , $real_date, $time_hour ){
2067
2068 $bookings = $row_settings['bookings'];
2069
2070 $class_arr = array();
2071
2072 if ( ( ! empty( $booking_id ) ) && isset( $bookings[ $booking_id ] ) ) {
2073
2074 // Appoved | Pending
2075 if ( count( $bookings[ $booking_id ]->dates ) > 0 ) {
2076 $is_approved = $bookings[ $booking_id ]->dates[0]->approved;
2077 } else {
2078 $is_approved = 0;
2079 }
2080 $class_arr[] = $is_approved ? 'approved_booking' : 'pending_booking';
2081
2082 // -----------------------------------------------------------------------------------------------------
2083 // Is Check In/out ?
2084 // -----------------------------------------------------------------------------------------------------
2085 $is_use_check_in_out_time = ( get_bk_option( 'booking_range_selection_time_is_active' ) == 'On' );
2086 $one_date__one_booking__check_in_out__arr = array();
2087 if (
2088 ( $is_use_check_in_out_time )
2089 && ( ( $row_settings['is_matrix'] ) || ( 30 != $row_settings['view_days_num'] ) )
2090 && ( ( ! $row_settings['is_matrix'] ) || ( 1 != $row_settings['view_days_num'] ) )
2091 ){
2092 $real_date_ymd = wpbc_datetime__no_wp_timezone( "Y-m-d", $real_date );
2093 foreach ( $bookings[ $booking_id ]->dates as $booking_date_obj ) {
2094 $booking_date_ymdhis = $booking_date_obj->booking_date;
2095 if ( substr( $booking_date_ymdhis, 0, 10 ) === $real_date_ymd ) {
2096 $is_check_in_out__or_full = substr( $booking_date_ymdhis, -1 ); // '1', '2' (not '0')
2097
2098 if ('1'=== $is_check_in_out__or_full ){
2099 $one_date__one_booking__check_in_out__arr[] = 'booking_check_in';
2100 }
2101 if ('2'=== $is_check_in_out__or_full ){
2102 $one_date__one_booking__check_in_out__arr[] = 'booking_check_out';
2103 }
2104 //break;
2105 }
2106 }
2107 }
2108 // If we have 2 or more like: [ 'booking_check_in', 'booking_check_out' ], in the same date for same booking, then it is time slots bookings
2109 if ( count( $one_date__one_booking__check_in_out__arr ) == 1 ) {
2110 $class_arr[] = $one_date__one_booking__check_in_out__arr[0];
2111 $class_arr[] = 'booking_change_over';
2112 }
2113 if ( count( $one_date__one_booking__check_in_out__arr ) > 1 ) {
2114 $class_arr[] = 'booking_time_slots';
2115 }
2116
2117 // -----------------------------------------------------------------------------------------------------
2118
2119 if ( isset( $bookings[ $booking_id ]->trash ) ) {
2120 $is_trash = $bookings[ $booking_id ]->trash;
2121 } else {
2122 $is_trash = false;
2123 }
2124 $class_arr[] = $is_trash ? 'booking_trash' : '';
2125
2126 /////////////////////////////////////////////////////////////////
2127
2128 if ( ( isset( $bookings[ $booking_id ]->form_data['email'] ) )
2129 && (
2130 ( '[email protected]' == $bookings[ $booking_id ]->form_data['email'] )
2131 || ( '[email protected]' == $bookings[ $booking_id ]->form_data['email'] )
2132 )
2133 ) {
2134 $is_blank_bookings = true;
2135 } else {
2136 $is_blank_bookings = false;
2137 }
2138 $class_arr[] = $is_blank_bookings ? 'booking_blank' : '';
2139
2140 /////////////////////////////////////////////////////////////////
2141
2142 if ( wpbc_datetime__no_wp_timezone( 'Y.m.d' ) > wpbc_datetime__no_wp_timezone( "Y.m.d", $real_date ) ) {
2143 $class_arr[] = 'past_date';
2144 }
2145 if ( wpbc_datetime__no_wp_timezone( 'Y.m.d' ) == wpbc_datetime__no_wp_timezone( "Y.m.d", $real_date ) ) {
2146 $class_arr[] = 'today_date';
2147 }
2148
2149 if ( $this->is_show_day_view( $row_settings ) ) {
2150 if ( ( wpbc_datetime__no_wp_timezone( 'm.d.Y' ) == wpbc_datetime__no_wp_timezone( "m.d.Y", $real_date ) ) // Today Date
2151 && ( intval( wpbc_datetime__no_wp_timezone( 'H' ) ) > intval( $time_hour ) ) ) {
2152 $class_arr[] = 'past_date';
2153 }
2154 }
2155 /////////////////////////////////////////////////////////////////
2156
2157 $css_class_additional = apply_filters( 'wpbc_timeline_booking_header_css', '', $booking_id, $bookings ); // FixIn: 7.0.1.41.
2158 $class_arr[] = $css_class_additional;
2159 }
2160
2161 // Remove empty values from array
2162 $class_arr = array_filter( $class_arr );
2163
2164 return $class_arr;
2165 }
2166
2167
2168 /**
2169 * Show Date cell :: 3 variants :: Date Number | Booking Pipeline | Booking Title
2170 * @param $row_settings
2171 */
2172 private function show_day_cell( $row_settings ){
2173
2174 $data_in_previous_cell = $this->data_in_previous_cell;
2175
2176 $yy = wpbc_datetime__no_wp_timezone( "Y", $row_settings[ 'real_date' ] ); // 2012
2177 $mm = wpbc_datetime__no_wp_timezone( "m", $row_settings[ 'real_date' ] ); // 09
2178 $dd = wpbc_datetime__no_wp_timezone( "d", $row_settings[ 'real_date' ] ); // 31
2179 $ww = wpbc_datetime__no_wp_timezone( "N", $row_settings[ 'real_date' ] ); // 7
2180 $day_week = $row_settings[ 'dwa' ][$ww]; // Su
2181
2182 $row_settings['day_filter_id'] = $yy . '-' . $mm . '-' . $dd;
2183
2184
2185 // <editor-fold defaultstate="collapsed" desc=" = $bookings_in_day_cell - Array of booking ID - Sorted by Time in this date cell = " >
2186
2187 $bookings_in__times_arr = array();
2188 /**
2189 * $bookings_in__times_arr = array( [0] => array( [0] => 918, [1] => 917 ), [3600] => array( [0] => 918 [1] => 917 ), ...
2190 [82800] => Array (
2191 [0] => 918
2192 [1] => 917
2193 )
2194 )
2195 */
2196 if ( ! empty ( $row_settings['time_array_new'][ $row_settings['day_filter_id'] ] ) ) { // $row_settings['time_array_new'][ '2019-07-19' ]
2197 $bookings_in__times_arr = $row_settings['time_array_new'][ $row_settings['day_filter_id'] ];
2198 }
2199
2200 $bookings_in_day_cell = array();
2201 if ( ! empty ( $bookings_in__times_arr ) ) {
2202 foreach ( $bookings_in__times_arr as $times_milliseconds => $bookings_in_times_arr ) {
2203
2204 foreach ( $bookings_in_times_arr as $booking_id_in_time_interval ) {
2205
2206 if ( ! in_array( $booking_id_in_time_interval, $bookings_in_day_cell ) ) {
2207 /**
2208 * Array ( [0] => 15 [1] => 16 [2] => 13 [3] => 14 )
2209 */
2210 $bookings_in_day_cell[] = $booking_id_in_time_interval;
2211 }
2212 }
2213 }
2214 }
2215 // </editor-fold>
2216
2217 //debuge($bookings_in__times_arr);
2218 // <editor-fold defaultstate="collapsed" desc=" = $cell_css[] - Define CSS classes of day cell = " >
2219
2220 $cell_css = array();
2221 $cell_css[] = 'flex_tl_day_cell';
2222 $cell_css[] = 'flex_tl_weekday' . $ww;
2223 $cell_css[] = $row_settings['day_filter_id'];
2224
2225 if ( wpbc_datetime__no_wp_timezone( 'm.d.Y' ) == wpbc_datetime__no_wp_timezone( "m.d.Y", $row_settings['real_date'] ) ) {
2226 $cell_css[] = 'today_date';
2227 } else if ( wpbc_datetime__no_wp_timezone( 'Y.m.d' ) > wpbc_datetime__no_wp_timezone( "Y.m.d", $row_settings['real_date'] ) ) {
2228 $cell_css[] = 'past_date';
2229 }
2230
2231 if ( ( $data_in_previous_cell['previous_month'] != $mm ) || ( 1 == $dd ) ) {
2232
2233 $data_in_previous_cell['previous_month'] = $mm;
2234 $cell_css[] = 'new_month';
2235 }
2236
2237 if ( ! empty( $bookings_in_day_cell ) ) {
2238 $cell_css[] = 'exist_booking_in_cell';
2239 } else {
2240 $cell_css[] = 'no_booking_in_cell';
2241 }
2242
2243 // </editor-fold>
2244
2245
2246 ?><div id="cell_<?php echo esc_attr( $row_settings[ 'current_resource_id' ] . '_' . $row_settings['day_filter_id'] ); ?>"
2247 class="<?php echo esc_attr( implode(' ', $cell_css ) ); ?>"
2248 ><?php
2249
2250 ////////////////////////////////////////////////////////////////////////////////////////
2251 // T i m e c e l l s
2252 ////////////////////////////////////////////////////////////////////////////////////////
2253 $time_selles_num = $row_settings['time_selles_num'];
2254 $tm = floor( 24 / $time_selles_num );
2255
2256
2257 ?><div class="<?php echo esc_attr(implode(' ', array(
2258 'in_cell_time_section_in_day',
2259 'flex_time_section_in_day_booking',
2260 'flex_time_in_days_num_' . $row_settings['view_days_num']
2261 )) ); ?>"
2262 ><?php
2263
2264 for ( $tt = 0; $tt < $time_selles_num; $tt++ ) {
2265
2266 // Get bookings for time-slot
2267 if ( $this->is_show_day_view( $row_settings ) ) {
2268
2269 $time_ms = $tt * 60 * 60;
2270 $bookings_in_this_time_arr = empty( $bookings_in__times_arr[ $time_ms ] ) ? array() : $bookings_in__times_arr[ $time_ms ];
2271 $is_start_new_booking = $this->is_start_new_booking_cell( $bookings_in_this_time_arr, $data_in_previous_cell['bookings_in_cell'] );
2272 $is_start_new_booking2 = $this->is_start_new_booking_cell2( $bookings_in_this_time_arr, $data_in_previous_cell['bookings_in_cell'] );
2273
2274 $bookings_in_day_cell = $bookings_in_this_time_arr;
2275
2276 } else { // Get bookings for a day
2277
2278 $is_start_new_booking = $this->is_start_new_booking_cell( $bookings_in_day_cell, $data_in_previous_cell['bookings_in_cell'] );
2279 $is_start_new_booking2 = $this->is_start_new_booking_cell2( $bookings_in_day_cell, $data_in_previous_cell['bookings_in_cell'] );
2280
2281 }
2282
2283 // Skip timeslots for day view
2284 if ( $this->is_show_day_view( $row_settings ) ) {
2285 if ( ( $tt < $row_settings['start_hour_for_1day_view'] ) || ( $tt > $row_settings['end_hour_for_1day_view'] ) ) {
2286 continue;
2287 }
2288 }
2289
2290
2291 $today_time_css_class=''; // FixIn: 10.0.0.40.
2292 if ( wpbc_datetime__use_wp_timezone( 'Y.m.d' ) == wpbc_datetime__use_wp_timezone( "Y.m.d", $row_settings[ 'real_date' ] ) ) {
2293 if ( $this->is_show_day_view( $row_settings ) ) {
2294 if ( ( wpbc_datetime__use_wp_timezone( 'm.d.Y' ) == wpbc_datetime__use_wp_timezone( "m.d.Y", $row_settings[ 'real_date' ] ) ) // Today Date
2295 && ( intval( wpbc_datetime__use_wp_timezone( 'H' ) ) == intval( $tt ) ) ) {
2296 $today_time_css_class = 'today_time';
2297 }
2298 }
2299
2300 }
2301
2302 ?><div class="<?php echo esc_attr( 'in_cell_time_hour time_hour' . ( $tt * $tm ) . ' ' . $today_time_css_class ); ?>" ><?php
2303
2304 if ( 'show_dates' == $row_settings['what_to_show'] ) {
2305
2306 ?>
2307 <div class="in_cell_date_container in_cell_date_container_<?php echo esc_attr( $row_settings['what_to_show'] ); ?>"><?php
2308 //if ( empty( $bookings_in_day_cell ) ) {
2309 if ( $this->is_show_day_view( $row_settings ) ) {
2310 $this->show_time_number_in_correct_format( $tt * $tm , $row_settings['view_days_num'] );
2311 } else {
2312 echo esc_html( $dd );
2313 }
2314 //}
2315 ?></div><?php
2316 }
2317
2318
2319 if ( 'show_bookings' == $row_settings['what_to_show'] ) {
2320
2321 if ( ! empty( $bookings_in_day_cell ) ) {
2322
2323 $booking_id_title = array();
2324
2325 ?>
2326 <div class="in_cell_date_container in_cell_date_container_<?php echo esc_attr( $row_settings['what_to_show'] );
2327
2328 // FixIn: 10.5.0.1.
2329 if (count($bookings_in_day_cell)>1){
2330 echo ' in_cell_date_container_has_several_bookings ';
2331 }
2332
2333 ?>"><?php
2334
2335 foreach ( $bookings_in_day_cell as $booking_id ) {
2336
2337 $booking_css_class_arr = $this->get_booking_class_arr( $booking_id, $row_settings, $row_settings['real_date'], $tt );
2338
2339 if ( ! in_array( 'booking_change_over', $booking_css_class_arr ) ) {
2340 if ( $is_start_new_booking2 ) {
2341 $booking_css_class_arr[] = 'start_new_booking';
2342 }
2343 }
2344
2345 ?>
2346 <div class="<?php echo esc_attr( implode( ' ', array(
2347 'booking_id',
2348 'booking_id_' . $booking_id,
2349 //$is_start_new_booking ? 'start_new_booking' : '',
2350 ) ) );
2351 echo ' ' . esc_attr( implode( ' ', $booking_css_class_arr ) );
2352 ?>"
2353 ><?php
2354
2355 // Booking CELL background
2356 $this->show_booking_title_for_pipeline_bar( $booking_id, $row_settings ); // Title, when mouse-over booking Pipeline (bar with background)
2357
2358 ?></div><?php
2359 }
2360 ?></div><?php
2361 }
2362 }
2363
2364
2365 if ( 'show_booking_titles' == $row_settings['what_to_show'] ) {
2366
2367 if ( ! empty( $bookings_in_day_cell ) ) {
2368
2369 // Title of new booking(s)
2370 if ( $is_start_new_booking ) {
2371
2372 ?><div class="<?php echo esc_attr( implode( ' ', array(
2373 'in_cell_date_container',
2374 'in_cell_date_container_booking_id_title',
2375 'in_cell_date_container_' . $row_settings['what_to_show']
2376 ) ) );
2377 echo esc_attr( ' booking_id_' . implode( '_', $bookings_in_day_cell ) );
2378 ?>"
2379 ><?php
2380
2381 $this->show_booking_title_for_timeline( $bookings_in_day_cell, $row_settings );
2382
2383 ?></div><?php
2384 }
2385 }
2386 }
2387
2388 ?></div><?php
2389
2390 $data_in_previous_cell['bookings_in_cell'] = $bookings_in_day_cell;
2391 }
2392
2393 ?></div><?php
2394
2395 ?></div><?php
2396
2397
2398 $this->data_in_previous_cell = $data_in_previous_cell;
2399 }
2400
2401 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2402 // Booking R O W
2403 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2404
2405 /** Row */
2406 public function wpbc_show_timeline_booking_row( $start_date, $booking_arr = array() ) {
2407
2408 $row_settings = array( 'start_date' => $start_date );
2409
2410 $row_settings = $this->get_init_row_settings( $row_settings );
2411
2412 if ( $row_settings['start_date'] !== false ) {
2413 list( $start_year, $start_month, $start_day ) = explode( '-', wpbc_datetime__no_wp_timezone( 'Y-m-d', $row_settings['start_date'] ) );
2414 } else {
2415 if ( ! empty( $this->request_args['scroll_start_date'] ) )
2416 list( $start_year, $start_month, $start_day ) = explode( '-', $this->request_args['scroll_start_date'] ); // scroll_start_date=2013-07-01
2417 else
2418 list( $start_year, $start_month, $start_day ) = explode( '-', wpbc_datetime__no_wp_timezone( 'Y-n-j' ) );
2419 }
2420
2421 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2422 // Dates / Times Line
2423 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2424
2425 $this->data_in_previous_cell['previous_booking_id'] = false;
2426
2427 $saved_previos_data_cell = $this->data_in_previous_cell;
2428
2429 foreach ( array( 'show_dates', 'show_bookings', 'show_booking_titles' ) as $what_to_show ) {
2430
2431 $this->data_in_previous_cell = $saved_previos_data_cell;
2432
2433 ?><div id="flex_resource_row_<?php echo esc_attr( $what_to_show . '_' . $booking_arr['current_resource_id'] ); ?>"
2434 class="<?php echo esc_attr( implode(' ', array(
2435 'flex_tl_dates_bar', 'flex_tl_row_height',
2436 'flex_tl_row_bar_' . $what_to_show ,
2437 $row_settings['is_matrix'] ? 'flex_tl_matrix_resources' : 'flex_tl_single_resource'
2438 ) ) ); ?>"
2439 ><?php
2440
2441 for ( $d_inc = 0; $d_inc < $row_settings['days_num']; $d_inc ++ ) {
2442
2443 $row_settings['real_date'] = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) + intval( $d_inc ) ), intval( $start_year ) );
2444
2445 $day_cell_params = array_merge( $row_settings, $booking_arr );
2446
2447 $day_cell_params['what_to_show'] = $what_to_show;
2448
2449 $this->show_day_cell( $day_cell_params );
2450 }
2451
2452 ?></div><?php
2453 }
2454 }
2455
2456
2457 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2458 // Timeline
2459 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2460
2461 /** Show Structure of the TimeLine */
2462 public function wpbc_show_timeline( $dates_array, $bookings, $booking_types, $time_array_new = array() ){
2463
2464 // Skip showing rows of booking resource(s) in TimeLine or Calendar Overview, if no any exist booking(s) for current view
2465 $booked_booking_resources = array(); //FixIn: 7.0.1.51
2466 if ( ! empty( $this->request_args['only_booked_resources'] ) ) {
2467
2468 foreach ( $bookings as $single_booking ) {
2469
2470 if ( ! empty( $single_booking->booking_type ) )
2471 $booked_booking_resources[] = $single_booking->booking_type;
2472
2473 foreach ( $single_booking->dates as $booking_date_obj ) {
2474 if ( ( isset( $booking_date_obj->type_id ) ) && ( ! empty( $booking_date_obj->type_id ) ) )
2475 $booked_booking_resources[] = $booking_date_obj->type_id;
2476 }
2477 }
2478 $booked_booking_resources = array_unique( $booked_booking_resources );
2479 }
2480
2481 $view_days_num = $this->request_args['view_days_num']; // Get start date and number of rows, which is depend from the view days mode
2482 $is_matrix = $this->request_args['is_matrix'];
2483 $scroll_day = 0;
2484 $scroll_month = 0;
2485 $start_year = wpbc_datetime__no_wp_timezone( "Y" );
2486 $start_month = wpbc_datetime__no_wp_timezone( "m" ); // 09
2487
2488 if ( ! empty( $this->request_args['scroll_start_date'] ) ) { // scroll_start_date=2013-07-01
2489 // Set the correct start date, if was selected the stard date different from the today in the Filters Tab.
2490 list( $start_year, $start_month, $start_day ) = explode( '-', $this->request_args['scroll_start_date'] );
2491 }
2492
2493 ////////////////////////////////////////////////////////////////////////
2494 // Get Start Date and Scroll Day/Month Variables
2495 ////////////////////////////////////////////////////////////////////////
2496 if ( $is_matrix ) { // MATRIX VIEW
2497
2498 $bk_resources_id = explode( ',', $this->request_args['wh_booking_type'] );
2499 $max_rows_number = count( $bk_resources_id );
2500
2501 switch ( $view_days_num ) {
2502 case '1':
2503 if ( isset( $this->request_args['scroll_day'] ) )
2504 $scroll_day = $this->request_args['scroll_day'];
2505 if ( empty( $this->request_args['scroll_start_date'] ) )
2506 $start_day = wpbc_datetime__no_wp_timezone( "d" ); // FixIn: 7.0.1.13.
2507 break;
2508
2509 case '30':
2510 case '60':
2511 if ( isset( $this->request_args['scroll_month'] ) )
2512 $scroll_month = $this->request_args['scroll_month'];
2513 if ( empty( $this->request_args['scroll_start_date'] ) )
2514 $start_day = 1;
2515 break;
2516
2517 case '7': // 7 Week - start from Monday (or other start week day)
2518 if ( isset( $this->request_args['scroll_day'] ) )
2519 $scroll_day = $this->request_args['scroll_day'];
2520 if ( empty( $this->request_args['scroll_start_date'] ) )
2521 $start_day = wpbc_datetime__no_wp_timezone( "d" );
2522 $start_week_day_num = wpbc_datetime__no_wp_timezone( "w" );
2523 $start_day_weeek = esc_js(get_bk_option( 'booking_start_day_weeek' )); //[0]:Sun .. [6]:Sut
2524
2525 if ( $start_week_day_num != $start_day_weeek ) {
2526 for ( $d_inc = 1; $d_inc < 8; $d_inc++ ) { // Just get week back
2527
2528 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) - intval( $d_inc ) ), intval( $start_year ) );
2529
2530 $start_week_day_num = wpbc_datetime__no_wp_timezone( "w", $real_date );
2531 if ( $start_week_day_num == $start_day_weeek ) {
2532 $start_day = wpbc_datetime__no_wp_timezone( "d", $real_date );
2533 $start_year = wpbc_datetime__no_wp_timezone( "Y", $real_date );
2534 $start_month = wpbc_datetime__no_wp_timezone( "m", $real_date );
2535 $d_inc = 9;
2536 }
2537 }
2538 }
2539 break;
2540
2541 default: //30
2542 if ( isset( $this->request_args['scroll_month'] ) )
2543 $scroll_month = $this->request_args['scroll_month'];
2544 if ( empty( $this->request_args['scroll_start_date'] ) )
2545 $start_day = 1;
2546 break;
2547 }
2548
2549 } else { // SINGLE Resource VIEW
2550
2551 switch ( $view_days_num ) {
2552 case '90':
2553 if ( isset( $this->request_args['scroll_day'] ) )
2554 $scroll_day = $this->request_args['scroll_day'];
2555 else
2556 $scroll_day = 0;
2557
2558 $max_rows_number = 12;
2559 if ( empty( $this->request_args['scroll_start_date'] ) )
2560 $start_day = wpbc_datetime__no_wp_timezone( "d" );
2561 $start_week_day_num = wpbc_datetime__no_wp_timezone( "w" );
2562 $start_day_weeek = esc_js(get_bk_option( 'booking_start_day_weeek' )); //[0]:Sun .. [6]:Sut
2563
2564 if ( $start_week_day_num != $start_day_weeek ) {
2565 for ( $d_inc = 1; $d_inc < 8; $d_inc++ ) { // Just get week back
2566 $real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) - intval( $d_inc ) ), intval( $start_year ) );
2567
2568 $start_week_day_num = wpbc_datetime__no_wp_timezone( "w", $real_date );
2569 if ( $start_week_day_num == $start_day_weeek ) {
2570 $start_day = wpbc_datetime__no_wp_timezone( "d", $real_date );
2571 $start_year = wpbc_datetime__no_wp_timezone( "Y", $real_date );
2572 $start_month = wpbc_datetime__no_wp_timezone( "m", $real_date );
2573 $d_inc = 9;
2574 }
2575 }
2576 }
2577 break;
2578
2579 case '365':
2580 if ( isset( $this->request_args['scroll_month'] ) )
2581 $scroll_month = $this->request_args['scroll_month'];
2582 else
2583 $scroll_month = 0;
2584 $max_rows_number = 12;
2585 if ( empty( $this->request_args['scroll_start_date'] ) )
2586 $start_day = 1;
2587 break;
2588
2589 default: // 30
2590 if ( isset( $this->request_args['scroll_day'] ) )
2591 $scroll_day = $this->request_args['scroll_day'];
2592 else
2593 $scroll_day = 0;
2594
2595 // FixIn: 8.9.4.3.
2596 if ( $this->is_frontend ) {
2597 $max_rows_number = intval( get_bk_option( 'booking_timeline__month_mode__days_number_show' ) );
2598 } else {
2599 $max_rows_number = intval( get_bk_option( 'booking_calendar_overview__day_mode__days_number_show' ) );;
2600 }
2601 if (empty($max_rows_number)) {
2602 $max_rows_number = 31;
2603 }
2604
2605 if ( empty( $this->request_args['scroll_start_date'] ) )
2606 $start_day = wpbc_datetime__no_wp_timezone( "d" ); // FixIn: 7.0.1.13.
2607 break;
2608 }
2609 }
2610
2611 ////////////////////////////////////////////////////////////////////////////////////////////////
2612
2613 // FixIn: 10.0.0.25.
2614 if ( ! $this->is_frontend ){
2615 $this->show_timeline_header_start__admin_panel();
2616 }
2617 // New Spinner Loader // FixIn: 10.0.0.25.
2618 ?><div class="flex_tl_table_loading wpbc_spins_loading_container">
2619 <div class="wpbc_booking_form_spin_loader"><div class="wpbc_spins_loader_wrapper"><div class="wpbc_spin_loader_one_new"></div></div></div>
2620 <?php // echo '<span class="0glyphicon 0glyphicon-refresh wpbc_icn_autorenew wpbc_spin"></span>' ?>
2621 <span><?php esc_html_e('Loading','booking'); ?>...</span>
2622 </div><?php
2623
2624
2625 ?><div class="flex_timeline_frame<?php
2626 if ( $this->is_frontend ) echo ' wpbc_timeline_front_end' ?> flex_frame_view_days_num_<?php echo esc_attr( $view_days_num );
2627 if ($is_matrix) { echo ' flex_tl_matrix_resources '; } else { echo ' flex_tl_single_resource '; }
2628 ?>">
2629 <div class="flex_tl_table">
2630 <div class="flex_tl_table_header" style="<?php if ( ! $this->is_frontend ) { echo 'display:none;'; /* //FixIn: 10.0.0.25 */ } ?>">
2631 <?php
2632 if ( $this->is_frontend ) {
2633 ?><div class="flex_tl_collumn_2"><?php
2634
2635 $title = wpbc_lang( $this->timeline_titles['header_title'] );
2636
2637 $params_nav = array();
2638 $params_nav['title'] = $title;
2639 $this->client_navigation( $params_nav );
2640
2641 ?></div><?php
2642
2643 } else {
2644 ?>
2645 <div class="flex_tl_collumn_1"><?php
2646 $title = wpbc_lang( $this->timeline_titles['header_column1'] );
2647 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2648 echo $title; // Resources .
2649 ?></div>
2650 <div class="flex_tl_collumn_2"><?php
2651 $title = wpbc_lang( $this->timeline_titles['header_column2'] );
2652 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2653 echo $title; // Dates.
2654 ?></div>
2655 <?php } ?>
2656 </div><?php
2657
2658 ?><div class="flex_tl__scrolling_sections"><?php
2659 ?><div class="flex_tl__scrolling_section1">
2660 <div class="flex_tl_table_titles"><div class="flex_tl_collumn_1"></div></div><?php
2661 for ( $d_inc = 0; $d_inc < $max_rows_number; $d_inc++ ) {
2662
2663 // Skip showing rows of booking resource(s) in TimeLine or Calendar Overview, if no any exist booking(s) for current view
2664 if ( ! empty( $this->request_args['only_booked_resources'] ) ) {
2665
2666 $resource_id = ( $is_matrix ) ? $bk_resources_id[ $d_inc ] : $this->request_args['wh_booking_type'];
2667
2668 if ( ! in_array( $resource_id, $booked_booking_resources ) ) { continue; }
2669 }
2670
2671 // Ger Start Date to real_date variable
2672 $real_date = $this->get_start_day__to_real_date( array( 'is_matrix' => $is_matrix, 'view_days_num' => $view_days_num, 'start_month' => $start_month, 'start_day' => $start_day, 'start_year' => $start_year, 'scroll_month' => $scroll_month, 'scroll_day' => $scroll_day, 'd_inc' => $d_inc ) );
2673
2674 ?><div class="flex_tl_table_row_bookings">
2675 <div class="flex_tl_collumn_1"><?php
2676
2677 // Title in first column of each row in calendar
2678 if ( ( $is_matrix ) && ( isset( $bk_resources_id[$d_inc] ) ) && (isset( $booking_types[$bk_resources_id[$d_inc]] )) ) { // Matrix - resource titles
2679
2680 $resource_value = $booking_types[$bk_resources_id[$d_inc]];
2681 $bk_admin_url = wpbc_get_params_in_url( wpbc_get_bookings_url( false, false ), array( 'wh_booking_type' ) );
2682
2683 ?><div class="flex_tl_resource_title flex_tl_row_height <?php
2684 if ( isset( $resource_value->parent ) ) { if ( $resource_value->parent == 0 ) { echo 'parent'; } else { echo 'child'; } }
2685 ?> "><?php
2686 if ( $this->is_frontend ) {
2687
2688 if ( ( isset( $this->options['resource_link'] ) ) && ( isset( $this->options['resource_link'][ $resource_value->booking_type_id ] ) ) ){ // FixIn: 7.0.1.50.
2689
2690 ?><a href="<?php echo esc_url( $this->options['resource_link'][ $resource_value->booking_type_id ] ); ?>" ><?php // FixIn: 7.2.1.14.
2691 }
2692
2693 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2694 echo wpbc_lang( $resource_value->title ); // FixIn: 7.0.1.11.
2695
2696 if ( ( isset( $this->options['resource_link'] ) ) && ( isset( $this->options['resource_link'][ $resource_value->booking_type_id ] ) ) ){ // FixIn: 7.0.1.50.
2697 ?></a><?php
2698 }
2699 } else {
2700 ?><a href="<?php echo esc_url( $bk_admin_url . '&wh_booking_type=' . $bk_resources_id[$d_inc] ); ?>"
2701 title="<?php echo esc_attr( wpbc_lang( $resource_value->title ) ); ?>"
2702 ><?php
2703 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2704 echo wpbc_lang( $resource_value->title );
2705 ?></a><?php
2706 }
2707 ?></div><?php
2708
2709 } else { // Single Resource - Dates titles
2710
2711 ?><div class="flex_tl_resource_title flex_tl_row_height"><?php
2712
2713 switch ( $view_days_num ) {
2714 case '90':
2715 $end_real_date = mktime( 0, 0, 0, intval( $start_month ), ( intval( $start_day ) + intval( $d_inc ) * 7 + intval( $scroll_day ) ) + 6, intval( $start_year ) );
2716 $date_format = ' j, Y'; //get_bk_option( 'booking_date_format');
2717 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2718 echo wpbc_datetime__no_wp_timezone( "M", $real_date ) . wpbc_datetime__no_wp_timezone( $date_format, $real_date ) . ' - ' . wpbc_datetime__no_wp_timezone( "M", $end_real_date ) . wpbc_datetime__no_wp_timezone( $date_format, $end_real_date );
2719 break;
2720
2721 case '365':
2722 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2723 echo wpbc_datetime__no_wp_timezone( "F", $real_date ) . ', ' . wpbc_datetime__no_wp_timezone( "Y", $real_date );
2724 break;
2725
2726 default: // 30
2727 //$date_format = 'd / m / Y';
2728 $date_format = get_bk_option( 'booking_date_format' ); // FixIn: 5.4.5.13.
2729 $ww = wpbc_datetime__no_wp_timezone( "N", $real_date ); //7
2730 ?>
2731 <div class="flex_tl_resource_title_dates_container">
2732 <div class="flex_tl_resource_title_dates_days flex_tl_weekday<?php echo esc_attr( $ww ); ?>"><?php
2733 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2734 echo wpbc_datetime__no_wp_timezone( $date_format, $real_date ); ?></div>
2735 <div class="flex_tl_resource_title_dates_weeks flex_tl_weekday<?php echo esc_attr( $ww ); ?>"><?php
2736 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2737 echo wpbc_datetime__no_wp_timezone( "D", $real_date ); ?></div>
2738 </div>
2739 <?php
2740 break;
2741 }
2742
2743 ?></div><?php
2744 }
2745 ?>
2746 </div>
2747 </div><?php
2748 }
2749
2750
2751 ?></div><?php
2752 ?><div class="flex_tl__scrolling_section2">
2753 <div class="flex_tl_table_titles flex_tl_row_max_width">
2754 <div class="flex_tl_collumn_2"><?php
2755 // Header above the calendar table
2756 $real_date = mktime( 0, 0, 0, intval( $start_month ), intval( $start_day ), intval( $start_year ) );
2757
2758 // Ger Start Date to real_date variable
2759 $real_date = $this->get_start_day__to_real_date( array( 'is_matrix' => $is_matrix, 'view_days_num' => $view_days_num, 'start_month' => $start_month, 'start_day' => $start_day, 'start_year' => $start_year, 'scroll_month' => $scroll_month, 'scroll_day' => $scroll_day, 'd_inc' => $d_inc ) );
2760
2761 $this->wpbc_show_timeline_header_row( $real_date );
2762 ?>
2763 </div>
2764 </div><?php
2765
2766 for ( $d_inc = 0; $d_inc < $max_rows_number; $d_inc++ ) {
2767
2768 // Skip showing rows of booking resource(s) in TimeLine or Calendar Overview, if no any exist booking(s) for current view
2769 if ( ! empty( $this->request_args['only_booked_resources'] ) ) {
2770
2771 $resource_id = ( $is_matrix ) ? $bk_resources_id[ $d_inc ] : $this->request_args['wh_booking_type'];
2772
2773 if ( ! in_array( $resource_id, $booked_booking_resources ) ) { continue; }
2774 }
2775
2776 // Ger Start Date to real_date variable
2777 $real_date = $this->get_start_day__to_real_date( array( 'is_matrix' => $is_matrix, 'view_days_num' => $view_days_num, 'start_month' => $start_month, 'start_day' => $start_day, 'start_year' => $start_year, 'scroll_month' => $scroll_month, 'scroll_day' => $scroll_day, 'd_inc' => $d_inc ) );
2778
2779 ?>
2780 <div class="flex_tl_table_row_bookings flex_tl_row_max_width">
2781
2782 <div class="flex_tl_collumn_2"><?php
2783
2784 if ( $is_matrix ) {
2785
2786 $this->reset_data_in_previous_cell();
2787
2788 $resource_id = $bk_resources_id[ $d_inc ];
2789
2790 } else {
2791 $resource_id = $this->request_args['wh_booking_type'];
2792 } // Request from GET or REQUEST
2793
2794 $booking_arr = array(
2795 'current_resource_id' => ( ( ! empty( $resource_id ) ) ? $resource_id : 1 ), // Remove dates and Times from the arrays, which is not belong to the $booking_arr['current_resource_id'] We do not remove it only, when the $booking_arr['current_resource_id'] - is empty - OLD ALL Resources VIEW
2796 'booked_dates_array' => $dates_array,
2797 'bookings' => $bookings,
2798 'booking_types' => $booking_types,
2799 'time_array_new' => $time_array_new
2800 );
2801
2802 /**
2803 * FROM: [2019-07-19] => Array ( [0] => Array (
2804 * [id] => 19
2805 [resource] => 3
2806 )
2807 [1] => Array (
2808 [id] => 19
2809 [resource] => 3
2810 ), ....
2811 * TO
2812 *
2813 * [2019-07-19] => Array (
2814 * [0] => 19
2815 * [1] => 19
2816 * [2] => 18
2817 * [3] => 18 ...
2818 */
2819 $booking_arr['booked_dates_array'] = $this->wpbc_dates_only_of_specific_resource(
2820 $booking_arr['booked_dates_array'],
2821 $booking_arr['current_resource_id'],
2822 $booking_arr['bookings']
2823 );
2824 /**
2825 * FROM: [2019-07-19] => Array ( ... , [28800] => Array(
2826 [0] => Array (
2827 [id] => 15
2828 [resource] => 3
2829 )
2830 [1] => Array (
2831 [id] => 16
2832 [resource] => 3
2833 )
2834 [2] => Array (
2835 [id] => 13
2836 [resource] => 3
2837 ) ....
2838 * TO
2839 * [2019-07-19] => Array ( ... , [28800] => Array(
2840 [0] => 15
2841 [1] => 16
2842 [2] => 13
2843 )
2844 */
2845 $booking_arr['time_array_new'] = $this->wpbc_times_only_of_specific_resource(
2846 $booking_arr['time_array_new'],
2847 $booking_arr['current_resource_id'],
2848 $booking_arr['bookings']
2849 );
2850
2851 $this->wpbc_show_timeline_booking_row( $real_date, $booking_arr );
2852
2853
2854 ?>
2855 </div>
2856 </div><?php
2857 }
2858 ?></div><?php
2859 ?></div><?php
2860
2861 ?></div></div><?php
2862
2863
2864 if ( ! $this->is_frontend ){
2865 $this->show_timeline_header_end__admin_panel(); // FixIn: 10.0.0.25.
2866 }
2867
2868 }
2869
2870
2871 /**
2872 * Ger Start Date to real_date variable
2873 *
2874 * @param $params = array(
2875 * 'is_matrix' => $is_matrix,
2876 * 'view_days_num' => $view_days_num,
2877 * 'start_month' => $start_month,
2878 * 'start_day' => $start_day,
2879 * 'start_year' => $start_year,
2880 * 'scroll_month' => $scroll_month
2881 * 'scroll_day' => $scroll_day
2882 * 'd_inc' => $d_inc
2883 * )
2884 *
2885 * @return false|int
2886 */
2887 private function get_start_day__to_real_date( $params ) {
2888
2889 if ( $params['is_matrix'] ) { // MATRIX VIEW
2890 switch ( $params['view_days_num'] ) { // Set real start date for the rows in calendar
2891 case '1':
2892 case '7':
2893 $real_date = mktime( 0, 0, 0, intval( $params['start_month'] ), ( intval( $params['start_day'] ) + intval( $params['scroll_day'] ) ), intval( $params['start_year'] ) );
2894 break;
2895
2896 case '30':
2897 case '90':
2898 $real_date = mktime( 0, 0, 0, ( intval( $params['start_month'] ) + intval( $params['scroll_month'] ) ), intval( $params['start_day'] ), intval( $params['start_year'] ) );
2899 break;
2900
2901 default: // 30
2902 $real_date = mktime( 0, 0, 0, ( intval( $params['start_month'] ) + intval( $params['scroll_month'] ) ), intval( $params['start_day'] ), intval( $params['start_year'] ) );
2903 break;
2904 }
2905 } else { // Single Resource View
2906 switch ( $params['view_days_num'] ) { // Set real start date for the rows in calendar
2907 case '90':
2908 $real_date = mktime( 0, 0, 0, intval( $params['start_month'] ), ( intval( $params['start_day'] ) + intval( $params['d_inc'] ) * 7 + intval( $params['scroll_day'] ) ), intval( $params['start_year'] ) );
2909 break;
2910
2911 case '365':
2912 $real_date = mktime( 0, 0, 0, ( intval( $params['start_month'] ) + intval( $params['d_inc'] ) + intval( $params['scroll_month'] ) ), intval( $params['start_day'] ), intval( $params['start_year'] ) );
2913 break;
2914
2915 default: // 30
2916 $real_date = mktime( 0, 0, 0, intval( $params['start_month'] ), ( intval( $params['start_day'] ) + intval( $params['d_inc'] ) + intval( $params['scroll_day'] ) ), intval( $params['start_year'] ) );
2917 break;
2918 }
2919 }
2920
2921 return $real_date;
2922 }
2923
2924 /**
2925 * Show timeline
2926 * All parameters must be defined.
2927 */
2928 public function show_timeline() {
2929
2930 $this->wpbc_show_timeline( $this->dates_array, $this->bookings, $this->booking_types, $this->time_array_new );
2931
2932 //FixIn: 10.0.0.25 // removed loader text from here
2933
2934 // FixIn: 9.1.2.4.
2935 echo '<script type="text/javascript">
2936 if ( ( document.readyState !== "loading" ) && ( ( "undefined" !== typeof jQuery ) && ( window.jQuery ) ) ){
2937 jQuery( ".flex_tl_table_loading").hide();
2938 jQuery( ".flex_tl_table" ).show();
2939 } else { ' ;
2940 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2941 echo wpbc_jq_ready_start(); // FixIn: 10.1.3.7.
2942 ?> jQuery( '.flex_tl_table_loading').hide();
2943 jQuery( '.flex_tl_table' ).show();
2944 <?php
2945 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2946 echo wpbc_jq_ready_end() . ' } </script>'; // FixIn: 10.1.3.7.
2947 }
2948
2949 /**
2950 * Show Header for Timeline in Calendar Overview page in admin panel. Header contain switches of modes and novigation buttons
2951 * @return void
2952 */
2953 public function show_timeline_header_start__admin_panel(){ // FixIn: 10.0.0.25.
2954
2955 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2956 $is_show_resources_matrix = ( ( isset( $_REQUEST['wh_booking_type'] ) ) && ( strpos( $_REQUEST['wh_booking_type'], ',' ) !== false ) )
2957 ? true : false;
2958
2959 $view_days_num = ( isset( $_REQUEST['view_days_num'] ) ) ? intval( $_REQUEST['view_days_num'] ) : get_bk_option( 'booking_view_days_num' ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
2960
2961 $bk_admin_url = wpbc_get_params_in_url( wpbc_get_bookings_url( false ), array( 'view_days_num' ) );
2962
2963 ?><div class="wpbc_calendar_overview__header" >
2964 <div class="wpdvlp-top-tabs ">
2965 <div class="wpdvlp-tabs-wrapper">
2966 <div class="nav-tabs"><?php
2967 if ( $is_show_resources_matrix ) {
2968 ?>
2969 <a href="<?php echo esc_url( $bk_admin_url . '&view_days_num=1' ); ?>"
2970 class="nav-tab <?php echo ( 1 == $view_days_num ) ? 'nav-tab-active' : ''; ?>"><i class="menu_icon icon-1x wpbc-bi-calendar-event"></i>
2971 <span class="nav-tab-text">&nbsp;&nbsp;<?php echo esc_html__('Day', 'booking') ; ?></span>
2972 </a>
2973 <a href="<?php echo esc_url( $bk_admin_url . '&view_days_num=7' ); ?>"
2974 class="nav-tab <?php echo ( 7 == $view_days_num ) ? 'nav-tab-active' : ''; ?>"><i class="menu_icon icon-1x wpbc-bi-calendar-week"></i>
2975 <span class="nav-tab-text">&nbsp;&nbsp;<?php echo esc_html__('Week', 'booking'); ?></span>
2976 </a>
2977 <a href="<?php echo esc_url( $bk_admin_url . '&view_days_num=30' ); ?>"
2978 class="nav-tab <?php echo ( 30 == $view_days_num ) ? 'nav-tab-active' : ''; ?>"><i class="menu_icon icon-1x wpbc-bi-calendar3"></i>
2979 <span class="nav-tab-text">&nbsp;&nbsp;<?php echo esc_html__('Month', 'booking'); ?></span>
2980 </a>
2981 <a href="<?php echo esc_url( $bk_admin_url . '&view_days_num=60' ); ?>"
2982 class="nav-tab <?php echo ( 60 == $view_days_num ) ? 'nav-tab-active' : ''; ?>"><i class="menu_icon icon-1x wpbc-bi-calendar2-week"></i>
2983 <span class="nav-tab-text">&nbsp;&nbsp;2 <?php echo esc_html__('Months', 'booking'); ?></span>
2984 </a>
2985 <?php
2986 } else {
2987 ?>
2988 <a href="<?php echo esc_url( $bk_admin_url . '&view_days_num=30' ); ?>"
2989 class="nav-tab <?php echo ( 30 == $view_days_num ) ? 'nav-tab-active' : ''; ?>"><i class="menu_icon icon-1x wpbc-bi-calendar-event"></i>
2990 <span class="nav-tab-text">&nbsp;&nbsp;<?php echo esc_html__('Day', 'booking') ; ?></span>
2991 </a>
2992 <a href="<?php echo esc_url( $bk_admin_url . '&view_days_num=90' ); ?>"
2993 class="nav-tab <?php echo ( 90 == $view_days_num ) ? 'nav-tab-active' : ''; ?>"><i class="menu_icon icon-1x wpbc-bi-calendar-week"></i>
2994 <span class="nav-tab-text">&nbsp;&nbsp;<?php echo esc_html__('Week', 'booking'); ?></span>
2995 </a>
2996 <a href="<?php echo esc_url( $bk_admin_url . '&view_days_num=365' ); ?>"
2997 class="nav-tab <?php echo ( 365 == $view_days_num ) ? 'nav-tab-active' : ''; ?>"><i class="menu_icon icon-1x wpbc-bi-calendar3"></i>
2998 <span class="nav-tab-text">&nbsp;&nbsp;<?php echo esc_html__('Month', 'booking'); ?></span>
2999 </a>
3000 <?php
3001 }
3002 ?><div class="wpbc_calendar_overview__navigation"><?php
3003
3004 wpbc_toolbar_btn__timeline_navigation();
3005
3006 ?></div>
3007 </div><!-- nav-tabs -->
3008 </div><!-- wpdvlp-tabs-wrapper -->
3009 </div><!-- wpdvlp-top-tabs -->
3010 </div>
3011 <div class="clear"></div>
3012 <div class="wpbc_calendar_overview__container">
3013 <?php
3014 }
3015
3016 function show_timeline_header_end__admin_panel(){ // FixIn: 10.0.0.25.
3017 ?></div><?php // End: .wpbc_calendar_overview__container
3018 }
3019
3020 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3021 // P O P O V E R
3022 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3023
3024 //TODO: Refactor this: 2019-07-29 09:01
3025
3026 /**
3027 * Get Data for Popover
3028 *
3029 * @param int $bk_id
3030 * @param array $bookings
3031 * @param array $booking_types
3032 * @param string $text_in_day_cell
3033 * @param string $header_title
3034 * @param string $content_text
3035 *
3036 * @return array
3037 */
3038 public function wpbc_get_booking_info_4_popover( $bk_id, $bookings, $booking_types ){
3039
3040 if ( ! $this->wpbc_is_booking_authorized_for_hash( $bk_id, $bookings ) ) {
3041 return array(
3042 'title' => '',
3043 'content' => '',
3044 );
3045 }
3046
3047 if ( isset( $bookings[ $bk_id ] ) ) {
3048 //$bookings[ $bk_id ]->form_show = str_replace( "&amp;", '&', $bookings[ $bk_id ]->form_show ); // FixIn: 7.1.2.12.
3049 // We escaping at other place: wpbc__legacy__get_form_content_arr()
3050 }
3051
3052 if ( count( $bookings[ $bk_id ]->dates ) > 0 ) {
3053 $is_approved = $bookings[ $bk_id ]->dates[0]->approved;
3054 } else {
3055 $is_approved = 0;
3056 }
3057
3058 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3059 // Title
3060 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3061 $header_title = '<div class=\'popover-title-id\' > ID: ' . $bk_id . '</div>'; // ID
3062
3063
3064 $is_can = true; //current_user_can( 'edit_posts' );
3065
3066 if (
3067 ( ( $is_can ) && ( ! $this->is_frontend ) )
3068 || ( ( $this->is_frontend ) && ( ! empty( $this->request_args['booking_hash'] ) ) )
3069 ) {
3070
3071 // Buttons
3072 $header_title .= '<div class=\'popover-title-buttons control-group timeline_info_bk_actionsbar_' . $bk_id . '\' >';
3073
3074
3075 if ( ( ! $this->is_frontend ) && ( $is_can ) ) {
3076 // Link
3077 $header_title .= '<a class=\'button button-secondary\'
3078 title=\'' . esc_attr( str_replace( "'", '', __( 'Booking Listing', 'booking' ) ) ) . '\'
3079 href=\''.wpbc_get_bookings_url( true, false ).'&wh_booking_id='.$bk_id.'&tab=vm_booking_listing\' ><i class=\'wpbc_icn_gps_fixed\'></i></a>';
3080 //Edit
3081 if ( class_exists( 'wpdev_bk_personal' ) ) {
3082 $bk_url_add = wpbc_get_new_booking_url( true, false );
3083 $bk_hash = (isset( $bookings[$bk_id]->hash )) ? $bookings[$bk_id]->hash : '';
3084 $bk_booking_type = $bookings[$bk_id]->booking_type;
3085 $edit_booking_url = $bk_url_add . '&booking_type=' . $bk_booking_type . '&booking_hash=' . $bk_hash . '&parent_res=1';
3086 // FixIn: 10.10.1.2 $edit_booking_url .= ( 'Off' !== get_bk_option( 'booking_is_resource_no_update__during_editing' ) ) ? '&resource_no_update=1' : ''; // FixIn: 9.4.2.3.
3087
3088 $custom_booking_form = '';
3089 if ( ! empty( $bookings[ $bk_id ]->form_data['_all_fields_']['wpbc_custom_booking_form'] ) ) {
3090 $custom_booking_form = $bookings[ $bk_id ]->form_data['_all_fields_']['wpbc_custom_booking_form'];
3091 $edit_booking_url .= '&booking_form=' . rawurlencode( $custom_booking_form ); // FixIn: 9.4.3.12.
3092 }
3093
3094 $edit_booking_onclick = "if ( 'function' === typeof wpbc_boo_listing__click__add_booking_modal_from_row ) {"
3095 . ' wpbc_boo_listing__click__add_booking_modal_from_row('
3096 . absint( $bk_id ) . ','
3097 . absint( $bk_booking_type ) . ','
3098 . "'" . esc_js( $bk_hash ) . "',"
3099 . "'" . esc_js( $custom_booking_form ) . "'"
3100 . ' ); return false; }';
3101
3102 $header_title .= '<a class=\'button button-secondary\'
3103 title=\'' . esc_attr( str_replace( "'", '', __( 'Edit', 'booking' ) ) ) . '\'
3104 href=\'' . esc_url( $edit_booking_url ) . '\' onclick=\'' . esc_attr( $edit_booking_onclick ) . '\' ><i class=\'wpbc_icn_draw\'></i></a>';
3105
3106
3107 $header_title .= '<span class=\'wpbc-buttons-separator\'></span>';
3108 }
3109 // Trash
3110 //$header_title .= '<a class=\'button button-secondary\' href=\'javascript:;\' onclick=\'javascript:delete_booking(' . $bk_id . ', ' . $this->current_user_id . ', &quot;' . wpbc_get_maybe_reloaded_booking_locale() . '&quot; , 1 );\' ><i class=\'wpbc_icn_delete_outline\'></i></a>';
3111 // FixIn: 6.1.1.10.
3112 $is_trash = $bookings[$bk_id]->trash;
3113
3114 // Trash
3115 $header_title .= '<a class=\'button button-secondary trash_bk_link'.(( $is_trash)?' hidden_items ':'').'\'
3116 title=\'' . esc_attr( str_replace( "'", '', __( 'Trash / Reject', 'booking' ) ) ) . '\'
3117 href=\'javascript:;\' onclick=\'javascript:if ( wpbc_are_you_sure_popup() ) trash__restore_booking(1,' . $bk_id . ', ' . $this->current_user_id . ', &quot;' . wpbc_get_maybe_reloaded_booking_locale() . '&quot; , 1 );\' ><i class=\'wpbc_icn_delete_outline\'></i></a>'; // FixIn: 8.4.7.14.
3118 // Restore
3119 $header_title .= '<a class=\'button button-secondary restore_bk_link'.((!$is_trash)?' hidden_items ':'').'\'
3120 title=\'' . esc_attr( str_replace( "'", '', __( 'Restore', 'booking' ) ) ) . '\'
3121 href=\'javascript:;\' onclick=\'javascript:trash__restore_booking(0,' . $bk_id . ', ' . $this->current_user_id . ', &quot;' . wpbc_get_maybe_reloaded_booking_locale() . '&quot; , 1 );\' ><i class=\'wpbc_icn_rotate_left\'></i></a>';
3122 // Delete
3123 $header_title .= '<a class=\'button button-secondary delete_bk_link'.((!$is_trash)?' hidden_items ':'').'\'
3124 title=\'' . esc_attr( str_replace( "'", '', __( 'Delete', 'booking' ) ) ) . '\'
3125 href=\'javascript:;\' onclick=\'javascript:if ( wpbc_are_you_sure_popup() ) delete_booking(' . $bk_id . ', ' . $this->current_user_id . ', &quot;' . wpbc_get_maybe_reloaded_booking_locale() . '&quot; , 1 );\' ><i class=\'wpbc_icn_close\'></i></a>'; // FixIn: 8.4.7.14.
3126 //End FixIn: 6.1.1.10
3127
3128 // Approve | Decline
3129 $header_title .= '<a class=\'button button-secondary approve_bk_link ' . ($is_approved ? 'hidden_items' : '') . '\'
3130 title=\'' . esc_attr( str_replace( "'", '', __( 'Approve', 'booking' ) ) ) . '\'
3131 href=\'javascript:;\' onclick=\'javascript:approve_unapprove_booking(' . $bk_id . ',1, ' . $this->current_user_id . ', &quot;' . wpbc_get_maybe_reloaded_booking_locale() . '&quot; , 1 );\' ><i class=\'wpbc_icn_check_circle_outline\'></i></a>';
3132 $header_title .= '<a class=\'button button-secondary pending_bk_link ' . ($is_approved ? '' : 'hidden_items') . '\'
3133 title=\'' . esc_attr( str_replace( "'", '', __( 'Pending', 'booking' ) ) ) . '\'
3134 href=\'javascript:;\' onclick=\'javascript:approve_unapprove_booking(' . $bk_id . ',0, ' . $this->current_user_id . ', &quot;' . wpbc_get_maybe_reloaded_booking_locale() . '&quot; , 1 );\' ><i class=\'wpbc_icn_block\'></i></a>';
3135
3136
3137 }
3138
3139 else if ( ( $this->is_frontend ) && ( ! empty( $this->request_args['booking_hash'] ) ) ) { // FixIn: 8.1.3.5.
3140 // Valid or not valid hash we was checked at beginning of function.
3141
3142 //Edit
3143 if ( class_exists( 'wpdev_bk_personal' ) ) {
3144
3145 // $edit_booking_url_admin = wpbc_get_bookings_url( true, false ).'&wh_booking_id='.$bk_id.'&tab=vm_booking_listing';
3146 // $trash_booking_url_admin = wpbc_get_bookings_url( true, false ).'&wh_booking_id='.$bk_id.'&tab=vm_booking_listing';
3147
3148 $is_change_hash_after_approvement = get_bk_option( 'booking_is_change_hash_after_approvement' ); // FixIn: 8.6.1.6.
3149 if ( ( ! $is_approved ) || ( 'On' != $is_change_hash_after_approvement ) ) { // FixIn: 8.2.1.14.
3150 $visitorbookingediturl = apply_bk_filter( 'wpdev_booking_set_booking_edit_link_at_email', '[visitorbookingediturl]', $bk_id );
3151 $visitorbookingcancelurl = apply_bk_filter( 'wpdev_booking_set_booking_edit_link_at_email', '[visitorbookingcancelurl]', $bk_id );
3152 $visitorbookingpayurl = apply_bk_filter( 'wpdev_booking_set_booking_edit_link_at_email', '[visitorbookingpayurl]', $bk_id );
3153
3154 $header_title .= '<a class=\'btn btn-default wpbc_btn_in_timeline\' title=\''. esc_attr( __( 'Edit', 'booking' ) ).'\' href=\'' . $visitorbookingediturl . '\' ><i class=\'wpbc_icn_draw\'></i></a>';
3155 $header_title .= '<a class=\'btn btn-default wpbc_btn_in_timeline\' title=\''. esc_attr( __( 'Cancel', 'booking' ) ).'\' href=\'' . $visitorbookingcancelurl . '\' ><i class=\'wpbc_icn_delete_outline\'></i></a>';
3156 $header_title .= '<a class=\'btn btn-default wpbc_btn_in_timeline\' title=\''. esc_attr( __( 'Pay', 'booking' ) ).'\' href=\'' . $visitorbookingpayurl . '\' ><i class=\'wpbc_icn_forward_to_inbox\'></i></a>';
3157 }
3158 }
3159 }
3160
3161 $header_title .= '</div>';
3162 }
3163
3164 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3165 // Content
3166 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3167
3168 // Container
3169 $content_text = '<div id=\'wpbc-booking-id-'.$bk_id.'\' class=\'flex-popover-content-data\' >';
3170
3171
3172 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3173 // Labels
3174 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3175 $content_text .= '<div class=\'flex-popover-bars\' >';
3176
3177 $content_text .= '<div class=\'flex-popover-labels-bar\' >';
3178
3179 // ID
3180 $content_text .= '<div class=\'flex-label flex-label-id\'>';
3181 $content_text .= '<span class=\'label0\'>' . $bk_id . '</span>';
3182 $content_text .= '</div>';
3183
3184 // Labels
3185 $content_text .= '<div class=\'flex-label flex-label-booking-status label-pending' . ( $is_approved ? ' hidden_items' : '' ) . '\'>'
3186 . __('Pending' ,'booking')
3187 . '</div>';
3188 $content_text .= '<div class=\'flex-label flex-label-booking-status label-approved' . ( ! $is_approved ? ' hidden_items' : '' ) . '\'>'
3189 . __('Approved' ,'booking')
3190 . '</div>';
3191
3192 // Resource
3193 if ( function_exists( 'wpbc_db__get_resource_title' ) ) {
3194
3195 if ( isset( $booking_types[ $bookings[ $bk_id ]->booking_type ] ) ) {
3196 $bk_title = wpbc_lang( $booking_types[ $bookings[ $bk_id ]->booking_type ]->title );
3197 } else {
3198 $bk_title = wpbc_get_resource_title( $bookings[ $bk_id ]->booking_type );
3199 }
3200
3201 $content_text .= '<div class=\'flex-label flex-label-resource\'>';
3202 $content_text .= '<span class=\'\'>' . esc_textarea( $bk_title ) . '</span>'; // FixIn: 7.1.1.2.
3203 $content_text .= '</div>';
3204 }
3205
3206 // Payment Status
3207 if ( ( function_exists( 'wpdev_bk_get_payment_status_simple' ) )
3208 && ( floatval( $bookings[ $bk_id ]->cost ) > 0 )
3209 ) {
3210 $pay_status = wpdev_bk_get_payment_status_simple( $bookings[ $bk_id ]->pay_status );
3211 $is_payment_ok = wpbc_is_payment_status_ok( trim( $bookings[ $bk_id ]->pay_status ) );
3212
3213 $payment_label_status = $is_payment_ok ? 'payment-label-success' : 'payment-label-unknown';
3214
3215 $content_text .= '<div class=\'flex-label flex-label-payment '. $payment_label_status .'\'>';
3216
3217 if ( $is_payment_ok )
3218 $content_text .= '<span class=\'label-prefix\'>' . esc_js( __( 'Payment', 'booking' ) ). '</span> ' . esc_js( $pay_status );
3219 else {
3220 $content_text .= '<span class=\'label-prefix\'>' . esc_js( __( 'Payment', 'booking' ) ) . '</span> ' . esc_js( $pay_status ); // FixIn: 7.1.1.3.
3221 }
3222
3223 $content_text .= '</div>';
3224 }
3225
3226 if ( ! $this->is_frontend ) {
3227 // Trash
3228 $content_text .= '<div class=\'flex-label flex-label-trash' . ( ( ! $bookings[$bk_id]->trash ) ? ' hidden_items ' : '' ) . '\'>';
3229 $content_text .= '<span class=\'\'>' . esc_js( __('Trash / Reject' ,'booking') ) . '</span>'; //FixIn: 6.1.1.10 // FixIn: 7.1.1.3.
3230 $content_text .= '</div>';
3231 }
3232
3233
3234 $content_text .= '</div>';
3235
3236
3237 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
3238 // Cost Bar
3239 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
3240 if ( ( class_exists( 'wpdev_bk_biz_s' ) ) ) { //&& ( ! $this->is_frontend ) ){
3241
3242 $content_text .= '<div class=\'flex-popover-cost-bar\' >';
3243
3244 // FixIn: 8.3.3.9.
3245 if ( floatval( $bookings[ $bk_id ]->cost ) > 0 ) {
3246 // Cost
3247 $booking_cost = wpbc_get_cost_with_currency_for_user( $bookings[ $bk_id ]->cost, $bookings[ $bk_id ]->booking_type );
3248
3249 $content_text .= '<div class=\'flex-label flex-label-cost\' >';
3250 //$content_text .= '<div class=\'text-left field-labels booking-labels\'>';
3251 $content_text .= '<div class=\'\'>' . $booking_cost . '</div>';
3252 //$content_text .= '</div>';
3253 $content_text .= '</div>';
3254 }
3255
3256 $content_text .= '</div>';
3257
3258 }
3259
3260 $content_text .= '</div>';
3261
3262
3263
3264 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3265 // Booking Data
3266 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3267
3268 // Booking Data
3269 $content_text .= '<div class=\'clear\'></div>'; // FixIn: 8.7.9.4.
3270 $content_text .= '<div class=\'flex-popover-booking-data\'>' . esc_textarea( $bookings[$bk_id]->form_show ) . '</div>'; // FixIn: 7.1.1.2.
3271 $content_text .= '<div class=\'clear\'></div>'; // FixIn: 8.7.9.4.
3272
3273 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3274 // Notes
3275 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3276
3277 // Notes
3278 if ( ! empty( $bookings[$bk_id]->remark ) ) {
3279 $content_text .= '<div class=\'wpbc-popover-booking-notes\'>' . '<strong>' . esc_js( __('Note', 'booking') ). ':</strong> ' . esc_textarea( $bookings[$bk_id]->remark ) . '</div>'; //FixIn: 7.1.1.2 // FixIn: 7.1.1.3.
3280 }
3281
3282 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3283 // Dates
3284 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3285
3286 $bk_dates_short_id = array(); //BL
3287 if ( count( $bookings[$bk_id]->dates ) > 0 )
3288 $bk_dates_short_id = (isset( $bookings[$bk_id]->dates_short_id )) ? $bookings[$bk_id]->dates_short_id : array(); // Array ([0] => [1] => .... [4] => 6... [11] => [12] => 8 )
3289
3290 $short_dates_content = wpbc_get_short_dates_formated_to_show( $bookings[$bk_id]->dates_short, $is_approved, $bk_dates_short_id, $booking_types );
3291 $short_dates_content = str_replace( '"', "'", $short_dates_content );
3292
3293 $content_text .= '<div class=\'flex-label-dates \'>';
3294 $content_text .= $short_dates_content;
3295 $content_text .= '</div>';
3296
3297 // FixIn: 8.9.4.14.
3298 $date_format = get_bk_option( 'booking_date_format' );
3299 if ( empty( $date_format ) ) {
3300 $date_format = 'm / d / Y, D';
3301 }
3302 $time_format = get_bk_option( 'booking_time_format' );
3303 if ( empty( $time_format ) ) {
3304 $time_format = 'h:i a';
3305 }
3306 $cr_date = wpbc_datetime__no_wp_timezone( $date_format . ' ' . $time_format, mysql2date( 'U', $bookings[ $bk_id ]->modification_date ) );
3307 $content_text .= '<div class=\'wpbc-listing-collumn field-system-info \'>';
3308 $content_text .= __( 'Created', 'booking' ) . ': ' . $cr_date;
3309 $content_text .= '</div>';
3310
3311
3312 $content_text .= '</div>'; // Main Container: 'flex-popover-content-data'
3313
3314 $popover = array(
3315 'title' => $header_title,
3316 'content' => $content_text
3317 );
3318
3319 if ( function_exists( 'wpbc_is_11_5_features_enabled' ) && wpbc_is_11_5_features_enabled() ) {
3320 $popover = apply_filters( 'wpbc_timeline_booking_popover', $popover, $bk_id, $bookings, $this->is_frontend );
3321 }
3322
3323 return $popover;
3324 }
3325
3326 }
3327
3328
3329
3330 /** Navigation of Timeline in Ajax request */
3331 function wpbc_ajax_flex_timeline() {
3332 /*
3333 [timeline_obj] => Array
3334 (
3335 [is_frontend] => 1
3336 [html_client_id] => wpbc_timeline_1454680376080
3337 [wh_booking_type] => 3,4,1,5,6,7,8,9,2,10,11,12,14
3338 [is_matrix] => 1
3339 [view_days_num] => 30
3340 [scroll_start_date] =>
3341 [scroll_day] => 0
3342 [scroll_month] => 0
3343 )
3344 */
3345
3346 // Public timeline navigation accepts only one flat scalar attribute map.
3347 // phpcs:ignore WordPress.Security.NonceVerification.Missing
3348 if ( ! isset( $_POST['timeline_obj'] ) || ! is_array( $_POST['timeline_obj'] ) ) {
3349 status_header( 400 );
3350 wp_die( '' );
3351 }
3352
3353 $attr = array();
3354 $allowed_timeline_keys = array_fill_keys(
3355 array(
3356 'is_frontend',
3357 'html_client_id',
3358 'wh_booking_type',
3359 'is_matrix',
3360 'view_days_num',
3361 'scroll_start_date',
3362 'scroll_day',
3363 'scroll_month',
3364 'header_column1',
3365 'header_column2',
3366 'header_title',
3367 'wh_trash',
3368 'limit_hours',
3369 'only_booked_resources',
3370 'options',
3371 'booking_hash',
3372 ),
3373 true
3374 );
3375 // phpcs:ignore WordPress.Security.NonceVerification.Missing
3376 foreach ( $_POST['timeline_obj'] as $tl_key => $tl_value ) {
3377 if ( ! is_scalar( $tl_key ) || ! is_scalar( $tl_value ) ) {
3378 status_header( 400 );
3379 wp_die( '' );
3380 }
3381
3382 $clean_key = sanitize_key( wp_unslash( (string) $tl_key ) );
3383 if ( '' === $clean_key || ! isset( $allowed_timeline_keys[ $clean_key ] ) ) {
3384 continue;
3385 }
3386 $attr[ $clean_key ] = wpbc_clean_text_value( wp_unslash( (string) $tl_value ) );
3387 }
3388
3389 // phpcs:ignore WordPress.Security.NonceVerification.Missing
3390 if ( isset( $_POST['nav_step'] ) && ! is_scalar( $_POST['nav_step'] ) ) {
3391 status_header( 400 );
3392 wp_die( '' );
3393 }
3394
3395 $attr['nav_step'] = isset( $_POST['nav_step'] ) ? wpbc_clean_text_value( wp_unslash( (string) $_POST['nav_step'] ) ) : '0'; // phpcs:ignore WordPress.Security.NonceVerification.Missing
3396 $attr['is_frontend'] = isset( $attr['is_frontend'] ) ? $attr['is_frontend'] : '1';
3397 if ( empty( $attr['html_client_id'] ) ) {
3398 status_header( 400 );
3399 wp_die( '' );
3400 }
3401
3402 // FixIn: 9.9.0.18.
3403 $server_zone = date_default_timezone_get(); // If in 'Theme' or 'other plugin' set default timezone other than UTC. Save it.
3404 if ( 'UTC' !== $server_zone ) { // Needed for WP date functions - set timezone to UTC.
3405 // phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
3406 @date_default_timezone_set( 'UTC' );
3407 }
3408
3409 ob_start();
3410
3411 $timeline = new WPBC_TimelineFlex();
3412
3413 $html_client_id = $timeline->ajax_init( $attr ); // Define arameters and get bookings
3414 //debuge($timeline->options);
3415
3416 //echo '<div class="wpbc_timeline_ajax_replace">'; // Replace content of this container
3417 $timeline->show_timeline();
3418
3419
3420 $is_show_popover_in_timeline = wpbc_is_show_popover_in_flex_timeline( $attr['is_frontend'], $attr['booking_hash'] ); // FixIn: 8.1.3.5.
3421
3422 if ( $is_show_popover_in_timeline ) { // Update New Popovers
3423
3424 $html = '<script type="text/javascript"> ' . wpbc_jq_ready_start(); // FixIn: 10.1.3.7.
3425 $html .= ' wpbc_define_tippy_popover(); ';
3426 $html .= wpbc_jq_ready_end() . '</script>'; // FixIn: 10.1.3.7.
3427
3428 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
3429 echo $html;
3430
3431 /* ?><script type="text/javascript"> wpbc_define_tippy_popover(); </script><?php */
3432 }
3433 //echo '</div>';
3434
3435
3436 $timeline_results = ob_get_contents();
3437
3438 ob_end_clean();
3439
3440 // FixIn: 9.9.0.18.
3441 if ( 'UTC' !== $server_zone ) { // Back to previos state, if it was changed.
3442 // phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
3443 @date_default_timezone_set( $server_zone );
3444 }
3445
3446 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
3447 echo $timeline_results ;
3448 }
3449 add_bk_action('wpbc_ajax_flex_timeline', 'wpbc_ajax_flex_timeline');
3450
3451
3452
3453 /** Check if we are showing booking details or not
3454 * Admin panel - always show
3455 * Timeline - show if activated setting option
3456 * Customer listing - show always, if valid hash.
3457 *
3458 * @param $is_frontend
3459 * @param $booking_hash
3460 *
3461 * @return bool
3462 */
3463 function wpbc_is_show_popover_in_flex_timeline( $is_frontend, $booking_hash ) {
3464
3465 // Default for admin.
3466 $is_show_popover_in_timeline = true;
3467
3468 // For client Timeline.
3469 if ( $is_frontend ) {
3470
3471 // FixIn: 10.14.11.1.
3472 if ( WPBC_DISABLE_POPOVER_IN_TIMELINE ) {
3473 $is_show_popover_in_timeline = false;
3474 } else {
3475 $is_show_popover_in_timeline = ( get_bk_option( 'booking_is_show_popover_in_timeline_front_end' ) == 'On' ) ? true : false;
3476 if ( ! class_exists( 'wpdev_bk_personal' ) ) {
3477 $is_show_popover_in_timeline = false; // FixIn: 10.14.9.2.
3478 }
3479 }
3480 }
3481
3482 // For customer booking listing with ability to edit.
3483 // FixIn: 8.1.3.5.
3484 if ( ( $is_frontend ) && ( ! empty( $booking_hash ) ) ) {
3485
3486 // In case if we have valid valid hash then show booking details.
3487 $my_booking_id_type = wpbc_hash__get_booking_id__resource_id( $booking_hash );
3488
3489 if ( ! empty( $my_booking_id_type ) ) {
3490 $is_show_popover_in_timeline = true;
3491 } else {
3492 $is_show_popover_in_timeline = false;
3493 }
3494 }
3495 return $is_show_popover_in_timeline;
3496 }
3497
3498
3499
3500 /**
3501 * TimeLine shortcode
3502 *
3503 * @param type $attr
3504 * @return type
3505 *
3506 * Shortcodes exmaples:
3507 *
3508 *
3509 ** Matrix:
3510 * 1 Month View Mode:
3511 [bookingtimeline type="3,4,1,5,6,7,8,9,2,10,11,12,14" view_days_num=30 scroll_start_date="" scroll_month=0 header_title='All Bookings']
3512 * 2 Months View Mode:
3513 [bookingtimeline type="1,5,6,7,8,9,2,10,11,12,3,4,14" view_days_num=60 scroll_start_date="" scroll_month=-1 header_title='All Bookings']
3514 * 1 Week View Mode:
3515 [bookingtimeline type="3,4" view_days_num=7 scroll_start_date="" scroll_day=-7 header_title='All Bookings']
3516 * 1 Day View Mode:
3517 [bookingtimeline type="3,4" view_days_num=1 scroll_start_date="" scroll_day=0 header_title='All Bookings']
3518
3519 ** Single:
3520 * 1 Month View Mode:
3521 [bookingtimeline type="4" view_days_num=30 scroll_start_date="" scroll_day=-15 scroll_month=0 header_title='All Bookings']
3522 * 3 Months View Mode:
3523 [bookingtimeline type="4" view_days_num=90 scroll_start_date="" scroll_day=-30]
3524 * 1 Year View Mode:
3525 [bookingtimeline type="4" view_days_num=365 scroll_start_date="" scroll_month=-3]
3526
3527
3528 */
3529 function bookingflextimeline_shortcode($attr) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
3530
3531 if ( wpbc_is_on_edit_page() ) {
3532 return wpbc_get_preview_for_shortcode( 'bookingflextimeline', $attr ); // FixIn: 9.9.0.39.
3533 }
3534
3535 $attr = wpbc_escape_shortcode_params( $attr ); //FixIn: 9.7.3.6.1
3536
3537 if ( '' === $attr ) {
3538 $attr = array(); // FixIn: 9.9.0.30.
3539 }
3540
3541 //if ( function_exists( 'wpbc_br_cache' ) ) $br_cache = wpbc_br_cache(); // Init booking resources cache
3542 if ( isset( $attr['resource_id'] ) ) { $attr['type'] = $attr['resource_id']; }
3543 if ( empty( $attr['type'] ) ) { // 8.7.7.4
3544 if ( class_exists( 'wpdev_bk_personal' ) ) {
3545 $br_list = wpbc_get_all_booking_resources_list();
3546 $br_list = array_keys( $br_list );
3547 $br_list = implode( ',', $br_list );
3548 $attr['type'] = $br_list;
3549 } else {
3550 $attr['type'] = wpbc_get_default_resource();
3551 }
3552 }
3553
3554 if ( ! isset( $attr['view_days_num' ] ) ) {
3555 $attr['view_days_num' ] = 30;
3556 }
3557 if ( ! isset( $attr['scroll_start_date' ] ) ) {
3558 $attr['scroll_start_date' ] = '';
3559 }
3560 if ( ! isset( $attr['scroll_day' ] ) ) {
3561 $attr['scroll_day' ] = 0;
3562 }
3563 if ( ! isset( $attr['scroll_month' ] ) ) {
3564 $attr['scroll_month' ] = 0;
3565 }
3566 if ( ! isset( $attr['header_title' ] ) ) {
3567 $attr['header_title' ] = '';
3568 }
3569
3570 // FixIn: 9.9.0.18.
3571 $server_zone = date_default_timezone_get(); // If in 'Theme' or 'other plugin' set default timezone other than UTC. Save it.
3572 if ( 'UTC' !== $server_zone ) { // Needed for WP date functions - set timezone to UTC
3573 // phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
3574 @date_default_timezone_set( 'UTC' );
3575 }
3576
3577 ob_start();
3578
3579 $timeline = new WPBC_TimelineFlex();
3580
3581 $html_client_id = $timeline->client_init( $attr ); // Define arameters and get bookings
3582
3583 //wpbc_datepicker_js(); // JS Datepicker
3584 //wpbc_datepicker_css(); // CSS DatePicker
3585
3586
3587 echo '<div class="wpdevelop">';
3588
3589 echo '<div id="' . esc_attr( $html_client_id ) . '" class="wpbc_timeline_client_border">';
3590
3591 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
3592 echo wp_nonce_field( 'WPBC_FLEXTIMELINE_NAV', 'wpbc_nonce_' . esc_attr( $html_client_id ), true, false );
3593 echo '<div id="ajax_respond_insert' . esc_attr( $html_client_id ) . '" class="ajax_respond_insert" style="display:none;"></div>';
3594
3595 echo '<div class="wpbc_timeline_ajax_replace">';
3596 if ( ! WPBC()->booking_obj->popover_front_end_js_is_writed ) { //Write this JS only once at page
3597 wpbc_bs_javascript_popover(); // JS Popover
3598 WPBC()->booking_obj->popover_front_end_js_is_writed = true;
3599 } // FixIn: 9.2.1.3.
3600
3601 //Define Global JavaScript Object - array of objects. // FixIn: 9.2.1.3.
3602 ?>
3603 <script type="text/javascript">
3604 var wpbc_timeline_obj;
3605 if ( undefined === wpbc_timeline_obj ){
3606 wpbc_timeline_obj = [];
3607 }
3608 </script>
3609 <?php
3610
3611 $timeline->show_timeline();
3612 echo '</div>';
3613
3614 echo '</div>';
3615
3616 echo '</div>';
3617
3618 // Fix for "Twenty Two" theme.
3619 // Theme incorrectly closing HTML elements with attributes that contain HTML tags in content of the posts and pages.
3620 // For example, if the HTML element have tags like this
3621 // <div data-content="<div class='flex-popover-content-data'>Data</div>" data-original-title="<div class='popover-title-id' > ID: 19</div>" >My text</div>
3622 // Theme show info like this
3623 // <div data-content="<div class='flex-popover-content-data'>Data</div>” data-original-title=”<div class='popover-title-id' > ID: 19</div>” >My text</div>
3624 /*
3625 ?><script type="text/javascript">
3626 wpbc_flextimeline_nav( wpbc_timeline_obj['<?php echo $html_client_id; ?>'], 0 );
3627 </script><?php
3628 */
3629
3630 $timeline_results = ob_get_contents();
3631
3632 ob_end_clean();
3633
3634 // FixIn: 9.9.0.18.
3635 if ( 'UTC' !== $server_zone ) { // Back to previos state, if it was changed.
3636 // phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
3637 @date_default_timezone_set( $server_zone );
3638 }
3639
3640 return $timeline_results ;
3641 }
3642 add_shortcode( 'bookingflextimeline', 'bookingflextimeline_shortcode' );
3643
3644
3645
3646 /** JSS */
3647 function wpbc_timeline_js_load_files( $where_to_load ) {
3648
3649 // FixIn: 8.6.1.13.
3650
3651 $is_in_footer = ! true;
3652
3653 if ( in_array( $where_to_load, array( 'admin', 'both', 'client' ) ) ) {
3654
3655 wp_enqueue_script( 'wpbc-timeline-flex'
3656 , trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/timeline_v2.js' /* wpbc_plugin_url( '/core/timeline/wpbc-flex-timeline.js' ) */
3657 , array( 'wpbc_all' /*, 'wp-element'*/ )
3658 , WP_BK_VERSION_NUM
3659 , array( 'in_footer' => WPBC_JS_IN_FOOTER ) //, $is_in_footer
3660 );
3661 }
3662 }
3663 add_action( 'wpbc_enqueue_js_files', 'wpbc_timeline_js_load_files', 50 );
3664
3665
3666 /** CSS */
3667 function wpbc_timeline_enqueue_css_files( $where_to_load ) {
3668
3669 // FixIn: 8.6.1.13.
3670
3671 if ( in_array( $where_to_load, array( 'admin', 'both', 'client' ) ) ) {
3672
3673 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
3674 if ( ( ( isset($_REQUEST['tab']) ) && ( $_REQUEST['tab']== 'vm_calendar' ) ) || ( 'client' == $where_to_load ) ){
3675
3676 wp_enqueue_style( 'wpbc-flex-timeline'
3677 , trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/timeline_v2.1.css' /* wpbc_plugin_url( '/src/css/code_mirror.css' ) */
3678 , array()
3679 , WP_BK_VERSION_NUM );
3680 }
3681 }
3682 }
3683 add_action( 'wpbc_enqueue_css_files', 'wpbc_timeline_enqueue_css_files', 50 );
3684