dolibarr  13.0.2
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  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <https://www.gnu.org/licenses/>.
23  */
24 
30 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
31 if (!empty($conf->ldap->enabled)) require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
32 
33 
37 class UserGroup extends CommonObject
38 {
42  public $element = 'usergroup';
43 
47  public $table_element = 'usergroup';
48 
53  public $ismultientitymanaged = 1;
54 
58  public $picto = 'group';
59 
63  public $entity;
64 
70  public $nom;
71 
75  public $name; // Name of group
76 
77  public $globalgroup; // Global group
78 
84  public $datec;
85 
91  public $datem;
92 
96  public $note;
97 
98  public $members = array(); // Array of users
99 
100  public $nb_rights; // Number of rights granted to the user
101 
102  private $_tab_loaded = array(); // Array of cache of already loaded permissions
103 
104  public $oldcopy; // To contains a clone of this when we need to save old properties of object
105 
106  public $fields = array(
107  'rowid'=>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'),
108  'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'notnull'=> 1, 'default'=>1, 'index'=>1, 'position'=>5),
109  'nom'=>array('type'=>'varchar(180)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Group name'),
110  'note' => array('type'=>'html', 'label'=>'Description', 'enabled'=>1, 'visible'=>1, 'position'=>20, 'notnull'=>-1,),
111  'datec' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>50, 'notnull'=>1,),
112  'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'position'=>60, 'notnull'=>1,),
113  'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'ModelPDF', 'enabled'=>1, 'visible'=>0, 'position'=>100),
114  );
115 
119  public $fk_element = 'fk_usergroup';
120 
124  protected $childtables = array();
125 
129  protected $childtablesoncascade = array('usergroup_rights', 'usergroup_user');
130 
131 
137  public function __construct($db)
138  {
139  $this->db = $db;
140  $this->nb_rights = 0;
141  }
142 
143 
152  public function fetch($id = '', $groupname = '', $load_members = true)
153  {
154  global $conf;
155 
156  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
157  if (!empty($groupname))
158  {
159  $result = $this->fetchCommon(0, '', ' AND nom = \''.$this->db->escape($groupname).'\'');
160  } else {
161  $result = $this->fetchCommon($id);
162  }
163 
164  $this->name = $this->nom; // For compatibility with field name
165 
166  if ($result)
167  {
168  if ($load_members)
169  {
170  $this->members = $this->listUsersForGroup();
171  }
172 
173  return 1;
174  } else {
175  $this->error = $this->db->lasterror();
176  return -1;
177  }
178  }
179 
180 
188  public function listGroupsForUser($userid, $load_members = true)
189  {
190  global $conf, $user;
191 
192  $ret = array();
193 
194  $sql = "SELECT g.rowid, ug.entity as usergroup_entity";
195  $sql .= " FROM ".MAIN_DB_PREFIX."usergroup as g,";
196  $sql .= " ".MAIN_DB_PREFIX."usergroup_user as ug";
197  $sql .= " WHERE ug.fk_usergroup = g.rowid";
198  $sql .= " AND ug.fk_user = ".$userid;
199  if (!empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && !$user->entity)
200  {
201  $sql .= " AND g.entity IS NOT NULL";
202  } else {
203  $sql .= " AND g.entity IN (0,".$conf->entity.")";
204  }
205  $sql .= " ORDER BY g.nom";
206 
207  dol_syslog(get_class($this)."::listGroupsForUser", LOG_DEBUG);
208  $result = $this->db->query($sql);
209  if ($result)
210  {
211  while ($obj = $this->db->fetch_object($result))
212  {
213  if (!array_key_exists($obj->rowid, $ret))
214  {
215  $newgroup = new UserGroup($this->db);
216  $newgroup->fetch($obj->rowid, '', $load_members);
217  $ret[$obj->rowid] = $newgroup;
218  }
219 
220  $ret[$obj->rowid]->usergroup_entity[] = $obj->usergroup_entity;
221  }
222 
223  $this->db->free($result);
224 
225  return $ret;
226  } else {
227  $this->error = $this->db->lasterror();
228  return -1;
229  }
230  }
231 
239  public function listUsersForGroup($excludefilter = '', $mode = 0)
240  {
241  global $conf, $user;
242 
243  $ret = array();
244 
245  $sql = "SELECT u.rowid";
246  if (!empty($this->id)) $sql .= ", ug.entity as usergroup_entity";
247  $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
248  if (!empty($this->id)) $sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
249  $sql .= " WHERE 1 = 1";
250  if (!empty($this->id)) $sql .= " AND ug.fk_user = u.rowid";
251  if (!empty($this->id)) $sql .= " AND ug.fk_usergroup = ".$this->id;
252  if (!empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && !$user->entity)
253  {
254  $sql .= " AND u.entity IS NOT NULL";
255  } else {
256  $sql .= " AND u.entity IN (0,".$conf->entity.")";
257  }
258  if (!empty($excludefilter)) $sql .= ' AND ('.$excludefilter.')';
259 
260  dol_syslog(get_class($this)."::listUsersForGroup", LOG_DEBUG);
261  $resql = $this->db->query($sql);
262  if ($resql)
263  {
264  while ($obj = $this->db->fetch_object($resql))
265  {
266  if (!array_key_exists($obj->rowid, $ret))
267  {
268  if ($mode != 1)
269  {
270  $newuser = new User($this->db);
271  $newuser->fetch($obj->rowid);
272  $ret[$obj->rowid] = $newuser;
273  } else $ret[$obj->rowid] = $obj->rowid;
274  }
275  if ($mode != 1 && !empty($obj->usergroup_entity))
276  {
277  $ret[$obj->rowid]->usergroup_entity[] = $obj->usergroup_entity;
278  }
279  }
280 
281  $this->db->free($resql);
282 
283  return $ret;
284  } else {
285  $this->error = $this->db->lasterror();
286  return -1;
287  }
288  }
289 
299  public function addrights($rid, $allmodule = '', $allperms = '', $entity = 0)
300  {
301  global $conf, $user, $langs;
302 
303  $entity = (!empty($entity) ? $entity : $conf->entity);
304 
305  dol_syslog(get_class($this)."::addrights $rid, $allmodule, $allperms, $entity");
306  $error = 0;
307  $whereforadd = '';
308 
309  $this->db->begin();
310 
311  if (!empty($rid))
312  {
313  $module = $perms = $subperms = '';
314 
315  // Si on a demande ajout d'un droit en particulier, on recupere
316  // les caracteristiques (module, perms et subperms) de ce droit.
317  $sql = "SELECT module, perms, subperms";
318  $sql .= " FROM ".MAIN_DB_PREFIX."rights_def";
319  $sql .= " WHERE id = ".((int) $rid);
320  $sql .= " AND entity = ".((int) $entity);
321 
322  $result = $this->db->query($sql);
323  if ($result) {
324  $obj = $this->db->fetch_object($result);
325  if ($obj) {
326  $module = $obj->module;
327  $perms = $obj->perms;
328  $subperms = $obj->subperms;
329  }
330  } else {
331  $error++;
332  dol_print_error($this->db);
333  }
334 
335  // Where pour la liste des droits a ajouter
336  $whereforadd = "id=".((int) $rid);
337  // Find also rights that are herited to add them too
338  if ($subperms) $whereforadd .= " OR (module='".$this->db->escape($module)."' AND perms='".$this->db->escape($perms)."' AND (subperms='lire' OR subperms='read'))";
339  elseif ($perms) $whereforadd .= " OR (module='".$this->db->escape($module)."' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
340  } else {
341  // Where pour la liste des droits a ajouter
342  if (!empty($allmodule))
343  {
344  if ($allmodule == 'allmodules')
345  {
346  $whereforadd = 'allmodules';
347  } else {
348  $whereforadd = "module='".$this->db->escape($allmodule)."'";
349  if (!empty($allperms)) $whereforadd .= " AND perms='".$this->db->escape($allperms)."'";
350  }
351  }
352  }
353 
354  // Add permission of the list $whereforadd
355  if (!empty($whereforadd))
356  {
357  //print "$module-$perms-$subperms";
358  $sql = "SELECT id";
359  $sql .= " FROM ".MAIN_DB_PREFIX."rights_def";
360  $sql .= " WHERE entity = ".$entity;
361  if (!empty($whereforadd) && $whereforadd != 'allmodules') {
362  $sql .= " AND ".$whereforadd;
363  }
364 
365  $result = $this->db->query($sql);
366  if ($result)
367  {
368  $num = $this->db->num_rows($result);
369  $i = 0;
370  while ($i < $num)
371  {
372  $obj = $this->db->fetch_object($result);
373  $nid = $obj->id;
374 
375  $sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup_rights WHERE fk_usergroup = $this->id AND fk_id=".$nid." AND entity = ".$entity;
376  if (!$this->db->query($sql)) $error++;
377  $sql = "INSERT INTO ".MAIN_DB_PREFIX."usergroup_rights (entity, fk_usergroup, fk_id) VALUES (".$entity.", ".$this->id.", ".$nid.")";
378  if (!$this->db->query($sql)) $error++;
379 
380  $i++;
381  }
382  } else {
383  $error++;
384  dol_print_error($this->db);
385  }
386 
387  if (!$error)
388  {
389  $langs->load("other");
390  $this->context = array('audit'=>$langs->trans("PermissionsAdd").($rid ? ' (id='.$rid.')' : ''));
391 
392  // Call trigger
393  $result = $this->call_trigger('USERGROUP_MODIFY', $user);
394  if ($result < 0) { $error++; }
395  // End call triggers
396  }
397  }
398 
399  if ($error) {
400  $this->db->rollback();
401  return -$error;
402  } else {
403  $this->db->commit();
404  return 1;
405  }
406  }
407 
408 
418  public function delrights($rid, $allmodule = '', $allperms = '', $entity = 0)
419  {
420  global $conf, $user, $langs;
421 
422  $error = 0;
423  $wherefordel = '';
424 
425  $entity = (!empty($entity) ? $entity : $conf->entity);
426 
427  $this->db->begin();
428 
429  if (!empty($rid))
430  {
431  $module = $perms = $subperms = '';
432 
433  // Si on a demande supression d'un droit en particulier, on recupere
434  // les caracteristiques module, perms et subperms de ce droit.
435  $sql = "SELECT module, perms, subperms";
436  $sql .= " FROM ".MAIN_DB_PREFIX."rights_def";
437  $sql .= " WHERE id = '".$this->db->escape($rid)."'";
438  $sql .= " AND entity = ".$entity;
439 
440  $result = $this->db->query($sql);
441  if ($result) {
442  $obj = $this->db->fetch_object($result);
443  if ($obj) {
444  $module = $obj->module;
445  $perms = $obj->perms;
446  $subperms = $obj->subperms;
447  }
448  } else {
449  $error++;
450  dol_print_error($this->db);
451  }
452 
453  // Where pour la liste des droits a supprimer
454  $wherefordel = "id=".$this->db->escape($rid);
455  // Suppression des droits induits
456  if ($subperms == 'lire' || $subperms == 'read') $wherefordel .= " OR (module='".$this->db->escape($module)."' AND perms='".$this->db->escape($perms)."' AND subperms IS NOT NULL)";
457  if ($perms == 'lire' || $perms == 'read') $wherefordel .= " OR (module='".$this->db->escape($module)."')";
458 
459  // Pour compatibilite, si lowid = 0, on est en mode suppression de tout
460  // TODO A virer quand sera gere par l'appelant
461  //if (substr($rid,-1,1) == 0) $wherefordel="module='$module'";
462  } else {
463  // Add permission of the list $wherefordel
464  if (!empty($allmodule))
465  {
466  if ($allmodule == 'allmodules')
467  {
468  $wherefordel = 'allmodules';
469  } else {
470  $wherefordel = "module='".$this->db->escape($allmodule)."'";
471  if (!empty($allperms)) $wherefordel .= " AND perms='".$this->db->escape($allperms)."'";
472  }
473  }
474  }
475 
476  // Suppression des droits de la liste wherefordel
477  if (!empty($wherefordel))
478  {
479  //print "$module-$perms-$subperms";
480  $sql = "SELECT id";
481  $sql .= " FROM ".MAIN_DB_PREFIX."rights_def";
482  $sql .= " WHERE entity = ".$entity;
483  if (!empty($wherefordel) && $wherefordel != 'allmodules') {
484  $sql .= " AND ".$wherefordel;
485  }
486 
487  $result = $this->db->query($sql);
488  if ($result)
489  {
490  $num = $this->db->num_rows($result);
491  $i = 0;
492  while ($i < $num)
493  {
494  $nid = 0;
495 
496  $obj = $this->db->fetch_object($result);
497  if ($obj) {
498  $nid = $obj->id;
499  }
500 
501  $sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup_rights";
502  $sql .= " WHERE fk_usergroup = $this->id AND fk_id=".$nid;
503  $sql .= " AND entity = ".$entity;
504  if (!$this->db->query($sql)) $error++;
505 
506  $i++;
507  }
508  } else {
509  $error++;
510  dol_print_error($this->db);
511  }
512 
513  if (!$error)
514  {
515  $langs->load("other");
516  $this->context = array('audit'=>$langs->trans("PermissionsDelete").($rid ? ' (id='.$rid.')' : ''));
517 
518  // Call trigger
519  $result = $this->call_trigger('USERGROUP_MODIFY', $user);
520  if ($result < 0) { $error++; }
521  // End call triggers
522  }
523  }
524 
525  if ($error) {
526  $this->db->rollback();
527  return -$error;
528  } else {
529  $this->db->commit();
530  return 1;
531  }
532  }
533 
534 
541  public function getrights($moduletag = '')
542  {
543  global $conf;
544 
545  if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag])
546  {
547  // Rights for this module are already loaded, so we leave
548  return;
549  }
550 
551  if (!empty($this->all_permissions_are_loaded))
552  {
553  // We already loaded all rights for this group, so we leave
554  return;
555  }
556 
557  /*
558  * Recuperation des droits
559  */
560  $sql = "SELECT r.module, r.perms, r.subperms ";
561  $sql .= " FROM ".MAIN_DB_PREFIX."usergroup_rights as u, ".MAIN_DB_PREFIX."rights_def as r";
562  $sql .= " WHERE r.id = u.fk_id";
563  $sql .= " AND r.entity = ".$conf->entity;
564  $sql .= " AND u.entity = ".$conf->entity;
565  $sql .= " AND u.fk_usergroup = ".$this->id;
566  $sql .= " AND r.perms IS NOT NULL";
567  if ($moduletag) $sql .= " AND r.module = '".$this->db->escape($moduletag)."'";
568 
569  dol_syslog(get_class($this).'::getrights', LOG_DEBUG);
570  $resql = $this->db->query($sql);
571  if ($resql)
572  {
573  $num = $this->db->num_rows($resql);
574  $i = 0;
575  while ($i < $num)
576  {
577  $obj = $this->db->fetch_object($resql);
578 
579  if ($obj) {
580  $module = $obj->module;
581  $perms = $obj->perms;
582  $subperms = $obj->subperms;
583 
584  if ($perms)
585  {
586  if (!isset($this->rights)) $this->rights = new stdClass(); // For avoid error
587  if (!isset($this->rights->$module) || !is_object($this->rights->$module)) $this->rights->$module = new stdClass();
588  if ($subperms)
589  {
590  if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) $this->rights->$module->$perms = new stdClass();
591  if (empty($this->rights->$module->$perms->$subperms)) $this->nb_rights++;
592  $this->rights->$module->$perms->$subperms = 1;
593  } else {
594  if (empty($this->rights->$module->$perms)) $this->nb_rights++;
595  $this->rights->$module->$perms = 1;
596  }
597  }
598  }
599 
600  $i++;
601  }
602  $this->db->free($resql);
603  }
604 
605  if ($moduletag == '')
606  {
607  // Si module etait non defini, alors on a tout charge, on peut donc considerer
608  // que les droits sont en cache (car tous charges) pour cet instance de group
609  $this->all_permissions_are_loaded = 1;
610  } else {
611  // If module defined, we flag it as loaded into cache
612  $this->_tab_loaded[$moduletag] = 1;
613  }
614 
615  return 1;
616  }
617 
624  public function delete(User $user)
625  {
626  return $this->deleteCommon($user);
627  }
628 
635  public function create($notrigger = 0)
636  {
637  global $user, $conf;
638 
639  $this->datec = dol_now();
640  if (!empty($this->name)) {
641  $this->nom = $this->name; // Field for 'name' is called 'nom' in database
642  }
643 
644  if (!isset($this->entity)) $this->entity = $conf->entity; // If not defined, we use default value
645 
646  return $this->createCommon($user, $notrigger);
647  }
648 
655  public function update($notrigger = 0)
656  {
657  global $user, $conf;
658 
659  if (!empty($this->name)) {
660  $this->nom = $this->name; // Field for 'name' is called 'nom' in database
661  }
662 
663  return $this->updateCommon($user, $notrigger);
664  }
665 
666 
673  public function getLibStatut($mode = 0)
674  {
675  return $this->LibStatut(0, $mode);
676  }
677 
678  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
686  public function LibStatut($status, $mode = 0)
687  {
688  // phpcs:enable
689  global $langs;
690  $langs->load('users');
691  return '';
692  }
693 
705  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
706  {
707  global $langs, $conf, $db, $hookmanager;
708  global $dolibarr_main_authentication, $dolibarr_main_demo;
709  global $menumanager;
710 
711  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpicto) $withpicto = 0;
712 
713  $result = ''; $label = '';
714 
715  $label .= '<div class="centpercent">';
716  $label .= '<u>'.$langs->trans("Group").'</u><br>';
717  $label .= '<b>'.$langs->trans('Name').':</b> '.$this->name;
718  $label .= '<br><b>'.$langs->trans("Description").':</b> '.$this->note;
719  $label .= '</div>';
720 
721  $url = DOL_URL_ROOT.'/user/group/card.php?id='.$this->id;
722 
723  if ($option != 'nolink')
724  {
725  // Add param to save lastsearch_values or not
726  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
727  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
728  if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
729  }
730 
731  $linkclose = "";
732  if (empty($notooltip))
733  {
734  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
735  {
736  $langs->load("users");
737  $label = $langs->trans("ShowGroup");
738  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1, 1).'"';
739  }
740  $linkclose .= ' title="'.dol_escape_htmltag($label, 1, 1).'"';
741  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
742 
743  /*
744  $hookmanager->initHooks(array('groupdao'));
745  $parameters=array('id'=>$this->id);
746  $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
747  if ($reshook > 0) $linkclose = $hookmanager->resPrint;
748  */
749  }
750 
751  $linkstart = '<a href="'.$url.'"';
752  $linkstart .= $linkclose.'>';
753  $linkend = '</a>';
754 
755  $result = $linkstart;
756  if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
757  if ($withpicto != 2) $result .= $this->name;
758  $result .= $linkend;
759 
760  global $action;
761  $hookmanager->initHooks(array('groupdao'));
762  $parameters = array('id'=>$this->id, 'getnomurl'=>$result);
763  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
764  if ($reshook > 0) $result = $hookmanager->resPrint;
765  else $result .= $hookmanager->resPrint;
766 
767  return $result;
768  }
769 
770  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
771  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
781  public function _load_ldap_dn($info, $mode = 0)
782  {
783  // phpcs:enable
784  global $conf;
785  $dn = '';
786  if ($mode == 0) $dn = $conf->global->LDAP_KEY_GROUPS."=".$info[$conf->global->LDAP_KEY_GROUPS].",".$conf->global->LDAP_GROUP_DN;
787  if ($mode == 1) $dn = $conf->global->LDAP_GROUP_DN;
788  if ($mode == 2) $dn = $conf->global->LDAP_KEY_GROUPS."=".$info[$conf->global->LDAP_KEY_GROUPS];
789  return $dn;
790  }
791 
792 
793  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
794  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
800  public function _load_ldap_info()
801  {
802  // phpcs:enable
803  global $conf;
804 
805  $info = array();
806 
807  // Object classes
808  $info["objectclass"] = explode(',', $conf->global->LDAP_GROUP_OBJECT_CLASS);
809 
810  // Champs
811  if ($this->name && !empty($conf->global->LDAP_GROUP_FIELD_FULLNAME)) $info[$conf->global->LDAP_GROUP_FIELD_FULLNAME] = $this->name;
812  //if ($this->name && ! empty($conf->global->LDAP_GROUP_FIELD_NAME)) $info[$conf->global->LDAP_GROUP_FIELD_NAME] = $this->name;
813  if ($this->note && !empty($conf->global->LDAP_GROUP_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_GROUP_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note, 2);
814  if (!empty($conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS))
815  {
816  $valueofldapfield = array();
817  foreach ($this->members as $key=>$val) // This is array of users for group into dolibarr database.
818  {
819  $muser = new User($this->db);
820  $muser->fetch($val->id);
821  $info2 = $muser->_load_ldap_info();
822  $valueofldapfield[] = $muser->_load_ldap_dn($info2);
823  }
824  $info[$conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS] = (!empty($valueofldapfield) ? $valueofldapfield : '');
825  }
826  if (!empty($info[$conf->global->LDAP_GROUP_FIELD_GROUPID])) {
827  $info[$conf->global->LDAP_GROUP_FIELD_GROUPID] = $this->id;
828  }
829  return $info;
830  }
831 
832 
840  public function initAsSpecimen()
841  {
842  global $conf, $user, $langs;
843 
844  // Initialise parametres
845  $this->id = 0;
846  $this->ref = 'SPECIMEN';
847  $this->specimen = 1;
848 
849  $this->name = 'DOLIBARR GROUP SPECIMEN';
850  $this->note = 'This is a note';
851  $this->datec = time();
852  $this->datem = time();
853 
854  // Members of this group is just me
855  $this->members = array(
856  $user->id => $user
857  );
858  }
859 
871  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
872  {
873  global $conf, $user, $langs;
874 
875  $langs->load("user");
876 
877  // Positionne le modele sur le nom du modele a utiliser
878  if (!dol_strlen($modele))
879  {
880  if (!empty($conf->global->USERGROUP_ADDON_PDF))
881  {
882  $modele = $conf->global->USERGROUP_ADDON_PDF;
883  } else {
884  $modele = 'grass';
885  }
886  }
887 
888  $modelpath = "core/modules/usergroup/doc/";
889 
890  return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
891  }
892 }
getLibStatut($mode=0)
Return label of status of user (active, inactive)
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto= 'UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
delrights($rid, $allmodule= '', $allperms= '', $entity=0)
Remove a permission from group.
getrights($moduletag= '')
Charge dans l&#39;objet group, la liste des permissions auquels le groupe a droit.
initAsSpecimen()
Initialise an instance with random values.
listGroupsForUser($userid, $load_members=true)
Return array of groups objects for a particular user.
listUsersForGroup($excludefilter= '', $mode=0)
Return array of User objects for group this-&gt;id (or all if this-&gt;id not defined)
dol_now($mode= 'auto')
Return date for now.
getNomUrl($withpicto=0, $option= '', $notooltip=0, $morecss= '', $save_lastsearch_value=-1)
Return a link to the user card (with optionaly the picto) Use this-&gt;id,this-&gt;lastname, this-&gt;firstname.
Class to manage Dolibarr users.
Definition: user.class.php:44
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
createCommon(User $user, $notrigger=false)
Create object into database.
Class to manage user groups.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
$conf db
API class for accounts.
Definition: inc.php:54
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
if(!empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'] s nom
Definition: list.php:560
__construct($db)
Constructor de la classe.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
create($notrigger=0)
Create group into database.
updateCommon(User $user, $notrigger=false)
Update object into database.
print $_SERVER["PHP_SELF"]
Edit parameters.
LibStatut($status, $mode=0)
Renvoi le libelle d&#39;un statut donne.
update($notrigger=0)
Update group into database.
fetch($id= '', $groupname= '', $load_members=true)
Charge un objet group avec toutes ses caracteristiques (except -&gt;members array)
call_trigger($triggerName, $user)
Call trigger based on this instance.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
addrights($rid, $allmodule= '', $allperms= '', $entity=0)
Add a permission to a group.
_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&#39;annuaire LDAP pour l&#39;objet.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
if(!empty($search_group)) natural_search(array("g.nom"g note
Definition: list.php:122
fetchCommon($id, $ref=null, $morewhere= '')
Load object in memory from the database.