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();
105 private $_tab_loaded = array();
110 public $all_permissions_are_loaded;
114 public $fields = array(
115 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'index' => 1,
'position' => 1,
'comment' =>
'Id'),
116 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'enabled' => 1,
'visible' => 0,
'notnull' => 1,
'default' =>
'1',
'index' => 1,
'position' => 5),
117 'nom' => array(
'type' =>
'varchar(180)',
'label' =>
'Name',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 10,
'searchall' => 1,
'comment' =>
'Group name'),
118 'note' => array(
'type' =>
'html',
'label' =>
'Description',
'enabled' => 1,
'visible' => 1,
'position' => 20,
'notnull' => -1,
'searchall' => 1),
119 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -2,
'position' => 50,
'notnull' => 1,),
120 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -2,
'position' => 60,
'notnull' => 1,),
121 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'ModelPDF',
'enabled' => 1,
'visible' => 0,
'position' => 100),
127 public $fk_element =
'fk_usergroup';
132 protected $childtables = array();
137 protected $childtablesoncascade = array(
'usergroup_rights',
'usergroup_user');
149 $this->ismultientitymanaged = 1;
150 $this->nb_rights = 0;
162 public function fetch($id = 0, $groupname =
'', $load_members =
false)
166 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
167 if (!empty($groupname)) {
168 $result = $this->
fetchCommon(0,
'',
' AND nom = \''.$this->db->escape($groupname).
'\'');
173 $this->
name = $this->nom;
182 $this->error = $this->db->lasterror();
201 $sql =
"SELECT g.rowid, ug.entity as usergroup_entity";
202 $sql .=
" FROM ".$this->db->prefix().
"usergroup as g,";
203 $sql .=
" ".$this->db->prefix().
"usergroup_user as ug";
204 $sql .=
" WHERE ug.fk_usergroup = g.rowid";
205 $sql .=
" AND ug.fk_user = ".((int) $userid);
206 if (isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
207 $sql .=
" AND g.entity IS NOT NULL";
209 $sql .=
" AND g.entity IN (0,".$conf->entity.
")";
211 $sql .=
" ORDER BY g.nom";
213 dol_syslog(get_class($this).
"::listGroupsForUser", LOG_DEBUG);
214 $result = $this->db->query($sql);
216 while ($obj = $this->db->fetch_object($result)) {
217 if (!array_key_exists($obj->rowid, $ret)) {
219 $newgroup->fetch($obj->rowid,
'', $load_members);
220 $ret[$obj->rowid] = $newgroup;
222 if (!is_array($ret[$obj->rowid]->usergroup_entity)) {
223 $ret[$obj->rowid]->usergroup_entity = array();
226 $ret[$obj->rowid]->usergroup_entity[] = (int) $obj->usergroup_entity;
229 $this->db->free($result);
233 $this->error = $this->db->lasterror();
251 $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";
252 if (!empty($this->
id)) {
253 $sql .=
", ug.entity as usergroup_entity";
255 $sql .=
" FROM ".$this->db->prefix().
"user as u";
256 if (!empty($this->
id)) {
257 $sql .=
", ".$this->db->prefix().
"usergroup_user as ug";
259 $sql .=
" WHERE 1 = 1";
260 if (!empty($this->
id)) {
261 $sql .=
" AND ug.fk_user = u.rowid";
263 if (!empty($this->
id)) {
264 $sql .=
" AND ug.fk_usergroup = ".((int) $this->
id);
266 if (isModEnabled(
'multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
267 $sql .=
" AND u.entity IS NOT NULL";
269 $sql .=
" AND u.entity IN (0,".$conf->entity.
")";
271 if (!empty($excludefilter)) {
272 $sql .=
' AND ('.$excludefilter.
')';
275 dol_syslog(get_class($this).
"::listUsersForGroup", LOG_DEBUG);
276 $resql = $this->db->query($sql);
279 while ($obj = $this->db->fetch_object($resql)) {
280 if (!array_key_exists($obj->rowid, $ret)) {
282 $newuser =
new User($this->db);
284 $newuser->id = $obj->rowid;
285 $newuser->login = $obj->login;
286 $newuser->photo = $obj->photo;
287 $newuser->lastname = $obj->lastname;
288 $newuser->firstname = $obj->firstname;
289 $newuser->email = $obj->email;
290 $newuser->socid = $obj->fk_soc;
291 $newuser->entity = $obj->entity;
292 $newuser->employee = $obj->employee;
293 $newuser->status = $obj->status;
295 $ret[$obj->rowid] = $newuser;
297 $ret[$obj->rowid] = $obj->rowid;
300 if ($mode != 1 && !empty($obj->usergroup_entity)) {
302 if (!is_array($ret[$obj->rowid]->usergroup_entity)) {
303 $ret[$obj->rowid]->usergroup_entity = array();
305 $ret[$obj->rowid]->usergroup_entity[] = (int) $obj->usergroup_entity;
309 $this->db->free($resql);
313 $this->error = $this->db->lasterror();
327 public function addrights($rid, $allmodule =
'', $allperms =
'', $entity = 0)
329 global $conf, $user, $langs;
331 $entity = (!empty($entity) ? $entity : $conf->entity);
333 dol_syslog(get_class($this).
"::addrights $rid, $allmodule, $allperms, $entity");
340 $module = $perms = $subperms =
'';
344 $sql =
"SELECT module, perms, subperms";
345 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
346 $sql .=
" WHERE id = ".((int) $rid);
347 $sql .=
" AND entity = ".((int) $entity);
349 $result = $this->db->query($sql);
351 $obj = $this->db->fetch_object($result);
353 $module = $obj->module;
354 $perms = $obj->perms;
355 $subperms = $obj->subperms;
363 $whereforadd =
"id=".((int) $rid);
366 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND (subperms='lire' OR subperms='read'))";
368 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
372 if (!empty($allmodule)) {
373 if ($allmodule ==
'allmodules') {
374 $whereforadd =
'allmodules';
376 $whereforadd =
"module='".$this->db->escape($allmodule).
"'";
377 if (!empty($allperms)) {
378 $whereforadd .=
" AND perms='".$this->db->escape($allperms).
"'";
385 if (!empty($whereforadd)) {
388 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
389 $sql .=
" WHERE entity = ".((int) $entity);
390 if (!empty($whereforadd) && $whereforadd !=
'allmodules') {
391 $sql .=
" AND ".$whereforadd;
394 $result = $this->db->query($sql);
396 $num = $this->db->num_rows($result);
399 $obj = $this->db->fetch_object($result);
402 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_rights WHERE fk_usergroup = ".((int) $this->
id).
" AND fk_id=".((int) $nid).
" AND entity = ".((int) $entity);
403 if (!$this->db->query($sql)) {
406 $sql =
"INSERT INTO ".$this->db->prefix().
"usergroup_rights (entity, fk_usergroup, fk_id) VALUES (".((int) $entity).
", ".((int) $this->
id).
", ".((int) $nid).
")";
407 if (!$this->db->query($sql)) {
419 $langs->load(
"other");
420 $this->context = array(
'audit' => $langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
423 $result = $this->
call_trigger(
'USERGROUP_MODIFY', $user);
432 $this->db->rollback();
450 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0)
452 global $conf, $user, $langs;
457 $entity = (!empty($entity) ? $entity : $conf->entity);
462 $module = $perms = $subperms =
'';
466 $sql =
"SELECT module, perms, subperms";
467 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
468 $sql .=
" WHERE id = ".((int) $rid);
469 $sql .=
" AND entity = ".((int) $entity);
471 $result = $this->db->query($sql);
473 $obj = $this->db->fetch_object($result);
475 $module = $obj->module;
476 $perms = $obj->perms;
477 $subperms = $obj->subperms;
485 $wherefordel =
"id = ".((int) $rid);
487 if ($subperms ==
'lire' || $subperms ==
'read') {
488 $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND subperms IS NOT NULL)";
490 if ($perms ==
'lire' || $perms ==
'read') {
491 $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
499 if (!empty($allmodule)) {
500 if ($allmodule ==
'allmodules') {
501 $wherefordel =
'allmodules';
503 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
504 if (!empty($allperms)) {
505 $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
512 if (!empty($wherefordel)) {
515 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
516 $sql .=
" WHERE entity = ".((int) $entity);
517 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
518 $sql .=
" AND ".$wherefordel;
521 $result = $this->db->query($sql);
523 $num = $this->db->num_rows($result);
528 $obj = $this->db->fetch_object($result);
533 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_rights";
534 $sql .=
" WHERE fk_usergroup = $this->id AND fk_id=".((int) $nid);
535 $sql .=
" AND entity = ".((int) $entity);
536 if (!$this->db->query($sql)) {
548 $langs->load(
"other");
549 $this->context = array(
'audit' => $langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
552 $result = $this->
call_trigger(
'USERGROUP_MODIFY', $user);
561 $this->db->rollback();
580 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
585 if (!empty($this->all_permissions_are_loaded)) {
593 $sql =
"SELECT r.module, r.perms, r.subperms ";
594 $sql .=
" FROM ".$this->db->prefix().
"usergroup_rights as u, ".$this->db->prefix().
"rights_def as r";
595 $sql .=
" WHERE r.id = u.fk_id";
596 $sql .=
" AND r.entity = ".((int) $conf->entity);
597 $sql .=
" AND u.entity = ".((int) $conf->entity);
598 $sql .=
" AND u.fk_usergroup = ".((int) $this->
id);
599 $sql .=
" AND r.perms IS NOT NULL";
601 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
604 dol_syslog(get_class($this).
'::getrights', LOG_DEBUG);
605 $resql = $this->db->query($sql);
607 $num = $this->db->num_rows($resql);
610 $obj = $this->db->fetch_object($resql);
613 $module = $obj->module;
614 $perms = $obj->perms;
615 $subperms = $obj->subperms;
618 if (!isset($this->rights)) {
621 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
622 $this->rights->$module =
new stdClass();
625 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
626 $this->rights->$module->$perms =
new stdClass();
628 if (empty($this->rights->$module->$perms->$subperms)) {
631 $this->rights->$module->$perms->$subperms = 1;
633 if (empty($this->rights->$module->$perms)) {
636 $this->rights->$module->$perms = 1;
643 $this->db->free($resql);
646 if ($moduletag ==
'') {
649 $this->all_permissions_are_loaded = 1;
652 $this->_tab_loaded[$moduletag] = 1;
664 public function delete(
User $user)
680 if (!empty($this->
name)) {
681 $this->nom = $this->name;
684 if (!isset($this->entity)) {
685 $this->entity = $conf->entity;
701 if (!empty($this->
name)) {
702 $this->nom = $this->name;
718 public function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0)
721 $lastname = $this->lastname;
722 $firstname = $this->firstname;
723 if (empty($lastname)) {
724 $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 :
'')))));
728 if (!empty($option) && !empty($this->civility_code)) {
729 if ($langs->transnoentitiesnoconv(
"Civility".$this->civility_code) !=
"Civility".$this->civility_code) {
730 $ret .= $langs->transnoentitiesnoconv(
"Civility".$this->civility_code).
' ';
732 $ret .= $this->civility_code.
' ';
764 $langs->load(
'users');
777 global $conf, $langs, $menumanager;
779 $option = $params[
'option'] ??
'';
783 $langs->load(
"users");
784 return [
'optimize' => $langs->trans(
"ShowGroup")];
786 $datas[
'divopen'] =
'<div class="centpercent">';
787 $datas[
'picto'] =
img_picto(
'',
'group').
' <u>'.$langs->trans(
"Group").
'</u><br>';
788 $datas[
'name'] =
'<b>'.$langs->trans(
'Name').
':</b> '.$this->name;
789 $datas[
'description'] =
'<br><b>'.$langs->trans(
"Description").
':</b> '.$this->note;
790 $datas[
'divclose'] =
'</div>';
806 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
808 global $langs, $conf, $db, $hookmanager;
817 'objecttype' => $this->element,
820 $classfortooltip =
'classfortooltip';
823 $classfortooltip =
'classforajaxtooltip';
824 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
830 if ($option ==
'permissions') {
831 $url = DOL_URL_ROOT.
'/user/group/perms.php?id='.$this->id;
833 $url = DOL_URL_ROOT.
'/user/group/card.php?id='.$this->id;
836 if ($option !=
'nolink') {
838 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
839 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
840 $add_save_lastsearch_values = 1;
842 if ($add_save_lastsearch_values) {
843 $url .=
'&save_lastsearch_values=1';
848 if (empty($notooltip)) {
850 $langs->load(
"users");
851 $label = $langs->trans(
"ShowGroup");
852 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1, 1).
'"';
854 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
855 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
858 $linkstart =
'<a href="'.$url.
'"';
859 $linkstart .= $linkclose.
'>';
862 $result = $linkstart;
864 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
866 if ($withpicto != 2) {
867 $result .= $this->name;
872 $hookmanager->initHooks(array(
'groupdao'));
873 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
874 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
876 $result = $hookmanager->resPrint;
878 $result .= $hookmanager->resPrint;
939 $valueofldapfield = array();
940 foreach ($this->members as $key => $val) {
941 $muser =
new User($this->db);
942 $muser->fetch($val->id);
943 $info2 = $muser->_load_ldap_info();
944 $valueofldapfield[] = $muser->_load_ldap_dn($info2);
946 $info[
getDolGlobalString(
'LDAP_GROUP_FIELD_GROUPMEMBERS')] = (!empty($valueofldapfield) ? $valueofldapfield :
'');
964 global $conf, $user, $langs;
968 $this->
ref =
'SPECIMEN';
971 $this->
name =
'DOLIBARR GROUP SPECIMEN';
972 $this->note =
'This is a note';
973 $this->datec = time();
977 $this->members = array(
995 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
997 global $conf, $user, $langs;
999 $langs->load(
"user");
1010 $modelpath =
"core/modules/usergroup/doc/";
1012 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1026 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1028 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1029 $return .=
'<div class="info-box info-box-sm">';
1030 $return .=
'<span class="info-box-icon bg-infobox-action">';
1032 $return .=
'</span>';
1033 $return .=
'<div class="info-box-content">';
1034 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1035 if ($selected >= 0) {
1036 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1038 if (property_exists($this,
'members')) {
1039 $return .=
'<br><span class="info-box-status opacitymedium">'.(empty($this->nb_users) ? 0 : $this->nb_users).
' '.$langs->trans(
'Users').
'</span>';
1041 if (property_exists($this,
'nb_rights')) {
1042 $return .=
'<br><div class="info-box-status margintoponly opacitymedium">'.$langs->trans(
'NbOfPermissions').
' : '.(empty($this->nb_rights) ? 0 : $this->nb_rights).
'</div>';
1044 $return .=
'</div>';
1045 $return .=
'</div>';
1046 $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)
Charge un object group avec toutes ses caracteristiques (except ->members array)
listUsersForGroup($excludefilter='', $mode=0)
Return array of User objects for group this->id (or all if this->id not defined)
getKanbanView($option='', $arraydata=null)
Return clicable 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 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.