| 1 |
<?php |
| 2 |
/** |
| 3 |
* @version 1.0 |
| 4 |
* @package Booking Calendar |
| 5 |
* @subpackage Google Calendar Import |
| 6 |
* @category Data Sync |
| 7 |
* |
| 8 |
* @author wpdevelop |
| 9 |
* @link https://wpbookingcalendar.com/ |
| 10 |
* @email info@wpbookingcalendar.com |
| 11 |
* |
| 12 |
* @modified 2014.06.27 |
| 13 |
* @since 5.2.0 |
| 14 |
*/ |
| 15 |
|
| 16 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 17 |
|
| 18 |
|
| 19 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 20 |
// A J A X |
| 21 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 22 |
|
| 23 |
//FixIn: 9.6.3.5 |
| 24 |
|
| 25 |
function wpbc_silent_import_all_events() { |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
global $wpdb; |
| 30 |
|
| 31 |
$wpbc_Google_Calendar = new WPBC_Google_Calendar(); |
| 32 |
|
| 33 |
$wpbc_Google_Calendar->setSilent(); |
| 34 |
|
| 35 |
$wpbc_Google_Calendar->set_timezone( get_bk_option('booking_gcal_timezone') ); |
| 36 |
|
| 37 |
$wpbc_Google_Calendar->set_events_max( get_bk_option( 'booking_gcal_events_max') ); |
| 38 |
|
| 39 |
$wpbc_Google_Calendar->set_events_from_with_array( |
| 40 |
array( get_bk_option( 'booking_gcal_events_from') |
| 41 |
, get_bk_option( 'booking_gcal_events_from_offset' ) |
| 42 |
, get_bk_option( 'booking_gcal_events_from_offset_type' ) ) |
| 43 |
); |
| 44 |
|
| 45 |
$wpbc_Google_Calendar->set_events_until_with_array( |
| 46 |
array( get_bk_option( 'booking_gcal_events_until') |
| 47 |
, get_bk_option( 'booking_gcal_events_until_offset' ) |
| 48 |
, get_bk_option( 'booking_gcal_events_until_offset_type' ) ) |
| 49 |
); |
| 50 |
|
| 51 |
if ( ! class_exists('wpdev_bk_personal') ) { |
| 52 |
|
| 53 |
$wpbc_Google_Calendar->setUrl( get_bk_option( 'booking_gcal_feed') ); |
| 54 |
$import_result = $wpbc_Google_Calendar->run(); |
| 55 |
|
| 56 |
} else { |
| 57 |
|
| 58 |
$types_list = $wpdb->get_results( "SELECT booking_type_id, import FROM {$wpdb->prefix}bookingtypes" ); |
| 59 |
|
| 60 |
foreach ($types_list as $wpbc_booking_resource) { |
| 61 |
$wpbc_booking_resource_id = $wpbc_booking_resource->booking_type_id; |
| 62 |
$wpbc_booking_resource_feed = $wpbc_booking_resource->import; |
| 63 |
if ( (! empty($wpbc_booking_resource_feed) ) && ($wpbc_booking_resource_feed != NULL ) && ( $wpbc_booking_resource_feed != '/' ) ) { |
| 64 |
|
| 65 |
$wpbc_Google_Calendar->setUrl($wpbc_booking_resource_feed); |
| 66 |
$wpbc_Google_Calendar->setResource($wpbc_booking_resource_id); |
| 67 |
|
| 68 |
//FixIn: 9.9.0.25 |
| 69 |
if ( function_exists( 'wpbm_delete_all_imported_bookings' ) ) { |
| 70 |
wpbm_delete_all_imported_bookings( array( 'resource_id' => $wpbc_booking_resource_id ) ); |
| 71 |
} |
| 72 |
$import_result = $wpbc_Google_Calendar->run(); |
| 73 |
} |
| 74 |
} |
| 75 |
} |
| 76 |
// debuge(2); |
| 77 |
} |
| 78 |
add_bk_action('wpbc_silent_import_all_events' , 'wpbc_silent_import_all_events' ); |
| 79 |
|
| 80 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 81 |
// Fields for Modal window |
| 82 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 83 |
|
| 84 |
function wpbc_gcal_settings_content_field_from( $booking_gcal_events_from, $booking_gcal_events_from_offset = '', $booking_gcal_events_from_offset_type = '' ) { |
| 85 |
if ($booking_gcal_events_from == "date") { |
| 86 |
echo '<style type="text/css"> .booking_gcal_events_from .wpbc_offset_value { display:none; } </style>'; |
| 87 |
} else { |
| 88 |
echo '<style type="text/css"> .booking_gcal_events_from .wpbc_offset_datetime { display:none; } </style>'; |
| 89 |
} |
| 90 |
?> |
| 91 |
<tr valign="top"> |
| 92 |
<th scope="row"><label for="booking_gcal_events_from" ><?php _e('From' ,'booking'); ?>:</label></th> |
| 93 |
<td class="booking_gcal_events_from"> |
| 94 |
<select id="booking_gcal_events_from" name="booking_gcal_events_from" |
| 95 |
onchange="javascript: if(this.value=='date') { |
| 96 |
jQuery('.booking_gcal_events_from .wpbc_offset_value').hide(); |
| 97 |
jQuery('.booking_gcal_events_from .wpbc_offset_datetime').show(); |
| 98 |
} else { |
| 99 |
jQuery('.booking_gcal_events_from .wpbc_offset_value').show(); |
| 100 |
jQuery('.booking_gcal_events_from .wpbc_offset_datetime').hide(); |
| 101 |
} |
| 102 |
jQuery('#booking_gcal_events_from_offset').val('');" > |
| 103 |
<?php |
| 104 |
$wpbc_options = array( |
| 105 |
"now" => __('Now' ,'booking') |
| 106 |
, "today" => __('00:00 today' ,'booking') |
| 107 |
, "week" => __('Start of current week' ,'booking') |
| 108 |
, "month-start" => __('Start of current month' ,'booking') |
| 109 |
, "month-end" => __('End of current month' ,'booking') |
| 110 |
, "any" => __('The start of time' ,'booking') |
| 111 |
, "date" => __('Specific date / time' ,'booking') |
| 112 |
); |
| 113 |
foreach ($wpbc_options as $key => $value) { |
| 114 |
?><option <?php if( $booking_gcal_events_from == $key ) echo "selected"; ?> value="<?php echo $key; ?>"><?php echo $value; ?></option><?php |
| 115 |
} |
| 116 |
?> |
| 117 |
</select> |
| 118 |
<span class="description"><?php _e('Select option, when to start retrieving events.' ,'booking');?></span> |
| 119 |
<div class="booking_gcal_events_from_offset" style="margin:10px 0 0;"> |
| 120 |
<label for="booking_gcal_events_from_offset"> <span class="wpbc_offset_value"><?php _e('Offset' ,'booking'); ?></span><span class="wpbc_offset_datetime" ><?php _e('Enter date / time' ,'booking'); ?></span>: </label> |
| 121 |
<input type="text" id="booking_gcal_events_from_offset" name="booking_gcal_events_from_offset" value="<?php echo $booking_gcal_events_from_offset; ?>" style="width:100px;text-align: right;" /> |
| 122 |
<span class="wpbc_offset_value"> |
| 123 |
<select id="booking_gcal_events_from_offset_type" name="booking_gcal_events_from_offset_type" style="margin-top: -2px;width: 99px;"> |
| 124 |
<?php |
| 125 |
$wpbc_options = array( |
| 126 |
"second" => __('seconds' ,'booking') |
| 127 |
, "minute" => __('minutes' ,'booking') |
| 128 |
, "hour" => __('hours' ,'booking') |
| 129 |
, "day" => __('days' ,'booking') |
| 130 |
); |
| 131 |
foreach ($wpbc_options as $key => $value) { |
| 132 |
?><option <?php if( $booking_gcal_events_from_offset_type == $key ) echo "selected"; ?> value="<?php echo $key; ?>"><?php echo $value; ?></option><?php |
| 133 |
} |
| 134 |
?> |
| 135 |
</select> |
| 136 |
<span class="description"><?php _e('You can specify an additional offset from you chosen start point. The offset can be negative.' ,'booking');?></span> |
| 137 |
</span> |
| 138 |
<span class="wpbc_offset_datetime"> |
| 139 |
<em><?php printf(__('Type your date in format %s. Example: %s' ,'booking'),'Y-m-d','2014-08-01'); ?></em> |
| 140 |
</span> |
| 141 |
</div> |
| 142 |
</td> |
| 143 |
</tr> |
| 144 |
<?php |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
function wpbc_gcal_settings_content_field_until( $booking_gcal_events_until, $booking_gcal_events_until_offset = '', $booking_gcal_events_until_offset_type = '' ) { |
| 149 |
if ($booking_gcal_events_until == "date") { |
| 150 |
echo '<style type="text/css"> .booking_gcal_events_until .wpbc_offset_value { display:none; } </style>'; |
| 151 |
} else { |
| 152 |
echo '<style type="text/css"> .booking_gcal_events_until .wpbc_offset_datetime { display:none; } </style>'; |
| 153 |
} |
| 154 |
?> |
| 155 |
<tr valign="top"> |
| 156 |
<th scope="row"><label for="booking_gcal_events_until" ><?php _e('Until' ,'booking'); ?>:</label></th> |
| 157 |
<td class="booking_gcal_events_until"> |
| 158 |
<select id="booking_gcal_events_until" name="booking_gcal_events_until" |
| 159 |
onchange="javascript: if(this.value=='date') { |
| 160 |
jQuery('.booking_gcal_events_until .wpbc_offset_value').hide(); |
| 161 |
jQuery('.booking_gcal_events_until .wpbc_offset_datetime').show(); |
| 162 |
} else { |
| 163 |
jQuery('.booking_gcal_events_until .wpbc_offset_value').show(); |
| 164 |
jQuery('.booking_gcal_events_until .wpbc_offset_datetime').hide(); |
| 165 |
} |
| 166 |
jQuery('#booking_gcal_events_until_offset').val('');" > |
| 167 |
<?php |
| 168 |
$wpbc_options = array( |
| 169 |
"now" => __('Now' ,'booking') |
| 170 |
, "today" => __('00:00 today' ,'booking') |
| 171 |
, "week" => __('Start of current week' ,'booking') |
| 172 |
, "month-start" => __('Start of current month' ,'booking') |
| 173 |
, "month-end" => __('End of current month' ,'booking') |
| 174 |
, "any" => __('The end of time' ,'booking') |
| 175 |
, "date" => __('Specific date / time' ,'booking') |
| 176 |
); |
| 177 |
foreach ($wpbc_options as $key => $value) { |
| 178 |
?><option <?php if( $booking_gcal_events_until == $key ) echo "selected"; ?> value="<?php echo $key; ?>"><?php echo $value; ?></option><?php |
| 179 |
} |
| 180 |
?> |
| 181 |
</select> |
| 182 |
<span class="description"><?php _e('Select option, when to stop retrieving events.' ,'booking');?></span> |
| 183 |
<div class="booking_gcal_events_until_offset" style="margin:10px 0 0;"> |
| 184 |
<label for="booking_gcal_events_until_offset" > <span class="wpbc_offset_value"><?php _e('Offset' ,'booking'); ?></span><span class="wpbc_offset_datetime" ><?php _e('Enter date / time' ,'booking'); ?></span>: </label> |
| 185 |
<input type="text" id="booking_gcal_events_until_offset" name="booking_gcal_events_until_offset" value="<?php echo $booking_gcal_events_until_offset; ?>" style="width:100px;text-align: right;" /> |
| 186 |
<span class="wpbc_offset_value"> |
| 187 |
<select id="booking_gcal_events_until_offset_type" name="booking_gcal_events_until_offset_type" style="margin-top: -2px;width: 99px;"> |
| 188 |
<?php |
| 189 |
$wpbc_options = array( |
| 190 |
"second" => __('seconds' ,'booking') |
| 191 |
, "minute" => __('minutes' ,'booking') |
| 192 |
, "hour" => __('hours' ,'booking') |
| 193 |
, "day" => __('days' ,'booking') |
| 194 |
); |
| 195 |
foreach ($wpbc_options as $key => $value) { |
| 196 |
?><option <?php if( $booking_gcal_events_until_offset_type == $key ) echo "selected"; ?> value="<?php echo $key; ?>"><?php echo $value; ?></option><?php |
| 197 |
} |
| 198 |
?> |
| 199 |
</select> |
| 200 |
<span class="description"><?php _e('You can specify an additional offset from you chosen end point. The offset can be negative.' ,'booking');?></span> |
| 201 |
</span> |
| 202 |
<span class="wpbc_offset_datetime"> |
| 203 |
<em><?php printf(__('Type your date in format %s. Example: %s' ,'booking'),'Y-m-d','2014-08-30'); ?></em> |
| 204 |
</span> |
| 205 |
|
| 206 |
</div> |
| 207 |
</td> |
| 208 |
</tr> |
| 209 |
<?php |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
function wpbc_gcal_settings_content_field_max_feeds($booking_gcal_events_max) { |
| 214 |
?> |
| 215 |
<tr valign="top"> |
| 216 |
<th scope="row"><label for="booking_gcal_events_max" ><?php _e('Maximum number' ,'booking'); ?>:</label></th> |
| 217 |
<td><input id="booking_gcal_events_max" name="booking_gcal_events_max" class="regular-text" type="text" value="<?php echo $booking_gcal_events_max; ?>" /> |
| 218 |
<span class="description"><?php |
| 219 |
_e('You can specify the maximum number of events to import during one session.' ,'booking'); |
| 220 |
?></span> |
| 221 |
</td> |
| 222 |
</tr> |
| 223 |
<?php |
| 224 |
} |
| 225 |
|
| 226 |
|
| 227 |
function wpbc_gcal_settings_content_field_timezone($booking_gcal_timezone) { |
| 228 |
?> |
| 229 |
<tr valign="top"> |
| 230 |
<th scope="row"><label for="booking_gcal_timezone" ><?php _e('Timezone' ,'booking'); ?>:</label></th> |
| 231 |
<td> |
| 232 |
<select id="booking_gcal_timezone" name="booking_gcal_timezone"> |
| 233 |
<?php |
| 234 |
$wpbc_options = array( |
| 235 |
"" => __('Default' ,'booking') |
| 236 |
); |
| 237 |
foreach ($wpbc_options as $key => $value) { |
| 238 |
?><option <?php if( $booking_gcal_timezone == $key ) echo "selected"; ?> value="<?php echo $key; ?>"><?php echo $value; ?></option><?php |
| 239 |
} |
| 240 |
|
| 241 |
|
| 242 |
// structure: $wpbc_booking_region_cities_list["Pacific"]["Fiji"] = "Fiji"; |
| 243 |
$wpbc_booking_region_cities_list = wpbc_get_booking_region_cities_list(); //FixIn: 8.9.4.9 |
| 244 |
|
| 245 |
foreach ($wpbc_booking_region_cities_list as $region => $region_cities) { |
| 246 |
|
| 247 |
echo '<optgroup label="'. $region .'">'; |
| 248 |
|
| 249 |
foreach ($region_cities as $city_key => $city_title) { |
| 250 |
|
| 251 |
if( $booking_gcal_timezone == $region .'/'. $city_key ) |
| 252 |
$is_selected = 'selected'; |
| 253 |
else |
| 254 |
$is_selected = ''; |
| 255 |
|
| 256 |
echo '<option '.$is_selected.' value="'. $region .'/'. $city_key .'">' . $city_title . '</option>'; |
| 257 |
|
| 258 |
} |
| 259 |
echo '</optgroup>'; |
| 260 |
} |
| 261 |
|
| 262 |
|
| 263 |
?> |
| 264 |
</select> |
| 265 |
<span class="description"><?php _e('Select a city in your required timezone, if you are having problems with dates and times.' ,'booking');?></span> |
| 266 |
</td> |
| 267 |
</tr> |
| 268 |
<?php |
| 269 |
} |
| 270 |
|
| 271 |
//FixIn: 9.6.3.5 |
| 272 |
|
| 273 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 274 |
// Activation |
| 275 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 276 |
function wpbc_sync_gcal_activate() { |
| 277 |
|
| 278 |
add_bk_option( 'booking_gcal_feed' , '' ); |
| 279 |
add_bk_option( 'booking_gcal_events_from', 'month-start'); |
| 280 |
add_bk_option( 'booking_gcal_events_from_offset' , '' ); |
| 281 |
add_bk_option( 'booking_gcal_events_from_offset_type' , '' ); |
| 282 |
add_bk_option( 'booking_gcal_events_until', 'any'); |
| 283 |
add_bk_option( 'booking_gcal_events_until_offset' , '' ); |
| 284 |
add_bk_option( 'booking_gcal_events_until_offset_type' , '' ); |
| 285 |
add_bk_option( 'booking_gcal_events_max', '25'); |
| 286 |
add_bk_option( 'booking_gcal_api_key', ''); |
| 287 |
add_bk_option( 'booking_gcal_timezone',''); |
| 288 |
add_bk_option( 'booking_gcal_is_send_email' , 'Off' ); |
| 289 |
add_bk_option( 'booking_gcal_auto_import_is_active' , 'Off' ); |
| 290 |
add_bk_option( 'booking_gcal_auto_import_time', '24' ); |
| 291 |
|
| 292 |
add_bk_option( 'booking_gcal_events_form_fields', 'a:3:{s:5:"title";s:9:"text^name";s:11:"description";s:16:"textarea^details";s:5:"where";s:5:"text^";}'); |
| 293 |
} |
| 294 |
add_bk_action('wpbc_other_versions_activation', 'wpbc_sync_gcal_activate' ); |
| 295 |
|
| 296 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 297 |
// Deactivation |
| 298 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 299 |
function wpbc_sync_gcal_deactivate() { |
| 300 |
|
| 301 |
delete_bk_option( 'booking_gcal_feed' ); |
| 302 |
delete_bk_option( 'booking_gcal_events_from'); |
| 303 |
delete_bk_option( 'booking_gcal_events_from_offset' ); |
| 304 |
delete_bk_option( 'booking_gcal_events_from_offset_type' ); |
| 305 |
|
| 306 |
delete_bk_option( 'booking_gcal_events_until'); |
| 307 |
delete_bk_option( 'booking_gcal_events_until_offset' ); |
| 308 |
delete_bk_option( 'booking_gcal_events_until_offset_type' ); |
| 309 |
|
| 310 |
delete_bk_option( 'booking_gcal_events_max' ); |
| 311 |
delete_bk_option( 'booking_gcal_api_key' ); |
| 312 |
delete_bk_option( 'booking_gcal_timezone'); |
| 313 |
delete_bk_option( 'booking_gcal_is_send_email' ); |
| 314 |
delete_bk_option( 'booking_gcal_auto_import_is_active' ); |
| 315 |
delete_bk_option( 'booking_gcal_auto_import_time' ); |
| 316 |
|
| 317 |
delete_bk_option( 'booking_gcal_events_form_fields'); |
| 318 |
|
| 319 |
} |
| 320 |
add_bk_action('wpbc_other_versions_deactivation', 'wpbc_sync_gcal_deactivate' ); |
| 321 |
|