Skip to content

Commit

Permalink
take care of user defined language (see: user profile)
Browse files Browse the repository at this point in the history
  • Loading branch information
browniebraun committed Apr 4, 2016
1 parent c4f3205 commit a76991c
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 21 deletions.
1 change: 1 addition & 0 deletions auth_profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
3 changes: 2 additions & 1 deletion include/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand Down
68 changes: 51 additions & 17 deletions include/global_languages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);

Expand All @@ -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 */
{
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -442,7 +440,6 @@ function get_list_of_locales () {
return $lang2locale;
}


/**
* get_installed_locales - finds all installed locales
*
Expand Down Expand Up @@ -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;
}
}


6 changes: 3 additions & 3 deletions include/global_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit a76991c

Please sign in to comment.