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 >
* Copyright ( C ) 2004 - 2018 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2005 - 2018 Regis Houssin < regis . houssin @ capnetworks . com >
* Copyright ( C ) 2011 Herve Prot < herve . prot @ symeos . com >
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
2011-08-01 01:19:04 +02:00
* along with this program . If not , see < http :// 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
2010-11-08 12:40:52 +01:00
if ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ))
{
2012-10-09 09:34:12 +02:00
if ( ! $user -> rights -> user -> group_advance -> read && ! $user -> admin )
accessforbidden ();
2010-11-08 12:40:52 +01:00
}
2005-09-06 21:17:12 +02:00
2017-06-06 07:57:03 +02:00
// Users/Groups management only in master entity if transverse mode
if ( ! empty ( $conf -> multicompany -> enabled ) && $conf -> entity > 1 && $conf -> global -> MULTICOMPANY_TRANSVERSE_MODE )
{
accessforbidden ();
}
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 " );
2017-12-12 11:31:30 +01:00
$sall = trim (( GETPOST ( 'search_all' , 'alphanohtml' ) != '' ) ? GETPOST ( 'search_all' , 'alphanohtml' ) : GETPOST ( 'sall' , 'alphanohtml' ));
2012-10-09 11:42:38 +02:00
$search_group = GETPOST ( 'search_group' );
2015-10-04 10:45:57 +02:00
$optioncss = GETPOST ( 'optioncss' , 'alpha' );
2005-09-06 21:17:12 +02:00
2018-04-12 18:05:12 +02:00
// Defini si peux lire/modifier utilisateurs et permisssions
$caneditperms = ( $user -> admin || $user -> rights -> user -> user -> creer );
// Advanced permissions
if ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ))
{
$caneditperms = ( $user -> admin || $user -> rights -> user -> group_advance -> write );
}
2017-01-17 20:04:41 +01:00
// Load variable for pagination
2017-06-08 14:55:12 +02:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2012-10-09 09:34:12 +02:00
$sortfield = GETPOST ( 'sortfield' , 'alpha' );
$sortorder = GETPOST ( 'sortorder' , 'alpha' );
$page = GETPOST ( 'page' , 'int' );
2017-01-23 12:29:05 +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
2005-01-31 17:21:47 +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 (
'g.nom' => " Group " ,
'g.note' => " Note "
);
2005-01-28 21:35:01 +01:00
2017-01-17 20:04:41 +01:00
/*
* Actions
*/
2017-09-15 10:50:50 +02:00
if ( GETPOST ( 'cancel' , 'alpha' )) { $action = 'list' ; $massaction = '' ; }
if ( ! GETPOST ( 'confirmmassaction' , 'alpha' ) && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills' ) { $massaction = '' ; }
2017-01-17 20:04:41 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters ); // Note that $action and $object may have been modified by some hooks
if ( $reshook < 0 ) setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
if ( empty ( $reshook ))
{
// Selection of new fields
include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php' ;
// Purge search criteria
2017-07-13 00:35:10 +02: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
2017-01-17 20:04:41 +01:00
{
$search_label = " " ;
$search_date_creation = " " ;
$search_date_update = " " ;
$search_array_options = array ();
}
}
2009-03-02 20:07:12 +01:00
/*
* View
*/
2005-01-27 16:55:40 +01:00
llxHeader ();
2018-03-26 15:45:56 +02:00
$sql = " SELECT g.rowid, g.nom as name, g.note, g.entity, g.datec, COUNT(DISTINCT ugu.fk_user) as nb, COUNT(DISTINCT ugr.fk_id) as nbpermissions " ;
2011-02-12 00:39:21 +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 " ;
2018-03-26 15:45:56 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " usergroup_rights as ugr ON ugr.fk_usergroup = g.rowid " ;
2017-06-06 07:57:03 +02:00
if ( ! empty ( $conf -> multicompany -> enabled ) && $conf -> entity == 1 && ( $conf -> global -> MULTICOMPANY_TRANSVERSE_MODE || ( $user -> admin && ! $user -> entity )))
2011-08-20 00:15:22 +02:00
{
$sql .= " WHERE g.entity IS NOT NULL " ;
}
else
{
$sql .= " WHERE g.entity IN (0, " . $conf -> entity . " ) " ;
}
2018-03-26 15:45:56 +02: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 );
2018-02-06 19:16:15 +01:00
$sql .= " GROUP BY g.rowid, g.nom, g.note, g.entity, g.datec " ;
2011-02-12 00:39:21 +01:00
$sql .= $db -> order ( $sortfield , $sortorder );
2005-09-06 21:17:12 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
2005-01-27 16:55:40 +01:00
{
2005-09-06 21:17:12 +02:00
$num = $db -> num_rows ( $resql );
2017-01-23 12:29:05 +01:00
2017-01-17 20:04:41 +01:00
$nbtotalofrecords = $num ;
2017-01-23 12:29:05 +01:00
2005-09-06 21:17:12 +02:00
$i = 0 ;
2012-10-09 11:56:39 +02:00
$param = " &search_group= " . urlencode ( $search_group ) . " &sall= " . urlencode ( $sall );
2015-10-04 10:45:57 +02:00
if ( $optioncss != '' ) $param .= '&optioncss=' . $optioncss ;
2017-01-23 12:29:05 +01:00
2017-01-17 20:04:41 +01:00
$text = $langs -> trans ( " ListOfGroups " );
2017-01-23 12:29:05 +01:00
2018-04-07 16:17:40 +02:00
$newcardbutton = '' ;
2018-04-12 18:05:12 +02:00
if ( $caneditperms )
2018-04-07 16:17:40 +02:00
{
2018-06-13 22:57:41 +02:00
$newcardbutton = '<a class="butActionNew" href="' . DOL_URL_ROOT . '/user/group/card.php?action=create&leftmenu="><span class="valignmiddle">' . $langs -> trans ( 'NewGroup' ) . '</span>' ;
2018-04-18 03:26:15 +02:00
$newcardbutton .= '<span class="fa fa-plus-circle valignmiddle"></span>' ;
$newcardbutton .= '</a>' ;
2018-04-07 16:17:40 +02:00
}
2017-01-17 20:04:41 +01:00
print '<form method="POST" id="searchFormList" action="' . $_SERVER [ " PHP_SELF " ] . '">' . " \n " ;
if ( $optioncss != '' ) print '<input type="hidden" name="optioncss" value="' . $optioncss . '">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ '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 . '">' ;
2017-05-21 02:43:51 +02:00
print '<input type="hidden" name="page" value="' . $page . '">' ;
2017-01-17 20:04:41 +01:00
print '<input type="hidden" name="mode" value="' . $mode . '">' ;
print '<input type="hidden" name="contextpage" value="' . $contextpage . '">' ;
2017-01-23 12:29:05 +01:00
2018-04-07 16:17:40 +02:00
print_barre_liste ( $text , $page , $_SERVER [ " PHP_SELF " ], $param , $sortfield , $sortorder , " " , $num , $nbtotalofrecords , 'title_generic' , 0 , $newcardbutton , '' , $limit );
2017-01-23 12:29:05 +01:00
2017-01-17 20:04:41 +01:00
if ( $sall )
{
foreach ( $fieldstosearchall as $key => $val ) $fieldstosearchall [ $key ] = $langs -> trans ( $val );
2018-06-22 22:53:53 +02:00
print '<div class="divsearchfieldfilter">' . $langs -> trans ( " FilterOnInto " , $sall ) . join ( ', ' , $fieldstosearchall ) . '</div>' ;
2016-02-07 02:55:56 +01:00
}
2017-01-23 12:29:05 +01:00
2016-02-07 02:55:56 +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
2017-01-17 20:04:41 +01:00
print '<div class="div-table-responsive">' ;
print '<table class="tagtable liste' . ( $moreforfilter ? " listwithfilterbefore " : " " ) . '">' . " \n " ;
2005-09-06 21:17:12 +02:00
print '<tr class="liste_titre">' ;
2017-08-02 13:31:53 +02:00
print_liste_field_titre ( " Group " , $_SERVER [ " PHP_SELF " ], " g.nom " , $param , " " , " " , $sortfield , $sortorder );
2011-08-19 09:22:17 +02:00
//multicompany
2017-06-06 07:57:03 +02:00
if ( ! empty ( $conf -> multicompany -> enabled ) && empty ( $conf -> global -> MULTICOMPANY_TRANSVERSE_MODE ) && $conf -> entity == 1 )
2011-08-20 00:15:22 +02:00
{
2017-08-02 13:31:53 +02:00
print_liste_field_titre ( " Entity " , $_SERVER [ " PHP_SELF " ], " g.entity " , $param , " " , 'align="center"' , $sortfield , $sortorder );
2011-08-20 00:15:22 +02:00
}
2017-08-02 13:31:53 +02:00
print_liste_field_titre ( " NbOfUsers " , $_SERVER [ " PHP_SELF " ], " nb " , $param , " " , 'align="center"' , $sortfield , $sortorder );
2018-03-26 15:45:56 +02:00
print_liste_field_titre ( " NbOfPermissions " , $_SERVER [ " PHP_SELF " ], " nbpermissions " , $param , " " , 'align="center"' , $sortfield , $sortorder );
2017-08-02 13:31:53 +02:00
print_liste_field_titre ( " DateCreationShort " , $_SERVER [ " PHP_SELF " ], " g.datec " , $param , " " , 'align="right"' , $sortfield , $sortorder );
2005-09-06 21:17:12 +02:00
print " </tr> \n " ;
2017-01-23 12:29:05 +01:00
2018-02-06 19:16:15 +01:00
$grouptemp = new UserGroup ( $db );
2005-09-06 21:17:12 +02:00
while ( $i < $num )
2005-01-27 16:55:40 +01:00
{
2005-09-06 21:17:12 +02:00
$obj = $db -> fetch_object ( $resql );
2017-06-06 07:57:03 +02:00
2018-02-06 19:29:16 +01:00
$grouptemp -> id = $obj -> rowid ;
2018-02-06 19:16:15 +01:00
$grouptemp -> name = $obj -> name ;
$grouptemp -> note = $obj -> note ;
2005-09-06 21:17:12 +02:00
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2018-02-06 19:16:15 +01:00
print '<td>' ;
print $grouptemp -> getNomUrl ( 1 );
2012-07-07 15:11:58 +02:00
if ( ! $obj -> entity )
2009-04-27 22:37:50 +02:00
{
2011-08-17 17:56:22 +02:00
print img_picto ( $langs -> trans ( " GlobalGroup " ), 'redstar' );
2009-04-27 22:37:50 +02:00
}
print " </td> " ;
2011-08-19 09:22:17 +02:00
//multicompany
2017-06-06 07:57:03 +02:00
if ( ! empty ( $conf -> multicompany -> enabled ) && is_object ( $mc ) && empty ( $conf -> global -> MULTICOMPANY_TRANSVERSE_MODE ) && $conf -> entity == 1 )
2011-08-19 09:22:17 +02:00
{
$mc -> getInfo ( $obj -> entity );
print '<td align="center">' . $mc -> label . '</td>' ;
}
2011-02-12 00:39:21 +01:00
print '<td align="center">' . $obj -> nb . '</td>' ;
2018-03-26 15:45:56 +02:00
print '<td align="center">' . $obj -> nbpermissions . '</td>' ;
2013-04-25 01:13:13 +02:00
print '<td align="right" class="nowrap">' . dol_print_date ( $db -> jdate ( $obj -> datec ), " dayhour " ) . '</td>' ;
2005-09-06 21:17:12 +02:00
print " </tr> \n " ;
$i ++ ;
2005-01-27 16:55:40 +01:00
}
print " </table> " ;
2017-01-23 12:29:05 +01:00
2017-01-17 20:04:41 +01:00
print '</div>' ;
print " </form> \n " ;
2017-01-23 12:29:05 +01:00
2017-06-16 17:01:43 +02:00
$db -> free ( $resql );
2005-01-27 16:55:40 +01:00
}
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2005-01-27 16:55:40 +01:00
}
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-07-10 13:20:53 +02:00
$db -> close ();