2005-01-27 16:55:40 +01:00
< ? php
2018-02-06 19:29:16 +01:00
/* Copyright ( C ) 2002 - 2003 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2019-02-16 10:29:15 +01:00
* Copyright ( C ) 2004 - 2018 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2005 - 2018 Regis Houssin < regis . houssin @ inodbox . com >
* Copyright ( C ) 2011 Herve Prot < herve . prot @ symeos . com >
2021-06-03 08:36:50 +02:00
* Copyright ( C ) 2019 - 2021 Frédéric France < frederic . france @ netlogic . fr >
2005-01-27 16:55:40 +01: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
2005-01-27 16:55:40 +01: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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2005-01-27 16:55:40 +01:00
*/
2009-03-02 20:07:12 +01:00
2005-01-28 21:35:01 +01:00
/**
2018-04-06 00:36:52 +02:00
* \file htdocs / user / group / list . php
2009-06-04 01:05:52 +02:00
* \ingroup core
2011-05-25 11:51:01 +02:00
* \brief Page of user groups
2009-06-04 01:05:52 +02:00
*/
2005-01-27 16:55:40 +01:00
2012-08-22 23:24:21 +02:00
require '../../main.inc.php' ;
2018-02-06 19:16:15 +01:00
require_once DOL_DOCUMENT_ROOT . '/user/class/usergroup.class.php' ;
2005-01-27 16:55:40 +01:00
2018-05-26 16:24:54 +02:00
// Load translation files required by page
2005-01-27 16:55:40 +01:00
$langs -> load ( " users " );
2019-11-13 19:37:08 +01:00
$sall = trim (( GETPOST ( 'search_all' , 'alphanohtml' ) != '' ) ? GETPOST ( 'search_all' , 'alphanohtml' ) : GETPOST ( 'sall' , 'alphanohtml' ));
$search_group = GETPOST ( 'search_group' );
2019-01-27 11:55:16 +01:00
$optioncss = GETPOST ( 'optioncss' , 'alpha' );
2021-06-03 08:36:50 +02:00
$massaction = GETPOST ( 'massaction' , 'alpha' ); // The bulk action (combo box choice into lists)
2021-07-08 12:17:32 +02:00
$contextpage = GETPOST ( 'optioncss' , 'aZ09' );
2005-09-06 21:17:12 +02:00
2018-04-12 18:05:12 +02:00
// Defini si peux lire/modifier utilisateurs et permisssions
2019-11-13 19:37:08 +01:00
$caneditperms = ( $user -> admin || $user -> rights -> user -> user -> creer );
2018-04-12 18:05:12 +02:00
// Advanced permissions
2021-02-26 13:18:40 +01:00
if ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS )) {
2019-11-13 19:37:08 +01:00
$caneditperms = ( $user -> admin || $user -> rights -> user -> group_advance -> write );
2018-04-12 18:05:12 +02:00
}
2017-01-17 20:04:41 +01:00
// Load variable for pagination
2019-11-13 19:37:08 +01:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2020-09-18 17:13:01 +02:00
$sortfield = GETPOST ( 'sortfield' , 'aZ09comma' );
2020-09-17 14:31:25 +02:00
$sortorder = GETPOST ( 'sortorder' , 'aZ09comma' );
2020-03-13 13:07:11 +01:00
$page = GETPOSTISSET ( 'pageplusone' ) ? ( GETPOST ( 'pageplusone' ) - 1 ) : GETPOST ( " page " , 'int' );
2021-02-26 13:18:40 +01:00
if ( empty ( $page ) || $page == - 1 ) {
$page = 0 ;
}
2017-01-17 20:04:41 +01:00
$offset = $limit * $page ;
2010-11-20 14:08:44 +01:00
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2009-03-02 20:07:12 +01:00
2021-02-26 13:18:40 +01:00
if ( ! $sortfield ) {
$sortfield = " g.nom " ;
}
if ( ! $sortorder ) {
$sortorder = " ASC " ;
}
2005-01-28 21:35:01 +01:00
2016-02-07 02:55:56 +01:00
// List of fields to search into when doing a "search in all"
$fieldstosearchall = array (
2020-10-31 14:32:18 +01:00
'g.nom' => " Group " ,
'g.note' => " Note "
2016-02-07 02:55:56 +01:00
);
2021-03-19 15:05:28 +01:00
if ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS )) {
if ( ! $user -> rights -> user -> group_advance -> read && ! $user -> admin ) {
accessforbidden ();
}
}
// Users/Groups management only in master entity if transverse mode
if ( ! empty ( $conf -> multicompany -> enabled ) && $conf -> entity > 1 && $conf -> global -> MULTICOMPANY_TRANSVERSE_MODE ) {
accessforbidden ();
}
if ( ! $user -> rights -> user -> user -> lire && ! $user -> admin ) {
accessforbidden ();
}
2005-01-28 21:35:01 +01:00
2017-01-17 20:04:41 +01:00
/*
* Actions
*/
2021-02-26 13:18:40 +01:00
if ( GETPOST ( 'cancel' , 'alpha' )) {
$action = 'list' ; $massaction = '' ;
}
2022-04-25 14:28:57 +02:00
if ( ! GETPOST ( 'confirmmassaction' , 'alpha' ) && $massaction != 'presend' && $massaction != 'confirm_presend' ) {
2021-02-26 13:18:40 +01:00
$massaction = '' ;
}
2017-01-17 20:04:41 +01:00
2019-11-13 19:37:08 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters ); // Note that $action and $object may have been modified by some hooks
2021-02-26 13:18:40 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2017-01-17 20:04:41 +01:00
2021-02-26 13:18:40 +01:00
if ( empty ( $reshook )) {
2020-10-31 14:32:18 +01:00
// Selection of new fields
include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php' ;
// Purge search criteria
2021-02-26 13:18:40 +01:00
if ( GETPOST ( 'button_removefilter_x' , 'alpha' ) || GETPOST ( 'button_removefilter.x' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' )) { // All test are required to be compatible with all browsers
2020-10-31 14:32:18 +01:00
$search_label = " " ;
$search_date_creation = " " ;
$search_date_update = " " ;
$search_array_options = array ();
}
2017-01-17 20:04:41 +01:00
}
2009-03-02 20:07:12 +01:00
/*
* View
*/
2005-01-27 16:55:40 +01:00
llxHeader ();
2021-07-03 18:09:48 +02:00
$sql = " SELECT g.rowid, g.nom as name, g.note, g.entity, g.datec, g.tms as datem, COUNT(DISTINCT ugu.fk_user) as nb, COUNT(DISTINCT ugr.fk_id) as nbpermissions " ;
2019-11-13 19:37:08 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " usergroup as g " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " usergroup_user as ugu ON ugu.fk_usergroup = g.rowid " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " usergroup_rights as ugr ON ugr.fk_usergroup = g.rowid " ;
2021-02-26 13:18:40 +01:00
if ( ! empty ( $conf -> multicompany -> enabled ) && $conf -> entity == 1 && ( $conf -> global -> MULTICOMPANY_TRANSVERSE_MODE || ( $user -> admin && ! $user -> entity ))) {
2019-11-13 19:37:08 +01:00
$sql .= " WHERE g.entity IS NOT NULL " ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:37:08 +01:00
$sql .= " WHERE g.entity IN (0, " . $conf -> entity . " ) " ;
2011-08-20 00:15:22 +02:00
}
2021-02-26 13:18:40 +01:00
if ( ! empty ( $search_group )) {
natural_search ( array ( " g.nom " , " g.note " ), $search_group );
}
if ( $sall ) {
$sql .= natural_search ( array ( " g.nom " , " g.note " ), $sall );
}
2021-07-03 18:09:48 +02:00
$sql .= " GROUP BY g.rowid, g.nom, g.note, g.entity, g.datec, g.tms " ;
2019-11-13 19:37:08 +01:00
$sql .= $db -> order ( $sortfield , $sortorder );
2011-02-12 00:39:21 +01:00
2005-09-06 21:17:12 +02:00
$resql = $db -> query ( $sql );
2021-02-26 13:18:40 +01:00
if ( $resql ) {
2020-10-31 14:32:18 +01:00
$num = $db -> num_rows ( $resql );
2017-01-23 12:29:05 +01:00
2020-10-31 14:32:18 +01:00
$nbtotalofrecords = $num ;
2017-01-23 12:29:05 +01:00
2020-10-31 14:32:18 +01:00
$i = 0 ;
2005-09-06 21:17:12 +02:00
2020-10-31 14:32:18 +01:00
$param = " &search_group= " . urlencode ( $search_group ) . " &sall= " . urlencode ( $sall );
2021-02-26 13:18:40 +01:00
if ( $optioncss != '' ) {
$param .= '&optioncss=' . $optioncss ;
}
2017-01-23 12:29:05 +01:00
2020-10-31 14:32:18 +01:00
$text = $langs -> trans ( " ListOfGroups " );
2017-01-23 12:29:05 +01:00
2020-10-31 14:32:18 +01:00
$newcardbutton = '' ;
2021-02-26 13:18:40 +01:00
if ( $caneditperms ) {
2020-10-31 14:32:18 +01:00
$newcardbutton .= dolGetButtonTitle ( $langs -> trans ( 'NewGroup' ), '' , 'fa fa-plus-circle' , DOL_URL_ROOT . '/user/group/card.php?action=create&leftmenu=' );
}
2018-04-07 16:17:40 +02:00
2020-10-31 14:32:18 +01:00
print '<form method="POST" id="searchFormList" action="' . $_SERVER [ " PHP_SELF " ] . '">' . " \n " ;
2021-02-26 13:18:40 +01:00
if ( $optioncss != '' ) {
print '<input type="hidden" name="optioncss" value="' . $optioncss . '">' ;
}
2020-10-31 14:32:18 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">' ;
print '<input type="hidden" name="sortfield" value="' . $sortfield . '">' ;
print '<input type="hidden" name="sortorder" value="' . $sortorder . '">' ;
print '<input type="hidden" name="contextpage" value="' . $contextpage . '">' ;
2017-01-23 12:29:05 +01:00
2020-10-31 14:32:18 +01:00
print_barre_liste ( $text , $page , $_SERVER [ " PHP_SELF " ], $param , $sortfield , $sortorder , " " , $num , $nbtotalofrecords , 'object_group' , 0 , $newcardbutton , '' , $limit , 0 , 0 , 1 );
2017-01-23 12:29:05 +01:00
2021-02-26 13:18:40 +01:00
if ( $sall ) {
foreach ( $fieldstosearchall as $key => $val ) {
$fieldstosearchall [ $key ] = $langs -> trans ( $val );
}
2020-10-31 14:32:18 +01:00
print '<div class="divsearchfieldfilter">' . $langs -> trans ( " FilterOnInto " , $sall ) . join ( ', ' , $fieldstosearchall ) . '</div>' ;
}
2017-01-23 12:29:05 +01:00
2020-10-31 14:32:18 +01:00
$moreforfilter = '' ;
2017-01-23 12:29:05 +01:00
2016-02-07 02:55:56 +01:00
//$varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
2016-03-25 15:24:57 +01:00
//$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
2017-01-23 12:29:05 +01:00
2020-10-31 14:32:18 +01:00
print '<div class="div-table-responsive">' ;
print '<table class="tagtable liste' . ( $moreforfilter ? " listwithfilterbefore " : " " ) . '">' . " \n " ;
print '<tr class="liste_titre">' ;
print_liste_field_titre ( " Group " , $_SERVER [ " PHP_SELF " ], " g.nom " , $param , " " , " " , $sortfield , $sortorder );
//multicompany
2021-02-26 13:18:40 +01:00
if ( ! empty ( $conf -> multicompany -> enabled ) && empty ( $conf -> global -> MULTICOMPANY_TRANSVERSE_MODE ) && $conf -> entity == 1 ) {
2020-10-31 14:32:18 +01:00
print_liste_field_titre ( " Entity " , $_SERVER [ " PHP_SELF " ], " g.entity " , $param , " " , '' , $sortfield , $sortorder , 'center ' );
}
print_liste_field_titre ( " NbOfUsers " , $_SERVER [ " PHP_SELF " ], " nb " , $param , " " , '' , $sortfield , $sortorder , 'center ' );
print_liste_field_titre ( " NbOfPermissions " , $_SERVER [ " PHP_SELF " ], " nbpermissions " , $param , " " , '' , $sortfield , $sortorder , 'center ' );
print_liste_field_titre ( " DateCreationShort " , $_SERVER [ " PHP_SELF " ], " g.datec " , $param , " " , '' , $sortfield , $sortorder , 'center ' );
2021-07-03 18:09:48 +02:00
print_liste_field_titre ( " DateLastModification " , $_SERVER [ " PHP_SELF " ], " g.tms " , $param , " " , '' , $sortfield , $sortorder , 'center ' );
2020-10-31 14:32:18 +01:00
print_liste_field_titre ( " " , $_SERVER [ " PHP_SELF " ]);
print " </tr> \n " ;
$grouptemp = new UserGroup ( $db );
2021-02-26 13:18:40 +01:00
while ( $i < $num ) {
2020-10-31 14:32:18 +01:00
$obj = $db -> fetch_object ( $resql );
$grouptemp -> id = $obj -> rowid ;
$grouptemp -> name = $obj -> name ;
$grouptemp -> note = $obj -> note ;
print '<tr class="oddeven">' ;
print '<td>' ;
print $grouptemp -> getNomUrl ( 1 );
2021-02-26 13:18:40 +01:00
if ( ! $obj -> entity ) {
2020-10-31 14:32:18 +01:00
print img_picto ( $langs -> trans ( " GlobalGroup " ), 'redstar' );
}
print " </td> " ;
//multicompany
2021-02-26 13:18:40 +01:00
if ( ! empty ( $conf -> multicompany -> enabled ) && is_object ( $mc ) && empty ( $conf -> global -> MULTICOMPANY_TRANSVERSE_MODE ) && $conf -> entity == 1 ) {
2020-10-31 14:32:18 +01:00
$mc -> getInfo ( $obj -> entity );
print '<td class="center">' . $mc -> label . '</td>' ;
}
print '<td class="center">' . $obj -> nb . '</td>' ;
2021-07-03 18:09:48 +02:00
print '<td class="center">' ;
print '<a href="' . DOL_URL_ROOT . '/user/group/perms.php?id=' . $obj -> rowid . '">' . $obj -> nbpermissions . '</a>' ;
print '</td>' ;
2020-10-31 14:32:18 +01:00
print '<td class="center nowrap">' . dol_print_date ( $db -> jdate ( $obj -> datec ), " dayhour " ) . '</td>' ;
2021-07-03 18:09:48 +02:00
print '<td class="center nowrap">' . dol_print_date ( $db -> jdate ( $obj -> datem ), " dayhour " ) . '</td>' ;
2020-10-31 14:32:18 +01:00
print '<td></td>' ;
print " </tr> \n " ;
$i ++ ;
}
print " </table> " ;
print '</div>' ;
print " </form> \n " ;
$db -> free ( $resql );
2020-05-21 15:05:19 +02:00
} else {
2020-10-31 14:32:18 +01:00
dol_print_error ( $db );
2005-01-27 16:55:40 +01:00
}
2018-08-04 15:58:05 +02:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-07-10 13:20:53 +02:00
$db -> close ();