Administration user : esthetic + rewrite add user

Correct bug : ajax_admin.js
This commit is contained in:
Dany De Bontridder 2015-06-01 22:17:33 +02:00
parent 2ee973fe7e
commit 1d177f5ebf
4 changed files with 78 additions and 38 deletions

View file

@ -138,7 +138,7 @@ if ($op=='folder_display') // operation
</form>
<p>
<?php
$found_dossier=count($a_dossier);
$nb_dossier=count($a_dossier);
$max=( $nb_dossier>=MAX_FOLDER_TO_SHOW)?MAX_FOLDER_TO_SHOW:$nb_dossier;
echo _('Dossiers trouvés').':'.$nb_dossier." "._('Dossiers affichés').$max;
?>

View file

@ -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));
}
/**

View file

@ -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="<span style=\"font-size:18px;color:red\">&#x2716;</span>";
$g_succeed="<span style=\"font-size:18px;color:green\">&#x2713;</span>";
/* 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",'');

View file

@ -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']))
}
?>
<div id="create_user" style="display:none">
<h2>Gestion Utilisateurs</h2>
<TABLE> <TR>
<form action="admin_repo.php?action=user_mgt" method="POST">
<TD><H3>
<?php
echo _("Ajout d'utilisateur");
echo '<H3></TD></TR>';
echo '<TR><TD> First Name </TD><TD><INPUT class="input_text" TYPE="TEXT" NAME="FNAME"></TD>';
echo '<TD> Last Name </TD><TD><INPUT class="input_text" TYPE="TEXT" NAME="LNAME"></TD></TR>';
echo '<TR><TD> login </TD><TD><INPUT class="input_text" TYPE="TEXT" NAME="LOGIN"></TD>';
echo '<TD> password </TD><TD> <INPUT class="input_text" TYPE="TEXT" NAME="PASS"></TD></TR>';
echo '</TABLE>';
<div id="create_user" style="display:none;width:30%;margin-right: 20%" class="inner_box">
<?php echo HtmlInput::title_box(_('Ajout Utilisateur'),"create_user","hide");?>
<form action="admin_repo.php?action=user_mgt" method="POST" onsubmit="return check_form()">
<div style="text-align: center">
<TABLE class="result" >
<TR><TD style="text-align: right"> <?php echo _('login')?></TD><TD><INPUT id="input_login" class="input_text" TYPE="TEXT" NAME="LOGIN"></TD></tr>
<TR><TD style="text-align: right"> <?php echo _('Prénom')?></TD><TD><INPUT class="input_text" TYPE="TEXT" NAME="FNAME"></TD></tr>
<TR><TD style="text-align: right"> <?php echo _('Nom')?></TD><TD><INPUT class="input_text" TYPE="TEXT" NAME="LNAME"></TD></TR>
<TR><TD style="text-align: right"> <?php echo _('Mot de passe')?></TD><TD> <INPUT id="input_password" class="input_text" TYPE="TEXT" NAME="PASS"></TD></TR>
<TR><TD style="text-align: right"> <?php echo _('Email')?></TD><TD> <INPUT class="input_text" TYPE="TEXT" NAME="EMAIL"></TD></TR>
</TABLE>
<?php
echo HtmlInput::submit("ADD",'Créer Utilisateur');
echo HtmlInput::button_action("Fermer", "$('create_user').style.display='none';$('cu').style.display='block'");
echo HtmlInput::button_action("Fermer", "$('create_user').style.display='none';");
?>
</div>
</FORM>
<script>
function check_form() {
if ($F('input_login') == "") {
alert('<?php echo _('Le login ne peut être vide') ?>');
$('input_login').setStyle({border:"red solid 2px"});
return false;
}
if ($F('input_password') == "") {
alert('<?php echo _('Le mot de passe ne peut être vide') ?>');
$('input_password').setStyle({border:"red solid 2px"});
return false;
}
return true;
}
</script>
</div>
<?php
echo '<p>';
echo HtmlInput::button_action("Ajout utilisateur", "$('create_user').show();$('cu').hide()","cu");
echo HtmlInput::button_action("Ajout utilisateur", "$('create_user').show();","cu");
echo '</p>';
// Show all the existing user on 7 columns
$repo=new Dossier(0);