dolibarr  18.0.0-alpha
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 
101  public $members = array(); // Array of users
102 
103  public $nb_rights; // Number of rights granted to the user
104  public $nb_users; // Number of users in the group
105 
106  private $_tab_loaded = array(); // Array of cache of already loaded permissions
107 
111  public $all_permissions_are_loaded;
112 
113  public $oldcopy; // To contains a clone of this when we need to save old properties of object
114 
115  public $fields = array(
116  'rowid'=>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'),
117  'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'notnull'=> 1, 'default'=>1, 'index'=>1, 'position'=>5),
118  'nom'=>array('type'=>'varchar(180)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Group name'),
119  'note' => array('type'=>'html', 'label'=>'Description', 'enabled'=>1, 'visible'=>1, 'position'=>20, 'notnull'=>-1, 'searchall'=>1),
120  'datec' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>50, 'notnull'=>1,),
121  'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'position'=>60, 'notnull'=>1,),
122  'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'ModelPDF', 'enabled'=>1, 'visible'=>0, 'position'=>100),
123  );
124 
128  public $fk_element = 'fk_usergroup';
129 
133  protected $childtables = array();
134 
138  protected $childtablesoncascade = array('usergroup_rights', 'usergroup_user');
139 
140 
146  public function __construct($db)
147  {
148  $this->db = $db;
149  $this->nb_rights = 0;
150  }
151 
152 
161  public function fetch($id = '', $groupname = '', $load_members = false)
162  {
163  global $conf;
164 
165  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
166  if (!empty($groupname)) {
167  $result = $this->fetchCommon(0, '', ' AND nom = \''.$this->db->escape($groupname).'\'');
168  } else {
169  $result = $this->fetchCommon($id);
170  }
171 
172  $this->name = $this->nom; // For compatibility with field name
173 
174  if ($result) {
175  if ($load_members) {
176  $this->members = $this->listUsersForGroup(); // This make a lot of subrequests
177  }
178 
179  return 1;
180  } else {
181  $this->error = $this->db->lasterror();
182  return -1;
183  }
184  }
185 
186 
194  public function listGroupsForUser($userid, $load_members = true)
195  {
196  global $conf, $user;
197 
198  $ret = array();
199 
200  $sql = "SELECT g.rowid, ug.entity as usergroup_entity";
201  $sql .= " FROM ".$this->db->prefix()."usergroup as g,";
202  $sql .= " ".$this->db->prefix()."usergroup_user as ug";
203  $sql .= " WHERE ug.fk_usergroup = g.rowid";
204  $sql .= " AND ug.fk_user = ".((int) $userid);
205  if (isModEnabled('multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
206  $sql .= " AND g.entity IS NOT NULL";
207  } else {
208  $sql .= " AND g.entity IN (0,".$conf->entity.")";
209  }
210  $sql .= " ORDER BY g.nom";
211 
212  dol_syslog(get_class($this)."::listGroupsForUser", LOG_DEBUG);
213  $result = $this->db->query($sql);
214  if ($result) {
215  while ($obj = $this->db->fetch_object($result)) {
216  if (!array_key_exists($obj->rowid, $ret)) {
217  $newgroup = new UserGroup($this->db);
218  $newgroup->fetch($obj->rowid, '', $load_members);
219  $ret[$obj->rowid] = $newgroup;
220  }
221 
222  $ret[$obj->rowid]->usergroup_entity[] = $obj->usergroup_entity;
223  }
224 
225  $this->db->free($result);
226 
227  return $ret;
228  } else {
229  $this->error = $this->db->lasterror();
230  return -1;
231  }
232  }
233 
241  public function listUsersForGroup($excludefilter = '', $mode = 0)
242  {
243  global $conf, $user;
244 
245  $ret = array();
246 
247  $sql = "SELECT u.rowid, u.login, u.lastname, u.firstname, u.photo, u.fk_soc, u.entity, u.employee, u.email";
248  if (!empty($this->id)) {
249  $sql .= ", ug.entity as usergroup_entity";
250  }
251  $sql .= " FROM ".$this->db->prefix()."user as u";
252  if (!empty($this->id)) {
253  $sql .= ", ".$this->db->prefix()."usergroup_user as ug";
254  }
255  $sql .= " WHERE 1 = 1";
256  if (!empty($this->id)) {
257  $sql .= " AND ug.fk_user = u.rowid";
258  }
259  if (!empty($this->id)) {
260  $sql .= " AND ug.fk_usergroup = ".((int) $this->id);
261  }
262  if (isModEnabled('multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
263  $sql .= " AND u.entity IS NOT NULL";
264  } else {
265  $sql .= " AND u.entity IN (0,".$conf->entity.")";
266  }
267  if (!empty($excludefilter)) {
268  $sql .= ' AND ('.$excludefilter.')';
269  }
270 
271  dol_syslog(get_class($this)."::listUsersForGroup", LOG_DEBUG);
272  $resql = $this->db->query($sql);
273 
274  if ($resql) {
275  while ($obj = $this->db->fetch_object($resql)) {
276  if (!array_key_exists($obj->rowid, $ret)) {
277  if ($mode != 1) {
278  $newuser = new User($this->db);
279  //$newuser->fetch($obj->rowid); // We are inside a loop, no subrequests inside a loop
280  $newuser->id = $obj->rowid;
281  $newuser->login = $obj->login;
282  $newuser->photo = $obj->photo;
283  $newuser->lastname = $obj->lastname;
284  $newuser->firstname = $obj->firstname;
285  $newuser->email = $obj->email;
286  $newuser->socid = $obj->fk_soc;
287  $newuser->entity = $obj->entity;
288  $newuser->employee = $obj->employee;
289 
290  $ret[$obj->rowid] = $newuser;
291  } else {
292  $ret[$obj->rowid] = $obj->rowid;
293  }
294  }
295  if ($mode != 1 && !empty($obj->usergroup_entity)) {
296  $ret[$obj->rowid]->usergroup_entity[] = $obj->usergroup_entity;
297  }
298  }
299 
300  $this->db->free($resql);
301 
302  return $ret;
303  } else {
304  $this->error = $this->db->lasterror();
305  return -1;
306  }
307  }
308 
318  public function addrights($rid, $allmodule = '', $allperms = '', $entity = 0)
319  {
320  global $conf, $user, $langs;
321 
322  $entity = (!empty($entity) ? $entity : $conf->entity);
323 
324  dol_syslog(get_class($this)."::addrights $rid, $allmodule, $allperms, $entity");
325  $error = 0;
326  $whereforadd = '';
327 
328  $this->db->begin();
329 
330  if (!empty($rid)) {
331  $module = $perms = $subperms = '';
332 
333  // Si on a demande ajout d'un droit en particulier, on recupere
334  // les caracteristiques (module, perms et subperms) de ce droit.
335  $sql = "SELECT module, perms, subperms";
336  $sql .= " FROM ".$this->db->prefix()."rights_def";
337  $sql .= " WHERE id = ".((int) $rid);
338  $sql .= " AND entity = ".((int) $entity);
339 
340  $result = $this->db->query($sql);
341  if ($result) {
342  $obj = $this->db->fetch_object($result);
343  if ($obj) {
344  $module = $obj->module;
345  $perms = $obj->perms;
346  $subperms = $obj->subperms;
347  }
348  } else {
349  $error++;
350  dol_print_error($this->db);
351  }
352 
353  // Where pour la liste des droits a ajouter
354  $whereforadd = "id=".((int) $rid);
355  // Find also rights that are herited to add them too
356  if ($subperms) {
357  $whereforadd .= " OR (module='".$this->db->escape($module)."' AND perms='".$this->db->escape($perms)."' AND (subperms='lire' OR subperms='read'))";
358  } elseif ($perms) {
359  $whereforadd .= " OR (module='".$this->db->escape($module)."' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
360  }
361  } else {
362  // Where pour la liste des droits a ajouter
363  if (!empty($allmodule)) {
364  if ($allmodule == 'allmodules') {
365  $whereforadd = 'allmodules';
366  } else {
367  $whereforadd = "module='".$this->db->escape($allmodule)."'";
368  if (!empty($allperms)) {
369  $whereforadd .= " AND perms='".$this->db->escape($allperms)."'";
370  }
371  }
372  }
373  }
374 
375  // Add permission of the list $whereforadd
376  if (!empty($whereforadd)) {
377  //print "$module-$perms-$subperms";
378  $sql = "SELECT id";
379  $sql .= " FROM ".$this->db->prefix()."rights_def";
380  $sql .= " WHERE entity = ".((int) $entity);
381  if (!empty($whereforadd) && $whereforadd != 'allmodules') {
382  $sql .= " AND ".$whereforadd;
383  }
384 
385  $result = $this->db->query($sql);
386  if ($result) {
387  $num = $this->db->num_rows($result);
388  $i = 0;
389  while ($i < $num) {
390  $obj = $this->db->fetch_object($result);
391  $nid = $obj->id;
392 
393  $sql = "DELETE FROM ".$this->db->prefix()."usergroup_rights WHERE fk_usergroup = ".((int) $this->id)." AND fk_id=".((int) $nid)." AND entity = ".((int) $entity);
394  if (!$this->db->query($sql)) {
395  $error++;
396  }
397  $sql = "INSERT INTO ".$this->db->prefix()."usergroup_rights (entity, fk_usergroup, fk_id) VALUES (".((int) $entity).", ".((int) $this->id).", ".((int) $nid).")";
398  if (!$this->db->query($sql)) {
399  $error++;
400  }
401 
402  $i++;
403  }
404  } else {
405  $error++;
406  dol_print_error($this->db);
407  }
408 
409  if (!$error) {
410  $langs->load("other");
411  $this->context = array('audit'=>$langs->trans("PermissionsAdd").($rid ? ' (id='.$rid.')' : ''));
412 
413  // Call trigger
414  $result = $this->call_trigger('USERGROUP_MODIFY', $user);
415  if ($result < 0) {
416  $error++;
417  }
418  // End call triggers
419  }
420  }
421 
422  if ($error) {
423  $this->db->rollback();
424  return -$error;
425  } else {
426  $this->db->commit();
427  return 1;
428  }
429  }
430 
431 
441  public function delrights($rid, $allmodule = '', $allperms = '', $entity = 0)
442  {
443  global $conf, $user, $langs;
444 
445  $error = 0;
446  $wherefordel = '';
447 
448  $entity = (!empty($entity) ? $entity : $conf->entity);
449 
450  $this->db->begin();
451 
452  if (!empty($rid)) {
453  $module = $perms = $subperms = '';
454 
455  // Si on a demande supression d'un droit en particulier, on recupere
456  // les caracteristiques module, perms et subperms de ce droit.
457  $sql = "SELECT module, perms, subperms";
458  $sql .= " FROM ".$this->db->prefix()."rights_def";
459  $sql .= " WHERE id = ".((int) $rid);
460  $sql .= " AND entity = ".((int) $entity);
461 
462  $result = $this->db->query($sql);
463  if ($result) {
464  $obj = $this->db->fetch_object($result);
465  if ($obj) {
466  $module = $obj->module;
467  $perms = $obj->perms;
468  $subperms = $obj->subperms;
469  }
470  } else {
471  $error++;
472  dol_print_error($this->db);
473  }
474 
475  // Where for the list of permissions to delete
476  $wherefordel = "id = ".((int) $rid);
477  // Suppression des droits induits
478  if ($subperms == 'lire' || $subperms == 'read') {
479  $wherefordel .= " OR (module='".$this->db->escape($module)."' AND perms='".$this->db->escape($perms)."' AND subperms IS NOT NULL)";
480  }
481  if ($perms == 'lire' || $perms == 'read') {
482  $wherefordel .= " OR (module='".$this->db->escape($module)."')";
483  }
484 
485  // Pour compatibilite, si lowid = 0, on est en mode suppression de tout
486  // TODO A virer quand sera gere par l'appelant
487  //if (substr($rid,-1,1) == 0) $wherefordel="module='$module'";
488  } else {
489  // Add permission of the list $wherefordel
490  if (!empty($allmodule)) {
491  if ($allmodule == 'allmodules') {
492  $wherefordel = 'allmodules';
493  } else {
494  $wherefordel = "module='".$this->db->escape($allmodule)."'";
495  if (!empty($allperms)) {
496  $wherefordel .= " AND perms='".$this->db->escape($allperms)."'";
497  }
498  }
499  }
500  }
501 
502  // Suppression des droits de la liste wherefordel
503  if (!empty($wherefordel)) {
504  //print "$module-$perms-$subperms";
505  $sql = "SELECT id";
506  $sql .= " FROM ".$this->db->prefix()."rights_def";
507  $sql .= " WHERE entity = ".((int) $entity);
508  if (!empty($wherefordel) && $wherefordel != 'allmodules') {
509  $sql .= " AND ".$wherefordel;
510  }
511 
512  $result = $this->db->query($sql);
513  if ($result) {
514  $num = $this->db->num_rows($result);
515  $i = 0;
516  while ($i < $num) {
517  $nid = 0;
518 
519  $obj = $this->db->fetch_object($result);
520  if ($obj) {
521  $nid = $obj->id;
522  }
523 
524  $sql = "DELETE FROM ".$this->db->prefix()."usergroup_rights";
525  $sql .= " WHERE fk_usergroup = $this->id AND fk_id=".((int) $nid);
526  $sql .= " AND entity = ".((int) $entity);
527  if (!$this->db->query($sql)) {
528  $error++;
529  }
530 
531  $i++;
532  }
533  } else {
534  $error++;
535  dol_print_error($this->db);
536  }
537 
538  if (!$error) {
539  $langs->load("other");
540  $this->context = array('audit'=>$langs->trans("PermissionsDelete").($rid ? ' (id='.$rid.')' : ''));
541 
542  // Call trigger
543  $result = $this->call_trigger('USERGROUP_MODIFY', $user);
544  if ($result < 0) {
545  $error++;
546  }
547  // End call triggers
548  }
549  }
550 
551  if ($error) {
552  $this->db->rollback();
553  return -$error;
554  } else {
555  $this->db->commit();
556  return 1;
557  }
558  }
559 
560 
567  public function getrights($moduletag = '')
568  {
569  global $conf;
570 
571  if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
572  // Rights for this module are already loaded, so we leave
573  return 0;
574  }
575 
576  if (!empty($this->all_permissions_are_loaded)) {
577  // We already loaded all rights for this group, so we leave
578  return 0;
579  }
580 
581  /*
582  * Recuperation des droits
583  */
584  $sql = "SELECT r.module, r.perms, r.subperms ";
585  $sql .= " FROM ".$this->db->prefix()."usergroup_rights as u, ".$this->db->prefix()."rights_def as r";
586  $sql .= " WHERE r.id = u.fk_id";
587  $sql .= " AND r.entity = ".((int) $conf->entity);
588  $sql .= " AND u.entity = ".((int) $conf->entity);
589  $sql .= " AND u.fk_usergroup = ".((int) $this->id);
590  $sql .= " AND r.perms IS NOT NULL";
591  if ($moduletag) {
592  $sql .= " AND r.module = '".$this->db->escape($moduletag)."'";
593  }
594 
595  dol_syslog(get_class($this).'::getrights', LOG_DEBUG);
596  $resql = $this->db->query($sql);
597  if ($resql) {
598  $num = $this->db->num_rows($resql);
599  $i = 0;
600  while ($i < $num) {
601  $obj = $this->db->fetch_object($resql);
602 
603  if ($obj) {
604  $module = $obj->module;
605  $perms = $obj->perms;
606  $subperms = $obj->subperms;
607 
608  if ($perms) {
609  if (!isset($this->rights)) {
610  $this->rights = new stdClass(); // For avoid error
611  }
612  if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
613  $this->rights->$module = new stdClass();
614  }
615  if ($subperms) {
616  if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
617  $this->rights->$module->$perms = new stdClass();
618  }
619  if (empty($this->rights->$module->$perms->$subperms)) {
620  $this->nb_rights++;
621  }
622  $this->rights->$module->$perms->$subperms = 1;
623  } else {
624  if (empty($this->rights->$module->$perms)) {
625  $this->nb_rights++;
626  }
627  $this->rights->$module->$perms = 1;
628  }
629  }
630  }
631 
632  $i++;
633  }
634  $this->db->free($resql);
635  }
636 
637  if ($moduletag == '') {
638  // Si module etait non defini, alors on a tout charge, on peut donc considerer
639  // que les droits sont en cache (car tous charges) pour cet instance de group
640  $this->all_permissions_are_loaded = 1;
641  } else {
642  // If module defined, we flag it as loaded into cache
643  $this->_tab_loaded[$moduletag] = 1;
644  }
645 
646  return 1;
647  }
648 
655  public function delete(User $user)
656  {
657  return $this->deleteCommon($user);
658  }
659 
666  public function create($notrigger = 0)
667  {
668  global $user, $conf;
669 
670  $this->datec = dol_now();
671  if (!empty($this->name)) {
672  $this->nom = $this->name; // Field for 'name' is called 'nom' in database
673  }
674 
675  if (!isset($this->entity)) {
676  $this->entity = $conf->entity; // If not defined, we use default value
677  }
678 
679  return $this->createCommon($user, $notrigger);
680  }
681 
688  public function update($notrigger = 0)
689  {
690  global $user, $conf;
691 
692  if (!empty($this->name)) {
693  $this->nom = $this->name; // Field for 'name' is called 'nom' in database
694  }
695 
696  return $this->updateCommon($user, $notrigger);
697  }
698 
699 
706  public function getLibStatut($mode = 0)
707  {
708  return $this->LibStatut(0, $mode);
709  }
710 
711  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
719  public function LibStatut($status, $mode = 0)
720  {
721  // phpcs:enable
722  global $langs;
723  $langs->load('users');
724  return '';
725  }
726 
734  public function getTooltipContentArray($params)
735  {
736  global $conf, $langs, $menumanager;
737 
738  $option = $params['option'] ?? '';
739 
740  $datas = [];
741  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
742  $langs->load("users");
743  return ['optimize' => $langs->trans("ShowGroup")];
744  }
745  $datas['divopen'] = '<div class="centpercent">';
746  $datas['picto'] = img_picto('', 'group').' <u>'.$langs->trans("Group").'</u><br>';
747  $datas['name'] = '<b>'.$langs->trans('Name').':</b> '.$this->name;
748  $datas['description'] = '<br><b>'.$langs->trans("Description").':</b> '.$this->note;
749  $datas['divclose'] = '</div>';
750 
751  return $datas;
752  }
753 
765  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
766  {
767  global $langs, $conf, $db, $hookmanager;
768  global $dolibarr_main_authentication, $dolibarr_main_demo;
769  global $menumanager;
770 
771  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpicto) {
772  $withpicto = 0;
773  }
774 
775  $result = '';
776  $params = [
777  'id' => $this->id,
778  'objecttype' => $this->element,
779  'option' => $option,
780  ];
781  $classfortooltip = 'classfortooltip';
782  $dataparams = '';
783  if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
784  $classfortooltip = 'classforajaxtooltip';
785  $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
786  $label = '';
787  } else {
788  $label = implode($this->getTooltipContentArray($params));
789  }
790 
791  if ($option == 'permissions') {
792  $url = DOL_URL_ROOT.'/user/group/perms.php?id='.$this->id;
793  } else {
794  $url = DOL_URL_ROOT.'/user/group/card.php?id='.$this->id;
795  }
796 
797  if ($option != 'nolink') {
798  // Add param to save lastsearch_values or not
799  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
800  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
801  $add_save_lastsearch_values = 1;
802  }
803  if ($add_save_lastsearch_values) {
804  $url .= '&save_lastsearch_values=1';
805  }
806  }
807 
808  $linkclose = "";
809  if (empty($notooltip)) {
810  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
811  $langs->load("users");
812  $label = $langs->trans("ShowGroup");
813  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1, 1).'"';
814  }
815  $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
816  $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
817  }
818 
819  $linkstart = '<a href="'.$url.'"';
820  $linkstart .= $linkclose.'>';
821  $linkend = '</a>';
822 
823  $result = $linkstart;
824  if ($withpicto) {
825  $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);
826  }
827  if ($withpicto != 2) {
828  $result .= $this->name;
829  }
830  $result .= $linkend;
831 
832  global $action;
833  $hookmanager->initHooks(array('groupdao'));
834  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
835  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
836  if ($reshook > 0) {
837  $result = $hookmanager->resPrint;
838  } else {
839  $result .= $hookmanager->resPrint;
840  }
841 
842  return $result;
843  }
844 
845  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
846  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
856  public function _load_ldap_dn($info, $mode = 0)
857  {
858  // phpcs:enable
859  global $conf;
860  $dn = '';
861  if ($mode == 0) {
862  $dn = $conf->global->LDAP_KEY_GROUPS."=".$info[$conf->global->LDAP_KEY_GROUPS].",".$conf->global->LDAP_GROUP_DN;
863  }
864  if ($mode == 1) {
865  $dn = $conf->global->LDAP_GROUP_DN;
866  }
867  if ($mode == 2) {
868  $dn = $conf->global->LDAP_KEY_GROUPS."=".$info[$conf->global->LDAP_KEY_GROUPS];
869  }
870  return $dn;
871  }
872 
873 
874  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
875  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
881  public function _load_ldap_info()
882  {
883  // phpcs:enable
884  global $conf;
885 
886  $info = array();
887 
888  // Object classes
889  $info["objectclass"] = explode(',', $conf->global->LDAP_GROUP_OBJECT_CLASS);
890 
891  // Champs
892  if ($this->name && !empty($conf->global->LDAP_GROUP_FIELD_FULLNAME)) {
893  $info[$conf->global->LDAP_GROUP_FIELD_FULLNAME] = $this->name;
894  }
895  //if ($this->name && !empty($conf->global->LDAP_GROUP_FIELD_NAME)) $info[$conf->global->LDAP_GROUP_FIELD_NAME] = $this->name;
896  if ($this->note && !empty($conf->global->LDAP_GROUP_FIELD_DESCRIPTION)) {
897  $info[$conf->global->LDAP_GROUP_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note, 2);
898  }
899  if (!empty($conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS)) {
900  $valueofldapfield = array();
901  foreach ($this->members as $key => $val) { // This is array of users for group into dolibarr database.
902  $muser = new User($this->db);
903  $muser->fetch($val->id);
904  $info2 = $muser->_load_ldap_info();
905  $valueofldapfield[] = $muser->_load_ldap_dn($info2);
906  }
907  $info[$conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS] = (!empty($valueofldapfield) ? $valueofldapfield : '');
908  }
909  if (!empty($conf->global->LDAP_GROUP_FIELD_GROUPID)) {
910  $info[$conf->global->LDAP_GROUP_FIELD_GROUPID] = $this->id;
911  }
912  return $info;
913  }
914 
915 
923  public function initAsSpecimen()
924  {
925  global $conf, $user, $langs;
926 
927  // Initialise parametres
928  $this->id = 0;
929  $this->ref = 'SPECIMEN';
930  $this->specimen = 1;
931 
932  $this->name = 'DOLIBARR GROUP SPECIMEN';
933  $this->note = 'This is a note';
934  $this->datec = time();
935  $this->tms = time();
936 
937  // Members of this group is just me
938  $this->members = array(
939  $user->id => $user
940  );
941  }
942 
954  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
955  {
956  global $conf, $user, $langs;
957 
958  $langs->load("user");
959 
960  // Positionne le modele sur le nom du modele a utiliser
961  if (!dol_strlen($modele)) {
962  if (!empty($conf->global->USERGROUP_ADDON_PDF)) {
963  $modele = $conf->global->USERGROUP_ADDON_PDF;
964  } else {
965  $modele = 'grass';
966  }
967  }
968 
969  $modelpath = "core/modules/usergroup/doc/";
970 
971  return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
972  }
973 
981  public function getKanbanView($option = '', $arraydata = null)
982  {
983  global $langs;
984 
985  $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
986 
987  $return = '<div class="box-flex-item box-flex-grow-zero">';
988  $return .= '<div class="info-box info-box-sm">';
989  $return .= '<span class="info-box-icon bg-infobox-action">';
990  $return .= img_picto('', $this->picto);
991  $return .= '</span>';
992  $return .= '<div class="info-box-content">';
993  $return .= '<span class="info-box-ref">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
994  $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
995  if (property_exists($this, 'members')) {
996  $return .= '<br><span class="info-box-status opacitymedium">'.(empty($this->nb_users) ? 0 : $this->nb_users).' '.$langs->trans('Users').'</span>';
997  }
998  if (property_exists($this, 'nb_rights')) {
999  $return .= '<br><div class="info-box-status margintoponly opacitymedium">'.$langs->trans('NbOfPermissions').' : '.(empty($this->nb_rights) ? 0 : $this->nb_rights).'</div>';
1000  }
1001  $return .= '</div>';
1002  $return .= '</div>';
1003  $return .= '</div>';
1004  return $return;
1005  }
1006 }
UserGroup\getrights
getrights($moduletag='')
Charge dans l'objet group, la liste des permissions auquels le groupe a droit.
Definition: usergroup.class.php:567
CommonObject\deleteCommon
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
Definition: commonobject.class.php:9776
CommonObject\fetchCommon
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9566
UserGroup\getLibStatut
getLibStatut($mode=0)
Return the label of the status.
Definition: usergroup.class.php:706
UserGroup\addrights
addrights($rid, $allmodule='', $allperms='', $entity=0)
Add a permission to a group.
Definition: usergroup.class.php:318
UserGroup\initAsSpecimen
initAsSpecimen()
Initialise an instance with random values.
Definition: usergroup.class.php:923
UserGroup\delrights
delrights($rid, $allmodule='', $allperms='', $entity=0)
Remove a permission from group.
Definition: usergroup.class.php:441
UserGroup\getKanbanView
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
Definition: usergroup.class.php:981
$sql
if(isModEnabled('facture') &&!empty($user->rights->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') &&!empty($user->rights->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:745
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:5052
UserGroup
Class to manage user groups.
Definition: usergroup.class.php:40
name
$conf db name
Definition: repair.php:123
UserGroup\listGroupsForUser
listGroupsForUser($userid, $load_members=true)
Return array of groups objects for a particular user.
Definition: usergroup.class.php:194
CommonObject
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Definition: commonobject.class.php:45
UserGroup\generateDocument
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
Definition: usergroup.class.php:954
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:4082
CommonObject\commonGenerateDocument
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
Definition: commonobject.class.php:5572
UserGroup\__construct
__construct($db)
Constructor de la classe.
Definition: usergroup.class.php:146
CommonObject\createCommon
createCommon(User $user, $notrigger=false)
Create object into database.
Definition: commonobject.class.php:9399
UserGroup\getNomUrl
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,...
Definition: usergroup.class.php:765
dol_string_nohtmltag
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
Definition: functions.lib.php:6988
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1689
UserGroup\fetch
fetch($id='', $groupname='', $load_members=false)
Charge un objet group avec toutes ses caracteristiques (except ->members array)
Definition: usergroup.class.php:161
UserGroup\LibStatut
LibStatut($status, $mode=0)
Return the label of a given status.
Definition: usergroup.class.php:719
CommonObject\updateCommon
updateCommon(User $user, $notrigger=false)
Update object into database.
Definition: commonobject.class.php:9672
UserGroup\getTooltipContentArray
getTooltipContentArray($params)
getTooltipContentArray
Definition: usergroup.class.php:734
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3944
UserGroup\update
update($notrigger=0)
Update group into database.
Definition: usergroup.class.php:688
UserGroup\create
create($notrigger=0)
Create group into database.
Definition: usergroup.class.php:666
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:167
UserGroup\listUsersForGroup
listUsersForGroup($excludefilter='', $mode=0)
Return array of User objects for group this->id (or all if this->id not defined)
Definition: usergroup.class.php:241
ref
$object ref
Definition: info.php:78
User
Class to manage Dolibarr users.
Definition: user.class.php:46
UserGroup\_load_ldap_dn
_load_ldap_dn($info, $mode=0)
Retourne chaine DN complete dans l'annuaire LDAP pour l'objet.
Definition: usergroup.class.php:856
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4419
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:3003
UserGroup\_load_ldap_info
_load_ldap_info()
Initialize the info array (array of LDAP values) that will be used to call LDAP functions.
Definition: usergroup.class.php:881
CommonObject\call_trigger
call_trigger($triggerName, $user)
Call trigger based on this instance.
Definition: commonobject.class.php:5981
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:116