PluginProbe
Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar / trunk
Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar vtrunk
2.1.20 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 trunk 1.1 2.0 2.0.1 2.0.10.2 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.17 2.0.18 2.0.2 2.0.20 2.0.21 2.0.22 2.0.23 All 54 releases
booking-manager / core / admin / api-settings.php

api-settings.php in Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar trunk, at core/admin/api-settings.php

683 lines 45.4 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 General Settings API - Saving different options
5 * @category Settings API
6 * @author wpdevelop
7 *
8 * @web-site https://oplugins.com/
9 * @email info@oplugins.com
10 * @modified 2016-02-24
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
14
15
16 // General Settings API - Saving different options
17 class WPBM_Settings_API_General extends WPBM_Settings_API {
18
19
20 /** Override Settings API Constructor
21 * During creation, system try to load values from DB, if exist.
22 *
23 * @param type $id - of Settings
24 */
25 public function __construct( $id = '' ){
26
27 $options = array(
28 'db_prefix_option' => '' // 'wpbm_'
29 , 'db_saving_type' => 'separate'
30 , 'id' => 'set_gen'
31 );
32
33 $id = empty($id) ? $options['id'] : $id;
34
35 parent::__construct( $id, $options ); // Define ID of Setting page and options
36
37 add_action( 'wpbm_after_settings_content', array($this, 'enqueue_js'), 10, 3 );
38 }
39
40
41 /** Init all fields rows for settings page */
42 public function init_settings_fields() {
43
44 $this->fields = array();
45
46 $default_options_values = wpbm_get_default_options();
47
48
49 // <editor-fold defaultstate="collapsed" desc=" G e n e r a l " >
50
51
52 // </editor-fold>
53
54
55 // <editor-fold defaultstate="collapsed" desc=" Miscellaneous " >
56
57
58 // Dates Format ////////////////////////////////////////////////////////
59
60 //FixIn: 2.0.12.3
61 $this->fields['wpbm_is_hide_details'] = array(
62 'type' => 'checkbox'
63 , 'default' => $default_options_values['wpbm_is_hide_details'] //'Off'
64 , 'title' => __('Remove booking details in exported .ics feed' , 'booking-manager')
65 , 'label' => __('Check this box to remove details (summary and description) from .ics feed during export process.' , 'booking-manager')
66 , 'description' => ''
67 , 'group' => 'wpbm_listing'
68 );
69
70 //FixIn: 2.1.12.1
71 $this->fields['wpbm_is_export_only_full_days'] = array(
72 'type' => 'checkbox'
73 , 'default' => $default_options_values['wpbm_is_export_only_full_days'] //'Off'
74 , 'title' => __('Export only full days (not time)' , 'booking-manager')
75 , 'label' => __('Check this box to export only full days without time to the .ics feed. This is a limitation in Airbnb and some other services.' , 'booking-manager')
76 , 'description' => ''
77 , 'group' => 'wpbm_listing'
78 );
79
80
81 $this->fields['wpbm_start_day_weeek'] = array(
82 'type' => 'select'
83 , 'default' => $default_options_values[ 'wpbm_start_day_weeek' ] // '2'
84 // , 'value' => false
85 , 'title' => __('Start Day of the week', 'booking-manager')
86 , 'description' => __('Select your start day of the week' ,'booking-manager')
87 , 'options' => array(
88 '0' => __('Sunday' ,'booking-manager')
89 , '1' => __('Monday' ,'booking-manager')
90 , '2' => __('Tuesday' ,'booking-manager')
91 , '3' => __('Wednesday' ,'booking-manager')
92 , '4' => __('Thursday' ,'booking-manager')
93 , '5' => __('Friday' ,'booking-manager')
94 , '6' => __('Saturday' ,'booking-manager')
95 )
96 , 'group' => 'wpbm_listing'
97 );
98
99
100 $this->fields['wpbm_date_format_html_prefix'] = array(
101 'type' => 'pure_html'
102 , 'group' => 'wpbm_listing'
103 , 'html' => '<tr valign="top" class="wpbm_tr_set_gen_wpbm_date_format">
104 <th scope="row">'.
105 WPBM_Settings_API::label_static( 'set_gen_wpbm_date_format'
106 , array( 'title'=> __('Date Format' , 'booking-manager'), 'label_css' => 'margin: 0.25em 0 !important;vertical-align: middle;' ) )
107 .'</th>
108 <td><fieldset>'
109 );
110 $field_options = array();
111 foreach ( array( __('F j, Y'), 'Y/m/d', 'm/d/Y', 'd/m/Y' ) as $format ) {
112 $field_options[ esc_attr($format) ] = array( 'title' => date_i18n( $format ) );
113 }
114 $field_options['custom'] = array( 'title' => __('Custom' , 'booking-manager') . ':', 'attr' => array( 'id' => 'date_format_selection_custom' ) );
115
116 $this->fields['wpbm_date_format_selection'] = array(
117 'type' => 'radio'
118 , 'default' => get_option('date_format')
119 , 'options' => $field_options
120 , 'group' => 'wpbm_listing'
121 , 'only_field' => true
122 );
123
124 $wpbm_date_format = get_wpbm_option( 'wpbm_date_format');
125 $this->fields['wpbm_date_format'] = array(
126 'type' => 'text'
127 , 'default' => $default_options_values['wpbm_date_format'] //get_option('date_format')
128 , 'value' => htmlentities( $wpbm_date_format ) // Display value of this field in specific way
129 , 'group' => 'wpbm_listing'
130 , 'placeholder' => get_option('date_format')
131 , 'css' => 'width:10em;'
132 , 'only_field' => true
133 );
134
135 $this->fields['wpbm_date_format_html_sufix'] = array(
136 'type' => 'pure_html'
137 , 'group' => 'wpbm_listing'
138 , 'html' => ' <span class="description"><code>' . date_i18n( $wpbm_date_format ) . '</code></span>'
139 . '<p class="description">'
140 . sprintf(__('Type your date format for emails and the item table. %sDocumentation on date formatting%s' , 'booking-manager'),'<br/><a href="http://codex.wordpress.org/Formatting_Date_and_Time" target="_blank">','</a>')
141 . ' </p>
142 </fieldset>
143 </td>
144 </tr>'
145 );
146
147 // Time Format
148 // $this->fields = apply_filters( 'wpbm_settings_wpbm_time_format', $this->fields, $default_options_values );
149
150 // Time Format /////////////////////////////////////////////////////////////
151 $this->fields['wpbm_time_format_html_prefix'] = array(
152 'type' => 'pure_html'
153 , 'group' => 'wpbm_listing'
154 , 'html' => '<tr valign="top" class="wpbc_tr_set_gen_wpbm_time_format">
155 <th scope="row">'.
156 WPBM_Settings_API::label_static( 'set_gen_wpbm_time_format'
157 , array( 'title'=> __('Time Format' ,'booking-manager'), 'label_css' => 'margin: 0.25em 0 !important;vertical-align: middle;' ) )
158 .'</th>
159 <td><fieldset>'
160 );
161 $field_options = array();
162 foreach ( array( 'g:i a', 'g:i A', 'H:i' ) as $format ) {
163 $field_options[ esc_attr($format) ] = array( 'title' => date_i18n( $format ) );
164 }
165 $field_options['custom'] = array( 'title' => __('Custom' ,'booking-manager') . ':', 'attr' => array( 'id' => 'time_format_selection_custom' ) );
166
167 $this->fields['wpbm_time_format_selection'] = array(
168 'type' => 'radio'
169 , 'default' => 'H:i'
170 , 'options' => $field_options
171 , 'group' => 'wpbm_listing'
172 , 'only_field' => true
173 );
174
175 $wpbm_time_format = get_wpbm_option( 'wpbm_time_format');
176 $this->fields['wpbm_time_format'] = array(
177 'type' => 'text'
178 , 'default' => $default_options_values['wpbm_time_format'] //'H:i'
179 , 'value' => htmlentities( $wpbm_time_format ) // Display value of this field in specific way
180 , 'group' => 'wpbm_listing'
181 , 'placeholder' => 'H:i'
182 , 'css' => 'width:5em;'
183 , 'only_field' => true
184 );
185
186 $this->fields['wpbm_time_format_html_sufix'] = array(
187 'type' => 'pure_html'
188 , 'group' => 'wpbm_listing'
189 , 'html' => ' <span class="description"><code>' . date_i18n( $wpbm_time_format ) . '</code></span>'
190 . '<p class="description">'
191 . sprintf(__('Type your time format for emails and listing. %sDocumentation on time formatting%s' ,'booking-manager'),'<br/><a href="http://php.net/manual/en/function.date.php" target="_blank">','</a>')
192 . ' </p>
193 </fieldset>
194 </td>
195 </tr>'
196 );
197
198 // </editor-fold>
199
200
201 // <editor-fold defaultstate="collapsed" desc=" Advanced " >
202
203
204 //Show | Hide links for Advanced JavaScript section
205 $this->fields['wpbm_advanced_js_loading_settings'] = array(
206 'type' => 'html'
207 , 'html' =>
208 '<a id="wpbm_show_advanced_section_link_show" class="wpbm_expand_section_link" href="javascript:void(0)">+ ' . __('Show advanced settings of JavaScript loading' , 'booking-manager') . '</a>'
209 . '<a id="wpbm_show_advanced_section_link_hide" class="wpbm_expand_section_link" href="javascript:void(0)" style="display:none;">- ' . __('Hide advanced settings of JavaScript loading' , 'booking-manager') . '</a>'
210 , 'cols' => 2
211 , 'group' => 'advanced'
212 );
213 /*
214 $this->fields['wpbm_is_not_load_bs_script_in_client'] = array(
215 'type' => 'checkbox'
216 , 'default' => $default_options_values['wpbm_is_not_load_bs_script_in_client'] //'Off'
217 , 'title' => __('Disable Bootstrap loading on Front-End' , 'booking-manager')
218 , 'label' => __(' If your theme or some other plugin is load the BootStrap JavaScripts, you can disable loading of this script by this plugin.' , 'booking-manager')
219 , 'description' => ''
220 , 'group' => 'advanced'
221 , 'tr_class' => 'wpbm_advanced_js_loading_settings wpbm_sub_settings_grayed hidden_items'
222 );
223 */
224 $this->fields['wpbm_is_not_load_bs_script_in_admin'] = array(
225 'type' => 'checkbox'
226 , 'default' => $default_options_values['wpbm_is_not_load_bs_script_in_admin'] //'Off'
227 , 'title' => __('Disable Bootstrap loading on Back-End' , 'booking-manager')
228 , 'label' => __(' If your theme or some other plugin is load the BootStrap JavaScripts, you can disable loading of this script by this plugin.' , 'booking-manager')
229 , 'description' => ''
230 , 'group' => 'advanced'
231 , 'tr_class' => 'wpbm_advanced_js_loading_settings wpbm_sub_settings_grayed hidden_items'
232 );
233 /*
234 $this->fields['hr_calendar_before_is_load_js_css_on_specific_pages'] = array( 'type' => 'hr', 'group' => 'advanced', 'tr_class' => 'wpbm_advanced_js_loading_settings wpbm_sub_settings_grayed hidden_items' );
235 $this->fields['wpbm_is_load_js_css_on_specific_pages'] = array(
236 'type' => 'checkbox'
237 , 'default' => $default_options_values['wpbm_is_load_js_css_on_specific_pages'] //'Off'
238 , 'title' => __('Load JS and CSS files only on specific pages' , 'booking-manager')
239 , 'label' => __('Activate loading of CSS and JavaScript files of plugin only at specific pages.' , 'booking-manager')
240 , 'description' => ''
241 , 'group' => 'advanced'
242 , 'tr_class' => 'wpbm_advanced_js_loading_settings wpbm_sub_settings_grayed hidden_items'
243 , 'is_demo_safe' => wpbm_is_this_demo()
244 );
245 $this->fields['wpbm_pages_for_load_js_css'] = array(
246 'type' => 'textarea'
247 , 'default' => $default_options_values['wpbm_pages_for_load_js_css'] //''
248 , 'placeholder' => '/wpbm-form/'
249 , 'title' => __('Relative URLs of pages, where to load plugin CSS and JS files' , 'booking-manager')
250 , 'description' => sprintf(__('Enter relative URLs of pages, where you have Booking Manager elements (item forms or availability calendars). Please enter one URL per line. Example: %s' , 'booking-manager'),'<code>/wpbm-form/</code>')
251 ,'description_tag' => 'p'
252 , 'css' => 'width:100%'
253 , 'rows' => 5
254 , 'group' => 'advanced'
255 , 'tr_class' => 'wpbm_advanced_js_loading_settings wpbm_is_load_js_css_on_specific_pages wpbm_sub_settings_grayed hidden_items'
256 , 'is_demo_safe' => wpbm_is_this_demo()
257 );
258 */
259 if ( wpbm_is_this_demo() )
260 $this->fields['wpbm_pages_for_load_js_css_demo'] = array( 'group' => 'advanced', 'type' => 'html', 'html' => wpbm_get_warning_text_in_demo_mode(), 'cols' => 2 , 'tr_class' => 'wpbm_advanced_js_loading_settings wpbm_sub_settings_grayed hidden_items' );
261
262
263 /*
264 // Show settings of powered by notice
265 $this->fields['wpbm_advanced_powered_by_notice_settings'] = array(
266 'type' => 'html'
267 , 'html' =>
268 '<a id="wpbm_powered_by_link_show" class="wpbm_expand_section_link" href="javascript:void(0)">+ ' . __('Show settings of powered by notice' , 'booking-manager') . '</a>'
269 . '<a id="wpbm_powered_by_link_hide" class="wpbm_expand_section_link" href="javascript:void(0)" style="display:none;">- ' . __('Hide settings of powered by notice' , 'booking-manager') . '</a>'
270 , 'cols' => 2
271 , 'group' => 'advanced'
272 );
273
274 $this->fields['wpbm_wpbm_copyright_adminpanel'] = array(
275 'type' => 'checkbox'
276 , 'default' => $default_options_values['wpbm_wpbm_copyright_adminpanel'] //'On'
277 , 'title' => __('Help and info notices' , 'booking-manager')
278 , 'label' => sprintf(__(' Turn On/Off version notice and help link to rate plugin at admin panel.' , 'booking-manager'),'oplugins.com')
279 , 'description' => ''
280 , 'group' => 'advanced'
281 , 'tr_class' => 'wpbm_is_show_powered_by_notice wpbm_sub_settings_grayed hidden_items'
282 );
283 */
284 if ( ( ! wpbm_is_this_demo() ) && ( current_user_can( 'activate_plugins' ) ) ) {
285
286
287 $this->fields['help_plugin_system_info'] = array(
288 'type' => 'help'
289 , 'value' => array() //FixIn: 2.0.1.4
290 , 'class' => ''
291 , 'css' => 'margin:0;padding:0;border:0;'
292 , 'description' => ''
293 , 'cols' => 2
294 , 'group' => 'advanced'
295 , 'tr_class' => ''
296 , 'description_tag' => 'p'
297 );
298
299 $this->fields['help_plugin_system_info']['value'][] =
300 '<div class="clear"></div><hr/><center><a class="button button" href="'
301 . wpbm_get_settings_url()
302 . '&system_info=show#wpbm_general_settings_system_info_metabox">'
303 . __('Plugin System Info' , 'booking-manager')
304 . '</a></center>';
305 }
306
307 // </editor-fold>
308
309
310 // <editor-fold defaultstate="collapsed" desc=" Information " >
311 if ( function_exists( 'wpbm_get_dashboard_info' ) ) {
312 $this->fields['wpbm_information'] = array(
313 'type' => 'html'
314 , 'html' => wpbm_get_dashboard_info()
315 , 'cols' => 2
316 , 'group' => 'information'
317 );
318 }
319 // </editor-fold>
320
321
322 // <editor-fold defaultstate="collapsed" desc=" User permissions for plugin menu pages " >
323
324
325 $this->fields['wpbm_menu_position'] = array(
326 'type' => 'select'
327 , 'default' => 'top'
328 , 'title' => __('Plugin menu position', 'booking-manager')
329 , 'description' => ''
330 , 'options' => array(
331 'top' => __('Top', 'booking-manager')
332 , 'middle' => __('Middle', 'booking-manager')
333 , 'bottom' => __('Bottom', 'booking-manager')
334 )
335 , 'group' => 'permissions'
336 , 'is_demo_safe' => wpbm_is_this_demo()
337 );
338
339 // $this->fields['wpbm_user_role_wpbm_header'] = array(
340 // 'type' => 'pure_html'
341 // , 'group' => 'permissions'
342 // , 'html' => '<tr valign="top">
343 // <th scope="row" colspan="2">
344 // <hr/><p><strong>' . wp_kses_post( __('User permissions for plugin menu pages' , 'booking-manager') ) . ':</strong></p>
345 // </th>
346 // </tr'
347 // );
348
349 $field_options = array();
350 $field_options['subscriber'] = translate_user_role('Subscriber');
351 $field_options['contributor'] = translate_user_role('Contributor');
352 $field_options['author'] = translate_user_role('Author');
353 $field_options['editor'] = translate_user_role('Editor');
354 $field_options['administrator'] = translate_user_role('Administrator');
355
356 $this->fields['wpbm_user_role_master'] = array(
357 'type' => 'select'
358 , 'default' => $default_options_values['wpbm_user_role_master'] //'editor'
359 , 'title' => __('Permission for plugin menu', 'booking-manager')
360 , 'description' => ''
361 , 'options' => $field_options
362 , 'group' => 'permissions'
363 , 'is_demo_safe' => wpbm_is_this_demo()
364 );
365 // $this->fields['wpbm_user_role_settings'] = array(
366 // 'type' => 'select'
367 // , 'default' => $default_options_values['wpbm_user_role_settings'] //'administrator'
368 // , 'title' => __('Settings', 'booking-manager')
369 // , 'description' => __('Select user access level for the menu pages of plugin' , 'booking-manager')
370 // , 'description_tag' => 'p'
371 // , 'options' => $field_options
372 // , 'group' => 'permissions'
373 // , 'is_demo_safe' => wpbm_is_this_demo()
374 // );
375
376 if ( wpbm_is_this_demo() )
377 $this->fields['wpbm_user_role_settings_demo'] = array( 'group' => 'permissions', 'type' => 'html', 'html' => wpbm_get_warning_text_in_demo_mode(), 'cols' => 2 );
378
379
380 // </editor-fold>
381
382
383 // <editor-fold defaultstate="collapsed" desc=" Uninstall " >
384 $this->fields['wpbm_is_delete_if_deactive'] = array(
385 'type' => 'checkbox'
386 , 'default' => $default_options_values['wpbm_is_delete_if_deactive'] //'Off'
387 , 'title' => __('Delete plugin settings, when plugin deactivated' , 'booking-manager')
388 , 'label' => __('Check this box to delete plugin settings options, when you uninstall this plugin.' , 'booking-manager')
389 , 'description' => ''
390 , 'group' => 'uninstall'
391 );
392 // </editor-fold>
393
394
395 //debuge($this->fields);die;
396 }
397
398
399 /** Add Custon JavaScript - for some specific settings options
400 * Need to executes after showing of entire settings page (on hook: wpbm_after_settings_content).
401 * After initial definition of settings, and possible definition after POST request.
402 *
403 * @param type $menu_slug
404 *
405 */
406 public function enqueue_js( $menu_slug, $active_page_tab, $active_page_subtab ) {
407
408 $js_script = '';
409
410 // Hide Legend items
411 $js_script .= "
412 if ( ! jQuery('#set_gen_wpbm_is_show_legend').is(':checked') ) {
413 jQuery('.wpbm_calendar_legend_items').addClass('hidden_items');
414 }
415 ";
416 // Hide or Show Legend items on click checkbox
417 $js_script .= " jQuery('#set_gen_wpbm_is_show_legend').on( 'change', function(){
418 if ( this.checked ) {
419 jQuery('.wpbm_calendar_legend_items').removeClass('hidden_items');
420 } else {
421 jQuery('.wpbm_calendar_legend_items').addClass('hidden_items');
422 }
423 } ); ";
424 // Thank you Message or Page
425 $js_script .= "
426 if ( jQuery('#type_of_thank_you_message_message').is(':checked') ) {
427 jQuery('.wpbm_calendar_thank_you_page').addClass('hidden_items');
428 }
429 if ( jQuery('#type_of_thank_you_message_page').is(':checked') ) {
430 jQuery('.wpbm_calendar_thank_you_message').addClass('hidden_items');
431 }
432 ";
433 $js_script .= " jQuery('input[name=\"set_gen_wpbm_type_of_thank_you_message\"]').on( 'change', function(){
434 if ( jQuery('#type_of_thank_you_message_message').is(':checked') ) {
435 jQuery('.wpbm_calendar_thank_you_message').removeClass('hidden_items');
436 jQuery('.wpbm_calendar_thank_you_page').addClass('hidden_items');
437 } else {
438 jQuery('.wpbm_calendar_thank_you_message').addClass('hidden_items');
439 jQuery('.wpbm_calendar_thank_you_page').removeClass('hidden_items');
440 }
441 } ); ";
442
443 // Default calendar view mode (Item Listing) - set active / inctive options depend from resource selection.
444 $js_script .= " jQuery('#set_gen_wpbm_view_days_num').on( 'focus', function(){
445 if ( jQuery('#set_gen_wpbm_default_wpbm_resource').length > 0 ) {
446 jQuery('#set_gen_wpbm_default_wpbm_resource').bind('change', function() {
447 jQuery('#set_gen_wpbm_view_days_num option:eq(2)').prop('selected', true);
448 });
449 if ( jQuery('#set_gen_wpbm_default_wpbm_resource').val() == '' ) {
450 jQuery('#set_gen_wpbm_view_days_num option:eq(0)').prop('disabled', false);
451 jQuery('#set_gen_wpbm_view_days_num option:eq(1)').prop('disabled', false);
452 jQuery('#set_gen_wpbm_view_days_num option:eq(2)').prop('disabled', false);
453 jQuery('#set_gen_wpbm_view_days_num option:eq(3)').prop('disabled', false);
454 jQuery('#set_gen_wpbm_view_days_num option:eq(4)').prop('disabled', true);
455 jQuery('#set_gen_wpbm_view_days_num option:eq(5)').prop('disabled', true);
456 } else {
457 jQuery('#set_gen_wpbm_view_days_num option:eq(0)').prop('disabled', true);
458 jQuery('#set_gen_wpbm_view_days_num option:eq(1)').prop('disabled', true);
459 jQuery('#set_gen_wpbm_view_days_num option:eq(2)').prop('disabled', false);
460 jQuery('#set_gen_wpbm_view_days_num option:eq(3)').prop('disabled', true);
461 jQuery('#set_gen_wpbm_view_days_num option:eq(4)').prop('disabled', false);
462 jQuery('#set_gen_wpbm_view_days_num option:eq(5)').prop('disabled', false);
463 }
464 }
465 } ); ";
466
467 ////////////////////////////////////////////////////////////////////////
468 // Set correct value for dates format, depend from selection of radio buttons
469 $wpbm_date_format = get_wpbm_option( 'wpbm_date_format');
470 // On initial Load set correct text value and correct radio button
471 $js_script .= "
472 // Select by default Custom value, later check all other predefined values
473 jQuery( '#date_format_selection_custom' ).prop('checked', true);
474
475 jQuery('input[name=\"set_gen_wpbm_date_format_selection\"]').each(function() {
476 var radio_button_value = jQuery( this ).val()
477 var encodedStr = radio_button_value.replace(/[\u00A0-\u9999<>\&]/gim, function(i) {
478 return '&#'+i.charCodeAt(0)+';';
479 });
480 if ( encodedStr == '". $wpbm_date_format ."' ) {
481 jQuery( this ).prop('checked', true);
482 }
483 });
484
485 jQuery('#set_gen_wpbm_date_format').val('". $wpbm_date_format ."');
486 ";
487 // On click Radio button "Date Format", - set value in custom Text field
488 $js_script .= " jQuery('input[name=\"set_gen_wpbm_date_format_selection\"]').on( 'change', function(){
489 if ( ( this.checked ) && ( jQuery(this).val() != 'custom' ) ){
490
491 jQuery('#set_gen_wpbm_date_format').val( jQuery(this).val().replace(/[\u00A0-\u9999<>\&]/gim,
492 function(i) {
493 return '&#'+i.charCodeAt(0)+';';
494 })
495 );
496 }
497 } ); ";
498 // If we edit custom "Date Format" Text field - select Custom Radio button.
499 $js_script .= " jQuery('#set_gen_wpbm_date_format').on( 'change', function(){
500 jQuery( '#date_format_selection_custom' ).prop('checked', true);
501 } ); ";
502
503
504
505
506 ////////////////////////////////////////////////////////////////////////
507 // Set correct value for Time Format, depend from selection of radio buttons
508 $wpbm_time_format = get_wpbm_option( 'wpbm_time_format');
509 // Function to load on initial stage of page loading, set correct value of text and select correct radio button.
510 $js_script .= "
511 // Select by default Custom value, later check all other predefined values
512 jQuery( '#time_format_selection_custom' ).prop('checked', true);
513
514 jQuery('input[name=\"set_gen_wpbm_time_format_selection\"]').each(function() {
515 var radio_button_value = jQuery( this ).val()
516 var encodedStr = radio_button_value.replace(/[\u00A0-\u9999<>\&]/gim, function(i) {
517 return '&#'+i.charCodeAt(0)+';';
518 });
519 if ( encodedStr == '". $wpbm_time_format ."' ) {
520 jQuery( this ).prop('checked', true);
521 }
522 });
523
524 jQuery('#set_gen_wpbm_time_format').val('". $wpbm_time_format ."');
525 ";
526 // On click Radio button "Time Format", - set value in custom Text field
527 $js_script .= " jQuery('input[name=\"set_gen_wpbm_time_format_selection\"]').on( 'change', function(){
528 if ( ( this.checked ) && ( jQuery(this).val() != 'custom' ) ){
529
530 jQuery('#set_gen_wpbm_time_format').val( jQuery(this).val().replace(/[\u00A0-\u9999<>\&]/gim,
531 function(i) {
532 return '&#'+i.charCodeAt(0)+';';
533 })
534 );
535 }
536 } ); ";
537 // If we edit custom "Time Format" Text field - select Custom Radio button.
538 $js_script .= " jQuery('#set_gen_wpbm_time_format').on( 'change', function(){
539 jQuery( '#time_format_selection_custom' ).prop('checked', true);
540 } ); ";
541
542
543 ////////////////////////////////////////////////////////////////////////
544 // Advanced section
545 ////////////////////////////////////////////////////////////////////////
546
547 // Click on "Allow unlimited items per same day(s)"
548 $js_script .= " jQuery('#set_gen_wpbm_is_days_always_available').on( 'change', function(){
549 if ( this.checked ) {
550 var answer = confirm('"
551 . esc_js( __( 'Warning', 'booking-manager') ) . '! '
552 . esc_js( __( 'You allow unlimited number of items per same dates, its can be a reason of double items on the same date. Do you really want to do this?', 'booking-manager') )
553 . "' );
554 if ( answer) {
555 this.checked = true;
556 jQuery('#set_gen_wpbm_check_on_server_if_dates_free').prop('checked', false );
557 jQuery('#set_gen_wpbm_is_show_pending_days_as_available').prop('checked', false );
558 jQuery('.wpbm_pending_days_as_available_sub_settings').addClass('hidden_items');
559 } else {
560 this.checked = false;
561 }
562 }
563 } ); ";
564 // Click on "Checking to prevent double item, during submitting item"
565 $js_script .= " jQuery('#set_gen_wpbm_check_on_server_if_dates_free').on( 'change', function(){
566 if ( this.checked ) {
567 var answer = confirm('"
568 . esc_js( __( 'Warning', 'booking-manager') ) . '! '
569 . esc_js( __( 'This feature can impact to speed of submitting item. Do you really want to do this?', 'booking-manager') )
570 . "' );
571 if ( answer) {
572 this.checked = true;
573 jQuery('#set_gen_wpbm_is_days_always_available').prop('checked', false );
574 } else {
575 this.checked = false;
576 }
577 }
578 } ); ";
579
580 // Click on Show Advanced JavaScript section link
581 $js_script .= " jQuery('#wpbm_show_advanced_section_link_show').on( 'click', function(){
582 jQuery('#wpbm_show_advanced_section_link_show').toggle(200);
583 jQuery('#wpbm_show_advanced_section_link_hide').animate( {opacity: 1}, 200 ).toggle(200);
584 jQuery('.wpbm_advanced_js_loading_settings').removeClass('hidden_items');
585
586 if ( ! jQuery('#set_gen_wpbm_is_load_js_css_on_specific_pages').is(':checked') ) {
587 jQuery('.wpbm_is_load_js_css_on_specific_pages').addClass('hidden_items');
588 }
589 } ); ";
590 $js_script .= " jQuery('#wpbm_show_advanced_section_link_hide').on( 'click', function(){
591 jQuery('#wpbm_show_advanced_section_link_hide').toggle(200);
592 jQuery('#wpbm_show_advanced_section_link_show').animate( {opacity: 1}, 200 ).toggle(200);
593 jQuery('.wpbm_advanced_js_loading_settings').addClass('hidden_items');
594 } ); ";
595 // Click on "is_not_load_bs_script_in_client"
596 $js_script .= " jQuery('#set_gen_wpbm_is_not_load_bs_script_in_client, #set_gen_wpbm_is_not_load_bs_script_in_admin').on( 'change', function(){
597 if ( this.checked ) {
598 var answer = confirm('"
599 . esc_js( __( 'Warning', 'booking-manager') ) . '! '
600 . esc_js( __( 'You are need to be sure what you are doing. You are disable of loading some JavaScripts Do you really want to do this?', 'booking-manager') )
601 . "' );
602 if ( answer) {
603 this.checked = true;
604 } else {
605 this.checked = false;
606 }
607 }
608 } ); ";
609 $js_script .= " jQuery('#set_gen_wpbm_is_load_js_css_on_specific_pages').on( 'change', function(){
610 if ( this.checked ) {
611 var answer = confirm('"
612 . esc_js( __( 'Warning', 'booking-manager') ) . '! '
613 . esc_js( __( 'You are need to be sure what you are doing. You are disable of loading some JavaScripts Do you really want to do this?', 'booking-manager') )
614 . "' );
615 if ( answer) {
616 this.checked = true;
617 jQuery('.wpbm_is_load_js_css_on_specific_pages').removeClass('hidden_items');
618 } else {
619 this.checked = false;
620 }
621 } else {
622 jQuery('.wpbm_is_load_js_css_on_specific_pages').addClass('hidden_items');
623 }
624 } );
625 ";
626
627
628 // Click on Powered by links
629 $js_script .= " jQuery('#wpbm_powered_by_link_show').on( 'click', function(){
630 jQuery('#wpbm_powered_by_link_show').toggle(200);
631 jQuery('#wpbm_powered_by_link_hide').animate( {opacity: 1}, 200 ).toggle(200);
632 jQuery('.wpbm_is_show_powered_by_notice').removeClass('hidden_items');
633 } ); ";
634 $js_script .= " jQuery('#wpbm_powered_by_link_hide').on( 'click', function(){
635 jQuery('#wpbm_powered_by_link_hide').toggle(200);
636 jQuery('#wpbm_powered_by_link_show').animate( {opacity: 1}, 200 ).toggle(200);
637 jQuery('.wpbm_is_show_powered_by_notice').addClass('hidden_items');
638 } ); ";
639
640
641 // Show confirmation window, if user activate this checkbox
642 $js_script .= " jQuery('#set_gen_wpbm_is_delete_if_deactive').on( 'change', function(){
643 if ( this.checked ) {
644 var answer = confirm('"
645 . esc_js( __( 'Warning', 'booking-manager') ) . '! '
646 . esc_js( __( 'If you check this option, all data will be deleted when you uninstall this plugin. Do you really want to do this?', 'booking-manager') )
647 . "' );
648 if ( answer) {
649 this.checked = true;
650 } else {
651 this.checked = false;
652 }
653 }
654 } );
655 ";
656
657 // Eneque JS to the footer of the page
658 wpbm_enqueue_js( $js_script );
659 }
660 }
661
662
663 /** Override VALIDATED fields BEFORE saving to DB
664 * Description:
665 * Check "Thank you page" URL
666 *
667 * @param array $validated_fields
668 */
669 function wpbm_settings_validate_fields_before_saving__all( $validated_fields ) {
670
671
672 // $validated_fields['wpbm_url_wrong_hash'] = wpbm_make_link_relative( $validated_fields['wpbm_url_wrong_hash'] );
673 // $validated_fields['wpbm_url_download_expired'] = wpbm_make_link_relative( $validated_fields['wpbm_url_download_expired'] );
674 // $validated_fields['wpbm_url_ip_not_valied'] = wpbm_make_link_relative( $validated_fields['wpbm_url_ip_not_valied'] );
675 // $validated_fields['wpbm_url_file_not_exist'] = wpbm_make_link_relative( $validated_fields['wpbm_url_file_not_exist'] );
676 // $validated_fields['wpbm_url_error_opening_file'] = wpbm_make_link_relative( $validated_fields['wpbm_url_error_opening_file'] );
677
678 unset( $validated_fields[ 'wpbm_date_format_selection' ] ); // We do not need to this field, because saving to DB only: "date_format" field
679 unset( $validated_fields[ 'wpbm_time_format_selection' ] ); // We do not need to this field, because saving to DB only: "time_format" field
680
681 return $validated_fields;
682 }
683 add_filter( 'wpbm_settings_validate_fields_before_saving', 'wpbm_settings_validate_fields_before_saving__all', 10, 1 ); // Hook for validated fields.