2005-01-27 16:55:40 +01:00
< ? php
2019-02-25 20:35:59 +01:00
/* Copyright ( c ) 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2018-09-20 17:26:39 +02:00
* Copyright ( c ) 2005 - 2018 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( c ) 2005 - 2018 Regis Houssin < regis . houssin @ inodbox . com >
2018-09-20 17:26:39 +02:00
* Copyright ( C ) 2012 Florian Henry < florian . henry @ open - concept . pro >
* Copyright ( C ) 2014 Juanjo Menent < jmenent @ 2 byte . es >
* Copyright ( C ) 2014 Alexis Algoud < alexis @ atm - consulting . fr >
* Copyright ( C ) 2018 Nicolas ZABOURI < info @ inovea - conseil . com >
2019-09-11 23:45:02 +02:00
* Copyright ( C ) 2019 Abbes Bahfir < dolipar @ dolipar . org >
2006-11-19 17:41:17 +01:00
*
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
*/
2006-11-19 17:41:17 +01:00
/**
2010-07-21 14:35:56 +02:00
* \file htdocs / user / class / usergroup . class . php
2012-01-11 01:06:56 +01:00
* \brief File of class to manage user groups
2009-05-04 20:01:47 +02:00
*/
2005-01-27 16:55:40 +01:00
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php' ;
2021-02-26 13:18:40 +01:00
if ( ! empty ( $conf -> ldap -> enabled )) {
require_once DOL_DOCUMENT_ROOT . " /core/class/ldap.class.php " ;
}
2006-11-20 03:10:47 +01:00
2006-11-19 17:41:17 +01:00
/**
2013-09-09 03:43:59 +02:00
* Class to manage user groups
2009-05-04 20:01:47 +02:00
*/
2009-04-27 22:37:50 +02:00
class UserGroup extends CommonObject
2005-01-27 16:55:40 +01:00
{
2018-08-23 18:52:47 +02:00
/**
* @ var string ID to identify managed object
*/
2020-04-10 10:59:32 +02:00
public $element = 'usergroup' ;
2018-09-02 20:37:12 +02:00
2018-08-22 19:56:24 +02:00
/**
* @ var string Name of table without prefix where object is stored
*/
2020-04-10 10:59:32 +02:00
public $table_element = 'usergroup' ;
2018-09-02 20:37:12 +02:00
2018-10-06 12:18:03 +02:00
/**
* 0 = No test on entity , 1 = Test with field entity , 2 = Test with link by societe
* @ var int
*/
public $ismultientitymanaged = 1 ;
2018-09-20 17:26:39 +02:00
2019-10-30 10:13:57 +01:00
/**
* @ var string String with name of icon for myobject . Must be the part after the 'object_' into object_myobject . png
*/
2020-04-10 10:59:32 +02:00
public $picto = 'group' ;
2017-06-06 07:57:03 +02:00
2018-08-31 18:27:16 +02:00
/**
* @ var int Entity of group
*/
public $entity ;
2018-02-06 19:16:15 +01:00
2015-04-23 23:21:06 +02:00
/**
2018-09-20 17:26:39 +02:00
* @ var string
2015-04-23 23:21:06 +02:00
* @ deprecated
2019-04-04 18:33:12 +02:00
* @ see $name
2015-04-23 23:21:06 +02:00
*/
2018-09-20 17:26:39 +02:00
public $nom ;
/**
* @ var string name
*/
2020-04-10 10:59:32 +02:00
public $name ; // Name of group
2018-09-20 17:26:39 +02:00
2020-04-10 10:59:32 +02:00
public $globalgroup ; // Global group
2018-09-20 17:26:39 +02:00
2019-03-22 09:38:04 +01:00
/**
2020-10-31 14:32:18 +01:00
* Date creation record ( datec )
*
* @ var integer
*/
public $datec ;
2018-09-20 17:26:39 +02:00
2019-03-22 09:38:04 +01:00
/**
2020-10-31 14:32:18 +01:00
* Date modification record ( tms )
*
* @ var integer
*/
public $datem ;
2018-09-20 17:26:39 +02:00
2020-12-05 23:53:55 +01:00
/**
* @ var string Description
*/
public $note ;
2018-09-20 17:26:39 +02:00
2020-04-10 10:59:32 +02:00
public $members = array (); // Array of users
2009-05-04 20:01:47 +02:00
2020-04-10 10:59:32 +02:00
public $nb_rights ; // Number of rights granted to the user
2017-12-15 15:15:14 +01:00
2020-04-10 10:59:32 +02:00
private $_tab_loaded = array (); // Array of cache of already loaded permissions
2012-01-11 01:06:56 +01:00
2020-04-10 10:59:32 +02:00
public $oldcopy ; // To contains a clone of this when we need to save old properties of object
2009-08-12 01:42:21 +02:00
2020-04-13 15:38:50 +02:00
public $fields = array (
'rowid' => array ( 'type' => 'integer' , 'label' => 'TechnicalID' , 'enabled' => 1 , 'visible' =>- 2 , 'notnull' => 1 , 'index' => 1 , 'position' => 1 , 'comment' => 'Id' ),
'entity' => array ( 'type' => 'integer' , 'label' => 'Entity' , 'enabled' => 1 , 'visible' => 0 , 'notnull' => 1 , 'default' => 1 , 'index' => 1 , 'position' => 5 ),
'nom' => array ( 'type' => 'varchar(180)' , 'label' => 'Name' , 'enabled' => 1 , 'visible' => 1 , 'notnull' => 1 , 'showoncombobox' => 1 , 'index' => 1 , 'position' => 10 , 'searchall' => 1 , 'comment' => 'Group name' ),
'note' => array ( 'type' => 'html' , 'label' => 'Description' , 'enabled' => 1 , 'visible' => 1 , 'position' => 20 , 'notnull' =>- 1 ,),
'datec' => array ( 'type' => 'datetime' , 'label' => 'DateCreation' , 'enabled' => 1 , 'visible' =>- 2 , 'position' => 50 , 'notnull' => 1 ,),
'tms' => array ( 'type' => 'timestamp' , 'label' => 'DateModification' , 'enabled' => 1 , 'visible' =>- 2 , 'position' => 60 , 'notnull' => 1 ,),
'model_pdf' => array ( 'type' => 'varchar(255)' , 'label' => 'ModelPDF' , 'enabled' => 1 , 'visible' => 0 , 'position' => 100 ),
);
2020-04-13 19:03:48 +02:00
/**
2020-12-05 23:53:55 +01:00
* @ var string Field with ID of parent key if this field has a parent
2020-04-13 19:03:48 +02:00
*/
public $fk_element = 'fk_usergroup' ;
/**
* @ var array List of child tables . To test if we can delete object .
*/
2020-04-23 18:55:10 +02:00
protected $childtables = array ();
2020-04-13 19:03:48 +02:00
/**
* @ var array List of child tables . To know object to delete on cascade .
*/
2020-04-23 18:55:10 +02:00
protected $childtablesoncascade = array ( 'usergroup_rights' , 'usergroup_user' );
2020-04-13 19:03:48 +02:00
2009-05-04 20:01:47 +02:00
/**
2020-10-31 14:32:18 +01:00
* Constructor de la classe
*
* @ param DoliDb $db Database handler
*/
public function __construct ( $db )
{
$this -> db = $db ;
$this -> nb_rights = 0 ;
}
2009-05-04 20:01:47 +02:00
/**
2019-03-22 09:38:04 +01:00
* Charge un objet group avec toutes ses caracteristiques ( except -> members array )
2011-09-04 20:41:19 +02:00
*
2017-09-15 23:21:42 +02:00
* @ param int $id Id of group to load
* @ param string $groupname Name of group to load
* @ param boolean $load_members Load all members of the group
* @ return int < 0 if KO , > 0 if OK
2009-05-04 20:01:47 +02:00
*/
2019-02-25 20:35:59 +01:00
public function fetch ( $id = '' , $groupname = '' , $load_members = true )
2009-05-04 20:01:47 +02:00
{
global $conf ;
2005-02-26 19:34:14 +01:00
2020-04-13 19:03:48 +02:00
dol_syslog ( get_class ( $this ) . " ::fetch " , LOG_DEBUG );
2021-02-26 13:18:40 +01:00
if ( ! empty ( $groupname )) {
2020-04-13 19:03:48 +02:00
$result = $this -> fetchCommon ( 0 , '' , ' AND nom = \'' . $this -> db -> escape ( $groupname ) . '\'' );
2020-05-21 15:05:19 +02:00
} else {
2020-04-13 19:03:48 +02:00
$result = $this -> fetchCommon ( $id );
2013-02-25 16:46:31 +01:00
}
2006-11-19 17:41:17 +01:00
2020-10-31 14:32:18 +01:00
$this -> name = $this -> nom ; // For compatibility with field name
2020-04-19 14:19:34 +02:00
2021-02-26 13:18:40 +01:00
if ( $result ) {
if ( $load_members ) {
2020-04-13 19:03:48 +02:00
$this -> members = $this -> listUsersForGroup ();
2009-05-04 20:01:47 +02:00
}
2020-04-13 19:03:48 +02:00
2009-05-04 20:01:47 +02:00
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2020-04-10 10:59:32 +02:00
$this -> error = $this -> db -> lasterror ();
2009-05-04 20:01:47 +02:00
return - 1 ;
}
}
2005-02-26 19:34:14 +01:00
2005-01-27 16:55:40 +01:00
2007-05-16 14:03:31 +02:00
/**
2019-02-25 20:35:59 +01:00
* Return array of groups objects for a particular user
2011-08-24 00:25:37 +02:00
*
2019-02-25 20:35:59 +01:00
* @ param int $userid User id to search
2017-09-15 23:21:42 +02:00
* @ param boolean $load_members Load all members of the group
2019-02-25 20:35:59 +01:00
* @ return array Array of groups objects
2009-05-04 20:01:47 +02:00
*/
2019-02-25 20:35:59 +01:00
public function listGroupsForUser ( $userid , $load_members = true )
2008-08-28 20:02:57 +02:00
{
2011-08-21 02:20:43 +02:00
global $conf , $user ;
2011-07-04 13:41:02 +02:00
2020-04-10 10:59:32 +02:00
$ret = array ();
2009-05-04 20:01:47 +02:00
2011-06-07 17:45:01 +02:00
$sql = " SELECT g.rowid, ug.entity as usergroup_entity " ;
2022-01-27 10:00:26 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " usergroup as g, " ;
$sql .= " " . $this -> db -> prefix () . " usergroup_user as ug " ;
2020-04-10 10:59:32 +02:00
$sql .= " WHERE ug.fk_usergroup = g.rowid " ;
2021-06-09 15:36:47 +02:00
$sql .= " AND ug.fk_user = " . (( int ) $userid );
2021-02-26 13:18:40 +01:00
if ( ! empty ( $conf -> multicompany -> enabled ) && $conf -> entity == 1 && $user -> admin && ! $user -> entity ) {
2020-04-10 10:59:32 +02:00
$sql .= " AND g.entity IS NOT NULL " ;
2020-05-21 15:05:19 +02:00
} else {
2020-04-10 10:59:32 +02:00
$sql .= " AND g.entity IN (0, " . $conf -> entity . " ) " ;
2011-08-20 00:15:22 +02:00
}
2020-04-10 10:59:32 +02:00
$sql .= " ORDER BY g.nom " ;
2009-05-04 20:01:47 +02:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::listGroupsForUser " , LOG_DEBUG );
2009-05-04 20:01:47 +02:00
$result = $this -> db -> query ( $sql );
2021-02-26 13:18:40 +01:00
if ( $result ) {
while ( $obj = $this -> db -> fetch_object ( $result )) {
if ( ! array_key_exists ( $obj -> rowid , $ret )) {
2020-04-10 10:59:32 +02:00
$newgroup = new UserGroup ( $this -> db );
2017-09-15 12:58:13 +02:00
$newgroup -> fetch ( $obj -> rowid , '' , $load_members );
2020-04-10 10:59:32 +02:00
$ret [ $obj -> rowid ] = $newgroup ;
2012-07-07 15:11:58 +02:00
}
2020-04-10 10:59:32 +02:00
$ret [ $obj -> rowid ] -> usergroup_entity [] = $obj -> usergroup_entity ;
2009-05-04 20:01:47 +02:00
}
2011-07-04 13:41:02 +02:00
2009-05-04 20:01:47 +02:00
$this -> db -> free ( $result );
2011-07-04 13:41:02 +02:00
2011-06-07 17:45:01 +02:00
return $ret ;
2020-05-21 15:05:19 +02:00
} else {
2020-04-10 10:59:32 +02:00
$this -> error = $this -> db -> lasterror ();
2008-08-28 20:02:57 +02:00
return - 1 ;
2009-05-04 20:01:47 +02:00
}
2008-08-28 20:02:57 +02:00
}
2009-05-04 20:01:47 +02:00
2010-01-16 20:56:05 +01:00
/**
2014-09-05 13:48:55 +02:00
* Return array of User objects for group this -> id ( or all if this -> id not defined )
2011-08-24 00:25:37 +02:00
*
2021-08-23 19:33:24 +02:00
* @ param string $excludefilter Filter to exclude . Do not use here a string coming from user input .
2014-03-12 12:57:26 +01:00
* @ param int $mode 0 = Return array of user instance , 1 = Return array of users id only
2015-01-17 15:11:12 +01:00
* @ return mixed Array of users or - 1 on error
2010-01-16 20:56:05 +01:00
*/
2019-02-25 20:35:59 +01:00
public function listUsersForGroup ( $excludefilter = '' , $mode = 0 )
2010-01-16 20:56:05 +01:00
{
2011-08-21 02:20:43 +02:00
global $conf , $user ;
2011-07-04 13:41:02 +02:00
2020-04-10 10:59:32 +02:00
$ret = array ();
2010-01-16 20:56:05 +01:00
2013-04-14 01:04:11 +02:00
$sql = " SELECT u.rowid " ;
2021-02-26 13:18:40 +01:00
if ( ! empty ( $this -> id )) {
$sql .= " , ug.entity as usergroup_entity " ;
}
2022-01-27 10:00:26 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " user as u " ;
2021-02-26 13:18:40 +01:00
if ( ! empty ( $this -> id )) {
2022-01-27 10:00:26 +01:00
$sql .= " , " . $this -> db -> prefix () . " usergroup_user as ug " ;
2021-02-26 13:18:40 +01:00
}
2020-04-10 10:59:32 +02:00
$sql .= " WHERE 1 = 1 " ;
2021-02-26 13:18:40 +01:00
if ( ! empty ( $this -> id )) {
$sql .= " AND ug.fk_user = u.rowid " ;
}
if ( ! empty ( $this -> id )) {
2021-08-23 19:33:24 +02:00
$sql .= " AND ug.fk_usergroup = " . (( int ) $this -> id );
2021-02-26 13:18:40 +01:00
}
if ( ! empty ( $conf -> multicompany -> enabled ) && $conf -> entity == 1 && $user -> admin && ! $user -> entity ) {
2020-04-10 10:59:32 +02:00
$sql .= " AND u.entity IS NOT NULL " ;
2020-05-21 15:05:19 +02:00
} else {
2020-04-10 10:59:32 +02:00
$sql .= " AND u.entity IN (0, " . $conf -> entity . " ) " ;
2011-08-20 00:15:22 +02:00
}
2021-02-26 13:18:40 +01:00
if ( ! empty ( $excludefilter )) {
$sql .= ' AND (' . $excludefilter . ')' ;
}
2012-07-07 15:11:58 +02:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::listUsersForGroup " , LOG_DEBUG );
2013-04-14 01:04:11 +02:00
$resql = $this -> db -> query ( $sql );
2021-02-26 13:18:40 +01:00
if ( $resql ) {
while ( $obj = $this -> db -> fetch_object ( $resql )) {
if ( ! array_key_exists ( $obj -> rowid , $ret )) {
if ( $mode != 1 ) {
2020-04-10 10:59:32 +02:00
$newuser = new User ( $this -> db );
2014-03-12 12:57:26 +01:00
$newuser -> fetch ( $obj -> rowid );
2020-04-10 10:59:32 +02:00
$ret [ $obj -> rowid ] = $newuser ;
2021-02-26 13:18:40 +01:00
} else {
$ret [ $obj -> rowid ] = $obj -> rowid ;
}
2012-07-07 15:11:58 +02:00
}
2021-02-26 13:18:40 +01:00
if ( $mode != 1 && ! empty ( $obj -> usergroup_entity )) {
2020-04-10 10:59:32 +02:00
$ret [ $obj -> rowid ] -> usergroup_entity [] = $obj -> usergroup_entity ;
2013-04-26 19:13:39 +02:00
}
2010-01-16 20:56:05 +01:00
}
2011-07-04 13:41:02 +02:00
2013-04-14 01:04:11 +02:00
$this -> db -> free ( $resql );
2011-07-04 13:41:02 +02:00
2011-06-07 17:45:01 +02:00
return $ret ;
2020-05-21 15:05:19 +02:00
} else {
2020-04-10 10:59:32 +02:00
$this -> error = $this -> db -> lasterror ();
2010-01-16 20:56:05 +01:00
return - 1 ;
}
}
2009-05-04 20:01:47 +02:00
/**
2017-02-28 11:48:46 +01:00
* Add a permission to a group
2011-09-04 20:41:19 +02:00
*
2017-06-06 07:57:03 +02:00
* @ param int $rid id du droit a ajouter
* @ param string $allmodule Ajouter tous les droits du module allmodule
* @ param string $allperms Ajouter tous les droits du module allmodule , perms allperms
* @ param int $entity Entity to use
* @ return int > 0 if OK , < 0 if KO
2009-05-04 20:01:47 +02:00
*/
2019-02-25 20:35:59 +01:00
public function addrights ( $rid , $allmodule = '' , $allperms = '' , $entity = 0 )
2005-02-26 19:34:14 +01:00
{
2017-02-28 11:48:46 +01:00
global $conf , $user , $langs ;
2009-05-04 20:01:47 +02:00
2020-04-10 10:59:32 +02:00
$entity = ( ! empty ( $entity ) ? $entity : $conf -> entity );
2017-06-06 07:57:03 +02:00
dol_syslog ( get_class ( $this ) . " ::addrights $rid , $allmodule , $allperms , $entity " );
2020-04-10 10:59:32 +02:00
$error = 0 ;
$whereforadd = '' ;
2009-05-04 20:01:47 +02:00
$this -> db -> begin ();
2021-02-26 13:18:40 +01:00
if ( ! empty ( $rid )) {
2020-11-07 15:57:38 +01:00
$module = $perms = $subperms = '' ;
2009-06-06 16:59:55 +02:00
// Si on a demande ajout d'un droit en particulier, on recupere
// les caracteristiques (module, perms et subperms) de ce droit.
2009-05-04 20:01:47 +02:00
$sql = " SELECT module, perms, subperms " ;
2022-01-27 10:00:26 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " rights_def " ;
2020-11-07 15:28:10 +01:00
$sql .= " WHERE id = " . (( int ) $rid );
$sql .= " AND entity = " . (( int ) $entity );
2009-05-04 20:01:47 +02:00
2020-04-10 10:59:32 +02:00
$result = $this -> db -> query ( $sql );
2009-05-04 20:01:47 +02:00
if ( $result ) {
$obj = $this -> db -> fetch_object ( $result );
2020-11-07 15:28:10 +01:00
if ( $obj ) {
$module = $obj -> module ;
$perms = $obj -> perms ;
$subperms = $obj -> subperms ;
}
2020-05-21 15:05:19 +02:00
} else {
2017-02-28 11:48:46 +01:00
$error ++ ;
2009-05-04 20:01:47 +02:00
dol_print_error ( $this -> db );
}
2009-06-06 16:59:55 +02:00
// Where pour la liste des droits a ajouter
2020-11-07 15:28:10 +01:00
$whereforadd = " id= " . (( int ) $rid );
2020-11-07 15:57:38 +01:00
// Find also rights that are herited to add them too
2021-02-26 13:18:40 +01:00
if ( $subperms ) {
$whereforadd .= " OR (module=' " . $this -> db -> escape ( $module ) . " ' AND perms=' " . $this -> db -> escape ( $perms ) . " ' AND (subperms='lire' OR subperms='read')) " ;
} elseif ( $perms ) {
$whereforadd .= " OR (module=' " . $this -> db -> escape ( $module ) . " ' AND (perms='lire' OR perms='read') AND subperms IS NULL) " ;
}
2020-05-21 15:05:19 +02:00
} else {
2009-06-06 16:59:55 +02:00
// Where pour la liste des droits a ajouter
2021-02-26 13:18:40 +01:00
if ( ! empty ( $allmodule )) {
if ( $allmodule == 'allmodules' ) {
2020-04-10 10:59:32 +02:00
$whereforadd = 'allmodules' ;
2020-05-21 15:05:19 +02:00
} else {
2020-04-10 10:59:32 +02:00
$whereforadd = " module=' " . $this -> db -> escape ( $allmodule ) . " ' " ;
2021-02-26 13:18:40 +01:00
if ( ! empty ( $allperms )) {
$whereforadd .= " AND perms=' " . $this -> db -> escape ( $allperms ) . " ' " ;
}
2018-07-03 21:46:20 +02:00
}
}
2009-05-04 20:01:47 +02:00
}
2020-11-07 15:28:10 +01:00
// Add permission of the list $whereforadd
2021-02-26 13:18:40 +01:00
if ( ! empty ( $whereforadd )) {
2009-05-04 20:01:47 +02:00
//print "$module-$perms-$subperms";
$sql = " SELECT id " ;
2022-01-27 10:00:26 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " rights_def " ;
2021-06-09 15:36:47 +02:00
$sql .= " WHERE entity = " . (( int ) $entity );
2020-04-10 10:59:32 +02:00
if ( ! empty ( $whereforadd ) && $whereforadd != 'allmodules' ) {
$sql .= " AND " . $whereforadd ;
2018-07-03 21:46:20 +02:00
}
2009-05-04 20:01:47 +02:00
2020-04-10 10:59:32 +02:00
$result = $this -> db -> query ( $sql );
2021-02-26 13:18:40 +01:00
if ( $result ) {
2009-05-04 20:01:47 +02:00
$num = $this -> db -> num_rows ( $result );
$i = 0 ;
2021-02-26 13:18:40 +01:00
while ( $i < $num ) {
2009-05-04 20:01:47 +02:00
$obj = $this -> db -> fetch_object ( $result );
$nid = $obj -> id ;
2022-01-27 10:00:26 +01:00
$sql = " DELETE FROM " . $this -> db -> prefix () . " usergroup_rights WHERE fk_usergroup = " . (( int ) $this -> id ) . " AND fk_id= " . (( int ) $nid ) . " AND entity = " . (( int ) $entity );
2021-02-26 13:18:40 +01:00
if ( ! $this -> db -> query ( $sql )) {
$error ++ ;
}
2022-01-27 10:00:26 +01:00
$sql = " INSERT INTO " . $this -> db -> prefix () . " usergroup_rights (entity, fk_usergroup, fk_id) VALUES ( " . (( int ) $entity ) . " , " . (( int ) $this -> id ) . " , " . (( int ) $nid ) . " ) " ;
2021-02-26 13:18:40 +01:00
if ( ! $this -> db -> query ( $sql )) {
$error ++ ;
}
2009-05-04 20:01:47 +02:00
$i ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2017-02-28 11:48:46 +01:00
$error ++ ;
2009-05-04 20:01:47 +02:00
dol_print_error ( $this -> db );
}
2017-05-24 11:27:27 +02:00
2021-02-26 13:18:40 +01:00
if ( ! $error ) {
2017-12-08 12:38:22 +01:00
$langs -> load ( " other " );
2020-04-10 10:59:32 +02:00
$this -> context = array ( 'audit' => $langs -> trans ( " PermissionsAdd " ) . ( $rid ? ' (id=' . $rid . ')' : '' ));
2017-05-24 11:27:27 +02:00
2020-10-31 14:32:18 +01:00
// Call trigger
$result = $this -> call_trigger ( 'USERGROUP_MODIFY' , $user );
2021-02-26 13:18:40 +01:00
if ( $result < 0 ) {
$error ++ ;
}
2020-10-31 14:32:18 +01:00
// End call triggers
2017-05-24 11:27:27 +02:00
}
2009-05-04 20:01:47 +02:00
}
2017-02-28 11:48:46 +01:00
if ( $error ) {
2009-05-04 20:01:47 +02:00
$this -> db -> rollback ();
2017-02-28 11:48:46 +01:00
return - $error ;
2020-05-21 15:05:19 +02:00
} else {
2009-05-04 20:01:47 +02:00
$this -> db -> commit ();
return 1 ;
}
}
/**
2017-02-28 11:48:46 +01:00
* Remove a permission from group
2011-09-04 20:41:19 +02:00
*
2017-06-06 07:57:03 +02:00
* @ param int $rid id du droit a retirer
* @ param string $allmodule Retirer tous les droits du module allmodule
* @ param string $allperms Retirer tous les droits du module allmodule , perms allperms
* @ param int $entity Entity to use
* @ return int > 0 if OK , < 0 if OK
2009-05-04 20:01:47 +02:00
*/
2019-02-25 20:35:59 +01:00
public function delrights ( $rid , $allmodule = '' , $allperms = '' , $entity = 0 )
2009-05-04 20:01:47 +02:00
{
2017-02-28 11:48:46 +01:00
global $conf , $user , $langs ;
2009-05-04 20:01:47 +02:00
2020-04-10 10:59:32 +02:00
$error = 0 ;
$wherefordel = '' ;
2009-05-04 20:01:47 +02:00
2020-04-10 10:59:32 +02:00
$entity = ( ! empty ( $entity ) ? $entity : $conf -> entity );
2017-06-06 07:57:03 +02:00
2009-05-04 20:01:47 +02:00
$this -> db -> begin ();
2021-02-26 13:18:40 +01:00
if ( ! empty ( $rid )) {
2020-11-07 19:39:51 +01:00
$module = $perms = $subperms = '' ;
2009-06-06 16:59:55 +02:00
// Si on a demande supression d'un droit en particulier, on recupere
// les caracteristiques module, perms et subperms de ce droit.
2009-05-04 20:01:47 +02:00
$sql = " SELECT module, perms, subperms " ;
2022-01-27 10:00:26 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " rights_def " ;
2021-06-09 15:36:47 +02:00
$sql .= " WHERE id = " . (( int ) $rid );
$sql .= " AND entity = " . (( int ) $entity );
2009-05-04 20:01:47 +02:00
2020-04-10 10:59:32 +02:00
$result = $this -> db -> query ( $sql );
2009-05-04 20:01:47 +02:00
if ( $result ) {
$obj = $this -> db -> fetch_object ( $result );
2020-11-07 19:25:04 +01:00
if ( $obj ) {
$module = $obj -> module ;
$perms = $obj -> perms ;
$subperms = $obj -> subperms ;
}
2020-05-21 15:05:19 +02:00
} else {
2017-02-28 11:48:46 +01:00
$error ++ ;
2009-05-04 20:01:47 +02:00
dol_print_error ( $this -> db );
}
2021-06-09 15:36:47 +02:00
// Where for the list of permissions to delete
$wherefordel = " id = " . (( int ) $rid );
2009-05-04 20:01:47 +02:00
// Suppression des droits induits
2021-02-26 13:18:40 +01:00
if ( $subperms == 'lire' || $subperms == 'read' ) {
$wherefordel .= " OR (module=' " . $this -> db -> escape ( $module ) . " ' AND perms=' " . $this -> db -> escape ( $perms ) . " ' AND subperms IS NOT NULL) " ;
}
if ( $perms == 'lire' || $perms == 'read' ) {
$wherefordel .= " OR (module=' " . $this -> db -> escape ( $module ) . " ') " ;
}
2009-05-04 20:01:47 +02:00
2009-06-06 16:59:55 +02:00
// Pour compatibilite, si lowid = 0, on est en mode suppression de tout
2009-12-21 01:32:17 +01:00
// TODO A virer quand sera gere par l'appelant
2014-06-11 17:51:50 +02:00
//if (substr($rid,-1,1) == 0) $wherefordel="module='$module'";
2019-02-25 20:35:59 +01:00
} else {
2020-11-07 19:25:04 +01:00
// Add permission of the list $wherefordel
2021-02-26 13:18:40 +01:00
if ( ! empty ( $allmodule )) {
if ( $allmodule == 'allmodules' ) {
2020-04-10 10:59:32 +02:00
$wherefordel = 'allmodules' ;
2020-05-21 15:05:19 +02:00
} else {
2020-04-10 10:59:32 +02:00
$wherefordel = " module=' " . $this -> db -> escape ( $allmodule ) . " ' " ;
2021-02-26 13:18:40 +01:00
if ( ! empty ( $allperms )) {
$wherefordel .= " AND perms=' " . $this -> db -> escape ( $allperms ) . " ' " ;
}
2018-07-03 21:46:20 +02:00
}
}
2009-05-04 20:01:47 +02:00
}
2005-02-26 19:34:14 +01:00
2009-05-04 20:01:47 +02:00
// Suppression des droits de la liste wherefordel
2021-02-26 13:18:40 +01:00
if ( ! empty ( $wherefordel )) {
2009-05-04 20:01:47 +02:00
//print "$module-$perms-$subperms";
$sql = " SELECT id " ;
2022-01-27 10:00:26 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " rights_def " ;
2021-08-23 19:33:24 +02:00
$sql .= " WHERE entity = " . (( int ) $entity );
2020-04-10 10:59:32 +02:00
if ( ! empty ( $wherefordel ) && $wherefordel != 'allmodules' ) {
$sql .= " AND " . $wherefordel ;
2018-07-03 21:46:20 +02:00
}
2009-05-04 20:01:47 +02:00
2020-04-10 10:59:32 +02:00
$result = $this -> db -> query ( $sql );
2021-02-26 13:18:40 +01:00
if ( $result ) {
2009-05-04 20:01:47 +02:00
$num = $this -> db -> num_rows ( $result );
$i = 0 ;
2021-02-26 13:18:40 +01:00
while ( $i < $num ) {
2020-11-07 19:39:51 +01:00
$nid = 0 ;
2009-05-04 20:01:47 +02:00
$obj = $this -> db -> fetch_object ( $result );
2020-11-07 19:39:51 +01:00
if ( $obj ) {
$nid = $obj -> id ;
}
2009-05-04 20:01:47 +02:00
2022-01-27 10:00:26 +01:00
$sql = " DELETE FROM " . $this -> db -> prefix () . " usergroup_rights " ;
2021-04-24 20:18:11 +02:00
$sql .= " WHERE fk_usergroup = $this->id AND fk_id= " . (( int ) $nid );
2021-08-23 19:33:24 +02:00
$sql .= " AND entity = " . (( int ) $entity );
2021-02-26 13:18:40 +01:00
if ( ! $this -> db -> query ( $sql )) {
$error ++ ;
}
2005-02-26 19:34:14 +01:00
2009-05-04 20:01:47 +02:00
$i ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2017-02-28 11:48:46 +01:00
$error ++ ;
2009-05-04 20:01:47 +02:00
dol_print_error ( $this -> db );
}
2017-05-24 11:27:27 +02:00
2021-02-26 13:18:40 +01:00
if ( ! $error ) {
2017-12-08 12:38:22 +01:00
$langs -> load ( " other " );
2020-04-10 10:59:32 +02:00
$this -> context = array ( 'audit' => $langs -> trans ( " PermissionsDelete " ) . ( $rid ? ' (id=' . $rid . ')' : '' ));
2017-05-24 11:27:27 +02:00
2020-10-31 14:32:18 +01:00
// Call trigger
$result = $this -> call_trigger ( 'USERGROUP_MODIFY' , $user );
2021-02-26 13:18:40 +01:00
if ( $result < 0 ) {
$error ++ ;
}
2020-10-31 14:32:18 +01:00
// End call triggers
2017-02-28 11:48:46 +01:00
}
2009-05-04 20:01:47 +02:00
}
2005-02-26 19:34:14 +01:00
2017-02-28 11:48:46 +01:00
if ( $error ) {
2009-05-04 20:01:47 +02:00
$this -> db -> rollback ();
2017-02-28 11:48:46 +01:00
return - $error ;
2020-05-21 15:05:19 +02:00
} else {
2009-05-04 20:01:47 +02:00
$this -> db -> commit ();
return 1 ;
2005-02-26 19:34:14 +01:00
}
}
2006-11-19 17:41:17 +01:00
2009-05-04 20:01:47 +02:00
/**
2011-09-04 20:41:19 +02:00
* Charge dans l ' objet group , la liste des permissions auquels le groupe a droit
*
2012-03-09 09:38:31 +01:00
* @ param string $moduletag Name of module we want permissions ( '' means all )
2019-02-25 20:35:59 +01:00
* @ return int < 0 if KO , > 0 if OK
2009-05-04 20:01:47 +02:00
*/
2019-02-25 20:35:59 +01:00
public function getrights ( $moduletag = '' )
2009-05-04 20:01:47 +02:00
{
global $conf ;
2021-02-26 13:18:40 +01:00
if ( $moduletag && isset ( $this -> _tab_loaded [ $moduletag ]) && $this -> _tab_loaded [ $moduletag ]) {
2019-06-18 20:15:04 +02:00
// Rights for this module are already loaded, so we leave
2012-01-11 01:06:56 +01:00
return ;
}
2021-02-26 13:18:40 +01:00
if ( ! empty ( $this -> all_permissions_are_loaded )) {
2019-06-18 20:15:04 +02:00
// We already loaded all rights for this group, so we leave
2009-05-04 20:01:47 +02:00
return ;
}
/*
2009-06-06 16:59:55 +02:00
* Recuperation des droits
2009-05-04 20:01:47 +02:00
*/
$sql = " SELECT r.module, r.perms, r.subperms " ;
2022-01-27 10:00:26 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " usergroup_rights as u, " . $this -> db -> prefix () . " rights_def as r " ;
2020-04-10 10:59:32 +02:00
$sql .= " WHERE r.id = u.fk_id " ;
2021-08-23 19:33:24 +02:00
$sql .= " AND r.entity = " . (( int ) $conf -> entity );
$sql .= " AND u.entity = " . (( int ) $conf -> entity );
$sql .= " AND u.fk_usergroup = " . (( int ) $this -> id );
2020-04-10 10:59:32 +02:00
$sql .= " AND r.perms IS NOT NULL " ;
2021-02-26 13:18:40 +01:00
if ( $moduletag ) {
$sql .= " AND r.module = ' " . $this -> db -> escape ( $moduletag ) . " ' " ;
}
2012-01-11 01:06:56 +01:00
2014-06-13 01:34:39 +02:00
dol_syslog ( get_class ( $this ) . '::getrights' , LOG_DEBUG );
2020-04-10 10:59:32 +02:00
$resql = $this -> db -> query ( $sql );
2021-02-26 13:18:40 +01:00
if ( $resql ) {
2010-08-09 18:07:24 +02:00
$num = $this -> db -> num_rows ( $resql );
2009-12-21 01:32:17 +01:00
$i = 0 ;
2021-02-26 13:18:40 +01:00
while ( $i < $num ) {
2012-01-11 01:06:56 +01:00
$obj = $this -> db -> fetch_object ( $resql );
2009-12-21 01:32:17 +01:00
2020-11-07 19:39:51 +01:00
if ( $obj ) {
$module = $obj -> module ;
$perms = $obj -> perms ;
$subperms = $obj -> subperms ;
2009-12-21 01:32:17 +01:00
2021-02-26 13:18:40 +01:00
if ( $perms ) {
if ( ! isset ( $this -> rights )) {
$this -> rights = new stdClass (); // For avoid error
}
if ( ! isset ( $this -> rights -> $module ) || ! is_object ( $this -> rights -> $module )) {
$this -> rights -> $module = new stdClass ();
}
if ( $subperms ) {
if ( ! isset ( $this -> rights -> $module -> $perms ) || ! is_object ( $this -> rights -> $module -> $perms )) {
$this -> rights -> $module -> $perms = new stdClass ();
}
if ( empty ( $this -> rights -> $module -> $perms -> $subperms )) {
$this -> nb_rights ++ ;
}
2020-11-07 19:39:51 +01:00
$this -> rights -> $module -> $perms -> $subperms = 1 ;
} else {
2021-02-26 13:18:40 +01:00
if ( empty ( $this -> rights -> $module -> $perms )) {
$this -> nb_rights ++ ;
}
2020-11-07 19:39:51 +01:00
$this -> rights -> $module -> $perms = 1 ;
}
2009-12-21 01:32:17 +01:00
}
}
2011-08-24 00:25:37 +02:00
2009-12-21 01:32:17 +01:00
$i ++ ;
}
2012-01-11 01:06:56 +01:00
$this -> db -> free ( $resql );
2009-05-04 20:01:47 +02:00
}
2021-02-26 13:18:40 +01:00
if ( $moduletag == '' ) {
2009-06-06 16:59:55 +02:00
// Si module etait non defini, alors on a tout charge, on peut donc considerer
2012-01-11 01:06:56 +01:00
// que les droits sont en cache (car tous charges) pour cet instance de group
2020-04-10 10:59:32 +02:00
$this -> all_permissions_are_loaded = 1 ;
2020-05-21 15:05:19 +02:00
} else {
2019-06-18 20:15:04 +02:00
// If module defined, we flag it as loaded into cache
2020-10-31 14:32:18 +01:00
$this -> _tab_loaded [ $moduletag ] = 1 ;
2012-01-11 01:06:56 +01:00
}
2009-05-04 20:01:47 +02:00
2020-10-31 14:32:18 +01:00
return 1 ;
2009-05-04 20:01:47 +02:00
}
2005-01-27 16:55:40 +01:00
2006-11-20 03:10:47 +01:00
/**
2018-12-22 17:34:27 +01:00
* Delete a group
2011-09-04 20:41:19 +02:00
*
2018-12-22 17:34:27 +01:00
* @ param User $user User that delete
2020-05-27 23:33:23 +02:00
* @ return int < 0 if KO , > 0 if OK
2009-05-04 20:01:47 +02:00
*/
2019-02-25 20:35:59 +01:00
public function delete ( User $user )
2006-11-20 03:10:47 +01:00
{
2020-04-13 19:03:48 +02:00
return $this -> deleteCommon ( $user );
2006-11-20 03:10:47 +01:00
}
2005-01-27 16:55:40 +01:00
2006-11-20 02:44:27 +01:00
/**
2011-06-07 17:45:01 +02:00
* Create group into database
2011-09-04 20:41:19 +02:00
*
* @ param int $notrigger 0 = triggers enabled , 1 = triggers disabled
* @ return int < 0 if KO , >= 0 if OK
2009-05-04 20:01:47 +02:00
*/
2019-02-25 20:35:59 +01:00
public function create ( $notrigger = 0 )
2006-11-20 02:44:27 +01:00
{
2020-04-13 19:03:48 +02:00
global $user , $conf ;
2009-05-04 20:01:47 +02:00
2020-04-13 19:03:48 +02:00
$this -> datec = dol_now ();
2020-09-07 10:34:44 +02:00
if ( ! empty ( $this -> name )) {
$this -> nom = $this -> name ; // Field for 'name' is called 'nom' in database
2020-04-21 16:14:38 +02:00
}
2011-08-24 00:25:37 +02:00
2021-02-26 13:18:40 +01:00
if ( ! isset ( $this -> entity )) {
$this -> entity = $conf -> entity ; // If not defined, we use default value
}
2010-05-05 19:42:01 +02:00
2020-04-13 19:03:48 +02:00
return $this -> createCommon ( $user , $notrigger );
2006-11-20 02:44:27 +01:00
}
2005-01-27 16:55:40 +01:00
2006-11-20 02:44:27 +01:00
/**
2011-05-28 13:50:51 +02:00
* Update group into database
2011-09-04 20:41:19 +02:00
*
* @ param int $notrigger 0 = triggers enabled , 1 = triggers disabled
* @ return int < 0 if KO , >= 0 if OK
2009-05-04 20:01:47 +02:00
*/
2019-02-25 20:35:59 +01:00
public function update ( $notrigger = 0 )
2009-05-04 20:01:47 +02:00
{
2020-04-13 19:03:48 +02:00
global $user , $conf ;
2011-08-24 00:25:37 +02:00
2020-09-07 10:34:44 +02:00
if ( ! empty ( $this -> name )) {
$this -> nom = $this -> name ; // Field for 'name' is called 'nom' in database
2011-08-20 00:15:22 +02:00
}
2009-08-12 01:42:21 +02:00
2020-04-13 19:03:48 +02:00
return $this -> updateCommon ( $user , $notrigger );
2006-11-20 02:13:13 +01:00
}
2006-11-19 17:41:17 +01:00
2017-05-09 10:19:39 +02:00
/**
* Return label of status of user ( active , inactive )
*
* @ param int $mode 0 = libelle long , 1 = libelle court , 2 = Picto + Libelle court , 3 = Picto , 4 = Picto + Libelle long , 5 = Libelle court + Picto
* @ return string Label of status
*/
2019-02-25 20:35:59 +01:00
public function getLibStatut ( $mode = 0 )
2017-05-09 10:19:39 +02:00
{
2020-10-31 14:32:18 +01:00
return $this -> LibStatut ( 0 , $mode );
2017-05-09 10:19:39 +02:00
}
2017-06-06 07:57:03 +02:00
2020-10-31 14:32:18 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-05-09 10:19:39 +02:00
/**
* Renvoi le libelle d ' un statut donne
*
2019-11-01 23:58:14 +01:00
* @ param int $status Id status
2017-05-09 10:19:39 +02:00
* @ param int $mode 0 = libelle long , 1 = libelle court , 2 = Picto + Libelle court , 3 = Picto , 4 = Picto + Libelle long , 5 = Libelle court + Picto
* @ return string Label of status
*/
2019-11-01 23:58:14 +01:00
public function LibStatut ( $status , $mode = 0 )
2017-05-09 10:19:39 +02:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
global $langs ;
$langs -> load ( 'users' );
return '' ;
2017-05-09 10:19:39 +02:00
}
2017-06-06 07:57:03 +02:00
2018-02-06 19:16:15 +01:00
/**
* Return a link to the user card ( with optionaly the picto )
2019-02-25 20:35:59 +01:00
* Use this -> id , this -> lastname , this -> firstname
2018-02-06 19:16:15 +01:00
*
2019-02-25 20:35:59 +01:00
* @ param int $withpicto Include picto in link ( 0 = No picto , 1 = Include picto into link , 2 = Only picto , - 1 = Include photo into link , - 2 = Only picto photo , - 3 = Only photo very small )
2021-07-03 18:09:48 +02:00
* @ param string $option On what the link point to ( 'nolink' , 'permissions' )
2018-02-06 19:16:15 +01:00
* @ param integer $notooltip 1 = Disable tooltip on picto and name
* @ param string $morecss Add more css on link
* @ param int $save_lastsearch_value - 1 = Auto , 0 = No save of lastsearch_values when clicking , 1 = Save lastsearch_values whenclicking
* @ return string String with URL
*/
2019-02-25 20:35:59 +01:00
public function getNomUrl ( $withpicto = 0 , $option = '' , $notooltip = 0 , $morecss = '' , $save_lastsearch_value = - 1 )
2018-02-06 19:16:15 +01:00
{
global $langs , $conf , $db , $hookmanager ;
global $dolibarr_main_authentication , $dolibarr_main_demo ;
global $menumanager ;
2021-02-26 13:18:40 +01:00
if ( ! empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER ) && $withpicto ) {
$withpicto = 0 ;
}
2018-02-06 19:16:15 +01:00
2020-04-10 10:59:32 +02:00
$result = '' ; $label = '' ;
2018-02-06 19:16:15 +01:00
2020-04-10 10:59:32 +02:00
$label .= '<div class="centpercent">' ;
2021-07-03 18:09:48 +02:00
$label .= img_picto ( '' , 'group' ) . ' <u>' . $langs -> trans ( " Group " ) . '</u><br>' ;
2020-04-10 10:59:32 +02:00
$label .= '<b>' . $langs -> trans ( 'Name' ) . ':</b> ' . $this -> name ;
$label .= '<br><b>' . $langs -> trans ( " Description " ) . ':</b> ' . $this -> note ;
$label .= '</div>' ;
2018-02-06 19:16:15 +01:00
2021-07-03 18:09:48 +02:00
if ( $option == 'permissions' ) {
$url = DOL_URL_ROOT . '/user/group/perms.php?id=' . $this -> id ;
} else {
$url = DOL_URL_ROOT . '/user/group/card.php?id=' . $this -> id ;
}
2018-02-06 19:16:15 +01:00
2021-02-26 13:18:40 +01:00
if ( $option != 'nolink' ) {
2018-02-06 19:16:15 +01:00
// Add param to save lastsearch_values or not
2020-04-10 10:59:32 +02:00
$add_save_lastsearch_values = ( $save_lastsearch_value == 1 ? 1 : 0 );
2021-02-26 13:18:40 +01:00
if ( $save_lastsearch_value == - 1 && preg_match ( '/list\.php/' , $_SERVER [ " PHP_SELF " ])) {
$add_save_lastsearch_values = 1 ;
}
if ( $add_save_lastsearch_values ) {
$url .= '&save_lastsearch_values=1' ;
}
2018-02-06 19:16:15 +01:00
}
2020-04-10 10:59:32 +02:00
$linkclose = " " ;
2021-02-26 13:18:40 +01:00
if ( empty ( $notooltip )) {
if ( ! empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER )) {
2018-02-06 19:16:15 +01:00
$langs -> load ( " users " );
2020-04-10 10:59:32 +02:00
$label = $langs -> trans ( " ShowGroup " );
$linkclose .= ' alt="' . dol_escape_htmltag ( $label , 1 , 1 ) . '"' ;
2018-02-06 19:16:15 +01:00
}
2020-04-10 10:59:32 +02:00
$linkclose .= ' title="' . dol_escape_htmltag ( $label , 1 , 1 ) . '"' ;
$linkclose .= ' class="classfortooltip' . ( $morecss ? ' ' . $morecss : '' ) . '"' ;
2018-02-06 19:16:15 +01:00
}
$linkstart = '<a href="' . $url . '"' ;
2020-04-10 10:59:32 +02:00
$linkstart .= $linkclose . '>' ;
$linkend = '</a>' ;
2018-02-06 19:16:15 +01:00
$result = $linkstart ;
2021-02-26 13:18:40 +01:00
if ( $withpicto ) {
$result .= img_object (( $notooltip ? '' : $label ), ( $this -> picto ? $this -> picto : 'generic' ), ( $notooltip ? (( $withpicto != 2 ) ? 'class="paddingright"' : '' ) : 'class="' . (( $withpicto != 2 ) ? 'paddingright ' : '' ) . 'classfortooltip"' ), 0 , 0 , $notooltip ? 0 : 1 );
}
if ( $withpicto != 2 ) {
$result .= $this -> name ;
}
2018-02-06 19:16:15 +01:00
$result .= $linkend ;
2018-03-15 20:46:55 +01:00
global $action ;
$hookmanager -> initHooks ( array ( 'groupdao' ));
2021-11-22 19:57:26 +01:00
$parameters = array ( 'id' => $this -> id , 'getnomurl' => & $result );
2020-04-10 10:59:32 +02:00
$reshook = $hookmanager -> executeHooks ( 'getNomUrl' , $parameters , $this , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-26 13:18:40 +01:00
if ( $reshook > 0 ) {
$result = $hookmanager -> resPrint ;
} else {
$result .= $hookmanager -> resPrint ;
}
2018-03-15 20:46:55 +01:00
2018-02-06 19:16:15 +01:00
return $result ;
}
2019-05-10 16:12:16 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2019-05-10 16:37:03 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2009-08-11 14:51:33 +02:00
/**
2011-09-04 20:41:19 +02:00
* Retourne chaine DN complete dans l 'annuaire LDAP pour l' objet
*
2014-06-20 13:07:15 +02:00
* @ param array $info Info array loaded by _load_ldap_info
2011-09-04 20:41:19 +02:00
* @ param int $mode 0 = Return full DN ( uid = qqq , ou = xxx , dc = aaa , dc = bbb )
* 1 = Return DN without key inside ( ou = xxx , dc = aaa , dc = bbb )
* 2 = Return key only ( uid = qqq )
* @ return string DN
2009-05-04 20:01:47 +02:00
*/
2020-10-31 14:32:18 +01:00
public function _load_ldap_dn ( $info , $mode = 0 )
2006-11-19 17:41:17 +01:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2006-11-21 23:51:05 +01:00
global $conf ;
2020-04-10 10:59:32 +02:00
$dn = '' ;
2021-02-26 13:18:40 +01:00
if ( $mode == 0 ) {
$dn = $conf -> global -> LDAP_KEY_GROUPS . " = " . $info [ $conf -> global -> LDAP_KEY_GROUPS ] . " , " . $conf -> global -> LDAP_GROUP_DN ;
}
if ( $mode == 1 ) {
$dn = $conf -> global -> LDAP_GROUP_DN ;
}
if ( $mode == 2 ) {
$dn = $conf -> global -> LDAP_KEY_GROUPS . " = " . $info [ $conf -> global -> LDAP_KEY_GROUPS ];
}
2006-11-21 23:51:05 +01:00
return $dn ;
2006-11-19 17:41:17 +01:00
}
2006-11-20 02:13:13 +01:00
2019-05-10 16:12:16 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2019-05-10 16:37:03 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2009-08-11 14:51:33 +02:00
/**
2011-09-04 20:41:19 +02:00
* Initialize the info array ( array of LDAP values ) that will be used to call LDAP functions
*
* @ return array Tableau info des attributs
2009-05-04 20:01:47 +02:00
*/
2020-10-31 14:32:18 +01:00
public function _load_ldap_info ()
2006-11-20 02:13:13 +01:00
{
2020-10-31 14:32:18 +01:00
// phpcs:enable
2019-06-18 20:01:28 +02:00
global $conf ;
2017-07-13 23:52:02 +02:00
2020-04-10 10:59:32 +02:00
$info = array ();
2009-05-04 20:01:47 +02:00
2007-04-13 02:35:13 +02:00
// Object classes
2020-04-10 10:59:32 +02:00
$info [ " objectclass " ] = explode ( ',' , $conf -> global -> LDAP_GROUP_OBJECT_CLASS );
2009-05-04 20:01:47 +02:00
2006-11-20 03:10:47 +01:00
// Champs
2021-02-26 13:18:40 +01:00
if ( $this -> name && ! empty ( $conf -> global -> LDAP_GROUP_FIELD_FULLNAME )) {
$info [ $conf -> global -> LDAP_GROUP_FIELD_FULLNAME ] = $this -> name ;
}
2014-10-04 17:20:17 +02:00
//if ($this->name && ! empty($conf->global->LDAP_GROUP_FIELD_NAME)) $info[$conf->global->LDAP_GROUP_FIELD_NAME] = $this->name;
2021-02-26 13:18:40 +01:00
if ( $this -> note && ! empty ( $conf -> global -> LDAP_GROUP_FIELD_DESCRIPTION )) {
$info [ $conf -> global -> LDAP_GROUP_FIELD_DESCRIPTION ] = dol_string_nohtmltag ( $this -> note , 2 );
}
if ( ! empty ( $conf -> global -> LDAP_GROUP_FIELD_GROUPMEMBERS )) {
2020-04-10 10:59:32 +02:00
$valueofldapfield = array ();
2021-02-26 13:18:40 +01:00
foreach ( $this -> members as $key => $val ) { // This is array of users for group into dolibarr database.
2020-04-10 10:59:32 +02:00
$muser = new User ( $this -> db );
2012-05-11 12:10:47 +02:00
$muser -> fetch ( $val -> id );
2016-06-16 23:39:59 +02:00
$info2 = $muser -> _load_ldap_info ();
2017-05-24 11:27:27 +02:00
$valueofldapfield [] = $muser -> _load_ldap_dn ( $info2 );
2009-12-21 01:50:46 +01:00
}
2020-04-10 10:59:32 +02:00
$info [ $conf -> global -> LDAP_GROUP_FIELD_GROUPMEMBERS ] = ( ! empty ( $valueofldapfield ) ? $valueofldapfield : '' );
2021-05-17 11:29:51 +02:00
}
if ( ! empty ( $conf -> global -> LDAP_GROUP_FIELD_GROUPID )) {
$info [ $conf -> global -> LDAP_GROUP_FIELD_GROUPID ] = $this -> id ;
}
2006-11-20 02:13:13 +01:00
return $info ;
}
2006-11-19 17:41:17 +01:00
/**
2020-10-31 14:32:18 +01:00
* Initialise an instance with random values .
* Used to build previews or test instances .
* id must be 0 if object instance is a specimen .
*
* @ return void
*/
public function initAsSpecimen ()
2006-11-19 17:41:17 +01:00
{
2009-12-19 15:12:55 +01:00
global $conf , $user , $langs ;
2006-11-19 17:41:17 +01:00
2009-06-06 16:59:55 +02:00
// Initialise parametres
2020-04-10 10:59:32 +02:00
$this -> id = 0 ;
2006-11-19 17:41:17 +01:00
$this -> ref = 'SPECIMEN' ;
2020-04-10 10:59:32 +02:00
$this -> specimen = 1 ;
2006-11-19 17:41:17 +01:00
2020-04-10 10:59:32 +02:00
$this -> name = 'DOLIBARR GROUP SPECIMEN' ;
$this -> note = 'This is a note' ;
$this -> datec = time ();
$this -> datem = time ();
2017-05-24 11:27:27 +02:00
2020-10-31 14:32:18 +01:00
// Members of this group is just me
$this -> members = array (
$user -> id => $user
);
}
2017-06-06 07:57:03 +02:00
2017-03-08 11:34:21 +01:00
/**
* Create a document onto disk according to template module .
*
* @ param string $modele Force model to use ( '' to not force )
* @ param Translate $outputlangs Object langs to use for output
* @ param int $hidedetails Hide details of lines
* @ param int $hidedesc Hide description
* @ param int $hideref Hide ref
2020-10-31 14:32:18 +01:00
* @ param null | array $moreparams Array to provide more information
2017-03-08 11:34:21 +01:00
* @ return int 0 if KO , 1 if OK
*/
2019-01-27 15:20:16 +01:00
public function generateDocument ( $modele , $outputlangs , $hidedetails = 0 , $hidedesc = 0 , $hideref = 0 , $moreparams = null )
2017-03-08 11:34:21 +01:00
{
2020-04-10 10:59:32 +02:00
global $conf , $user , $langs ;
2017-03-08 11:34:21 +01:00
$langs -> load ( " user " );
// Positionne le modele sur le nom du modele a utiliser
2021-02-26 13:18:40 +01:00
if ( ! dol_strlen ( $modele )) {
if ( ! empty ( $conf -> global -> USERGROUP_ADDON_PDF )) {
2017-03-08 11:34:21 +01:00
$modele = $conf -> global -> USERGROUP_ADDON_PDF ;
2020-05-21 15:05:19 +02:00
} else {
2017-03-08 11:34:21 +01:00
$modele = 'grass' ;
}
}
$modelpath = " core/modules/usergroup/doc/ " ;
2018-06-15 09:47:28 +02:00
return $this -> commonGenerateDocument ( $modelpath , $modele , $outputlangs , $hidedetails , $hidedesc , $hideref , $moreparams );
2017-03-08 11:34:21 +01:00
}
2005-01-27 16:55:40 +01:00
}