2005-01-27 16:55:40 +01:00
< ? php
2018-09-20 17:26:39 +02:00
/* Copyright ( c ) 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* 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 >
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
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
*/
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' ;
2018-07-26 11:57:25 +02: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
*/
2011-09-20 19:19:46 +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
*/
2011-09-20 19:19:46 +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
2017-05-09 10:19:39 +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
* @ see name
*/
2018-09-20 17:26:39 +02:00
public $nom ;
/**
* @ var string name
*/
public $name ; // Name of group
2016-12-23 16:40:13 +01:00
public $globalgroup ; // Global group
2018-09-20 17:26:39 +02:00
2016-12-23 16:40:13 +01:00
public $datec ; // Creation date of group
2018-09-20 17:26:39 +02:00
2016-12-23 16:40:13 +01:00
public $datem ; // Modification date of group
2018-09-20 17:26:39 +02:00
2018-02-06 19:16:15 +01:00
public $note ; // Description
2018-09-20 17:26:39 +02:00
2016-12-23 16:40:13 +01:00
public $members = array (); // Array of users
2009-05-04 20:01:47 +02:00
2017-12-15 22:14:28 +01:00
public $nb_rights ; // Number of rights granted to the user
2017-12-15 15:15:14 +01:00
2012-01-11 01:06:56 +01:00
private $_tab_loaded = array (); // Array of cache of already loaded permissions
2016-12-23 16:40:13 +01: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
2009-05-04 20:01:47 +02:00
/**
2011-07-08 20:49:16 +02:00
* Constructor de la classe
2011-09-04 20:41:19 +02:00
*
2012-05-11 12:47:15 +02:00
* @ param DoliDb $db Database handler
2009-05-04 20:01:47 +02:00
*/
2012-07-30 17:17:33 +02:00
function __construct ( $db )
2009-05-04 20:01:47 +02:00
{
2012-05-11 12:47:15 +02:00
$this -> db = $db ;
2017-12-15 15:15:14 +01:00
$this -> nb_rights = 0 ;
2009-05-04 20:01:47 +02:00
}
/**
2017-05-29 10:15:10 +02:00
* Charge un objet group avec toutes ces 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
*/
2017-09-15 12:58:13 +02:00
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
2012-01-30 10:22:50 +01:00
$sql = " SELECT g.rowid, g.entity, g.nom as name, g.note, g.datec, g.tms as datem " ;
2009-05-04 20:01:47 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " usergroup as g " ;
2013-02-25 16:46:31 +01:00
if ( $groupname )
{
$sql .= " WHERE g.nom = ' " . $this -> db -> escape ( $groupname ) . " ' " ;
}
else
{
$sql .= " WHERE g.rowid = " . $id ;
}
2006-11-19 17:41:17 +01:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::fetch " , LOG_DEBUG );
2009-05-04 20:01:47 +02:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
if ( $this -> db -> num_rows ( $result ))
{
$obj = $this -> db -> fetch_object ( $result );
$this -> id = $obj -> rowid ;
$this -> ref = $obj -> rowid ;
$this -> entity = $obj -> entity ;
2012-01-30 10:22:50 +01:00
$this -> name = $obj -> name ;
2014-10-04 17:20:17 +02:00
$this -> nom = $obj -> name ; // Deprecated
2009-05-04 20:01:47 +02:00
$this -> note = $obj -> note ;
$this -> datec = $obj -> datec ;
$this -> datem = $obj -> datem ;
2017-09-15 12:58:13 +02:00
if ( $load_members )
$this -> members = $this -> listUsersForGroup ();
2010-01-16 20:56:05 +01:00
2014-09-22 16:31:58 +02:00
2018-02-20 19:38:18 +01:00
// Retreive all extrafield
2014-09-22 16:31:58 +02:00
// fetch optionals attributes and labels
2018-02-20 19:38:18 +01:00
$this -> fetch_optionals ();
2014-10-04 17:20:17 +02:00
2009-08-12 01:42:21 +02:00
// Sav current LDAP Current DN
//$this->ldap_dn = $this->_load_ldap_dn($this->_load_ldap_info(),0);
2009-05-04 20:01:47 +02:00
}
$this -> db -> free ( $result );
return 1 ;
}
else
{
$this -> error = $this -> db -> lasterror ();
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
/**
2011-06-07 17:45:01 +02:00
* Return array of groups objects for a particular user
2011-08-24 00:25:37 +02:00
*
2017-09-15 23:21:42 +02:00
* @ param int $userid User id to search
* @ param boolean $load_members Load all members of the group
* @ return array Array of groups objects
2009-05-04 20:01:47 +02:00
*/
2017-09-15 12:58:13 +02:00
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
2009-05-04 20:01:47 +02:00
$ret = array ();
2011-06-07 17:45:01 +02:00
$sql = " SELECT g.rowid, ug.entity as usergroup_entity " ;
2009-05-04 20:01:47 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " usergroup as g, " ;
$sql .= " " . MAIN_DB_PREFIX . " usergroup_user as ug " ;
$sql .= " WHERE ug.fk_usergroup = g.rowid " ;
2011-06-07 17:45:01 +02:00
$sql .= " AND ug.fk_user = " . $userid ;
2011-08-21 12:01:36 +02:00
if ( ! empty ( $conf -> multicompany -> enabled ) && $conf -> entity == 1 && $user -> admin && ! $user -> entity )
2011-08-20 00:15:22 +02:00
{
$sql .= " AND g.entity IS NOT NULL " ;
}
else
{
$sql .= " AND g.entity IN (0, " . $conf -> entity . " ) " ;
}
2009-05-04 20:01:47 +02:00
$sql .= " ORDER BY g.nom " ;
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 );
if ( $result )
{
while ( $obj = $this -> db -> fetch_object ( $result ))
{
2012-07-07 15:11:58 +02:00
if ( ! array_key_exists ( $obj -> rowid , $ret ))
{
$newgroup = new UserGroup ( $this -> db );
2017-09-15 12:58:13 +02:00
$newgroup -> fetch ( $obj -> rowid , '' , $load_members );
2012-07-07 15:11:58 +02:00
$ret [ $obj -> rowid ] = $newgroup ;
}
$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 ;
2009-05-04 20:01:47 +02:00
}
else
{
$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
*
2013-04-14 01:04:11 +02:00
* @ param string $excludefilter Filter to exclude
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
*/
2014-03-12 12:57:26 +01:00
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
2010-01-16 20:56:05 +01:00
$ret = array ();
2013-04-14 01:04:11 +02:00
$sql = " SELECT u.rowid " ;
if ( ! empty ( $this -> id )) $sql .= " , ug.entity as usergroup_entity " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " user as u " ;
if ( ! empty ( $this -> id )) $sql .= " , " . MAIN_DB_PREFIX . " usergroup_user as ug " ;
$sql .= " WHERE 1 = 1 " ;
if ( ! empty ( $this -> id )) $sql .= " AND ug.fk_user = u.rowid " ;
if ( ! empty ( $this -> id )) $sql .= " AND ug.fk_usergroup = " . $this -> id ;
2012-07-07 15:11:58 +02:00
if ( ! empty ( $conf -> multicompany -> enabled ) && $conf -> entity == 1 && $user -> admin && ! $user -> entity )
2011-08-20 00:15:22 +02:00
{
$sql .= " AND u.entity IS NOT NULL " ;
}
else
{
$sql .= " AND u.entity IN (0, " . $conf -> entity . " ) " ;
}
2013-04-14 01:04:11 +02: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 );
if ( $resql )
2010-01-16 20:56:05 +01:00
{
2013-04-14 01:04:11 +02:00
while ( $obj = $this -> db -> fetch_object ( $resql ))
2010-01-16 20:56:05 +01:00
{
2012-07-07 15:11:58 +02:00
if ( ! array_key_exists ( $obj -> rowid , $ret ))
{
2014-03-12 12:57:26 +01:00
if ( $mode != 1 )
{
$newuser = new User ( $this -> db );
$newuser -> fetch ( $obj -> rowid );
$ret [ $obj -> rowid ] = $newuser ;
}
else $ret [ $obj -> rowid ] = $obj -> rowid ;
2012-07-07 15:11:58 +02:00
}
2014-03-12 12:57:26 +01:00
if ( $mode != 1 && ! empty ( $obj -> usergroup_entity ))
2013-04-26 19:13:39 +02:00
{
$ret [ $obj -> rowid ] -> usergroup_entity [] = $obj -> usergroup_entity ;
}
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 ;
2010-01-16 20:56:05 +01:00
}
else
{
$this -> error = $this -> db -> lasterror ();
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
*/
2017-06-06 07:57:03 +02:00
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
2017-06-06 07:57:03 +02:00
$entity = ( ! empty ( $entity ) ? $entity : $conf -> entity );
dol_syslog ( get_class ( $this ) . " ::addrights $rid , $allmodule , $allperms , $entity " );
2017-02-28 11:48:46 +01:00
$error = 0 ;
2009-05-04 20:01:47 +02:00
$whereforadd = '' ;
$this -> db -> begin ();
2012-10-20 09:40:50 +02:00
if ( ! empty ( $rid ))
2009-05-04 20:01:47 +02:00
{
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 " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " rights_def " ;
2012-10-20 11:10:36 +02:00
$sql .= " WHERE id = ' " . $this -> db -> escape ( $rid ) . " ' " ;
2017-06-06 07:57:03 +02:00
$sql .= " AND entity = " . $entity ;
2009-05-04 20:01:47 +02:00
$result = $this -> db -> query ( $sql );
if ( $result ) {
$obj = $this -> db -> fetch_object ( $result );
$module = $obj -> module ;
$perms = $obj -> perms ;
$subperms = $obj -> subperms ;
}
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
2012-10-20 11:10:36 +02:00
$whereforadd = " id= " . $this -> db -> escape ( $rid );
2009-05-04 20:01:47 +02:00
// Ajout des droits induits
2012-01-11 01:06:56 +01:00
if ( $subperms ) $whereforadd .= " OR (module=' $module ' AND perms=' $perms ' AND (subperms='lire' OR subperms='read')) " ;
else if ( $perms ) $whereforadd .= " OR (module=' $module ' AND (perms='lire' OR perms='read') AND subperms IS NULL) " ;
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 ajout de tout
// TODO A virer quand sera gere par l'appelant
2014-06-17 10:15:53 +02:00
//if (substr($rid,-1,1) == 0) $whereforadd="module='$module'";
2009-05-04 20:01:47 +02:00
}
else {
2009-06-06 16:59:55 +02:00
// Where pour la liste des droits a ajouter
2018-07-03 21:46:20 +02:00
if ( ! empty ( $allmodule ))
{
if ( $allmodule == 'allmodules' )
{
$whereforadd = 'allmodules' ;
}
else
{
$whereforadd = " module=' " . $this -> db -> escape ( $allmodule ) . " ' " ;
if ( ! empty ( $allperms )) $whereforadd .= " AND perms=' " . $this -> db -> escape ( $allperms ) . " ' " ;
}
}
2009-05-04 20:01:47 +02:00
}
// Ajout des droits de la liste whereforadd
2012-10-20 09:40:50 +02:00
if ( ! empty ( $whereforadd ))
2009-05-04 20:01:47 +02:00
{
//print "$module-$perms-$subperms";
$sql = " SELECT id " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " rights_def " ;
2018-07-03 21:46:20 +02:00
$sql .= " WHERE entity = " . $entity ;
if ( ! empty ( $whereforadd ) && $whereforadd != 'allmodules' ) {
$sql .= " AND " . $whereforadd ;
}
2009-05-04 20:01:47 +02:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
$num = $this -> db -> num_rows ( $result );
$i = 0 ;
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $result );
$nid = $obj -> id ;
2017-06-06 07:57:03 +02:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " usergroup_rights WHERE fk_usergroup = $this->id AND fk_id= " . $nid . " AND entity = " . $entity ;
2017-02-28 11:48:46 +01:00
if ( ! $this -> db -> query ( $sql )) $error ++ ;
2017-06-06 07:57:03 +02:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " usergroup_rights (entity, fk_usergroup, fk_id) VALUES ( " . $entity . " , " . $this -> id . " , " . $nid . " ) " ;
2017-02-28 11:48:46 +01:00
if ( ! $this -> db -> query ( $sql )) $error ++ ;
2009-05-04 20:01:47 +02:00
$i ++ ;
}
}
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
2017-02-28 11:48:46 +01:00
if ( ! $error )
{
2017-12-08 12:38:22 +01:00
$langs -> load ( " other " );
$this -> context = array ( 'audit' => $langs -> trans ( " PermissionsAdd " ) . ( $rid ? ' (id=' . $rid . ')' : '' ));
2017-05-24 11:27:27 +02:00
2017-02-28 11:48:46 +01:00
// Call trigger
$result = $this -> call_trigger ( 'GROUP_MODIFY' , $user );
if ( $result < 0 ) { $error ++ ; }
// 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 ;
2009-05-04 20:01:47 +02:00
}
else {
$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
*/
2017-06-06 07:57:03 +02:00
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
2017-02-28 11:48:46 +01:00
$error = 0 ;
2009-05-04 20:01:47 +02:00
$wherefordel = '' ;
2017-06-06 07:57:03 +02:00
$entity = ( ! empty ( $entity ) ? $entity : $conf -> entity );
2009-05-04 20:01:47 +02:00
$this -> db -> begin ();
2012-10-20 09:40:50 +02:00
if ( ! empty ( $rid ))
2009-05-04 20:01:47 +02:00
{
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 " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " rights_def " ;
2012-10-20 11:10:36 +02:00
$sql .= " WHERE id = ' " . $this -> db -> escape ( $rid ) . " ' " ;
2017-06-06 07:57:03 +02:00
$sql .= " AND entity = " . $entity ;
2009-05-04 20:01:47 +02:00
$result = $this -> db -> query ( $sql );
if ( $result ) {
$obj = $this -> db -> fetch_object ( $result );
$module = $obj -> module ;
$perms = $obj -> perms ;
$subperms = $obj -> subperms ;
}
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 supprimer
2012-10-20 11:10:36 +02:00
$wherefordel = " id= " . $this -> db -> escape ( $rid );
2009-05-04 20:01:47 +02:00
// Suppression des droits induits
2010-10-28 21:31:11 +02:00
if ( $subperms == 'lire' || $subperms == 'read' ) $wherefordel .= " OR (module=' $module ' AND perms=' $perms ' AND subperms IS NOT NULL) " ;
if ( $perms == 'lire' || $perms == 'read' ) $wherefordel .= " OR (module=' $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'";
2009-05-04 20:01:47 +02:00
}
else {
2009-06-06 16:59:55 +02:00
// Where pour la liste des droits a supprimer
2018-07-03 21:46:20 +02:00
if ( ! empty ( $allmodule ))
{
if ( $allmodule == 'allmodules' )
{
$wherefordel = 'allmodules' ;
}
else
{
$wherefordel = " module=' " . $this -> db -> escape ( $allmodule ) . " ' " ;
if ( ! empty ( $allperms )) $whereforadd .= " AND perms=' " . $this -> db -> escape ( $allperms ) . " ' " ;
}
}
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
2012-10-20 09:40:50 +02:00
if ( ! empty ( $wherefordel ))
2005-02-26 19:34:14 +01:00
{
2009-05-04 20:01:47 +02:00
//print "$module-$perms-$subperms";
$sql = " SELECT id " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " rights_def " ;
2018-07-03 21:46:20 +02:00
$sql .= " WHERE entity = " . $entity ;
if ( ! empty ( $wherefordel ) && $wherefordel != 'allmodules' ) {
$sql .= " AND " . $wherefordel ;
}
2009-05-04 20:01:47 +02:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
$num = $this -> db -> num_rows ( $result );
$i = 0 ;
while ( $i < $num )
{
$obj = $this -> db -> fetch_object ( $result );
$nid = $obj -> id ;
2012-01-11 01:06:56 +01:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " usergroup_rights " ;
$sql .= " WHERE fk_usergroup = $this->id AND fk_id= " . $nid ;
2017-06-06 07:57:03 +02:00
$sql .= " AND entity = " . $entity ;
2017-02-28 11:48:46 +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 ++ ;
}
}
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
2017-02-28 11:48:46 +01:00
if ( ! $error )
{
2017-12-08 12:38:22 +01:00
$langs -> load ( " other " );
$this -> context = array ( 'audit' => $langs -> trans ( " PermissionsDelete " ) . ( $rid ? ' (id=' . $rid . ')' : '' ));
2017-05-24 11:27:27 +02:00
2017-02-28 11:48:46 +01:00
// Call trigger
$result = $this -> call_trigger ( 'GROUP_MODIFY' , $user );
if ( $result < 0 ) { $error ++ ; }
// End call triggers
}
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 ;
2009-05-04 20:01:47 +02:00
}
else {
$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 )
* @ return int < 0 if KO , > 0 if OK
2009-05-04 20:01:47 +02:00
*/
2012-01-11 01:06:56 +01:00
function getrights ( $moduletag = '' )
2009-05-04 20:01:47 +02:00
{
global $conf ;
2012-01-11 01:06:56 +01:00
if ( $moduletag && isset ( $this -> _tab_loaded [ $moduletag ]) && $this -> _tab_loaded [ $moduletag ])
{
// Le fichier de ce module est deja charge
return ;
}
2012-07-10 13:20:53 +02:00
if ( ! empty ( $this -> all_permissions_are_loaded ))
2009-05-04 20:01:47 +02:00
{
2009-06-06 16:59:55 +02:00
// Si les permissions ont deja ete chargees, on quitte
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 " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " usergroup_rights as u, " . MAIN_DB_PREFIX . " rights_def as r " ;
$sql .= " WHERE r.id = u.fk_id " ;
$sql .= " AND r.entity = " . $conf -> entity ;
2017-06-06 07:57:03 +02:00
$sql .= " AND u.entity = " . $conf -> entity ;
2009-05-04 20:01:47 +02:00
$sql .= " AND u.fk_usergroup = " . $this -> id ;
$sql .= " AND r.perms IS NOT NULL " ;
2012-01-11 01:06:56 +01:00
if ( $moduletag ) $sql .= " AND r.module = ' " . $this -> db -> escape ( $moduletag ) . " ' " ;
2014-06-13 01:34:39 +02:00
dol_syslog ( get_class ( $this ) . '::getrights' , LOG_DEBUG );
2010-08-09 18:07:24 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
2009-05-04 20:01:47 +02:00
{
2010-08-09 18:07:24 +02:00
$num = $this -> db -> num_rows ( $resql );
2009-12-21 01:32:17 +01:00
$i = 0 ;
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
2012-01-11 01:06:56 +01:00
$module = $obj -> module ;
$perms = $obj -> perms ;
$subperms = $obj -> subperms ;
2009-12-21 01:32:17 +01:00
2012-01-11 01:06:56 +01:00
if ( $perms )
{
2013-01-19 14:32:37 +01:00
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 ();
2012-01-11 01:06:56 +01:00
if ( $subperms )
2009-12-21 01:32:17 +01:00
{
2013-01-19 14:32:37 +01:00
if ( ! isset ( $this -> rights -> $module -> $perms ) || ! is_object ( $this -> rights -> $module -> $perms )) $this -> rights -> $module -> $perms = new stdClass ();
2017-12-15 15:15:14 +01:00
if ( empty ( $this -> rights -> $module -> $perms -> $subperms )) $this -> nb_rights ++ ;
2012-01-11 01:06:56 +01:00
$this -> rights -> $module -> $perms -> $subperms = 1 ;
2009-12-21 01:32:17 +01:00
}
else
{
2017-12-15 15:15:14 +01:00
if ( empty ( $this -> rights -> $module -> $perms )) $this -> nb_rights ++ ;
2012-01-11 01:06:56 +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
}
2012-01-11 01:06:56 +01:00
if ( $moduletag == '' )
2009-05-04 20:01:47 +02:00
{
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
2009-05-04 20:01:47 +02:00
$this -> all_permissions_are_loaded = 1 ;
}
2012-01-11 01:06:56 +01:00
else
{
// Si module defini, on le marque comme charge en cache
$this -> _tab_loaded [ $moduletag ] = 1 ;
}
2009-05-04 20:01:47 +02:00
2011-09-04 20:41:19 +02: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
/**
2011-09-04 20:41:19 +02:00
* Efface un groupe de la base
*
* @ return < 0 if KO , > 0 if OK
2009-05-04 20:01:47 +02:00
*/
2006-11-20 03:10:47 +01:00
function delete ()
{
2009-05-04 20:01:47 +02:00
global $user , $conf , $langs ;
2006-11-20 03:10:47 +01:00
2011-12-05 19:41:38 +01:00
$error = 0 ;
2012-01-11 01:06:56 +01:00
2006-11-20 03:10:47 +01:00
$this -> db -> begin ();
2009-05-04 20:01:47 +02:00
2006-11-20 03:10:47 +01:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " usergroup_rights " ;
$sql .= " WHERE fk_usergroup = " . $this -> id ;
$this -> db -> query ( $sql );
2009-05-04 20:01:47 +02:00
2006-11-20 03:10:47 +01:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " usergroup_user " ;
$sql .= " WHERE fk_usergroup = " . $this -> id ;
$this -> db -> query ( $sql );
2009-05-04 20:01:47 +02:00
2014-09-22 16:31:58 +02:00
// Remove extrafields
if (( ! $error ) && ( empty ( $conf -> global -> MAIN_EXTRAFIELDS_DISABLED ))) // For avoid conflicts if trigger used
{
$result = $this -> deleteExtraFields ();
if ( $result < 0 )
{
$error ++ ;
dol_syslog ( get_class ( $this ) . " ::delete error -4 " . $this -> error , LOG_ERR );
}
}
2006-11-20 03:10:47 +01:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " usergroup " ;
$sql .= " WHERE rowid = " . $this -> id ;
$result = $this -> db -> query ( $sql );
if ( $result )
{
2014-07-03 14:01:01 +02:00
// Call trigger
$result = $this -> call_trigger ( 'GROUP_DELETE' , $user );
2014-09-05 13:48:55 +02:00
if ( $result < 0 ) { $error ++ ; $this -> db -> rollback (); return - 1 ; }
2014-07-03 14:01:01 +02:00
// End call triggers
2009-05-04 20:01:47 +02:00
2006-11-20 03:10:47 +01:00
$this -> db -> commit ();
return 1 ;
}
else
{
$this -> db -> rollback ();
2009-02-20 23:53:15 +01:00
dol_print_error ( $this -> db );
2006-11-20 03:10:47 +01:00
return - 1 ;
}
}
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
*/
2011-06-07 17:45:01 +02:00
function create ( $notrigger = 0 )
2006-11-20 02:44:27 +01:00
{
2014-09-22 16:31:58 +02:00
global $user , $conf , $langs , $hookmanager ;
2009-05-04 20:01:47 +02:00
2011-12-05 19:41:38 +01:00
$error = 0 ;
2010-05-05 19:42:01 +02:00
$now = dol_now ();
2011-08-24 00:25:37 +02:00
2013-09-09 03:43:59 +02:00
if ( ! isset ( $this -> entity )) $this -> entity = $conf -> entity ; // If not defined, we use default value
$entity = $this -> entity ;
if ( ! empty ( $conf -> multicompany -> enabled ) && $conf -> entity == 1 ) $entity = $this -> entity ;
2010-05-05 19:42:01 +02:00
2014-07-03 14:01:01 +02:00
$this -> db -> begin ();
2014-09-05 13:48:55 +02:00
2011-06-07 17:45:01 +02:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " usergroup ( " ;
$sql .= " datec " ;
$sql .= " , nom " ;
$sql .= " , entity " ;
$sql .= " ) VALUES ( " ;
$sql .= " ' " . $this -> db -> idate ( $now ) . " ' " ;
$sql .= " ,' " . $this -> db -> escape ( $this -> nom ) . " ' " ;
2014-06-09 12:34:10 +02:00
$sql .= " , " . $this -> db -> escape ( $entity );
2011-06-07 17:45:01 +02:00
$sql .= " ) " ;
2009-05-04 20:01:47 +02:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::create " , LOG_DEBUG );
2006-11-20 02:44:27 +01:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
2010-05-05 19:42:01 +02:00
$this -> id = $this -> db -> last_insert_id ( MAIN_DB_PREFIX . " usergroup " );
2009-05-04 20:01:47 +02:00
2006-11-20 02:44:27 +01:00
if ( $this -> update ( 1 ) < 0 ) return - 2 ;
2011-07-04 13:41:02 +02:00
2014-11-15 19:04:21 +01:00
$action = 'create' ;
2014-10-04 17:20:17 +02:00
2014-09-22 16:31:58 +02:00
// Actions on extra fields (by external module or standard code)
2017-02-28 11:20:33 +01:00
if ( empty ( $conf -> global -> MAIN_EXTRAFIELDS_DISABLED )) // For avoid conflicts if trigger used
2014-09-22 16:31:58 +02:00
{
2017-02-28 11:20:33 +01:00
$result = $this -> insertExtraFields ();
if ( $result < 0 )
2014-09-22 16:31:58 +02:00
{
2017-02-28 11:20:33 +01:00
$error ++ ;
2014-09-22 16:31:58 +02:00
}
}
2014-10-04 17:20:17 +02:00
2014-11-15 19:04:21 +01:00
if ( ! $error && ! $notrigger )
2011-06-07 17:45:01 +02:00
{
2014-07-03 14:01:01 +02:00
// Call trigger
$result = $this -> call_trigger ( 'GROUP_CREATE' , $user );
2014-09-05 13:48:55 +02:00
if ( $result < 0 ) { $error ++ ; $this -> db -> rollback (); return - 1 ; }
2014-07-03 14:01:01 +02:00
// End call triggers
2011-06-07 17:45:01 +02:00
}
2009-05-04 20:01:47 +02:00
2014-09-22 16:31:58 +02:00
if ( $error > 0 ) { $error ++ ; $this -> db -> rollback (); return - 1 ; }
else $this -> db -> commit ();
2014-10-04 17:20:17 +02:00
2006-11-20 02:44:27 +01:00
return $this -> id ;
}
else
{
2014-07-03 14:01:01 +02:00
$this -> db -> rollback ();
2010-05-05 19:42:01 +02:00
$this -> error = $this -> db -> lasterror ();
2006-11-20 02:44:27 +01:00
return - 1 ;
}
}
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
*/
function update ( $notrigger = 0 )
{
2014-09-22 16:31:58 +02:00
global $user , $conf , $langs , $hookmanager ;
2005-02-08 01:18:23 +01:00
2009-08-12 01:42:21 +02:00
$error = 0 ;
2011-08-24 00:25:37 +02:00
2011-08-20 00:15:22 +02:00
$entity = $conf -> entity ;
2011-08-21 12:01:36 +02:00
if ( ! empty ( $conf -> multicompany -> enabled ) && $conf -> entity == 1 )
2011-08-20 00:15:22 +02:00
{
$entity = $this -> entity ;
}
2009-08-12 01:42:21 +02:00
2014-07-03 14:01:01 +02:00
$this -> db -> begin ();
2014-09-05 13:48:55 +02:00
2009-05-04 20:01:47 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " usergroup SET " ;
2014-10-04 17:20:17 +02:00
$sql .= " nom = ' " . $this -> db -> escape ( $this -> name ) . " ' " ;
2014-06-09 12:34:10 +02:00
$sql .= " , entity = " . $this -> db -> escape ( $entity );
2011-08-20 00:15:22 +02:00
$sql .= " , note = ' " . $this -> db -> escape ( $this -> note ) . " ' " ;
$sql .= " WHERE rowid = " . $this -> id ;
2009-05-04 20:01:47 +02:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::update " , LOG_DEBUG );
2009-08-12 01:42:21 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
2009-05-04 20:01:47 +02:00
{
2014-11-15 19:04:21 +01:00
$action = 'update' ;
2014-10-04 17:20:17 +02:00
2014-09-22 16:31:58 +02:00
// Actions on extra fields (by external module or standard code)
2017-02-28 11:20:33 +01:00
if ( empty ( $conf -> global -> MAIN_EXTRAFIELDS_DISABLED )) // For avoid conflicts if trigger used
2014-09-22 16:31:58 +02:00
{
2017-02-28 11:20:33 +01:00
$result = $this -> insertExtraFields ();
if ( $result < 0 )
2014-09-22 16:31:58 +02:00
{
2017-02-28 11:20:33 +01:00
$error ++ ;
2014-09-22 16:31:58 +02:00
}
}
2014-10-04 17:20:17 +02:00
2014-11-15 19:04:21 +01:00
if ( ! $error && ! $notrigger )
2009-05-04 20:01:47 +02:00
{
2014-07-03 14:01:01 +02:00
// Call trigger
$result = $this -> call_trigger ( 'GROUP_MODIFY' , $user );
2014-09-05 13:48:55 +02:00
if ( $result < 0 ) { $error ++ ; }
2014-07-03 14:01:01 +02:00
// End call triggers
2009-05-04 20:01:47 +02:00
}
2010-01-16 20:56:05 +01:00
2014-09-05 13:48:55 +02:00
if ( ! $error )
2014-07-03 14:01:01 +02:00
{
$this -> db -> commit ();
return 1 ;
}
else
{
$this -> db -> rollback ();
return - $error ;
}
2009-05-04 20:01:47 +02:00
}
else
{
2014-07-03 14:01:01 +02:00
$this -> db -> rollback ();
2009-05-04 20:01:47 +02:00
dol_print_error ( $this -> db );
2010-01-16 20:56:05 +01:00
return - 1 ;
2009-05-04 20:01:47 +02:00
}
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
*/
function getLibStatut ( $mode = 0 )
{
return $this -> LibStatut ( 0 , $mode );
}
2017-06-06 07:57:03 +02:00
2018-09-02 20:37:12 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2017-05-09 10:19:39 +02:00
/**
* Renvoi le libelle d ' un statut donne
*
* @ param int $statut Id statut
* @ 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
*/
function LibStatut ( $statut , $mode = 0 )
{
2018-09-02 20:37:12 +02:00
// phpcs:enable
2017-05-09 10:19:39 +02:00
global $langs ;
$langs -> load ( 'users' );
return '' ;
}
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 )
* Use this -> id , this -> lastname , this -> firstname
*
* @ 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 )
* @ param string $option On what the link point to ( 'nolink' , )
* @ 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
*/
function getNomUrl ( $withpicto = 0 , $option = '' , $notooltip = 0 , $morecss = '' , $save_lastsearch_value =- 1 )
{
global $langs , $conf , $db , $hookmanager ;
global $dolibarr_main_authentication , $dolibarr_main_demo ;
global $menumanager ;
if ( ! empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER ) && $withpicto ) $withpicto = 0 ;
$result = '' ; $label = '' ;
$link = '' ; $linkstart = '' ; $linkend = '' ;
$label .= '<div class="centpercent">' ;
$label .= '<u>' . $langs -> trans ( " Group " ) . '</u><br>' ;
$label .= '<b>' . $langs -> trans ( 'Name' ) . ':</b> ' . $this -> name ;
$label .= '<br><b>' . $langs -> trans ( " Description " ) . ':</b> ' . $this -> note ;
$label .= '</div>' ;
$url = DOL_URL_ROOT . '/user/group/card.php?id=' . $this -> id ;
if ( $option != 'nolink' )
{
// Add param to save lastsearch_values or not
$add_save_lastsearch_values = ( $save_lastsearch_value == 1 ? 1 : 0 );
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' ;
}
$linkclose = " " ;
if ( empty ( $notooltip ))
{
if ( ! empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER ))
{
$langs -> load ( " users " );
$label = $langs -> trans ( " ShowGroup " );
2018-04-12 18:57:51 +02:00
$linkclose .= ' alt="' . dol_escape_htmltag ( $label , 1 , 1 ) . '"' ;
2018-02-06 19:16:15 +01:00
}
2018-04-12 18:57:51 +02:00
$linkclose .= ' title="' . dol_escape_htmltag ( $label , 1 , 1 ) . '"' ;
2018-02-06 19:16:15 +01:00
$linkclose .= ' class="classfortooltip' . ( $morecss ? ' ' . $morecss : '' ) . '"' ;
2018-06-04 12:55:55 +02:00
/*
$hookmanager -> initHooks ( array ( 'groupdao' ));
$parameters = array ( 'id' => $this -> id );
$reshook = $hookmanager -> executeHooks ( 'getnomurltooltip' , $parameters , $this , $action ); // Note that $action and $object may have been modified by some hooks
if ( $reshook > 0 ) $linkclose = $hookmanager -> resPrint ;
*/
2018-02-06 19:16:15 +01:00
}
$linkstart = '<a href="' . $url . '"' ;
$linkstart .= $linkclose . '>' ;
$linkend = '</a>' ;
$result = $linkstart ;
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 ;
$result .= $linkend ;
2018-03-15 20:46:55 +01:00
global $action ;
$hookmanager -> initHooks ( array ( 'groupdao' ));
$parameters = array ( 'id' => $this -> id , 'getnomurl' => $result );
$reshook = $hookmanager -> executeHooks ( 'getNomUrl' , $parameters , $this , $action ); // Note that $action and $object may have been modified by some hooks
if ( $reshook > 0 ) $result = $hookmanager -> resPrint ;
else $result .= $hookmanager -> resPrint ;
2018-02-06 19:16:15 +01:00
return $result ;
}
2018-09-02 20:37:12 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
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
*/
2006-11-21 23:51:05 +01:00
function _load_ldap_dn ( $info , $mode = 0 )
2006-11-19 17:41:17 +01:00
{
2018-09-02 20:37:12 +02:00
// phpcs:enable
2006-11-21 23:51:05 +01:00
global $conf ;
$dn = '' ;
2009-08-11 22:16:58 +02:00
if ( $mode == 0 ) $dn = $conf -> global -> LDAP_KEY_GROUPS . " = " . $info [ $conf -> global -> LDAP_KEY_GROUPS ] . " , " . $conf -> global -> LDAP_GROUP_DN ;
2006-11-21 23:51:05 +01:00
if ( $mode == 1 ) $dn = $conf -> global -> LDAP_GROUP_DN ;
if ( $mode == 2 ) $dn = $conf -> global -> LDAP_KEY_GROUPS . " = " . $info [ $conf -> global -> LDAP_KEY_GROUPS ];
return $dn ;
2006-11-19 17:41:17 +01:00
}
2006-11-20 02:13:13 +01:00
2018-09-02 20:37:12 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
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
*/
2006-11-21 23:51:05 +01:00
function _load_ldap_info ()
2006-11-20 02:13:13 +01:00
{
2018-09-02 20:37:12 +02:00
// phpcs:enable
2006-11-20 02:13:13 +01:00
global $conf , $langs ;
2017-07-13 23:52:02 +02:00
2006-11-21 23:51:05 +01:00
$info = array ();
2009-05-04 20:01:47 +02:00
2007-04-13 02:35:13 +02:00
// Object classes
2009-10-20 15:14:44 +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
2014-10-04 17:20:17 +02:00
if ( $this -> name && ! empty ( $conf -> global -> LDAP_GROUP_FIELD_FULLNAME )) $info [ $conf -> global -> LDAP_GROUP_FIELD_FULLNAME ] = $this -> name ;
//if ($this->name && ! empty($conf->global->LDAP_GROUP_FIELD_NAME)) $info[$conf->global->LDAP_GROUP_FIELD_NAME] = $this->name;
2018-04-06 12:27:55 +02:00
if ( $this -> note && ! empty ( $conf -> global -> LDAP_GROUP_FIELD_DESCRIPTION )) $info [ $conf -> global -> LDAP_GROUP_FIELD_DESCRIPTION ] = dol_string_nohtmltag ( $this -> note , 2 );
2012-09-15 10:01:35 +02:00
if ( ! empty ( $conf -> global -> LDAP_GROUP_FIELD_GROUPMEMBERS ))
2009-12-21 01:50:46 +01:00
{
2009-12-21 12:12:57 +01:00
$valueofldapfield = array ();
2012-05-11 12:10:47 +02:00
foreach ( $this -> members as $key => $val ) // This is array of users for group into dolibarr database.
2009-12-21 01:50:46 +01: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
}
2009-12-21 13:28:21 +01:00
$info [ $conf -> global -> LDAP_GROUP_FIELD_GROUPMEMBERS ] = ( ! empty ( $valueofldapfield ) ? $valueofldapfield : '' );
2009-12-21 01:50:46 +01:00
}
2006-11-20 02:13:13 +01:00
return $info ;
}
2006-11-19 17:41:17 +01:00
/**
2011-09-20 19:19:46 +02: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
2006-11-19 17:41:17 +01:00
*/
function initAsSpecimen ()
{
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
2006-11-19 17:41:17 +01:00
$this -> id = 0 ;
$this -> ref = 'SPECIMEN' ;
$this -> specimen = 1 ;
2014-10-04 17:20:17 +02:00
$this -> name = 'DOLIBARR GROUP SPECIMEN' ;
2006-11-19 17:41:17 +01:00
$this -> note = 'This is a note' ;
2009-05-04 20:01:47 +02:00
$this -> datec = time ();
$this -> datem = time ();
2017-05-24 11:27:27 +02:00
// Members of this group is just me
$this -> members = array (
$user -> id => $user
);
2006-11-19 17:41:17 +01:00
}
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
2018-09-02 20:37:12 +02: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
*/
2018-06-15 09:47:28 +02:00
public function generateDocument ( $modele , $outputlangs , $hidedetails = 0 , $hidedesc = 0 , $hideref = 0 , $moreparams = null )
2017-03-08 11:34:21 +01:00
{
global $conf , $user , $langs ;
$langs -> load ( " user " );
// Positionne le modele sur le nom du modele a utiliser
if ( ! dol_strlen ( $modele ))
{
if ( ! empty ( $conf -> global -> USERGROUP_ADDON_PDF ))
{
$modele = $conf -> global -> USERGROUP_ADDON_PDF ;
}
else
{
$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
}