dolibarr  17.0.4
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)) {
32  require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
33 }
34 
35 
39 class UserGroup extends CommonObject
40 {
44  public $element = 'usergroup';
45 
49  public $table_element = 'usergroup';
50 
55  public $ismultientitymanaged = 1;
56 
60  public $picto = 'group';
61 
65  public $entity;
66 
72  public $nom;
73 
77  public $name; // Name of group
78 
79  public $globalgroup; // Global group
80 
86  public $datec;
87 
93  public $datem;
94 
98  public $note;
99 
100  public $members = array(); // Array of users
101 
102  public $nb_rights; // Number of rights granted to the user
103 
104  private $_tab_loaded = array(); // Array of cache of already loaded permissions
105 
106  public $oldcopy; // To contains a clone of this when we need to save old properties of object
107 
108  public $fields = array(
109  'rowid'=>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'),
110  'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'notnull'=> 1, 'default'=>1, 'index'=>1, 'position'=>5),
111  'nom'=>array('type'=>'varchar(180)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Group name'),
112  'note' => array('type'=>'html', 'label'=>'Description', 'enabled'=>1, 'visible'=>1, 'position'=>20, 'notnull'=>-1,),
113  'datec' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>50, 'notnull'=>1,),
114  'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'position'=>60, 'notnull'=>1,),
115  'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'ModelPDF', 'enabled'=>1, 'visible'=>0, 'position'=>100),
116  );
117 
121  public $fk_element = 'fk_usergroup';
122 
126  protected $childtables = array();
127 
131  protected $childtablesoncascade = array('usergroup_rights', 'usergroup_user');
132 
133 
139  public function __construct($db)
140  {
141  $this->db = $db;
142  $this->nb_rights = 0;
143  }
144 
145 
154  public function fetch($id = '', $groupname = '', $load_members = true)
155  {
156  global $conf;
157 
158  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
159  if (!empty($groupname)) {
160  $result = $this->fetchCommon(0, '', ' AND nom = \''.$this->db->escape($groupname).'\'');
161  } else {
162  $result = $this->fetchCommon($id);
163  }
164 
165  $this->name = $this->nom; // For compatibility with field name
166 
167  if ($result) {
168  if ($load_members) {
169  $this->members = $this->listUsersForGroup();
170  }
171 
172  return 1;
173  } else {
174  $this->error = $this->db->lasterror();
175  return -1;
176  }
177  }
178 
179 
187  public function listGroupsForUser($userid, $load_members = true)
188  {
189  global $conf, $user;
190 
191  $ret = array();
192 
193  $sql = "SELECT g.rowid, ug.entity as usergroup_entity";
194  $sql .= " FROM ".$this->db->prefix()."usergroup as g,";
195  $sql .= " ".$this->db->prefix()."usergroup_user as ug";
196  $sql .= " WHERE ug.fk_usergroup = g.rowid";
197  $sql .= " AND ug.fk_user = ".((int) $userid);
198  if (isModEnabled('multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
199  $sql .= " AND g.entity IS NOT NULL";
200  } else {
201  $sql .= " AND g.entity IN (0,".$conf->entity.")";
202  }
203  $sql .= " ORDER BY g.nom";
204 
205  dol_syslog(get_class($this)."::listGroupsForUser", LOG_DEBUG);
206  $result = $this->db->query($sql);
207  if ($result) {
208  while ($obj = $this->db->fetch_object($result)) {
209  if (!array_key_exists($obj->rowid, $ret)) {
210  $newgroup = new UserGroup($this->db);
211  $newgroup->fetch($obj->rowid, '', $load_members);
212  $ret[$obj->rowid] = $newgroup;
213  }
214 
215  $ret[$obj->rowid]->usergroup_entity[] = $obj->usergroup_entity;
216  }
217 
218  $this->db->free($result);
219 
220  return $ret;
221  } else {
222  $this->error = $this->db->lasterror();
223  return -1;
224  }
225  }
226 
234  public function listUsersForGroup($excludefilter = '', $mode = 0)
235  {
236  global $conf, $user;
237 
238  $ret = array();
239 
240  $sql = "SELECT u.rowid";
241  if (!empty($this->id)) {
242  $sql .= ", ug.entity as usergroup_entity";
243  }
244  $sql .= " FROM ".$this->db->prefix()."user as u";
245  if (!empty($this->id)) {
246  $sql .= ", ".$this->db->prefix()."usergroup_user as ug";
247  }
248  $sql .= " WHERE 1 = 1";
249  if (!empty($this->id)) {
250  $sql .= " AND ug.fk_user = u.rowid";
251  }
252  if (!empty($this->id)) {
253  $sql .= " AND ug.fk_usergroup = ".((int) $this->id);
254  }
255  if (isModEnabled('multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
256  $sql .= " AND u.entity IS NOT NULL";
257  } else {
258  $sql .= " AND u.entity IN (0,".$conf->entity.")";
259  }
260  if (!empty($excludefilter)) {
261  $sql .= ' AND ('.$excludefilter.')';
262  }
263 
264  dol_syslog(get_class($this)."::listUsersForGroup", LOG_DEBUG);
265  $resql = $this->db->query($sql);
266  if ($resql) {
267  while ($obj = $this->db->fetch_object($resql)) {
268  if (!array_key_exists($obj->rowid, $ret)) {
269  if ($mode != 1) {
270  $newuser = new User($this->db);
271  $newuser->fetch($obj->rowid);
272  $ret[$obj->rowid] = $newuser;
273  } else {
274  $ret[$obj->rowid] = $obj->rowid;
275  }
276  }
277  if ($mode != 1 && !empty($obj->usergroup_entity)) {
278  $ret[$obj->rowid]->usergroup_entity[] = $obj->usergroup_entity;
279  }
280  }
281 
282  $this->db->free($resql);
283 
284  return $ret;
285  } else {
286  $this->error = $this->db->lasterror();
287  return -1;
288  }
289  }
290 
300  public function addrights($rid, $allmodule = '', $allperms = '', $entity = 0)
301  {
302  global $conf, $user, $langs;
303 
304  $entity = (!empty($entity) ? $entity : $conf->entity);
305 
306  dol_syslog(get_class($this)."::addrights $rid, $allmodule, $allperms, $entity");
307  $error = 0;
308  $whereforadd = '';
309 
310  $this->db->begin();
311 
312  if (!empty($rid)) {
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 ".$this->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) {
339  $whereforadd .= " OR (module='".$this->db->escape($module)."' AND perms='".$this->db->escape($perms)."' AND (subperms='lire' OR subperms='read'))";
340  } elseif ($perms) {
341  $whereforadd .= " OR (module='".$this->db->escape($module)."' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
342  }
343  } else {
344  // Where pour la liste des droits a ajouter
345  if (!empty($allmodule)) {
346  if ($allmodule == 'allmodules') {
347  $whereforadd = 'allmodules';
348  } else {
349  $whereforadd = "module='".$this->db->escape($allmodule)."'";
350  if (!empty($allperms)) {
351  $whereforadd .= " AND perms='".$this->db->escape($allperms)."'";
352  }
353  }
354  }
355  }
356 
357  // Add permission of the list $whereforadd
358  if (!empty($whereforadd)) {
359  //print "$module-$perms-$subperms";
360  $sql = "SELECT id";
361  $sql .= " FROM ".$this->db->prefix()."rights_def";
362  $sql .= " WHERE entity = ".((int) $entity);
363  if (!empty($whereforadd) && $whereforadd != 'allmodules') {
364  $sql .= " AND ".$whereforadd;
365  }
366 
367  $result = $this->db->query($sql);
368  if ($result) {
369  $num = $this->db->num_rows($result);
370  $i = 0;
371  while ($i < $num) {
372  $obj = $this->db->fetch_object($result);
373  $nid = $obj->id;
374 
375  $sql = "DELETE FROM ".$this->db->prefix()."usergroup_rights WHERE fk_usergroup = ".((int) $this->id)." AND fk_id=".((int) $nid)." AND entity = ".((int) $entity);
376  if (!$this->db->query($sql)) {
377  $error++;
378  }
379  $sql = "INSERT INTO ".$this->db->prefix()."usergroup_rights (entity, fk_usergroup, fk_id) VALUES (".((int) $entity).", ".((int) $this->id).", ".((int) $nid).")";
380  if (!$this->db->query($sql)) {
381  $error++;
382  }
383 
384  $i++;
385  }
386  } else {
387  $error++;
388  dol_print_error($this->db);
389  }
390 
391  if (!$error) {
392  $langs->load("other");
393  $this->context = array('audit'=>$langs->trans("PermissionsAdd").($rid ? ' (id='.$rid.')' : ''));
394 
395  // Call trigger
396  $result = $this->call_trigger('USERGROUP_MODIFY', $user);
397  if ($result < 0) {
398  $error++;
399  }
400  // End call triggers
401  }
402  }
403 
404  if ($error) {
405  $this->db->rollback();
406  return -$error;
407  } else {
408  $this->db->commit();
409  return 1;
410  }
411  }
412 
413 
423  public function delrights($rid, $allmodule = '', $allperms = '', $entity = 0)
424  {
425  global $conf, $user, $langs;
426 
427  $error = 0;
428  $wherefordel = '';
429 
430  $entity = (!empty($entity) ? $entity : $conf->entity);
431 
432  $this->db->begin();
433 
434  if (!empty($rid)) {
435  $module = $perms = $subperms = '';
436 
437  // Si on a demande supression d'un droit en particulier, on recupere
438  // les caracteristiques module, perms et subperms de ce droit.
439  $sql = "SELECT module, perms, subperms";
440  $sql .= " FROM ".$this->db->prefix()."rights_def";
441  $sql .= " WHERE id = ".((int) $rid);
442  $sql .= " AND entity = ".((int) $entity);
443 
444  $result = $this->db->query($sql);
445  if ($result) {
446  $obj = $this->db->fetch_object($result);
447  if ($obj) {
448  $module = $obj->module;
449  $perms = $obj->perms;
450  $subperms = $obj->subperms;
451  }
452  } else {
453  $error++;
454  dol_print_error($this->db);
455  }
456 
457  // Where for the list of permissions to delete
458  $wherefordel = "id = ".((int) $rid);
459  // Suppression des droits induits
460  if ($subperms == 'lire' || $subperms == 'read') {
461  $wherefordel .= " OR (module='".$this->db->escape($module)."' AND perms='".$this->db->escape($perms)."' AND subperms IS NOT NULL)";
462  }
463  if ($perms == 'lire' || $perms == 'read') {
464  $wherefordel .= " OR (module='".$this->db->escape($module)."')";
465  }
466 
467  // Pour compatibilite, si lowid = 0, on est en mode suppression de tout
468  // TODO A virer quand sera gere par l'appelant
469  //if (substr($rid,-1,1) == 0) $wherefordel="module='$module'";
470  } else {
471  // Add permission of the list $wherefordel
472  if (!empty($allmodule)) {
473  if ($allmodule == 'allmodules') {
474  $wherefordel = 'allmodules';
475  } else {
476  $wherefordel = "module='".$this->db->escape($allmodule)."'";
477  if (!empty($allperms)) {
478  $wherefordel .= " AND perms='".$this->db->escape($allperms)."'";
479  }
480  }
481  }
482  }
483 
484  // Suppression des droits de la liste wherefordel
485  if (!empty($wherefordel)) {
486  //print "$module-$perms-$subperms";
487  $sql = "SELECT id";
488  $sql .= " FROM ".$this->db->prefix()."rights_def";
489  $sql .= " WHERE entity = ".((int) $entity);
490  if (!empty($wherefordel) && $wherefordel != 'allmodules') {
491  $sql .= " AND ".$wherefordel;
492  }
493 
494  $result = $this->db->query($sql);
495  if ($result) {
496  $num = $this->db->num_rows($result);
497  $i = 0;
498  while ($i < $num) {
499  $nid = 0;
500 
501  $obj = $this->db->fetch_object($result);
502  if ($obj) {
503  $nid = $obj->id;
504  }
505 
506  $sql = "DELETE FROM ".$this->db->prefix()."usergroup_rights";
507  $sql .= " WHERE fk_usergroup = $this->id AND fk_id=".((int) $nid);
508  $sql .= " AND entity = ".((int) $entity);
509  if (!$this->db->query($sql)) {
510  $error++;
511  }
512 
513  $i++;
514  }
515  } else {
516  $error++;
517  dol_print_error($this->db);
518  }
519 
520  if (!$error) {
521  $langs->load("other");
522  $this->context = array('audit'=>$langs->trans("PermissionsDelete").($rid ? ' (id='.$rid.')' : ''));
523 
524  // Call trigger
525  $result = $this->call_trigger('USERGROUP_MODIFY', $user);
526  if ($result < 0) {
527  $error++;
528  }
529  // End call triggers
530  }
531  }
532 
533  if ($error) {
534  $this->db->rollback();
535  return -$error;
536  } else {
537  $this->db->commit();
538  return 1;
539  }
540  }
541 
542 
549  public function getrights($moduletag = '')
550  {
551  global $conf;
552 
553  if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
554  // Rights for this module are already loaded, so we leave
555  return;
556  }
557 
558  if (!empty($this->all_permissions_are_loaded)) {
559  // We already loaded all rights for this group, so we leave
560  return;
561  }
562 
563  /*
564  * Recuperation des droits
565  */
566  $sql = "SELECT r.module, r.perms, r.subperms ";
567  $sql .= " FROM ".$this->db->prefix()."usergroup_rights as u, ".$this->db->prefix()."rights_def as r";
568  $sql .= " WHERE r.id = u.fk_id";
569  $sql .= " AND r.entity = ".((int) $conf->entity);
570  $sql .= " AND u.entity = ".((int) $conf->entity);
571  $sql .= " AND u.fk_usergroup = ".((int) $this->id);
572  $sql .= " AND r.perms IS NOT NULL";
573  if ($moduletag) {
574  $sql .= " AND r.module = '".$this->db->escape($moduletag)."'";
575  }
576 
577  dol_syslog(get_class($this).'::getrights', LOG_DEBUG);
578  $resql = $this->db->query($sql);
579  if ($resql) {
580  $num = $this->db->num_rows($resql);
581  $i = 0;
582  while ($i < $num) {
583  $obj = $this->db->fetch_object($resql);
584 
585  if ($obj) {
586  $module = $obj->module;
587  $perms = $obj->perms;
588  $subperms = $obj->subperms;
589 
590  if ($perms) {
591  if (!isset($this->rights)) {
592  $this->rights = new stdClass(); // For avoid error
593  }
594  if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
595  $this->rights->$module = new stdClass();
596  }
597  if ($subperms) {
598  if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
599  $this->rights->$module->$perms = new stdClass();
600  }
601  if (empty($this->rights->$module->$perms->$subperms)) {
602  $this->nb_rights++;
603  }
604  $this->rights->$module->$perms->$subperms = 1;
605  } else {
606  if (empty($this->rights->$module->$perms)) {
607  $this->nb_rights++;
608  }
609  $this->rights->$module->$perms = 1;
610  }
611  }
612  }
613 
614  $i++;
615  }
616  $this->db->free($resql);
617  }
618 
619  if ($moduletag == '') {
620  // Si module etait non defini, alors on a tout charge, on peut donc considerer
621  // que les droits sont en cache (car tous charges) pour cet instance de group
622  $this->all_permissions_are_loaded = 1;
623  } else {
624  // If module defined, we flag it as loaded into cache
625  $this->_tab_loaded[$moduletag] = 1;
626  }
627 
628  return 1;
629  }
630 
637  public function delete(User $user)
638  {
639  return $this->deleteCommon($user);
640  }
641 
648  public function create($notrigger = 0)
649  {
650  global $user, $conf;
651 
652  $this->datec = dol_now();
653  if (!empty($this->name)) {
654  $this->nom = $this->name; // Field for 'name' is called 'nom' in database
655  }
656 
657  if (!isset($this->entity)) {
658  $this->entity = $conf->entity; // If not defined, we use default value
659  }
660 
661  return $this->createCommon($user, $notrigger);
662  }
663 
670  public function update($notrigger = 0)
671  {
672  global $user, $conf;
673 
674  if (!empty($this->name)) {
675  $this->nom = $this->name; // Field for 'name' is called 'nom' in database
676  }
677 
678  return $this->updateCommon($user, $notrigger);
679  }
680 
681 
688  public function getLibStatut($mode = 0)
689  {
690  return $this->LibStatut(0, $mode);
691  }
692 
693  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
701  public function LibStatut($status, $mode = 0)
702  {
703  // phpcs:enable
704  global $langs;
705  $langs->load('users');
706  return '';
707  }
708 
720  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
721  {
722  global $langs, $conf, $db, $hookmanager;
723  global $dolibarr_main_authentication, $dolibarr_main_demo;
724  global $menumanager;
725 
726  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpicto) {
727  $withpicto = 0;
728  }
729 
730  $result = ''; $label = '';
731 
732  $label .= '<div class="centpercent">';
733  $label .= img_picto('', 'group').' <u>'.$langs->trans("Group").'</u><br>';
734  $label .= '<b>'.$langs->trans('Name').':</b> '.$this->name;
735  $label .= '<br><b>'.$langs->trans("Description").':</b> '.$this->note;
736  $label .= '</div>';
737 
738  if ($option == 'permissions') {
739  $url = DOL_URL_ROOT.'/user/group/perms.php?id='.$this->id;
740  } else {
741  $url = DOL_URL_ROOT.'/user/group/card.php?id='.$this->id;
742  }
743 
744  if ($option != 'nolink') {
745  // Add param to save lastsearch_values or not
746  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
747  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
748  $add_save_lastsearch_values = 1;
749  }
750  if ($add_save_lastsearch_values) {
751  $url .= '&save_lastsearch_values=1';
752  }
753  }
754 
755  $linkclose = "";
756  if (empty($notooltip)) {
757  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
758  $langs->load("users");
759  $label = $langs->trans("ShowGroup");
760  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1, 1).'"';
761  }
762  $linkclose .= ' title="'.dol_escape_htmltag($label, 1, 1).'"';
763  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
764  }
765 
766  $linkstart = '<a href="'.$url.'"';
767  $linkstart .= $linkclose.'>';
768  $linkend = '</a>';
769 
770  $result = $linkstart;
771  if ($withpicto) {
772  $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);
773  }
774  if ($withpicto != 2) {
775  $result .= $this->name;
776  }
777  $result .= $linkend;
778 
779  global $action;
780  $hookmanager->initHooks(array('groupdao'));
781  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
782  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
783  if ($reshook > 0) {
784  $result = $hookmanager->resPrint;
785  } else {
786  $result .= $hookmanager->resPrint;
787  }
788 
789  return $result;
790  }
791 
792  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
793  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
803  public function _load_ldap_dn($info, $mode = 0)
804  {
805  // phpcs:enable
806  global $conf;
807  $dn = '';
808  if ($mode == 0) {
809  $dn = $conf->global->LDAP_KEY_GROUPS."=".$info[$conf->global->LDAP_KEY_GROUPS].",".$conf->global->LDAP_GROUP_DN;
810  }
811  if ($mode == 1) {
812  $dn = $conf->global->LDAP_GROUP_DN;
813  }
814  if ($mode == 2) {
815  $dn = $conf->global->LDAP_KEY_GROUPS."=".$info[$conf->global->LDAP_KEY_GROUPS];
816  }
817  return $dn;
818  }
819 
820 
821  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
822  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
828  public function _load_ldap_info()
829  {
830  // phpcs:enable
831  global $conf;
832 
833  $info = array();
834 
835  // Object classes
836  $info["objectclass"] = explode(',', $conf->global->LDAP_GROUP_OBJECT_CLASS);
837 
838  // Champs
839  if ($this->name && !empty($conf->global->LDAP_GROUP_FIELD_FULLNAME)) {
840  $info[$conf->global->LDAP_GROUP_FIELD_FULLNAME] = $this->name;
841  }
842  //if ($this->name && !empty($conf->global->LDAP_GROUP_FIELD_NAME)) $info[$conf->global->LDAP_GROUP_FIELD_NAME] = $this->name;
843  if ($this->note && !empty($conf->global->LDAP_GROUP_FIELD_DESCRIPTION)) {
844  $info[$conf->global->LDAP_GROUP_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note, 2);
845  }
846  if (!empty($conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS)) {
847  $valueofldapfield = array();
848  foreach ($this->members as $key => $val) { // This is array of users for group into dolibarr database.
849  $muser = new User($this->db);
850  $muser->fetch($val->id);
851  $info2 = $muser->_load_ldap_info();
852  $valueofldapfield[] = $muser->_load_ldap_dn($info2);
853  }
854  $info[$conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS] = (!empty($valueofldapfield) ? $valueofldapfield : '');
855  }
856  if (!empty($conf->global->LDAP_GROUP_FIELD_GROUPID)) {
857  $info[$conf->global->LDAP_GROUP_FIELD_GROUPID] = $this->id;
858  }
859  return $info;
860  }
861 
862 
870  public function initAsSpecimen()
871  {
872  global $conf, $user, $langs;
873 
874  // Initialise parametres
875  $this->id = 0;
876  $this->ref = 'SPECIMEN';
877  $this->specimen = 1;
878 
879  $this->name = 'DOLIBARR GROUP SPECIMEN';
880  $this->note = 'This is a note';
881  $this->datec = time();
882  $this->datem = time();
883 
884  // Members of this group is just me
885  $this->members = array(
886  $user->id => $user
887  );
888  }
889 
901  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
902  {
903  global $conf, $user, $langs;
904 
905  $langs->load("user");
906 
907  // Positionne le modele sur le nom du modele a utiliser
908  if (!dol_strlen($modele)) {
909  if (!empty($conf->global->USERGROUP_ADDON_PDF)) {
910  $modele = $conf->global->USERGROUP_ADDON_PDF;
911  } else {
912  $modele = 'grass';
913  }
914  }
915 
916  $modelpath = "core/modules/usergroup/doc/";
917 
918  return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
919  }
920 }
$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)
_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)
Renvoi le libelle d'un statut donne.
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.
fetch($id='', $groupname='', $load_members=true)
Charge un objet group avec toutes ses caracteristiques (except ->members array)
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 label of status of user (active, inactive)
__construct($db)
Constructor de la classe.
update($notrigger=0)
Update group into database.
Class to manage Dolibarr users.
Definition: user.class.php:47
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)) $resql
Social contributions to pay.
Definition: index.php:745
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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:122
$conf db
API class for accounts.
Definition: inc.php:41