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,".$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,".$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 $sql .=
" AND ".$whereforadd;
415 $result = $this->db->query($sql);
417 $num = $this->db->num_rows($result);
420 $obj = $this->db->fetch_object($result);
423 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_rights WHERE fk_usergroup = ".((int) $this->
id).
" AND fk_id=".((int) $nid).
" AND entity = ".((int) $entity);
424 if (!$this->db->query($sql)) {
427 $sql =
"INSERT INTO ".$this->db->prefix().
"usergroup_rights (entity, fk_usergroup, fk_id) VALUES (".((int) $entity).
", ".((int) $this->
id).
", ".((int) $nid).
")";
428 if (!$this->db->query($sql)) {
440 $langs->load(
"other");
441 $this->context = array(
'audit' => $langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
444 $result = $this->call_trigger(
'USERGROUP_MODIFY', $user);
453 $this->db->rollback();
471 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0)
473 global $conf, $user, $langs;
478 $entity = (!empty($entity) ? $entity : $conf->entity);
483 $module = $perms = $subperms =
'';
487 $sql =
"SELECT module, perms, subperms";
488 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
489 $sql .=
" WHERE id = ".((int) $rid);
490 $sql .=
" AND entity = ".((int) $entity);
492 $result = $this->db->query($sql);
494 $obj = $this->db->fetch_object($result);
496 $module = $obj->module;
497 $perms = $obj->perms;
498 $subperms = $obj->subperms;
506 $wherefordel =
"id = ".((int) $rid);
508 if ($subperms ==
'lire' || $subperms ==
'read') {
509 $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND subperms IS NOT NULL)";
511 if ($perms ==
'lire' || $perms ==
'read') {
512 $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
520 if (!empty($allmodule)) {
521 if ($allmodule ==
'allmodules') {
522 $wherefordel =
'allmodules';
524 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
525 if (!empty($allperms)) {
526 $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
533 if (!empty($wherefordel)) {
536 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
537 $sql .=
" WHERE entity = ".((int) $entity);
538 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
539 $sql .=
" AND ".$wherefordel;
542 $result = $this->db->query($sql);
544 $num = $this->db->num_rows($result);
549 $obj = $this->db->fetch_object($result);
554 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_rights";
555 $sql .=
" WHERE fk_usergroup = $this->id AND fk_id=".((int) $nid);
556 $sql .=
" AND entity = ".((int) $entity);
557 if (!$this->db->query($sql)) {
569 $langs->load(
"other");
570 $this->context = array(
'audit' => $langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
573 $result = $this->call_trigger(
'USERGROUP_MODIFY', $user);
582 $this->db->rollback();
615 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
620 if (!empty($this->all_permissions_are_loaded)) {
626 $sql =
"SELECT r.module, r.perms, r.subperms ";
627 $sql .=
" FROM ".$this->db->prefix().
"usergroup_rights as u, ".$this->db->prefix().
"rights_def as r";
628 $sql .=
" WHERE r.id = u.fk_id";
629 $sql .=
" AND r.entity = ".((int) $conf->entity);
630 $sql .=
" AND u.entity = ".((int) $conf->entity);
631 $sql .=
" AND u.fk_usergroup = ".((int) $this->
id);
632 $sql .=
" AND r.perms IS NOT NULL";
634 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
637 dol_syslog(get_class($this).
'::getrights', LOG_DEBUG);
638 $resql = $this->db->query($sql);
640 $num = $this->db->num_rows($resql);
643 $obj = $this->db->fetch_object($resql);
646 $module = $obj->module;
647 $perms = $obj->perms;
648 $subperms = $obj->subperms;
651 if (!isset($this->rights)) {
654 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
655 $this->rights->$module =
new stdClass();
658 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
659 $this->rights->$module->$perms =
new stdClass();
661 if (empty($this->rights->$module->$perms->$subperms)) {
664 $this->rights->$module->$perms->$subperms = 1;
666 if (empty($this->rights->$module->$perms)) {
669 $this->rights->$module->$perms = 1;
676 $this->db->free($resql);
679 if ($moduletag ==
'') {
682 $this->all_permissions_are_loaded = 1;
685 $this->_tab_loaded[$moduletag] = 1;
697 public function delete(
User $user)
713 if (!empty($this->
name)) {
714 $this->nom = $this->name;
716 if (!empty($this->note_private)) {
717 $this->note = $this->note_private;
720 if (!isset($this->entity)) {
721 $this->entity = $conf->entity;
737 if (!empty($this->
name)) {
738 $this->nom = $this->name;
741 if (!empty($this->note_private)) {
742 $this->note = $this->note_private;
758 public function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0)
761 $lastname = $this->lastname;
762 $firstname = $this->firstname;
763 if (empty($lastname)) {
764 $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 :
'')))));
768 if (!empty($option) && !empty($this->civility_code)) {
769 if ($langs->transnoentitiesnoconv(
"Civility".$this->civility_code) !=
"Civility".$this->civility_code) {
770 $ret .= $langs->transnoentitiesnoconv(
"Civility".$this->civility_code).
' ';
772 $ret .= $this->civility_code.
' ';
804 $langs->load(
'users');
816 global $conf, $langs, $menumanager;
818 $option = $params[
'option'] ??
'';
822 $langs->load(
"users");
823 return [
'optimize' => $langs->trans(
"ShowGroup")];
825 $datas[
'divopen'] =
'<div class="centpercent">';
826 $datas[
'picto'] =
img_picto(
'',
'group').
' <u>'.$langs->trans(
"Group").
'</u><br>';
827 $datas[
'name'] =
'<b>'.$langs->trans(
'Name').
':</b> '.$this->name;
828 $datas[
'description'] =
'<br><b>'.$langs->trans(
"Description").
':</b> '.$this->note;
829 $datas[
'divclose'] =
'</div>';
845 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
847 global $langs, $conf, $db, $hookmanager;
856 'objecttype' => $this->element,
859 $classfortooltip =
'classfortooltip';
862 $classfortooltip =
'classforajaxtooltip';
863 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
869 if ($option ==
'permissions') {
870 $baseurl = DOL_URL_ROOT.
'/user/group/perms.php';
872 $baseurl = DOL_URL_ROOT.
'/user/group/card.php';
874 $query = [
'id' => $this->id];
876 if ($option !=
'nolink') {
878 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
879 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
880 $add_save_lastsearch_values = 1;
882 if ($add_save_lastsearch_values) {
883 $query = array_merge($query, [
'save_lastsearch_values' => 1]);
889 if (empty($notooltip)) {
891 $langs->load(
"users");
892 $label = $langs->trans(
"ShowGroup");
893 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1, 1).
'"';
895 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
896 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
899 $linkstart =
'<a href="'.$url.
'"';
900 $linkstart .= $linkclose.
'>';
903 $result = $linkstart;
905 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
907 if ($withpicto != 2) {
908 $result .= $this->name;
913 $hookmanager->initHooks(array(
'groupdao'));
914 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
915 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
917 $result = $hookmanager->resPrint;
919 $result .= $hookmanager->resPrint;
980 $valueofldapfield = array();
981 foreach ($this->members as $key => $val) {
982 $muser =
new User($this->db);
983 $muser->fetch($val->id);
984 $info2 = $muser->_load_ldap_info();
985 $valueofldapfield[] = $muser->_load_ldap_dn($info2);
987 $info[
getDolGlobalString(
'LDAP_GROUP_FIELD_GROUPMEMBERS')] = (!empty($valueofldapfield) ? $valueofldapfield :
'');
1005 global $conf, $user, $langs;
1009 $this->
ref =
'SPECIMEN';
1010 $this->specimen = 1;
1012 $this->
name =
'DOLIBARR GROUP SPECIMEN';
1013 $this->note =
'This is a note';
1014 $this->datec = time();
1015 $this->tms = time();
1018 $this->members = array(
1036 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
1038 global $conf, $user, $langs;
1040 $langs->load(
"user");
1051 $modelpath =
"core/modules/usergroup/doc/";
1053 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1067 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1069 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1070 $return .=
'<div class="info-box info-box-sm">';
1071 $return .=
'<span class="info-box-icon bg-infobox-action">';
1073 $return .=
'</span>';
1074 $return .=
'<div class="info-box-content">';
1075 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1076 if ($selected >= 0) {
1077 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1079 if (property_exists($this,
'members')) {
1080 $return .=
'<br><span class="info-box-status opacitymedium">'.(empty($this->nb_users) ? 0 : $this->nb_users).
' '.$langs->trans(
'Users').
'</span>';
1082 if (property_exists($this,
'nb_rights')) {
1083 $return .=
'<br><div class="info-box-status margintoponly opacitymedium">'.$langs->trans(
'NbOfPermissions').
' : '.(empty($this->nb_rights) ? 0 : $this->nb_rights).
'</div>';
1085 $return .=
'</div>';
1086 $return .=
'</div>';
1087 $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)
Retourne chaine DN complete dans l'annuaire LDAP pour l'objet.
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)
dolBuildUrl($url, $params=[], $addtoken=false)
Return path of url.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
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.