2004-10-20 23:06:45 +02:00
< ? php
2005-08-23 13:40:19 +02:00
/* Copyright ( C ) 2002 - 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2011-05-25 11:51:01 +02:00
* Copyright ( C ) 2004 - 2011 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-12-30 15:13:49 +01:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2002-05-06 21:10:48 +02:00
* ( 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
2011-08-01 01:19:04 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2002-05-06 21:10:48 +02:00
*/
2009-01-31 01:15:34 +01:00
2005-01-18 20:44:23 +01:00
/**
2009-06-04 01:05:52 +02:00
* \file htdocs / user / index . php
* \ingroup core
2011-05-25 11:51:01 +02:00
* \brief Page of users
2009-06-04 01:05:52 +02:00
*/
2004-11-03 23:00:47 +01:00
2012-08-22 23:24:21 +02:00
require '../main.inc.php' ;
2012-10-09 09:34:12 +02:00
if ( ! empty ( $conf -> multicompany -> enabled ))
2012-12-08 15:35:08 +01:00
dol_include_once ( '/multicompany/class/actions_multicompany.class.php' , 'ActionsMulticompany' );
2011-08-19 09:22:17 +02:00
2002-05-06 21:10:48 +02:00
2012-10-09 09:34:12 +02:00
if ( ! $user -> rights -> user -> user -> lire && ! $user -> admin )
accessforbidden ();
2005-08-23 13:40:19 +02:00
2004-07-31 17:42:28 +02:00
$langs -> load ( " users " );
2007-02-26 01:00:03 +01:00
$langs -> load ( " companies " );
2004-07-31 17:42:28 +02:00
2010-10-29 18:08:54 +02:00
// Security check (for external users)
$socid = 0 ;
2012-10-09 09:34:12 +02:00
if ( $user -> societe_id > 0 )
$socid = $user -> societe_id ;
2010-10-29 18:08:54 +02:00
2011-11-02 20:24:51 +01:00
$sall = GETPOST ( 'sall' , 'alpha' );
2012-07-10 13:20:53 +02:00
$search_user = GETPOST ( 'search_user' , 'alpha' );
2013-11-17 17:09:58 +01:00
$search_statut = GETPOST ( 'search_statut' , 'alpha' );
if ( $search_statut == '' ) $search_statut = 1 ; // always display activ customer first
2005-09-06 21:17:12 +02:00
2012-10-09 09:34:12 +02:00
$sortfield = GETPOST ( 'sortfield' , 'alpha' );
$sortorder = GETPOST ( 'sortorder' , 'alpha' );
$page = GETPOST ( 'page' , 'int' );
2010-11-20 14:08:44 +01:00
if ( $page == - 1 ) { $page = 0 ; }
$offset = $conf -> liste_limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2005-01-31 17:21:47 +01:00
$limit = $conf -> liste_limit ;
2005-02-26 15:23:54 +01:00
if ( ! $sortfield ) $sortfield = " u.login " ;
2005-01-31 17:21:47 +01:00
if ( ! $sortorder ) $sortorder = " ASC " ;
2007-02-26 01:00:03 +01:00
$userstatic = new User ( $db );
2010-10-29 18:08:54 +02:00
$companystatic = new Societe ( $db );
2013-11-17 17:09:58 +01:00
$form = new Form ( $db );
2007-02-26 01:00:03 +01:00
2011-11-02 20:17:55 +01:00
2009-01-31 01:15:34 +01:00
/*
* View
*/
2005-01-31 17:21:47 +01:00
2013-02-21 10:22:33 +01:00
llxHeader ( '' , $langs -> trans ( " ListOfUsers " ));
2004-07-31 17:42:28 +02:00
2013-02-19 13:24:32 +01:00
print_fiche_titre ( $langs -> trans ( " ListOfUsers " ), '<form action="' . DOL_URL_ROOT . '/user/hierarchy.php" method="POST"><input type="submit" class="button" style="width:120px" name="viewcal" value="' . dol_escape_htmltag ( $langs -> trans ( " HierarchicView " )) . '"></form>' );
2002-07-03 14:46:00 +02:00
2013-02-23 17:40:28 +01:00
$sql = " SELECT u.rowid, u.lastname, u.firstname, u.admin, u.fk_societe, u.login, " ;
2010-05-08 18:29:37 +02:00
$sql .= " u.datec, " ;
$sql .= " u.tms as datem, " ;
$sql .= " u.datelastlogin, " ;
2009-04-27 22:37:50 +02:00
$sql .= " u.ldap_sid, u.statut, u.entity, " ;
2010-10-29 18:08:54 +02:00
$sql .= " s.nom, s.canvas " ;
2005-09-26 03:01:53 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " user as u " ;
2007-06-12 00:51:47 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe as s ON u.fk_societe = s.rowid " ;
2012-07-10 13:20:53 +02:00
if ( ! empty ( $conf -> multicompany -> enabled ) && $conf -> entity == 1 && ( ! empty ( $conf -> multicompany -> transverse_mode ) || ( ! empty ( $user -> admin ) && empty ( $user -> entity ))))
2011-08-20 00:15:22 +02:00
{
$sql .= " WHERE u.entity IS NOT NULL " ;
}
2011-08-19 09:22:17 +02:00
else
2011-08-20 00:15:22 +02:00
{
$sql .= " WHERE u.entity IN (0, " . $conf -> entity . " ) " ;
}
2012-10-09 09:34:12 +02:00
if ( ! empty ( $socid )) $sql .= " AND u.fk_societe = " . $socid ;
if ( ! empty ( $search_user ))
2005-09-26 03:01:53 +02:00
{
2013-02-23 12:30:01 +01:00
$sql .= " AND (u.login LIKE '% " . $db -> escape ( $search_user ) . " %' OR u.lastname LIKE '% " . $db -> escape ( $search_user ) . " %' OR u.firstname LIKE '% " . $db -> escape ( $search_user ) . " %') " ;
2005-01-31 17:21:47 +01:00
}
2013-11-17 17:09:58 +01:00
if ( $search_statut != '' )
{
$sql .= " AND (u.statut= " . $search_statut . " ) " ;
}
2013-02-23 12:30:01 +01:00
if ( $sall ) $sql .= " AND (u.login LIKE '% " . $db -> escape ( $sall ) . " %' OR u.lastname LIKE '% " . $db -> escape ( $sall ) . " %' OR u.firstname LIKE '% " . $db -> escape ( $sall ) . " %' OR u.email LIKE '% " . $db -> escape ( $sall ) . " %' OR u.note LIKE '% " . $db -> escape ( $sall ) . " %') " ;
2011-11-02 20:17:55 +01:00
$sql .= $db -> order ( $sortfield , $sortorder );
2002-05-06 21:10:48 +02:00
$result = $db -> query ( $sql );
2002-12-23 00:40:26 +01:00
if ( $result )
{
2005-03-06 17:01:38 +01:00
$num = $db -> num_rows ( $result );
2004-11-03 23:00:47 +01:00
$i = 0 ;
2013-11-20 00:46:04 +01:00
print '<form method="POST" id="searchFormList" action="' . $_SERVER [ " PHP_SELF " ] . '">' . " \n " ;
2013-11-17 17:09:58 +01:00
2005-09-06 21:17:12 +02:00
$param = " search_user= $search_user &sall= $sall " ;
2011-08-20 00:15:22 +02:00
print '<table class="noborder" width="100%">' ;
2004-11-03 23:00:47 +01:00
print '<tr class="liste_titre">' ;
2007-11-11 16:55:45 +01:00
print_liste_field_titre ( $langs -> trans ( " Login " ), " index.php " , " u.login " , $param , " " , " " , $sortfield , $sortorder );
2013-02-23 13:59:17 +01:00
print_liste_field_titre ( $langs -> trans ( " LastName " ), " index.php " , " u.lastname " , $param , " " , " " , $sortfield , $sortorder );
2007-11-11 16:55:45 +01:00
print_liste_field_titre ( $langs -> trans ( " FirstName " ), " index.php " , " u.firstname " , $param , " " , " " , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( " Company " ), " index.php " , " u.fk_societe " , $param , " " , " " , $sortfield , $sortorder );
2009-04-27 22:37:50 +02:00
print_liste_field_titre ( $langs -> trans ( " DateCreation " ), " index.php " , " u.datec " , $param , " " , 'align="center"' , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( " LastConnexion " ), " index.php " , " u.datelastlogin " , $param , " " , 'align="center"' , $sortfield , $sortorder );
2013-11-17 17:09:58 +01:00
print_liste_field_titre ( $langs -> trans ( " Status " ), " index.php " , " u.statut " , $param , " " , 'align="center"' , $sortfield , $sortorder );
print '<td width="1%"> </td>' ;
print " </tr> \n " ;
//SearchBar
print '<tr class="liste_titre">' ;
print '<td colspan="6"> </td>' ;
print '<td>' ;
print $form -> selectarray ( 'search_statut' , array ( '0' => $langs -> trans ( 'Disabled' ), '1' => $langs -> trans ( 'Enabled' )), $search_statut );
print '</td>' ;
print '<td class="liste_titre" align="right">' ;
2014-01-13 10:15:07 +01:00
print '<input class="liste_titre" type="image" src="' . img_picto ( $langs -> trans ( " Search " ), 'search.png' , '' , '' , 1 ) . '" value="' . dol_escape_htmltag ( $langs -> trans ( " Search " )) . '" title="' . dol_escape_htmltag ( $langs -> trans ( " Search " )) . '">' ;
2013-11-17 17:09:58 +01:00
print '</td>' ;
2004-11-03 23:00:47 +01:00
print " </tr> \n " ;
$var = True ;
while ( $i < $num )
2002-12-23 00:40:26 +01:00
{
2005-03-06 17:01:38 +01:00
$obj = $db -> fetch_object ( $result );
2004-11-03 23:00:47 +01:00
$var =! $var ;
2013-06-20 09:18:12 +02:00
print " <tr " . $bc [ $var ] . " > " ;
2007-02-26 01:00:03 +01:00
print '<td><a href="fiche.php?id=' . $obj -> rowid . '">' . img_object ( $langs -> trans ( " ShowUser " ), " user " ) . ' ' . $obj -> login . '</a>' ;
2011-08-21 12:01:36 +02:00
if ( ! empty ( $conf -> multicompany -> enabled ) && $obj -> admin && ! $obj -> entity )
2004-11-03 23:00:47 +01:00
{
2011-08-17 17:56:22 +02:00
print img_picto ( $langs -> trans ( " SuperAdministrator " ), 'redstar' );
2009-04-27 22:37:50 +02:00
}
else if ( $obj -> admin )
{
print img_picto ( $langs -> trans ( " Administrator " ), 'star' );
2004-11-03 23:00:47 +01:00
}
2007-02-26 01:00:03 +01:00
print '</td>' ;
2013-02-23 13:59:17 +01:00
print '<td>' . ucfirst ( $obj -> lastname ) . '</td>' ;
2005-02-26 15:23:54 +01:00
print '<td>' . ucfirst ( $obj -> firstname ) . '</td>' ;
2005-09-26 03:01:53 +02:00
print " <td> " ;
if ( $obj -> fk_societe )
{
2010-10-29 18:08:54 +02:00
$companystatic -> id = $obj -> fk_societe ;
$companystatic -> nom = $obj -> nom ;
$companystatic -> canvas = $obj -> canvas ;
print $companystatic -> getNomUrl ( 1 );
2005-09-26 03:01:53 +02:00
}
2012-09-17 16:16:48 +02:00
// Multicompany enabled
2011-08-21 12:01:36 +02:00
else if ( ! empty ( $conf -> multicompany -> enabled ))
2011-08-19 09:22:17 +02:00
{
2011-09-22 12:55:37 +02:00
if ( ! $obj -> entity )
2011-08-20 00:15:22 +02:00
{
print $langs -> trans ( " AllEntities " );
}
else
{
2012-09-17 16:16:48 +02:00
// $mc is defined in conf.class.php if multicompany enabled.
2012-09-17 22:08:41 +02:00
if ( is_object ( $mc ))
{
$mc -> getInfo ( $obj -> entity );
print $mc -> label ;
}
2011-08-20 00:15:22 +02:00
}
2011-08-19 09:22:17 +02:00
}
2006-06-24 17:13:29 +02:00
else if ( $obj -> ldap_sid )
{
print $langs -> trans ( " DomainUser " );
}
2011-08-20 00:15:22 +02:00
else
{
print $langs -> trans ( " InternalUser " );
}
2005-09-26 03:01:53 +02:00
print '</td>' ;
2009-01-31 01:15:34 +01:00
2007-11-16 04:30:07 +01:00
// Date creation
2013-04-25 01:13:13 +02:00
print '<td class="nowrap" align="center">' . dol_print_date ( $db -> jdate ( $obj -> datec ), " dayhour " ) . '</td>' ;
2007-11-16 04:30:07 +01:00
// Date last login
2013-04-25 01:13:13 +02:00
print '<td class="nowrap" align="center">' . dol_print_date ( $db -> jdate ( $obj -> datelastlogin ), " dayhour " ) . '</td>' ;
2007-02-26 01:00:03 +01:00
// Statut
$userstatic -> statut = $obj -> statut ;
2013-11-17 17:09:58 +01:00
print '<td width="100" align="center">' . $userstatic -> getLibStatut ( 5 ) . '</td>' ;
print '<td> </td>' ;
2004-11-03 23:00:47 +01:00
print " </tr> \n " ;
$i ++ ;
2002-12-23 00:40:26 +01:00
}
2004-11-03 23:00:47 +01:00
print " </table> " ;
2013-11-17 17:09:58 +01:00
print " </form> \n " ;
2005-03-06 17:01:38 +01:00
$db -> free ( $result );
2002-12-23 00:40:26 +01:00
}
2004-11-03 23:00:47 +01:00
else
2002-12-23 00:40:26 +01:00
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2002-05-06 21:10:48 +02:00
}
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-09-17 16:00:41 +02:00
$db -> close ();
2002-05-06 21:10:48 +02:00
?>