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';
84 public $usergroup_entity;
101 public $members = array();
121 private $_tab_loaded = array();
126 public $all_permissions_are_loaded;
128 public $fields = array(
129 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'index' => 1,
'position' => 1,
'comment' =>
'Id'),
130 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'enabled' => 1,
'visible' => 0,
'notnull' => 1,
'default' =>
'1',
'index' => 1,
'position' => 5),
131 'nom' => array(
'type' =>
'varchar(180)',
'label' =>
'Name',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 10,
'searchall' => 1,
'comment' =>
'Group name'),
132 'note' => array(
'type' =>
'html',
'label' =>
'Description',
'enabled' => 1,
'visible' => 1,
'position' => 20,
'notnull' => -1,
'searchall' => 1),
133 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -2,
'position' => 50,
'notnull' => 1,),
134 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -2,
'position' => 60,
'notnull' => 1,),
135 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'ModelPDF',
'enabled' => 1,
'visible' => 0,
'position' => 100),
141 public $fk_element =
'fk_usergroup';
146 protected $childtables = array();
151 protected $childtablesoncascade = array(
'usergroup_rights',
'usergroup_user');
156 public $isextrafieldmanaged = 1;
168 $this->ismultientitymanaged = 1;
169 $this->nb_rights = 0;
181 public function fetch($id = 0, $groupname =
'', $load_members =
false)
183 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
184 if (!empty($groupname)) {
185 $result = $this->
fetchCommon(0,
'',
' AND nom = \''.$this->db->escape($groupname).
'\'');
190 $this->
name = $this->nom;
200 $this->error = $this->db->lasterror();
219 $sql =
"SELECT g.rowid, ug.entity as usergroup_entity";
220 $sql .=
" FROM ".$this->db->prefix().
"usergroup as g,";
221 $sql .=
" ".$this->db->prefix().
"usergroup_user as ug";
222 $sql .=
" WHERE ug.fk_usergroup = g.rowid";
223 $sql .=
" AND ug.fk_user = ".((int) $userid);
224 if (isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && !$user->entity) {
225 $sql .=
" AND g.entity IS NOT NULL";
227 $sql .=
" AND g.entity IN (0,".$conf->entity.
")";
229 $sql .=
" ORDER BY g.nom";
231 dol_syslog(get_class($this).
"::listGroupsForUser", LOG_DEBUG);
232 $result = $this->db->query($sql);
234 while ($obj = $this->db->fetch_object($result)) {
235 if (!array_key_exists($obj->rowid, $ret)) {
237 $newgroup->fetch($obj->rowid,
'', $load_members);
238 $ret[$obj->rowid] = $newgroup;
240 if (!is_array($ret[$obj->rowid]->usergroup_entity)) {
241 $ret[$obj->rowid]->usergroup_entity = array();
244 $ret[$obj->rowid]->usergroup_entity[] = (int) $obj->usergroup_entity;
247 $this->db->free($result);
251 $this->error = $this->db->lasterror();
269 $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";
270 if (!empty($this->
id)) {
271 $sql .=
", ug.entity as usergroup_entity";
273 $sql .=
" FROM ".$this->db->prefix().
"user as u";
274 if (!empty($this->
id)) {
275 $sql .=
", ".$this->db->prefix().
"usergroup_user as ug";
277 $sql .=
" WHERE 1 = 1";
278 if (!empty($this->
id)) {
279 $sql .=
" AND ug.fk_user = u.rowid";
281 if (!empty($this->
id)) {
282 $sql .=
" AND ug.fk_usergroup = ".((int) $this->
id);
284 if (isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && !$user->entity) {
285 $sql .=
" AND u.entity IS NOT NULL";
287 $sql .=
" AND u.entity IN (0,".$conf->entity.
")";
289 if (!empty($excludefilter)) {
290 $sql .=
' AND ('.$excludefilter.
')';
293 dol_syslog(get_class($this).
"::listUsersForGroup", LOG_DEBUG);
294 $resql = $this->db->query($sql);
297 while ($obj = $this->db->fetch_object($resql)) {
298 if (!array_key_exists($obj->rowid, $ret)) {
300 $newuser =
new User($this->db);
302 $newuser->id = $obj->rowid;
303 $newuser->login = $obj->login;
304 $newuser->photo = $obj->photo;
305 $newuser->lastname = $obj->lastname;
306 $newuser->firstname = $obj->firstname;
307 $newuser->email = $obj->email;
308 $newuser->socid = $obj->fk_soc;
309 $newuser->entity = $obj->entity;
310 $newuser->employee = $obj->employee;
311 $newuser->status = $obj->status;
313 $ret[$obj->rowid] = $newuser;
315 $ret[$obj->rowid] = $obj->rowid;
318 if ($mode != 1 && !empty($obj->usergroup_entity)) {
320 if (!is_array($ret[$obj->rowid]->usergroup_entity)) {
321 $ret[$obj->rowid]->usergroup_entity = array();
323 $ret[$obj->rowid]->usergroup_entity[] = (int) $obj->usergroup_entity;
327 $this->db->free($resql);
331 $this->error = $this->db->lasterror();
345 public function addrights($rid, $allmodule =
'', $allperms =
'', $entity = 0)
347 global
$conf, $user, $langs;
349 $entity = (!empty($entity) ? $entity :
$conf->entity);
351 dol_syslog(get_class($this).
"::addrights $rid, $allmodule, $allperms, $entity");
358 $module = $perms = $subperms =
'';
362 $sql =
"SELECT module, perms, subperms";
363 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
364 $sql .=
" WHERE id = ".((int) $rid);
365 $sql .=
" AND entity = ".((int) $entity);
367 $result = $this->db->query($sql);
369 $obj = $this->db->fetch_object($result);
371 $module = $obj->module;
372 $perms = $obj->perms;
373 $subperms = $obj->subperms;
381 $whereforadd =
"id=".((int) $rid);
384 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND (subperms='lire' OR subperms='read'))";
386 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
390 if (!empty($allmodule)) {
391 if ($allmodule ==
'allmodules') {
392 $whereforadd =
'allmodules';
394 $whereforadd =
"module='".$this->db->escape($allmodule).
"'";
395 if (!empty($allperms)) {
396 $whereforadd .=
" AND perms='".$this->db->escape($allperms).
"'";
403 if (!empty($whereforadd)) {
406 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
407 $sql .=
" WHERE entity = ".((int) $entity);
408 if (!empty($whereforadd) && $whereforadd !=
'allmodules') {
409 $sql .=
" AND ".$whereforadd;
412 $result = $this->db->query($sql);
414 $num = $this->db->num_rows($result);
417 $obj = $this->db->fetch_object($result);
420 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_rights WHERE fk_usergroup = ".((int) $this->
id).
" AND fk_id=".((int) $nid).
" AND entity = ".((int) $entity);
421 if (!$this->db->query($sql)) {
424 $sql =
"INSERT INTO ".$this->db->prefix().
"usergroup_rights (entity, fk_usergroup, fk_id) VALUES (".((int) $entity).
", ".((int) $this->
id).
", ".((int) $nid).
")";
425 if (!$this->db->query($sql)) {
437 $langs->load(
"other");
438 $this->context = array(
'audit' => $langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
441 $result = $this->
call_trigger(
'USERGROUP_MODIFY', $user);
450 $this->db->rollback();
468 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0)
470 global
$conf, $user, $langs;
475 $entity = (!empty($entity) ? $entity :
$conf->entity);
480 $module = $perms = $subperms =
'';
484 $sql =
"SELECT module, perms, subperms";
485 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
486 $sql .=
" WHERE id = ".((int) $rid);
487 $sql .=
" AND entity = ".((int) $entity);
489 $result = $this->db->query($sql);
491 $obj = $this->db->fetch_object($result);
493 $module = $obj->module;
494 $perms = $obj->perms;
495 $subperms = $obj->subperms;
503 $wherefordel =
"id = ".((int) $rid);
505 if ($subperms ==
'lire' || $subperms ==
'read') {
506 $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND subperms IS NOT NULL)";
508 if ($perms ==
'lire' || $perms ==
'read') {
509 $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
517 if (!empty($allmodule)) {
518 if ($allmodule ==
'allmodules') {
519 $wherefordel =
'allmodules';
521 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
522 if (!empty($allperms)) {
523 $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
530 if (!empty($wherefordel)) {
533 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
534 $sql .=
" WHERE entity = ".((int) $entity);
535 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
536 $sql .=
" AND ".$wherefordel;
539 $result = $this->db->query($sql);
541 $num = $this->db->num_rows($result);
546 $obj = $this->db->fetch_object($result);
551 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_rights";
552 $sql .=
" WHERE fk_usergroup = $this->id AND fk_id=".((int) $nid);
553 $sql .=
" AND entity = ".((int) $entity);
554 if (!$this->db->query($sql)) {
566 $langs->load(
"other");
567 $this->context = array(
'audit' => $langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
570 $result = $this->
call_trigger(
'USERGROUP_MODIFY', $user);
579 $this->db->rollback();
612 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
617 if (!empty($this->all_permissions_are_loaded)) {
623 $sql =
"SELECT r.module, r.perms, r.subperms ";
624 $sql .=
" FROM ".$this->db->prefix().
"usergroup_rights as u, ".$this->db->prefix().
"rights_def as r";
625 $sql .=
" WHERE r.id = u.fk_id";
626 $sql .=
" AND r.entity = ".((int)
$conf->entity);
627 $sql .=
" AND u.entity = ".((int)
$conf->entity);
628 $sql .=
" AND u.fk_usergroup = ".((int) $this->
id);
629 $sql .=
" AND r.perms IS NOT NULL";
631 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
634 dol_syslog(get_class($this).
'::getrights', LOG_DEBUG);
635 $resql = $this->db->query($sql);
637 $num = $this->db->num_rows($resql);
640 $obj = $this->db->fetch_object($resql);
643 $module = $obj->module;
644 $perms = $obj->perms;
645 $subperms = $obj->subperms;
648 if (!isset($this->rights)) {
651 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
652 $this->rights->$module =
new stdClass();
655 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
656 $this->rights->$module->$perms =
new stdClass();
658 if (empty($this->rights->$module->$perms->$subperms)) {
661 $this->rights->$module->$perms->$subperms = 1;
663 if (empty($this->rights->$module->$perms)) {
666 $this->rights->$module->$perms = 1;
673 $this->db->free($resql);
676 if ($moduletag ==
'') {
679 $this->all_permissions_are_loaded = 1;
682 $this->_tab_loaded[$moduletag] = 1;
694 public function delete(
User $user)
710 if (!empty($this->
name)) {
711 $this->nom = $this->name;
714 if (!isset($this->entity)) {
715 $this->entity =
$conf->entity;
731 if (!empty($this->
name)) {
732 $this->nom = $this->name;
748 public function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0)
751 $lastname = $this->lastname;
752 $firstname = $this->firstname;
753 if (empty($lastname)) {
754 $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 :
'')))));
758 if (!empty($option) && !empty($this->civility_code)) {
759 if ($langs->transnoentitiesnoconv(
"Civility".$this->civility_code) !=
"Civility".$this->civility_code) {
760 $ret .= $langs->transnoentitiesnoconv(
"Civility".$this->civility_code).
' ';
762 $ret .= $this->civility_code.
' ';
794 $langs->load(
'users');
806 global
$conf, $langs, $menumanager;
808 $option = $params[
'option'] ??
'';
812 $langs->load(
"users");
813 return [
'optimize' => $langs->trans(
"ShowGroup")];
815 $datas[
'divopen'] =
'<div class="centpercent">';
816 $datas[
'picto'] =
img_picto(
'',
'group').
' <u>'.$langs->trans(
"Group").
'</u><br>';
817 $datas[
'name'] =
'<b>'.$langs->trans(
'Name').
':</b> '.$this->name;
818 $datas[
'description'] =
'<br><b>'.$langs->trans(
"Description").
':</b> '.$this->note;
819 $datas[
'divclose'] =
'</div>';
835 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
837 global $langs,
$conf, $db, $hookmanager;
846 'objecttype' => $this->element,
849 $classfortooltip =
'classfortooltip';
852 $classfortooltip =
'classforajaxtooltip';
853 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
859 if ($option ==
'permissions') {
860 $url = DOL_URL_ROOT.
'/user/group/perms.php?id='.$this->id;
862 $url = DOL_URL_ROOT.
'/user/group/card.php?id='.$this->id;
865 if ($option !=
'nolink') {
867 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
868 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
869 $add_save_lastsearch_values = 1;
871 if ($add_save_lastsearch_values) {
872 $url .=
'&save_lastsearch_values=1';
877 if (empty($notooltip)) {
879 $langs->load(
"users");
880 $label = $langs->trans(
"ShowGroup");
881 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1, 1).
'"';
883 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
884 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
887 $linkstart =
'<a href="'.$url.
'"';
888 $linkstart .= $linkclose.
'>';
891 $result = $linkstart;
893 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
895 if ($withpicto != 2) {
896 $result .= $this->name;
901 $hookmanager->initHooks(array(
'groupdao'));
902 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
903 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
905 $result = $hookmanager->resPrint;
907 $result .= $hookmanager->resPrint;
968 $valueofldapfield = array();
969 foreach ($this->members as $key => $val) {
970 $muser =
new User($this->db);
971 $muser->fetch($val->id);
972 $info2 = $muser->_load_ldap_info();
973 $valueofldapfield[] = $muser->_load_ldap_dn($info2);
975 $info[
getDolGlobalString(
'LDAP_GROUP_FIELD_GROUPMEMBERS')] = (!empty($valueofldapfield) ? $valueofldapfield :
'');
993 global
$conf, $user, $langs;
997 $this->
ref =
'SPECIMEN';
1000 $this->
name =
'DOLIBARR GROUP SPECIMEN';
1001 $this->note =
'This is a note';
1002 $this->datec = time();
1003 $this->tms = time();
1006 $this->members = array(
1024 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
1026 global
$conf, $user, $langs;
1028 $langs->load(
"user");
1039 $modelpath =
"core/modules/usergroup/doc/";
1041 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1055 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1057 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1058 $return .=
'<div class="info-box info-box-sm">';
1059 $return .=
'<span class="info-box-icon bg-infobox-action">';
1061 $return .=
'</span>';
1062 $return .=
'<div class="info-box-content">';
1063 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1064 if ($selected >= 0) {
1065 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1067 if (property_exists($this,
'members')) {
1068 $return .=
'<br><span class="info-box-status opacitymedium">'.(empty($this->nb_users) ? 0 : $this->nb_users).
' '.$langs->trans(
'Users').
'</span>';
1070 if (property_exists($this,
'nb_rights')) {
1071 $return .=
'<br><div class="info-box-status margintoponly opacitymedium">'.$langs->trans(
'NbOfPermissions').
' : '.(empty($this->nb_rights) ? 0 : $this->nb_rights).
'</div>';
1073 $return .=
'</div>';
1074 $return .=
'</div>';
1075 $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_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.
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.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
$conf db name
Only used if Module[ID]Name translation string is not found.