PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.1.8
LatePoint – Calendar Booking Plugin for Appointments and Events v5.1.8
5.6.7 5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / lib / helpers / settings_helper.php
latepoint / lib / helpers Last commit date
activities_helper.php 1 year ago agent_helper.php 1 year ago auth_helper.php 1 year ago blocks_helper.php 1 year ago booking_helper.php 1 year ago bricks_helper.php 1 year ago bundles_helper.php 1 year ago calendar_helper.php 1 year ago carts_helper.php 1 year ago connector_helper.php 1 year ago csv_helper.php 1 year ago customer_helper.php 1 year ago database_helper.php 1 year ago debug_helper.php 1 year ago defaults_helper.php 1 year ago elementor_helper.php 1 year ago email_helper.php 1 year ago encrypt_helper.php 1 year ago events_helper.php 1 year ago form_helper.php 1 year ago icalendar_helper.php 1 year ago image_helper.php 1 year ago invoices_helper.php 1 year ago license_helper.php 1 year ago location_helper.php 1 year ago marketing_systems_helper.php 1 year ago meeting_systems_helper.php 1 year ago menu_helper.php 1 year ago meta_helper.php 1 year ago migrations_helper.php 1 year ago money_helper.php 1 year ago notifications_helper.php 1 year ago order_intent_helper.php 1 year ago orders_helper.php 1 year ago pages_helper.php 1 year ago params_helper.php 1 year ago payments_helper.php 1 year ago price_breakdown_helper.php 1 year ago process_jobs_helper.php 1 year ago processes_helper.php 1 year ago replacer_helper.php 1 year ago resource_helper.php 1 year ago roles_helper.php 1 year ago router_helper.php 1 year ago service_helper.php 1 year ago sessions_helper.php 1 year ago settings_helper.php 1 year ago shortcodes_helper.php 1 year ago sms_helper.php 1 year ago steps_helper.php 1 year ago stripe_connect_helper.php 1 year ago styles_helper.php 1 year ago support_topics_helper.php 1 year ago time_helper.php 1 year ago timeline_helper.php 1 year ago transaction_helper.php 1 year ago transaction_intent_helper.php 1 year ago util_helper.php 1 year ago version_specific_updates_helper.php 1 year ago whatsapp_helper.php 1 year ago work_periods_helper.php 1 year ago wp_datetime.php 1 year ago wp_user_helper.php 1 year ago
settings_helper.php
660 lines
1 <?php
2
3 class OsSettingsHelper {
4
5 public static $loaded_values;
6
7
8 private static $encrypted_settings = [
9 'license',
10 'google_calendar_client_secret',
11 'facebook_app_secret',
12 'google_client_secret',
13 'braintree_secret_key',
14 'braintree_merchant_id',
15 'paypal_client_secret'
16 ];
17
18 private static $settings_to_autoload = [
19 'enable_google_login',
20 'time_system',
21 'date_format',
22 'currency_symbol_before',
23 'currency_symbol_after',
24 'phone_format',
25 'steps_show_timezone_selector',
26 'show_booking_end_time',
27 'stripe_publishable_key',
28 'enable_facebook_login',
29 'earliest_possible_booking',
30 'enable_payments_local',
31 'color_scheme_for_booking_form',
32 'latest_possible_booking',
33 'facebook_app_id',
34 'google_client_id',
35 'paypal_client_id',
36 'paypal_currency_iso_code',
37 'paypal_use_braintree_api',
38 'stripe_secret_key',
39 'steps_hide_agent_info',
40 'booking_hash',
41 'payments_environment',
42 'list_of_phone_countries',
43 'included_phone_countries',
44 'wp_users_as_customers',
45 'thousand_separator',
46 'decimal_separator',
47 'number_of_decimals',
48 'default_phone_country'
49 ];
50
51 private static $defaults = [
52 'date_format' => LATEPOINT_DEFAULT_DATE_FORMAT,
53 'time_system' => LATEPOINT_DEFAULT_TIME_SYSTEM,
54 'currency_symbol_before' => '$'
55 ];
56
57 public static function get_remote_url( $extra = '' ) {
58 return base64_decode( LATEPOINT_REMOTE_HASH ) . $extra;
59 }
60
61 public static function get_business_logo_url() {
62 $default_logo_url = LATEPOINT_IMAGES_URL . 'logo.png';
63
64 return OsImageHelper::get_image_url_by_id( OsSettingsHelper::get_settings_value( 'business_logo' ), 'thumbnail', $default_logo_url );
65 }
66
67 public static function get_business_logo_image( $height = '50px' ) {
68 $url = self::get_business_logo_url();
69
70 return '<img src="' . $url . '" style="height: ' . $height . '; width: auto"/>';
71 }
72
73 public static function get_encrypted_settings() {
74 $encrypted_settings = apply_filters( 'latepoint_encrypted_settings', self::$encrypted_settings );
75
76 return $encrypted_settings;
77 }
78
79
80 public static function get_active_addons(): array {
81 return json_decode( OsSettingsHelper::get_settings_value( 'active_addons', '' ) ) ?? [];
82 }
83
84 /**
85 * @param array $tables
86 *
87 * @return string
88 */
89 public static function export_data( array $tables = [] ): string {
90
91 if ( empty( $tables ) ) {
92 $tables = OsDatabaseHelper::get_all_latepoint_tables();
93 }
94
95 global $wpdb;
96
97 $output = [];
98
99 foreach ( $tables as $table ) {
100 // Check if table exists
101 $table_exists = $wpdb->get_var( "SHOW TABLES LIKE '{$table}'" );
102
103 if ( ! $table_exists ) {
104 continue; // Skip this table if it doesn't exist
105 }
106 // Get all rows from the table
107 $rows = $wpdb->get_results( "SELECT * FROM {$table}", ARRAY_A );
108
109 if ( $rows ) {
110 // Get table create statement
111 $create_table = $wpdb->get_row( "SHOW CREATE TABLE {$table}", ARRAY_N );
112 $var_table = str_replace($wpdb->prefix, '{{TABLE_PREFIX}}', $table);
113 $create_table = str_replace($table, $var_table, $create_table);
114
115 $output[ $var_table ] = [
116 'create' => $create_table[1],
117 'prefix' => $wpdb->prefix,
118 'data' => $rows
119 ];
120 }
121 }
122
123 // Generate filename
124 $filename = 'latepoint_backup_' . date( 'Y-m-d_H-i-s' ) . '.json';
125
126 $json = wp_json_encode($output, JSON_PRETTY_PRINT);
127
128 // Send headers for file download
129 header( 'Content-Type: application/json' );
130 header( 'Content-Disposition: attachment; filename="' . $filename . '"' );
131 header( 'Content-Length: ' . strlen( $json ) );
132 header( 'Pragma: no-cache' );
133
134 return $json;
135 }
136
137 /**
138 * @param string $data
139 *
140 * @return bool
141 * @throws Exception
142 */
143 public static function import_data( string $data ): bool {
144 global $wpdb;
145
146 if ( empty( $data ) ) {
147 throw new Exception( __( 'Error reading uploaded file', 'latepoint' ) );
148 }
149
150 // update table name from original to new prefix
151 $data = str_replace('{{TABLE_PREFIX}}', $wpdb->prefix, $data);
152
153 $data = json_decode( $data, true );
154 if ( json_last_error() !== JSON_ERROR_NONE ) {
155 throw new Exception( __( 'Invalid JSON file format', 'latepoint' ) );
156 }
157
158 foreach ( $data as $table => $table_data ) {
159 // Drop table if exists
160 $wpdb->query( "DROP TABLE IF EXISTS {$table}" );
161
162 // Create table
163 $wpdb->query( $table_data['create'] );
164
165 // Insert data
166 foreach ( $table_data['data'] as $row ) {
167 $wpdb->insert( $table, $row );
168 }
169
170 // Find auto-increment columns and their max values
171 $columns = $wpdb->get_results( "SHOW COLUMNS FROM {$table} WHERE Extra = 'auto_increment'" );
172 foreach ( $columns as $column ) {
173 // Get the maximum value for this column
174 $max_id = $wpdb->get_var( "SELECT MAX({$column->Field}) FROM {$table}" );
175
176 // Set the auto_increment value to max + 1
177 if ( $max_id ) {
178 $wpdb->query( "ALTER TABLE {$table} AUTO_INCREMENT = " . ( $max_id + 1 ) );
179 }
180 }
181 }
182
183 return true;
184 }
185
186 public static function run_autoload() {
187 /**
188 * Default settings to be used in SettingsHelper when no value exists in DB
189 *
190 * @param {array} $default_settings Array of key => value pairs of setting names and their default values
191 * @returns {array} The filtered array of default settings
192 *
193 * @since 4.7.2
194 * @hook latepoint_settings_defaults
195 *
196 */
197 self::$defaults = apply_filters( 'latepoint_settings_defaults', self::$defaults );
198 foreach ( self::$defaults as $name => $default ) {
199 self::$loaded_values[ $name ] = $default;
200 }
201
202 $settings_model = new OsSettingsModel();
203
204 /**
205 * Settings to autoload in SettingsHelper on every page load, this is done to reduce the number of queries to DB
206 *
207 * @param {array} $settings Array of setting names to autoload
208 * @returns {array} The filtered array of setting names
209 *
210 * @since 4.7.2
211 * @hook latepoint_settings_to_autoload
212 *
213 */
214 self::$settings_to_autoload = apply_filters( 'latepoint_settings_to_autoload', self::$settings_to_autoload );
215 $settings_arr = $settings_model->select( 'name, value' )->where( array( 'name' => self::$settings_to_autoload ) )->get_results();
216
217
218 if ( $settings_arr && is_array( $settings_arr ) ) {
219 foreach ( $settings_arr as $setting ) {
220 if ( in_array( $setting->name, self::get_encrypted_settings() ) ) {
221 self::$loaded_values[ $setting->name ] = OsEncryptHelper::decrypt_value( $setting->value );
222 } else {
223 self::$loaded_values[ $setting->name ] = $setting->value;
224 }
225 }
226 }
227 }
228
229
230 // ENVIRONMENT SETTINGS
231
232 // BASE ENVIRONMENT
233 public static function is_env_live() {
234 return ( LATEPOINT_ENV == LATEPOINT_ENV_LIVE );
235 }
236
237 public static function is_env_dev() {
238 return ( LATEPOINT_ENV == LATEPOINT_ENV_DEV );
239 }
240
241 public static function is_env_demo() {
242 return ( LATEPOINT_ENV == LATEPOINT_ENV_DEMO );
243 }
244
245 // SMS, EMAILS
246
247 public static function is_sms_allowed() {
248 return LATEPOINT_ALLOW_SMS;
249 }
250
251 public static function is_whatsapp_allowed() {
252 return LATEPOINT_ALLOW_WHATSAPP;
253 }
254
255 public static function is_email_allowed() {
256 return LATEPOINT_ALLOW_EMAILS;
257 }
258
259 // PAYMENTS ENVIRONMENT
260 public static function is_env_payments_live() {
261 return ( self::get_payments_environment() == LATEPOINT_PAYMENTS_ENV_LIVE );
262 }
263
264 public static function is_env_payments_dev() {
265 return ( self::get_payments_environment() == LATEPOINT_PAYMENTS_ENV_DEV );
266 }
267
268 public static function is_env_payments_demo() {
269 return ( self::get_payments_environment() == LATEPOINT_PAYMENTS_ENV_DEMO );
270 }
271
272 public static function get_payments_environment() {
273 return self::get_settings_value( 'payments_environment', LATEPOINT_PAYMENTS_ENV_LIVE );
274 }
275
276
277 public static function append_payment_env_key( string $string, string $force_env = '' ): string {
278 if ( $force_env ) {
279 if ( $force_env == LATEPOINT_PAYMENTS_ENV_DEV ) {
280 $string .= LATEPOINT_PAYMENTS_DEV_SUFFIX;
281 }
282 } else {
283 if ( self::is_env_payments_dev() ) {
284 $string .= LATEPOINT_PAYMENTS_DEV_SUFFIX;
285 }
286 }
287
288 return $string;
289 }
290
291 public static function set_menu_layout_style( $layout ) {
292 OsSessionsHelper::setcookie( LATEPOINT_ADMIN_MENU_LAYOUT_STYLE_COOKIE, $layout );
293 }
294
295 public static function get_menu_layout_style() {
296 if ( ! isset( $_COOKIE[ LATEPOINT_ADMIN_MENU_LAYOUT_STYLE_COOKIE ] ) ) {
297 self::set_menu_layout_style( 'full' );
298 }
299
300 return isset( $_COOKIE[ LATEPOINT_ADMIN_MENU_LAYOUT_STYLE_COOKIE ] ) ? sanitize_text_field( wp_unslash( $_COOKIE[ LATEPOINT_ADMIN_MENU_LAYOUT_STYLE_COOKIE ] ) ) : 'full';
301 }
302
303 public static function get_time_system() {
304 return self::get_settings_value( 'time_system', LATEPOINT_DEFAULT_TIME_SYSTEM );
305 }
306
307 public static function get_date_format() {
308 return self::get_settings_value( 'date_format', LATEPOINT_DEFAULT_DATE_FORMAT );
309 }
310
311 public static function get_date_format_for_js() {
312 $format = strtolower( self::get_date_format() );
313
314 return str_replace( [ 'd', 'm', 'y' ], [ 'dd', 'mm', 'yyyy' ], $format );
315 }
316
317 public static function get_readable_datetime_format( $no_year = false, $no_seconds = true ) {
318 return self::get_readable_date_format( $no_year ) . ', ' . self::get_readable_time_format( $no_seconds );
319 }
320
321 public static function get_order_types_list_for_any_agent_logic(): array {
322 $order_types = [
323 LATEPOINT_ANY_AGENT_ORDER_RANDOM => __( 'Randomly picked agent', 'latepoint' ),
324 LATEPOINT_ANY_AGENT_ORDER_PRICE_HIGH => __( 'Most expensive agent', 'latepoint' ),
325 LATEPOINT_ANY_AGENT_ORDER_PRICE_LOW => __( 'Least expensive agent', 'latepoint' ),
326 LATEPOINT_ANY_AGENT_ORDER_BUSY_HIGH => __( 'Agent with the most bookings on that day', 'latepoint' ),
327 LATEPOINT_ANY_AGENT_ORDER_BUSY_LOW => __( 'Agent with the least bookings on that day', 'latepoint' )
328 ];
329
330 /**
331 * Get the list of order types for agent selection logic when "ANY" agent is pre-selected in the booking form
332 *
333 * @param {array} $order_types Array of order types
334 *
335 * @returns {array} Filtered array of order types
336 * @since 4.7.6
337 * @hook latepoint_get_order_types_list_for_any_agent_logic
338 *
339 */
340 return apply_filters( 'latepoint_get_order_types_list_for_any_agent_logic', $order_types );
341 }
342
343 public static function get_readable_time_format( $no_seconds = true ) {
344 $seconds = $no_seconds ? '' : ':s';
345 $format = ( self::get_time_system() == '12' ) ? "g:i$seconds a" : "G:i$seconds";
346
347 return $format;
348 }
349
350 public static function get_readable_date_format( $no_year = false ) {
351 if ( OsSettingsHelper::is_on( 'disable_verbose_date_output' ) ) {
352 return self::get_date_format();
353 }
354 $format = ( $no_year ) ? 'F j' : 'M j, Y';
355 switch ( self::get_date_format() ) {
356 case 'm/d/Y':
357 case 'm.d.Y':
358 $format = ( $no_year ) ? 'F j' : 'M j, Y';
359 break;
360 case 'd.m.Y':
361 case 'd/m/Y':
362 $format = ( $no_year ) ? 'j F' : 'j M, Y';
363 break;
364 case 'Y-m-d':
365 $format = ( $no_year ) ? 'F j' : 'Y, M j';
366 break;
367 }
368
369 return $format;
370 }
371
372
373 public static function get_booking_template_for_calendar() {
374 return OsSettingsHelper::get_settings_value( 'booking_template_for_calendar', '{{service_name}}' );
375 }
376
377
378 public static function get_selected_columns_for_bookings_table() {
379 return OsSettingsHelper::get_settings_value( 'bookings_table_columns', [] );
380 }
381
382 public static function get_available_columns_for_bookings_table() {
383 $available_columns = [];
384
385 $available_columns['customer'] = [
386 'email' => __( 'Email', 'latepoint' ),
387 'phone' => __( 'Phone', 'latepoint' )
388 ];
389
390 $available_columns['booking'] = [
391 'booking_code' => __( 'Code', 'latepoint' ),
392 'duration' => __( 'Duration', 'latepoint' ),
393 'source_id' => __( 'Source ID', 'latepoint' ),
394 'payment_method' => __( 'Payment Method', 'latepoint' ),
395 'payment_portion' => __( 'Payment Portion', 'latepoint' ),
396 'formatted_price' => __( 'Price', 'latepoint' )
397 ];
398
399 $available_columns = apply_filters( 'latepoint_bookings_table_columns', $available_columns );
400
401 return $available_columns;
402 }
403
404 public static function force_bite( $request ) {
405 }
406
407 public static function read_encoded( $str ) {
408 return base64_decode( $str );
409 }
410
411 public static function get_db_version() {
412 return get_option( 'latepoint_db_version' );
413 }
414
415 public static function force_release( $request ) {
416 }
417
418 public static function is_enabled_show_dial_code_with_flag() {
419 return ( self::get_settings_value( 'show_dial_code_with_flag', LATEPOINT_VALUE_ON ) == LATEPOINT_VALUE_ON );
420 }
421
422 public static function is_using_google_login() {
423 return self::is_on( 'enable_google_login' );
424 }
425
426 public static function is_using_facebook_login() {
427 return self::is_on( 'enable_facebook_login' );
428 }
429
430 public static function is_using_social_login() {
431 return ( self::is_using_google_login() || self::is_using_facebook_login() );
432 }
433
434 public static function get_steps_support_text() {
435 $default = '<h5>Questions?</h5><p>Call (858) 939-3746 for help</p>';
436
437 return self::get_settings_value( 'steps_support_text', $default );
438 }
439
440 public static function get_default_fields_for_customer() {
441 $default_fields = [
442 'first_name' => [ 'locked' => false, 'label' => __( 'First Name', 'latepoint' ), 'required' => true, 'width' => 'os-col-6', 'active' => true ],
443 'last_name' => [ 'locked' => false, 'label' => __( 'Last Name', 'latepoint' ), 'required' => true, 'width' => 'os-col-6', 'active' => true ],
444 'email' => [ 'locked' => true, 'label' => __( 'Email Address', 'latepoint' ), 'required' => true, 'width' => 'os-col-6', 'active' => true ],
445 'phone' => [ 'locked' => false, 'label' => __( 'Phone Number', 'latepoint' ), 'required' => false, 'width' => 'os-col-6', 'active' => true ],
446 'notes' => [ 'locked' => false, 'label' => __( 'Comments', 'latepoint' ), 'required' => false, 'width' => 'os-col-12', 'active' => true ]
447 ];
448
449 $fields_from_db = OsSettingsHelper::get_settings_value( 'default_fields_for_customer', '' );
450 $fields_from_db_arr = json_decode( $fields_from_db, true );
451 if ( $fields_from_db_arr ) {
452 foreach ( $fields_from_db_arr as $name => $field_from_db ) {
453 if ( isset( $default_fields[ $name ] ) ) {
454 $default_fields[ $name ] = $field_from_db;
455 }
456 }
457 }
458 $default_fields = apply_filters( 'latepoint_default_fields_for_customer', $default_fields );
459
460 return $default_fields;
461 }
462
463 public static function remove_setting_by_name( $name ) {
464 $settings_model = new OsSettingsModel();
465 $settings_model = $settings_model->delete_where( array( 'name' => $name ) );
466 self::reset_loaded_value( $name );
467 }
468
469 public static function save_setting_by_name( $name, $value ) {
470 $settings_model = new OsSettingsModel();
471 $settings_model = $settings_model->where( array( 'name' => $name ) )->set_limit( 1 )->get_results_as_models();
472 if ( $settings_model ) {
473 $settings_model->value = self::prepare_value( $name, $value );
474 } else {
475 $settings_model = new OsSettingsModel();
476 $settings_model->name = $name;
477 $settings_model->value = self::prepare_value( $name, $value );
478 }
479 self::reset_loaded_value( $name );
480
481 return $settings_model->save();
482 }
483
484 public static function reset_loaded_value( $name ) {
485 unset( self::$loaded_values[ $name ] );
486 }
487
488 public static function prepare_value( $name, $value ) {
489 if ( in_array( $name, self::get_encrypted_settings() ) ) {
490 $value = OsEncryptHelper::encrypt_value( $value );
491 }
492 if ( is_array( $value ) ) {
493 $value = maybe_serialize( $value );
494 }
495
496 return $value;
497 }
498
499 public static function get_settings_value( $name, $default = false ) {
500 if ( isset( self::$loaded_values[ $name ] ) ) {
501 return self::$loaded_values[ $name ];
502 }
503 $settings_model = new OsSettingsModel();
504 $settings_model = $settings_model->where( array( 'name' => $name ) )->set_limit( 1 )->get_results_as_models();
505 if ( $settings_model ) {
506 if ( in_array( $name, self::get_encrypted_settings() ) ) {
507 $value = OsEncryptHelper::decrypt_value( $settings_model->value );
508 } else {
509 $value = maybe_unserialize( $settings_model->value );
510 }
511 } else {
512 $value = $default;
513 }
514 self::$loaded_values[ $name ] = $value;
515
516 return self::$loaded_values[ $name ];
517 }
518
519
520 public static function get_any_agent_order() {
521 return self::get_settings_value( 'any_agent_order', LATEPOINT_ANY_AGENT_ORDER_RANDOM );
522 }
523
524 public static function get_day_calendar_min_height() {
525 $height = preg_replace( '/\D/', '', self::get_settings_value( 'day_calendar_min_height', 700 ) );
526 if ( ! $height ) {
527 $height = 700;
528 }
529
530 return $height;
531 }
532
533 public static function get_default_timeblock_interval() {
534 $timeblock_interval = self::get_settings_value( 'timeblock_interval', LATEPOINT_DEFAULT_TIMEBLOCK_INTERVAL );
535 if ( empty( $timeblock_interval ) ) {
536 $timeblock_interval = LATEPOINT_DEFAULT_TIMEBLOCK_INTERVAL;
537 }
538
539 return intval( $timeblock_interval );
540 }
541
542 public static function get_customer_dashboard_url( $include_site_url = true ) {
543 $path = self::get_settings_value( 'page_url_customer_dashboard', '/customer-dashboard' );
544
545 return ( $include_site_url ) ? site_url( $path ) : $path;
546 }
547
548 public static function get_customer_login_url( $include_site_url = true ) {
549 $path = self::get_settings_value( 'page_url_customer_login', '/customer-login' );
550
551 return ( $include_site_url ) ? site_url( $path ) : $path;
552 }
553
554
555 // BOOKING STEPS
556
557 public static function steps_show_service_categories() {
558 return ( self::get_settings_value( 'steps_show_service_categories', 'on' ) == 'on' );
559 }
560
561 public static function steps_show_location_categories() {
562 return ( self::get_settings_value( 'steps_show_location_categories', 'on' ) == 'on' );
563 }
564
565 public static function steps_show_agent_bio() {
566 return ( self::get_settings_value( 'steps_show_agent_bio' ) == 'on' );
567 }
568
569 public static function get_booking_form_color_scheme() {
570 return self::get_settings_value( 'color_scheme_for_booking_form', 'blue' );
571 }
572
573 public static function get_booking_form_border_radius() {
574 return self::get_settings_value( 'border_radius', 'flat' );
575 }
576
577 public static function get_default_phone_country() {
578 return OsSettingsHelper::get_settings_value( 'default_phone_country', 'us' );
579 }
580
581 public static function get_included_phone_countries(): array {
582 if ( OsSettingsHelper::get_settings_value( 'list_of_phone_countries', LATEPOINT_ALL ) == LATEPOINT_ALL ) {
583 return [];
584 } else {
585 return array_map( 'trim', explode( ',', OsSettingsHelper::get_settings_value( 'included_phone_countries', '' ) ) );
586 }
587 }
588
589
590 public static function is_on( string $setting, $default = false ): bool {
591 return ( self::get_settings_value( $setting, $default ) == LATEPOINT_VALUE_ON );
592 }
593
594 public static function is_off( string $setting, $default = false ): bool {
595 return ( self::get_settings_value( $setting, $default ) != LATEPOINT_VALUE_ON );
596 }
597
598 public static function generate_default_form_fields( array $default_fields ) {
599 ?>
600 <div class="os-default-fields" data-route="<?php echo esc_attr( OsRouterHelper::build_route_name( 'form_fields', 'update_default_fields' ) ); ?>">
601 <form>
602 <?php foreach ( $default_fields as $name => $default_field ) {
603 $atts = [];
604 if ( $default_field['locked'] ) {
605 $atts['disabled'] = 'disabled';
606 }
607 ?>
608 <div class="os-default-field <?php echo $default_field['active'] ? '' : 'is-disabled'; ?>">
609 <?php
610 if ( $default_field['locked'] ) {
611 echo '<div class="locked-field"><i class="latepoint-icon latepoint-icon-lock"></i><span>' . esc_html__( 'Email Address field can not be disabled.', 'latepoint' ) . '</span></div>';
612 } else {
613 $active = $default_field['active'] ? 'on' : 'off';
614 $field_name = 'default_fields[' . $name . '][active]';
615 echo '<div class="os-toggler ' . esc_attr( $active ) . '" data-for="' . esc_attr( OsFormHelper::name_to_id( $field_name ) ) . '"><div class="toggler-rail"><div class="toggler-pill"></div></div></div>';
616 echo OsFormHelper::hidden_field( $field_name, $default_field['active'] );
617 } ?>
618 <div class="os-field-name"><?php echo esc_html( $default_field['label'] ); ?></div>
619 <div class="os-field-setting">
620 <?php echo OsFormHelper::checkbox_field( 'default_fields[' . $name . '][required]', __( 'Required?', 'latepoint' ), 'on', $default_field['required'], $atts ); ?>
621 </div>
622 <div class="os-field-setting">
623 <?php echo OsFormHelper::select_field( 'default_fields[' . $name . '][width]', false, array(
624 'os-col-12' => __( 'Full Width', 'latepoint' ),
625 'os-col-6' => __( 'Half Width', 'latepoint' )
626 ), $default_field['width'] ); ?>
627 </div>
628 </div>
629 <?php } ?>
630 </form>
631 </div>
632 <?php
633 }
634
635
636 /**
637 * Get value set for start of week in WordPress, can be from 1-7 (representing Monday-Sunday)
638 * @return mixed
639 */
640 public static function get_start_of_week(): int {
641 $wp_value = intval( get_option( 'start_of_week', 0 ) );
642
643 return $wp_value ? $wp_value : 7; // in WordPress they start count on sunday and it's 0, we are using PHP Date library that starts week on Monday and it's 1-7
644 }
645
646 public static function get_number_of_records_per_page(): int {
647 return intval( OsSettingsHelper::get_settings_value( 'number_of_records_per_page', 20 ) );
648 }
649
650 public static function can_download_records_as_csv(): bool {
651 return OsAuthHelper::is_admin_logged_in() || self::is_on( 'allow_non_admins_download_csv' );
652 }
653
654 public static function get_link_attributes_for_premium_features() : string {
655 return ' data-os-action="'.OsRouterHelper::build_route_name('settings', 'premium_modal').'" data-os-lightbox-classes="width-600" data-os-output-target="lightbox" ';
656 }
657
658 }
659
660 ?>