PluginProbe
Booking Calendar / 10.10
Booking Calendar v10.10
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 10.11.3 All 202 releases
booking / core / admin / page-ics-general.php

page-ics-general.php in Booking Calendar 10.10, at core/admin/page-ics-general.php

699 lines 31.9 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 * @menu Booking > Settings > (Sync) General page
5 * @category Settings API
6 * @author wpdevelop
7 *
8 * @web-site https://wpbookingcalendar.com/
9 * @email info@wpbookingcalendar.com
10 * @modified 2017-12-18
11 *
12 */
13
14 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
15
16 // FixIn: 8.1.1.10.
17 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
18 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
19
20
21 /** API for Settings Page */
22 class WPBC_API_SettingsGeneralSync extends WPBC_Settings_API {
23
24 /**
25 * Settings API Constructor
26 * During creation, system try to load values from DB, if exist.
27 *
28 * @param type $id - "Pure Name"
29 */
30 public function __construct( $id, $init_fields_values = array(), $options = array() ) {
31
32 // This configuration meaning that options will be saved separately, without $id of this CLASS, just by using names of fields -- update_bk_option( $this->options['db_prefix_option'] . $field_name , $field_value );
33 $default_options = array(
34 'db_prefix_option' => ''
35 , 'db_saving_type' => 'separate'
36 );
37 // separate_prefix: update_bk_option( $this->options['db_prefix_option'] . $settings_id . '_' . $field_name , $value );
38 $options = wp_parse_args( $options, $default_options );
39
40 /**
41 * Activation and deactivation of these options already done at the wpbc-gcal.php file
42
43 // add_bk_action( 'wpbc_other_versions_activation', array( $this, 'activate' ) ); // Activate
44 // add_bk_action( 'wpbc_other_versions_deactivation', array( $this, 'deactivate' ) ); // Deactivate
45 */
46
47 parent::__construct( $id, $options, $init_fields_values ); // Define ID of Setting page and options
48 }
49
50
51
52 /** Define settings Fields */
53 public function init_settings_fields() {
54
55 $this->fields = array();
56
57 // TODO:
58 // add_bk_option( 'booking_gcal_events_form_fields', 'a:3:{s:5:"title";s:9:"text^name";s:11:"description";s:12:"text^details";s:5:"where";s:5:"text^";}');
59
60 // Problem with email^email field, previously its was text^email and problem with textarea^details field, previously its was text^details
61
62
63 ////////////////////////////////////////////////////////////////////////
64 // Get form fields from different forms in the paid versions
65 ////////////////////////////////////////////////////////////////////////
66 $options = array();
67 $options[ 'text^' ] = __('None' ,'booking');
68
69 $booking_forms = wpbc_get__in_all_forms__field_names_arr();
70
71 foreach ( $booking_forms as $single_booking_form ) {
72
73 //OPTGROUP - Open
74 $options[ $single_booking_form['name'] ] = array(
75 'title' => ucfirst( trim( $single_booking_form['name'] ) )
76 , 'optgroup' => true
77 , 'close' => false );
78
79 $field_listing = $single_booking_form['listing'];
80 for ( $i = 0; $i < $single_booking_form['num']; $i++ ) {
81 $options[ ( ( trim( $single_booking_form['name'] ) != 'standard' ) ? trim( $single_booking_form['name'] ) . '^' : '' ) .
82 trim( $single_booking_form['listing']['fields_type'][$i] ). '^' . trim( $single_booking_form['listing']['fields'][$i] )
83 ] = ( trim( $single_booking_form['listing']['labels'][$i] ) );
84 }
85
86 //OPTGROUP - Close
87 $options[ $single_booking_form['name'] . '_close' ] = array(
88 'title' => $single_booking_form['name'] // ucfirst( trim( $option_group_name ) )
89 , 'optgroup' => true
90 , 'close' => true );
91 }
92 ////////////////////////////////////////////////////////////////////////
93
94
95
96 // booking_gcal_events_form_fields - !!! real name of option to save. This option have to be skipped during saving and during loading need some actions.
97 $this->fields['booking_gcal_events_form_fields_title'] = array(
98 'type' => 'select'
99 , 'default' => ''
100 , 'title' => __('Event Title', 'booking')
101 /* translators: 1: Open HTML strong symbol, 2: Close HTML strong symbol. */
102 , 'description' => sprintf( __( 'Select field for assigning to %1$sevent property%2$s' ,'booking'), '<b>', '</b>' )
103 , 'description_tag' => 'span'
104 , 'css' => ''
105 , 'options' => $options
106 , 'group' => 'events_fields'
107 );
108 $this->fields['booking_gcal_events_form_fields_description'] = array(
109 'type' => 'select'
110 , 'default' => ''
111 , 'title' => __('Event Description (optional field)' ,'booking')
112 /* translators: 1: Open HTML strong symbol, 2: Close HTML strong symbol. */
113 , 'description' => sprintf( __( 'Select field for assigning to %1$sevent property%2$s' ,'booking'), '<b>', '</b>' )
114 , 'description_tag' => 'span'
115 , 'css' => ''
116 , 'options' => $options
117 , 'group' => 'events_fields'
118 );
119 $this->fields['booking_gcal_events_form_fields_where'] = array(
120 'type' => 'select'
121 , 'default' => ''
122 , 'title' => __('Location' ,'booking')
123 /* translators: 1: Open HTML strong symbol, 2: Close HTML strong symbol. */
124 , 'description' => sprintf( __( 'Select field for assigning to %1$sevent property%2$s' ,'booking'), '<b>', '</b>' )
125 , 'description_tag' => 'span'
126 , 'css' => ''
127 , 'options' => $options
128 , 'group' => 'events_fields'
129 );
130 ////////////////////////////////////////////////////////////////////////
131
132
133 $options = array();
134 $options[''] = __('Default' ,'booking');
135
136 // structure: $wpbc_booking_region_cities_list["Pacific"]["Fiji"] = "Fiji";
137 $wpbc_booking_region_cities_list = wpbc_get_booking_region_cities_list(); // FixIn: 8.9.4.9.
138
139 foreach ( $wpbc_booking_region_cities_list as $region => $region_cities) {
140
141 //OPTGROUP - Open
142 $options[ $region ] = array(
143 'title' => ucfirst( trim( $region ) )
144 , 'optgroup' => true
145 , 'close' => false );
146
147 foreach ($region_cities as $city_key => $city_title) {
148
149 $options[ trim( $region .'/'. $city_key ) ] = ( trim( $city_title ) );
150 }
151
152 //OPTGROUP - Close
153 $options[ $region . '_close' ] = array(
154 'title' => $region // ucfirst( trim( $option_group_name ) )
155 , 'optgroup' => true
156 , 'close' => true );
157 }
158 $this->fields['booking_gcal_timezone'] = array(
159 'type' => 'select'
160 , 'default' => ''
161 , 'title' => __('Timezone', 'booking')
162 , 'description' => __('Select a city in your required timezone, if you are having problems with dates and times.' ,'booking')
163 , 'description_tag' => 'p'
164 , 'css' => ''
165 , 'options' => $options
166 , 'group' => 'general'
167 );
168
169 // FixIn: 9.5.4.1.
170 $this->fields['booking_ics_import_append_checkout_day'] = array(
171 'type' => 'checkbox'
172 , 'default' => 'On'
173 , 'title' => __('Append check out day', 'booking')
174 , 'label' => __('Append one check out day, during import .ics feeds' ,'booking')
175 , 'description' => ''
176 , 'group' => 'import_advanced'
177 );
178
179 if ( class_exists( 'wpdev_bk_biz_s' ) ) {
180 // FixIn: 8.1.3.29.
181 $this->fields['booking_ics_import_add_change_over_time'] = array(
182 'type' => 'checkbox'
183 , 'default' => 'On'
184 , 'title' => __('Use check in/out time', 'booking')
185 , 'label' => __('Use check in/out time of plugin, during import .ics feeds' ,'booking')
186 , 'description' => ''
187 , 'group' => 'import_advanced'
188 );
189 // FixIn: 8.5.2.3.
190 $this->fields['booking_is_ics_export_only_approved'] = array(
191 'type' => 'checkbox'
192 , 'default' => 'Off'
193 , 'title' => __('Export only approved bookings', 'booking')
194 , 'label' => __('Enable of export only approved bookings in .ics feeds' ,'booking')
195 , 'description' => ''
196 , 'group' => 'export_advanced'
197 );
198
199 // FixIn: 8.8.3.19.
200 $this->fields['booking_is_ics_export_imported_bookings'] = array(
201 'type' => 'select'
202 , 'default' => ''
203 , 'title' => __('Export bookings type', 'booking')
204 , 'description' => __('Select which type of bookings to export' ,'booking')
205 , 'description_tag' => 'p'
206 , 'css' => ''
207 , 'options' => array (
208 '' => __('All bookings','booking'),
209 'plugin' => __('Bookings created in Booking Calendar','booking'),
210 'imported' => __('Imported bookings','booking'),
211 )
212 , 'group' => 'export_advanced'
213 );
214 }
215 // FixIn: 10.3.0.1.
216 $this->fields['booking_g_cal_export_no_data'] = array(
217 'type' => 'checkbox'
218 , 'default' => 'Off'
219 , 'title' => __('Remove Details in Google Calendar Export', 'booking')
220 , 'label' => __('Enable this option to exclude booking summary details when exporting to Google Calendar using the \'Add to Google Calendar\' button.' ,'booking')
221 , 'description' => ''
222 , 'group' => 'export_advanced'
223 );
224
225 // FixIn: 8.5.1.1.
226 /*
227 // FixIn: 8.4.7.1.
228 $this->fields['booking_ics_force_import'] = array(
229 'type' => 'checkbox'
230 , 'default' => 'Off'
231 , 'title' => __('Force import', 'booking')
232 , 'label' => __('Import bookings without checking, if such bookings already have been imported.' ,'booking')
233 , 'description' => ''
234 , 'group' => 'import_advanced'
235 );
236 /**/
237 //FixIn: 8.4.7.12 //FixIn: // FixIn: 9.1.2.6.
238 $this->fields['booking_ics_force_trash_before_import'] = array(
239 'type' => 'select'
240 , 'default' => 'Off'
241 , 'title' => __('Trash / delete all imported bookings before new import', 'booking')
242 , 'description' => __('Move all previously imported bookings to trash or permanently delete before new import bookings. Its can resolve issue of updating deleted and edited events in external sources. Its work only, if you are using one source (.ics feed) for importing into specific booking resource!' ,'booking')
243 , 'description_tag' => 'p'
244 , 'css' => ''
245 , 'options' => array ( // FixIn: 9.7.3.9.
246 'Off' => __( 'Do nothing', 'booking' ),
247 'On' => __( 'Trash imported bookings', 'booking' ),
248 'delete' => __( 'Permanently delete', 'booking' )
249 )
250 , 'group' => 'import_advanced'
251 );
252
253
254 $this->fields['booking_condition_import_only_new'] = array(
255 'type' => 'checkbox'
256 , 'default' => 'Off'
257 , 'title' => __( 'Import conditions', 'booking' )//__('Import only new events', 'booking')
258 , 'label' => '<strong>' . esc_html__( 'Import Only New Events', 'booking' ) . '</strong> - ' . __( 'Import only if the event has not been imported before.', 'booking' )
259 , 'description' => ''
260 , 'group' => 'import_advanced'
261 );
262 $this->fields['booking_condition_import_if_available'] = array(
263 'type' => 'checkbox'
264 , 'default' => 'Off'
265 , 'title' => ''//__('Import if dates available', 'booking')
266 , 'label' => '<strong>' . esc_html__( 'Import if Dates Available', 'booking' ) . '</strong> - ' . esc_html__( 'Import only if dates are available in the source calendar.', 'booking' )
267 , 'description' => ''
268 , 'group' => 'import_advanced'
269 );
270
271
272 ////////////////////////////////////////////////////////////////////////
273
274 }
275
276 }
277
278
279 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
280 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
281
282
283 /**
284 * Show Content
285 * Update Content
286 * Define Slug
287 * Define where to show
288 */
289 class WPBC_Page_SettingsGeneralSync extends WPBC_Page_Structure {
290
291 public $settings_api = false;
292
293
294 /**
295 * API - for Fields of this Settings Page
296 *
297 * @param array $init_fields_values - array of init form fields data - this array can ovveride "default" fields and loaded data.
298 * @return object API
299 */
300 public function get_api( $init_fields_values = array() ){
301
302 if ( $this->settings_api === false ) {
303 $this->settings_api = new WPBC_API_SettingsGeneralSync( 'general_sync' , $init_fields_values );
304 }
305 return $this->settings_api;
306 }
307
308
309 public function in_page() {
310 return 'wpbc-settings';
311 }
312
313
314 public function tabs() {
315
316 $tabs = array();
317
318 $tabs[ 'sync' ] = array(
319 'title' => __( 'Sync', 'booking') // Title of TAB
320 , 'page_title'=> __( 'Sync', 'booking') // Title of Page
321 , 'hint' => __('Import' ,'booking') . ' / ' . __('Export' ,'booking')
322 //, 'link' => '' // Can be skiped, then generated link based on Page and Tab tags. Or can be extenral link
323 //, 'position' => '' // 'left' || 'right' || ''
324 //, 'css_classes'=> '' // CSS class(es)
325 //, 'icon' => '' // Icon - link to the real PNG img
326 , 'font_icon' => 'wpbc_icn_sync_alt' // CSS definition of forn Icon
327 //, 'default' => false // Is this tab activated by default or not: true || false.
328 //, 'disabled' => false // Is this tab disbaled: true || false.
329 //, 'hided' => false // Is this tab hided: true || false.
330 , 'subtabs' => array()
331 );
332
333
334 $subtabs = array();
335
336 $subtabs[ 'general' ] = array(
337 'type' => 'subtab' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html'
338 , 'title' => __( 'General', 'booking' ) // Title of TAB
339 , 'page_title' => __( 'General Settings', 'booking' ) . ' - ' . __( 'Sync', 'booking' ) // Title of Page
340 , 'hint' => __( 'General Settings', 'booking' ) . ' - ' . __( 'Sync', 'booking' ) // Hint
341 , 'link' => '' // link
342 , 'position' => '' // 'left' || 'right' || ''
343 , 'css_classes' => '' // CSS class(es)
344 //, 'icon' => 'http://.../icon.png' // Icon - link to the real PNG img
345 //, 'font_icon' => 'wpbc_icn_mail_outline' // CSS definition of Font Icon
346 , 'header_font_icon' => 'wpbc_icn_sync_alt' // CSS definition of Font Icon // FixIn: 9.6.1.4.
347 , 'default' => true // Is this sub tab activated by default or not: true || false.
348 , 'disabled' => false // Is this sub tab deactivated: true || false.
349 , 'checkbox' => false // or definition array for specific checkbox: array( 'checked' => true, 'name' => 'feature1_active_status' ) //, 'checkbox' => array( 'checked' => $is_checked, 'name' => 'enabled_active_status' )
350 , 'content' => 'content' // Function to load as conten of this TAB
351 //, 'is_use_left_navigation' => true // We commented this line to have the vertical subline of menu
352 );
353
354 $tabs[ 'sync' ]['subtabs'] = $subtabs;
355
356
357 return $tabs;
358 }
359
360
361 /** Show Content of Settings page */
362 public function content() {
363
364 $this->css();
365
366 ////////////////////////////////////////////////////////////////////////
367 // Checking
368 ////////////////////////////////////////////////////////////////////////
369
370 do_action( 'wpbc_hook_settings_page_header', 'ics_general_settings' ); // Define Notices Section and show some static messages, if needed
371
372 if ( ! wpbc_is_mu_user_can_be_here('activated_user') ) return false; // Check if MU user activated, otherwise show Warning message.
373
374 // 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.
375
376
377
378 ////////////////////////////////////////////////////////////////////////
379 // Load Data
380 ////////////////////////////////////////////////////////////////////////
381
382 $this->get_api(); // Load fields Data from DB
383
384 /**
385 * O v e r l o a d some values for our pseudo options - during normal opening of page
386 * if we making saving, so we need to overload these options
387 * one more time
388 */
389 $booking_gcal_events_form_fields = get_bk_option( 'booking_gcal_events_form_fields');
390 $booking_gcal_events_form_fields = maybe_unserialize( $booking_gcal_events_form_fields );
391
392 if (isset($booking_gcal_events_form_fields['title']))
393 $this->get_api()->set_field_value( 'booking_gcal_events_form_fields_title', $booking_gcal_events_form_fields['title'] );
394
395 if (isset($booking_gcal_events_form_fields['description']))
396 $this->get_api()->set_field_value( 'booking_gcal_events_form_fields_description', $booking_gcal_events_form_fields['description'] );
397
398 if (isset($booking_gcal_events_form_fields['where']))
399 $this->get_api()->set_field_value( 'booking_gcal_events_form_fields_where', $booking_gcal_events_form_fields['where'] );
400
401 $this->get_api()->set_values_to_fields();
402
403
404 ////////////////////////////////////////////////////////////////////////
405 // S u b m i t Main Form
406 ////////////////////////////////////////////////////////////////////////
407
408 $submit_form_name = 'wpbc_general_sync'; // Define form name
409
410 // $this->get_api()->validated_form_id = $submit_form_name; // Define ID of Form for ability to validate fields (like required field) before submit.
411
412 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
413 if ( isset( $_POST['is_form_sbmitted_'. $submit_form_name ] ) ) {
414
415 // Nonce checking {Return false if invalid, 1 if generated between, 0-12 hours ago, 2 if generated between 12-24 hours ago. }
416 $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
417
418 // Save Changes
419 $this->update();
420 }
421
422 ////////////////////////////////////////////////////////////////////////
423 // JavaScript: Tooltips, Popover, Datepick (js & css)
424 ////////////////////////////////////////////////////////////////////////
425
426 echo '<span class="wpdevelop">';
427
428 wpbc_js_for_bookings_page();
429
430 echo '</span>';
431
432 ?><div class="clear" style="margin-bottom:0px;"></div><?php
433
434
435 ////////////////////////////////////////////////////////////////////////
436 // Content ////////////////////////////////////////////////////////////
437 ?>
438 <div class="clear" style="margin-bottom:0px;"></div>
439 <span class="metabox-holder">
440 <form name="<?php echo esc_attr( $submit_form_name ); ?>" id="<?php echo esc_attr( $submit_form_name ); ?>" action="" method="post" autocomplete="off">
441 <?php
442 // N o n c e field, and key for checking S u b m i t
443 wp_nonce_field( 'wpbc_settings_page_' . $submit_form_name );
444 ?><input type="hidden" name="is_form_sbmitted_<?php echo esc_attr( $submit_form_name ); ?>" id="is_form_sbmitted_<?php echo esc_attr( $submit_form_name ); ?>" value="1" /><?php
445 ?><div class="clear"></div><?php
446
447 ?><div class="clear" style="height:10px;"></div><?php
448
449
450 wpbc_open_meta_box_section( 'wpbc_settings_general_sync_events_general', __('General Settings' ,'booking') );
451
452 $this->get_api()->show( 'general' );
453
454 wpbc_close_meta_box_section();
455
456
457 wpbc_open_meta_box_section( 'wpbc_settings_general_sync_events_fields', __('Import' ,'booking') . ' > ' . __('Assign events fields to specific booking form field' ,'booking') );
458
459 $this->get_api()->show( 'events_fields' );
460
461 wpbc_close_meta_box_section();
462
463 // FixIn: 8.5.1.1.
464 // if ( class_exists( 'wpdev_bk_biz_s' ) ) {
465
466 wpbc_open_meta_box_section( 'wpbc_settings_general_sync_import', __( 'Import', 'booking' ) . ' ' . __( 'Advanced', 'booking' ) );
467
468 $this->get_api()->show( 'import_advanced' );
469
470 wpbc_close_meta_box_section();
471
472
473 wpbc_open_meta_box_section( 'wpbc_settings_general_sync_export', __( 'Export', 'booking' ) . ' ' . __( 'Advanced', 'booking' ) );
474
475 $this->get_api()->show( 'export_advanced' );
476
477 wpbc_close_meta_box_section();
478 // }
479 ?>
480
481 <div class="clear"></div>
482
483 <input type="submit" value="<?php esc_attr_e('Save Changes','booking'); ?>" class="button button-primary wpbc_submit_button" />
484 <?php
485
486 ?>
487 </form>
488 </span>
489 <?php
490
491 do_action( 'wpbc_hook_settings_page_footer', 'ics_general_settings' );
492
493 $this->enqueue_js();
494
495 }
496
497
498 /** Save Chanages */
499 public function update() {
500 // if ( function_exists( 'wpbc_general_sync__update') )
501 // wpbc_general_sync__update();
502
503 // Get Validated Email fields
504 $validated_fields = $this->get_api()->validate_post();
505
506 $validated_fields = apply_filters( 'wpbc_fields_before_saving_to_db__general_sync', $validated_fields ); //Hook for validated fields.
507
508 //debuge($validated_fields);
509
510 $this->get_api()->save_to_db( $validated_fields );
511
512 wpbc_show_changes_saved_message();
513 }
514
515
516 // <editor-fold defaultstate="collapsed" desc=" CSS & JS " >
517
518 /** CSS for this page */
519 private function css() {
520 ?>
521 <style type="text/css">
522 .wpbc_import_ics_bar .wpbc_import_btn,
523 .wpbc_import_ics_bar .wpbc_upload_btn{
524 float:left;
525 margin:9px 5px 10px 1px;
526
527 }
528 .wpbc_import_ics_bar .wpbc_import_div {
529 float:left;
530 width:70%;
531 }
532 .wpbc_import_ics_bar .wpbc_import_br_selection,
533 .wpbc_import_ics_bar .wpbc_import_url {
534 float:left;
535 width:28%;
536 height: 2em;
537 padding: 2px;
538 border-radius: 0;
539 margin:10px 5px 10px 1px;
540 }
541 .wpbc_import_ics_bar .wpbc_import_url {
542 width:70%;
543 padding: 2px 5px;
544 }
545 .wpbc_system_info_log {
546 font-size: 11px;
547 line-height: 1.5em;
548 border: 2px dashed #e85;
549 padding: 5px 20px;
550 display: none;
551 }
552 /**********************************************************************************************************/
553 .wpbc-help-message {
554 border:none;
555 }
556 /* toolbar fix */
557 .wpdevelop .visibility_container .control-group {
558 margin: 2px 8px 3px 0; /* margin: 0 8px 5px 0; */ /* FixIn: 9.5.4.8 */
559 }
560 /* Selectbox element in toolbar */
561 .visibility_container select optgroup{
562 color:#999;
563 vertical-align: middle;
564 font-style: italic;
565 font-weight: 400;
566 }
567 .visibility_container select option {
568 padding:5px;
569 font-weight: 600;
570 }
571 .visibility_container select optgroup option{
572 padding: 5px 20px;
573 color:#555;
574 font-weight: 600;
575 }
576 #wpbc_create_new_custom_form_name_fields {
577 width: 360px;
578 display:none;
579 }
580 @media (max-width: 782px) {
581 .wpbc_import_ics_bar .wpbc_import_br_selection,
582 .wpbc_import_ics_bar .wpbc_import_div {
583 float:none;
584 width:100%;
585 }
586 }
587 @media (max-width: 399px) {
588 #wpbc_create_new_custom_form_name_fields {
589 width: 100%;
590 }
591 }
592 </style>
593 <?php
594 }
595
596
597
598 /**
599 * Add Custon JavaScript - for some specific settings options
600 * Executed After post content, after initial definition of settings, and possible definition after POST request.
601 *
602 * @param type $menu_slug
603 */
604 private function enqueue_js(){
605
606 // JavaScript //////////////////////////////////////////////////////////////
607
608 $js_script = '';
609
610 // //Show|Hide grayed section
611 // $js_script .= "
612 // if ( ! jQuery('#ics_general_booking_gcal_auto_import_is_active').is(':checked') ) {
613 // jQuery('.wpbc_tr_auto_import').addClass('hidden_items');
614 // }
615 // ";
616
617 // // Hide|Show on Click Radion
618 // $js_script .= " jQuery('input[name=\"paypal_pro_hosted_solution\"]').on( 'change', function(){
619 // jQuery('.wpbc_sub_settings_paypal_account_type').addClass('hidden_items');
620 // if ( jQuery('#paypal_type_standard').is(':checked') ) {
621 // jQuery('.wpbc_sub_settings_paypal_standard').removeClass('hidden_items');
622 // } else {
623 // jQuery('.wpbc_sub_settings_paypal_pro_hosted').removeClass('hidden_items');
624 // }
625 // } ); ";
626
627 ////////////////////////////////////////////////////////////////////////
628
629
630 // Eneque JS to the footer of the page
631 wpbc_enqueue_js( $js_script );
632 }
633
634 // </editor-fold>
635
636 }
637 add_action('wpbc_menu_created', array( new WPBC_Page_SettingsGeneralSync() , '__construct') ); // Executed after creation of Menu
638
639
640 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
641 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
642
643
644 /**
645 * Validate some fields during saving to DB
646 * Skip saving some pseudo options, instead of that creare new real option.
647 *
648 * @param array $validated_fields
649 * @return type
650 */
651 function wpbc_fields_before_saving_to_db__general_sync( $validated_fields ) {
652
653 // Set new option based on pseudo options
654 $validated_fields['booking_gcal_events_form_fields'] = array(
655 'title' => $validated_fields['booking_gcal_events_form_fields_title']
656 , 'description' => $validated_fields['booking_gcal_events_form_fields_description']
657 , 'where' => $validated_fields['booking_gcal_events_form_fields_where']
658 );
659 // Unset several pseudo options.
660 unset( $validated_fields['booking_gcal_events_form_fields_title'] );
661 unset( $validated_fields['booking_gcal_events_form_fields_description'] );
662 unset( $validated_fields['booking_gcal_events_form_fields_where'] );
663
664 return $validated_fields;
665 }
666 add_filter('wpbc_fields_before_saving_to_db__general_sync', 'wpbc_fields_before_saving_to_db__general_sync');
667
668
669
670 /**
671 * Override fields array of Settings page, AFTER saving to DB. Some fields have to have different Values.
672 * Set here values for our pseudo-options, after saving to DB
673 * Because they was not overloading during this saving
674 *
675 * @param array $fields
676 * @param string $page_id
677 * @return array - fields
678 */
679 function wpbc_fields_after_saving_to_db__general_sync( $fields, $page_id ) {
680
681 if ( $page_id == 'general_sync' ) { // Check our API ID relative saving of this settings page
682
683 $booking_gcal_events_form_fields = get_bk_option( 'booking_gcal_events_form_fields');
684 $booking_gcal_events_form_fields = maybe_unserialize( $booking_gcal_events_form_fields );
685
686 if (isset($booking_gcal_events_form_fields['title']))
687 $fields[ 'booking_gcal_events_form_fields_title' ]['value'] = $booking_gcal_events_form_fields['title'];
688
689 if (isset($booking_gcal_events_form_fields['description']))
690 $fields[ 'booking_gcal_events_form_fields_description' ]['value'] = $booking_gcal_events_form_fields['description'];
691
692 if (isset($booking_gcal_events_form_fields['where']))
693 $fields[ 'booking_gcal_events_form_fields_where' ]['value'] = $booking_gcal_events_form_fields['where'];
694
695 }
696 return $fields;
697 }
698 add_filter('wpbc_fields_after_saving_to_db', 'wpbc_fields_after_saving_to_db__general_sync', 10, 2);
699