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');
165 $this->ismultientitymanaged = 1;
166 $this->nb_rights = 0;
178 public function fetch($id = 0, $groupname =
'', $load_members =
false)
180 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
181 if (!empty($groupname)) {
182 $result = $this->
fetchCommon(0,
'',
' AND nom = \''.$this->db->escape($groupname).
'\'');
187 $this->
name = $this->nom;
188 $this->note_private = $this->note;
198 $this->error = $this->db->lasterror();
217 $sql =
"SELECT g.rowid, ug.entity as usergroup_entity";
218 $sql .=
" FROM ".$this->db->prefix().
"usergroup as g,";
219 $sql .=
" ".$this->db->prefix().
"usergroup_user as ug";
220 $sql .=
" WHERE ug.fk_usergroup = g.rowid";
221 $sql .=
" AND ug.fk_user = ".((int) $userid);
222 if (
isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
223 $sql .=
" AND g.entity IS NOT NULL";
225 $sql .=
" AND g.entity IN (0,".$conf->entity.
")";
227 $sql .=
" ORDER BY g.nom";
229 dol_syslog(get_class($this).
"::listGroupsForUser", LOG_DEBUG);
230 $result = $this->db->query($sql);
232 while ($obj = $this->db->fetch_object($result)) {
233 if (!array_key_exists($obj->rowid, $ret)) {
235 $newgroup->fetch($obj->rowid,
'', $load_members);
236 $ret[$obj->rowid] = $newgroup;
238 if (!is_array($ret[$obj->rowid]->usergroup_entity)) {
239 $ret[$obj->rowid]->usergroup_entity = array();
242 $ret[$obj->rowid]->usergroup_entity[] = (int) $obj->usergroup_entity;
245 $this->db->free($result);
249 $this->error = $this->db->lasterror();
267 $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";
268 if (!empty($this->
id)) {
269 $sql .=
", ug.entity as usergroup_entity";
271 $sql .=
" FROM ".$this->db->prefix().
"user as u";
272 if (!empty($this->
id)) {
273 $sql .=
", ".$this->db->prefix().
"usergroup_user as ug";
275 $sql .=
" WHERE 1 = 1";
276 if (!empty($this->
id)) {
277 $sql .=
" AND ug.fk_user = u.rowid";
279 if (!empty($this->
id)) {
280 $sql .=
" AND ug.fk_usergroup = ".((int) $this->
id);
282 if (
isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
283 $sql .=
" AND u.entity IS NOT NULL";
285 $sql .=
" AND u.entity IN (0,".$conf->entity.
")";
287 if (!empty($excludefilter)) {
288 $sql .=
' AND ('.$excludefilter.
')';
291 dol_syslog(get_class($this).
"::listUsersForGroup", LOG_DEBUG);
292 $resql = $this->db->query($sql);
295 while ($obj = $this->db->fetch_object($resql)) {
296 if (!array_key_exists($obj->rowid, $ret)) {
298 $newuser =
new User($this->db);
300 $newuser->id = $obj->rowid;
301 $newuser->login = $obj->login;
302 $newuser->photo = $obj->photo;
303 $newuser->lastname = $obj->lastname;
304 $newuser->firstname = $obj->firstname;
305 $newuser->email = $obj->email;
306 $newuser->socid = $obj->fk_soc;
307 $newuser->entity = $obj->entity;
308 $newuser->employee = $obj->employee;
309 $newuser->status = $obj->status;
311 $ret[$obj->rowid] = $newuser;
313 $ret[$obj->rowid] = $obj->rowid;
316 if ($mode != 1 && !empty($obj->usergroup_entity)) {
318 if (!is_array($ret[$obj->rowid]->usergroup_entity)) {
319 $ret[$obj->rowid]->usergroup_entity = array();
321 $ret[$obj->rowid]->usergroup_entity[] = (int) $obj->usergroup_entity;
325 $this->db->free($resql);
329 $this->error = $this->db->lasterror();
343 public function addrights($rid, $allmodule =
'', $allperms =
'', $entity = 0)
345 global $conf, $user, $langs;
347 $entity = (!empty($entity) ? $entity : $conf->entity);
349 dol_syslog(get_class($this).
"::addrights $rid, $allmodule, $allperms, $entity");
356 $module = $perms = $subperms =
'';
360 $sql =
"SELECT module, perms, subperms";
361 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
362 $sql .=
" WHERE id = ".((int) $rid);
363 $sql .=
" AND entity = ".((int) $entity);
365 $result = $this->db->query($sql);
367 $obj = $this->db->fetch_object($result);
369 $module = $obj->module;
370 $perms = $obj->perms;
371 $subperms = $obj->subperms;
379 $whereforadd =
"id=".((int) $rid);
382 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND (subperms='lire' OR subperms='read'))";
384 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
388 if (!empty($allmodule)) {
389 if ($allmodule ==
'allmodules') {
390 $whereforadd =
'allmodules';
392 $whereforadd =
"module='".$this->db->escape($allmodule).
"'";
393 if (!empty($allperms)) {
394 $whereforadd .=
" AND perms='".$this->db->escape($allperms).
"'";
401 if (!empty($whereforadd)) {
404 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
405 $sql .=
" WHERE entity = ".((int) $entity);
406 if (!empty($whereforadd) && $whereforadd !=
'allmodules') {
407 $sql .=
" AND ".$whereforadd;
410 $result = $this->db->query($sql);
412 $num = $this->db->num_rows($result);
415 $obj = $this->db->fetch_object($result);
418 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_rights WHERE fk_usergroup = ".((int) $this->
id).
" AND fk_id=".((int) $nid).
" AND entity = ".((int) $entity);
419 if (!$this->db->query($sql)) {
422 $sql =
"INSERT INTO ".$this->db->prefix().
"usergroup_rights (entity, fk_usergroup, fk_id) VALUES (".((int) $entity).
", ".((int) $this->
id).
", ".((int) $nid).
")";
423 if (!$this->db->query($sql)) {
435 $langs->load(
"other");
436 $this->context = array(
'audit' => $langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
439 $result = $this->call_trigger(
'USERGROUP_MODIFY', $user);
448 $this->db->rollback();
466 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0)
468 global $conf, $user, $langs;
473 $entity = (!empty($entity) ? $entity : $conf->entity);
478 $module = $perms = $subperms =
'';
482 $sql =
"SELECT module, perms, subperms";
483 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
484 $sql .=
" WHERE id = ".((int) $rid);
485 $sql .=
" AND entity = ".((int) $entity);
487 $result = $this->db->query($sql);
489 $obj = $this->db->fetch_object($result);
491 $module = $obj->module;
492 $perms = $obj->perms;
493 $subperms = $obj->subperms;
501 $wherefordel =
"id = ".((int) $rid);
503 if ($subperms ==
'lire' || $subperms ==
'read') {
504 $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND subperms IS NOT NULL)";
506 if ($perms ==
'lire' || $perms ==
'read') {
507 $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
515 if (!empty($allmodule)) {
516 if ($allmodule ==
'allmodules') {
517 $wherefordel =
'allmodules';
519 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
520 if (!empty($allperms)) {
521 $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
528 if (!empty($wherefordel)) {
531 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
532 $sql .=
" WHERE entity = ".((int) $entity);
533 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
534 $sql .=
" AND ".$wherefordel;
537 $result = $this->db->query($sql);
539 $num = $this->db->num_rows($result);
544 $obj = $this->db->fetch_object($result);
549 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_rights";
550 $sql .=
" WHERE fk_usergroup = $this->id AND fk_id=".((int) $nid);
551 $sql .=
" AND entity = ".((int) $entity);
552 if (!$this->db->query($sql)) {
564 $langs->load(
"other");
565 $this->context = array(
'audit' => $langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
568 $result = $this->call_trigger(
'USERGROUP_MODIFY', $user);
577 $this->db->rollback();
610 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
615 if (!empty($this->all_permissions_are_loaded)) {
621 $sql =
"SELECT r.module, r.perms, r.subperms ";
622 $sql .=
" FROM ".$this->db->prefix().
"usergroup_rights as u, ".$this->db->prefix().
"rights_def as r";
623 $sql .=
" WHERE r.id = u.fk_id";
624 $sql .=
" AND r.entity = ".((int) $conf->entity);
625 $sql .=
" AND u.entity = ".((int) $conf->entity);
626 $sql .=
" AND u.fk_usergroup = ".((int) $this->
id);
627 $sql .=
" AND r.perms IS NOT NULL";
629 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
632 dol_syslog(get_class($this).
'::getrights', LOG_DEBUG);
633 $resql = $this->db->query($sql);
635 $num = $this->db->num_rows($resql);
638 $obj = $this->db->fetch_object($resql);
641 $module = $obj->module;
642 $perms = $obj->perms;
643 $subperms = $obj->subperms;
646 if (!isset($this->rights)) {
649 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
650 $this->rights->$module =
new stdClass();
653 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
654 $this->rights->$module->$perms =
new stdClass();
656 if (empty($this->rights->$module->$perms->$subperms)) {
659 $this->rights->$module->$perms->$subperms = 1;
661 if (empty($this->rights->$module->$perms)) {
664 $this->rights->$module->$perms = 1;
671 $this->db->free($resql);
674 if ($moduletag ==
'') {
677 $this->all_permissions_are_loaded = 1;
680 $this->_tab_loaded[$moduletag] = 1;
692 public function delete(
User $user)
708 if (!empty($this->
name)) {
709 $this->nom = $this->name;
711 if (!empty($this->note_private)) {
712 $this->note = $this->note_private;
715 if (!isset($this->entity)) {
716 $this->entity = $conf->entity;
732 if (!empty($this->
name)) {
733 $this->nom = $this->name;
736 if (!empty($this->note_private)) {
737 $this->note = $this->note_private;
753 public function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0)
756 $lastname = $this->lastname;
757 $firstname = $this->firstname;
758 if (empty($lastname)) {
759 $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 :
'')))));
763 if (!empty($option) && !empty($this->civility_code)) {
764 if ($langs->transnoentitiesnoconv(
"Civility".$this->civility_code) !=
"Civility".$this->civility_code) {
765 $ret .= $langs->transnoentitiesnoconv(
"Civility".$this->civility_code).
' ';
767 $ret .= $this->civility_code.
' ';
799 $langs->load(
'users');
811 global $conf, $langs, $menumanager;
813 $option = $params[
'option'] ??
'';
817 $langs->load(
"users");
818 return [
'optimize' => $langs->trans(
"ShowGroup")];
820 $datas[
'divopen'] =
'<div class="centpercent">';
821 $datas[
'picto'] =
img_picto(
'',
'group').
' <u>'.$langs->trans(
"Group").
'</u><br>';
822 $datas[
'name'] =
'<b>'.$langs->trans(
'Name').
':</b> '.$this->name;
823 $datas[
'description'] =
'<br><b>'.$langs->trans(
"Description").
':</b> '.$this->note;
824 $datas[
'divclose'] =
'</div>';
840 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
842 global $langs, $conf, $db, $hookmanager;
851 'objecttype' => $this->element,
854 $classfortooltip =
'classfortooltip';
857 $classfortooltip =
'classforajaxtooltip';
858 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
864 if ($option ==
'permissions') {
865 $baseurl = DOL_URL_ROOT.
'/user/group/perms.php';
867 $baseurl = DOL_URL_ROOT.
'/user/group/card.php';
869 $query = [
'id' => $this->id];
871 if ($option !=
'nolink') {
873 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
874 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
875 $add_save_lastsearch_values = 1;
877 if ($add_save_lastsearch_values) {
878 $query = array_merge($query, [
'save_lastsearch_values' => 1]);
884 if (empty($notooltip)) {
886 $langs->load(
"users");
887 $label = $langs->trans(
"ShowGroup");
888 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1, 1).
'"';
890 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
891 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
894 $linkstart =
'<a href="'.$url.
'"';
895 $linkstart .= $linkclose.
'>';
898 $result = $linkstart;
900 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
902 if ($withpicto != 2) {
903 $result .= $this->name;
908 $hookmanager->initHooks(array(
'groupdao'));
909 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
910 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
912 $result = $hookmanager->resPrint;
914 $result .= $hookmanager->resPrint;
975 $valueofldapfield = array();
976 foreach ($this->members as $key => $val) {
977 $muser =
new User($this->db);
978 $muser->fetch($val->id);
979 $info2 = $muser->_load_ldap_info();
980 $valueofldapfield[] = $muser->_load_ldap_dn($info2);
982 $info[
getDolGlobalString(
'LDAP_GROUP_FIELD_GROUPMEMBERS')] = (!empty($valueofldapfield) ? $valueofldapfield :
'');
1000 global $conf, $user, $langs;
1004 $this->
ref =
'SPECIMEN';
1005 $this->specimen = 1;
1007 $this->
name =
'DOLIBARR GROUP SPECIMEN';
1008 $this->note =
'This is a note';
1009 $this->datec = time();
1010 $this->tms = time();
1013 $this->members = array(
1031 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
1033 global $conf, $user, $langs;
1035 $langs->load(
"user");
1046 $modelpath =
"core/modules/usergroup/doc/";
1048 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1062 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1064 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1065 $return .=
'<div class="info-box info-box-sm">';
1066 $return .=
'<span class="info-box-icon bg-infobox-action">';
1068 $return .=
'</span>';
1069 $return .=
'<div class="info-box-content">';
1070 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1071 if ($selected >= 0) {
1072 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1074 if (property_exists($this,
'members')) {
1075 $return .=
'<br><span class="info-box-status opacitymedium">'.(empty($this->nb_users) ? 0 : $this->nb_users).
' '.$langs->trans(
'Users').
'</span>';
1077 if (property_exists($this,
'nb_rights')) {
1078 $return .=
'<br><div class="info-box-status margintoponly opacitymedium">'.$langs->trans(
'NbOfPermissions').
' : '.(empty($this->nb_rights) ? 0 : $this->nb_rights).
'</div>';
1080 $return .=
'</div>';
1081 $return .=
'</div>';
1082 $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.