2005-01-27 16:55:40 +01:00
< ? php
2017-07-12 15:52:58 +02:00
/* Copyright ( C ) 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2021-05-31 16:00:03 +02:00
* Copyright ( C ) 2005 - 2021 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2005 - 2017 Regis Houssin < regis . houssin @ inodbox . com >
* Copyright ( C ) 2011 Herve Prot < herve . prot @ symeos . com >
* Copyright ( C ) 2012 Florian Henry < florian . henry @ open - concept . pro >
* Copyright ( C ) 2018 Juanjo Menent < jmenent @ 2 byte . es >
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
*/
/**
2014-09-18 21:18:25 +02:00
* \file htdocs / user / group / card . php
2021-05-31 16:00:03 +02:00
* \brief Tab of a user group
2008-11-20 23:00:17 +01:00
*/
2005-01-27 16:55:40 +01:00
2012-08-22 23:24:21 +02:00
require '../../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/user/class/usergroup.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/usergroups.lib.php' ;
2014-09-22 23:43:22 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php' ;
2017-03-08 11:34:21 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
2005-01-27 16:55:40 +01:00
2006-05-30 23:42:38 +02:00
// Defini si peux lire/modifier utilisateurs et permisssions
2019-11-07 12:59:59 +01:00
$canreadperms = ( $user -> admin || $user -> rights -> user -> user -> lire );
$caneditperms = ( $user -> admin || $user -> rights -> user -> user -> creer );
$candisableperms = ( $user -> admin || $user -> rights -> user -> user -> supprimer );
2019-02-25 10:44:22 +01:00
$feature2 = 'user' ;
2010-11-08 12:40:52 +01:00
// Advanced permissions
2021-02-26 13:18:40 +01:00
if ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS )) {
2020-10-31 14:32:18 +01:00
$canreadperms = ( $user -> admin || $user -> rights -> user -> group_advance -> read );
$caneditperms = ( $user -> admin || $user -> rights -> user -> group_advance -> write );
$candisableperms = ( $user -> admin || $user -> rights -> user -> group_advance -> delete );
$feature2 = 'group_advance' ;
2010-11-08 12:40:52 +01:00
}
2006-05-30 23:42:38 +02:00
2018-05-26 16:24:54 +02:00
// Load translation files required by page
$langs -> loadLangs ( array ( 'users' , 'other' ));
2005-01-27 16:55:40 +01:00
2019-02-16 10:29:15 +01:00
$id = GETPOST ( 'id' , 'int' );
2020-09-16 19:39:50 +02:00
$action = GETPOST ( 'action' , 'aZ09' );
2019-02-16 10:29:15 +01:00
$cancel = GETPOST ( 'cancel' , 'aZ09' );
$confirm = GETPOST ( 'confirm' , 'alpha' );
2019-11-07 12:59:59 +01:00
$contextpage = GETPOST ( 'contextpage' , 'aZ' ) ? GETPOST ( 'contextpage' , 'aZ' ) : 'groupcard' ; // To manage different context of search
2020-04-13 15:38:50 +02:00
$backtopage = GETPOST ( 'backtopage' , 'alpha' );
2011-08-21 02:20:43 +02:00
2019-02-16 10:29:15 +01:00
$userid = GETPOST ( 'user' , 'int' );
2018-04-07 16:17:40 +02:00
2011-06-07 17:45:01 +02:00
$object = new Usergroup ( $db );
2014-09-22 16:31:58 +02:00
$extrafields = new ExtraFields ( $db );
// fetch optionals attributes and labels
2019-10-06 14:41:52 +02:00
$extrafields -> fetch_name_optionals_label ( $object -> table_element );
2005-01-31 16:28:22 +01:00
2020-04-13 19:03:48 +02:00
// Load object
include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php' ; // Must be include, not include_once.
$object -> getrights ();
2017-11-04 15:40:35 +01:00
// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
2019-11-07 12:59:59 +01:00
$hookmanager -> initHooks ( array ( 'groupcard' , 'globalcard' ));
2018-03-31 18:48:27 +02:00
2021-03-19 15:05:28 +01:00
// Security check
$result = restrictedArea ( $user , 'user' , $id , 'usergroup&usergroup' , $feature2 );
// 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-03-31 18:48:27 +02:00
2005-01-31 16:28:22 +01:00
2005-01-27 16:55:40 +01:00
/**
2017-11-04 15:40:35 +01:00
* Actions
2005-02-26 15:23:54 +01:00
*/
2019-11-07 12:59:59 +01:00
$parameters = array ( 'id' => $id , 'userid' => $userid , 'caneditperms' => $caneditperms );
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // 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' );
}
2012-07-07 10:57:54 +02:00
2017-11-04 15:40:35 +01:00
if ( empty ( $reshook )) {
2020-04-13 15:38:50 +02:00
$backurlforlist = DOL_URL_ROOT . '/user/group/list.php' ;
if ( empty ( $backtopage ) || ( $cancel && empty ( $id ))) {
if ( empty ( $backtopage ) || ( $cancel && strpos ( $backtopage , '__ID__' ))) {
2021-02-26 13:18:40 +01:00
if ( empty ( $id ) && (( $action != 'add' && $action != 'create' ) || $cancel )) {
$backtopage = $backurlforlist ;
} else {
2021-09-18 19:34:46 +02:00
$backtopage = DOL_URL_ROOT . '/user/group/card.php?id=' . ( $id > 0 ? $id : '__ID__' );
2021-02-26 13:18:40 +01:00
}
2020-04-13 15:38:50 +02:00
}
}
2021-02-26 13:18:40 +01:00
if ( $cancel ) {
2020-04-13 15:38:50 +02:00
header ( " Location: " . $backtopage );
exit ;
2018-04-07 16:17:40 +02:00
}
2017-11-04 15:40:35 +01:00
// Action remove group
2021-02-26 13:18:40 +01:00
if ( $action == 'confirm_delete' && $confirm == " yes " ) {
if ( $caneditperms ) {
2017-11-04 15:40:35 +01:00
$object -> fetch ( $id );
2018-12-22 17:34:27 +01:00
$object -> delete ( $user );
2018-12-11 13:25:33 +01:00
header ( " Location: " . DOL_URL_ROOT . " /user/group/list.php?restore_lastsearch_values=1 " );
2017-11-04 15:40:35 +01:00
exit ;
2020-05-21 15:05:19 +02:00
} else {
2017-11-04 15:40:35 +01:00
$langs -> load ( " errors " );
setEventMessages ( $langs -> trans ( 'ErrorForbidden' ), null , 'errors' );
}
}
2011-07-08 20:49:16 +02:00
2017-11-04 15:40:35 +01:00
// Action add group
2021-02-26 13:18:40 +01:00
if ( $action == 'add' ) {
if ( $caneditperms ) {
2022-06-13 10:44:20 +02:00
if ( ! GETPOST ( " nom " , " alphanohtml " )) {
2017-11-04 15:40:35 +01:00
setEventMessages ( $langs -> trans ( " NameNotDefined " ), null , 'errors' );
2019-11-07 12:59:59 +01:00
$action = " create " ; // Go back to create page
2017-11-04 15:40:35 +01:00
} else {
2022-06-13 10:44:20 +02:00
$object -> name = GETPOST ( " nom " , 'alphanohtml' );
2020-09-18 01:29:17 +02:00
$object -> note = dol_htmlcleanlastbr ( trim ( GETPOST ( " note " , 'restricthtml' )));
2011-07-08 20:49:16 +02:00
2017-11-04 15:40:35 +01:00
// Fill array 'array_options' with data from add form
2019-10-06 14:41:52 +02:00
$ret = $extrafields -> setOptionalsFromPost ( null , $object );
2021-02-26 13:18:40 +01:00
if ( $ret < 0 ) {
$error ++ ;
}
2011-07-08 20:49:16 +02:00
2021-02-26 13:18:40 +01:00
if ( ! empty ( $conf -> multicompany -> enabled ) && ! empty ( $conf -> global -> MULTICOMPANY_TRANSVERSE_MODE )) {
$object -> entity = 0 ;
} else {
2021-05-17 07:08:45 +02:00
if ( $conf -> entity == 1 && $user -> admin && ! $user -> entity ) { // Same permissions test than the one used to show the combo of entities into the form
$object -> entity = GETPOSTISSET ( " entity " ) ? GETPOST ( " entity " ) : $conf -> entity ;
} else {
$object -> entity = $conf -> entity ;
}
2021-02-26 13:18:40 +01:00
}
2011-07-08 20:49:16 +02:00
2017-11-04 15:40:35 +01:00
$db -> begin ();
2011-07-08 20:49:16 +02:00
2017-11-04 15:40:35 +01:00
$id = $object -> create ();
2005-01-27 16:55:40 +01:00
2021-02-26 13:18:40 +01:00
if ( $id > 0 ) {
2017-11-04 15:40:35 +01:00
$db -> commit ();
2011-07-08 20:49:16 +02:00
2017-11-04 15:40:35 +01:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2017-11-04 15:40:35 +01:00
$db -> rollback ();
2011-07-08 20:49:16 +02:00
2017-11-04 15:40:35 +01:00
$langs -> load ( " errors " );
2019-01-27 11:55:16 +01:00
setEventMessages ( $langs -> trans ( " ErrorGroupAlreadyExists " , $object -> name ), null , 'errors' );
2019-11-07 12:59:59 +01:00
$action = " create " ; // Go back to create page
2017-11-04 15:40:35 +01:00
}
}
2020-05-21 15:05:19 +02:00
} else {
2017-11-04 15:40:35 +01:00
$langs -> load ( " errors " );
setEventMessages ( $langs -> trans ( 'ErrorForbidden' ), null , 'errors' );
}
}
2005-01-27 16:55:40 +01:00
2017-11-04 15:40:35 +01:00
// Add/Remove user into group
2021-02-26 13:18:40 +01:00
if ( $action == 'adduser' || $action == 'removeuser' ) {
if ( $caneditperms ) {
if ( $userid > 0 ) {
2017-11-04 15:40:35 +01:00
$object -> fetch ( $id );
$object -> oldcopy = clone $object ;
2005-01-27 16:55:40 +01:00
2017-11-04 15:40:35 +01:00
$edituser = new User ( $db );
$edituser -> fetch ( $userid );
2021-02-26 13:18:40 +01:00
if ( $action == 'adduser' ) {
$result = $edituser -> SetInGroup ( $object -> id , $object -> entity );
}
if ( $action == 'removeuser' ) {
$result = $edituser -> RemoveFromGroup ( $object -> id , $object -> entity );
}
2011-07-08 20:49:16 +02:00
2021-02-26 13:18:40 +01:00
if ( $result > 0 ) {
2017-11-04 15:40:35 +01:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2017-11-04 15:40:35 +01:00
setEventMessages ( $edituser -> error , $edituser -> errors , 'errors' );
}
}
2020-05-21 15:05:19 +02:00
} else {
2017-11-04 15:40:35 +01:00
$langs -> load ( " errors " );
setEventMessages ( $langs -> trans ( 'ErrorForbidden' ), null , 'errors' );
}
}
2011-07-08 20:49:16 +02:00
2021-02-26 13:18:40 +01:00
if ( $action == 'update' ) {
if ( $caneditperms ) {
2017-11-04 15:40:35 +01:00
$db -> begin ();
2012-07-07 10:57:54 +02:00
2017-11-04 15:40:35 +01:00
$object -> fetch ( $id );
2014-09-22 16:31:58 +02:00
2017-11-04 15:40:35 +01:00
$object -> oldcopy = clone $object ;
2011-07-08 20:49:16 +02:00
2022-06-13 10:44:20 +02:00
$object -> name = GETPOST ( " nom " , 'alphanohtml' );
2022-03-08 21:19:29 +01:00
$object -> note = dol_htmlcleanlastbr ( trim ( GETPOST ( " note " , 'restricthtml' )));
2011-07-08 20:49:16 +02:00
2017-11-04 15:40:35 +01:00
// Fill array 'array_options' with data from add form
2021-12-06 11:19:12 +01:00
$ret = $extrafields -> setOptionalsFromPost ( null , $object , '@GETPOSTISSET' );
2021-02-26 13:18:40 +01:00
if ( $ret < 0 ) {
$error ++ ;
}
2017-06-06 07:57:03 +02:00
2021-02-26 13:18:40 +01:00
if ( ! empty ( $conf -> multicompany -> enabled ) && ! empty ( $conf -> global -> MULTICOMPANY_TRANSVERSE_MODE )) {
$object -> entity = 0 ;
2022-03-17 10:56:14 +01:00
} elseif ( GETPOSTISSET ( " entity " )) {
$object -> entity = GETPOST ( " entity " , " int " );
2021-02-26 13:18:40 +01:00
}
2005-02-27 15:12:16 +01:00
2019-11-07 12:59:59 +01:00
$ret = $object -> update ();
2017-11-04 15:40:35 +01:00
2021-02-26 13:18:40 +01:00
if ( $ret >= 0 && ! count ( $object -> errors )) {
2017-11-04 15:40:35 +01:00
setEventMessages ( $langs -> trans ( " GroupModified " ), null , 'mesgs' );
$db -> commit ();
2020-05-21 15:05:19 +02:00
} else {
2017-11-04 15:40:35 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$db -> rollback ();
}
2020-05-21 15:05:19 +02:00
} else {
2017-11-04 15:40:35 +01:00
$langs -> load ( " errors " );
setEventMessages ( $langs -> trans ( 'ErrorForbidden' ), null , 'mesgs' );
}
}
// Actions to build doc
2021-11-18 19:25:07 +01:00
$upload_dir = $conf -> user -> dir_output . '/usergroups' ;
2019-11-07 12:59:59 +01:00
$permissiontoadd = $user -> rights -> user -> user -> creer ;
2017-11-04 15:40:35 +01:00
include DOL_DOCUMENT_ROOT . '/core/actions_builddoc.inc.php' ;
}
2005-02-27 15:12:16 +01:00
2009-08-12 01:42:21 +02:00
/*
* View
*/
2019-01-27 11:55:16 +01:00
llxHeader ( '' , $langs -> trans ( " GroupCard " ));
2005-01-27 16:55:40 +01:00
2011-06-07 17:45:01 +02:00
$form = new Form ( $db );
2011-04-06 21:54:06 +02:00
$fuserstatic = new User ( $db );
2017-03-08 11:34:21 +01:00
$form = new Form ( $db );
$formfile = new FormFile ( $db );
2005-01-27 16:55:40 +01:00
2022-07-11 00:05:50 +02:00
if ( $action == 'create' ) {
2020-10-31 14:32:18 +01:00
print load_fiche_titre ( $langs -> trans ( " NewGroup " ), '' , 'object_group' );
2011-07-08 20:49:16 +02:00
2022-05-19 13:08:00 +02:00
dol_set_focus ( '#nom' );
2013-02-18 15:01:00 +01:00
2020-10-31 14:32:18 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' ;
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
print '<input type="hidden" name="action" value="add">' ;
2020-04-13 15:38:50 +02:00
print '<input type="hidden" name="backtopage" value="' . $backtopage . '">' ;
2011-07-08 20:49:16 +02:00
2020-10-31 14:32:18 +01:00
print dol_get_fiche_head ( '' , '' , '' , 0 , '' );
2015-05-04 11:41:30 +02:00
2020-10-31 14:32:18 +01:00
print '<table class="border centpercent tableforfieldcreate">' ;
2011-08-24 00:10:25 +02:00
2011-08-19 09:22:17 +02:00
// Multicompany
2021-02-26 13:18:40 +01:00
if ( ! empty ( $conf -> multicompany -> enabled ) && is_object ( $mc )) {
if ( empty ( $conf -> global -> MULTICOMPANY_TRANSVERSE_MODE ) && $conf -> entity == 1 && $user -> admin && ! $user -> entity ) {
2017-01-22 12:13:32 +01:00
print " <tr> " . '<td class="tdtop">' . $langs -> trans ( " Entity " ) . '</td>' ;
2011-08-20 00:15:22 +02:00
print " <td> " . $mc -> select_entities ( $conf -> entity );
print " </td></tr> \n " ;
2020-05-21 15:05:19 +02:00
} else {
2011-08-20 00:15:22 +02:00
print '<input type="hidden" name="entity" value="' . $conf -> entity . '" />' ;
}
2011-08-19 09:22:17 +02:00
}
2011-07-08 20:49:16 +02:00
2020-04-13 15:38:50 +02:00
// Common attributes
include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_add.tpl.php' ;
2014-10-04 17:20:17 +02:00
2014-09-22 16:31:58 +02:00
// Other attributes
2020-04-13 15:38:50 +02:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_add.tpl.php' ;
2014-10-04 17:20:17 +02:00
2020-04-13 15:38:50 +02:00
print " </table> \n " ;
2011-10-10 00:03:26 +02:00
2020-10-31 14:32:18 +01:00
print dol_get_fiche_end ();
2015-05-04 11:41:30 +02:00
2020-10-31 14:32:18 +01:00
print '<div class="center">' ;
print '<input class="button" name="add" value="' . $langs -> trans ( " CreateGroup " ) . '" type="submit">' ;
print ' ' ;
2020-11-23 15:12:52 +01:00
print '<input class="button button-cancel" value="' . $langs -> trans ( " Cancel " ) . '" name="cancel" type="submit">' ;
2020-10-31 14:32:18 +01:00
print '</div>' ;
2011-10-10 00:03:26 +02:00
2020-10-31 14:32:18 +01:00
print " </form> " ;
2021-02-26 13:18:40 +01:00
} else {
/* ************************************************************************** */
/* */
/* Visu et edition */
/* */
/* ************************************************************************** */
if ( $id ) {
2020-04-13 19:03:48 +02:00
$res = $object -> fetch_optionals ();
2020-10-31 14:32:18 +01:00
$head = group_prepare_head ( $object );
$title = $langs -> trans ( " Group " );
2011-07-08 20:49:16 +02:00
2011-08-19 09:22:17 +02:00
/*
* Confirmation suppression
*/
2021-02-26 13:18:40 +01:00
if ( $action == 'delete' ) {
2019-01-27 11:55:16 +01:00
print $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id , $langs -> trans ( " DeleteAGroup " ), $langs -> trans ( " ConfirmDeleteGroup " , $object -> name ), " confirm_delete " , '' , 0 , 1 );
2011-08-19 09:22:17 +02:00
}
/*
* Fiche en mode visu
*/
2021-02-26 13:18:40 +01:00
if ( $action != 'edit' ) {
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'group' , $title , - 1 , 'group' );
2015-05-04 11:41:30 +02:00
2018-04-06 00:36:52 +02:00
$linkback = '<a href="' . DOL_URL_ROOT . '/user/group/list.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2018-02-07 12:08:25 +01:00
2019-01-27 11:55:16 +01:00
dol_banner_tab ( $object , 'id' , $linkback , $user -> rights -> user -> user -> lire || $user -> admin );
2017-06-06 07:57:03 +02:00
2017-05-09 10:19:39 +02:00
print '<div class="fichecenter">' ;
2020-04-13 15:38:50 +02:00
print '<div class="fichehalfleft">' ;
2017-05-09 10:19:39 +02:00
print '<div class="underbanner clearboth"></div>' ;
2017-06-06 07:57:03 +02:00
2019-10-06 14:57:34 +02:00
print '<table class="border centpercent tableforfield">' ;
2011-08-19 09:22:17 +02:00
2020-10-31 14:32:18 +01:00
// Name (already in dol_banner, we keep it to have the GlobalGroup picto, but we should move it in dol_banner)
2021-02-26 13:18:40 +01:00
if ( ! empty ( $conf -> mutlicompany -> enabled )) {
2020-10-31 14:32:18 +01:00
print '<tr><td class="titlefield">' . $langs -> trans ( " Name " ) . '</td>' ;
print '<td class="valeur">' . dol_escape_htmltag ( $object -> name );
2021-02-26 13:18:40 +01:00
if ( empty ( $object -> entity )) {
2020-10-31 14:32:18 +01:00
print img_picto ( $langs -> trans ( " GlobalGroup " ), 'redstar' );
}
print " </td></tr> \n " ;
}
2011-08-24 00:10:25 +02:00
2011-08-20 00:15:22 +02:00
// 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 && $user -> admin && ! $user -> entity ) {
2011-08-20 00:15:22 +02:00
$mc -> getInfo ( $object -> entity );
2017-12-02 14:57:27 +01:00
print " <tr> " . '<td class="titlefield">' . $langs -> trans ( " Entity " ) . '</td>' ;
2018-04-06 19:23:41 +02:00
print '<td class="valeur">' . dol_escape_htmltag ( $mc -> label );
2011-08-20 00:15:22 +02:00
print " </td></tr> \n " ;
}
2011-08-19 09:22:17 +02:00
2020-04-13 19:03:48 +02:00
unset ( $object -> fields [ 'nom' ]); // Name already displayed in banner
2020-04-13 15:38:50 +02:00
// Common attributes
$keyforbreak = '' ;
include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_view.tpl.php' ;
2014-10-04 17:20:17 +02:00
2014-09-22 16:31:58 +02:00
// Other attributes
2019-11-07 12:59:59 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php' ;
2014-10-04 17:20:17 +02:00
2020-04-13 15:38:50 +02:00
print '</table>' ;
print '</div>' ;
print '</div>' ;
print '<div class="clearboth"></div>' ;
2017-06-06 07:57:03 +02:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2015-05-04 11:41:30 +02:00
2011-08-19 09:22:17 +02:00
/*
2021-03-16 04:22:43 +01:00
* Action bar
2011-08-19 09:22:17 +02:00
*/
print '<div class="tabsAction">' ;
2020-04-13 15:38:50 +02:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'addMoreActionsButtons' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2021-02-26 13:18:40 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2020-04-13 15:38:50 +02:00
2021-02-26 13:18:40 +01:00
if ( $caneditperms ) {
2021-09-18 22:04:41 +02:00
print '<a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&action=edit&token=' . newToken () . '">' . $langs -> trans ( " Modify " ) . '</a>' ;
2011-08-19 09:22:17 +02:00
}
2021-02-26 13:18:40 +01:00
if ( $candisableperms ) {
2021-09-19 14:41:46 +02:00
print '<a class="butActionDelete" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=delete&token=' . newToken () . '&id=' . $object -> id . '">' . $langs -> trans ( " DeleteGroup " ) . '</a>' ;
2011-08-19 09:22:17 +02:00
}
print " </div> \n " ;
2011-07-08 20:49:16 +02:00
2020-10-31 14:32:18 +01:00
// List users in group
2009-05-04 20:13:07 +02:00
2020-10-31 14:32:18 +01:00
print load_fiche_titre ( $langs -> trans ( " ListOfUsersInGroup " ), '' , 'user' );
2009-05-04 20:13:07 +02:00
2020-10-31 14:32:18 +01:00
// On selectionne les users qui ne sont pas deja dans le groupe
$exclude = array ();
2011-08-24 00:10:25 +02:00
2021-02-26 13:18:40 +01:00
if ( ! empty ( $object -> members )) {
foreach ( $object -> members as $useringroup ) {
2019-11-07 12:59:59 +01:00
$exclude [] = $useringroup -> id ;
2017-11-04 15:40:35 +01:00
}
}
2011-07-08 20:49:16 +02:00
2017-11-04 15:40:35 +01:00
// Other form for add user to group
2019-11-07 12:59:59 +01:00
$parameters = array ( 'caneditperms' => $caneditperms , 'exclude' => $exclude );
$reshook = $hookmanager -> executeHooks ( 'formAddUserToGroup' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2017-11-04 15:40:35 +01:00
print $hookmanager -> resPrint ;
2009-05-04 20:13:07 +02:00
2021-02-26 13:18:40 +01:00
if ( empty ( $reshook )) {
if ( $caneditperms ) {
2017-11-04 15:40:35 +01:00
print '<form action="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '" method="POST">' . " \n " ;
2019-12-01 10:20:11 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2017-11-04 15:40:35 +01:00
print '<input type="hidden" name="action" value="adduser">' ;
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' . " \n " ;
2017-11-04 15:40:35 +01:00
print '<tr class="liste_titre"><td class="titlefield liste_titre">' . $langs -> trans ( " NonAffectedUsers " ) . '</td>' . " \n " ;
print '<td class="liste_titre">' ;
2021-09-28 11:53:00 +02:00
print $form -> select_dolusers ( '' , 'user' , 1 , $exclude , 0 , '' , '' , $object -> entity , 0 , 0 , '' , 0 , '' , 'minwidth200 maxwidth500' );
2017-11-04 15:40:35 +01:00
print ' ' ;
print '<input type="hidden" name="entity" value="' . $conf -> entity . '">' ;
2021-09-16 11:33:42 +02:00
print '<input type="submit" class="button buttongen button-add" value="' . $langs -> trans ( " Add " ) . '">' ;
2017-11-04 15:40:35 +01:00
print '</td></tr>' . " \n " ;
print '</table></form>' . " \n " ;
print '<br>' ;
}
2011-06-07 17:45:01 +02:00
2017-11-04 15:40:35 +01:00
/*
* Group members
*/
2020-04-19 14:29:18 +02:00
2021-07-03 17:58:37 +02:00
print '<div class="div-table-responsive">' ; // You can use div-table-responsive-no-min if you dont need reserved height for your table
2019-02-16 10:29:15 +01:00
print '<table class="noborder centpercent">' ;
2017-11-04 15:40:35 +01:00
print '<tr class="liste_titre">' ;
print '<td class="liste_titre">' . $langs -> trans ( " Login " ) . '</td>' ;
print '<td class="liste_titre">' . $langs -> trans ( " Lastname " ) . '</td>' ;
print '<td class="liste_titre">' . $langs -> trans ( " Firstname " ) . '</td>' ;
2019-02-16 10:29:15 +01:00
print '<td class="liste_titre center" width="5">' . $langs -> trans ( " Status " ) . '</td>' ;
print '<td class="liste_titre right" width="5"> </td>' ;
2017-11-04 15:40:35 +01:00
print " </tr> \n " ;
2021-02-26 13:18:40 +01:00
if ( ! empty ( $object -> members )) {
foreach ( $object -> members as $useringroup ) {
2017-11-04 15:40:35 +01:00
print '<tr class="oddeven">' ;
2021-07-03 17:58:37 +02:00
print '<td class="tdoverflowmax150">' ;
2017-11-04 15:40:35 +01:00
print $useringroup -> getNomUrl ( - 1 , '' , 0 , 0 , 24 , 0 , 'login' );
2022-09-10 08:33:36 +02:00
if ( isModEnabled ( 'multicompany' ) && $useringroup -> admin && empty ( $useringroup -> entity )) {
2020-10-31 14:32:18 +01:00
print img_picto ( $langs -> trans ( " SuperAdministrator " ), 'redstar' );
} elseif ( $useringroup -> admin ) {
print img_picto ( $langs -> trans ( " Administrator " ), 'star' );
}
2017-11-04 15:40:35 +01:00
print '</td>' ;
print '<td>' . $useringroup -> lastname . '</td>' ;
print '<td>' . $useringroup -> firstname . '</td>' ;
2020-04-13 15:38:50 +02:00
print '<td class="center">' . $useringroup -> getLibStatut ( 5 ) . '</td>' ;
2019-02-16 10:29:15 +01:00
print '<td class="right">' ;
2019-11-07 12:59:59 +01:00
if ( ! empty ( $user -> admin )) {
2022-05-08 15:18:34 +02:00
print '<a href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&action=removeuser&token=' . newToken () . '&user=' . $useringroup -> id . '">' ;
2018-03-19 19:08:35 +01:00
print img_picto ( $langs -> trans ( " RemoveFromGroup " ), 'unlink' );
2017-11-04 15:40:35 +01:00
print '</a>' ;
2020-05-21 15:05:19 +02:00
} else {
2017-11-04 15:40:35 +01:00
print " - " ;
}
print " </td></tr> \n " ;
2017-07-12 15:52:58 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2017-11-04 15:40:35 +01:00
print '<tr><td colspan="6" class="opacitymedium">' . $langs -> trans ( " None " ) . '</td></tr>' ;
}
print " </table> " ;
2021-07-03 17:58:37 +02:00
print '</div>' ;
2017-11-04 15:40:35 +01:00
}
print " <br> " ;
print '<div class="fichecenter"><div class="fichehalfleft">' ;
2017-06-06 07:57:03 +02:00
2017-03-08 11:34:21 +01:00
/*
2021-03-16 04:04:18 +01:00
* Generated documents
2021-02-26 13:18:40 +01:00
*/
2020-04-12 18:36:22 +02:00
2020-10-31 14:32:18 +01:00
$filename = dol_sanitizeFileName ( $object -> ref );
2021-11-18 19:25:07 +01:00
$filedir = $conf -> user -> dir_output . " /usergroups/ " . dol_sanitizeFileName ( $object -> ref );
2020-10-31 14:32:18 +01:00
$urlsource = $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id ;
$genallowed = $user -> rights -> user -> user -> creer ;
$delallowed = $user -> rights -> user -> user -> supprimer ;
2017-06-06 07:57:03 +02:00
2022-05-08 15:18:34 +02:00
$somethingshown = $formfile -> showdocuments ( 'usergroup' , $filename , $filedir , $urlsource , $genallowed , $delallowed , $object -> model_pdf , 1 , 0 , 0 , 28 , 0 , '' , 0 , '' , $mysoc -> default_lang );
2017-06-06 07:57:03 +02:00
2020-10-31 14:32:18 +01:00
// Show links to link elements
$linktoelem = $form -> showLinkToObjectBlock ( $object , null , null );
$somethingshown = $form -> showLinkedObjectBlock ( $object , $linktoelem );
2017-06-06 07:57:03 +02:00
2021-10-23 17:18:35 +02:00
print '</div><div class="fichehalfright">' ;
2017-06-06 07:57:03 +02:00
2017-03-08 11:34:21 +01:00
// List of actions on element
2017-12-09 17:29:19 +01:00
/* include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php' ;
2017-03-08 11:34:21 +01:00
$formactions = new FormActions ( $db );
2017-12-09 17:29:19 +01:00
$somethingshown = $formactions -> showactions ( $object , 'usergroup' , $socid , 1 ); */
2017-06-06 07:57:03 +02:00
2021-10-23 17:18:35 +02:00
print '</div></div>' ;
2020-10-31 14:32:18 +01:00
}
2009-05-04 20:13:07 +02:00
2020-10-31 14:32:18 +01:00
/*
2021-02-26 13:18:40 +01:00
* Fiche en mode edition
*/
2020-04-12 18:36:22 +02:00
2021-02-26 13:18:40 +01:00
if ( $action == 'edit' && $caneditperms ) {
2020-10-31 14:32:18 +01:00
print '<form action="' . $_SERVER [ 'PHP_SELF' ] . '" method="post" name="updategroup" enctype="multipart/form-data">' ;
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
print '<input type="hidden" name="action" value="update">' ;
2020-04-13 15:38:50 +02:00
print '<input type="hidden" name="backtopage" value="' . $backtopage . '">' ;
print '<input type="hidden" name="id" value="' . $object -> id . '">' ;
2009-05-04 20:13:07 +02:00
2020-10-31 14:32:18 +01:00
print dol_get_fiche_head ( $head , 'group' , $title , 0 , 'group' );
2015-05-04 11:41:30 +02:00
2020-04-13 15:38:50 +02:00
print '<table class="border centpercent tableforfieldedit">' . " \n " ;
2011-08-24 00:10:25 +02:00
2020-04-13 15:38:50 +02:00
// Multicompany
2021-02-26 13:18:40 +01:00
if ( ! empty ( $conf -> multicompany -> enabled ) && is_object ( $mc )) {
if ( empty ( $conf -> global -> MULTICOMPANY_TRANSVERSE_MODE ) && $conf -> entity == 1 && $user -> admin && ! $user -> entity ) {
2020-04-13 15:38:50 +02:00
print " <tr> " . '<td class="tdtop">' . $langs -> trans ( " Entity " ) . '</td>' ;
print " <td> " . $mc -> select_entities ( $object -> entity );
print " </td></tr> \n " ;
2020-05-21 15:05:19 +02:00
} else {
2017-07-12 15:52:58 +02:00
print '<input type="hidden" name="entity" value="' . $conf -> entity . '" />' ;
}
2020-04-13 15:38:50 +02:00
}
// Common attributes
include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_edit.tpl.php' ;
2011-07-08 20:49:16 +02:00
2017-07-12 15:52:58 +02:00
// Other attributes
2020-04-13 15:38:50 +02:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_edit.tpl.php' ;
2014-10-04 17:20:17 +02:00
2020-04-13 15:38:50 +02:00
print '</table>' ;
2011-11-05 23:18:49 +01:00
2020-10-31 14:32:18 +01:00
print dol_get_fiche_end ();
2011-11-05 23:18:49 +01:00
2021-08-20 14:41:30 +02:00
print $form -> buttonsSaveCancel ();
2011-07-08 20:49:16 +02:00
2020-10-31 14:32:18 +01:00
print '</form>' ;
}
}
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-01-13 18:24:25 +01:00
$db -> close ();