dolibarr 23.0.3
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-2025 Frédéric France <frederic.france@free.fr>
11 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
12 * Copyright (C) 2025 Charlene Benke <charlene@patas-monkey.com>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <https://www.gnu.org/licenses/>.
26 */
27
33require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
34if (isModEnabled('ldap')) {
35 require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
36}
37
38
43{
47 public $element = 'usergroup';
48
52 public $table_element = 'usergroup';
53
57 public $picto = 'group';
58
64 public $nom;
65
69 public $name; // Name of group
70
74 public $globalgroup; // Global group
75
80 public $usergroup_entity;
81
87 public $datec;
88
92 public $note;
93
97 public $color;
98
102 public $members = array();
103
107 public $nb_rights;
108
112 public $nb_users;
113
117 public $rights;
118
122 private $_tab_loaded = array(); // Array of cache of already loaded permissions
123
127 public $all_permissions_are_loaded;
128
129 public $fields = array(
130 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'index' => 1, 'position' => 1, 'comment' => 'Id'),
131 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'default' => '1', 'index' => 1, 'position' => 5),
132 'nom' => array('type' => 'varchar(180)', 'label' => 'Name', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'showoncombobox' => 1, 'index' => 1, 'position' => 10, 'searchall' => 1, 'comment' => 'Group name'),
133 'note' => array('type' => 'html', 'label' => 'Description', 'enabled' => 1, 'visible' => 1, 'position' => 20, 'notnull' => -1, 'searchall' => 1),
134 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -2, 'position' => 50, 'notnull' => 1,),
135 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -2, 'position' => 60, 'notnull' => 1,),
136 'color' => array('type' => 'varchar(6)', 'label' => 'Color', 'enabled' => 1, 'visible' => 1, 'position' => 70, 'notnull' => -1, 'comment' => 'Color for pictogram'),
137 'model_pdf' => array('type' => 'varchar(255)', 'label' => 'ModelPDF', 'enabled' => 1, 'visible' => 0, 'position' => 100),
138 );
139
143 public $fk_element = 'fk_usergroup';
144
148 protected $childtables = array();
149
153 protected $childtablesoncascade = array('usergroup_rights', 'usergroup_user');
154
155
161 public function __construct($db)
162 {
163 $this->db = $db;
164
165 $this->ismultientitymanaged = 1;
166 $this->nb_rights = 0;
167 }
168
169
178 public function fetch($id = 0, $groupname = '', $load_members = false)
179 {
180 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
181 if (!empty($groupname)) {
182 $result = $this->fetchCommon(0, '', ' AND nom = \''.$this->db->escape($groupname).'\'');
183 } else {
184 $result = $this->fetchCommon($id);
185 }
186
187 $this->name = $this->nom; // For compatibility with field name
188 $this->note_private = $this->note; // For compatibility with old field note
189
190 if ($result) {
191 if ($load_members) {
192 $excludefilter = '';
193 $this->members = $this->listUsersForGroup($excludefilter, 0); // This make a request to get list of users but may also do subrequest to fetch each users on some versions
194 }
195
196 return 1;
197 } else {
198 $this->error = $this->db->lasterror();
199 return -1;
200 }
201 }
202
203
211 public function listGroupsForUser($userid, $load_members = true)
212 {
213 global $conf, $user;
214
215 $ret = array();
216
217 $sql = "SELECT g.rowid, ug.entity as usergroup_entity";
218 $sql .= " FROM ".$this->db->prefix()."usergroup as g,";
219 $sql .= " ".$this->db->prefix()."usergroup_user as ug";
220 $sql .= " WHERE ug.fk_usergroup = g.rowid";
221 $sql .= " AND ug.fk_user = ".((int) $userid);
222 if (isModEnabled('multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
223 $sql .= " AND g.entity IS NOT NULL";
224 } else {
225 $sql .= " AND g.entity IN (0,".$conf->entity.")";
226 }
227 $sql .= " ORDER BY g.nom";
228
229 dol_syslog(get_class($this)."::listGroupsForUser", LOG_DEBUG);
230 $result = $this->db->query($sql);
231 if ($result) {
232 while ($obj = $this->db->fetch_object($result)) {
233 if (!array_key_exists($obj->rowid, $ret)) {
234 $newgroup = new UserGroup($this->db);
235 $newgroup->fetch($obj->rowid, '', $load_members);
236 $ret[$obj->rowid] = $newgroup;
237 }
238 if (!is_array($ret[$obj->rowid]->usergroup_entity)) {
239 $ret[$obj->rowid]->usergroup_entity = array();
240 }
241 // $ret[$obj->rowid] is instance of UserGroup
242 $ret[$obj->rowid]->usergroup_entity[] = (int) $obj->usergroup_entity;
243 }
244
245 $this->db->free($result);
246
247 return $ret;
248 } else {
249 $this->error = $this->db->lasterror();
250 return -1;
251 }
252 }
253
261 public function listUsersForGroup($excludefilter = '', $mode = 0)
262 {
263 global $conf, $user;
264
265 $ret = array();
266
267 $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";
268 if (!empty($this->id)) {
269 $sql .= ", ug.entity as usergroup_entity";
270 }
271 $sql .= " FROM ".$this->db->prefix()."user as u";
272 if (!empty($this->id)) {
273 $sql .= ", ".$this->db->prefix()."usergroup_user as ug";
274 }
275 $sql .= " WHERE 1 = 1";
276 if (!empty($this->id)) {
277 $sql .= " AND ug.fk_user = u.rowid";
278 }
279 if (!empty($this->id)) {
280 $sql .= " AND ug.fk_usergroup = ".((int) $this->id);
281 }
282 if (isModEnabled('multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
283 $sql .= " AND u.entity IS NOT NULL";
284 } else {
285 $sql .= " AND u.entity IN (0,".$conf->entity.")";
286 }
287 if (!empty($excludefilter)) {
288 $sql .= ' AND ('.$excludefilter.')';
289 }
290
291 dol_syslog(get_class($this)."::listUsersForGroup", LOG_DEBUG);
292 $resql = $this->db->query($sql);
293
294 if ($resql) {
295 while ($obj = $this->db->fetch_object($resql)) {
296 if (!array_key_exists($obj->rowid, $ret)) {
297 if ($mode != 1) {
298 $newuser = new User($this->db);
299 //$newuser->fetch($obj->rowid); // We are inside a loop, no subrequests inside a loop
300 $newuser->id = $obj->rowid;
301 $newuser->login = $obj->login;
302 $newuser->photo = $obj->photo;
303 $newuser->lastname = $obj->lastname;
304 $newuser->firstname = $obj->firstname;
305 $newuser->email = $obj->email;
306 $newuser->socid = $obj->fk_soc;
307 $newuser->entity = $obj->entity;
308 $newuser->employee = $obj->employee;
309 $newuser->status = $obj->status;
310
311 $ret[$obj->rowid] = $newuser;
312 } else {
313 $ret[$obj->rowid] = $obj->rowid;
314 }
315 }
316 if ($mode != 1 && !empty($obj->usergroup_entity)) {
317 // $ret[$obj->rowid] is instance of User
318 if (!is_array($ret[$obj->rowid]->usergroup_entity)) {
319 $ret[$obj->rowid]->usergroup_entity = array();
320 }
321 $ret[$obj->rowid]->usergroup_entity[] = (int) $obj->usergroup_entity;
322 }
323 }
324
325 $this->db->free($resql);
326
327 return $ret;
328 } else {
329 $this->error = $this->db->lasterror();
330 return -1;
331 }
332 }
333
343 public function addrights($rid, $allmodule = '', $allperms = '', $entity = 0)
344 {
345 global $conf, $user, $langs;
346
347 $entity = (!empty($entity) ? $entity : $conf->entity);
348
349 dol_syslog(get_class($this)."::addrights $rid, $allmodule, $allperms, $entity");
350 $error = 0;
351 $whereforadd = '';
352
353 $this->db->begin();
354
355 if (!empty($rid)) {
356 $module = $perms = $subperms = '';
357
358 // Si on a demande ajout d'un droit en particulier, on recupere
359 // les caracteristiques (module, perms et subperms) de ce droit.
360 $sql = "SELECT module, perms, subperms";
361 $sql .= " FROM ".$this->db->prefix()."rights_def";
362 $sql .= " WHERE id = ".((int) $rid);
363 $sql .= " AND entity = ".((int) $entity);
364
365 $result = $this->db->query($sql);
366 if ($result) {
367 $obj = $this->db->fetch_object($result);
368 if ($obj) {
369 $module = $obj->module;
370 $perms = $obj->perms;
371 $subperms = $obj->subperms;
372 }
373 } else {
374 $error++;
375 dol_print_error($this->db);
376 }
377
378 // Where pour la liste des droits a ajouter
379 $whereforadd = "id=".((int) $rid);
380 // Find also rights that are herited to add them too
381 if ($subperms) {
382 $whereforadd .= " OR (module='".$this->db->escape($module)."' AND perms='".$this->db->escape($perms)."' AND (subperms='lire' OR subperms='read'))";
383 } elseif ($perms) {
384 $whereforadd .= " OR (module='".$this->db->escape($module)."' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
385 }
386 } else {
387 // Where pour la liste des droits a ajouter
388 if (!empty($allmodule)) {
389 if ($allmodule == 'allmodules') {
390 $whereforadd = 'allmodules';
391 } else {
392 $whereforadd = "module='".$this->db->escape($allmodule)."'";
393 if (!empty($allperms)) {
394 $whereforadd .= " AND perms='".$this->db->escape($allperms)."'";
395 }
396 }
397 }
398 }
399
400 // Add permission of the list $whereforadd
401 if (!empty($whereforadd)) {
402 //print "$module-$perms-$subperms";
403 $sql = "SELECT id";
404 $sql .= " FROM ".$this->db->prefix()."rights_def";
405 $sql .= " WHERE entity = ".((int) $entity);
406 if (!empty($whereforadd) && $whereforadd != 'allmodules') {
407 $sql .= " AND ".$whereforadd;
408 }
409
410 $result = $this->db->query($sql);
411 if ($result) {
412 $num = $this->db->num_rows($result);
413 $i = 0;
414 while ($i < $num) {
415 $obj = $this->db->fetch_object($result);
416 $nid = $obj->id;
417
418 $sql = "DELETE FROM ".$this->db->prefix()."usergroup_rights WHERE fk_usergroup = ".((int) $this->id)." AND fk_id=".((int) $nid)." AND entity = ".((int) $entity);
419 if (!$this->db->query($sql)) {
420 $error++;
421 }
422 $sql = "INSERT INTO ".$this->db->prefix()."usergroup_rights (entity, fk_usergroup, fk_id) VALUES (".((int) $entity).", ".((int) $this->id).", ".((int) $nid).")";
423 if (!$this->db->query($sql)) {
424 $error++;
425 }
426
427 $i++;
428 }
429 } else {
430 $error++;
431 dol_print_error($this->db);
432 }
433
434 if (!$error) {
435 $langs->load("other");
436 $this->context = array('audit' => $langs->trans("PermissionsAdd").($rid ? ' (id='.$rid.')' : ''));
437
438 // Call trigger
439 $result = $this->call_trigger('USERGROUP_MODIFY', $user);
440 if ($result < 0) {
441 $error++;
442 }
443 // End call triggers
444 }
445 }
446
447 if ($error) {
448 $this->db->rollback();
449 return -$error;
450 } else {
451 $this->db->commit();
452 return 1;
453 }
454 }
455
456
466 public function delrights($rid, $allmodule = '', $allperms = '', $entity = 0)
467 {
468 global $conf, $user, $langs;
469
470 $error = 0;
471 $wherefordel = '';
472
473 $entity = (!empty($entity) ? $entity : $conf->entity);
474
475 $this->db->begin();
476
477 if (!empty($rid)) {
478 $module = $perms = $subperms = '';
479
480 // Si on a demande suppression d'un droit en particulier, on recupere
481 // les caracteristiques module, perms et subperms de ce droit.
482 $sql = "SELECT module, perms, subperms";
483 $sql .= " FROM ".$this->db->prefix()."rights_def";
484 $sql .= " WHERE id = ".((int) $rid);
485 $sql .= " AND entity = ".((int) $entity);
486
487 $result = $this->db->query($sql);
488 if ($result) {
489 $obj = $this->db->fetch_object($result);
490 if ($obj) {
491 $module = $obj->module;
492 $perms = $obj->perms;
493 $subperms = $obj->subperms;
494 }
495 } else {
496 $error++;
497 dol_print_error($this->db);
498 }
499
500 // Where for the list of permissions to delete
501 $wherefordel = "id = ".((int) $rid);
502 // Suppression des droits induits
503 if ($subperms == 'lire' || $subperms == 'read') {
504 $wherefordel .= " OR (module='".$this->db->escape($module)."' AND perms='".$this->db->escape($perms)."' AND subperms IS NOT NULL)";
505 }
506 if ($perms == 'lire' || $perms == 'read') {
507 $wherefordel .= " OR (module='".$this->db->escape($module)."')";
508 }
509
510 // Pour compatibilite, si lowid = 0, on est en mode suppression de tout
511 // TODO To remove when this will be implemented by the caller
512 //if (substr($rid,-1,1) == 0) $wherefordel="module='$module'";
513 } else {
514 // Add permission of the list $wherefordel
515 if (!empty($allmodule)) {
516 if ($allmodule == 'allmodules') {
517 $wherefordel = 'allmodules';
518 } else {
519 $wherefordel = "module='".$this->db->escape($allmodule)."'";
520 if (!empty($allperms)) {
521 $wherefordel .= " AND perms='".$this->db->escape($allperms)."'";
522 }
523 }
524 }
525 }
526
527 // Suppression des droits de la liste wherefordel
528 if (!empty($wherefordel)) {
529 //print "$module-$perms-$subperms";
530 $sql = "SELECT id";
531 $sql .= " FROM ".$this->db->prefix()."rights_def";
532 $sql .= " WHERE entity = ".((int) $entity);
533 if (!empty($wherefordel) && $wherefordel != 'allmodules') {
534 $sql .= " AND ".$wherefordel;
535 }
536
537 $result = $this->db->query($sql);
538 if ($result) {
539 $num = $this->db->num_rows($result);
540 $i = 0;
541 while ($i < $num) {
542 $nid = 0;
543
544 $obj = $this->db->fetch_object($result);
545 if ($obj) {
546 $nid = $obj->id;
547 }
548
549 $sql = "DELETE FROM ".$this->db->prefix()."usergroup_rights";
550 $sql .= " WHERE fk_usergroup = $this->id AND fk_id=".((int) $nid);
551 $sql .= " AND entity = ".((int) $entity);
552 if (!$this->db->query($sql)) {
553 $error++;
554 }
555
556 $i++;
557 }
558 } else {
559 $error++;
560 dol_print_error($this->db);
561 }
562
563 if (!$error) {
564 $langs->load("other");
565 $this->context = array('audit' => $langs->trans("PermissionsDelete").($rid ? ' (id='.$rid.')' : ''));
566
567 // Call trigger
568 $result = $this->call_trigger('USERGROUP_MODIFY', $user);
569 if ($result < 0) {
570 $error++;
571 }
572 // End call triggers
573 }
574 }
575
576 if ($error) {
577 $this->db->rollback();
578 return -$error;
579 } else {
580 $this->db->commit();
581 return 1;
582 }
583 }
584
595 public function getrights($moduletag = '')
596 {
597 return $this->loadRights($moduletag);
598 }
599
606 public function loadRights($moduletag = '')
607 {
608 global $conf;
609
610 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
611 // Rights for this module are already loaded, so we leave
612 return 0;
613 }
614
615 if (!empty($this->all_permissions_are_loaded)) {
616 // We already loaded all rights for this group, so we leave
617 return 0;
618 }
619
620 // Load permission from group
621 $sql = "SELECT r.module, r.perms, r.subperms ";
622 $sql .= " FROM ".$this->db->prefix()."usergroup_rights as u, ".$this->db->prefix()."rights_def as r";
623 $sql .= " WHERE r.id = u.fk_id";
624 $sql .= " AND r.entity = ".((int) $conf->entity);
625 $sql .= " AND u.entity = ".((int) $conf->entity);
626 $sql .= " AND u.fk_usergroup = ".((int) $this->id);
627 $sql .= " AND r.perms IS NOT NULL";
628 if ($moduletag) {
629 $sql .= " AND r.module = '".$this->db->escape($moduletag)."'";
630 }
631
632 dol_syslog(get_class($this).'::getrights', LOG_DEBUG);
633 $resql = $this->db->query($sql);
634 if ($resql) {
635 $num = $this->db->num_rows($resql);
636 $i = 0;
637 while ($i < $num) {
638 $obj = $this->db->fetch_object($resql);
639
640 if ($obj) {
641 $module = $obj->module;
642 $perms = $obj->perms;
643 $subperms = $obj->subperms;
644
645 if ($perms) {
646 if (!isset($this->rights)) {
647 $this->rights = new stdClass(); // For avoid error
648 }
649 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
650 $this->rights->$module = new stdClass();
651 }
652 if ($subperms) {
653 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
654 $this->rights->$module->$perms = new stdClass();
655 }
656 if (empty($this->rights->$module->$perms->$subperms)) {
657 $this->nb_rights++;
658 }
659 $this->rights->$module->$perms->$subperms = 1;
660 } else {
661 if (empty($this->rights->$module->$perms)) {
662 $this->nb_rights++;
663 }
664 $this->rights->$module->$perms = 1;
665 }
666 }
667 }
668
669 $i++;
670 }
671 $this->db->free($resql);
672 }
673
674 if ($moduletag == '') {
675 // Si module etait non defini, alors on a tout charge, on peut donc considerer
676 // que les droits sont en cache (car tous charges) pour cet instance de group
677 $this->all_permissions_are_loaded = 1;
678 } else {
679 // If module defined, we flag it as loaded into cache
680 $this->_tab_loaded[$moduletag] = 1;
681 }
682
683 return 1;
684 }
685
692 public function delete(User $user)
693 {
694 return $this->deleteCommon($user);
695 }
696
703 public function create($notrigger = 0)
704 {
705 global $user, $conf;
706
707 $this->datec = dol_now();
708 if (!empty($this->name)) {
709 $this->nom = $this->name; // Field for 'name' is called 'nom' in database
710 }
711 if (!empty($this->note_private)) {
712 $this->note = $this->note_private; // Field for 'note_private' is called 'note' in database
713 }
714
715 if (!isset($this->entity)) {
716 $this->entity = $conf->entity; // If not defined, we use default value
717 }
718
719 return $this->createCommon($user, $notrigger);
720 }
721
728 public function update($notrigger = 0)
729 {
730 global $user, $conf;
731
732 if (!empty($this->name)) {
733 $this->nom = $this->name; // Field for 'name' is called 'nom' in database
734 }
735
736 if (!empty($this->note_private)) {
737 $this->note = $this->note_private; // Field for 'note_private' is called 'note' in database
738 }
739
740 return $this->updateCommon($user, $notrigger);
741 }
742
743
753 public function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0)
754 {
755 //print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n";
756 $lastname = $this->lastname;
757 $firstname = $this->firstname;
758 if (empty($lastname)) {
759 $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 : '')))));
760 }
761
762 $ret = '';
763 if (!empty($option) && !empty($this->civility_code)) {
764 if ($langs->transnoentitiesnoconv("Civility".$this->civility_code) != "Civility".$this->civility_code) {
765 $ret .= $langs->transnoentitiesnoconv("Civility".$this->civility_code).' ';
766 } else {
767 $ret .= $this->civility_code.' ';
768 }
769 }
770
771 $ret .= dolGetFirstLastname((string) $firstname, (string) $lastname, $nameorder);
772
773 return dol_trunc($ret, $maxlen);
774 }
775
782 public function getLibStatut($mode = 0)
783 {
784 return $this->LibStatut(0, $mode);
785 }
786
787 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
795 public function LibStatut($status, $mode = 0)
796 {
797 // phpcs:enable
798 global $langs;
799 $langs->load('users');
800 return '';
801 }
802
809 public function getTooltipContentArray($params)
810 {
811 global $conf, $langs, $menumanager;
812
813 $option = $params['option'] ?? '';
814
815 $datas = [];
816 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
817 $langs->load("users");
818 return ['optimize' => $langs->trans("ShowGroup")];
819 }
820 $datas['divopen'] = '<div class="centpercent">';
821 $datas['picto'] = img_picto('', 'group').' <u>'.$langs->trans("Group").'</u><br>';
822 $datas['name'] = '<b>'.$langs->trans('Name').':</b> '.$this->name;
823 $datas['description'] = '<br><b>'.$langs->trans("Description").':</b> '.$this->note;
824 $datas['divclose'] = '</div>';
825
826 return $datas;
827 }
828
840 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
841 {
842 global $langs, $conf, $db, $hookmanager;
843
844 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') && $withpicto) {
845 $withpicto = 0;
846 }
847
848 $result = '';
849 $params = [
850 'id' => $this->id,
851 'objecttype' => $this->element,
852 'option' => $option,
853 ];
854 $classfortooltip = 'classfortooltip';
855 $dataparams = '';
856 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
857 $classfortooltip = 'classforajaxtooltip';
858 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
859 $label = '';
860 } else {
861 $label = implode($this->getTooltipContentArray($params));
862 }
863
864 if ($option == 'permissions') {
865 $baseurl = DOL_URL_ROOT.'/user/group/perms.php';
866 } else {
867 $baseurl = DOL_URL_ROOT.'/user/group/card.php';
868 }
869 $query = ['id' => $this->id];
870
871 if ($option != 'nolink') {
872 // Add param to save lastsearch_values or not
873 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
874 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
875 $add_save_lastsearch_values = 1;
876 }
877 if ($add_save_lastsearch_values) {
878 $query = array_merge($query, ['save_lastsearch_values' => 1]);
879 }
880 }
881 $url = dolBuildUrl($baseurl, $query);
882
883 $linkclose = "";
884 if (empty($notooltip)) {
885 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
886 $langs->load("users");
887 $label = $langs->trans("ShowGroup");
888 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1, 1).'"';
889 }
890 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
891 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
892 }
893
894 $linkstart = '<a href="'.$url.'"';
895 $linkstart .= $linkclose.'>';
896 $linkend = '</a>';
897
898 $result = $linkstart;
899 if ($withpicto) {
900 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
901 }
902 if ($withpicto != 2) {
903 $result .= $this->name;
904 }
905 $result .= $linkend;
906
907 global $action;
908 $hookmanager->initHooks(array('groupdao'));
909 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
910 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
911 if ($reshook > 0) {
912 $result = $hookmanager->resPrint;
913 } else {
914 $result .= $hookmanager->resPrint;
915 }
916
917 return $result;
918 }
919
920 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
921 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
931 public function _load_ldap_dn($info, $mode = 0)
932 {
933 // phpcs:enable
934 global $conf;
935 $dn = '';
936 if ($mode == 0) {
937 $dn = getDolGlobalString('LDAP_KEY_GROUPS') . "=".$info[getDolGlobalString('LDAP_KEY_GROUPS')]."," . getDolGlobalString('LDAP_GROUP_DN');
938 }
939 if ($mode == 1) {
940 $dn = getDolGlobalString('LDAP_GROUP_DN');
941 }
942 if ($mode == 2) {
943 $dn = getDolGlobalString('LDAP_KEY_GROUPS') . "=".$info[getDolGlobalString('LDAP_KEY_GROUPS')];
944 }
945 return $dn;
946 }
947
948
949 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
950 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
956 public function _load_ldap_info()
957 {
958 // phpcs:enable
959 global $conf;
960
961 $info = array();
962
963 // Object classes
964 $info["objectclass"] = explode(',', getDolGlobalString('LDAP_GROUP_OBJECT_CLASS'));
965
966 // Champs
967 if ($this->name && getDolGlobalString('LDAP_GROUP_FIELD_FULLNAME')) {
968 $info[getDolGlobalString('LDAP_GROUP_FIELD_FULLNAME')] = $this->name;
969 }
970 //if ($this->name && !empty($conf->global->LDAP_GROUP_FIELD_NAME)) $info[$conf->global->LDAP_GROUP_FIELD_NAME] = $this->name;
971 if ($this->note && getDolGlobalString('LDAP_GROUP_FIELD_DESCRIPTION')) {
972 $info[getDolGlobalString('LDAP_GROUP_FIELD_DESCRIPTION')] = dol_string_nohtmltag($this->note, 2);
973 }
974 if (getDolGlobalString('LDAP_GROUP_FIELD_GROUPMEMBERS')) {
975 $valueofldapfield = array();
976 foreach ($this->members as $key => $val) { // This is array of users for group into dolibarr database.
977 $muser = new User($this->db);
978 $muser->fetch($val->id);
979 $info2 = $muser->_load_ldap_info();
980 $valueofldapfield[] = $muser->_load_ldap_dn($info2);
981 }
982 $info[getDolGlobalString('LDAP_GROUP_FIELD_GROUPMEMBERS')] = (!empty($valueofldapfield) ? $valueofldapfield : '');
983 }
984 if (getDolGlobalString('LDAP_GROUP_FIELD_GROUPID')) {
985 $info[getDolGlobalString('LDAP_GROUP_FIELD_GROUPID')] = $this->id;
986 }
987 return $info;
988 }
989
990
998 public function initAsSpecimen()
999 {
1000 global $conf, $user, $langs;
1001
1002 // Initialise parameters
1003 $this->id = 0;
1004 $this->ref = 'SPECIMEN';
1005 $this->specimen = 1;
1006
1007 $this->name = 'DOLIBARR GROUP SPECIMEN';
1008 $this->note = 'This is a note';
1009 $this->datec = time();
1010 $this->tms = time();
1011
1012 // Members of this group is just me
1013 $this->members = array(
1014 $user->id => $user
1015 );
1016
1017 return 1;
1018 }
1019
1031 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1032 {
1033 global $conf, $user, $langs;
1034
1035 $langs->load("user");
1036
1037 // Positionne le modele sur le nom du modele a utiliser
1038 if (!dol_strlen($modele)) {
1039 if (getDolGlobalString('USERGROUP_ADDON_PDF')) {
1040 $modele = getDolGlobalString('USERGROUP_ADDON_PDF');
1041 } else {
1042 $modele = 'grass';
1043 }
1044 }
1045
1046 $modelpath = "core/modules/usergroup/doc/";
1047
1048 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1049 }
1050
1058 public function getKanbanView($option = '', $arraydata = null)
1059 {
1060 global $langs;
1061
1062 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1063
1064 $return = '<div class="box-flex-item box-flex-grow-zero">';
1065 $return .= '<div class="info-box info-box-sm">';
1066 $return .= '<span class="info-box-icon bg-infobox-action">';
1067 $return .= img_picto('', $this->picto);
1068 $return .= '</span>';
1069 $return .= '<div class="info-box-content">';
1070 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1071 if ($selected >= 0) {
1072 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1073 }
1074 if (property_exists($this, 'members')) {
1075 $return .= '<br><span class="info-box-status opacitymedium">'.(empty($this->nb_users) ? 0 : $this->nb_users).' '.$langs->trans('Users').'</span>';
1076 }
1077 if (property_exists($this, 'nb_rights')) {
1078 $return .= '<br><div class="info-box-status margintoponly opacitymedium">'.$langs->trans('NbOfPermissions').' : '.(empty($this->nb_rights) ? 0 : $this->nb_rights).'</div>';
1079 }
1080 $return .= '</div>';
1081 $return .= '</div>';
1082 $return .= '</div>';
1083 return $return;
1084 }
1085}
$object ref
Definition info.php:90
Parent class of all other business classes (invoices, contracts, proposals, orders,...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
createCommon(User $user, $notrigger=0)
Create object in the database.
updateCommon(User $user, $notrigger=0)
Update object into database.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
Class to manage user groups.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the user card (with optionally the picto) Use this->id,this->lastname,...
fetch($id=0, $groupname='', $load_members=false)
Load a group object with all properties (except ->members array that is array of users in group)
listUsersForGroup($excludefilter='', $mode=0)
Return array of User objects for group this->id (or all if this->id not defined)
loadRights($moduletag='')
Load the list of permissions for the user into the group object.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
_load_ldap_info()
Initialize the info array (array of LDAP values) that will be used to call LDAP functions.
_load_ldap_dn($info, $mode=0)
Retourne chaine DN complete dans l'annuaire LDAP pour l'objet.
LibStatut($status, $mode=0)
Return the label of a given status.
delrights($rid, $allmodule='', $allperms='', $entity=0)
Remove a permission from group.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
listGroupsForUser($userid, $load_members=true)
Return array of groups objects for a particular user.
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+' '+name+' '+lastname)
addrights($rid, $allmodule='', $allperms='', $entity=0)
Add a permission to a group.
initAsSpecimen()
Initialise an instance with random values.
create($notrigger=0)
Create group into database.
getrights($moduletag='')
Load the list of permissions for the user into the group object.
getLibStatut($mode=0)
Return the label of the status.
getTooltipContentArray($params)
getTooltipContentArray
__construct($db)
Class constructor.
update($notrigger=0)
Update group into database.
Class to manage Dolibarr users.
dol_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dolBuildUrl($url, $params=[], $addtoken=false)
Return path of url.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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:128