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

page-import-gcal.php in Booking Calendar 10.1.3, at core/admin/page-import-gcal.php

839 lines 51.6 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 * @package Booking > Settings > Import page
5 * @category Settings API
6 * @author wpdevelop
7 *
8 * @web-site https://wpbookingcalendar.com/
9 * @email info@wpbookingcalendar.com
10 * @modified 2016-08-07
11 *
12 * This is COMMERCIAL SCRIPT
13 * We are not guarantee correct work and support of Booking Calendar, if some file(s) was modified by someone else then wpdevelop.
14 */
15
16 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
17
18
19 /** API for Settings Page */
20 class WPBC_API_SettingsImportGCal extends WPBC_Settings_API {
21
22 /**
23 * Settings API Constructor
24 * During creation, system try to load values from DB, if exist.
25 *
26 * @param type $id - "Pure Name"
27 */
28 public function __construct( $id, $init_fields_values = array(), $options = array() ) {
29
30 $default_options = array(
31 'db_prefix_option' => ''
32 , 'db_saving_type' => 'separate'
33 );
34 // separate_prefix: update_bk_option( $this->options['db_prefix_option'] . $settings_id . '_' . $field_name , $value );
35 $options = wp_parse_args( $options, $default_options );
36
37 /**
38 * Activation and deactivation of these options already done at the wpbc-gcal.php file
39 //
40 // add_bk_action( 'wpbc_other_versions_activation', array( $this, 'activate' ) ); // Activate
41 // add_bk_action( 'wpbc_other_versions_deactivation', array( $this, 'deactivate' ) ); // Deactivate
42 */
43
44 parent::__construct( $id, $options, $init_fields_values ); // Define ID of Setting page and options
45 }
46
47
48 /** Define settings Fields */
49 public function init_settings_fields() {
50
51 $this->fields = array();
52
53
54 // Auto import
55 if ( wpbc_is_mu_user_can_be_here('only_super_admin') ){
56
57 $this->fields['booking_gcal_auto_import_is_active'] = array(
58 'type' => 'checkbox'
59 , 'default' => 'Off'
60 , 'title' => __( 'Activate auto import', 'booking' )
61 , 'label' => sprintf(__('Check this box to %sactivate%s auto import events and creation bookings from them' ,'booking'),'<b>','</b>')
62 , 'description' => ''
63 , 'group' => 'auto_import'
64
65 );
66 // $options = array();
67 // $options[1] = '1 ' . __( 'hour', 'booking' );
68 // for ( $i = 2; $i < 24; $i++ ) {
69 // $options[$i] = $i . ' ' . __( 'hours', 'booking' );
70 // }
71 // $options[24] = '1 ' . __( 'day', 'booking' );
72 // for ( $i = 2; $i < 32; $i++ ) {
73 // $options[( $i * 24)] = $i . ' ' . __( 'days', 'booking' );
74 // }
75
76 // Fix for legacy code (previously) was only integer value here in hours
77 $legacy_booking_gcal_auto_import_time = get_bk_option( 'booking_gcal_auto_import_time' );
78 if ( ( false === strpos( $legacy_booking_gcal_auto_import_time, 'm' ) ) && ( false === strpos( $legacy_booking_gcal_auto_import_time, 'd' ) ) ) {
79 update_bk_option( 'booking_gcal_auto_import_time', strval( intval( $legacy_booking_gcal_auto_import_time ) * 60 ) . 'm' );
80 }
81
82 // Options
83 $extra_time = array();
84 foreach ( range( 15, 55, 15 ) as $extra_num ) { // Each 5 minutes
85 $extra_time[ $extra_num . 'm' ] = $extra_num . ' ' . __( 'minutes', 'booking' );
86 }
87 $extra_time[ '60' . 'm' ] = '1 ' . __( 'hour', 'booking' );
88 foreach ( range( 75, 115, 15 ) as $extra_num ) { // 1 hour + Each 5 minutes
89 $extra_time[ $extra_num . 'm' ] = '1 ' . __( 'hour', 'booking' ) . ' ' . ( $extra_num - 60 ) . ' ' . __( 'minutes', 'booking' );
90 }
91 foreach ( range( 120, 1380, 60 ) as $extra_num ) { // Each Hour based on minutes
92 $extra_time[ $extra_num . 'm' ] = ( $extra_num / 60 ) . ' ' . __( 'hours', 'booking' );
93 }
94 foreach ( range( 1, 30, 1 ) as $extra_num ) { // Each Day
95 $extra_time[ $extra_num . 'd' ] = $extra_num . ' ' . __( 'day(s)', 'booking' );
96 }
97
98 $cron_info = '';
99 $readable_time_of_next_run = WPBC()->cron->get_readable_time_of_last_run( 'wpbc_import_gcal' );
100 if ( ! empty( $readable_time_of_next_run ) ) {
101 $cron_info .= '<br/><strong>' . __( 'Last import', 'booking' ) . '</strong>: ' . $readable_time_of_next_run;
102 }
103 $readable_time_of_next_run = WPBC()->cron->get_readable_time_of_next_run( 'wpbc_import_gcal', '<strong>'.__( 'during', 'booking' ).'</strong> <code>' ) . '</code>';
104 if ( ! empty( $readable_time_of_next_run ) ) {
105 $cron_info .= '<br/><strong>' . __( 'Next import', 'booking' ) . '</strong>: ' . $readable_time_of_next_run;
106 }
107
108 // $active_tasks_arr = WPBC()->cron->get_active_tasks_info();
109 // if ( ! empty( $active_tasks_arr['wpbc_import_gcal'] ) ) {
110 // $cron_info .= '<br/><strong>' . __( 'Last import', 'booking' ) . '</strong>: ' . $active_tasks_arr['wpbc_import_gcal']['last_time__run__local'];
111 // $cron_info .= '<br/><strong>' . __( 'Next import', 'booking' ) . '</strong>: ' . $active_tasks_arr['wpbc_import_gcal']['next_time__run__local'];
112 // $cron_info .= ' ' . __( 'during', 'booking' ) . ': <strong>' . wpbc_get_readable_time_interval( $active_tasks_arr['wpbc_import_gcal']['next_run_after_seconds'] ) . '</strong> ';
113 // }
114
115 $this->fields['booking_gcal_auto_import_time'] = array(
116 'type' => 'select'
117 , 'default' => '24'
118 , 'title' => __('Import events every' ,'booking')
119 , 'description' => __('Select time duration of import requests.' ,'booking') . $cron_info
120 , 'description_tag' => 'span'
121 , 'css' => ''
122 , 'options' => $extra_time
123 , 'tr_class' => 'wpbc_sub_settings_grayed wpbc_tr_auto_import'
124 , 'group' => 'auto_import'
125 );
126 }
127 ////////////////////////////////////////////////////////////////////////
128
129
130 // General Google Calendar Settings
131 $this->fields['booking_gcal_api_key'] = array(
132 'type' => 'text'
133 , 'default' => ''
134 //, 'placeholder' => ''
135 , 'title' => __('Google API Key', 'booking')
136 , 'description' => __('Please enter your Google API key. This field required to import events.' ,'booking')
137 . '<div class="wpbc-settings-notice notice-info" style="text-align:left;"><strong>'
138 . __('Note:' ,'booking') . '</strong> '
139 . sprintf( __('You can check in this %sinstruction how to generate and use your Google API key%s.' ,'booking')
140 , '<a href="https://wpbookingcalendar.com/faq/import-gc-events/">'
141 ,'</a>'
142 )
143 . '</div>'
144 . ( ( wpbc_is_this_demo() ) ? wpbc_get_warning_text_in_demo_mode() : '' )
145 , 'description_tag' => 'p'
146 , 'css' => ''//'width:100%'
147 , 'group' => 'general'
148 , 'tr_class' => '' // 'wpbc_sub_settings_grayed'
149 //, 'validate_as' => array( 'required' )
150 , 'is_demo_safe' => wpbc_is_this_demo()
151 );
152
153
154 // General Google ID for Free version
155 if ( ! class_exists('wpdev_bk_personal') )
156 $this->fields['booking_gcal_feed'] = array(
157 'type' => 'text'
158 , 'default' => ''
159 //, 'placeholder' => ''
160 , 'title' => __('Google Calendar ID', 'booking')
161 , 'description' => ( ( wpbc_is_this_demo() ) ? wpbc_get_warning_text_in_demo_mode() : '' )
162 , 'description_tag' => 'span'
163 , 'css' => 'width:100%'
164 , 'group' => 'general'
165 , 'tr_class' => '' // 'wpbc_sub_settings_grayed'
166 //, 'validate_as' => array( 'required' )
167 , 'is_demo_safe' => wpbc_is_this_demo()
168 );
169
170 ////////////////////////////////////////////////////////////////////////
171
172
173 // M A X num - Default Settings
174 $this->fields['booking_gcal_events_max'] = array(
175 'type' => 'text'
176 , 'default' => '25'
177 //, 'placeholder' => ''
178 , 'title' => __('Maximum number', 'booking')
179 , 'description' => __('You can specify the maximum number of events to import during one session.' ,'booking')
180 , 'description_tag' => 'span'
181 , 'css' => 'width:4em'
182 , 'group' => 'default_settings'
183 , 'tr_class' => '' // 'wpbc_sub_settings_grayed'
184 //, 'validate_as' => array( 'required' )
185 );
186 // F R O M /////////////////////////////////////////////////////////
187 $options = array(
188 "now" => __('Now' ,'booking')
189 , "today" => __('00:00 today' ,'booking')
190 , "week" => __('Start of current week' ,'booking')
191 , "month-start" => __('Start of current month' ,'booking')
192 , "month-end" => __('End of current month' ,'booking')
193 , "any" => __('The start of time' ,'booking')
194 , "date" => __('Specific date / time' ,'booking')
195 );
196 $this->fields['booking_gcal_events_from'] = array(
197 'type' => 'select'
198 , 'default' => 'month-start'
199 , 'title' => __('From', 'booking')
200 , 'description' => __('Select option, when to start retrieving events.' ,'booking')
201 , 'description_tag' => 'span'
202 , 'css' => ''
203 , 'options' => $options
204 , 'group' => 'default_settings'
205 );
206 /////////////
207 $this->fields['booking_gcal_events_from_offset_html_prefix'] = array(
208 'type' => 'pure_html'
209 , 'group' => 'default_settings'
210 , 'html' => '<tr valign="top" class="wpbc_tr_import_gcal_booking_gcal_events_from_offset wpbc_sub_settings_grayed wpbc_tr_from_offset">
211 <th scope="row">
212 <label class="wpbc-form-text" for="'
213 . esc_attr( 'import_gcal_booking_gcal_events_from_offset' )
214 . '">'
215 . '<span class="wpbc_offset_value">' . wp_kses_post( __('Offset' ,'booking') ) . '</span>'
216 . '<span class="wpbc_offset_datetime">' . wp_kses_post( __('Enter date / time' ,'booking') ) . '</span>'
217 . '</label>
218 </th>
219 <td><fieldset>'
220 );
221 $this->fields['booking_gcal_events_from_offset'] = array(
222 'type' => 'text'
223 , 'default' => ''
224 //, 'placeholder' => ''
225 , 'title' => ''
226 , 'description' => ''
227 , 'description_tag' => 'span'
228 , 'css' => 'width:6em;height:28px;margin:0;vertical-align:middle;'
229 , 'group' => 'default_settings'
230 , 'tr_class' => 'wpbc_sub_settings_grayed wpbc_tr_from_offset'
231 , 'only_field' => true
232 );
233 $option_types = array(
234 'second' => __('seconds' ,'booking')
235 , 'minute' => __('minutes' ,'booking')
236 , 'hour' => __('hours' ,'booking')
237 , 'day' => __('days' ,'booking')
238 );
239 $this->fields['booking_gcal_events_from_offset_type'] = array(
240 'type' => 'select'
241 , 'default' => ''
242 , 'title' => ''
243 , 'description' => ''
244 , 'description_tag' => 'span'
245 , 'css' => ''
246 , 'options' => $option_types
247 , 'group' => 'default_settings'
248 , 'class' => 'wpbc_offset_value'
249 , 'tr_class' => 'wpbc_sub_settings_grayed'
250 , 'only_field' => true
251 );
252 $this->fields['booking_gcal_events_from_offset_html_sufix'] = array(
253 'type' => 'pure_html'
254 , 'group' => 'default_settings'
255 , 'html' => ' <span class="description wpbc_offset_value">'
256 . __('You can specify an additional offset from you chosen start point. The offset can be negative.' ,'booking')
257 . '</span>
258 <span class="description wpbc_offset_datetime">'
259 . sprintf( __('Type your date in format %s. Example: %s' ,'booking'), '<code>Y-m-d</code>', '<code>' . date_i18n( 'Y-m-d' ) . '</code>' )
260 . '</span>
261 </fieldset>
262 </td>
263 </tr>'
264 );
265 /////////////
266
267
268 // U N T I L /////////////////////////////////////////////////////
269 $options = array(
270 "now" => __('Now' ,'booking')
271 , "today" => __('00:00 today' ,'booking')
272 , "week" => __('Start of current week' ,'booking')
273 , "month-start" => __('Start of current month' ,'booking')
274 , "month-end" => __('End of current month' ,'booking')
275 , "any" => __('The end of time' ,'booking')
276 , "date" => __('Specific date / time' ,'booking')
277 );
278 $this->fields['booking_gcal_events_until'] = array(
279 'type' => 'select'
280 , 'default' => 'any'
281 , 'title' => __('Until', 'booking')
282 , 'description' => __('Select option, when to stop retrieving events.' ,'booking')
283 , 'description_tag' => 'span'
284 , 'css' => ''
285 , 'options' => $options
286 , 'group' => 'default_settings'
287 );
288 /////////////
289 $this->fields['booking_gcal_events_until_offset_html_prefix'] = array(
290 'type' => 'pure_html'
291 , 'group' => 'default_settings'
292 , 'html' => '<tr valign="top" class="wpbc_tr_import_gcal_booking_gcal_events_until_offset wpbc_sub_settings_grayed wpbc_tr_until_offset">
293 <th scope="row">
294 <label class="wpbc-form-text" for="'
295 . esc_attr( 'import_gcal_booking_gcal_events_until_offset' )
296 . '">'
297 . '<span class="wpbc_offset_value">' . wp_kses_post( __('Offset' ,'booking') ) . '</span>'
298 . '<span class="wpbc_offset_datetime">' . wp_kses_post( __('Enter date / time' ,'booking') ) . '</span>'
299 . '</label>
300 </th>
301 <td><fieldset>'
302 );
303 $this->fields['booking_gcal_events_until_offset'] = array(
304 'type' => 'text'
305 , 'default' => ''
306 //, 'placeholder' => ''
307 , 'title' => ''
308 , 'description' => ''
309 , 'description_tag' => 'span'
310 , 'css' => 'width:6em;height:28px;margin:0;vertical-align:middle;'
311 , 'group' => 'default_settings'
312 , 'tr_class' => 'wpbc_sub_settings_grayed wpbc_tr_until_offset'
313 , 'only_field' => true
314 );
315 $option_types = array(
316 'second' => __('seconds' ,'booking')
317 , 'minute' => __('minutes' ,'booking')
318 , 'hour' => __('hours' ,'booking')
319 , 'day' => __('days' ,'booking')
320 );
321 $this->fields['booking_gcal_events_until_offset_type'] = array(
322 'type' => 'select'
323 , 'default' => ''
324 , 'title' => ''
325 , 'description' => ''
326 , 'description_tag' => 'span'
327 , 'css' => ''
328 , 'options' => $option_types
329 , 'group' => 'default_settings'
330 , 'class' => 'wpbc_offset_value'
331 , 'tr_class' => 'wpbc_sub_settings_grayed'
332 , 'only_field' => true
333 );
334 $this->fields['booking_gcal_events_until_offset_html_sufix'] = array(
335 'type' => 'pure_html'
336 , 'group' => 'default_settings'
337 , 'html' => ' <span class="description wpbc_offset_value">'
338 . __('You can specify an additional offset from you chosen start point. The offset can be negative.' ,'booking')
339 . '</span>
340 <span class="description wpbc_offset_datetime">'
341 . sprintf( __('Type your date in format %s. Example: %s' ,'booking'), '<code>Y-m-d</code>', '<code>' . date_i18n( 'Y-m-d' ) . '</code>' )
342 . '</span>
343 </fieldset>
344 </td>
345 </tr>'
346 );
347 /////////////
348
349 ////////////////////////////////////////////////////////////////////////
350
351 // Help
352 $this->fields['booking_gcal_events_help'] = array(
353 'type' => 'help'
354 , 'value' => array()
355 , 'cols' => 2
356 , 'group' => 'help'
357 );
358 $this->fields['booking_gcal_events_help']['value'][] = '<h4 style="margin-top:-20px;">01. ' . __('To get Google Calendar API key please follow this instruction' ,'booking') . ':</h4>';
359 $this->fields['booking_gcal_events_help']['value'][] = '<ol style="list-style-type: decimal !important;margin-left: 15px;font-size:0.86em;">';
360 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf(__('Go to Google Developer Console: %s.' ,'booking'),'<a href="https://console.developers.google.com" target="_blank">https://console.developers.google.com</a>') . '</li>';
361 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf(__('Give your project a name and click "Create".' ,'booking')) . '</li>';
362 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf(__('In the sidebar click on "APIs & auth".' ,'booking')) . '</li>';
363 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf(__('Click APIs and make sure "Calendar API" is set to ON.' ,'booking')) . '</li>';
364 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf(__('Now click on "Credentials" in the sidebar.' ,'booking')) . '</li>';
365 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf(__('Under the section "Public API access" click the button "Create new Key".' ,'booking')) . '</li>';
366 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf(__('On the popup click the button "Server Key" and click "Create".' ,'booking')) . '</li>';
367 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf(__('You will now see a table loaded with the top item being the API Key. Copy this and paste it into %sGoogle API Key%s field at this page.' ,'booking'),'<strong>','</strong>') . '</li>';
368 $this->fields['booking_gcal_events_help']['value'][] = '</ol>';
369
370 $this->fields['booking_gcal_events_help']['value'][] = '<h4>02. ' . __('Set Your Calendar to Public' ,'booking') . ':</h4>';
371 $this->fields['booking_gcal_events_help']['value'][] = '<ol style="list-style-type: decimal !important;margin-left: 15px;font-size:0.86em;">';
372 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf(__('Navigate to your Google calendars.' ,'booking'),'<a href="https://console.developers.google.com" target="_blank">https://console.developers.google.com</a>') . '</li>';
373 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf(__('Open the settings for the calendar.' ,'booking')) . '</li>';
374 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf(__('Click the "Share this Calendar" link.' ,'booking')) . '</li>';
375 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf(__('Click the checkbox to make calendar public. Do not check the other option.' ,'booking')) . '</li>';
376 $this->fields['booking_gcal_events_help']['value'][] = '</ol>';
377
378 $this->fields['booking_gcal_events_help']['value'][] = '<h4>03. ' . __('Find Your Calendar ID' ,'booking') . ':</h4>';
379 $this->fields['booking_gcal_events_help']['value'][] = '<ol style="list-style-type: decimal !important;margin-left: 15px;font-size:0.86em;">';
380 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf(__('Navigate to your Google calendars.' ,'booking'),'<a href="https://console.developers.google.com" target="_blank">https://console.developers.google.com</a>') . '</li>';
381 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf(__('Open the settings for the calendar.' ,'booking')) . '</li>';
382 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf(__('Now copy the Calendar ID to use in the plugin settings in your WordPress admin. Make sure to %suse the Calendar ID only, not the entire XML feed URL%s.' ,'booking'),'<strong>','</strong>') . '</li>';
383 $this->fields['booking_gcal_events_help']['value'][] = '</ol>';
384
385 ////////////////////////////////////////////////////////////////////////
386 }
387
388 }
389
390
391
392 /**
393 * Show Content
394 * Update Content
395 * Define Slug
396 * Define where to show
397 */
398 class WPBC_Page_SettingsImportGCal extends WPBC_Page_Structure {
399
400
401 public $settings_api = false;
402
403 /**
404 * API - for Fields of this Settings Page
405 *
406 * @param array $init_fields_values - array of init form fields data - this array can ovveride "default" fields and loaded data.
407 * @return object API
408 */
409 public function get_api( $init_fields_values = array() ){
410
411 if ( $this->settings_api === false ) {
412 $this->settings_api = new WPBC_API_SettingsImportGCal( 'import_gcal' , $init_fields_values );
413 }
414 return $this->settings_api;
415 }
416
417
418 public function in_page() {
419 return 'wpbc-settings';
420 }
421
422
423 public function tabs() {
424
425 $tabs = array();
426
427 $tabs[ 'sync' ] = array(
428 'title' => __( 'Sync', 'booking') // Title of TAB
429 , 'page_title'=> __( 'Sync', 'booking') // Title of Page
430 , 'hint' => __('Import' ,'booking') . ' / ' . __('Export' ,'booking')
431 //, 'link' => '' // Can be skiped, then generated link based on Page and Tab tags. Or can be extenral link
432 //, 'position' => '' // 'left' || 'right' || ''
433 //, 'css_classes'=> '' // CSS class(es)
434 //, 'icon' => '' // Icon - link to the real PNG img
435 , 'font_icon' => 'wpbc_icn_sync_alt' // CSS definition of forn Icon
436 //, 'default' => false // Is this tab activated by default or not: true || false.
437 //, 'disabled' => false // Is this tab disbaled: true || false.
438 //, 'hided' => false // Is this tab hided: true || false.
439 , 'subtabs' => array()
440 );
441
442
443 $subtabs = array();
444
445 $subtabs[ 'gcal' ] = array(
446 'type' => 'subtab' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html'
447 , 'title' => __('Import Google Calendar Events', 'booking') //__('Google Calendar' ,'booking') . ' - ' . __('Events Import' ,'booking') // Title of TAB
448 , 'page_title' => __('Import Google Calendar Events', 'booking') //__('Import Settings' ,'booking') // Title of Page
449 , 'hint' => __('Import Google Calendar Events' ,'booking') // Hint
450 , 'link' => '' // link
451 , 'position' => '' // 'left' || 'right' || ''
452 , 'css_classes' => '' // CSS class(es)
453 //, 'icon' => 'http://.../icon.png' // Icon - link to the real PNG img
454 //, 'font_icon' => 'wpbc_icn_mail_outline' // CSS definition of Font Icon
455 , 'header_font_icon' => 'wpbc_icn_sync_alt' // CSS definition of Font Icon //FixIn: 9.6.1.4
456 , 'default' => false // Is this sub tab activated by default or not: true || false.
457 , 'disabled' => false // Is this sub tab deactivated: true || false.
458 , 'checkbox' => false // or definition array for specific checkbox: array( 'checked' => true, 'name' => 'feature1_active_status' ) //, 'checkbox' => array( 'checked' => $is_checked, 'name' => 'enabled_active_status' )
459 , 'content' => 'content' // Function to load as conten of this TAB
460 );
461
462 $tabs[ 'sync' ]['subtabs'] = $subtabs;
463
464
465 return $tabs;
466 }
467
468
469 /** Show Content of Settings page */
470 public function content() {
471
472 //$active_tasks_arr = WPBC()->cron->get_active_tasks_info();
473 //debuge( $active_tasks_arr );
474
475 $this->css();
476
477 ////////////////////////////////////////////////////////////////////////
478 // Checking
479 ////////////////////////////////////////////////////////////////////////
480
481 do_action( 'wpbc_hook_settings_page_header', 'import_gcal_settings'); // Define Notices Section and show some static messages, if needed
482
483 if ( ! wpbc_is_mu_user_can_be_here('activated_user') ) return false; // Check if MU user activated, otherwise show Warning message.
484
485 // if ( ! wpbc_is_mu_user_can_be_here('only_super_admin') ) return false; // User is not Super admin, so exit. Basically its was already checked at the bottom of the PHP file, just in case.
486
487
488 ////////////////////////////////////////////////////////////////////////
489 // Load Data
490 ////////////////////////////////////////////////////////////////////////
491
492 $this->get_api(); // Load fields Data from DB
493
494
495 ////////////////////////////////////////////////////////////////////////
496 // S u b m i t Main Form
497 ////////////////////////////////////////////////////////////////////////
498
499 $submit_form_name = 'wpbc_import_gcal'; // Define form name
500
501 // $this->get_api()->validated_form_id = $submit_form_name; // Define ID of Form for ability to validate fields (like required field) before submit.
502
503 if ( isset( $_POST['is_form_sbmitted_'. $submit_form_name ] ) ) {
504
505 // Nonce checking {Return false if invalid, 1 if generated between, 0-12 hours ago, 2 if generated between 12-24 hours ago. }
506 $nonce_gen_time = check_admin_referer( 'wpbc_settings_page_' . $submit_form_name ); // Its stop show anything on submiting, if its not refear to the original page
507
508 // Save Changes
509 $this->update();
510 }
511
512
513 ////////////////////////////////////////////////////////////////////////
514 // JavaScript: Tooltips, Popover, Datepick (js & css)
515 ////////////////////////////////////////////////////////////////////////
516
517 echo '<span class="wpdevelop">';
518
519 wpbc_js_for_bookings_page();
520
521 echo '</span>';
522
523 ?><div class="clear" style="margin-bottom:0px;"></div><?php
524
525
526 // Scroll links ////////////////////////////////////////////////////////
527 ?>
528 <div class="wpdvlp-sub-tabs" style="background:none;border:none;box-shadow: none;padding:0;"><span class="nav-tabs" style="text-align:right;">
529 <a href="javascript:void(0);" onclick="javascript:wpbc_scroll_to('#wpbc_settings_import_gcal_events_general_metabox' );" original-title="" class="nav-tab go-to-link"><span><?php _e('General Settings', 'booking'); ?></span></a>
530 <?php if ( wpbc_is_mu_user_can_be_here('only_super_admin') ) { ?>
531 <a href="javascript:void(0);" onclick="javascript:wpbc_scroll_to('#wpbc_settings_import_gcal_events_auto_import_metabox' );" original-title="" class="nav-tab go-to-link"><span><?php _e('Auto import events' ,'booking'); ?></span></a>
532 <?php } ?>
533 <a href="javascript:void(0);" onclick="javascript:wpbc_scroll_to('#wpbc_settings_import_gcal_events_default_settings_metabox' );" original-title="" class="nav-tab go-to-link"><span><?php _e('Default settings for retrieving events' ,'booking'); ?></span></a>
534 <?php if ( class_exists('wpdev_bk_personal') ) { ?>
535 <a href="javascript:void(0);" onclick="javascript:wpbc_scroll_to('#wpbc_resource_table_gcal_id' );" original-title="" class="nav-tab go-to-link"><span><?php _e('Resources' ,'booking'); ?></span></a>
536 <?php } ?>
537 </span></div>
538 <?php
539
540 if ( class_exists('wpdev_bk_personal') )
541 wpbc_toolbar_search_by_id__top_form( array(
542 'search_form_id' => 'wpbc_booking_resources_search_form'
543 , 'search_get_key' => 'wh_resource_id'
544 , 'is_pseudo' => false
545 ) );
546
547
548 ////////////////////////////////////////////////////////////////////////
549 // Content ////////////////////////////////////////////////////////////
550 ?>
551 <div class="clear" style="margin-bottom:0px;"></div>
552 <span class="metabox-holder">
553 <form name="<?php echo $submit_form_name; ?>" id="<?php echo $submit_form_name; ?>" action="" method="post" autocomplete="off">
554 <?php
555 // N o n c e field, and key for checking S u b m i t
556 wp_nonce_field( 'wpbc_settings_page_' . $submit_form_name );
557 ?><input type="hidden" name="is_form_sbmitted_<?php echo $submit_form_name; ?>" id="is_form_sbmitted_<?php echo $submit_form_name; ?>" value="1" /><?php
558 ?><div class="clear"></div><?php
559
560 // Add hidden input SEARCH KEY field into main form, if previosly was searching by ID or Title
561 if ( class_exists('wpdev_bk_personal') )
562 wpbc_hidden_search_by_id_field_in_main_form( array( 'search_get_key' => 'wh_resource_id' ) ); //FixIn: 8.0.1.12
563
564 ?><div class="clear" style="height:10px;"></div><?php
565
566 ?><div class="wpbc_settings_row wpbc_settings_row_left"><?php
567
568
569 wpbc_open_meta_box_section( 'wpbc_settings_import_gcal_events_general', __('Google Calendar - General Settings' ,'booking') );
570
571 $this->get_api()->show( 'general' );
572
573 wpbc_close_meta_box_section();
574
575
576 if ( wpbc_is_mu_user_can_be_here('only_super_admin') ){
577
578 wpbc_open_meta_box_section( 'wpbc_settings_import_gcal_events_auto_import', __('Auto import events' ,'booking') );
579
580 $this->get_api()->show( 'auto_import' );
581
582 wpbc_close_meta_box_section();
583 }
584
585
586 wpbc_open_meta_box_section( 'wpbc_settings_import_gcal_events_default_settings', __('Default settings for retrieving events' ,'booking') );
587
588 $this->get_api()->show( 'default_settings' );
589
590 wpbc_close_meta_box_section();
591
592 ?>
593 </div>
594 <div class="wpbc_settings_row wpbc_settings_row_right"><?php
595
596 wpbc_open_meta_box_section( 'wpbc_settings_import_gcal_form_help', __('Help', 'booking') );
597 $this->get_api()->show( 'help' );
598 wpbc_close_meta_box_section();
599 ?>
600 </div>
601 <div id="wpbc_resources_link" class="clear"></div>
602 <?php if ( class_exists('wpdev_bk_personal') ) { ?>
603 <div id="wpbc_resource_table_gcal_id" class="wpbc_settings_row wpbc_settings_row_rightNO"><?php
604
605 //wpbc_open_meta_box_section( 'wpbc_settings_import_gcal_resources', __('Resources', 'booking') );
606
607 wpbc_import_gcal__show_table();
608
609 //wpbc_close_meta_box_section();
610 ?>
611 </div>
612 <div class="clear"></div>
613 <?php } ?>
614 <input type="submit" value="<?php _e('Save Changes','booking'); ?>" class="button button-primary wpbc_submit_button" />
615 </form>
616 </span>
617 <?php
618
619 do_action( 'wpbc_hook_settings_page_footer', 'import_gcal_settings' );
620
621 $this->enqueue_js();
622 }
623
624
625 /** Save Chanages */
626 public function update() {
627 //debuge($_POST);
628 if ( function_exists( 'wpbc_import_gcal__update') )
629 wpbc_import_gcal__update();
630
631 // Get Validated Email fields
632 $validated_fields = $this->get_api()->validate_post();
633
634 $validated_fields = apply_filters( 'wpbc_fields_before_saving_to_db__import_gcal', $validated_fields ); //Hook for validated fields.
635
636 //debuge($validated_fields);
637
638 $this->get_api()->save_to_db( $validated_fields );
639
640 wpbc_show_changes_saved_message();
641
642 // Old way of saving:
643 // update_bk_option( 'booking_cache_expiration' , WPBC_Settings_API::validate_text_post_static( 'booking_cache_expiration' ) );
644 }
645
646 //TODO: clear unused CSS here
647
648 // <editor-fold defaultstate="collapsed" desc=" CSS & JS " >
649
650 /** CSS for this page */
651 private function css() {
652 ?>
653 <style type="text/css">
654 .wpbc-help-message {
655 border:none;
656 }
657 /* toolbar fix */
658 .wpdevelop .visibility_container .control-group {
659 margin: 2px 8px 3px 0; /* margin: 0 8px 5px 0; */ /* FixIn: 9.5.4.8 */
660 }
661 /* Selectbox element in toolbar */
662 .visibility_container select optgroup{
663 color:#999;
664 vertical-align: middle;
665 font-style: italic;
666 font-weight: 400;
667 }
668 .visibility_container select option {
669 padding:5px;
670 font-weight: 600;
671 }
672 .visibility_container select optgroup option{
673 padding: 5px 20px;
674 color:#555;
675 font-weight: 600;
676 }
677 #wpbc_create_new_custom_form_name_fields {
678 width: 360px;
679 display:none;
680 }
681 @media (max-width: 399px) {
682 #wpbc_create_new_custom_form_name_fields {
683 width: 100%;
684 }
685 }
686 </style>
687 <?php
688 }
689
690
691
692 /**
693 * Add Custon JavaScript - for some specific settings options
694 * Executed After post content, after initial definition of settings, and possible definition after POST request.
695 *
696 * @param type $menu_slug
697 */
698 private function enqueue_js(){
699
700 // JavaScript //////////////////////////////////////////////////////////////
701
702 $js_script = '';
703
704
705 //Show|Hide grayed section
706 $js_script .= "
707 if ( ! jQuery('#import_gcal_booking_gcal_auto_import_is_active').is(':checked') ) {
708 jQuery('.wpbc_tr_auto_import').addClass('hidden_items');
709 }
710 ";
711 // Hide|Show on Click Checkbox
712 $js_script .= " jQuery('#import_gcal_booking_gcal_auto_import_is_active').on( 'change', function(){
713 if ( this.checked ) {
714 jQuery('.wpbc_tr_auto_import').removeClass('hidden_items');
715 } else {
716 jQuery('.wpbc_tr_auto_import').addClass('hidden_items');
717 }
718 } ); ";
719 // F R O M
720 $js_script .= "
721 if ( jQuery('#import_gcal_booking_gcal_events_from').val() != 'date' ) {
722 jQuery('.wpbc_tr_from_offset .wpbc_offset_value').removeClass('hidden_items');
723 jQuery('.wpbc_tr_from_offset .wpbc_offset_datetime').addClass('hidden_items');
724 } else {
725 jQuery('.wpbc_tr_from_offset .wpbc_offset_value').addClass('hidden_items');
726 jQuery('.wpbc_tr_from_offset .wpbc_offset_datetime').removeClass('hidden_items');
727 }
728 ";
729 // On select option in selectbox
730 $js_script .= " jQuery('#import_gcal_booking_gcal_events_from').on( 'change', function(){
731 jQuery('#import_gcal_booking_gcal_events_from_offset').val('');
732 if ( jQuery(this).val() != 'date' ){
733 jQuery('.wpbc_tr_from_offset .wpbc_offset_value').removeClass('hidden_items');
734 jQuery('.wpbc_tr_from_offset .wpbc_offset_datetime').addClass('hidden_items');
735 } else {
736 jQuery('.wpbc_tr_from_offset .wpbc_offset_value').addClass('hidden_items');
737 jQuery('.wpbc_tr_from_offset .wpbc_offset_datetime').removeClass('hidden_items');
738 }
739 } ); ";
740 // U n t i l
741 $js_script .= "
742 if ( jQuery('#import_gcal_booking_gcal_events_until').val() != 'date' ) {
743 jQuery('.wpbc_tr_until_offset .wpbc_offset_value').removeClass('hidden_items');
744 jQuery('.wpbc_tr_until_offset .wpbc_offset_datetime').addClass('hidden_items');
745 } else {
746 jQuery('.wpbc_tr_until_offset .wpbc_offset_value').addClass('hidden_items');
747 jQuery('.wpbc_tr_until_offset .wpbc_offset_datetime').removeClass('hidden_items');
748 }
749 ";
750 // On select option in selectbox
751 $js_script .= " jQuery('#import_gcal_booking_gcal_events_until').on( 'change', function(){
752 jQuery('#import_gcal_booking_gcal_events_until_offset').val('');
753 if ( jQuery(this).val() != 'date' ){
754 jQuery('.wpbc_tr_until_offset .wpbc_offset_value').removeClass('hidden_items');
755 jQuery('.wpbc_tr_until_offset .wpbc_offset_datetime').addClass('hidden_items');
756 } else {
757 jQuery('.wpbc_tr_until_offset .wpbc_offset_value').addClass('hidden_items');
758 jQuery('.wpbc_tr_until_offset .wpbc_offset_datetime').removeClass('hidden_items');
759 }
760 } ); ";
761
762
763 // // Hide|Show on Click Radion
764 // $js_script .= " jQuery('input[name=\"paypal_pro_hosted_solution\"]').on( 'change', function(){
765 // jQuery('.wpbc_sub_settings_paypal_account_type').addClass('hidden_items');
766 // if ( jQuery('#paypal_type_standard').is(':checked') ) {
767 // jQuery('.wpbc_sub_settings_paypal_standard').removeClass('hidden_items');
768 // } else {
769 // jQuery('.wpbc_sub_settings_paypal_pro_hosted').removeClass('hidden_items');
770 // }
771 // } ); ";
772
773 ////////////////////////////////////////////////////////////////////////
774
775
776 // Eneque JS to the footer of the page
777 wpbc_enqueue_js( $js_script );
778 }
779
780 // </editor-fold>
781
782 }
783 add_action('wpbc_menu_created', array( new WPBC_Page_SettingsImportGCal() , '__construct') ); // Executed after creation of Menu
784
785
786 /**
787 * Override fields array of Settings page, AFTER saving to DB. Some fields have to have different Values.
788 * Set here values for our pseudo-options, after saving to DB
789 * Because they was not overloading during this saving
790 *
791 * @param array $fields
792 * @param string $page_id
793 * @return array - fields
794 */
795 function wpbc_fields_after_saving_to_db__import_gcal( $fields, $page_id ) {
796
797 if ( $page_id == 'import_gcal' ) { // Check our API ID relative saving of this settings page
798
799 // Update Cron //FixIn: 7.0.1.9
800 if ( $fields['booking_gcal_auto_import_is_active']['value'] == 'On' ) {
801
802 $booking_gcal_auto_import_time = $fields['booking_gcal_auto_import_time']['value'];
803
804 if ( false !== strpos( $booking_gcal_auto_import_time, 'm' ) ) {
805
806 $booking_gcal_auto_import_time = str_replace( array( 'm', 'd' ), '', $booking_gcal_auto_import_time );
807 $booking_gcal_auto_import_time = intval( $booking_gcal_auto_import_time );
808 $time_dimension = 'm';
809
810 } else if ( false !== strpos( $booking_gcal_auto_import_time, 'd' ) ) {
811 $booking_gcal_auto_import_time = str_replace( array( 'm', 'd' ), '', $booking_gcal_auto_import_time );
812 $booking_gcal_auto_import_time = intval( $booking_gcal_auto_import_time );
813 $time_dimension = 'd';
814
815 } else { // Old hours
816
817 $booking_gcal_auto_import_time = intval( $booking_gcal_auto_import_time );
818 $time_dimension = 'h';
819 }
820
821
822 update_bk_option( 'booking_gcal_auto_import_time', $fields['booking_gcal_auto_import_time']['value'] );
823
824 // add
825 WPBC()->cron->update( 'wpbc_import_gcal' , array(
826 'action' => array( 'wpbc_silent_import_all_events' ) // Action and parameters
827 , 'start_time' => (time()-1) // Now
828 , 'last_execution' => time() // Set last time execution
829 , 'recurrence' => intval( $booking_gcal_auto_import_time ) // Set time value
830 , 'time_dimension' => $time_dimension // 'h' - hours, 'm' - minutes, 'd' - days
831 ) );
832 } else {
833 WPBC()->cron->delete( 'wpbc_import_gcal' ); // delete
834 }
835
836 }
837 return $fields;
838 }
839 add_filter('wpbc_fields_after_saving_to_db', 'wpbc_fields_after_saving_to_db__import_gcal', 10, 2);