From a76991ce11738cbd2da25698a1f6cb39136f36d0 Mon Sep 17 00:00:00 2001 From: Browniebraun Date: Mon, 4 Apr 2016 22:08:01 +0200 Subject: [PATCH] take care of user defined language (see: user profile) --- auth_profile.php | 1 + include/global.php | 3 +- include/global_languages.php | 68 +++++++++++++++++++++++++++--------- include/global_settings.php | 6 ++-- 4 files changed, 57 insertions(+), 21 deletions(-) diff --git a/auth_profile.php b/auth_profile.php index 7bff76e04c..eb69aed4d7 100644 --- a/auth_profile.php +++ b/auth_profile.php @@ -116,6 +116,7 @@ function form_save() { raise_message(1); /* reset local settings cache so the user sees the new settings */ + kill_session_var('sess_user_language'); kill_session_var('sess_graph_config_array'); } diff --git a/include/global.php b/include/global.php index 435fa5df4d..4ed10c720a 100644 --- a/include/global.php +++ b/include/global.php @@ -152,7 +152,6 @@ /* include additional modules */ include_once($config['library_path'] . '/functions.php'); include_once($config['include_path'] . '/global_constants.php'); -include_once($config['include_path'] . '/global_languages.php'); if ((isset($no_http_headers) && $no_http_headers == true) || in_array(basename($_SERVER['PHP_SELF']), $no_http_header_files, true)) { $is_web = false; @@ -234,6 +233,8 @@ function addslashes_deep($value) { /* gather the existing cactidb version */ $config['cacti_db_version'] = db_fetch_cell("SELECT cacti FROM version LIMIT 1"); +include_once($config['include_path'] . '/global_languages.php'); + include_once($config['library_path'] . '/auth.php'); include_once($config['library_path'] . '/plugins.php'); include_once($config['include_path'] . '/plugins.php'); diff --git a/include/global_languages.php b/include/global_languages.php index f77f2cfe7c..5db0a716aa 100644 --- a/include/global_languages.php +++ b/include/global_languages.php @@ -47,7 +47,7 @@ { $cacti_locale = $_GET['language']; $cacti_country = $lang2locale[$_GET['language']]['country']; - $_SESSION['sess_i18n_language'] = $cacti_locale; + $_SESSION['sess_user_language'] = $cacti_locale; unset($_SESSION['sess_current_date1']); unset($_SESSION['sess_current_date2']); @@ -56,24 +56,22 @@ } /* language definition stored in the SESSION */ -elseif (isset($_SESSION['sess_i18n_language']) && isset($lang2locale[$_SESSION['sess_i18n_language']])) +elseif (isset($_SESSION['sess_user_language']) && isset($lang2locale[$_SESSION['sess_user_language']])) { - $cacti_locale = $_SESSION['sess_i18n_language']; - $cacti_country = $lang2locale[$_SESSION['sess_i18n_language']]['country']; + $cacti_locale = $_SESSION['sess_user_language']; + $cacti_country = $lang2locale[$_SESSION['sess_user_language']]['country']; } - -#elseif ($user_locale = read_user_setting('language')) +elseif ($user_locale = read_user_i18n_setting('user_language')) /* look up for user customized language setting stored in Cacti DB */ -#{ -# if (isset($lang2locale[$user_locale])) -# { -# $cacti_locale = $user_locale; -# $cacti_country = $lang2locale[$cacti_locale]['country']; -# $_SESSION['sess_i18n_language'] = $cacti_locale; -# } - -#} +{ + if (isset($lang2locale[$user_locale])) + { + $cacti_locale = $user_locale; + $cacti_country = $lang2locale[$cacti_locale]['country']; + $_SESSION['sess_user_language'] = $cacti_locale; + } +} elseif ( isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && ( read_config_option('i18n_auto_detection') | read_config_option('i18n_auto_detection') == '' ) ) /* detect browser settings if auto detection is enabled */ { @@ -192,7 +190,7 @@ function load_fallback_procedure(){ load_i18n_fallback_wrappers(); /* reset variables */ - $_SESSION['sess_i18n_language'] = ''; + $_SESSION['sess_user_language'] = ''; $cacti_textdomains = array(); define('CACTI_LOCALE', 'en'); @@ -442,7 +440,6 @@ function get_list_of_locales () { return $lang2locale; } - /** * get_installed_locales - finds all installed locales * @@ -472,4 +469,41 @@ function get_installed_locales(){ return $supported_languages; } +/* read_user_i18n_setting - finds the current value of a i18n configuration setting + @arg $config_name - the name of the configuration setting as specified $settings_user array + in 'include/global_settings.php' + @returns - the current value of the i18n configuration option or the system default value */ +function read_user_i18n_setting($config_name) { + global $config; + + /* users must have cacti user auth turned on to use this, or the guest account must be active */ + if (isset($_SESSION['sess_user_id'])) { + $effective_uid = $_SESSION['sess_user_id']; + }else if (isset($config['config_options_array']['export_user_id'])) { + $effective_uid = $config['config_options_array']['export_user_id']; + }else if ((read_config_option('auth_method') == 0)) { + if (isset($_SESSION['sess_config_array'])) { + $config_array = $_SESSION['sess_config_array']; + }else if (isset($config['config_options_array'])) { + $config_array = $config['config_options_array']; + } + if (!isset($config_array[$config_name])) { + $effective_uid = db_fetch_cell_prepared("SELECT user_auth.id from settings INNER JOIN user_auth ON user_auth.username = settings.value WHERE settings.name = 'guest_user'"); + } + if (strlen($effective_uid) == 0) { + $effective_uid = 0; + } + }else{ + $effective_uid = 0; + } + + $db_setting = db_fetch_row_prepared('SELECT value FROM settings_user WHERE name = ? AND user_id = ?', array($config_name, $effective_uid)); + + if (isset($db_setting['value'])) { + return $db_setting['value']; + }else{ + return false; + } +} + diff --git a/include/global_settings.php b/include/global_settings.php index 80f9bb7f53..4bd26d608f 100644 --- a/include/global_settings.php +++ b/include/global_settings.php @@ -1717,9 +1717,9 @@ 'array' => $graph_views, 'default' => '1' ), - 'default_language' => array( - 'friendly_name' => __('Default Language'), - 'description' => __('Default language for this system.'), + 'user_language' => array( + 'friendly_name' => __('User Language'), + 'description' => __('Defines the preferred GUI language.'), 'method' => 'drop_array', 'default' => 'us', 'array' => get_installed_locales()