dolibarr  19.0.0-dev
usergroup.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (c) 2005-2018 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (c) 2005-2018 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2012 Florian Henry <florian.henry@open-concept.pro>
6  * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
7  * Copyright (C) 2014 Alexis Algoud <alexis@atm-consulting.fr>
8  * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
9  * Copyright (C) 2019 Abbes Bahfir <dolipar@dolipar.org>
10  * Copyright (C) 2023 Frédéric France <frederic.france@netlogic.fr>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <https://www.gnu.org/licenses/>.
24  */
25 
31 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
32 if (isModEnabled('ldap')) {
33  require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
34 }
35 
36 
40 class UserGroup extends CommonObject
41 {
45  public $element = 'usergroup';
46 
50  public $table_element = 'usergroup';
51 
56  public $ismultientitymanaged = 1;
57 
61  public $picto = 'group';
62 
66  public $entity;
67 
73  public $nom;
74 
78  public $name; // Name of group
79 
80  public $globalgroup; // Global group
81 
87  public $datec;
88 
94  public $tms;
95 
99  public $note;
100 
104  public $members = array(); // Array of users
105 
106  public $nb_rights; // Number of rights granted to the user
107  public $nb_users; // Number of users in the group
108 
109  public $rights; // Permissions of the group
110 
111  private $_tab_loaded = array(); // Array of cache of already loaded permissions
112 
116  public $all_permissions_are_loaded;
117 
118  public $oldcopy; // To contains a clone of this when we need to save old properties of object
119 
120  public $fields = array(
121  'rowid'=>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'),
122  'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'notnull'=> 1, 'default'=>1, 'index'=>1, 'position'=>5),
123  'nom'=>array('type'=>'varchar(180)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Group name'),
124  'note' => array('type'=>'html', 'label'=>'Description', 'enabled'=>1, 'visible'=>1, 'position'=>20, 'notnull'=>-1, 'searchall'=>1),
125  'datec' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>50, 'notnull'=>1,),
126  'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'position'=>60, 'notnull'=>1,),
127  'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'ModelPDF', 'enabled'=>1, 'visible'=>0, 'position'=>100),
128  );
129 
133  public $fk_element = 'fk_usergroup';
134 
138  protected $childtables = array();
139 
143  protected $childtablesoncascade = array('usergroup_rights', 'usergroup_user');
144 
145 
151  public function __construct($db)
152  {
153  $this->db = $db;
154  $this->nb_rights = 0;
155  }
156 
157 
166  public function fetch($id = '', $groupname = '', $load_members = false)
167  {
168  global $conf;
169 
170  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
171  if (!empty($groupname)) {
172  $result = $this->fetchCommon(0, '', ' AND nom = \''.$this->db->escape($groupname).'\'');
173  } else {
174  $result = $this->fetchCommon($id);
175  }
176 
177  $this->name = $this->nom; // For compatibility with field name
178 
179  if ($result) {
180  if ($load_members) {
181  $this->members = $this->listUsersForGroup(); // This make a lot of subrequests
182  }
183 
184  return 1;
185  } else {
186  $this->error = $this->db->lasterror();
187  return -1;
188  }
189  }
190 
191 
199  public function listGroupsForUser($userid, $load_members = true)
200  {
201  global $conf, $user;
202 
203  $ret = array();
204 
205  $sql = "SELECT g.rowid, ug.entity as usergroup_entity";
206  $sql .= " FROM ".$this->db->prefix()."usergroup as g,";
207  $sql .= " ".$this->db->prefix()."usergroup_user as ug";
208  $sql .= " WHERE ug.fk_usergroup = g.rowid";
209  $sql .= " AND ug.fk_user = ".((int) $userid);
210  if (isModEnabled('multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
211  $sql .= " AND g.entity IS NOT NULL";
212  } else {
213  $sql .= " AND g.entity IN (0,".$conf->entity.")";
214  }
215  $sql .= " ORDER BY g.nom";
216 
217  dol_syslog(get_class($this)."::listGroupsForUser", LOG_DEBUG);
218  $result = $this->db->query($sql);
219  if ($result) {
220  while ($obj = $this->db->fetch_object($result)) {
221  if (!array_key_exists($obj->rowid, $ret)) {
222  $newgroup = new UserGroup($this->db);
223  $newgroup->fetch($obj->rowid, '', $load_members);
224  $ret[$obj->rowid] = $newgroup;
225  }
226 
227  $ret[$obj->rowid]->usergroup_entity[] = $obj->usergroup_entity;
228  }
229 
230  $this->db->free($result);
231 
232  return $ret;
233  } else {
234  $this->error = $this->db->lasterror();
235  return -1;
236  }
237  }
238 
246  public function listUsersForGroup($excludefilter = '', $mode = 0)
247  {
248  global $conf, $user;
249 
250  $ret = array();
251 
252  $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";
253  if (!empty($this->id)) {
254  $sql .= ", ug.entity as usergroup_entity";
255  }
256  $sql .= " FROM ".$this->db->prefix()."user as u";
257  if (!empty($this->id)) {
258  $sql .= ", ".$this->db->prefix()."usergroup_user as ug";
259  }
260  $sql .= " WHERE 1 = 1";
261  if (!empty($this->id)) {
262  $sql .= " AND ug.fk_user = u.rowid";
263  }
264  if (!empty($this->id)) {
265  $sql .= " AND ug.fk_usergroup = ".((int) $this->id);
266  }
267  if (isModEnabled('multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
268  $sql .= " AND u.entity IS NOT NULL";
269  } else {
270  $sql .= " AND u.entity IN (0,".$conf->entity.")";
271  }
272  if (!empty($excludefilter)) {
273  $sql .= ' AND ('.$excludefilter.')';
274  }
275 
276  dol_syslog(get_class($this)."::listUsersForGroup", LOG_DEBUG);
277  $resql = $this->db->query($sql);
278 
279  if ($resql) {
280  while ($obj = $this->db->fetch_object($resql)) {
281  if (!array_key_exists($obj->rowid, $ret)) {
282  if ($mode != 1) {
283  $newuser = new User($this->db);
284  //$newuser->fetch($obj->rowid); // We are inside a loop, no subrequests inside a loop
285  $newuser->id = $obj->rowid;
286  $newuser->login = $obj->login;
287  $newuser->photo = $obj->photo;
288  $newuser->lastname = $obj->lastname;
289  $newuser->firstname = $obj->firstname;
290  $newuser->email = $obj->email;
291  $newuser->socid = $obj->fk_soc;
292  $newuser->entity = $obj->entity;
293  $newuser->employee = $obj->employee;
294  $newuser->status = $obj->status;
295 
296  $ret[$obj->rowid] = $newuser;
297  } else {
298  $ret[$obj->rowid] = $obj->rowid;
299  }
300  }
301  if ($mode != 1 && !empty($obj->usergroup_entity)) {
302  $ret[$obj->rowid]->usergroup_entity[] = $obj->usergroup_entity;
303  }
304  }
305 
306  $this->db->free($resql);
307 
308  return $ret;
309  } else {
310  $this->error = $this->db->lasterror();
311  return -1;
312  }
313  }
314 
324  public function addrights($rid, $allmodule = '', $allperms = '', $entity = 0)
325  {
326  global $conf, $user, $langs;
327 
328  $entity = (!empty($entity) ? $entity : $conf->entity);
329 
330  dol_syslog(get_class($this)."::addrights $rid, $allmodule, $allperms, $entity");
331  $error = 0;
332  $whereforadd = '';
333 
334  $this->db->begin();
335 
336  if (!empty($rid)) {
337  $module = $perms = $subperms = '';
338 
339  // Si on a demande ajout d'un droit en particulier, on recupere
340  // les caracteristiques (module, perms et subperms) de ce droit.
341  $sql = "SELECT module, perms, subperms";
342  $sql .= " FROM ".$this->db->prefix()."rights_def";
343  $sql .= " WHERE id = ".((int) $rid);
344  $sql .= " AND entity = ".((int) $entity);
345 
346  $result = $this->db->query($sql);
347  if ($result) {
348  $obj = $this->db->fetch_object($result);
349  if ($obj) {
350  $module = $obj->module;
351  $perms = $obj->perms;
352  $subperms = $obj->subperms;
353  }
354  } else {
355  $error++;
356  dol_print_error($this->db);
357  }
358 
359  // Where pour la liste des droits a ajouter
360  $whereforadd = "id=".((int) $rid);
361  // Find also rights that are herited to add them too
362  if ($subperms) {
363  $whereforadd .= " OR (module='".$this->db->escape($module)."' AND perms='".$this->db->escape($perms)."' AND (subperms='lire' OR subperms='read'))";
364  } elseif ($perms) {
365  $whereforadd .= " OR (module='".$this->db->escape($module)."' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
366  }
367  } else {
368  // Where pour la liste des droits a ajouter
369  if (!empty($allmodule)) {
370  if ($allmodule == 'allmodules') {
371  $whereforadd = 'allmodules';
372  } else {
373  $whereforadd = "module='".$this->db->escape($allmodule)."'";
374  if (!empty($allperms)) {
375  $whereforadd .= " AND perms='".$this->db->escape($allperms)."'";
376  }
377  }
378  }
379  }
380 
381  // Add permission of the list $whereforadd
382  if (!empty($whereforadd)) {
383  //print "$module-$perms-$subperms";
384  $sql = "SELECT id";
385  $sql .= " FROM ".$this->db->prefix()."rights_def";
386  $sql .= " WHERE entity = ".((int) $entity);
387  if (!empty($whereforadd) && $whereforadd != 'allmodules') {
388  $sql .= " AND ".$whereforadd;
389  }
390 
391  $result = $this->db->query($sql);
392  if ($result) {
393  $num = $this->db->num_rows($result);
394  $i = 0;
395  while ($i < $num) {
396  $obj = $this->db->fetch_object($result);
397  $nid = $obj->id;
398 
399  $sql = "DELETE FROM ".$this->db->prefix()."usergroup_rights WHERE fk_usergroup = ".((int) $this->id)." AND fk_id=".((int) $nid)." AND entity = ".((int) $entity);
400  if (!$this->db->query($sql)) {
401  $error++;
402  }
403  $sql = "INSERT INTO ".$this->db->prefix()."usergroup_rights (entity, fk_usergroup, fk_id) VALUES (".((int) $entity).", ".((int) $this->id).", ".((int) $nid).")";
404  if (!$this->db->query($sql)) {
405  $error++;
406  }
407 
408  $i++;
409  }
410  } else {
411  $error++;
412  dol_print_error($this->db);
413  }
414 
415  if (!$error) {
416  $langs->load("other");
417  $this->context = array('audit'=>$langs->trans("PermissionsAdd").($rid ? ' (id='.$rid.')' : ''));
418 
419  // Call trigger
420  $result = $this->call_trigger('USERGROUP_MODIFY', $user);
421  if ($result < 0) {
422  $error++;
423  }
424  // End call triggers
425  }
426  }
427 
428  if ($error) {
429  $this->db->rollback();
430  return -$error;
431  } else {
432  $this->db->commit();
433  return 1;
434  }
435  }
436 
437 
447  public function delrights($rid, $allmodule = '', $allperms = '', $entity = 0)
448  {
449  global $conf, $user, $langs;
450 
451  $error = 0;
452  $wherefordel = '';
453 
454  $entity = (!empty($entity) ? $entity : $conf->entity);
455 
456  $this->db->begin();
457 
458  if (!empty($rid)) {
459  $module = $perms = $subperms = '';
460 
461  // Si on a demande supression d'un droit en particulier, on recupere
462  // les caracteristiques module, perms et subperms de ce droit.
463  $sql = "SELECT module, perms, subperms";
464  $sql .= " FROM ".$this->db->prefix()."rights_def";
465  $sql .= " WHERE id = ".((int) $rid);
466  $sql .= " AND entity = ".((int) $entity);
467 
468  $result = $this->db->query($sql);
469  if ($result) {
470  $obj = $this->db->fetch_object($result);
471  if ($obj) {
472  $module = $obj->module;
473  $perms = $obj->perms;
474  $subperms = $obj->subperms;
475  }
476  } else {
477  $error++;
478  dol_print_error($this->db);
479  }
480 
481  // Where for the list of permissions to delete
482  $wherefordel = "id = ".((int) $rid);
483  // Suppression des droits induits
484  if ($subperms == 'lire' || $subperms == 'read') {
485  $wherefordel .= " OR (module='".$this->db->escape($module)."' AND perms='".$this->db->escape($perms)."' AND subperms IS NOT NULL)";
486  }
487  if ($perms == 'lire' || $perms == 'read') {
488  $wherefordel .= " OR (module='".$this->db->escape($module)."')";
489  }
490 
491  // Pour compatibilite, si lowid = 0, on est en mode suppression de tout
492  // TODO A virer quand sera gere par l'appelant
493  //if (substr($rid,-1,1) == 0) $wherefordel="module='$module'";
494  } else {
495  // Add permission of the list $wherefordel
496  if (!empty($allmodule)) {
497  if ($allmodule == 'allmodules') {
498  $wherefordel = 'allmodules';
499  } else {
500  $wherefordel = "module='".$this->db->escape($allmodule)."'";
501  if (!empty($allperms)) {
502  $wherefordel .= " AND perms='".$this->db->escape($allperms)."'";
503  }
504  }
505  }
506  }
507 
508  // Suppression des droits de la liste wherefordel
509  if (!empty($wherefordel)) {
510  //print "$module-$perms-$subperms";
511  $sql = "SELECT id";
512  $sql .= " FROM ".$this->db->prefix()."rights_def";
513  $sql .= " WHERE entity = ".((int) $entity);
514  if (!empty($wherefordel) && $wherefordel != 'allmodules') {
515  $sql .= " AND ".$wherefordel;
516  }
517 
518  $result = $this->db->query($sql);
519  if ($result) {
520  $num = $this->db->num_rows($result);
521  $i = 0;
522  while ($i < $num) {
523  $nid = 0;
524 
525  $obj = $this->db->fetch_object($result);
526  if ($obj) {
527  $nid = $obj->id;
528  }
529 
530  $sql = "DELETE FROM ".$this->db->prefix()."usergroup_rights";
531  $sql .= " WHERE fk_usergroup = $this->id AND fk_id=".((int) $nid);
532  $sql .= " AND entity = ".((int) $entity);
533  if (!$this->db->query($sql)) {
534  $error++;
535  }
536 
537  $i++;
538  }
539  } else {
540  $error++;
541  dol_print_error($this->db);
542  }
543 
544  if (!$error) {
545  $langs->load("other");
546  $this->context = array('audit'=>$langs->trans("PermissionsDelete").($rid ? ' (id='.$rid.')' : ''));
547 
548  // Call trigger
549  $result = $this->call_trigger('USERGROUP_MODIFY', $user);
550  if ($result < 0) {
551  $error++;
552  }
553  // End call triggers
554  }
555  }
556 
557  if ($error) {
558  $this->db->rollback();
559  return -$error;
560  } else {
561  $this->db->commit();
562  return 1;
563  }
564  }
565 
566 
573  public function getrights($moduletag = '')
574  {
575  global $conf;
576 
577  if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
578  // Rights for this module are already loaded, so we leave
579  return 0;
580  }
581 
582  if (!empty($this->all_permissions_are_loaded)) {
583  // We already loaded all rights for this group, so we leave
584  return 0;
585  }
586 
587  /*
588  * Recuperation des droits
589  */
590  $sql = "SELECT r.module, r.perms, r.subperms ";
591  $sql .= " FROM ".$this->db->prefix()."usergroup_rights as u, ".$this->db->prefix()."rights_def as r";
592  $sql .= " WHERE r.id = u.fk_id";
593  $sql .= " AND r.entity = ".((int) $conf->entity);
594  $sql .= " AND u.entity = ".((int) $conf->entity);
595  $sql .= " AND u.fk_usergroup = ".((int) $this->id);
596  $sql .= " AND r.perms IS NOT NULL";
597  if ($moduletag) {
598  $sql .= " AND r.module = '".$this->db->escape($moduletag)."'";
599  }
600 
601  dol_syslog(get_class($this).'::getrights', LOG_DEBUG);
602  $resql = $this->db->query($sql);
603  if ($resql) {
604  $num = $this->db->num_rows($resql);
605  $i = 0;
606  while ($i < $num) {
607  $obj = $this->db->fetch_object($resql);
608 
609  if ($obj) {
610  $module = $obj->module;
611  $perms = $obj->perms;
612  $subperms = $obj->subperms;
613 
614  if ($perms) {
615  if (!isset($this->rights)) {
616  $this->rights = new stdClass(); // For avoid error
617  }
618  if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
619  $this->rights->$module = new stdClass();
620  }
621  if ($subperms) {
622  if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
623  $this->rights->$module->$perms = new stdClass();
624  }
625  if (empty($this->rights->$module->$perms->$subperms)) {
626  $this->nb_rights++;
627  }
628  $this->rights->$module->$perms->$subperms = 1;
629  } else {
630  if (empty($this->rights->$module->$perms)) {
631  $this->nb_rights++;
632  }
633  $this->rights->$module->$perms = 1;
634  }
635  }
636  }
637 
638  $i++;
639  }
640  $this->db->free($resql);
641  }
642 
643  if ($moduletag == '') {
644  // Si module etait non defini, alors on a tout charge, on peut donc considerer
645  // que les droits sont en cache (car tous charges) pour cet instance de group
646  $this->all_permissions_are_loaded = 1;
647  } else {
648  // If module defined, we flag it as loaded into cache
649  $this->_tab_loaded[$moduletag] = 1;
650  }
651 
652  return 1;
653  }
654 
661  public function delete(User $user)
662  {
663  return $this->deleteCommon($user);
664  }
665 
672  public function create($notrigger = 0)
673  {
674  global $user, $conf;
675 
676  $this->datec = dol_now();
677  if (!empty($this->name)) {
678  $this->nom = $this->name; // Field for 'name' is called 'nom' in database
679  }
680 
681  if (!isset($this->entity)) {
682  $this->entity = $conf->entity; // If not defined, we use default value
683  }
684 
685  return $this->createCommon($user, $notrigger);
686  }
687 
694  public function update($notrigger = 0)
695  {
696  global $user, $conf;
697 
698  if (!empty($this->name)) {
699  $this->nom = $this->name; // Field for 'name' is called 'nom' in database
700  }
701 
702  return $this->updateCommon($user, $notrigger);
703  }
704 
705 
715  public function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0)
716  {
717  //print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n";
718  $lastname = $this->lastname;
719  $firstname = $this->firstname;
720  if (empty($lastname)) {
721  $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 : '')))));
722  }
723 
724  $ret = '';
725  if (!empty($option) && !empty($this->civility_code)) {
726  if ($langs->transnoentitiesnoconv("Civility".$this->civility_code) != "Civility".$this->civility_code) {
727  $ret .= $langs->transnoentitiesnoconv("Civility".$this->civility_code).' ';
728  } else {
729  $ret .= $this->civility_code.' ';
730  }
731  }
732 
733  $ret .= dolGetFirstLastname($firstname, $lastname, $nameorder);
734 
735  return dol_trunc($ret, $maxlen);
736  }
737 
744  public function getLibStatut($mode = 0)
745  {
746  return $this->LibStatut(0, $mode);
747  }
748 
749  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
757  public function LibStatut($status, $mode = 0)
758  {
759  // phpcs:enable
760  global $langs;
761  $langs->load('users');
762  return '';
763  }
764 
772  public function getTooltipContentArray($params)
773  {
774  global $conf, $langs, $menumanager;
775 
776  $option = $params['option'] ?? '';
777 
778  $datas = [];
779  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
780  $langs->load("users");
781  return ['optimize' => $langs->trans("ShowGroup")];
782  }
783  $datas['divopen'] = '<div class="centpercent">';
784  $datas['picto'] = img_picto('', 'group').' <u>'.$langs->trans("Group").'</u><br>';
785  $datas['name'] = '<b>'.$langs->trans('Name').':</b> '.$this->name;
786  $datas['description'] = '<br><b>'.$langs->trans("Description").':</b> '.$this->note;
787  $datas['divclose'] = '</div>';
788 
789  return $datas;
790  }
791 
803  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
804  {
805  global $langs, $conf, $db, $hookmanager;
806  global $dolibarr_main_authentication, $dolibarr_main_demo;
807  global $menumanager;
808 
809  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpicto) {
810  $withpicto = 0;
811  }
812 
813  $result = '';
814  $params = [
815  'id' => $this->id,
816  'objecttype' => $this->element,
817  'option' => $option,
818  ];
819  $classfortooltip = 'classfortooltip';
820  $dataparams = '';
821  if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
822  $classfortooltip = 'classforajaxtooltip';
823  $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
824  $label = '';
825  } else {
826  $label = implode($this->getTooltipContentArray($params));
827  }
828 
829  if ($option == 'permissions') {
830  $url = DOL_URL_ROOT.'/user/group/perms.php?id='.$this->id;
831  } else {
832  $url = DOL_URL_ROOT.'/user/group/card.php?id='.$this->id;
833  }
834 
835  if ($option != 'nolink') {
836  // Add param to save lastsearch_values or not
837  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
838  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
839  $add_save_lastsearch_values = 1;
840  }
841  if ($add_save_lastsearch_values) {
842  $url .= '&save_lastsearch_values=1';
843  }
844  }
845 
846  $linkclose = "";
847  if (empty($notooltip)) {
848  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
849  $langs->load("users");
850  $label = $langs->trans("ShowGroup");
851  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1, 1).'"';
852  }
853  $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
854  $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
855  }
856 
857  $linkstart = '<a href="'.$url.'"';
858  $linkstart .= $linkclose.'>';
859  $linkend = '</a>';
860 
861  $result = $linkstart;
862  if ($withpicto) {
863  $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : $dataparams.'class="'.(($withpicto != 2) ? 'paddingright ' : '').$classfortooltip.'"'), 0, 0, $notooltip ? 0 : 1);
864  }
865  if ($withpicto != 2) {
866  $result .= $this->name;
867  }
868  $result .= $linkend;
869 
870  global $action;
871  $hookmanager->initHooks(array('groupdao'));
872  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
873  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
874  if ($reshook > 0) {
875  $result = $hookmanager->resPrint;
876  } else {
877  $result .= $hookmanager->resPrint;
878  }
879 
880  return $result;
881  }
882 
883  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
884  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
894  public function _load_ldap_dn($info, $mode = 0)
895  {
896  // phpcs:enable
897  global $conf;
898  $dn = '';
899  if ($mode == 0) {
900  $dn = $conf->global->LDAP_KEY_GROUPS."=".$info[$conf->global->LDAP_KEY_GROUPS].",".$conf->global->LDAP_GROUP_DN;
901  }
902  if ($mode == 1) {
903  $dn = $conf->global->LDAP_GROUP_DN;
904  }
905  if ($mode == 2) {
906  $dn = $conf->global->LDAP_KEY_GROUPS."=".$info[$conf->global->LDAP_KEY_GROUPS];
907  }
908  return $dn;
909  }
910 
911 
912  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
913  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
919  public function _load_ldap_info()
920  {
921  // phpcs:enable
922  global $conf;
923 
924  $info = array();
925 
926  // Object classes
927  $info["objectclass"] = explode(',', $conf->global->LDAP_GROUP_OBJECT_CLASS);
928 
929  // Champs
930  if ($this->name && !empty($conf->global->LDAP_GROUP_FIELD_FULLNAME)) {
931  $info[$conf->global->LDAP_GROUP_FIELD_FULLNAME] = $this->name;
932  }
933  //if ($this->name && !empty($conf->global->LDAP_GROUP_FIELD_NAME)) $info[$conf->global->LDAP_GROUP_FIELD_NAME] = $this->name;
934  if ($this->note && !empty($conf->global->LDAP_GROUP_FIELD_DESCRIPTION)) {
935  $info[$conf->global->LDAP_GROUP_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note, 2);
936  }
937  if (!empty($conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS)) {
938  $valueofldapfield = array();
939  foreach ($this->members as $key => $val) { // This is array of users for group into dolibarr database.
940  $muser = new User($this->db);
941  $muser->fetch($val->id);
942  $info2 = $muser->_load_ldap_info();
943  $valueofldapfield[] = $muser->_load_ldap_dn($info2);
944  }
945  $info[$conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS] = (!empty($valueofldapfield) ? $valueofldapfield : '');
946  }
947  if (!empty($conf->global->LDAP_GROUP_FIELD_GROUPID)) {
948  $info[$conf->global->LDAP_GROUP_FIELD_GROUPID] = $this->id;
949  }
950  return $info;
951  }
952 
953 
961  public function initAsSpecimen()
962  {
963  global $conf, $user, $langs;
964 
965  // Initialise parametres
966  $this->id = 0;
967  $this->ref = 'SPECIMEN';
968  $this->specimen = 1;
969 
970  $this->name = 'DOLIBARR GROUP SPECIMEN';
971  $this->note = 'This is a note';
972  $this->datec = time();
973  $this->tms = time();
974 
975  // Members of this group is just me
976  $this->members = array(
977  $user->id => $user
978  );
979  }
980 
992  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
993  {
994  global $conf, $user, $langs;
995 
996  $langs->load("user");
997 
998  // Positionne le modele sur le nom du modele a utiliser
999  if (!dol_strlen($modele)) {
1000  if (!empty($conf->global->USERGROUP_ADDON_PDF)) {
1001  $modele = $conf->global->USERGROUP_ADDON_PDF;
1002  } else {
1003  $modele = 'grass';
1004  }
1005  }
1006 
1007  $modelpath = "core/modules/usergroup/doc/";
1008 
1009  return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1010  }
1011 
1019  public function getKanbanView($option = '', $arraydata = null)
1020  {
1021  global $langs;
1022 
1023  $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1024 
1025  $return = '<div class="box-flex-item box-flex-grow-zero">';
1026  $return .= '<div class="info-box info-box-sm">';
1027  $return .= '<span class="info-box-icon bg-infobox-action">';
1028  $return .= img_picto('', $this->picto);
1029  $return .= '</span>';
1030  $return .= '<div class="info-box-content">';
1031  $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1032  $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1033  if (property_exists($this, 'members')) {
1034  $return .= '<br><span class="info-box-status opacitymedium">'.(empty($this->nb_users) ? 0 : $this->nb_users).' '.$langs->trans('Users').'</span>';
1035  }
1036  if (property_exists($this, 'nb_rights')) {
1037  $return .= '<br><div class="info-box-status margintoponly opacitymedium">'.$langs->trans('NbOfPermissions').' : '.(empty($this->nb_rights) ? 0 : $this->nb_rights).'</div>';
1038  }
1039  $return .= '</div>';
1040  $return .= '</div>';
1041  $return .= '</div>';
1042  return $return;
1043  }
1044 }
$object ref
Definition: info.php:78
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.
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
updateCommon(User $user, $notrigger=false)
Update object into 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 optionaly the picto) Use this->id,this->lastname,...
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='')
Charge dans l'objet group, la liste des permissions auquels le groupe a droit.
getLibStatut($mode=0)
Return the label of the status.
fetch($id='', $groupname='', $load_members=false)
Charge un objet group avec toutes ses caracteristiques (except ->members array)
getTooltipContentArray($params)
getTooltipContentArray
__construct($db)
Constructor de la classe.
update($notrigger=0)
Update group into database.
Class to manage Dolibarr users.
Definition: user.class.php:48
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
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 dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
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.
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.
Definition: repair.php:123