2002-05-06 21:10:48 +02:00
< ? PHP
2004-02-13 18:36:27 +01:00
/* Copyright ( C ) 2002 - 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2004-06-09 12:39:40 +02:00
* Copyright ( C ) 2002 - 2003 Jean - Louis Bergamo < jlb @ j1b . org >
* Copyright ( C ) 2004 Laurent Destailleur < eldy @ users . sourceforge . net >
2002-05-06 21:10:48 +02:00
*
* 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 .
*
2002-12-13 17:51:03 +01:00
* $Id $
* $Source $
2002-05-06 21:10:48 +02:00
*/
2003-09-11 17:26:39 +02:00
require ( " ./pre.inc.php " );
2002-05-06 21:10:48 +02:00
2003-02-20 18:40:42 +01:00
$form = new Form ( $db );
2002-05-06 21:10:48 +02:00
2004-06-09 12:39:40 +02:00
$action = isset ( $_GET [ " action " ]) ? $_GET [ " action " ] : $_POST [ " action " ];
2003-11-21 18:33:36 +01:00
if ( $_GET [ " subaction " ] == 'addrights' && $user -> admin )
2003-08-10 14:44:43 +02:00
{
2004-06-09 12:39:40 +02:00
$edituser = new User ( $db , $_GET [ " id " ]);
$edituser -> addrights ( $_GET [ " rights " ]);
2003-08-10 14:44:43 +02:00
}
2003-11-21 18:33:36 +01:00
if ( $_GET [ " subaction " ] == 'delrights' && $user -> admin )
2003-08-10 14:44:43 +02:00
{
2004-06-09 12:39:40 +02:00
$edituser = new User ( $db , $_GET [ " id " ]);
$edituser -> delrights ( $_GET [ " rights " ]);
2003-08-10 14:44:43 +02:00
}
2004-06-09 12:39:40 +02:00
if ( $_POST [ " action " ] == 'confirm_delete' && $_POST [ " confirm " ] == " yes " )
2003-08-10 14:44:43 +02:00
{
2004-06-09 12:39:40 +02:00
if ( $id <> $user -> id )
2003-08-10 14:44:43 +02:00
{
2004-06-09 12:39:40 +02:00
$edituser = new User ( $db , $id );
$edituser -> fetch ( $id );
$edituser -> delete ();
Header ( " Location: index.php " );
2003-08-10 14:44:43 +02:00
}
}
2004-06-09 12:39:40 +02:00
if ( $_POST [ " action " ] == 'add' && $user -> admin )
2002-12-13 17:51:03 +01:00
{
2004-06-09 12:39:40 +02:00
$edituser = new User ( $db , 0 );
$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 " ];
$id = $edituser -> create ();
if ( isset ( $_POST [ 'password' ]) && $_POST [ 'password' ] != '' )
2004-02-13 18:36:27 +01:00
{
2004-06-09 12:39:40 +02:00
$edituser -> password ( $_POST [ 'password' ], $conf -> password_encrypted );
2004-02-13 18:36:27 +01:00
}
2002-05-06 21:10:48 +02:00
}
2004-06-09 12:39:40 +02:00
if ( $_POST [ " action " ] == 'update' && $user -> admin )
2002-12-13 17:51:03 +01:00
{
2004-07-21 11:59:06 +02:00
$edituser = new User ( $db , $_GET [ " 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 ())
2002-12-19 19:55:38 +01:00
{
2004-07-21 11:59:06 +02:00
print $edituser -> error ();
2002-12-19 19:55:38 +01:00
}
2004-07-21 11:59:06 +02:00
if ( isset ( $password ) && $password != '' )
2003-06-20 16:30:08 +02:00
{
2004-07-21 11:59:06 +02:00
$edituser -> password ( $password , $conf -> password_encrypted );
2003-06-20 16:30:08 +02:00
}
2002-12-19 19:55:38 +01:00
}
2002-05-06 21:10:48 +02:00
2004-06-09 12:39:40 +02:00
if ( $action == 'password' && $user -> admin )
2002-12-19 19:55:38 +01:00
{
2004-06-09 12:39:40 +02:00
$edituser = new User ( $db , $id );
$edituser -> fetch ();
2002-12-19 19:55:38 +01:00
2004-06-09 12:39:40 +02:00
if ( $edituser -> password ( '' , $conf -> password_encrypted ))
2002-12-19 19:55:38 +01:00
{
2004-06-09 12:39:40 +02:00
$message = " Mot de passe chang<6E> et envoy<6F> <20> $edituser->email " ;
2002-12-19 19:55:38 +01:00
}
2002-05-06 21:10:48 +02:00
}
2004-06-09 12:39:40 +02:00
2003-08-10 14:44:43 +02:00
llxHeader ();
2002-12-19 19:55:38 +01:00
2004-06-09 12:39:40 +02:00
2002-12-13 17:51:03 +01:00
/* ************************************************************************** */
/* */
/* Nouvel utilisateur */
/* */
/* ************************************************************************** */
if ( $action == 'create' )
{
2004-06-09 12:39:40 +02:00
print_titre ( 'Nouvel utilisateur' );
2004-07-21 11:59:06 +02:00
print '<form action="fiche.php" method="post">' ;
2004-06-09 12:39:40 +02:00
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 );
2004-06-20 01:51:21 +02:00
print " </td></tr> \n " ;
2004-06-09 12:39:40 +02:00
if ( defined ( " MAIN_MODULE_WEBCALENDAR " ))
2003-11-19 15:39:35 +01:00
{
2004-06-09 12:39:40 +02:00
print " <tr> " . '<td valign="top">Login Webcal</td>' ;
print '<td class="valeur"><input size="30" type="text" name="webcal_login" value=""></td></tr>' ;
2003-11-19 15:39:35 +01:00
}
2004-06-09 12:39:40 +02:00
print " <tr> " . '<td valign="top">Note</td><td>' ;
print " <textarea name= \" note \" rows= \" 12 \" cols= \" 40 \" > " ;
2004-06-20 01:51:21 +02:00
print " </textarea></td></tr> \n " ;
2004-06-09 12:39:40 +02:00
print " <tr> " . '<td align="center" colspan="2"><input value="Enregistrer" type="submit"></td></tr>' ;
2004-06-20 01:51:21 +02:00
print " </form> " ;
print " </table> \n " ;
2002-12-13 17:51:03 +01:00
}
/* ************************************************************************** */
/* */
2002-12-19 19:55:38 +01:00
/* Visu et edition */
2002-12-13 17:51:03 +01:00
/* */
/* ************************************************************************** */
else
{
2004-06-09 12:39:40 +02:00
if ( $_GET [ " id " ])
2002-12-19 19:55:38 +01:00
{
2004-06-09 12:39:40 +02:00
$fuser = new User ( $db , $_GET [ " id " ]);
$fuser -> fetch ();
/*
* Confirmation suppression
*/
if ( $action == 'delete' )
{
print_fiche_titre ( " Suppression fiche utilisateur " , $message );
print '<br>' ;
$html = new Form ( $db );
2004-07-17 01:46:27 +02:00
$html -> form_confirm ( " $PHP_SELF ?id= $fuser->id " , " D<EFBFBD> sactiver cet utilisateur " , " Etes-vous s<> r de vouloir d<> sactiver cet utilisateur ? " , " confirm_delete " );
2004-06-09 12:39:40 +02:00
}
if ( $_GET [ " action " ] == 'perms' )
{
print_fiche_titre ( " Permissions utilisateur " , $message );
print '<br>' ;
/*
* Ecran ajout / suppression permission
*/
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>' ;
// Droits existant
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 ;
}
2004-06-09 12:43:11 +02:00
print '<tr ' . $bc [ $var ] . '><td><a href="fiche.php?id=' . $fuser -> id . '&action=perms&subaction=addrights&rights=' . $obj -> id . '">Ajouter</a></td>' ;
print '<td>' . $obj -> libelle . '</td><td>' . $obj -> module . '</td></tr>' ;
2004-06-09 12:39:40 +02:00
$i ++ ;
}
}
print '</table>' ;
print '</td><td colspan="2" valign="top">' ;
// Droits poss<73> d<EFBFBD> s
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 ;
}
2004-06-09 12:43:11 +02:00
print " <tr $bc[$var] ><td> " . $obj -> libelle . '</td><td>' . $obj -> module . '</td>' ;
print '<td align="right"><a href="fiche.php?id=' . $fuser -> id . '&action=perms&subaction=delrights&rights=' . $obj -> id . '">' . img_delete () . '</a></td></tr>' ;
2004-06-09 12:39:40 +02:00
$i ++ ;
}
}
print '</table>' ;
print '</td></tr>' ;
print " <tr> " . '<td align="center" colspan="4"><a href="fiche.php?id=' . $id . '">ok</a></td></tr></table>' ;
}
if ( $_GET [ " action " ] != 'perms' && $_GET [ " action " ] != 'edit' )
{
/*
* Affichage onglet
*/
$h = 0 ;
2004-06-10 19:44:42 +02:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/user/fiche.php?id=' . $fuser -> id ;
2004-06-09 12:39:40 +02:00
$head [ $h ][ 1 ] = " Fiche utilisateur " ;
$h ++ ;
dolibarr_fiche_head ( $head , $hselected );
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 width="25%" valign="top">Pr<50> nom</td>' ;
print '<td width="25%" class="valeur">' . $fuser -> prenom . '</td>' ;
2004-06-20 01:51:21 +02:00
print " </tr> \n " ;
2004-06-09 12:39:40 +02:00
print " <tr> " . '<td width="25%" valign="top">Login</td>' ;
print '<td width="25%" class="valeur">' . $fuser -> login . '</td>' ;
print '<td width="25%" valign="top">Email</td>' ;
2004-06-20 01:51:21 +02:00
print '<td width="25%" class="valeur"><a href="mailto:' . $fuser -> email . '">' . $fuser -> email . '</a></td>' ;
print " </tr> \n " ;
2004-06-09 12:39:40 +02:00
print " <tr> " . '<td width="25%" valign="top">Administrateur</td>' ;
print '<td colspan="3" class="valeur">' . $yn [ $fuser -> admin ] . '</td>' ;
2004-06-20 01:51:21 +02:00
print " </tr> \n " ;
2004-06-09 12:39:40 +02:00
print " <tr> " . '<td width="25%" valign="top">Id Soci<63> t<EFBFBD> </td>' ;
2004-06-20 01:51:21 +02:00
print '<td colspan="3" class="valeur">' . $fuser -> societe_id . ' </td>' ;
print " </tr> \n " ;
2004-06-09 12:39:40 +02:00
print " <tr> " . '<td width="25%" valign="top">Fiche contact</td>' ;
print '<td colspan="3" valign="top">' ;
if ( $fuser -> contact_id )
{
print '<a href="../comm/people.php?contactid=' . $fuser -> contact_id . '&socid=' . $fuser -> societe_id . '">Fiche contact</a>' ;
}
else
{
print " Pas de fiche parmi les Contacts " ;
}
print '</td>' ;
2004-06-20 01:51:21 +02:00
print " </tr> \n " ;
2004-06-09 12:39:40 +02:00
print " <tr> " . '<td width="25%" valign="top">Note</td>' ;
2004-06-20 01:51:21 +02:00
print '<td colspan="3" class="valeur">' . nl2br ( $fuser -> note ) . ' </td>' ;
print " </tr> \n " ;
2004-06-09 12:39:40 +02:00
// Autres caract<63> ristiques issus des autres modules
if ( defined ( " MAIN_MODULE_WEBCALENDAR " ))
{
print " <tr> " . '<td width="25%" valign="top">Webcal Login</td>' ;
2004-06-20 01:51:21 +02:00
print '<td colspan="3">' . $fuser -> webcal_login . ' </td>' ;
print " </tr> \n " ;
2004-06-09 12:39:40 +02:00
}
2004-06-20 01:51:21 +02:00
print " </table> \n " ;
print " <br> \n " ;
2004-06-09 12:39:40 +02:00
2004-06-20 01:51:21 +02:00
print " </div> \n " ;
2004-06-09 12:39:40 +02:00
/*
* Droits
*/
print '<table width="100%" class="noborder" cellpadding="0" cellspacing="0">' ;
print '<tr class="liste_titre"><td>Droits</td><td>Module</td></tr>' ;
$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 ;
}
2004-06-20 01:51:21 +02:00
print " <tr $bc[$var] ><td> " . $obj -> libelle . '</td><td>' . $obj -> module . " </td></tr> \n " ;
2004-06-09 12:39:40 +02:00
$i ++ ;
}
}
2004-06-20 01:51:21 +02:00
print " </table> \n " ;
print " <br> \n " ;
2004-06-09 12:39:40 +02:00
/*
* Barre d ' actions
*
*/
print '<div class="tabsAction">' ;
if ( $user -> admin )
{
print '<a class="tabAction" href="fiche.php?action=edit&id=' . $fuser -> id . '">Editer</a>' ;
}
if ( $user -> id == $id or $user -> admin )
{
2004-07-23 23:23:58 +02:00
print '<a class="tabAction" href="fiche.php?action=password&id=' . $fuser -> id . '">Envoyer nouveau mot de passe</a>' ;
2004-06-09 12:39:40 +02:00
}
if ( $user -> admin )
{
print '<a class="tabAction" href="fiche.php?action=perms&id=' . $fuser -> id . '">Permissions</a>' ;
}
if ( $user -> admin && $user -> id <> $id )
{
2004-07-17 01:46:27 +02:00
print '<a class="tabAction" href="fiche.php?action=delete&id=' . $fuser -> id . '">D<> sactiver utilisateur</a>' ;
2004-06-09 12:39:40 +02:00
}
2004-06-20 01:51:21 +02:00
print " </div> \n " ;
2004-06-09 12:39:40 +02:00
print " <br> \n " ;
}
/* ************************************************************************** */
/* */
/* Edition */
/* */
/* ************************************************************************** */
if ( $action == 'edit' && $user -> admin && ! $fuser -> societe_id )
{
print_fiche_titre ( " Edition fiche utilisateur " , $message );
print '<br>' ;
2004-07-21 11:59:06 +02:00
print '<form action="fiche.php?id=' . $fuser -> id . '" method="post">' ;
2004-06-09 12:39:40 +02:00
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">Note</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>' ;
}
2002-12-19 19:55:38 +01:00
}
2004-06-09 12:39:40 +02:00
2002-05-06 21:10:48 +02:00
}
$db -> close ();
llxFooter ( " <em>Dernière modification $Date $ révision $Revision $ </em> " );
?>