Files
dolibarr/htdocs/user/fiche.php
Rodolphe Quiedeville f13c30263c synchro
2004-02-13 17:36:27 +00:00

434 lines
14 KiB
PHP
Raw Blame History

<?PHP
/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*/
require("./pre.inc.php");
$form = new Form($db);
if ($_GET["subaction"] == 'addrights' && $user->admin)
{
$edituser = new User($db,$_GET["id"]);
$edituser->addrights($_GET["rights"]);
}
if ($_GET["subaction"] == 'delrights' && $user->admin)
{
$edituser = new User($db,$_GET["id"]);
$edituser->delrights($_GET["rights"]);
}
if ($HTTP_POST_VARS["action"] == 'confirm_delete' && $HTTP_POST_VARS["confirm"] == "yes")
{
if ($id <> $user->id)
{
$edituser = new User($db, $id);
$edituser->fetch($id);
$edituser->delete();
Header("Location: index.php");
}
}
if ($HTTP_POST_VARS["action"] == 'add' && $user->admin)
{
$edituser = new User($db,0);
$edituser->nom = $HTTP_POST_VARS["nom"];
$edituser->note = $HTTP_POST_VARS["note"];
$edituser->prenom = $HTTP_POST_VARS["prenom"];
$edituser->login = $HTTP_POST_VARS["login"];
$edituser->email = $HTTP_POST_VARS["email"];
$edituser->admin = $HTTP_POST_VARS["admin"];
$edituser->webcal_login = $HTTP_POST_VARS["webcal_login"];
$id = $edituser->create();
if (isset($_POST['password']) && $_POST['password']!='' )
{
$edituser->password($_POST['password'],$conf->password_encrypted);
}
}
if ($_POST["action"] == 'update' && $user->admin)
{
$edituser = new User($db, $id);
$edituser->fetch();
$edituser->nom = $_POST["nom"];
$edituser->note = $_POST["note"];
$edituser->prenom = $_POST["prenom"];
$edituser->login = $_POST["login"];
$edituser->email = $_POST["email"];
$edituser->admin = $_POST["admin"];
$edituser->webcal_login = $_POST["webcal_login"];
if (! $edituser->update())
{
print $edituser->error();
}
if (isset($password) && $password !='' )
{
$edituser->password($password,$conf->password_encrypted);
}
}
if ($action == 'password' && $user->admin)
{
$edituser = new User($db, $id);
$edituser->fetch();
if ($edituser->password('',$conf->password_encrypted))
{
$message = "Mot de passe chang<6E> et envoy<6F> <20> $edituser->email";
}
}
llxHeader();
/* ************************************************************************** */
/* */
/* Nouvel utilisateur */
/* */
/* ************************************************************************** */
if ($action == 'create')
{
print '<div class="titre">Nouvel utilisateur</div><br>';
print '<form action="'.$PHP_SELF.'" method="post">';
print '<input type="hidden" name="action" value="add">';
print '<table class="border" width="100%" cellpadding="3" cellspacing="0">';
print '<tr><td valign="top" width="20%">Pr<50>nom</td>';
print '<td class="valeur"><input size="30" type="text" name="prenom" value=""></td></tr>';
print "<tr>".'<td valign="top">Nom</td>';
print '<td class="valeur"><input size="30" type="text" name="nom" value=""></td></tr>';
print "<tr>".'<td valign="top">Login</td>';
print '<td class="valeur"><input size="20" type="text" name="login" value=""></td></tr>';
print "<tr>".'<td valign="top">Password</td>';
print '<td class="valeur"><input size="30" type="text" name="password" value=""></td></tr>';
print "<tr>".'<td valign="top">Email</td>';
print '<td class="valeur"><input size="40" type="text" name="email" value=""></td></tr>';
print "<tr>".'<td valign="top">Admin</td>';
print '<td class="valeur">';
$form->selectyesnonum('admin',0);
print '</td></tr>';
if (defined("MAIN_MODULE_WEBCALENDAR"))
{
print "<tr>".'<td valign="top">Login Webcal</td>';
print '<td class="valeur"><input size="30" type="text" name="webcal_login" value=""></td></tr>';
}
print "<tr>".'<td valign="top">Note</td><td>';
print "<textarea name=\"note\" rows=\"12\" cols=\"40\">";
print "</textarea></td></tr>";
print "<tr>".'<td align="center" colspan="2"><input value="Enregistrer" type="submit"></td></tr>';
print '</form>';
print '</table>';
}
/* ************************************************************************** */
/* */
/* Visu et edition */
/* */
/* ************************************************************************** */
else
{
if ($_GET["id"])
{
$fuser = new User($db, $_GET["id"]);
$fuser->fetch();
print_fiche_titre("Fiche utilisateur",$message);
if ($request == 'delete')
{
print '<form method="post" action="'.$PHP_SELF.'?id='.$fuser->id.'">';
print '<input type="hidden" name="action" value="confirm_delete">';
print '<table class="border" cellspacing="0" border="1" width="100%" cellpadding="3">';
print "<tr>".'<td colspan="3">Supprimer cet utilisateur</td></tr>';
print "<tr>".'<td class="delete">Etes-vous sur de vouloir supprimer cet utilisateur ?</td><td class="delete">';
$htmls = new Form($db);
$htmls->selectyesno("confirm","no");
print "</td>\n";
print '<td class="delete" align="center"><input type="submit" value="Confirmer"</td></tr>';
print '</table>';
print "</form>\n";
}
if ($_GET["request"] == 'perms')
{
/*
* Droits
*/
print '<table class="border" width="100%" border="0" cellpadding="3" cellspacing="0">';
print '<tr><td width="25%" valign="top">Nom</td>';
print '<td width="25%" class="valeur">'.$fuser->nom.'</td>';
print '<td width="25%" valign="top">Pr<50>nom</td>';
print '<td width="25%" class="valeur">'.$fuser->prenom.'</td></tr>';
print "<tr>".'<td valign="top" colspan="2">';
print '<table width="100%" class="noborder" cellpadding="2" cellspacing="0">';
$sql = "SELECT r.id, r.libelle, r.module FROM ".MAIN_DB_PREFIX."rights_def as r ORDER BY r.id ASC";
if ($db->query($sql))
{
$num = $db->num_rows();
$i = 0;
$var = True;
while ($i < $num)
{
$obj = $db->fetch_object($i);
if ($oldmod <> $obj->module)
{
$oldmod = $obj->module;
$var = !$var;
}
print '<tr '. $bc[$var].'><td><a href="fiche.php?id='.$fuser->id.'&amp;request=perms&amp;subaction=addrights&amp;rights='.$obj->id.'">Ajouter</a></td><td>';
print $obj->libelle . '</td></tr>';
$i++;
}
}
print '</table>';
print '</td><td colspan="2" valign="top">';
/*
* Droits
*/
print '<table class="noborder" width="100%" cellpadding="2" cellspacing="0">';
$sql = "SELECT r.id, r.libelle, r.module FROM ".MAIN_DB_PREFIX."rights_def as r, ".MAIN_DB_PREFIX."user_rights as ur";
$sql .= " WHERE ur.fk_id = r.id AND ur.fk_user = ".$fuser->id. " ORDER BY r.id ASC";
$var = True;
if ($db->query($sql))
{
$num = $db->num_rows();
$i = 0;
while ($i < $num)
{
$obj = $db->fetch_object($i);
if ($oldmod <> $obj->module)
{
$oldmod = $obj->module;
$var = !$var;
}
print "<tr $bc[$var]><td>".$obj->libelle . '</td>';
print '<td align="right"><a href="fiche.php?id='.$fuser->id.'&amp;request=perms&amp;subaction=delrights&amp;rights='.$obj->id.'">Supprimer</a></td></tr>';
$i++;
}
}
print '</table>';
print '</td></tr>';
print "<tr>".'<td align="center" colspan="4"><a href="fiche.php?id='.$id.'">ok</a></td></tr></table>';
}
else
{
/*
* Affichage
*/
print '<table class="border" width="100%" cellpadding="3" cellspacing="0">';
print "<tr>".'<td width="25%" valign="top">Nom</td>';
print '<td width="25%" class="valeur">'.$fuser->nom.'</td>';
print '<td>Droits</td></tr>';
print "<tr>".'<td width="25%" valign="top">Pr<50>nom</td>';
print '<td width="25%" class="valeur">'.$fuser->prenom.'</td>';
if (defined("MAIN_MODULE_WEBCALENDAR"))
{
print '<td valign="top" rowspan="7">';
}
else
{
print '<td valign="top" rowspan="6">';
}
/*
* Droits
*/
print '<table width="100%" class="noborder" cellpadding="0" cellspacing="0">';
$sql = "SELECT r.libelle, r.module FROM ".MAIN_DB_PREFIX."rights_def as r, ".MAIN_DB_PREFIX."user_rights as ur";
$sql .= " WHERE ur.fk_id = r.id AND ur.fk_user = ".$fuser->id. " ORDER BY r.id ASC";
$var = True;
if ($db->query($sql))
{
$num = $db->num_rows();
$i = 0;
while ($i < $num)
{
$obj = $db->fetch_object($i);
if ($oldmod <> $obj->module)
{
$oldmod = $obj->module;
$var = !$var;
}
print "<tr $bc[$var]><td>".$obj->libelle . '</td></tr>';
$i++;
}
}
print '</table>';
print '</td></tr>';
print "<tr>".'<td width="25%" valign="top">Login</td>';
print '<td width="25%" class="valeur">'.$fuser->login.'</td></tr>';
print "<tr>".'<td width="25%" valign="top">Email</td>';
print '<td width="25%" class="valeur"><a href="mailto:'.$fuser->email.'">'.$fuser->email.'</a></td></tr>';
if (defined("MAIN_MODULE_WEBCALENDAR"))
{
print "<tr>".'<td width="25%" valign="top">Webcal Login</td>';
print '<td width="25%" class="valeur">'.$fuser->webcal_login.'&nbsp;</td></tr>';
}
print "<tr>".'<td width="25%" valign="top">Administrateur</td>';
print '<td width="25%" class="valeur">'.$yn[$fuser->admin].'</td></tr>';
print "<tr>".'<td width="25%" valign="top">Id Soci<63>t<EFBFBD></td>';
print '<td width="25%" class="valeur">'.$fuser->societe_id.'&nbsp;</td></tr>';
print "<tr>".'<td width="25%" valign="top">';
if ($fuser->contact_id)
{
print '<a href="../comm/people.php?contactid='.$fuser->contact_id.'&amp;socid='.$fuser->societe_id.'">Fiche contact</a>';
}
else
{
print "&nbsp;";
}
print '</td>';
print '<td width="25%" class="valeur">&nbsp;</td></tr>';
print "<tr>".'<td width="25%" valign="top">Note</td>';
print '<td colspan="3" class="valeur">'.nl2br($fuser->note).'&nbsp;</td></tr>';
print '</table>';
/*
* Barre d'action
*/
print '<br><table id="actions" width="100%" border="1" cellspacing="0" cellpadding="2">'."<tr>";
if ($user->admin)
{
print '<td width="20%" align="center"><a href="fiche.php?action=edit&amp;id='.$fuser->id.'">Editer</a></td>';
}
else
{
print '<td width="20%" align="center">-</td>';
}
print '<td width="20%" align="center">-</td>';
if ($user->id == $id or $user->admin)
{
print '<td width="20%" align="center"><a href="fiche.php?action=password&amp;id='.$fuser->id.'">Nouveau mot de passe</a></td>';
}
else
{
print '<td width="20%" align="center">-</td>';
}
if ($user->admin)
{
print '<td width="20%" align="center"><a href="fiche.php?request=perms&amp;id='.$fuser->id.'">Permissions</a></td>';
}
else
{
print '<td width="20%" align="center">-</td>';
}
if ($user->admin && $user->id <> $id)
{
print '<td width="20%" align="center"><a href="fiche.php?request=delete&amp;id='.$fuser->id.'">Supprimer</a></td>';
}
else
{
print '<td width="20%" align="center">-</td>';
}
print '</tr></table><br>';
/* ************************************************************************** */
/* */
/* Edition */
/* */
/* ************************************************************************** */
if ($action == 'edit' && $user->admin && !$fuser->societe_id)
{
print '<hr><div class="titre">Edition de l\'utilisateur</div><br>';
print '<form action="'.$PHP_SELF.'?id='.$id.'" method="post">';
print '<input type="hidden" name="action" value="update">';
print '<table class="border" border="1" cellpadding="3" cellspacing="0">';
print "<tr>".'<td valign="top">Nom</td>';
print '<td><input size="30" type="text" name="nom" value="'.$fuser->nom.'"></td></tr>';
print "<tr>".'<td valign="top">Pr<50>nom</td>';
print '<td><input size="20" type="text" name="prenom" value="'.$fuser->prenom.'"></td></tr>';
print "<tr>".'<td valign="top">Login</td>';
print '<td><input size="10" maxlength="8" type="text" name="login" value="'.$fuser->login.'"></td></tr>';
print "<tr>".'<td valign="top">Email</td>';
print '<td><input size="30" type="text" name="email" value="'.$fuser->email.'"></td></tr>';
print "<tr>".'<td valign="top">Admin ?</td>';
print '<td class="valeur">';
$form->selectyesnonum('admin',$fuser->admin);
print '</td></tr>';
print "<tr>".'<td valign="top">Login Webcal</td>';
print '<td class="valeur"><input size="30" type="text" name="webcal_login" value="'.$fuser->webcal_login.'"></td></tr>';
print "<tr>".'<td valign="top">Description</td><td>';
print "<textarea name=\"note\" rows=\"12\" cols=\"40\">";
print $fuser->note;
print "</textarea></td></tr>";
print "<tr>".'<td align="center" colspan="3"><input value="Enregistrer" type="submit"></td></tr>';
print '</form>';
print '</table>';
}
}
}
}
$db->close();
llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>");
?>