diff --git a/html/admin/sql/patch/ac-upgrade6.sql b/html/admin/sql/patch/ac-upgrade6.sql
index 1b42fd72c..0c9a6f774 100644
--- a/html/admin/sql/patch/ac-upgrade6.sql
+++ b/html/admin/sql/patch/ac-upgrade6.sql
@@ -9,6 +9,7 @@ comment on column user_global_pref.user_id is 'user''s login ';
comment on column user_global_pref.parameter_type is 'the type of parameter ';
comment on column user_global_pref.parameter_value is 'the value of parameter ';
+alter table user_global_pref add constraint fk_user_id foreign key (user_id) references ac_users(use_login) on delete cascade on update cascade;
alter table user_global_pref add constraint pk_user_global_pref primary key (user_id,parameter_type);
insert into user_global_pref select use_login,'PAGESIZE','50' from ac_users;
diff --git a/html/admin_repo.php b/html/admin_repo.php
index 6efcb9d29..4e2cc7bc9 100644
--- a/html/admin_repo.php
+++ b/html/admin_repo.php
@@ -52,10 +52,8 @@ if ( isset ($_GET["action"]) ) {
if ( isset ($_POST["LOGIN"]) ) {
$cn=DbConnect();
$pass5=md5($_POST['PASS']);
- $Res=ExecSql($cn,"insert into ac_users(use_first_name,use_name,use_login,use_active,use_pass
- ,use_usertype)
- values ('".$_POST["FNAME"]."','".$_POST["LNAME"]."','".$_POST["LOGIN"]."',1,'$pass5',
- 'user')");
+ $Res=ExecSql($cn,"insert into ac_users(use_first_name,use_name,use_login,use_active,use_pass)
+ values ('".$_POST["FNAME"]."','".$_POST["LNAME"]."','".$_POST["LOGIN"]."',1,'$pass5')");
} //SET login
// Show all the existing user on 7 columns
diff --git a/html/user_pref.php b/html/user_pref.php
index 579f58d4d..4ea923927 100644
--- a/html/user_pref.php
+++ b/html/user_pref.php
@@ -29,16 +29,20 @@ $User=new cl_user($cn);
$User->Check();
// Met a jour le theme utilisateur (style)
if ( isset ( $_POST['style_user']) ) {
- $Res=ExecSql($Rep,
- "update user_global_pref set parameter_value='".$_POST['style_user'].
- "' where user_id='".$_SESSION['g_user']."' and parameter_type='THEME'");
- // echo '
Theme utilisateur changé ';
+ $User->update_global_pref('THEME',$_POST['style_user']);
$_SESSION['g_theme']=$_POST['style_user'];
}
html_page_start($_SESSION['g_theme']);
+// Met a jour le pagesize
+if ( isset ( $_POST['p_size']) ) {
+ $User->update_global_pref('PAGESIZE',$_POST['p_size']);
+ $_SESSION['g_pagesize']=$_POST['p_size'];
+
+}
+
// show the top menu depending of the use_style
// comta style
@@ -136,6 +140,27 @@ if ( isset ($_SESSION['g_dossier']) ) {
+ Taille des pages
+
+
}
diff --git a/include/class_user.php b/include/class_user.php
index 6698f91f2..cdd32ac43 100644
--- a/include/class_user.php
+++ b/include/class_user.php
@@ -106,7 +106,6 @@ class cl_user {
$_SESSION['use_name']=$r['use_name'];
$_SESSION['use_first_name']=$r['use_first_name'];
- $this->theme=$_SESSION['g_theme'];
$this->admin=$_SESSION['use_admin'];
$this->name=$_SESSION['use_name'];
$this->first_name=$_SESSION['use_first_name'];
@@ -281,13 +280,18 @@ function GetPreferences ()
function GetGlobalPref()
{
+ echo_debug(__FILE__,__LINE__,"function GetGlobalPref");
$cn=Dbconnect();
// Load everything in an array
$Res=ExecSql ($cn,"select parameter_type,parameter_value from
user_global_pref
where user_id='".$this->id."'");
$Max=pg_NumRows($Res);
- if ( $Max == 0 ) return null;
+ if ( $Max == 0 ) {
+ $this->insert_default_global_pref();
+ $this->GetGlobalPref();
+ return;
+ }
// Load value into array
$line=array();
for ($i=0;$i<$Max;$i++) {
@@ -298,8 +302,73 @@ function GetGlobalPref()
// save array into g_ variable
$array_pref=array ('g_theme'=>'THEME','g_pagesize'=>'PAGESIZE');
foreach ($array_pref as $name=>$parameter ) {
+ if ( ! isset ($line[$parameter]) ) {
+ echo_debug("Missing pref : ".$parameter);
+ $this->insert_default_global_pref($parameter);
+ $this->GetGlobalPref();
+ return;
+ }
$_SESSION[$name]=$line[$parameter];
}
}
+
+/* function insert_default_global_pref
+ **************************************************
+ * Purpose : insert default pref
+ * if no parameter are given insert all the existing
+ * parameter otherwise only the requested
+ * parm :
+ * - parameter's type or nothing
+ * gen :
+ * - none
+ * return: nothing
+ */
+function insert_default_global_pref($p_type="",$p_value="") {
+ echo_debug(__FILE__,__LINE__,"function insert_default_global_pref");
+ echo_debug(__FILE__,__LINE__,"parameter p_type $p_type p_value $p_value");
+
+ $default_parameter= array("THEME"=>"Light",
+ "PAGESIZE"=>"50");
+ $cn=Dbconnect();
+ $Sql="insert into user_global_pref(user_id,parameter_type,parameter_value)
+ values ('%s','%s','%s')";
+ if ( $p_type == "" ) {
+ foreach ( $default_parameter as $name=>$value) {
+ $Insert=sprintf($Sql,$this->id,$name,$value);
+ ExecSql($cn,$Insert);
+ }
+ }
+ else {
+ $value=($p_value=="")?$default_parameter[$p_type]:$p_value;
+ $Insert=sprintf($Sql,$this->id,$p_type,$value);
+ ExecSql($cn,$Insert);
+ }
+
+
+}
+
+/* function update_global_pref
+ **************************************************
+ * Purpose : update default pref
+ * if value is not given then use the default value
+ * parm :
+ * - parameter's type
+ * - parameter's value value of the type
+ * gen :
+ * - none
+ * return: nothing
+ */
+function update_global_pref($p_type,$p_value="") {
+ $default_parameter= array("THEME"=>"Light",
+ "PAGESIZE"=>"50");
+ $cn=Dbconnect();
+ $Sql="update user_global_pref set parameter_value='%s'
+ where parameter_type='%s' and
+ user_id='%s'";
+ $value=($p_value=="")?$default_parameter[$p_type]:$p_value;
+ $Update=sprintf($Sql,$value,$p_type,$this->id);
+ ExecSql($cn,$Update);
+
+ }//end function
}
?>