32require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
33if (isModEnabled(
'ldap')) {
34 require_once DOL_DOCUMENT_ROOT.
"/core/class/ldap.class.php";
46 public $element =
'usergroup';
51 public $table_element =
'usergroup';
56 public $picto =
'group';
81 public $usergroup_entity;
98 public $members = array();
118 private $_tab_loaded = array();
123 public $all_permissions_are_loaded;
127 public $fields = array(
128 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'index' => 1,
'position' => 1,
'comment' =>
'Id'),
129 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'enabled' => 1,
'visible' => 0,
'notnull' => 1,
'default' =>
'1',
'index' => 1,
'position' => 5),
130 'nom' => array(
'type' =>
'varchar(180)',
'label' =>
'Name',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 10,
'searchall' => 1,
'comment' =>
'Group name'),
131 'note' => array(
'type' =>
'html',
'label' =>
'Description',
'enabled' => 1,
'visible' => 1,
'position' => 20,
'notnull' => -1,
'searchall' => 1),
132 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -2,
'position' => 50,
'notnull' => 1,),
133 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -2,
'position' => 60,
'notnull' => 1,),
134 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'ModelPDF',
'enabled' => 1,
'visible' => 0,
'position' => 100),
140 public $fk_element =
'fk_usergroup';
145 protected $childtables = array();
150 protected $childtablesoncascade = array(
'usergroup_rights',
'usergroup_user');
162 $this->ismultientitymanaged = 1;
163 $this->nb_rights = 0;
175 public function fetch($id = 0, $groupname =
'', $load_members =
false)
177 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
178 if (!empty($groupname)) {
179 $result = $this->
fetchCommon(0,
'',
' AND nom = \''.$this->db->escape($groupname).
'\'');
184 $this->
name = $this->nom;
194 $this->error = $this->db->lasterror();
213 $sql =
"SELECT g.rowid, ug.entity as usergroup_entity";
214 $sql .=
" FROM ".$this->db->prefix().
"usergroup as g,";
215 $sql .=
" ".$this->db->prefix().
"usergroup_user as ug";
216 $sql .=
" WHERE ug.fk_usergroup = g.rowid";
217 $sql .=
" AND ug.fk_user = ".((int) $userid);
218 if (isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
219 $sql .=
" AND g.entity IS NOT NULL";
221 $sql .=
" AND g.entity IN (0,".$conf->entity.
")";
223 $sql .=
" ORDER BY g.nom";
225 dol_syslog(get_class($this).
"::listGroupsForUser", LOG_DEBUG);
226 $result = $this->db->query($sql);
228 while ($obj = $this->db->fetch_object($result)) {
229 if (!array_key_exists($obj->rowid, $ret)) {
231 $newgroup->fetch($obj->rowid,
'', $load_members);
232 $ret[$obj->rowid] = $newgroup;
234 if (!is_array($ret[$obj->rowid]->usergroup_entity)) {
235 $ret[$obj->rowid]->usergroup_entity = array();
238 $ret[$obj->rowid]->usergroup_entity[] = (int) $obj->usergroup_entity;
241 $this->db->free($result);
245 $this->error = $this->db->lasterror();
263 $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";
264 if (!empty($this->
id)) {
265 $sql .=
", ug.entity as usergroup_entity";
267 $sql .=
" FROM ".$this->db->prefix().
"user as u";
268 if (!empty($this->
id)) {
269 $sql .=
", ".$this->db->prefix().
"usergroup_user as ug";
271 $sql .=
" WHERE 1 = 1";
272 if (!empty($this->
id)) {
273 $sql .=
" AND ug.fk_user = u.rowid";
275 if (!empty($this->
id)) {
276 $sql .=
" AND ug.fk_usergroup = ".((int) $this->
id);
278 if (isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
279 $sql .=
" AND u.entity IS NOT NULL";
281 $sql .=
" AND u.entity IN (0,".$conf->entity.
")";
283 if (!empty($excludefilter)) {
284 $sql .=
' AND ('.$excludefilter.
')';
287 dol_syslog(get_class($this).
"::listUsersForGroup", LOG_DEBUG);
288 $resql = $this->db->query($sql);
291 while ($obj = $this->db->fetch_object($resql)) {
292 if (!array_key_exists($obj->rowid, $ret)) {
294 $newuser =
new User($this->db);
296 $newuser->id = $obj->rowid;
297 $newuser->login = $obj->login;
298 $newuser->photo = $obj->photo;
299 $newuser->lastname = $obj->lastname;
300 $newuser->firstname = $obj->firstname;
301 $newuser->email = $obj->email;
302 $newuser->socid = $obj->fk_soc;
303 $newuser->entity = $obj->entity;
304 $newuser->employee = $obj->employee;
305 $newuser->status = $obj->status;
307 $ret[$obj->rowid] = $newuser;
309 $ret[$obj->rowid] = $obj->rowid;
312 if ($mode != 1 && !empty($obj->usergroup_entity)) {
314 if (!is_array($ret[$obj->rowid]->usergroup_entity)) {
315 $ret[$obj->rowid]->usergroup_entity = array();
317 $ret[$obj->rowid]->usergroup_entity[] = (int) $obj->usergroup_entity;
321 $this->db->free($resql);
325 $this->error = $this->db->lasterror();
339 public function addrights($rid, $allmodule =
'', $allperms =
'', $entity = 0)
341 global $conf, $user, $langs;
343 $entity = (!empty($entity) ? $entity : $conf->entity);
345 dol_syslog(get_class($this).
"::addrights $rid, $allmodule, $allperms, $entity");
352 $module = $perms = $subperms =
'';
356 $sql =
"SELECT module, perms, subperms";
357 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
358 $sql .=
" WHERE id = ".((int) $rid);
359 $sql .=
" AND entity = ".((int) $entity);
361 $result = $this->db->query($sql);
363 $obj = $this->db->fetch_object($result);
365 $module = $obj->module;
366 $perms = $obj->perms;
367 $subperms = $obj->subperms;
375 $whereforadd =
"id=".((int) $rid);
378 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND (subperms='lire' OR subperms='read'))";
380 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
384 if (!empty($allmodule)) {
385 if ($allmodule ==
'allmodules') {
386 $whereforadd =
'allmodules';
388 $whereforadd =
"module='".$this->db->escape($allmodule).
"'";
389 if (!empty($allperms)) {
390 $whereforadd .=
" AND perms='".$this->db->escape($allperms).
"'";
397 if (!empty($whereforadd)) {
400 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
401 $sql .=
" WHERE entity = ".((int) $entity);
402 if (!empty($whereforadd) && $whereforadd !=
'allmodules') {
403 $sql .=
" AND ".$whereforadd;
406 $result = $this->db->query($sql);
408 $num = $this->db->num_rows($result);
411 $obj = $this->db->fetch_object($result);
414 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_rights WHERE fk_usergroup = ".((int) $this->
id).
" AND fk_id=".((int) $nid).
" AND entity = ".((int) $entity);
415 if (!$this->db->query($sql)) {
418 $sql =
"INSERT INTO ".$this->db->prefix().
"usergroup_rights (entity, fk_usergroup, fk_id) VALUES (".((int) $entity).
", ".((int) $this->
id).
", ".((int) $nid).
")";
419 if (!$this->db->query($sql)) {
431 $langs->load(
"other");
432 $this->context = array(
'audit' => $langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
435 $result = $this->
call_trigger(
'USERGROUP_MODIFY', $user);
444 $this->db->rollback();
462 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0)
464 global $conf, $user, $langs;
469 $entity = (!empty($entity) ? $entity : $conf->entity);
474 $module = $perms = $subperms =
'';
478 $sql =
"SELECT module, perms, subperms";
479 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
480 $sql .=
" WHERE id = ".((int) $rid);
481 $sql .=
" AND entity = ".((int) $entity);
483 $result = $this->db->query($sql);
485 $obj = $this->db->fetch_object($result);
487 $module = $obj->module;
488 $perms = $obj->perms;
489 $subperms = $obj->subperms;
497 $wherefordel =
"id = ".((int) $rid);
499 if ($subperms ==
'lire' || $subperms ==
'read') {
500 $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND subperms IS NOT NULL)";
502 if ($perms ==
'lire' || $perms ==
'read') {
503 $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
511 if (!empty($allmodule)) {
512 if ($allmodule ==
'allmodules') {
513 $wherefordel =
'allmodules';
515 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
516 if (!empty($allperms)) {
517 $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
524 if (!empty($wherefordel)) {
527 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
528 $sql .=
" WHERE entity = ".((int) $entity);
529 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
530 $sql .=
" AND ".$wherefordel;
533 $result = $this->db->query($sql);
535 $num = $this->db->num_rows($result);
540 $obj = $this->db->fetch_object($result);
545 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_rights";
546 $sql .=
" WHERE fk_usergroup = $this->id AND fk_id=".((int) $nid);
547 $sql .=
" AND entity = ".((int) $entity);
548 if (!$this->db->query($sql)) {
560 $langs->load(
"other");
561 $this->context = array(
'audit' => $langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
564 $result = $this->
call_trigger(
'USERGROUP_MODIFY', $user);
573 $this->db->rollback();
606 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
611 if (!empty($this->all_permissions_are_loaded)) {
617 $sql =
"SELECT r.module, r.perms, r.subperms ";
618 $sql .=
" FROM ".$this->db->prefix().
"usergroup_rights as u, ".$this->db->prefix().
"rights_def as r";
619 $sql .=
" WHERE r.id = u.fk_id";
620 $sql .=
" AND r.entity = ".((int) $conf->entity);
621 $sql .=
" AND u.entity = ".((int) $conf->entity);
622 $sql .=
" AND u.fk_usergroup = ".((int) $this->
id);
623 $sql .=
" AND r.perms IS NOT NULL";
625 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
628 dol_syslog(get_class($this).
'::getrights', LOG_DEBUG);
629 $resql = $this->db->query($sql);
631 $num = $this->db->num_rows($resql);
634 $obj = $this->db->fetch_object($resql);
637 $module = $obj->module;
638 $perms = $obj->perms;
639 $subperms = $obj->subperms;
642 if (!isset($this->rights)) {
645 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
646 $this->rights->$module =
new stdClass();
649 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
650 $this->rights->$module->$perms =
new stdClass();
652 if (empty($this->rights->$module->$perms->$subperms)) {
655 $this->rights->$module->$perms->$subperms = 1;
657 if (empty($this->rights->$module->$perms)) {
660 $this->rights->$module->$perms = 1;
667 $this->db->free($resql);
670 if ($moduletag ==
'') {
673 $this->all_permissions_are_loaded = 1;
676 $this->_tab_loaded[$moduletag] = 1;
688 public function delete(
User $user)
704 if (!empty($this->
name)) {
705 $this->nom = $this->name;
708 if (!isset($this->entity)) {
709 $this->entity = $conf->entity;
725 if (!empty($this->
name)) {
726 $this->nom = $this->name;
742 public function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0)
745 $lastname = $this->lastname;
746 $firstname = $this->firstname;
747 if (empty($lastname)) {
748 $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 :
'')))));
752 if (!empty($option) && !empty($this->civility_code)) {
753 if ($langs->transnoentitiesnoconv(
"Civility".$this->civility_code) !=
"Civility".$this->civility_code) {
754 $ret .= $langs->transnoentitiesnoconv(
"Civility".$this->civility_code).
' ';
756 $ret .= $this->civility_code.
' ';
788 $langs->load(
'users');
800 global $conf, $langs, $menumanager;
802 $option = $params[
'option'] ??
'';
806 $langs->load(
"users");
807 return [
'optimize' => $langs->trans(
"ShowGroup")];
809 $datas[
'divopen'] =
'<div class="centpercent">';
810 $datas[
'picto'] =
img_picto(
'',
'group').
' <u>'.$langs->trans(
"Group").
'</u><br>';
811 $datas[
'name'] =
'<b>'.$langs->trans(
'Name').
':</b> '.$this->name;
812 $datas[
'description'] =
'<br><b>'.$langs->trans(
"Description").
':</b> '.$this->note;
813 $datas[
'divclose'] =
'</div>';
829 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
831 global $langs, $conf, $db, $hookmanager;
840 'objecttype' => $this->element,
843 $classfortooltip =
'classfortooltip';
846 $classfortooltip =
'classforajaxtooltip';
847 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
853 if ($option ==
'permissions') {
854 $url = DOL_URL_ROOT.
'/user/group/perms.php?id='.$this->id;
856 $url = DOL_URL_ROOT.
'/user/group/card.php?id='.$this->id;
859 if ($option !=
'nolink') {
861 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
862 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
863 $add_save_lastsearch_values = 1;
865 if ($add_save_lastsearch_values) {
866 $url .=
'&save_lastsearch_values=1';
871 if (empty($notooltip)) {
873 $langs->load(
"users");
874 $label = $langs->trans(
"ShowGroup");
875 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1, 1).
'"';
877 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
878 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
881 $linkstart =
'<a href="'.$url.
'"';
882 $linkstart .= $linkclose.
'>';
885 $result = $linkstart;
887 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
889 if ($withpicto != 2) {
890 $result .= $this->name;
895 $hookmanager->initHooks(array(
'groupdao'));
896 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
897 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
899 $result = $hookmanager->resPrint;
901 $result .= $hookmanager->resPrint;
962 $valueofldapfield = array();
963 foreach ($this->members as $key => $val) {
964 $muser =
new User($this->db);
965 $muser->fetch($val->id);
966 $info2 = $muser->_load_ldap_info();
967 $valueofldapfield[] = $muser->_load_ldap_dn($info2);
969 $info[
getDolGlobalString(
'LDAP_GROUP_FIELD_GROUPMEMBERS')] = (!empty($valueofldapfield) ? $valueofldapfield :
'');
987 global $conf, $user, $langs;
991 $this->
ref =
'SPECIMEN';
994 $this->
name =
'DOLIBARR GROUP SPECIMEN';
995 $this->note =
'This is a note';
996 $this->datec = time();
1000 $this->members = array(
1018 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
1020 global $conf, $user, $langs;
1022 $langs->load(
"user");
1033 $modelpath =
"core/modules/usergroup/doc/";
1035 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1049 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1051 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1052 $return .=
'<div class="info-box info-box-sm">';
1053 $return .=
'<span class="info-box-icon bg-infobox-action">';
1055 $return .=
'</span>';
1056 $return .=
'<div class="info-box-content">';
1057 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1058 if ($selected >= 0) {
1059 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1061 if (property_exists($this,
'members')) {
1062 $return .=
'<br><span class="info-box-status opacitymedium">'.(empty($this->nb_users) ? 0 : $this->nb_users).
' '.$langs->trans(
'Users').
'</span>';
1064 if (property_exists($this,
'nb_rights')) {
1065 $return .=
'<br><div class="info-box-status margintoponly opacitymedium">'.$langs->trans(
'NbOfPermissions').
' : '.(empty($this->nb_rights) ? 0 : $this->nb_rights).
'</div>';
1067 $return .=
'</div>';
1068 $return .=
'</div>';
1069 $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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
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.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
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.
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.