Commit a568bcb3 authored by Jean-Philippe Levy's avatar Jean-Philippe Levy

Add user language feature

parent 0842a839
......@@ -38,8 +38,22 @@ class Translator
*/
public function __construct()
{
global $database_eonweb;
$lang = 0;
// # Languages files
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
// Check if user default lang is defined
if(isset($_COOKIE['user_id'])){
$lang = mysqli_result(sqlrequest($database_eonweb,"select user_language from users where user_id='".$_COOKIE['user_id']."'"),0);
}
// Check if isset browser lang
if($lang) {
$GLOBALS['langformat']=$lang;
}
elseif(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
// Language detection
$lang = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
......
......@@ -727,7 +727,7 @@ function ldap_escape ($str){
}
// User creation
function insert_user($user_name, $user_descr, $user_group, $user_password1, $user_password2, $user_type, $user_location, $user_mail, $user_limitation, $message, $in_nagvis = false, $in_cacti = false, $nagvis_group){
function insert_user($user_name, $user_descr, $user_group, $user_password1, $user_password2, $user_type, $user_location, $user_mail, $user_limitation, $message, $in_nagvis = false, $in_cacti = false, $nagvis_group = false, $user_language = false){
global $database_host;
global $database_cacti;
global $database_username;
......@@ -762,7 +762,7 @@ function insert_user($user_name, $user_descr, $user_group, $user_password1, $use
$user_password = md5($user_password1);
// Insert into eonweb
sqlrequest("$database_eonweb","INSERT INTO users (user_name,user_descr,group_id,user_passwd,user_type,user_location,user_limitation) VALUES('$user_name', '$user_descr', '$user_group', '$user_password', '$user_type', '$user_location','$user_limitation')");
sqlrequest("$database_eonweb","INSERT INTO users (user_name,user_descr,group_id,user_passwd,user_type,user_location,user_limitation,user_language) VALUES('$user_name', '$user_descr', '$user_group', '$user_password', '$user_type', '$user_location', '$user_limitation', '$user_language')");
$user_id=mysqli_result(sqlrequest("$database_eonweb","SELECT user_id FROM users WHERE user_name='$user_name'"),0,"user_id");
$group_name=mysqli_result(sqlrequest("$database_eonweb","SELECT group_name FROM groups WHERE group_id='$user_group'"),0,"group_name");
......
......@@ -125,6 +125,10 @@
"label.admin_user.user_cacti": "Utilisateur Cacti",
"label.admin_user.user_desc": "Description de l'utilisateur",
"label.admin_user.user_group": "Groupe",
"label.admin_user.user_lang": "Choisir une langue",
"label.admin_user.user_lang_en": "Anglais",
"label.admin_user.user_lang_fr": "Français",
"label.admin_user.user_lang_0": "Langue du navigateur",
"label.admin_user.user_ldap": "Utilisateur LDAP",
"label.admin_user.user_limit": "Utilisateur limité",
"label.admin_user.user_mail": "Email de l'utilisateur",
......
......@@ -125,6 +125,10 @@
"label.admin_user.user_cacti": "Cacti user",
"label.admin_user.user_desc": "User description",
"label.admin_user.user_group": "Group",
"label.admin_user.user_lang": "Choose a language",
"label.admin_user.user_lang_en": "English",
"label.admin_user.user_lang_fr": "French",
"label.admin_user.user_lang_0": "Browser language",
"label.admin_user.user_ldap": "LDAP user",
"label.admin_user.user_limit": "User limited",
"label.admin_user.user_mail": "User mail",
......
......@@ -36,13 +36,52 @@ include("../../side.php");
function retrieve_user_info($user_id)
{
global $database_eonweb;
return sqlrequest("$database_eonweb","SELECT user_name, user_descr, group_id, user_passwd, user_type, user_location, user_limitation FROM users WHERE user_id='$user_id'");
return sqlrequest("$database_eonweb","SELECT user_name, user_descr, group_id, user_passwd, user_type, user_location, user_limitation, user_language FROM users WHERE user_id='$user_id'");
}
// Display user language selection
function GetUserLang() {
global $database_eonweb;
global $user_id;
global $path_languages;
// definition of variables and Research language files
$path_label_lang = "label.admin_user.user_lang_";
$files = array('en');
$handler = opendir($path_languages);
while ($file = readdir($handler)) {
if(preg_match('#messages-(.+).json#', $file, $matches)){
$files[] = $matches[1];
}
}
closedir($handler);
$files = array_filter($files);
array_unshift($files,"0");
$files = array_unique($files);
// creation of a select and catch values
$langtmp = mysqli_result(sqlrequest("$database_eonweb","SELECT user_language FROM users WHERE user_id='".$user_id."'"),0);
$res = '<select class="form-control" name="user_language">';
foreach($files as $v) {
if($v == $langtmp){
$res.="<option value='".$v."' selected=selected>".getLabel($path_label_lang.$v)."</option>";
}
else{
$res.="<option value='".$v."'>".getLabel($path_label_lang.$v)."</option>";
}
}
$res .= '</select>';
return $res;
}
//--------------------------------------------------------
// Update User Information & Right
function update_user($user_id, $user_name, $user_descr, $user_group, $user_password1, $user_password2 ,$user_type, $user_location, $user_mail, $user_limitation, $old_group_id, $old_name, $create_user_in_nagvis, $create_user_in_cacti, $nagvis_role_id)
function update_user($user_id, $user_name, $user_descr, $user_group, $user_password1, $user_password2 ,$user_type, $user_location, $user_mail, $user_limitation, $old_group_id, $old_name, $create_user_in_nagvis, $create_user_in_cacti, $nagvis_role_id, $user_language)
{
global $database_host;
global $database_cacti;
......@@ -72,11 +111,11 @@ include("../../side.php");
if ($user_password1 != "abcdefghijklmnopqrstuvwxyz") {
$passwd_temp = md5($user_password1);
// Update into eonweb
sqlrequest("$database_eonweb","UPDATE users set user_name='$user_name', user_descr='$user_descr',group_id='$user_group',user_passwd='$passwd_temp',user_type='$user_type',user_location='$user_location',user_limitation='$user_limitation' WHERE user_id ='$user_id'");
sqlrequest("$database_eonweb","UPDATE users set user_name='$user_name', user_descr='$user_descr',group_id='$user_group',user_passwd='$passwd_temp',user_type='$user_type',user_location='$user_location',user_limitation='$user_limitation',user_language='$user_language' WHERE user_id ='$user_id'");
}
else {
// Update into eonweb
sqlrequest("$database_eonweb","UPDATE users set user_name='$user_name', user_descr='$user_descr',group_id='$user_group',user_type='$user_type',user_location='$user_location',user_limitation='$user_limitation' WHERE user_id ='$user_id'");
sqlrequest("$database_eonweb","UPDATE users set user_name='$user_name', user_descr='$user_descr',group_id='$user_group',user_type='$user_type',user_location='$user_location',user_limitation='$user_limitation',user_language='$user_language' WHERE user_id ='$user_id'");
}
// Update into lilac
......@@ -181,6 +220,7 @@ include("../../side.php");
$user_group = retrieve_form_data("user_group","");
$user_type = retrieve_form_data("user_type","");
$user_limitation = retrieve_form_data("user_limitation","");
$user_language = retrieve_form_data("user_language","");
$old_group_id = mysqli_result(sqlrequest($database_eonweb,"select group_id from users where user_id='$user_id'"),0,"group_id");
$old_name = retrieve_form_data("user_name_old","");
......@@ -225,7 +265,7 @@ include("../../side.php");
$user_group = retrieve_form_data("user_group","");
$nagvis_grp = retrieve_form_data("nagvis_group", "");
$user_id=insert_user(stripAccents($user_name), $user_descr, $user_group, $user_password1, $user_password2, $user_type, $user_location,$user_mail,$user_limitation, true, $create_user_in_nagvis, $create_user_in_cacti, $nagvis_grp);
$user_id=insert_user(stripAccents($user_name), $user_descr, $user_group, $user_password1, $user_password2, $user_type, $user_location,$user_mail,$user_limitation, true, $create_user_in_nagvis, $create_user_in_cacti, $nagvis_grp, $user_language);
//message(8,"User location: $user_location",'ok'); // For debug pupose, to be removed
// Retrieve Group Information from database
......@@ -237,6 +277,7 @@ include("../../side.php");
$user_group=mysqli_result($user_name_descr,0,"group_id");
$user_type=mysqli_result($user_name_descr,0,"user_type");
$user_limitation = retrieve_form_data("user_limitation","");
$user_language = retrieve_form_data("user_language","");
$user_location=mysqli_result($user_name_descr,0,"user_location");
$user_password1= "abcdefghijklmnopqrstuvwxyz";
$user_password2= "abcdefghijklmnopqrstuvwxyz";
......@@ -256,7 +297,7 @@ include("../../side.php");
// ACCOUNT UPDATE (and retrieve parameters)
//------------------------------------------------------------------------------------------------
if (isset($_POST['update'])){
update_user($user_id, stripAccents($user_name), $user_descr, $user_group, $user_password1, $user_password2, $user_type, $user_location, $user_mail, $user_limitation, $old_group_id, $old_name, $create_user_in_nagvis, $create_user_in_cacti, $nagvis_role_id);
update_user($user_id, stripAccents($user_name), $user_descr, $user_group, $user_password1, $user_password2, $user_type, $user_location, $user_mail, $user_limitation, $old_group_id, $old_name, $create_user_in_nagvis, $create_user_in_cacti, $nagvis_role_id, $user_language);
//message(8,"Update: User location = $user_location",'ok'); // For debug pupose, to be removed
//message(8,"Update: User name = $user_name",'ok'); // For debug pupose, to be removed
}
......@@ -390,6 +431,15 @@ include("../../side.php");
</div>
</div>
<!-- Adding a language defined by user -->
<div class="row form-group">
<label class="col-md-3"><?php echo getLabel("label.admin_user.user_lang"); ?></label>
<div class="col-md-9">
<?php echo GetUserLang(); ?>
</div>
</div>
<!-- If not user admin -->
<?php if($user_id!="1") { ?>
<div class="row form-group">
<label class="col-md-3"><?php echo getLabel("label.admin_user.user_group"); ?></label>
......@@ -447,7 +497,7 @@ include("../../side.php");
?>
</div>
</div>
<?php } ?>
<div class="form-group">
<?php
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment