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