33require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
35 require_once DOL_DOCUMENT_ROOT.
"/core/class/ldap.class.php";
47 public $element =
'usergroup';
52 public $table_element =
'usergroup';
57 public $picto =
'group';
80 public $usergroup_entity;
102 public $members = array();
122 private $_tab_loaded = array();
127 public $all_permissions_are_loaded;
129 public $fields = array(
130 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'index' => 1,
'position' => 1,
'comment' =>
'Id'),
131 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'enabled' => 1,
'visible' => 0,
'notnull' => 1,
'default' =>
'1',
'index' => 1,
'position' => 5),
132 'nom' => array(
'type' =>
'varchar(180)',
'label' =>
'Name',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 10,
'searchall' => 1,
'comment' =>
'Group name'),
133 'note' => array(
'type' =>
'html',
'label' =>
'Description',
'enabled' => 1,
'visible' => 1,
'position' => 20,
'notnull' => -1,
'searchall' => 1),
134 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -2,
'position' => 50,
'notnull' => 1,),
135 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -2,
'position' => 60,
'notnull' => 1,),
136 'color' => array(
'type' =>
'varchar(6)',
'label' =>
'Color',
'enabled' => 1,
'visible' => 1,
'position' => 70,
'notnull' => -1,
'comment' =>
'Color for pictogram'),
137 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'ModelPDF',
'enabled' => 1,
'visible' => 0,
'position' => 100),
143 public $fk_element =
'fk_usergroup';
148 protected $childtables = array();
153 protected $childtablesoncascade = array(
'usergroup_rights',
'usergroup_user');
158 public $isextrafieldmanaged = 1;
170 $this->ismultientitymanaged = 1;
171 $this->nb_rights = 0;
183 public function fetch($id = 0, $groupname =
'', $load_members =
false)
185 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
186 if (!empty($groupname)) {
187 $result = $this->
fetchCommon(0,
'',
' AND nom = \''.$this->db->escape($groupname).
'\'');
192 $this->
name = $this->nom;
193 $this->note_private = $this->note;
203 $this->error = $this->db->lasterror();
222 $sql =
"SELECT g.rowid, ug.entity as usergroup_entity";
223 $sql .=
" FROM ".$this->db->prefix().
"usergroup as g,";
224 $sql .=
" ".$this->db->prefix().
"usergroup_user as ug";
225 $sql .=
" WHERE ug.fk_usergroup = g.rowid";
226 $sql .=
" AND ug.fk_user = ".((int) $userid);
227 if (
isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && !$user->entity) {
228 $sql .=
" AND g.entity IS NOT NULL";
230 $sql .=
" AND g.entity IN (0,".((int)
$conf->entity).
")";
232 $sql .=
" ORDER BY g.nom";
234 dol_syslog(get_class($this).
"::listGroupsForUser", LOG_DEBUG);
235 $result = $this->db->query($sql);
237 while ($obj = $this->db->fetch_object($result)) {
238 if (!array_key_exists($obj->rowid, $ret)) {
240 $newgroup->fetch($obj->rowid,
'', $load_members);
241 $ret[$obj->rowid] = $newgroup;
243 if (!is_array($ret[$obj->rowid]->usergroup_entity)) {
244 $ret[$obj->rowid]->usergroup_entity = array();
247 $ret[$obj->rowid]->usergroup_entity[] = (int) $obj->usergroup_entity;
250 $this->db->free($result);
254 $this->error = $this->db->lasterror();
272 $sql =
"SELECT u.rowid, u.login, u.lastname, u.firstname, u.photo, u.fk_soc, u.entity, u.employee, u.email, u.statut as status";
273 if (!empty($this->
id)) {
274 $sql .=
", ug.entity as usergroup_entity";
276 $sql .=
" FROM ".$this->db->prefix().
"user as u";
277 if (!empty($this->
id)) {
278 $sql .=
", ".$this->db->prefix().
"usergroup_user as ug";
280 $sql .=
" WHERE 1 = 1";
281 if (!empty($this->
id)) {
282 $sql .=
" AND ug.fk_user = u.rowid";
284 if (!empty($this->
id)) {
285 $sql .=
" AND ug.fk_usergroup = ".((int) $this->
id);
287 if (
isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
288 $sql .=
" AND u.entity IS NOT NULL";
290 $sql .=
" AND u.entity IN (0,".((int)
$conf->entity).
")";
292 if (!empty($excludefilter)) {
293 $sql .=
' AND ('.$excludefilter.
')';
296 dol_syslog(get_class($this).
"::listUsersForGroup", LOG_DEBUG);
297 $resql = $this->db->query($sql);
300 while ($obj = $this->db->fetch_object($resql)) {
301 if (!array_key_exists($obj->rowid, $ret)) {
303 $newuser =
new User($this->db);
305 $newuser->id = $obj->rowid;
306 $newuser->login = $obj->login;
307 $newuser->photo = $obj->photo;
308 $newuser->lastname = $obj->lastname;
309 $newuser->firstname = $obj->firstname;
310 $newuser->email = $obj->email;
311 $newuser->socid = $obj->fk_soc;
312 $newuser->entity = $obj->entity;
313 $newuser->employee = $obj->employee;
314 $newuser->status = $obj->status;
316 $ret[$obj->rowid] = $newuser;
318 $ret[$obj->rowid] = $obj->rowid;
321 if ($mode != 1 && !empty($obj->usergroup_entity)) {
323 if (!is_array($ret[$obj->rowid]->usergroup_entity)) {
324 $ret[$obj->rowid]->usergroup_entity = array();
326 $ret[$obj->rowid]->usergroup_entity[] = (int) $obj->usergroup_entity;
330 $this->db->free($resql);
334 $this->error = $this->db->lasterror();
348 public function addrights($rid, $allmodule =
'', $allperms =
'', $entity = 0)
350 global
$conf, $user, $langs;
352 $entity = (!empty($entity) ? $entity :
$conf->entity);
354 dol_syslog(get_class($this).
"::addrights $rid, $allmodule, $allperms, $entity");
361 $module = $perms = $subperms =
'';
365 $sql =
"SELECT module, perms, subperms";
366 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
367 $sql .=
" WHERE id = ".((int) $rid);
368 $sql .=
" AND entity = ".((int) $entity);
370 $result = $this->db->query($sql);
372 $obj = $this->db->fetch_object($result);
374 $module = $obj->module;
375 $perms = $obj->perms;
376 $subperms = $obj->subperms;
384 $whereforadd =
"id=".((int) $rid);
387 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND (subperms='lire' OR subperms='read'))";
389 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
393 if (!empty($allmodule)) {
394 if ($allmodule ==
'allmodules') {
395 $whereforadd =
'allmodules';
397 $whereforadd =
"module='".$this->db->escape($allmodule).
"'";
398 if (!empty($allperms)) {
399 $whereforadd .=
" AND perms='".$this->db->escape($allperms).
"'";
406 if (!empty($whereforadd)) {
409 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
410 $sql .=
" WHERE entity = ".((int) $entity);
411 if (!empty($whereforadd) && $whereforadd !=
'allmodules') {
412 $sanitizedwhereforadd = $whereforadd;
413 $sql .=
" AND ".$sanitizedwhereforadd;
416 $result = $this->db->query($sql);
418 $num = $this->db->num_rows($result);
421 $obj = $this->db->fetch_object($result);
424 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_rights WHERE fk_usergroup = ".((int) $this->
id).
" AND fk_id=".((int) $nid).
" AND entity = ".((int) $entity);
425 if (!$this->db->query($sql)) {
428 $sql =
"INSERT INTO ".$this->db->prefix().
"usergroup_rights (entity, fk_usergroup, fk_id) VALUES (".((int) $entity).
", ".((int) $this->
id).
", ".((int) $nid).
")";
429 if (!$this->db->query($sql)) {
441 $langs->load(
"other");
442 $this->context = array(
'audit' => $langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
445 $result = $this->call_trigger(
'USERGROUP_MODIFY', $user);
454 $this->db->rollback();
472 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0)
474 global
$conf, $user, $langs;
479 $entity = (!empty($entity) ? $entity :
$conf->entity);
484 $module = $perms = $subperms =
'';
488 $sql =
"SELECT module, perms, subperms";
489 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
490 $sql .=
" WHERE id = ".((int) $rid);
491 $sql .=
" AND entity = ".((int) $entity);
493 $result = $this->db->query($sql);
495 $obj = $this->db->fetch_object($result);
497 $module = $obj->module;
498 $perms = $obj->perms;
499 $subperms = $obj->subperms;
507 $wherefordel =
"id = ".((int) $rid);
509 if ($subperms ==
'lire' || $subperms ==
'read') {
510 $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND subperms IS NOT NULL)";
512 if ($perms ==
'lire' || $perms ==
'read') {
513 $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
521 if (!empty($allmodule)) {
522 if ($allmodule ==
'allmodules') {
523 $wherefordel =
'allmodules';
525 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
526 if (!empty($allperms)) {
527 $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
534 if (!empty($wherefordel)) {
537 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
538 $sql .=
" WHERE entity = ".((int) $entity);
539 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
540 $sanitizedwherefordel = $wherefordel;
541 $sql .=
" AND ".$sanitizedwherefordel;
544 $result = $this->db->query($sql);
546 $num = $this->db->num_rows($result);
551 $obj = $this->db->fetch_object($result);
556 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_rights";
557 $sql .=
" WHERE fk_usergroup = ".((int) $this->
id).
" AND fk_id=".((int) $nid);
558 $sql .=
" AND entity = ".((int) $entity);
559 if (!$this->db->query($sql)) {
571 $langs->load(
"other");
572 $this->context = array(
'audit' => $langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
575 $result = $this->call_trigger(
'USERGROUP_MODIFY', $user);
584 $this->db->rollback();
617 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
622 if (!empty($this->all_permissions_are_loaded)) {
628 $sql =
"SELECT r.module, r.perms, r.subperms ";
629 $sql .=
" FROM ".$this->db->prefix().
"usergroup_rights as u, ".$this->db->prefix().
"rights_def as r";
630 $sql .=
" WHERE r.id = u.fk_id";
631 $sql .=
" AND r.entity = ".((int)
$conf->entity);
632 $sql .=
" AND u.entity = ".((int)
$conf->entity);
633 $sql .=
" AND u.fk_usergroup = ".((int) $this->
id);
634 $sql .=
" AND r.perms IS NOT NULL";
636 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
639 dol_syslog(get_class($this).
'::getrights', LOG_DEBUG);
640 $resql = $this->db->query($sql);
642 $num = $this->db->num_rows($resql);
645 $obj = $this->db->fetch_object($resql);
648 $module = $obj->module;
649 $perms = $obj->perms;
650 $subperms = $obj->subperms;
653 if (!isset($this->rights)) {
656 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
657 $this->rights->$module =
new stdClass();
660 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
661 $this->rights->$module->$perms =
new stdClass();
663 if (empty($this->rights->$module->$perms->$subperms)) {
666 $this->rights->$module->$perms->$subperms = 1;
668 if (empty($this->rights->$module->$perms)) {
671 $this->rights->$module->$perms = 1;
678 $this->db->free($resql);
681 if ($moduletag ==
'') {
684 $this->all_permissions_are_loaded = 1;
687 $this->_tab_loaded[$moduletag] = 1;
699 public function delete(
User $user)
715 if (!empty($this->
name)) {
716 $this->nom = $this->name;
718 if (!empty($this->note_private)) {
719 $this->note = $this->note_private;
722 if (!isset($this->entity)) {
723 $this->entity =
$conf->entity;
739 if (!empty($this->
name)) {
740 $this->nom = $this->name;
743 if (!empty($this->note_private)) {
744 $this->note = $this->note_private;
760 public function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0)
763 $lastname = $this->lastname;
764 $firstname = $this->firstname;
765 if (empty($lastname)) {
766 $lastname = (isset($this->lastname) ? $this->lastname : (isset($this->
name) ? $this->
name : (isset($this->nom) ? $this->nom : (isset($this->societe) ? $this->societe : (isset($this->company) ? $this->company :
'')))));
770 if (!empty($option) && !empty($this->civility_code)) {
771 if ($langs->transnoentitiesnoconv(
"Civility".$this->civility_code) !=
"Civility".$this->civility_code) {
772 $ret .= $langs->transnoentitiesnoconv(
"Civility".$this->civility_code).
' ';
774 $ret .= $this->civility_code.
' ';
806 $langs->load(
'users');
818 global
$conf, $langs, $menumanager;
820 $option = $params[
'option'] ??
'';
824 $langs->load(
"users");
825 return [
'optimize' => $langs->trans(
"ShowGroup")];
827 $datas[
'divopen'] =
'<div class="centpercent">';
828 $datas[
'picto'] =
img_picto(
'',
'group').
' <u>'.$langs->trans(
"Group").
'</u><br>';
829 $datas[
'name'] =
'<b>'.$langs->trans(
'Name').
':</b> '.$this->name;
830 $datas[
'description'] =
'<br><b>'.$langs->trans(
"Description").
':</b> '.$this->note;
831 $datas[
'divclose'] =
'</div>';
847 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
849 global $langs,
$conf, $db, $hookmanager;
858 'objecttype' => $this->element,
861 $classfortooltip =
'classfortooltip';
864 $classfortooltip =
'classforajaxtooltip';
865 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
871 if ($option ==
'permissions') {
872 $baseurl = DOL_URL_ROOT.
'/user/group/perms.php';
874 $baseurl = DOL_URL_ROOT.
'/user/group/card.php';
876 $query = [
'id' => $this->id];
878 if ($option !=
'nolink') {
880 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
881 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
882 $add_save_lastsearch_values = 1;
884 if ($add_save_lastsearch_values) {
885 $query = array_merge($query, [
'save_lastsearch_values' => 1]);
891 if (empty($notooltip)) {
893 $langs->load(
"users");
894 $label = $langs->trans(
"ShowGroup");
895 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1, 1).
'"';
897 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
898 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
901 $linkstart =
'<a href="'.$url.
'"';
902 $linkstart .= $linkclose.
'>';
905 $result = $linkstart;
907 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
909 if ($withpicto != 2) {
910 $result .= $this->name;
915 $hookmanager->initHooks(array(
'groupdao'));
916 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
917 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
919 $result = $hookmanager->resPrint;
921 $result .= $hookmanager->resPrint;
982 $valueofldapfield = array();
983 foreach ($this->members as $key => $val) {
984 $muser =
new User($this->db);
985 $muser->fetch($val->id);
986 $info2 = $muser->_load_ldap_info();
987 $valueofldapfield[] = $muser->_load_ldap_dn($info2);
989 $info[
getDolGlobalString(
'LDAP_GROUP_FIELD_GROUPMEMBERS')] = (!empty($valueofldapfield) ? $valueofldapfield :
'');
1007 global
$conf, $user, $langs;
1011 $this->
ref =
'SPECIMEN';
1012 $this->specimen = 1;
1014 $this->
name =
'DOLIBARR GROUP SPECIMEN';
1015 $this->note =
'This is a note';
1016 $this->datec = time();
1017 $this->tms = time();
1020 $this->members = array(
1038 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
1040 global
$conf, $user, $langs;
1042 $langs->load(
"user");
1053 $modelpath =
"core/modules/usergroup/doc/";
1055 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1069 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1071 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1072 $return .=
'<div class="info-box info-box-sm">';
1073 $return .=
'<span class="info-box-icon bg-infobox-action">';
1075 $return .=
'</span>';
1076 $return .=
'<div class="info-box-content">';
1077 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1078 if ($selected >= 0) {
1079 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1081 if (property_exists($this,
'members')) {
1082 $return .=
'<br><span class="info-box-status opacitymedium">'.(empty($this->nb_users) ? 0 : $this->nb_users).
' '.$langs->trans(
'Users').
'</span>';
1084 if (property_exists($this,
'nb_rights')) {
1085 $return .=
'<br><div class="info-box-status margintoponly opacitymedium">'.$langs->trans(
'NbOfPermissions').
' : '.(empty($this->nb_rights) ? 0 : $this->nb_rights).
'</div>';
1087 $return .=
'</div>';
1088 $return .=
'</div>';
1089 $return .=
'</div>';
Parent class of all other business classes (invoices, contracts, proposals, orders,...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
createCommon(User $user, $notrigger=0)
Create object in the database.
updateCommon(User $user, $notrigger=0)
Update object into database.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
Class to manage user groups.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the user card (with optionally the picto) Use this->id,this->lastname,...
fetch($id=0, $groupname='', $load_members=false)
Load a group object with all properties (except ->members array that is array of users in group)
listUsersForGroup($excludefilter='', $mode=0)
Return array of User objects for group this->id (or all if this->id not defined)
loadRights($moduletag='')
Load the list of permissions for the user into the group object.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
_load_ldap_info()
Initialize the info array (array of LDAP values) that will be used to call LDAP functions.
_load_ldap_dn($info, $mode=0)
Returns the full DN string in the LDAP directory for the object.
LibStatut($status, $mode=0)
Return the label of a given status.
delrights($rid, $allmodule='', $allperms='', $entity=0)
Remove a permission from group.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
listGroupsForUser($userid, $load_members=true)
Return array of groups objects for a particular user.
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+' '+name+' '+lastname)
addrights($rid, $allmodule='', $allperms='', $entity=0)
Add a permission to a group.
initAsSpecimen()
Initialise an instance with random values.
create($notrigger=0)
Create group into database.
getrights($moduletag='')
Load the list of permissions for the user into the group object.
getLibStatut($mode=0)
Return the label of the status.
getTooltipContentArray($params)
getTooltipContentArray
__construct($db)
Class constructor.
update($notrigger=0)
Update group into database.
Class to manage Dolibarr users.
dol_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db name
Only used if Module[ID]Name translation string is not found.