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');
163 $this->ismultientitymanaged = 1;
164 $this->nb_rights = 0;
176 public function fetch($id = 0, $groupname =
'', $load_members =
false)
178 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
179 if (!empty($groupname)) {
180 $result = $this->
fetchCommon(0,
'',
' AND nom = \''.$this->db->escape($groupname).
'\'');
185 $this->
name = $this->nom;
195 $this->error = $this->db->lasterror();
214 $sql =
"SELECT g.rowid, ug.entity as usergroup_entity";
215 $sql .=
" FROM ".$this->db->prefix().
"usergroup as g,";
216 $sql .=
" ".$this->db->prefix().
"usergroup_user as ug";
217 $sql .=
" WHERE ug.fk_usergroup = g.rowid";
218 $sql .=
" AND ug.fk_user = ".((int) $userid);
219 if (isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && !$user->entity) {
220 $sql .=
" AND g.entity IS NOT NULL";
222 $sql .=
" AND g.entity IN (0,".$conf->entity.
")";
224 $sql .=
" ORDER BY g.nom";
226 dol_syslog(get_class($this).
"::listGroupsForUser", LOG_DEBUG);
227 $result = $this->db->query($sql);
229 while ($obj = $this->db->fetch_object($result)) {
230 if (!array_key_exists($obj->rowid, $ret)) {
232 $newgroup->fetch($obj->rowid,
'', $load_members);
233 $ret[$obj->rowid] = $newgroup;
235 if (!is_array($ret[$obj->rowid]->usergroup_entity)) {
236 $ret[$obj->rowid]->usergroup_entity = array();
239 $ret[$obj->rowid]->usergroup_entity[] = (int) $obj->usergroup_entity;
242 $this->db->free($result);
246 $this->error = $this->db->lasterror();
264 $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";
265 if (!empty($this->
id)) {
266 $sql .=
", ug.entity as usergroup_entity";
268 $sql .=
" FROM ".$this->db->prefix().
"user as u";
269 if (!empty($this->
id)) {
270 $sql .=
", ".$this->db->prefix().
"usergroup_user as ug";
272 $sql .=
" WHERE 1 = 1";
273 if (!empty($this->
id)) {
274 $sql .=
" AND ug.fk_user = u.rowid";
276 if (!empty($this->
id)) {
277 $sql .=
" AND ug.fk_usergroup = ".((int) $this->
id);
279 if (isModEnabled(
'multicompany') &&
$conf->entity == 1 && $user->admin && !$user->entity) {
280 $sql .=
" AND u.entity IS NOT NULL";
282 $sql .=
" AND u.entity IN (0,".$conf->entity.
")";
284 if (!empty($excludefilter)) {
285 $sql .=
' AND ('.$excludefilter.
')';
288 dol_syslog(get_class($this).
"::listUsersForGroup", LOG_DEBUG);
289 $resql = $this->db->query($sql);
292 while ($obj = $this->db->fetch_object($resql)) {
293 if (!array_key_exists($obj->rowid, $ret)) {
295 $newuser =
new User($this->db);
297 $newuser->id = $obj->rowid;
298 $newuser->login = $obj->login;
299 $newuser->photo = $obj->photo;
300 $newuser->lastname = $obj->lastname;
301 $newuser->firstname = $obj->firstname;
302 $newuser->email = $obj->email;
303 $newuser->socid = $obj->fk_soc;
304 $newuser->entity = $obj->entity;
305 $newuser->employee = $obj->employee;
306 $newuser->status = $obj->status;
308 $ret[$obj->rowid] = $newuser;
310 $ret[$obj->rowid] = $obj->rowid;
313 if ($mode != 1 && !empty($obj->usergroup_entity)) {
315 if (!is_array($ret[$obj->rowid]->usergroup_entity)) {
316 $ret[$obj->rowid]->usergroup_entity = array();
318 $ret[$obj->rowid]->usergroup_entity[] = (int) $obj->usergroup_entity;
322 $this->db->free($resql);
326 $this->error = $this->db->lasterror();
340 public function addrights($rid, $allmodule =
'', $allperms =
'', $entity = 0)
342 global
$conf, $user, $langs;
344 $entity = (!empty($entity) ? $entity :
$conf->entity);
346 dol_syslog(get_class($this).
"::addrights $rid, $allmodule, $allperms, $entity");
353 $module = $perms = $subperms =
'';
357 $sql =
"SELECT module, perms, subperms";
358 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
359 $sql .=
" WHERE id = ".((int) $rid);
360 $sql .=
" AND entity = ".((int) $entity);
362 $result = $this->db->query($sql);
364 $obj = $this->db->fetch_object($result);
366 $module = $obj->module;
367 $perms = $obj->perms;
368 $subperms = $obj->subperms;
376 $whereforadd =
"id=".((int) $rid);
379 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND (subperms='lire' OR subperms='read'))";
381 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
385 if (!empty($allmodule)) {
386 if ($allmodule ==
'allmodules') {
387 $whereforadd =
'allmodules';
389 $whereforadd =
"module='".$this->db->escape($allmodule).
"'";
390 if (!empty($allperms)) {
391 $whereforadd .=
" AND perms='".$this->db->escape($allperms).
"'";
398 if (!empty($whereforadd)) {
401 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
402 $sql .=
" WHERE entity = ".((int) $entity);
403 if (!empty($whereforadd) && $whereforadd !=
'allmodules') {
404 $sql .=
" AND ".$whereforadd;
407 $result = $this->db->query($sql);
409 $num = $this->db->num_rows($result);
412 $obj = $this->db->fetch_object($result);
415 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_rights WHERE fk_usergroup = ".((int) $this->
id).
" AND fk_id=".((int) $nid).
" AND entity = ".((int) $entity);
416 if (!$this->db->query($sql)) {
419 $sql =
"INSERT INTO ".$this->db->prefix().
"usergroup_rights (entity, fk_usergroup, fk_id) VALUES (".((int) $entity).
", ".((int) $this->
id).
", ".((int) $nid).
")";
420 if (!$this->db->query($sql)) {
432 $langs->load(
"other");
433 $this->context = array(
'audit' => $langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
436 $result = $this->
call_trigger(
'USERGROUP_MODIFY', $user);
445 $this->db->rollback();
463 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0)
465 global
$conf, $user, $langs;
470 $entity = (!empty($entity) ? $entity :
$conf->entity);
475 $module = $perms = $subperms =
'';
479 $sql =
"SELECT module, perms, subperms";
480 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
481 $sql .=
" WHERE id = ".((int) $rid);
482 $sql .=
" AND entity = ".((int) $entity);
484 $result = $this->db->query($sql);
486 $obj = $this->db->fetch_object($result);
488 $module = $obj->module;
489 $perms = $obj->perms;
490 $subperms = $obj->subperms;
498 $wherefordel =
"id = ".((int) $rid);
500 if ($subperms ==
'lire' || $subperms ==
'read') {
501 $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND subperms IS NOT NULL)";
503 if ($perms ==
'lire' || $perms ==
'read') {
504 $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
512 if (!empty($allmodule)) {
513 if ($allmodule ==
'allmodules') {
514 $wherefordel =
'allmodules';
516 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
517 if (!empty($allperms)) {
518 $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
525 if (!empty($wherefordel)) {
528 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
529 $sql .=
" WHERE entity = ".((int) $entity);
530 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
531 $sql .=
" AND ".$wherefordel;
534 $result = $this->db->query($sql);
536 $num = $this->db->num_rows($result);
541 $obj = $this->db->fetch_object($result);
546 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_rights";
547 $sql .=
" WHERE fk_usergroup = $this->id AND fk_id=".((int) $nid);
548 $sql .=
" AND entity = ".((int) $entity);
549 if (!$this->db->query($sql)) {
561 $langs->load(
"other");
562 $this->context = array(
'audit' => $langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
565 $result = $this->
call_trigger(
'USERGROUP_MODIFY', $user);
574 $this->db->rollback();
607 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
612 if (!empty($this->all_permissions_are_loaded)) {
618 $sql =
"SELECT r.module, r.perms, r.subperms ";
619 $sql .=
" FROM ".$this->db->prefix().
"usergroup_rights as u, ".$this->db->prefix().
"rights_def as r";
620 $sql .=
" WHERE r.id = u.fk_id";
621 $sql .=
" AND r.entity = ".((int)
$conf->entity);
622 $sql .=
" AND u.entity = ".((int)
$conf->entity);
623 $sql .=
" AND u.fk_usergroup = ".((int) $this->
id);
624 $sql .=
" AND r.perms IS NOT NULL";
626 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
629 dol_syslog(get_class($this).
'::getrights', LOG_DEBUG);
630 $resql = $this->db->query($sql);
632 $num = $this->db->num_rows($resql);
635 $obj = $this->db->fetch_object($resql);
638 $module = $obj->module;
639 $perms = $obj->perms;
640 $subperms = $obj->subperms;
643 if (!isset($this->rights)) {
646 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
647 $this->rights->$module =
new stdClass();
650 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
651 $this->rights->$module->$perms =
new stdClass();
653 if (empty($this->rights->$module->$perms->$subperms)) {
656 $this->rights->$module->$perms->$subperms = 1;
658 if (empty($this->rights->$module->$perms)) {
661 $this->rights->$module->$perms = 1;
668 $this->db->free($resql);
671 if ($moduletag ==
'') {
674 $this->all_permissions_are_loaded = 1;
677 $this->_tab_loaded[$moduletag] = 1;
689 public function delete(
User $user)
705 if (!empty($this->
name)) {
706 $this->nom = $this->name;
709 if (!isset($this->entity)) {
710 $this->entity =
$conf->entity;
726 if (!empty($this->
name)) {
727 $this->nom = $this->name;
743 public function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0)
746 $lastname = $this->lastname;
747 $firstname = $this->firstname;
748 if (empty($lastname)) {
749 $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 :
'')))));
753 if (!empty($option) && !empty($this->civility_code)) {
754 if ($langs->transnoentitiesnoconv(
"Civility".$this->civility_code) !=
"Civility".$this->civility_code) {
755 $ret .= $langs->transnoentitiesnoconv(
"Civility".$this->civility_code).
' ';
757 $ret .= $this->civility_code.
' ';
789 $langs->load(
'users');
801 global
$conf, $langs, $menumanager;
803 $option = $params[
'option'] ??
'';
807 $langs->load(
"users");
808 return [
'optimize' => $langs->trans(
"ShowGroup")];
810 $datas[
'divopen'] =
'<div class="centpercent">';
811 $datas[
'picto'] =
img_picto(
'',
'group').
' <u>'.$langs->trans(
"Group").
'</u><br>';
812 $datas[
'name'] =
'<b>'.$langs->trans(
'Name').
':</b> '.$this->name;
813 $datas[
'description'] =
'<br><b>'.$langs->trans(
"Description").
':</b> '.$this->note;
814 $datas[
'divclose'] =
'</div>';
830 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
832 global $langs,
$conf, $db, $hookmanager;
841 'objecttype' => $this->element,
844 $classfortooltip =
'classfortooltip';
847 $classfortooltip =
'classforajaxtooltip';
848 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
854 if ($option ==
'permissions') {
855 $url = DOL_URL_ROOT.
'/user/group/perms.php?id='.$this->id;
857 $url = DOL_URL_ROOT.
'/user/group/card.php?id='.$this->id;
860 if ($option !=
'nolink') {
862 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
863 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
864 $add_save_lastsearch_values = 1;
866 if ($add_save_lastsearch_values) {
867 $url .=
'&save_lastsearch_values=1';
872 if (empty($notooltip)) {
874 $langs->load(
"users");
875 $label = $langs->trans(
"ShowGroup");
876 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1, 1).
'"';
878 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
879 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
882 $linkstart =
'<a href="'.$url.
'"';
883 $linkstart .= $linkclose.
'>';
886 $result = $linkstart;
888 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
890 if ($withpicto != 2) {
891 $result .= $this->name;
896 $hookmanager->initHooks(array(
'groupdao'));
897 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
898 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
900 $result = $hookmanager->resPrint;
902 $result .= $hookmanager->resPrint;
963 $valueofldapfield = array();
964 foreach ($this->members as $key => $val) {
965 $muser =
new User($this->db);
966 $muser->fetch($val->id);
967 $info2 = $muser->_load_ldap_info();
968 $valueofldapfield[] = $muser->_load_ldap_dn($info2);
970 $info[
getDolGlobalString(
'LDAP_GROUP_FIELD_GROUPMEMBERS')] = (!empty($valueofldapfield) ? $valueofldapfield :
'');
988 global
$conf, $user, $langs;
992 $this->
ref =
'SPECIMEN';
995 $this->
name =
'DOLIBARR GROUP SPECIMEN';
996 $this->note =
'This is a note';
997 $this->datec = time();
1001 $this->members = array(
1019 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
1021 global
$conf, $user, $langs;
1023 $langs->load(
"user");
1034 $modelpath =
"core/modules/usergroup/doc/";
1036 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1050 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1052 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1053 $return .=
'<div class="info-box info-box-sm">';
1054 $return .=
'<span class="info-box-icon bg-infobox-action">';
1056 $return .=
'</span>';
1057 $return .=
'<div class="info-box-content">';
1058 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1059 if ($selected >= 0) {
1060 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1062 if (property_exists($this,
'members')) {
1063 $return .=
'<br><span class="info-box-status opacitymedium">'.(empty($this->nb_users) ? 0 : $this->nb_users).
' '.$langs->trans(
'Users').
'</span>';
1065 if (property_exists($this,
'nb_rights')) {
1066 $return .=
'<br><div class="info-box-status margintoponly opacitymedium">'.$langs->trans(
'NbOfPermissions').
' : '.(empty($this->nb_rights) ? 0 : $this->nb_rights).
'</div>';
1068 $return .=
'</div>';
1069 $return .=
'</div>';
1070 $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.
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.