From 1d177f5ebf4190e51a5faa7eb7758a2834149c05 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Mon, 1 Jun 2015 22:17:33 +0200 Subject: [PATCH] Administration user : esthetic + rewrite add user Correct bug : ajax_admin.js --- include/ajax_admin.php | 2 +- include/class_user.php | 39 ++++++++++++++++++------- include/constant.php | 11 +++++--- include/user.inc.php | 64 +++++++++++++++++++++++++++--------------- 4 files changed, 78 insertions(+), 38 deletions(-) diff --git a/include/ajax_admin.php b/include/ajax_admin.php index c2baed09c..df96795c1 100644 --- a/include/ajax_admin.php +++ b/include/ajax_admin.php @@ -138,7 +138,7 @@ if ($op=='folder_display') // operation

=MAX_FOLDER_TO_SHOW)?MAX_FOLDER_TO_SHOW:$nb_dossier; echo _('Dossiers trouvés').':'.$nb_dossier." "._('Dossiers affichés').$max; ?> diff --git a/include/class_user.php b/include/class_user.php index 2e9f4088f..195d333a3 100644 --- a/include/class_user.php +++ b/include/class_user.php @@ -40,7 +40,13 @@ class User var $db; var $admin; var $valid; - + var $first_name; + var $name; + var $active ; + var $login ; + var $password ; + var $email ; + function User(&$p_cn, $p_id = -1) { // if p_id is not set then check the connected user @@ -99,13 +105,14 @@ class User $sql_array = array($this->id); } $sql = "select use_id, - use_first_name, - use_name, - use_login, - use_active, - use_admin, - use_pass - from ac_users "; + use_first_name, + use_name, + use_login, + use_active, + use_admin, + use_pass, + use_email + from ac_users "; $cn = new Database(); $Res = $cn->exec_sql($sql . $sql_cond, $sql_array); if (($Max = Database::num_row($Res)) == 0) @@ -118,15 +125,27 @@ class User $this->login = $row['use_login']; $this->admin = $row['use_admin']; $this->password = $row['use_pass']; + $this->email=$row['use_email']; } function save() { $Sql = "update ac_users set use_first_name=$1, use_name=$2 - ,use_active=$3,use_admin=$4,use_pass=$5 where use_id=$6"; + ,use_active=$3,use_admin=$4,use_pass=$5 ,use_email = $7 where use_id=$6"; $cn = new Database(); - $Res = $cn->exec_sql($Sql, array($this->first_name, $this->last_name, $this->active, $this->admin, $this->pass, $this->id)); + $Res = $cn->exec_sql($Sql, array($this->first_name, $this->last_name, $this->active, $this->admin, $this->pass, $this->id,$this->email)); + } + function insert() + { + + $Sql = "INSERT INTO ac_users( + use_first_name, use_name, use_login, use_active, use_pass, + use_admin, use_email) + VALUES ($1, $2, $3, $4, $5, $6, $7) returning use_id"; + + $cn = new Database(); + $this->id= $cn->get_value($Sql, array($this->first_name, $this->last_name, $this->login,0,0, $this->pass,$this->email)); } /** diff --git a/include/constant.php b/include/constant.php index 35b065f8a..e5e86f2f5 100644 --- a/include/constant.php +++ b/include/constant.php @@ -31,6 +31,11 @@ global $version_noalyss; */ $inc_path=get_include_path(); $dirname=dirname(__FILE__); +/* Global variable of the include dir */ +global $g_include_dir,$g_ext_dir; +$g_include_dir=$dirname; +$g_ext_dir = $dirname."/ext"; + if ( strpos($inc_path,";") != 0 ) { $new_path=$inc_path.';'.$dirname; $os=0; /* $os is 0 for windoz */ @@ -60,19 +65,17 @@ $g_failed=""; $g_succeed=""; /* uncomment for development */ -/* define ('SVNINFO',6800); define ("DEBUG",true); define ("LOGINPUT",true); - */ -define ('SVNINFO',6803); +/*define ('SVNINFO',6801); define ("DEBUG",false); define ("LOGINPUT",false); - +*/ $version_noalyss=SVNINFO; // If you don't want to be notified of the update // define ("SITE_UPDATE",''); diff --git a/include/user.inc.php b/include/user.inc.php index 85799eed6..e0842eb30 100644 --- a/include/user.inc.php +++ b/include/user.inc.php @@ -35,23 +35,27 @@ if ( isset ($_POST["ADD"]) ) { $cn=new Database(); $pass5=md5($_POST['PASS']); - - $first_name=Database::escape_string($_POST['FNAME']); - $last_name=Database::escape_string($_POST['LNAME']); - $login=$_POST['LOGIN']; + $new_user=new User($cn,0); + $new_user->first_name=HtmlInput::default_value_post('FNAME',''); + $new_user->last_name=HtmlInput::default_value_post('LNAME',''); + $login=HtmlInput::default_value_post('LOGIN',''); $login=str_replace("'","",$login); $login=str_replace('"',"",$login); $login=str_replace(" ","",$login); $login=strtolower($login); + $new_user->login=$login; + $new_user->email=HtmlInput::default_value_post('EMAIL',''); if ( trim($login)=="") { alert("Le login ne peut pas être vide"); } else { - $Res=$cn->exec_sql("insert into ac_users(use_first_name,use_name,use_login,use_active,use_pass) - values ($1,$2,$3,1,$4)", - array($first_name,$last_name,$login,$pass5)); + $new_user->insert(); + $new_user->load(); + $_REQUEST['use_id']=$new_user->id; + require_once("user_detail.inc.php"); + return; } } //SET login @@ -65,30 +69,44 @@ if ( isset($_REQUEST['det'])) } ?> -