PluginProbe
Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar / 2.1.9
Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar v2.1.9
2.1.22 2.1.21 2.1.20 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 trunk 1.1 2.0 2.0.1 2.0.10.2 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.17 2.0.18 2.0.2 2.0.20 2.0.21 All 56 releases
booking-manager / core / wpbc / wpbm-bc-import.php

wpbm-bc-import.php in Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar 2.1.9, at core/wpbc/wpbm-bc-import.php

1,437 lines 62.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @version 1.0
4 * @description Booking Calendar integration - Import bookings from ICS events
5 *
6 * @author wpdevelop
7 * @link https://oplugins.com/
8 * @email [email protected]
9 *
10 * @modified 2017-06-28
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
14
15
16 /**
17 * Move All imported bookings into the Trash
18 *
19 * @return bool
20 */
21 function wpbm_delete_all_imported_bookings( $params ){ //FixIn: 2.0.10.3
22
23 $booking_ics_force_trash_before_import = get_bk_option( 'booking_ics_force_trash_before_import' ); //FixIn: 2.0.10.1 <- available in Booking Calendar since update 2.0.10
24
25 if ( 'Off' == $booking_ics_force_trash_before_import ) {
26 return false;
27 }
28
29 global $wpdb;
30
31 $resource_id = $params['resource_id'];
32 $is_trash = 1;
33
34 //FixIn: 2.0.24.1 //FixIn: 9.1.2.6
35 if (
36 ( 'On' == $booking_ics_force_trash_before_import )
37 || ( 'trash' == $booking_ics_force_trash_before_import )
38 ) {
39 // Trash bookings
40 $my_sql = "UPDATE {$wpdb->prefix}booking AS bk SET bk.trash = {$is_trash} WHERE sync_gid != '' AND trash != 1 AND booking_type = {$resource_id}";
41
42 if ( false === $wpdb->query( $my_sql ) ) {
43 ?> <script type="text/javascript"> var my_message = '<?php echo html_entity_decode( esc_js( get_debuge_error( 'Error during trash booking in DB', __FILE__, __LINE__ ) ), ENT_QUOTES ); ?>'; wpbc_admin_show_message( my_message, 'error', 30000 ); </script> <?php
44 return false;
45 }
46
47 } else { // Permanently delete bookings
48
49 $bookings_obj_arr = $wpdb->get_results( "SELECT booking_id as ID FROM {$wpdb->prefix}booking WHERE sync_gid != '' AND trash != 1 AND booking_type = {$resource_id} LIMIT 0, 1000" );
50
51 $id_arr = array();
52 foreach ( $bookings_obj_arr as $booking_obj ) {
53 $id_arr[] = $booking_obj->ID;
54 }
55 $string_id = implode( ',', $id_arr );
56
57 if ( $string_id != '' ) {
58
59 // D E L E T E Dates
60 if ( false === $wpdb->query( "DELETE FROM {$wpdb->prefix}bookingdates WHERE booking_id IN ({$string_id})" ) ) { ?> <script type="text/javascript"> document.getElementById('ajax_working').innerHTML = '<div style=&quot;height:20px;width:100%;text-align:center;margin:15px auto;&quot;><?php debuge_error('Error during updating exist booking for deleting dates in BD' ,__FILE__,__LINE__); ?></div>'; </script> <?php die(); }
61 // D E L E T E Bookings
62 if ( false === $wpdb->query( "DELETE FROM {$wpdb->prefix}booking WHERE booking_id IN ({$string_id})" ) ){ ?> <script type="text/javascript"> document.getElementById('ajax_working').innerHTML = '<div style=&quot;height:20px;width:100%;text-align:center;margin:15px auto;&quot;><?php debuge_error('Error during deleting booking at DB',__FILE__,__LINE__ ); ?></div>'; </script> <?php die(); }
63 }
64
65 }
66
67 return true;
68 }
69
70 ////////////////////////////////////////////////////////////////////////////////////////////
71 // I M P O R T
72 ////////////////////////////////////////////////////////////////////////////////////////////
73
74 /** Import ICS feed and create bookings .in Booking Calendar
75 *
76 * @param array $attr = array(
77 'url' => ''
78 , 'resource_id' => 1
79 , 'import_conditions' => '' | 'if_dates_free' // maybe rename ??? if_dates_booked_then_not_import
80 )
81 * @return int|bool number of imported bookings or FALSE if error
82 */
83 function wpbm_ics_import_start( $attr ) {
84
85 if ( ! wpbm_is_wpbc_supported() ) {
86 // echo 'Booking Manager require Booking Calendar 9.8 or newer';
87 return wpbm_ics_import_start_legacy( $attr );
88
89 }
90
91 // <editor-fold defaultstate="collapsed" desc=" Parse / validate parameters " >
92 /////////////////////////////////////////////////////////////////////
93 // Parse / validate parameters
94 /////////////////////////////////////////////////////////////////////
95 $defaults = array(
96 'url' => ''
97 , 'resource_id' => 1
98 , 'delete' => 0
99 , 'import_conditions' => ''
100 , 'from' => 'any' // 'today' // '00:00 today'
101 , 'from_offset' => ''
102 , 'until' => 'any' // 'year-end'
103 , 'until_offset' => ''
104 , 'max' => ''
105 , 'is_all_dates_in' => true // Conditional of Dates checking. TRUE - Remove event if al least 1 day not in conditional interval, FALSE - save event, if at leat one date in conditional interval
106 );
107 $shortcode = array();
108
109 foreach ( $attr as $param_name => $param_value ) {
110
111 switch ( $param_name) { // Validate Params
112
113 case 'url':
114 $shortcode[ $param_name ] = esc_url_raw( $param_value ); // $shortcode[ 'url' ]
115 $shortcode[ $param_name ] = str_replace( '&amp;', '&', $shortcode[ $param_name ] ); //FixIn: 2.0.14.2
116 break;
117
118 case 'import_conditions':
119 $shortcode[ $param_name ] = esc_attr( $param_value ); // $shortcode[ 'resource_id' ]
120 break;
121
122 case 'resource_id':
123 $shortcode[ $param_name ] = intval($param_value ); // $shortcode[ 'resource_id' ]
124 break;
125
126 case 'from': // 'now', 'today', 'week', 'month-start', 'month-end', 'year-start', 'any', 'date' = 2017-08-07
127 $shortcode[ $param_name ] = $param_value;
128 break;
129
130 case 'from_offset': // 5d, 10h, 5m, 30s -- if from: { 'now', 'today', 'week', 'month-start', 'month-end', 'year-start' }
131 $shortcode[ $param_name ] = $param_value;
132 break;
133
134 case 'until': // 'now', 'today', 'week', 'month-start', 'month-end', 'year-end', 'any', 'date' = 2017-08-07
135 $shortcode[ $param_name ] = $param_value;
136 break;
137
138 case 'until_offset': // 5d, 10h, 5m, 30s -- if until: { 'now', 'today', 'week', 'month-start', 'month-end', 'year-end' }
139 $shortcode[ $param_name ] = $param_value;
140 break;
141
142 case 'max':
143 $shortcode[ $param_name ] = intval( $param_value );
144 break;
145
146 case 'is_all_dates_in': // Conditional of Dates checking. TRUE - Remove event if al least 1 day not in conditional interval, FALSE - save event, if at leat one date in conditional interval
147 $shortcode[ $param_name ] = intval( $param_value );
148 break;
149
150
151 default:
152 $shortcode[ $param_name ] = $param_value;
153 break;
154 }
155 }
156 $shortcode = wp_parse_args( $shortcode, $defaults );
157 // </editor-fold>
158
159 // <editor-fold defaultstate="collapsed" desc=" Notice - Import Parameters | Error No URL" >
160
161 do_action( 'wpbc_show_debug', array( 'Import Parameters' , $shortcode ) ); // S_Y_S_T_E_M L_O_G
162
163 if ( empty( $shortcode[ 'url' ] ) ) {
164 do_action( 'wpbc_admin_show_top_notice', __( 'No ics url feed', 'booking-manager' ), 'error', 5000 ); // N_O_T_I_C_E in H_E_A_D_E_R
165 return false;
166 }
167 // </editor-fold>
168
169 ///////////////////////////////////////////////////////////////////// - Get, Parse ICS Feed
170
171 $ics_array = wpbm_ics_file_to_array( $shortcode[ 'url' ] );
172
173 // <editor-fold defaultstate="collapsed" desc=" Notice - feed contain N events | Error Importing " >
174 do_action( 'wpbc_show_debug', array( 'Imported data' , $ics_array) ); // S_Y_S_T_E_M L_O_G
175
176 // If Error
177 if ( is_wp_error( $ics_array ) ) {
178
179 $error_message = $ics_array->get_error_message();
180 do_action( 'wpbc_admin_show_top_notice', $error_message, 'error', 5000 ); // N_O_T_I_C_E in H_E_A_D_E_R
181 return false;
182 }
183
184 //FixIn: 2.0.7.3
185 $ics_array_events_num = 0;
186 if ( ( ! empty( $ics_array ) ) && ( ! empty( $ics_array[ 'events' ] ) ) && ( is_array( $ics_array[ 'events' ] ) ) ) {
187 $ics_array_events_num = count( $ics_array[ 'events' ] );
188 }
189 do_action( 'wpbc_admin_show_top_notice' // N_O_T_I_C_E in H_E_A_D_E_R
190 , sprintf ( __( '.ics feed contain %s events at URL %s', 'booking-manager' ), '<b>' . $ics_array_events_num . '</b>', '<b><a href="'. $shortcode[ 'url' ] .'">' . $shortcode[ 'url' ] . '</a></b>' )
191 , 'info', 5000 );
192 // </editor-fold>
193
194 if ( 'skip' != $shortcode['delete'] ) {
195 wpbm_delete_all_imported_bookings( array( 'resource_id' => $shortcode['resource_id'] ) ); //FixIn: 2.0.18.3 //FixIn: 2.0.10.3
196 }
197
198
199 $bk_array = array();
200 // Get Only '_BOOKING...' field from ICS array
201 if ( $ics_array !== false ) {
202 $bk_array = wpbm_get_booking_fields_from_ics_array( $ics_array[ 'events' ] );
203 }
204
205 do_action( 'wpbc_show_debug', array( 'Imported Events', $bk_array ) ); // S_Y_S_T_E_M L_O_G
206
207
208 //FixIn: 2.0.6.1 - Set timezone frrom Booking > Settings > Sync page for booking listing shortcode
209 $tzid = get_bk_option( 'booking_gcal_timezone' );
210 if ( ! empty( $tzid ) ) {
211 foreach ( $bk_array as $bk_k => $bk_ics_data_arr ) {
212
213
214 //apply our timezone from the Booking > Settings > Search page
215 foreach ( $bk_array[ $bk_k ]['_BOOKING_DATES'] as $dk => $day ) {
216 //$bk_array[ $bk_k ][ '_BOOKING_DATES' ][ $dk ] = ZDateHelper::toLocalDateTime( get_gmt_from_date( $day ), $tzid );
217
218 //FixIn: 2.0.7.4 - Skip adding Timezone to "middle" days, if days start with time 00:00:00 - its means event for full day, not the start/end time
219 // Apply timezone only to fist and last days in a list, if the change over days activated in the Booking Calendar
220 $ics_time_in_day = substr( $day, -8);
221 if ( '00:00:00' == $ics_time_in_day ) {
222 continue;
223 }
224 //FixIn: 2.0.7.4 - Skip adding Timezone to "middle" days, if Booking Calendar use change over days, to prevent of having clock icon in middle days.
225 if ( ( class_exists( 'wpdev_bk_biz_s' ) )
226 && ( get_bk_option( 'booking_range_selection_time_is_active') == 'On' )
227 && ( get_bk_option( 'booking_ics_import_add_change_over_time' ) !== 'Off' )
228 ) { //FixIn: 2.0.5.1
229 $days_number = count( $bk_array[ $bk_k ]['_BOOKING_DATES'] );
230 if ( ( 0 != $dk ) && ( ( $days_number - 1) != $dk ) ) {
231 continue;
232 }
233 // We are append one day to the booking, so skip this day for timezone, as well
234 if ( ( get_bk_option( 'booking_ics_import_append_checkout_day' ) !== 'Off' ) && ( ( $days_number - 1) == $dk ) ) {
235 continue;
236 }
237 }
238
239 $bk_array[ $bk_k ]['_BOOKING_DATES'][ $dk ] = ZDateHelper::toLocalDateTime( $day, $tzid );
240 }
241 }
242 }
243
244 ///////////////////////////////////////////////////////////////////// - Check if these EVENTS was imported before or NOT
245
246 $booking_ics_force_import = get_bk_option( 'booking_ics_force_import' ); //FixIn: 2.0.10.1
247 $booking_condition_import_only_new = get_bk_option( 'booking_condition_import_only_new' ); //FixIn: 9.8.15.8
248 if ( false === $booking_condition_import_only_new ) {
249 // OLD:
250 if ( 'On' !== $booking_ics_force_import ) {
251 $bk_array = wpbm_clear_events_from_exist_bookings( $bk_array );
252 }
253 } else {
254 // NEW
255 if ( 'On' === $booking_condition_import_only_new ) {
256 $bk_array = wpbm_clear_events_from_exist_bookings( $bk_array );
257 }
258 }
259
260
261 // <editor-fold defaultstate="collapsed" desc=" Notice - if events was imported previously | Already ALL Imported " >
262 do_action( 'wpbc_show_debug', array( 'Check, if events was imported previously. New events: ', $bk_array ) ); // S_Y_S_T_E_M L_O_G
263
264 if ( empty( $bk_array ) ) {
265
266 do_action( 'wpbc_admin_show_top_notice' // N_O_T_I_C_E in H_E_A_D_E_R
267 , '<strong>' . __( 'Warning', 'booking' ) . '!</strong> '
268 . sprintf( __( 'No any new events to import! These events was import previously, already.', 'booking-manager' ), '<strong>' . count( $bk_array ) . '</strong>' )
269 , 'warning', 3000 );
270 return 0;
271 }
272 // </editor-fold>
273
274
275 ///////////////////////////////////////////////////////////////////// - Skip events that does not fit to filter parameters: FROM - UNTIL
276
277 // Sort Events
278 $bk_array = wpbm_sort_events_by( $bk_array );
279
280 // Filter By Dates - "From - Until"
281 $bk_array = wpbm_clear_events_by_dates( $bk_array, $shortcode );
282
283 // Filter events by - "Max"
284 $bk_array = wpbm_clear_events_by_count( $bk_array, $shortcode );
285
286
287 // <editor-fold defaultstate="collapsed" desc=" Notice - Creation of N bookings " >
288 do_action( 'wpbc_admin_show_top_notice' // N_O_T_I_C_E in H_E_A_D_E_R
289 , sprintf( __( 'Imported of %s bookings', 'booking-manager' ), '<strong>' . count( $bk_array ) . '</strong>' )
290 , 'info', 3000 );
291
292 do_action( 'wpbc_show_debug', array( 'Create bookings after filtering', $bk_array ) ); // S_Y_S_T_E_M L_O_G
293 // </editor-fold>
294
295 ///////////////////////////////////////////////////////////////////// - Loop events > C r e a t e B o o k i n g s
296
297 // Get assigning fields for SUMMARY, DESCRIPTION, LOCATION
298 $assigned_fields_arr = WPBM_create_bookings_from_events::get_assigned_form_fields();
299
300 $booking_added_num = 0;
301
302 foreach ( $bk_array as $ics_event) {
303
304 //FixIn: 2.1.3
305 if (
306 ( 'On' == get_bk_option( 'booking_ics_import_append_checkout_day' ) )
307 || (
308 ( class_exists( 'wpdev_bk_biz_s' ) )
309 && ( get_bk_option( 'booking_range_selection_time_is_active') == 'On' )
310 && ( get_bk_option( 'booking_ics_import_add_change_over_time' ) !== 'Off' )
311 && ( count( $ics_event[ '_BOOKING_DATES' ] ) == 1 )
312 )
313 ) { //FixIn: 2.0.27.1 //FixIn: 9.5.4.1
314 // Add one additional day to .ics event (useful in some cases for bookings with change-over days), if the imported .ics dates is coming without check in/our times
315 // Later system is adding check in/out times from Booking Calendar to this event
316 $ics_event_check_out = $ics_event['_BOOKING_DATES'][ ( count( $ics_event['_BOOKING_DATES'] ) - 1 ) ];
317
318 //FixIn Start: 2.0.28.1 ------------------------------------------------------------------------------------
319 // Is check in/out dates in this event it's the same date
320 $test_check_in = substr( $ics_event['_BOOKING_DATES'][0], 0, 10 );
321 $test_check_out = substr( $ics_event['_BOOKING_DATES'][ ( count( $ics_event['_BOOKING_DATES'] ) - 1 ) ], 0, 10 );
322 if ( count( $ics_event['_BOOKING_DATES'] ) > 1 ) { //FixIn: 2.1.3
323 if ( $test_check_in === $test_check_out ) {
324 // It is the same date, like 2024-02-12 10:00:01, 2024-02-12 14:59:52, then remove this date, because we will add new date
325 unset( $ics_event['_BOOKING_DATES'][ ( count( $ics_event['_BOOKING_DATES'] ) - 1 ) ] );
326 // Important! Reindex array, after unset operation.
327 $ics_event['_BOOKING_DATES'] = array_values( $ics_event['_BOOKING_DATES'] );
328 } else {
329 // It is other date, in this case, we need to define other time:
330 $ics_event['_BOOKING_DATES'][ ( count( $ics_event['_BOOKING_DATES'] ) - 1 ) ] = $test_check_out . ' 00:00:00';
331 }
332 }
333 //FixIn End: 2.0.28.1 --------------------------------------------------------------------------------------
334
335 $ics_event_check_out = strtotime( $ics_event_check_out );
336 $ics_event_check_out = strtotime( '+1 day', $ics_event_check_out );
337 $ics_event_check_out = date_i18n( "Y-m-d H:i:s", $ics_event_check_out ); //FixIn: 2.0.28.1 //$ics_event_check_out = date_i18n( "Y-m-d 00:00:00", $ics_event_check_out );
338 $ics_event['_BOOKING_DATES'][] = $ics_event_check_out;
339 }
340
341 $booking_data = array();
342
343 if ( ( class_exists( 'wpdev_bk_biz_s' ) )
344 && ( get_bk_option( 'booking_range_selection_time_is_active') == 'On' )
345 && ( get_bk_option( 'booking_ics_import_add_change_over_time' ) !== 'Off' )
346 && ( count( $ics_event[ '_BOOKING_DATES' ] ) > 1 )
347 ) {
348 $dates_formats = array_fill( 0, count( $ics_event[ '_BOOKING_DATES' ] ), "Y-m-d" ); // Array ( [0] => Y-m-d [1] => Y-m-d ... )
349 } else {
350 $dates_formats = array_fill( 0, count( $ics_event[ '_BOOKING_DATES' ] ), "Y-m-d H:i:s" ); //FixIn: 2.0.15.4
351 }
352 $booking_dates_unix = array_map( 'strtotime', $ics_event[ '_BOOKING_DATES' ] ); // Array ( [0] => 1498262400 [1] => 1498348800 )
353 $simple_booking_dates = array_map( 'date_i18n', $dates_formats , $booking_dates_unix ); // Array ( '2017-06-23', '2017-06-24', '2017-06-25', '2017-06-26' )
354
355
356 //Add check in/out times to full day events //FixIn: 8.1.3.29
357 if ( ( class_exists( 'wpdev_bk_biz_s' ) )
358 && ( get_bk_option( 'booking_range_selection_time_is_active') == 'On' )
359 && ( get_bk_option( 'booking_ics_import_add_change_over_time' ) !== 'Off' )
360 ) { //FixIn: 2.0.5.1
361
362 if ( ( is_array( $simple_booking_dates ) ) && ( count( $simple_booking_dates ) > 1 ) ) { //FixIn: 2.0.10.4
363 $wpbc_check_in = ' ' . get_bk_option( 'booking_range_selection_start_time') . ':01'; // ' 14:00:01'
364 $wpbc_check_out = ' ' . get_bk_option( 'booking_range_selection_end_time') . ':02'; // ' 10:00:02';
365 $simple_booking_dates[0] = $simple_booking_dates[0] . $wpbc_check_in;
366 $simple_booking_dates[ ( count( $simple_booking_dates ) - 1 ) ] = $simple_booking_dates[ ( count( $simple_booking_dates ) - 1 ) ] . $wpbc_check_out;
367 $ics_event['_BOOKING_DATES'][0] = $simple_booking_dates[0];
368 $ics_event['_BOOKING_DATES'][ ( count( $simple_booking_dates ) - 1 ) ] = $simple_booking_dates[ ( count( $simple_booking_dates ) - 1 ) ];
369 }
370 }
371
372
373 WPBM_create_bookings_from_events::set_ics_dates( $ics_event[ '_BOOKING_DATES' ] );
374
375 $booking = array(
376 'dates' => $simple_booking_dates // array( '2017-06-24', '2017-06-24', '2017-06-25', '2017-06-26' )
377 , 'data' => array()
378 , 'resource_id' => $shortcode[ 'resource_id' ]
379 );
380
381
382 $bk_data = array();
383 foreach ( $assigned_fields_arr as $assigned_field ) {
384
385 switch ( $assigned_field[ 'ics_field_name' ] ) {
386
387 case 'title':
388 $bk_data [ $assigned_field[ 'name' ] ]= array( 'type' => $assigned_field[ 'type' ], 'value' => trim( $ics_event[ '_BOOKING_SUMMARY' ] ) );
389 break;
390
391 case 'description':
392 $bk_data [ $assigned_field[ 'name' ] ]= array( 'type' => $assigned_field[ 'type' ], 'value' => trim( $ics_event[ '_BOOKING_DESCRIPTION' ] ) );
393 break;
394
395 case 'where':
396 $bk_data [ $assigned_field[ 'name' ] ]= array( 'type' => $assigned_field[ 'type' ], 'value' => trim( $ics_event[ '_BOOKING_LOCATION' ] ) );
397 break;
398
399 default:
400 break;
401 }
402 }
403
404 // Email
405 $email = '[email protected]'; //get_option ( 'admin_email' );
406 if ( ! empty( $ics_event['_BOOKING_ATTENDEE'] ) ) {
407 $email = str_replace( 'mailto:', '', $ics_event['_BOOKING_ATTENDEE'] );
408 if ( ! is_email( $email ) ) {
409 $email = '[email protected]';
410 }
411 }
412 $bk_data [ 'email' ] = array( 'value' => $email, 'type' => 'email' );
413
414 // Optional Start and End times
415 $start_time = substr( $ics_event[ '_BOOKING_DATES' ][ 0 ], 11 );
416 $end_time = $ics_event[ '_BOOKING_DATES' ][ ( count( $ics_event[ '_BOOKING_DATES' ] ) - 1 ) ];
417 $end_time = substr( $end_time, 11 );
418
419 // Convert times H:i:s to seconds +1 +2 seconds and convert back to H:i -----------------------------------
420 $in_seconds = wpbc_transform__24_hours_his__in__seconds( $start_time );
421 $is_check_in_out__or_full = $in_seconds % 10; // 0, 1, 2
422 if ( 1 === $is_check_in_out__or_full ) {
423 $in_seconds = $in_seconds - 1;
424 }
425 $start_time = wpbc_transform__seconds__in__24_hours_his( $in_seconds );
426 $start_time = substr( $start_time, 0, 5 );
427
428 $in_seconds = wpbc_transform__24_hours_his__in__seconds( $end_time );
429 $is_check_in_out__or_full = $in_seconds % 10; // 0, 1, 2
430 if ( 2 === $is_check_in_out__or_full ) {
431 $in_seconds = $in_seconds + 8;
432 }
433 $end_time = wpbc_transform__seconds__in__24_hours_his( $in_seconds );
434 $end_time = substr( $end_time, 0, 5 );
435 // -------------------------------------------------------------------------------------------------------------
436
437 //Add check in/out times //FixIn: 8.1.3.29
438 if ( ( class_exists( 'wpdev_bk_biz_s' ) )
439 && ( get_bk_option( 'booking_range_selection_time_is_active') == 'On' )
440 && ( get_bk_option( 'booking_ics_import_add_change_over_time' ) !== 'Off' )
441 ){ //FixIn: 2.0.5.1
442
443 $start_time = get_bk_option( 'booking_range_selection_start_time' ); // ' 14:00'
444 $end_time = get_bk_option( 'booking_range_selection_end_time' ); // ' 10:00'
445 }
446
447
448 if ( ( $start_time !== '00:00' ) || ( $end_time !== '00:00' ) ) {
449 $bk_data [ 'rangetime' ] = array( 'value' => $start_time . ' - ' . $end_time, 'type' => 'select-one' );
450 }
451
452 $booking['data'] = $bk_data;
453
454 $additional_params = array( 'sync_gid' => $ics_event['_BOOKING_UID'], 'is_send_emeils' => 0 ); //FixIn: 2.0.10.2
455
456 /**
457 *
458 *
459 // $ics_event[ '_BOOKING_DATES' ]; // array ( [0] => 2014-09-16 05:00:01 [1] => 2014-09-16 12:00:02 )
460 // $ics_event[ '_BOOKING_SUMMARY' ]; // Event (timezone Pacific GMT-07:00)
461 // $ics_event[ '_BOOKING_DESCRIPTION' ]; // 8/7/2017 1:00pm TO 3:30pm 8/8/2017 (GMT-07:00) Pacific Time
462 // $ics_event[ '_BOOKING_LOCATION' ]; // Pacific Coast Highway, Pacific Coast Hwy, Los Angeles, CA, USA
463 // $ics_event[ '_BOOKING_UID' ]; // [email protected]
464 // $ics_event[ '_BOOKING_MODIFIED' ]; // 2017-06-28 10:12:35
465 */
466
467 add_filter( 'wpbc_get_insert_sql_for_dates', 'wpbm_get_insert_sql_for_dates', 10, 5 );
468
469
470 if ( ( function_exists( 'get_bk_option' ) ) && ( get_bk_option( 'booking_auto_approve_bookings_when_import' ) == 'On' ) ) {
471 $additional_params ['is_approve_booking'] = 1;
472 }
473
474
475 // Check dates availability and process only if dates available in specific booking resource!
476 if (
477 ( $shortcode[ 'import_conditions' ] == 'if_dates_free' )
478 || ( 'On' == get_bk_option( 'booking_condition_import_if_available' ) ) //FixIn: 9.8.15.8 - 'Import only, if days are available'
479 ) { //FixIn: 2.0.15.2
480
481 $is_dates_booked = wpbc_api_is_dates_booked( $ics_event['_BOOKING_DATES'], $booking['resource_id']
482 , array(
483 'is_use_booking_recurrent_time' => false // If we import bookings, all the times defined in dates, so no need to use it
484 )
485 );
486 } else{
487 $is_dates_booked = false;
488 $additional_params['save_booking_even_if_unavailable'] = 1;
489 }
490 $additional_params['is_use_booking_recurrent_time'] = false;
491
492 if ( ! $is_dates_booked ) {
493
494 $booking_id = wpbc_api_booking_add_new( $booking[ 'dates' ], $booking[ 'data' ], $booking[ 'resource_id' ] , $additional_params );
495
496 if ( ( is_int( $booking_id ) ) && ( $booking_id > 0 ) ) {
497
498 $booking_added_num++;
499
500 // Add notes to the booking relative source of imported booking // FixIn: 2.0.7.2
501 $import_url = parse_url( $shortcode[ 'url' ] );
502 if (
503 ( false !== $import_url )
504 && ( ! empty( $import_url[ "host" ]))
505 && ( class_exists('wpdev_bk_personal') )
506 ){
507 $remark_text = '[' . date_i18n( 'Y-m-d H:i:s' ) . '] ' . sprintf( __( 'Imported from %s ', 'booking-manager' ), $import_url["host"] );
508 $remark_text = str_replace( '%', '&#37;', $remark_text );
509 $remark_text = str_replace( array( '"', "'" ), '', $remark_text );
510 $remark_text = trim( $remark_text );
511
512 $is_append = true;
513 make_bk_action( 'wpdev_make_update_of_remark', $booking_id, $remark_text, $is_append );
514 }
515
516 do_action( 'wpbc_show_debug', sprintf ( 'Added new booking ID:<strong>%d</strong> ', $booking_id ) ); // S_Y_S_T_E_M L_O_G
517 }
518
519 if ( is_wp_error( $booking_id ) ) {
520 do_action( 'wpbc_show_debug', implode( ' ', $booking_id->get_error_messages()) );
521
522 do_action( 'wpbc_admin_show_top_notice' // N_O_T_I_C_E in H_E_A_D_E_R
523 , implode( ' ', $booking_id->get_error_messages())
524 , 'warning', 30000 );
525 }
526
527 } else {
528
529 do_action( 'wpbc_show_debug', // S_Y_S_T_E_M L_O_G
530 sprintf ( 'Event was not create becausse dates %s already booked in booking resource ID = %d'
531 , implode( ', ', $booking[ 'dates' ] ) , $booking[ 'resource_id' ] ) );
532 }
533
534 remove_filter( 'wpbc_get_insert_sql_for_dates', 'wpbm_get_insert_sql_for_dates', 10 );
535
536
537 // Remove previously saved dates to our 'Static' class.
538 WPBM_create_bookings_from_events::erase_ics_dates();
539 }
540
541 return $booking_added_num;
542 }
543 add_action( 'wpbm_ics_import_start', 'wpbm_ics_import_start', 10, 1 );
544
545
546 // Legacy Import
547
548 /** Import ICS feed and create bookings .in Booking Calendar
549 *
550 * @param array $attr = array(
551 'url' => ''
552 , 'resource_id' => 1
553 , 'import_conditions' => '' | 'if_dates_free' // maybe rename ??? if_dates_booked_then_not_import
554 )
555 * @return int|bool number of imported bookings or FALSE if error
556 */
557 function wpbm_ics_import_start_legacy( $attr ) {
558
559 // <editor-fold defaultstate="collapsed" desc=" Parse / validate parameters " >
560 /////////////////////////////////////////////////////////////////////
561 // Parse / validate parameters
562 /////////////////////////////////////////////////////////////////////
563 $defaults = array(
564 'url' => ''
565 , 'resource_id' => 1
566 , 'delete' => 0
567 , 'import_conditions' => ''
568 , 'from' => 'any' // 'today' // '00:00 today'
569 , 'from_offset' => ''
570 , 'until' => 'any' // 'year-end'
571 , 'until_offset' => ''
572 , 'max' => ''
573 , 'is_all_dates_in' => true // Conditional of Dates checking. TRUE - Remove event if al least 1 day not in conditional interval, FALSE - save event, if at leat one date in conditional interval
574 );
575 $shortcode = array();
576
577 foreach ( $attr as $param_name => $param_value ) {
578
579 switch ( $param_name) { // Validate Params
580
581 case 'url':
582 $shortcode[ $param_name ] = esc_url_raw( $param_value ); // $shortcode[ 'url' ]
583 $shortcode[ $param_name ] = str_replace( '&amp;', '&', $shortcode[ $param_name ] ); //FixIn: 2.0.14.2
584 break;
585
586 case 'import_conditions':
587 $shortcode[ $param_name ] = esc_attr( $param_value ); // $shortcode[ 'resource_id' ]
588 break;
589
590 case 'resource_id':
591 $shortcode[ $param_name ] = intval($param_value ); // $shortcode[ 'resource_id' ]
592 break;
593
594 case 'from': // 'now', 'today', 'week', 'month-start', 'month-end', 'year-start', 'any', 'date' = 2017-08-07
595 $shortcode[ $param_name ] = $param_value;
596 break;
597
598 case 'from_offset': // 5d, 10h, 5m, 30s -- if from: { 'now', 'today', 'week', 'month-start', 'month-end', 'year-start' }
599 $shortcode[ $param_name ] = $param_value;
600 break;
601
602 case 'until': // 'now', 'today', 'week', 'month-start', 'month-end', 'year-end', 'any', 'date' = 2017-08-07
603 $shortcode[ $param_name ] = $param_value;
604 break;
605
606 case 'until_offset': // 5d, 10h, 5m, 30s -- if until: { 'now', 'today', 'week', 'month-start', 'month-end', 'year-end' }
607 $shortcode[ $param_name ] = $param_value;
608 break;
609
610 case 'max':
611 $shortcode[ $param_name ] = intval( $param_value );
612 break;
613
614 case 'is_all_dates_in': // Conditional of Dates checking. TRUE - Remove event if al least 1 day not in conditional interval, FALSE - save event, if at leat one date in conditional interval
615 $shortcode[ $param_name ] = intval( $param_value );
616 break;
617
618
619 default:
620 $shortcode[ $param_name ] = $param_value;
621 break;
622 }
623 }
624 $shortcode = wp_parse_args( $shortcode, $defaults );
625 // </editor-fold>
626
627 //debuge($shortcode);
628 // <editor-fold defaultstate="collapsed" desc=" Notice - Import Parameters | Error No URL" >
629
630 do_action( 'wpbc_show_debug', array( 'Import Parameters' , $shortcode ) ); // S_Y_S_T_E_M L_O_G
631
632 if ( empty( $shortcode[ 'url' ] ) ) {
633 do_action( 'wpbc_admin_show_top_notice', __( 'No ics url feed', 'booking-manager' ), 'error', 5000 ); // N_O_T_I_C_E in H_E_A_D_E_R
634 return false;
635 }
636 // </editor-fold>
637
638 ///////////////////////////////////////////////////////////////////// - Get, Parse ICS Feed
639
640 $ics_array = wpbm_ics_file_to_array( $shortcode[ 'url' ] );
641
642 // <editor-fold defaultstate="collapsed" desc=" Notice - feed contain N events | Error Importing " >
643 do_action( 'wpbc_show_debug', array( 'Imported data' , $ics_array) ); // S_Y_S_T_E_M L_O_G
644
645 // If Error
646 if ( is_wp_error( $ics_array ) ) {
647
648 $error_message = $ics_array->get_error_message();
649 do_action( 'wpbc_admin_show_top_notice', $error_message, 'error', 5000 ); // N_O_T_I_C_E in H_E_A_D_E_R
650 return false;
651 }
652
653 //FixIn: 2.0.7.3
654 $ics_array_events_num = 0;
655 if ( ( ! empty( $ics_array ) ) && ( ! empty( $ics_array[ 'events' ] ) ) && ( is_array( $ics_array[ 'events' ] ) ) ) {
656 $ics_array_events_num = count( $ics_array[ 'events' ] );
657 }
658 do_action( 'wpbc_admin_show_top_notice' // N_O_T_I_C_E in H_E_A_D_E_R
659 , sprintf ( __( '.ics feed contain %s events at URL %s', 'booking-manager' ), '<b>' . $ics_array_events_num . '</b>', '<b><a href="'. $shortcode[ 'url' ] .'">' . $shortcode[ 'url' ] . '</a></b>' )
660 , 'info', 5000 );
661 // </editor-fold>
662
663 //FixIn: 2.0.18.3
664 if ( 'skip' != $shortcode['delete'] ) {
665 wpbm_delete_all_imported_bookings( array( 'resource_id' => $shortcode['resource_id'] ) ); //FixIn: 2.0.10.3
666 }
667
668 $bk_array = array();
669 // Get Only '_BOOKING...' field from ICS array
670 if ( $ics_array !== false ) {
671 $bk_array = wpbm_get_booking_fields_from_ics_array( $ics_array[ 'events' ] );
672 }
673
674 do_action( 'wpbc_show_debug', array( 'Imported Events', $bk_array ) ); // S_Y_S_T_E_M L_O_G
675
676
677 //FixIn: 2.0.6.1 - Set timezone frrom Booking > Settings > Sync page for booking listing shortcode
678 $tzid = get_bk_option( 'booking_gcal_timezone' );
679 if ( ! empty( $tzid ) ) {
680 foreach ( $bk_array as $bk_k => $bk_ics_data_arr ) {
681
682
683 //apply our timezone from the Booking > Settings > Search page
684 foreach ( $bk_array[ $bk_k ]['_BOOKING_DATES'] as $dk => $day ) {
685 //$bk_array[ $bk_k ][ '_BOOKING_DATES' ][ $dk ] = ZDateHelper::toLocalDateTime( get_gmt_from_date( $day ), $tzid );
686
687 //FixIn: 2.0.7.4 - Skip adding Timezone to "middle" days, if days start with time 00:00:00 - its means event for full day, not the start/end time
688 // Apply timezone only to fist and last days in a list, if the change over days activated in the Booking Calendar
689 $ics_time_in_day = substr( $day, -8);
690 if ( '00:00:00' == $ics_time_in_day ) {
691 continue;
692 }
693 //FixIn: 2.0.7.4 - Skip adding Timezone to "middle" days, if Booking Calendar use change over days, to prevent of having clock icon in middle days.
694 if ( ( class_exists( 'wpdev_bk_biz_s' ) )
695 && ( get_bk_option( 'booking_range_selection_time_is_active') == 'On' )
696 && ( get_bk_option( 'booking_ics_import_add_change_over_time' ) !== 'Off' )
697 ) { //FixIn: 2.0.5.1
698 $days_number = count( $bk_array[ $bk_k ]['_BOOKING_DATES'] );
699 if ( ( 0 != $dk ) && ( ( $days_number - 1) != $dk ) ) {
700 continue;
701 }
702 // We are append one day to the booking, so skip this day for timezone, as well
703 if ( ( get_bk_option( 'booking_ics_import_append_checkout_day' ) !== 'Off' ) && ( ( $days_number - 1) == $dk ) ) {
704 continue;
705 }
706 }
707
708 $bk_array[ $bk_k ]['_BOOKING_DATES'][ $dk ] = ZDateHelper::toLocalDateTime( $day, $tzid );
709 }
710 }
711 }
712
713 ///////////////////////////////////////////////////////////////////// - Check if these EVENTS was imported before or NOT
714
715 $booking_ics_force_import = get_bk_option( 'booking_ics_force_import' ); //FixIn: 2.0.10.1
716 $booking_condition_import_only_new = get_bk_option( 'booking_condition_import_only_new' ); //FixIn: 9.8.15.8
717 if ( false === $booking_condition_import_only_new ) {
718 // OLD:
719 if ( 'On' !== $booking_ics_force_import ) {
720 $bk_array = wpbm_clear_events_from_exist_bookings( $bk_array );
721 }
722 } else {
723 // NEW:
724 if ( 'On' === $booking_condition_import_only_new ) {
725 $bk_array = wpbm_clear_events_from_exist_bookings( $bk_array );
726 }
727 }
728
729 // <editor-fold defaultstate="collapsed" desc=" Notice - if events was imported previously | Already ALL Imported " >
730 do_action( 'wpbc_show_debug', array( 'Check, if events was imported previously. New events: ', $bk_array ) ); // S_Y_S_T_E_M L_O_G
731
732 if ( empty( $bk_array ) ) {
733
734 do_action( 'wpbc_admin_show_top_notice' // N_O_T_I_C_E in H_E_A_D_E_R
735 , '<strong>' . __( 'Warning', 'booking' ) . '!</strong> '
736 . sprintf( __( 'No any new events to import! These events was import previously, already.', 'booking-manager' ), '<strong>' . count( $bk_array ) . '</strong>' )
737 , 'warning', 3000 );
738 return 0;
739 }
740 // </editor-fold>
741
742
743 ///////////////////////////////////////////////////////////////////// - Skip events that does not fit to filter parameters: FROM - UNTIL
744
745 // $bk_array = wpbm_clear_events_by_dates( $bk_array, $shortcode );
746
747
748 // Sort Events
749 $bk_array = wpbm_sort_events_by( $bk_array );
750
751 // Filter By Dates - "From - Until"
752 $bk_array = wpbm_clear_events_by_dates( $bk_array, $shortcode );
753
754 // Filter events by - "Max"
755 $bk_array = wpbm_clear_events_by_count( $bk_array, $shortcode );
756
757
758 // <editor-fold defaultstate="collapsed" desc=" Notice - Creation of N bookings " >
759 do_action( 'wpbc_admin_show_top_notice' // N_O_T_I_C_E in H_E_A_D_E_R
760 , sprintf( __( 'Imported of %s bookings', 'booking-manager' ), '<strong>' . count( $bk_array ) . '</strong>' )
761 , 'info', 3000 );
762
763 do_action( 'wpbc_show_debug', array( 'Create bookings after filtering', $bk_array ) ); // S_Y_S_T_E_M L_O_G
764 // </editor-fold>
765
766 ///////////////////////////////////////////////////////////////////// - Loop events > C r e a t e B o o k i n g s
767
768 // Get assigning fields for SUMMARY, DESCRIPTION, LOCATION
769 $assigned_fields_arr = WPBM_create_bookings_from_events::get_assigned_form_fields();
770
771 $booking_added_num = 0;
772
773 foreach ( $bk_array as $ics_event) {
774
775 //FixIn: 2.0.5.2
776 //FixIn: 8.1.3.29
777 // if ( ( class_exists( 'wpdev_bk_biz_s' ) )
778 // && ( get_bk_option( 'booking_range_selection_time_is_active') == 'On' )
779 // && ( get_bk_option( 'booking_ics_import_add_change_over_time' ) !== 'Off' )
780 // && ( get_bk_option( 'booking_ics_import_append_checkout_day' ) !== 'Off' )
781 // ) {
782 if ( 'On' == get_bk_option( 'booking_ics_import_append_checkout_day' ) ) { //FixIn: 2.0.27.1 //FixIn: 9.5.4.1
783 // Add one additional day to .ics event (useful in some cases for bookings with change-over days), if the imported .ics dates is coming without check in/our times
784 // Later system is adding check in/out times from Booking Calendar to this event
785 $ics_event_check_out = $ics_event['_BOOKING_DATES'][ ( count( $ics_event['_BOOKING_DATES'] ) - 1 ) ];
786
787 //FixIn Start: 2.0.28.1 ------------------------------------------------------------------------------------
788 // Is check in/out dates in this event it's the same date
789 $test_check_in = substr( $ics_event['_BOOKING_DATES'][0], 0, 10 );
790 $test_check_out = substr( $ics_event['_BOOKING_DATES'][ ( count( $ics_event['_BOOKING_DATES'] ) - 1 ) ], 0, 10 );
791 if ( $test_check_in === $test_check_out ) {
792 // It is the same date, like 2024-02-12 10:00:01, 2024-02-12 14:59:52, then remove this date, because we will add new date
793 unset( $ics_event['_BOOKING_DATES'][ ( count( $ics_event['_BOOKING_DATES'] ) - 1 ) ] );
794 // Important! Reindex array, after unset operation.
795 $ics_event['_BOOKING_DATES'] = array_values( $ics_event['_BOOKING_DATES'] );
796 } else {
797 // It is other date, in this case, we need to define other time:
798 $ics_event['_BOOKING_DATES'][ ( count( $ics_event['_BOOKING_DATES'] ) - 1 ) ] = $test_check_out . ' 00:00:00';
799 }
800 //FixIn End: 2.0.28.1 --------------------------------------------------------------------------------------
801
802 $ics_event_check_out = strtotime( $ics_event_check_out );
803 $ics_event_check_out = strtotime( '+1 day', $ics_event_check_out );
804 $ics_event_check_out = date_i18n( "Y-m-d H:i:s", $ics_event_check_out ); //FixIn: 2.0.28.1 //$ics_event_check_out = date_i18n( "Y-m-d 00:00:00", $ics_event_check_out );
805 $ics_event['_BOOKING_DATES'][] = $ics_event_check_out;
806 }
807
808 $booking_data = array();
809
810 if ( ( class_exists( 'wpdev_bk_biz_s' ) )
811 && ( get_bk_option( 'booking_range_selection_time_is_active') == 'On' )
812 && ( get_bk_option( 'booking_ics_import_add_change_over_time' ) !== 'Off' )
813 && ( count( $ics_event[ '_BOOKING_DATES' ] ) > 1 )
814 ) {
815 $dates_formats = array_fill( 0, count( $ics_event[ '_BOOKING_DATES' ] ), "Y-m-d" ); // Array ( [0] => Y-m-d [1] => Y-m-d ... )
816 } else {
817 $dates_formats = array_fill( 0, count( $ics_event[ '_BOOKING_DATES' ] ), "Y-m-d H:i:s" ); //FixIn: 2.0.15.4
818 }
819 $booking_dates_unix = array_map( 'strtotime', $ics_event[ '_BOOKING_DATES' ] ); // Array ( [0] => 1498262400 [1] => 1498348800 )
820 $simple_booking_dates = array_map( 'date_i18n', $dates_formats , $booking_dates_unix ); // Array ( '2017-06-23', '2017-06-24', '2017-06-25', '2017-06-26' )
821
822
823 //FixIn: 8.1.3.29
824 if ( ( class_exists( 'wpdev_bk_biz_s' ) )
825 && ( get_bk_option( 'booking_range_selection_time_is_active') == 'On' )
826 && ( get_bk_option( 'booking_ics_import_add_change_over_time' ) !== 'Off' )
827 ) { //FixIn: 2.0.5.1
828 //Add check in/out times to full day events
829 if ( ( is_array( $simple_booking_dates ) ) && ( count( $simple_booking_dates ) > 1 ) ) { //FixIn: 2.0.10.4
830 $wpbc_check_in = ' ' . get_bk_option( 'booking_range_selection_start_time') . ':01'; // ' 14:00:01'
831 $wpbc_check_out = ' ' . get_bk_option( 'booking_range_selection_end_time') . ':02'; // ' 10:00:02';
832 $simple_booking_dates[0] = $simple_booking_dates[0] . $wpbc_check_in;
833 $simple_booking_dates[ ( count( $simple_booking_dates ) - 1 ) ] = $simple_booking_dates[ ( count( $simple_booking_dates ) - 1 ) ] . $wpbc_check_out;
834 $ics_event['_BOOKING_DATES'][0] = $simple_booking_dates[0];
835 $ics_event['_BOOKING_DATES'][ ( count( $simple_booking_dates ) - 1 ) ] = $simple_booking_dates[ ( count( $simple_booking_dates ) - 1 ) ];
836 }
837 }
838
839 //debuge($ics_event[ '_BOOKING_DATES' ]);die;
840 // Tempoary save our dates
841
842 // if( count( $ics_event['_BOOKING_DATES'] ) > 2 ) {
843 // unset( $ics_event['_BOOKING_DATES'][ ( count( $ics_event['_BOOKING_DATES'] ) - 1 ) ] ); //Remove last imported date
844 // if ( count( $ics_event['_BOOKING_DATES'] ) > 2 ) { // Add one date if number of days in booking more than 2
845 // $ics_event['_BOOKING_DATES'][ ( count( $ics_event['_BOOKING_DATES'] ) - 1 ) ] = $simple_booking_dates[ ( count( $ics_event['_BOOKING_DATES'] ) - 1 ) ] . $wpbc_check_out;
846 // } else if ( count( $ics_event['_BOOKING_DATES'] ) == 1 ) { // Add one date, if we are having only 1 day in booking (previously was having 2 dates
847 // $ics_event['_BOOKING_DATES'][] = $simple_booking_dates[ ( count( $ics_event['_BOOKING_DATES'] ) - 1 ) ] . $wpbc_check_out;
848 // }
849 // }
850 WPBM_create_bookings_from_events::set_ics_dates( $ics_event[ '_BOOKING_DATES' ] );
851
852 $booking = array(
853 'dates' => $simple_booking_dates // array( '2017-06-24', '2017-06-24', '2017-06-25', '2017-06-26' )
854 , 'data' => array()
855 , 'resource_id' => $shortcode[ 'resource_id' ]
856 );
857
858
859 $bk_data = array();
860 foreach ( $assigned_fields_arr as $assigned_field ) {
861
862 switch ( $assigned_field[ 'ics_field_name' ] ) {
863
864 case 'title':
865 $bk_data [ $assigned_field[ 'name' ] ]= array( 'type' => $assigned_field[ 'type' ], 'value' => trim( $ics_event[ '_BOOKING_SUMMARY' ] ) );
866 break;
867
868 case 'description':
869 $bk_data [ $assigned_field[ 'name' ] ]= array( 'type' => $assigned_field[ 'type' ], 'value' => trim( $ics_event[ '_BOOKING_DESCRIPTION' ] ) );
870 break;
871
872 case 'where':
873 $bk_data [ $assigned_field[ 'name' ] ]= array( 'type' => $assigned_field[ 'type' ], 'value' => trim( $ics_event[ '_BOOKING_LOCATION' ] ) );
874 break;
875
876 default:
877 break;
878 }
879 }
880
881 // Email
882 $home_url = explode( '://', home_url() );
883 //if (count($home_url>0)) //FixIn: 2.0.3.2
884 // $email = 'ics@' . $home_url[1];
885 //else
886 $email = get_option ( 'admin_email' );
887 $bk_data [ 'email' ] = array( 'value' => $email, 'type' => 'email' );
888
889 // Optional Start and End times
890 $start_time = substr( $ics_event[ '_BOOKING_DATES' ][ 0 ], 11, 5 );
891 $end_time = $ics_event[ '_BOOKING_DATES' ][ ( count( $ics_event[ '_BOOKING_DATES' ] ) - 1 ) ];
892 $end_time = substr( $end_time, 11, 5 );
893
894 //FixIn: 8.1.3.29
895 if ( ( class_exists( 'wpdev_bk_biz_s' ) )
896 && ( get_bk_option( 'booking_range_selection_time_is_active') == 'On' )
897 && ( get_bk_option( 'booking_ics_import_add_change_over_time' ) !== 'Off' )
898 ){ //FixIn: 2.0.5.1
899 //Add check in/out times
900 $start_time = get_bk_option( 'booking_range_selection_start_time' ); // ' 14:00'
901 $end_time = get_bk_option( 'booking_range_selection_end_time' ); // ' 10:00'
902 }
903
904
905 if ( ( $start_time !== '00:00' ) || ( $end_time !== '00:00' ) ) {
906 $bk_data [ 'rangetime' ] = array( 'value' => $start_time . ' - ' . $end_time, 'type' => 'select-one' );
907 }
908
909 $booking['data'] = $bk_data;
910
911 $additional_params = array( 'sync_gid' => $ics_event['_BOOKING_UID'], 'is_send_emeils' => 0 ); //FixIn: 2.0.10.2
912
913 /**
914 // $ics_event[ '_BOOKING_DATES' ]; // array ( [0] => 2014-09-16 05:00:01 [1] => 2014-09-16 12:00:02 )
915 // $ics_event[ '_BOOKING_SUMMARY' ]; // Event (timezone Pacific GMT-07:00)
916 // $ics_event[ '_BOOKING_DESCRIPTION' ]; // 8/7/2017 1:00pm TO 3:30pm 8/8/2017 (GMT-07:00) Pacific Time
917 // $ics_event[ '_BOOKING_LOCATION' ]; // Pacific Coast Highway, Pacific Coast Hwy, Los Angeles, CA, USA
918 // $ics_event[ '_BOOKING_UID' ]; // [email protected]
919 // $ics_event[ '_BOOKING_MODIFIED' ]; // 2017-06-28 10:12:35
920 */
921
922 add_filter( 'wpbc_get_insert_sql_for_dates', 'wpbm_get_insert_sql_for_dates', 10, 5 );
923
924 // Do not overupdate "child booking resources" when saving bookings to parent booking resource. Just skip this checking
925 add_filter( 'wpbc_is_reupdate_dates_to_child_resources', 'wpbm_is_reupdate_dates_to_child_resources', 10, 7 );
926
927 // Check dates availability and process
928 // only if dates available in specific booking resource!
929 if (
930 ( $shortcode[ 'import_conditions' ] == 'if_dates_free' )
931 || ( 'On' == get_bk_option( 'booking_condition_import_if_available' ) ) //FixIn: 9.8.15.8 - 'Import only, if days are available'
932 ){
933 $is_dates_booked = wpbc_api_is_dates_booked( $ics_event['_BOOKING_DATES'], $booking['resource_id'] ); //FixIn: 2.0.15.2
934 //$is_dates_booked = wpbc_api_is_dates_booked( $booking['dates'], $booking['resource_id'] );
935 } else{
936 $is_dates_booked = false;
937 }
938
939
940 if ( ! $is_dates_booked ) {
941
942 $booking_id = wpbc_api_booking_add_new( $booking[ 'dates' ], $booking[ 'data' ], $booking[ 'resource_id' ] , $additional_params );
943 $booking_added_num++;
944
945 //if ( ( defined( 'WP_BK_AUTO_APPROVE_WHEN_IMPORT_GCAL' ) ) && ( WP_BK_AUTO_APPROVE_WHEN_IMPORT_GCAL ) ){ // Auto approve booking if imported
946 if ( ( function_exists( 'get_bk_option' )) && ( get_bk_option( 'booking_auto_approve_bookings_when_import' ) == 'On' ) ) { //FixIn: 8.1.3.27
947 // Auto approve booking, when imported. //FixIn:7.0.1.59
948 global $wpdb;
949 if ( false === $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->prefix}bookingdates SET approved = %s WHERE booking_id IN ({$booking_id})", '1' ) ) ){
950 ?> <script type="text/javascript">
951 var my_message = '<?php echo html_entity_decode( esc_js( get_debuge_error('Error during updating to DB' ,__FILE__,__LINE__) ),ENT_QUOTES) ; ?>';
952 wpbc_admin_show_message( my_message, 'error', 30000 );
953 </script> <?php
954 die();
955 }
956 }
957
958 //FixIn: 2.0.7.2 - add notes to the booking relative source of imported booking
959 $import_url = parse_url( $shortcode[ 'url' ] );
960 if ( ( false !== $import_url ) && ( ! empty( $import_url[ "host" ])) && ( class_exists('wpdev_bk_personal') ) ) {
961
962 $remark_text = str_replace('%','&#37;', '[' . date_i18n('Y-m-d H:i:s') . '] ' . sprintf( __( 'Imported from %s ', 'booking-manager'), $import_url[ "host" ] ) );
963 $my_remark = str_replace( array( '"', "'" ),'',$remark_text);
964 $my_remark = trim( $my_remark );
965
966 global $wpdb;
967
968 $update_sql = $wpdb->prepare( "UPDATE {$wpdb->prefix}booking AS bk SET bk.remark= %s WHERE bk.booking_id= %d ", $remark_text, $booking_id );
969 if ( false === $wpdb->query( $update_sql ) ) {
970 ?> <script type="text/javascript">
971 var my_message = '<?php echo html_entity_decode( esc_js( get_debuge_error('Error during updating notes in DB' ,__FILE__,__LINE__) ),ENT_QUOTES) ; ?>';
972 wpbc_admin_show_message( my_message, 'error', 30000 );
973 </script> <?php
974 die();
975 }
976 }
977
978 do_action( 'wpbc_show_debug', sprintf ( 'Added new booking ID:<strong>%d</strong> ', $booking_id ) ); // S_Y_S_T_E_M L_O_G
979 } else {
980
981 do_action( 'wpbc_show_debug', // S_Y_S_T_E_M L_O_G
982 sprintf ( 'Event was not create becausse dates %s already booked in booking resource ID = %d'
983 , implode( ', ', $booking[ 'dates' ] ) , $booking[ 'resource_id' ] ) );
984 }
985
986 remove_filter( 'wpbc_get_insert_sql_for_dates', 'wpbm_get_insert_sql_for_dates', 10 );
987 remove_filter( 'wpbc_is_reupdate_dates_to_child_resources', 'wpbm_is_reupdate_dates_to_child_resources', 10 );
988
989 // Remove previously saved dates to our 'Static' class.
990 WPBM_create_bookings_from_events::erase_ics_dates();
991 }
992
993 return $booking_added_num;
994 }
995
996
997
998 ////////////////////////////////////////////////////////////////////////////////////////////
999 // Booking Calendar support functions
1000 ////////////////////////////////////////////////////////////////////////////////////////////
1001
1002
1003 /** Clear array of Events from events that already exist in Booking table
1004 * Check UID and GUID sync paramaters
1005 *
1006 * @param array $bk_array - array of events
1007 * @return array - trimmed array
1008 */
1009 function wpbm_clear_events_from_exist_bookings( $bk_array ) {
1010
1011 $bk_uid = $bk_guid = array();
1012 // GET array of UID for imported bookings
1013 foreach ( $bk_array as $ics_key => $ics_event) {
1014
1015 $bk_uid[ $ics_key ] = $ics_event[ '_BOOKING_UID' ];
1016
1017 if ( strpos( $ics_event[ '_BOOKING_UID' ], '@google.com') !== false ) {
1018 // [email protected] - ID of event from ICS
1019 // 15ig8t0i739kajgjc8ekc386dt_20170815 - ID of event during import from Google Calendar (probabaly created by ID before @ + first date)
1020
1021 $bk_guid[ $ics_key ] = str_replace( '@google.com'
1022 , date_i18n( '_Ymd', strtotime( $ics_event[ '_BOOKING_DATES' ][0] ) )
1023 , $ics_event[ '_BOOKING_UID' ]
1024 );
1025 }
1026 }
1027 $bookings_check_uid = array_merge( $bk_uid,$bk_guid );
1028
1029 $bookings_exit_uid = wpbm_get_exist_bookings_gid( $bookings_check_uid );
1030
1031 // Remove events which already exist
1032 foreach ( $bk_uid as $ics_key => $ics_uid ) {
1033
1034 // If exist UID remove it from event
1035 if ( in_array( $ics_uid, $bookings_exit_uid ) ) {
1036 unset( $bk_array[ $ics_key ] );
1037 }
1038
1039 // If we are having such GUID and it exist, then remove ir
1040 if ( isset( $bk_guid[ $ics_key ] ) ) {
1041 $ics_gid = $bk_guid[ $ics_key ];
1042 if ( in_array( $ics_uid, $bookings_exit_uid ) ) {
1043 unset( $bk_array[ $ics_key ] );
1044 }
1045 }
1046 }
1047 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1048
1049 return $bk_array;
1050 }
1051
1052
1053 /** Check if bookings exist with specific sync UID
1054 *
1055 * @global type $wpdb
1056 * @param array of UID to check
1057 * @return array of exist UID
1058 */
1059 function wpbm_get_exist_bookings_gid( $uid_arr ) {
1060
1061 $sql_sync_gid = implode( "','", $uid_arr );
1062
1063 $exist_bookings_guid = array();
1064
1065 if ( ! empty( $sql_sync_gid ) ) {
1066 global $wpdb;
1067
1068 $my_sql = "SELECT * FROM {$wpdb->prefix}booking WHERE sync_gid IN ('{$sql_sync_gid}') AND trash != 1"; //FixIn: 2.0.9.3
1069 //debuge($sql_sync_gid);
1070 //$my_sql = "SELECT * FROM wp_booking WHERE sync_gid IN ('[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]')";
1071 //debuge($my_sql);
1072 $exist_bookings = $wpdb->get_results( $my_sql );
1073
1074 //debuge( 'wpbc_show_debug', array( 'SQL: ', $my_sql, $exist_bookings ) );
1075
1076 foreach ( $exist_bookings as $bk ) {
1077 $exist_bookings_guid[] = $bk->sync_gid;
1078 }
1079 }
1080 return $exist_bookings_guid;
1081 }
1082
1083
1084 /** Trim number of events in array
1085 *
1086 * @param array $bk_array
1087 * @param array $shortcode
1088 * @return array
1089 */
1090 function wpbm_clear_events_by_count( $bk_array, $shortcode ) {
1091
1092 if ( empty( $shortcode['max'] ) ) {
1093 return $bk_array;
1094 } else {
1095 $max = intval( $shortcode['max'] );
1096 }
1097
1098 $bk_count= count( $bk_array );
1099 if ( $max > $bk_count )
1100 return $bk_array;
1101
1102 $cnt = 0;
1103 $events_arr = array();
1104
1105 foreach ( $bk_array as $ev_key => $ev_arr ) {
1106
1107 $events_arr[] = $ev_arr;
1108
1109 $cnt++;
1110 if ( $cnt >= $max )
1111 break;
1112 }
1113
1114 return $events_arr;
1115 }
1116
1117
1118
1119
1120 /** Remove ONLY dates from event(s) that does not fit to filter parameters: FROM - UNTIL -- All events will exist here
1121 *
1122 * @param array $bk_array - array of events
1123 * @param array $shortcode
1124 * @return array - trimmed array
1125 */
1126 function wpbm_remove_dates_from_event_not_in_condition( $bk_array, $shortcode ) {
1127
1128 if ( ( ! isset( $shortcode['from'] ) ) && ( ! isset( $shortcode['until'] ) ) ) {
1129 return $bk_array;
1130 }
1131
1132 // <editor-fold defaultstate="collapsed" desc=" F R O M C o n d " >
1133
1134 // F R O M
1135 $offset = wpbm_get_offset_unix_from_param( $shortcode[ 'from_offset' ] );
1136
1137 if ( $shortcode['from'] == 'any' ) $shortcode['from'] = 'any-start';
1138 if ( $shortcode['from'] == 'week' ) $shortcode['from'] = 'week-start';
1139
1140 $condition_from = wpbm_get_time_unix_from_param_offset( $shortcode['from'], $offset );
1141
1142 // </editor-fold>
1143
1144
1145 // <editor-fold defaultstate="collapsed" desc=" U N T I L C o n d " >
1146
1147 // U N T I L
1148 $offset = wpbm_get_offset_unix_from_param( $shortcode[ 'until_offset' ] );
1149
1150 if ( $shortcode['until'] == 'any' ) $shortcode['until'] = 'any-end';
1151 if ( $shortcode['until'] == 'week' ) $shortcode['until'] = 'week-end';
1152
1153 $condition_until = wpbm_get_time_unix_from_param_offset( $shortcode['until'], $offset );
1154
1155 // </editor-fold>
1156
1157
1158 foreach ( $bk_array as $e_key => $ics_event ) {
1159
1160 $new_dates = array();
1161 //debuge($ics_event[ '_BOOKING_DATES' ] );
1162 foreach ( $ics_event[ '_BOOKING_DATES' ] as $d_key => $ics_date ) {
1163
1164 $ics_date_unix = strtotime( $ics_date );
1165 //debuge( $d_key, $ics_date , array( $condition_from, $condition_until ) );
1166 if ( ( $condition_from <= $ics_date_unix ) && ( $condition_until >= $ics_date_unix ) ) {
1167
1168 $new_dates[] = $ics_date;
1169 }
1170 }
1171 //debuge( $new_dates ); die;
1172 $bk_array[ $e_key ][ '_BOOKING_DATES' ] = $new_dates;
1173 }
1174
1175 return $bk_array;
1176 }
1177
1178
1179 /** Skip events that does not fit to filter parameters: FROM - UNTIL
1180 *
1181 * @param array $bk_array - array of events
1182 * @param array $shortcode
1183 * @return array - trimmed array
1184 */
1185 function wpbm_clear_events_by_dates( $bk_array, $shortcode ) {
1186
1187 if ( ( ! isset( $shortcode['from'] ) ) && ( ! isset( $shortcode['until'] ) ) ) {
1188 return $bk_array;
1189 }
1190
1191 // <editor-fold defaultstate="collapsed" desc=" F R O M C o n d " >
1192
1193 // F R O M
1194 $offset = wpbm_get_offset_unix_from_param( $shortcode[ 'from_offset' ] );
1195
1196 if ( $shortcode['from'] == 'any' ) $shortcode['from'] = 'any-start';
1197 if ( $shortcode['from'] == 'week' ) $shortcode['from'] = 'week-start';
1198
1199 $condition_from = wpbm_get_time_unix_from_param_offset( $shortcode['from'], $offset );
1200
1201 // </editor-fold>
1202
1203
1204 // <editor-fold defaultstate="collapsed" desc=" U N T I L C o n d " >
1205
1206 // U N T I L
1207 $offset = wpbm_get_offset_unix_from_param( $shortcode[ 'until_offset' ] );
1208
1209 if ( $shortcode['until'] == 'any' ) $shortcode['until'] = 'any-end';
1210 if ( $shortcode['until'] == 'week' ) $shortcode['until'] = 'week-end';
1211
1212 $condition_until = wpbm_get_time_unix_from_param_offset( $shortcode['until'], $offset );
1213
1214 // </editor-fold>
1215
1216 // Conditional of Dates checking. TRUE - Remove event if al least 1 day not in conditional interval, FALSE - save event, if at leat one date in conditional interval
1217 if ( ! isset( $shortcode['is_all_dates_in'] ) )
1218 $is_all_dates_in_condition = true;
1219 else
1220 $is_all_dates_in_condition = (bool) $shortcode['is_all_dates_in'];
1221
1222 //debuge($condition_from, date_i18n('Y-m-d H:is',$condition_from));
1223 //debuge($condition_until, date_i18n('Y-m-d H:is',$condition_until));
1224 //debuge( (int) $is_all_dates_in_condition );
1225 //die;
1226 // Remove some events, that does not inside From | End time
1227 $remove_events_keys = array();
1228 foreach ( $bk_array as $e_key => $ics_event ) {
1229 foreach ( $ics_event[ '_BOOKING_DATES' ] as $d_key => $ics_date ) {
1230 $ics_date = strtotime( $ics_date );
1231
1232 if ( $is_all_dates_in_condition ) {
1233 // STRICT - ALL DATES
1234 if ( ( $condition_from > $ics_date ) || ($condition_until < $ics_date ) ) {
1235
1236 $remove_events_keys[] = $e_key;
1237 continue;
1238 }
1239 } else {
1240 // AT LEAST 1 DATE
1241 if ( ( $condition_from <= $ics_date ) && ( $condition_until >= $ics_date ) ) {
1242
1243 $remove_events_keys = array_diff( $remove_events_keys, array( $e_key ) ); // Remove values "$e_key" from array
1244 break;
1245 } else {
1246 if ( ! in_array( $e_key, $remove_events_keys ) ) {
1247 $remove_events_keys[] = $e_key;
1248 }
1249 }
1250
1251 }
1252
1253 }
1254 }
1255
1256 // Remove them
1257 $remove_events_keys = array_unique( $remove_events_keys );
1258
1259 //debuge( $bk_array, $remove_events_keys);
1260 foreach ( $remove_events_keys as $evnt_key ) {
1261 unset( $bk_array[ $evnt_key ] );
1262 }
1263
1264 return $bk_array;
1265 }
1266
1267
1268 /** Get time offset in seconds based on parameter
1269 *
1270 * @param string $offset_param 30s | 5m | 2h | 7d | just seconds
1271 * @return int
1272 */
1273 function wpbm_get_offset_unix_from_param( $offset_param ) {
1274
1275 $offset = 0;
1276 if ( ! empty( $offset_param ) ) {
1277
1278 $offset_type = substr( $offset_param, -1 );
1279 $offset_value = substr( $offset_param, 0, -1 );
1280
1281 switch ( $offset_type ) {
1282 case "s": // Seconds
1283 $offset = intval( $offset_value );
1284 break;
1285 case "m": // Minutes
1286 $offset = intval( $offset_value ) * 60 ;
1287 break;
1288 case "h": // Hours
1289 $offset = intval( $offset_value ) * 3600 ;
1290 break;
1291 case "d": // Days
1292 $offset = intval( $offset_value ) * 86400 ;
1293 break;
1294 default:
1295 $offset = intval( $offset_value );
1296 }
1297 }
1298 return $offset;
1299 }
1300
1301
1302 /** Get Unix Time based on date parameter / condition and offset in seconds
1303 *
1304 * @param string $check_day - date type: // 'now' | 'today' | 'week' == 'week-start' | 'week-end' | 'month-start' | 'month-end' | 'year-start' | 'year-end' | 'any' == 'any-end' | 'any-start' | '2017-08-07'
1305 * @param int $offset_unix - offset in seconds
1306 * @return int - Unix time in seconds
1307 */
1308 function wpbm_get_time_unix_from_param_offset( $check_day, $offset_unix ) {
1309
1310 // $condition_end = strtotime ( $shortcode['until'] . ' +1 day - 1 second' );
1311
1312 $check_sql_day = explode( '-', $check_day );
1313 if ( count( $check_sql_day ) == 3 ) {
1314 $check_day = 'date';
1315 }
1316
1317 switch ( $check_day ) {
1318 // Don't just use time() for 'now', as this will effectively make cache duration 1 second.
1319 // Instead set to previous minute. Events in Google Calendar cannot be set to precision of seconds anyway
1320 case 'now':
1321
1322 //$time_unix = strtotime( date_i18n( 'Y-m-d H:i:s' ) ) + $offset_unix; // "Now" in "Timezone" from WordPress > Settings
1323 $time_unix = mktime( date_i18n( 'H' ), date_i18n( 'i' ), 0, date_i18n( 'm' ), date_i18n( 'j' ), date_i18n( 'Y' ) ) + $offset_unix ;
1324 break;
1325 case 'today':
1326 //$time_unix = strtotime( date_i18n( 'Y-m-d 00:00:00' ) ) + $offset_unix; // "Today 00:00" in "Timezone" from WordPress > Settings
1327 $time_unix = mktime( 0, 0, 0, date_i18n( 'm' ), date_i18n( 'j' ), date_i18n( 'Y' ) ) + $offset_unix ;
1328 break;
1329 case 'week':
1330 case 'week-start':
1331
1332 $start_of_week = get_wpbm_option( 'wpbm_start_day_weeek' ); //get_option( 'start_of_week' );
1333 if ( empty( $start_of_week ) )
1334 $start_of_week = 0;
1335
1336 $start_day = date_i18n( 'w' ) - $start_of_week ;
1337 if ( $start_day < 0 )
1338 $start_day = 7 + $start_day;
1339
1340 $time_unix = mktime( 0, 0, 0, date_i18n( 'm' ), ( date_i18n( 'j' ) - $start_day ), date_i18n( 'Y' ) ) + $offset_unix ;
1341 break;
1342 case 'week-end':
1343
1344 $start_of_week = get_wpbm_option( 'wpbm_start_day_weeek' ); //get_option( 'start_of_week' );
1345 if ( empty( $start_of_week ) )
1346 $start_of_week = 0;
1347
1348 $start_day = date_i18n( 'w' ) - $start_of_week ;
1349 if ( $start_day < 0 )
1350 $start_day = 7 + $start_day;
1351 // minus 1 second -- prevent of events exactly == start Next period
1352 $time_unix = mktime( 0, 0, 0, date_i18n( 'm' ), ( date_i18n( 'j' ) - $start_day + 7 ), date_i18n( 'Y' ) ) + $offset_unix - 1;
1353 break;
1354 case 'month-start':
1355 $time_unix = mktime( 0, 0, 0, date_i18n( 'm' ), 1, date_i18n( 'Y' ) ) + $offset_unix ;
1356 break;
1357 case 'month-end':
1358 $time_unix = mktime( 0, 0, 0, date_i18n( 'm' ) + 1, 1, date_i18n( 'Y' ) ) + $offset_unix - 1; // minus 1 second -- prevent of events exactly == start Next period
1359 break;
1360 case 'year-start':
1361 $time_unix = mktime( 0, 0, 0, 1, 1, date_i18n( 'Y' ) ) + $offset_unix ;
1362 break;
1363 case 'year-end':
1364 $time_unix = mktime( 0, 0, 0, 1, 1, date_i18n( 'Y' ) + 1 ) + $offset_unix - 1; // minus 1 second -- prevent of events exactly == start Next period
1365 break;
1366 case 'date':
1367
1368 if ( intval( $check_sql_day[0] ) - intval( date('Y') ) > 15 ) { //FixIn m.2.0.1
1369 $time_unix =2145916800;
1370 } else {
1371 $time_unix = mktime( 0, 0, 0, intval( $check_sql_day[1] ), intval( $check_sql_day[2] ), intval( $check_sql_day[0] ) );
1372 }
1373 break;
1374 case 'any-start':
1375 $time_unix = 0; // any - 1970-01-01 00:00
1376 break;
1377 case 'any-end':
1378 $time_unix = 2145916800; //any - 2038-01-01 00:00
1379 break;
1380 default:
1381 $time_unix = 2145916800; //any END - 2038-01-01 00:00
1382 }
1383
1384 //debuge($time_unix, date_i18n('Y-m-d H:i:s (D)',$time_unix));
1385
1386
1387 return $time_unix;
1388 }
1389
1390
1391 //FixIn: 2.0.11.4
1392 /**
1393 * Get booking ID, by searching in Booking Calendar by UID
1394 * @param string $uid
1395 *
1396 * @return empty string | int $booking_id
1397 */
1398 function wpbm_get_booking_id_by_UID( $uid ){
1399
1400 $booking_id = array(); //FixIn: 2.0.14.1
1401
1402 if ( function_exists( 'wpbc_api_get_bookings_arr' ) ) {
1403
1404 /*
1405 $param = array(
1406 'wh_booking_datenext' => 1,
1407 'wh_booking_dateprior' => 1,
1408 'wh_booking_date' => 3,
1409 'wh_trash' => 'any',
1410 'wh_modification_dateprior' => 1,
1411 'wh_modification_date' => 3,
1412 'wh_pay_status' => 'all',
1413
1414 'wh_booking_type' => '-999',
1415 'wh_keyword' => $uid
1416 );
1417
1418 $bookings_arr = wpbc_api_get_bookings_arr( $param );
1419 */
1420 global $wpdb;
1421
1422 $sql = "SELECT booking_id FROM {$wpdb->prefix}booking as bk WHERE bk.sync_gid LIKE '%%" . wpbc_clean_like_string_for_db( $uid ) . "%%'";
1423
1424 //$sql_escaped = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}booking as bk WHERE bk.sync_gid LIKE '%%%s%%'", $uid );
1425
1426 $res = $wpdb->get_results( $sql );
1427
1428 foreach ( $res as $booking_obj ) {
1429 $booking_id[] = $booking_obj->booking_id;
1430 }
1431
1432 //debuge('$bookings_arr',$res);
1433
1434 }
1435
1436 return implode( ',', $booking_id );
1437 }