PluginProbe
Booking Calendar / 11.8
Booking Calendar v11.8
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 11.8, at core/admin/page-ics-general.php

707 lines 32.2 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 $this->fields['booking_ics_import_append_extra_checkout_day'] = array(
180 'type' => 'checkbox'
181 , 'default' => 'Off'
182 , 'title' => __('Append extra day after imported checkout day', 'booking')
183 , 'label' => __('Append one extra day after the imported check out day during import .ics feeds.' ,'booking')
184 , 'description' => __('This option works together with "Append check out day" and is useful only if you need to block one additional day after the checkout date from the imported calendar.' ,'booking')
185 , 'group' => 'import_advanced'
186 );
187
188 if ( class_exists( 'wpdev_bk_biz_s' ) ) {
189 // FixIn: 8.1.3.29.
190 $this->fields['booking_ics_import_add_change_over_time'] = array(
191 'type' => 'checkbox'
192 , 'default' => 'On'
193 , 'title' => __('Use check in/out time', 'booking')
194 , 'label' => __('Use check in/out time of plugin, during import .ics feeds' ,'booking')
195 , 'description' => ''
196 , 'group' => 'import_advanced'
197 );
198 // FixIn: 8.5.2.3.
199 $this->fields['booking_is_ics_export_only_approved'] = array(
200 'type' => 'checkbox'
201 , 'default' => 'Off'
202 , 'title' => __('Export only approved bookings', 'booking')
203 , 'label' => __('Enable of export only approved bookings in .ics feeds' ,'booking')
204 , 'description' => ''
205 , 'group' => 'export_advanced'
206 );
207
208 // FixIn: 8.8.3.19.
209 $this->fields['booking_is_ics_export_imported_bookings'] = array(
210 'type' => 'select'
211 , 'default' => ''
212 , 'title' => __('Export bookings type', 'booking')
213 , 'description' => __('Select which type of bookings to export' ,'booking')
214 , 'description_tag' => 'p'
215 , 'css' => ''
216 , 'options' => array (
217 '' => __('All bookings','booking'),
218 'plugin' => __('Bookings created in Booking Calendar','booking'),
219 'imported' => __('Imported bookings','booking'),
220 )
221 , 'group' => 'export_advanced'
222 );
223 }
224 // FixIn: 10.3.0.1.
225 $this->fields['booking_g_cal_export_no_data'] = array(
226 'type' => 'checkbox'
227 , 'default' => 'Off'
228 , 'title' => __('Remove Details in Google Calendar Export', 'booking')
229 , 'label' => __('Enable this option to exclude booking summary details when exporting to Google Calendar using the \'Add to Google Calendar\' button.' ,'booking')
230 , 'description' => ''
231 , 'group' => 'export_advanced'
232 );
233
234 // FixIn: 8.5.1.1.
235 /*
236 // FixIn: 8.4.7.1.
237 $this->fields['booking_ics_force_import'] = array(
238 'type' => 'checkbox'
239 , 'default' => 'Off'
240 , 'title' => __('Force import', 'booking')
241 , 'label' => __('Import bookings without checking, if such bookings already have been imported.' ,'booking')
242 , 'description' => ''
243 , 'group' => 'import_advanced'
244 );
245 /**/
246 //FixIn: 8.4.7.12 //FixIn: // FixIn: 9.1.2.6.
247 $this->fields['booking_ics_force_trash_before_import'] = array(
248 'type' => 'select'
249 , 'default' => 'Off'
250 , 'title' => __('Trash / delete all imported bookings before new import', 'booking')
251 , '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')
252 , 'description_tag' => 'p'
253 , 'css' => ''
254 , 'options' => array ( // FixIn: 9.7.3.9.
255 'Off' => __( 'Do nothing', 'booking' ),
256 'On' => __( 'Trash imported bookings', 'booking' ),
257 'delete' => __( 'Permanently delete', 'booking' )
258 )
259 , 'group' => 'import_advanced'
260 );
261
262
263 $this->fields['booking_condition_import_only_new'] = array(
264 'type' => 'checkbox'
265 , 'default' => 'Off'
266 , 'title' => __( 'Import conditions', 'booking' )//__('Import only new events', 'booking')
267 , 'label' => '<strong>' . esc_html__( 'Import Only New Events', 'booking' ) . '</strong> - ' . __( 'Import only if the event has not been imported before.', 'booking' )
268 , 'description' => ''
269 , 'group' => 'import_advanced'
270 );
271 $this->fields['booking_condition_import_if_available'] = array(
272 'type' => 'checkbox'
273 , 'default' => 'Off'
274 , 'title' => ''//__('Import if dates available', 'booking')
275 , 'label' => '<strong>' . esc_html__( 'Import if Dates Available', 'booking' ) . '</strong> - ' . esc_html__( 'Import only if dates are available in the source calendar.', 'booking' )
276 , 'description' => ''
277 , 'group' => 'import_advanced'
278 );
279
280
281 ////////////////////////////////////////////////////////////////////////
282
283 }
284
285 }
286
287
288 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
289 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
290
291
292 /**
293 * Show Content
294 * Update Content
295 * Define Slug
296 * Define where to show
297 */
298 class WPBC_Page_SettingsGeneralSync extends WPBC_Page_Structure {
299
300 public $settings_api = false;
301
302
303 /**
304 * API - for Fields of this Settings Page
305 *
306 * @param array $init_fields_values - array of init form fields data - this array can ovveride "default" fields and loaded data.
307 * @return object API
308 */
309 public function get_api( $init_fields_values = array() ){
310
311 if ( $this->settings_api === false ) {
312 $this->settings_api = new WPBC_API_SettingsGeneralSync( 'general_sync' , $init_fields_values );
313 }
314 return $this->settings_api;
315 }
316
317
318 public function in_page() {
319 return 'wpbc-settings';
320 }
321
322
323 public function tabs() {
324
325 $tabs = array();
326
327 $tabs[ 'sync' ] = array(
328 'title' => __( 'Sync', 'booking') // Title of TAB
329 , 'page_title'=> __( 'Sync', 'booking') // Title of Page
330 , 'hint' => __('Import' ,'booking') . ' / ' . __('Export' ,'booking')
331 //, 'link' => '' // Can be skiped, then generated link based on Page and Tab tags. Or can be extenral link
332 //, 'position' => '' // 'left' || 'right' || ''
333 //, 'css_classes'=> '' // CSS class(es)
334 //, 'icon' => '' // Icon - link to the real PNG img
335 , 'font_icon' => 'wpbc_icn_sync_alt' // CSS definition of forn Icon
336 //, 'default' => false // Is this tab activated by default or not: true || false.
337 //, 'disabled' => false // Is this tab disbaled: true || false.
338 //, 'hided' => false // Is this tab hided: true || false.
339 , 'subtabs' => array()
340 );
341
342
343 $subtabs = array();
344
345 $subtabs[ 'general' ] = array(
346 'type' => 'subtab' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html'
347 , 'title' => __( 'Sync Options', 'booking' ) // Title of TAB
348 , 'page_title' => __( 'Sync Options', 'booking' ) // Title of Page
349 , 'hint' => __( 'Configure import/export rules, timezones, and which fields to include in sync operations.', 'booking' ) // Hint.
350 , 'link' => '' // link
351 , 'position' => '' // 'left' || 'right' || ''
352 , 'css_classes' => '' // CSS class(es)
353 //, 'icon' => 'http://.../icon.png' // Icon - link to the real PNG img
354 , 'font_icon' => 'wpbc_icn_cloud_sync'
355 , 'default' => true // Is this sub tab activated by default or not: true || false.
356 , 'disabled' => false // Is this sub tab deactivated: true || false.
357 , 'checkbox' => false // or definition array for specific checkbox: array( 'checked' => true, 'name' => 'feature1_active_status' ) //, 'checkbox' => array( 'checked' => $is_checked, 'name' => 'enabled_active_status' )
358 , 'content' => 'content' // Function to load as conten of this TAB
359
360 );
361
362 $tabs[ 'sync' ]['subtabs'] = $subtabs;
363
364
365 return $tabs;
366 }
367
368
369 /** Show Content of Settings page */
370 public function content() {
371
372 $this->css();
373
374 ////////////////////////////////////////////////////////////////////////
375 // Checking
376 ////////////////////////////////////////////////////////////////////////
377
378 do_action( 'wpbc_hook_settings_page_header', 'ics_general_settings' ); // Define Notices Section and show some static messages, if needed
379
380 if ( ! wpbc_is_mu_user_can_be_here('activated_user') ) return false; // Check if MU user activated, otherwise show Warning message.
381
382 // 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.
383
384
385
386 ////////////////////////////////////////////////////////////////////////
387 // Load Data
388 ////////////////////////////////////////////////////////////////////////
389
390 $this->get_api(); // Load fields Data from DB
391
392 /**
393 * O v e r l o a d some values for our pseudo options - during normal opening of page
394 * if we making saving, so we need to overload these options
395 * one more time
396 */
397 $booking_gcal_events_form_fields = get_bk_option( 'booking_gcal_events_form_fields');
398 $booking_gcal_events_form_fields = maybe_unserialize( $booking_gcal_events_form_fields );
399
400 if (isset($booking_gcal_events_form_fields['title']))
401 $this->get_api()->set_field_value( 'booking_gcal_events_form_fields_title', $booking_gcal_events_form_fields['title'] );
402
403 if (isset($booking_gcal_events_form_fields['description']))
404 $this->get_api()->set_field_value( 'booking_gcal_events_form_fields_description', $booking_gcal_events_form_fields['description'] );
405
406 if (isset($booking_gcal_events_form_fields['where']))
407 $this->get_api()->set_field_value( 'booking_gcal_events_form_fields_where', $booking_gcal_events_form_fields['where'] );
408
409 $this->get_api()->set_values_to_fields();
410
411
412 ////////////////////////////////////////////////////////////////////////
413 // S u b m i t Main Form
414 ////////////////////////////////////////////////////////////////////////
415
416 $submit_form_name = 'wpbc_general_sync'; // Define form name
417
418 // $this->get_api()->validated_form_id = $submit_form_name; // Define ID of Form for ability to validate fields (like required field) before submit.
419
420 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
421 if ( isset( $_POST['is_form_sbmitted_'. $submit_form_name ] ) ) {
422
423 // Nonce checking {Return false if invalid, 1 if generated between, 0-12 hours ago, 2 if generated between 12-24 hours ago. }
424 $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
425
426 // Save Changes
427 $this->update();
428 }
429
430 ////////////////////////////////////////////////////////////////////////
431 // JavaScript: Tooltips, Popover, Datepick (js & css)
432 ////////////////////////////////////////////////////////////////////////
433
434 echo '<span class="wpdevelop">';
435
436 wpbc_js_for_bookings_page();
437
438 echo '</span>';
439
440 ?><div class="clear" style="margin-bottom:0px;"></div><?php
441
442
443 ////////////////////////////////////////////////////////////////////////
444 // Content ////////////////////////////////////////////////////////////
445 ?>
446 <div class="clear" style="margin-bottom:0px;"></div>
447 <span class="metabox-holder">
448 <form name="<?php echo esc_attr( $submit_form_name ); ?>" id="<?php echo esc_attr( $submit_form_name ); ?>" action="" method="post" autocomplete="off">
449 <?php
450 // N o n c e field, and key for checking S u b m i t
451 wp_nonce_field( 'wpbc_settings_page_' . $submit_form_name );
452 ?><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
453 ?><div class="clear"></div><?php
454
455 ?><div class="clear" style="height:10px;"></div><?php
456
457
458 wpbc_open_meta_box_section( 'wpbc_settings_general_sync_events_general', __('General Settings' ,'booking') );
459
460 $this->get_api()->show( 'general' );
461
462 wpbc_close_meta_box_section();
463
464
465 wpbc_open_meta_box_section( 'wpbc_settings_general_sync_events_fields', __('Import' ,'booking') . ' > ' . __('Assign events fields to specific booking form field' ,'booking') );
466
467 $this->get_api()->show( 'events_fields' );
468
469 wpbc_close_meta_box_section();
470
471 // FixIn: 8.5.1.1.
472 // if ( class_exists( 'wpdev_bk_biz_s' ) ) {
473
474 wpbc_open_meta_box_section( 'wpbc_settings_general_sync_import', __( 'Import', 'booking' ) . ' ' . __( 'Advanced', 'booking' ) );
475
476 $this->get_api()->show( 'import_advanced' );
477
478 wpbc_close_meta_box_section();
479
480
481 wpbc_open_meta_box_section( 'wpbc_settings_general_sync_export', __( 'Export', 'booking' ) . ' ' . __( 'Advanced', 'booking' ) );
482
483 $this->get_api()->show( 'export_advanced' );
484
485 wpbc_close_meta_box_section();
486 // }
487 ?>
488
489 <div class="clear"></div>
490
491 <input type="submit" value="<?php esc_attr_e('Save Changes','booking'); ?>" class="button button-primary wpbc_submit_button" />
492 <?php
493
494 ?>
495 </form>
496 </span>
497 <?php
498
499 do_action( 'wpbc_hook_settings_page_footer', 'ics_general_settings' );
500
501 $this->enqueue_js();
502
503 }
504
505
506 /** Save Chanages */
507 public function update() {
508 // if ( function_exists( 'wpbc_general_sync__update') )
509 // wpbc_general_sync__update();
510
511 // Get Validated Email fields
512 $validated_fields = $this->get_api()->validate_post();
513
514 $validated_fields = apply_filters( 'wpbc_fields_before_saving_to_db__general_sync', $validated_fields ); //Hook for validated fields.
515
516 //debuge($validated_fields);
517
518 $this->get_api()->save_to_db( $validated_fields );
519
520 wpbc_show_changes_saved_message();
521 }
522
523
524 // <editor-fold defaultstate="collapsed" desc=" CSS & JS " >
525
526 /** CSS for this page */
527 private function css() {
528 ?>
529 <style type="text/css">
530 .wpbc_import_ics_bar .wpbc_import_btn,
531 .wpbc_import_ics_bar .wpbc_upload_btn{
532 float:left;
533 margin:9px 5px 10px 1px;
534
535 }
536 .wpbc_import_ics_bar .wpbc_import_div {
537 float:left;
538 width:70%;
539 }
540 .wpbc_import_ics_bar .wpbc_import_br_selection,
541 .wpbc_import_ics_bar .wpbc_import_url {
542 float:left;
543 width:28%;
544 height: 2em;
545 padding: 2px;
546 border-radius: 0;
547 margin:10px 5px 10px 1px;
548 }
549 .wpbc_import_ics_bar .wpbc_import_url {
550 width:70%;
551 padding: 2px 5px;
552 }
553 .wpbc_system_info_log {
554 font-size: 11px;
555 line-height: 1.5em;
556 border: 2px dashed #e85;
557 padding: 5px 20px;
558 display: none;
559 }
560 /**********************************************************************************************************/
561 .wpbc-help-message {
562 border:none;
563 }
564 /* toolbar fix */
565 .wpdevelop .visibility_container .control-group {
566 margin: 2px 8px 3px 0; /* margin: 0 8px 5px 0; */ /* FixIn: 9.5.4.8 */
567 }
568 /* Selectbox element in toolbar */
569 .visibility_container select optgroup{
570 color:#999;
571 vertical-align: middle;
572 font-style: italic;
573 font-weight: 400;
574 }
575 .visibility_container select option {
576 padding:5px;
577 font-weight: 600;
578 }
579 .visibility_container select optgroup option{
580 padding: 5px 20px;
581 color:#555;
582 font-weight: 600;
583 }
584 #wpbc_create_new_custom_form_name_fields {
585 width: 360px;
586 display:none;
587 }
588 @media (max-width: 782px) {
589 .wpbc_import_ics_bar .wpbc_import_br_selection,
590 .wpbc_import_ics_bar .wpbc_import_div {
591 float:none;
592 width:100%;
593 }
594 }
595 @media (max-width: 399px) {
596 #wpbc_create_new_custom_form_name_fields {
597 width: 100%;
598 }
599 }
600 </style>
601 <?php
602 }
603
604
605
606 /**
607 * Add Custon JavaScript - for some specific settings options
608 * Executed After post content, after initial definition of settings, and possible definition after POST request.
609 *
610 * @param type $menu_slug
611 */
612 private function enqueue_js(){
613
614 // JavaScript //////////////////////////////////////////////////////////////
615
616 $js_script = '';
617
618 // //Show|Hide grayed section
619 // $js_script .= "
620 // if ( ! jQuery('#ics_general_booking_gcal_auto_import_is_active').is(':checked') ) {
621 // jQuery('.wpbc_tr_auto_import').addClass('hidden_items');
622 // }
623 // ";
624
625 // // Hide|Show on Click Radion
626 // $js_script .= " jQuery('input[name=\"paypal_pro_hosted_solution\"]').on( 'change', function(){
627 // jQuery('.wpbc_sub_settings_paypal_account_type').addClass('hidden_items');
628 // if ( jQuery('#paypal_type_standard').is(':checked') ) {
629 // jQuery('.wpbc_sub_settings_paypal_standard').removeClass('hidden_items');
630 // } else {
631 // jQuery('.wpbc_sub_settings_paypal_pro_hosted').removeClass('hidden_items');
632 // }
633 // } ); ";
634
635 ////////////////////////////////////////////////////////////////////////
636
637
638 // Eneque JS to the footer of the page
639 wpbc_enqueue_js( $js_script );
640 }
641
642 // </editor-fold>
643
644 }
645 add_action('wpbc_menu_created', array( new WPBC_Page_SettingsGeneralSync() , '__construct') ); // Executed after creation of Menu
646
647
648 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
649 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
650
651
652 /**
653 * Validate some fields during saving to DB
654 * Skip saving some pseudo options, instead of that creare new real option.
655 *
656 * @param array $validated_fields
657 * @return type
658 */
659 function wpbc_fields_before_saving_to_db__general_sync( $validated_fields ) {
660
661 // Set new option based on pseudo options
662 $validated_fields['booking_gcal_events_form_fields'] = array(
663 'title' => $validated_fields['booking_gcal_events_form_fields_title']
664 , 'description' => $validated_fields['booking_gcal_events_form_fields_description']
665 , 'where' => $validated_fields['booking_gcal_events_form_fields_where']
666 );
667 // Unset several pseudo options.
668 unset( $validated_fields['booking_gcal_events_form_fields_title'] );
669 unset( $validated_fields['booking_gcal_events_form_fields_description'] );
670 unset( $validated_fields['booking_gcal_events_form_fields_where'] );
671
672 return $validated_fields;
673 }
674 add_filter('wpbc_fields_before_saving_to_db__general_sync', 'wpbc_fields_before_saving_to_db__general_sync');
675
676
677
678 /**
679 * Override fields array of Settings page, AFTER saving to DB. Some fields have to have different Values.
680 * Set here values for our pseudo-options, after saving to DB
681 * Because they was not overloading during this saving
682 *
683 * @param array $fields
684 * @param string $page_id
685 * @return array - fields
686 */
687 function wpbc_fields_after_saving_to_db__general_sync( $fields, $page_id ) {
688
689 if ( $page_id == 'general_sync' ) { // Check our API ID relative saving of this settings page
690
691 $booking_gcal_events_form_fields = get_bk_option( 'booking_gcal_events_form_fields');
692 $booking_gcal_events_form_fields = maybe_unserialize( $booking_gcal_events_form_fields );
693
694 if (isset($booking_gcal_events_form_fields['title']))
695 $fields[ 'booking_gcal_events_form_fields_title' ]['value'] = $booking_gcal_events_form_fields['title'];
696
697 if (isset($booking_gcal_events_form_fields['description']))
698 $fields[ 'booking_gcal_events_form_fields_description' ]['value'] = $booking_gcal_events_form_fields['description'];
699
700 if (isset($booking_gcal_events_form_fields['where']))
701 $fields[ 'booking_gcal_events_form_fields_where' ]['value'] = $booking_gcal_events_form_fields['where'];
702
703 }
704 return $fields;
705 }
706 add_filter('wpbc_fields_after_saving_to_db', 'wpbc_fields_after_saving_to_db__general_sync', 10, 2);
707