dolibarr 24.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 * Copyright (C) 2023-2026 Frédéric France <frederic.france@free.fr>
11 * Copyright (C) 2024-2026 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
158 public $isextrafieldmanaged = 1;
159
160
166 public function __construct($db)
167 {
168 $this->db = $db;
169
170 $this->ismultientitymanaged = 1;
171 $this->nb_rights = 0;
172 }
173
174
183 public function fetch($id = 0, $groupname = '', $load_members = false)
184 {
185 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
186 if (!empty($groupname)) {
187 $result = $this->fetchCommon(0, '', ' AND nom = \''.$this->db->escape($groupname).'\'');
188 } else {
189 $result = $this->fetchCommon($id);
190 }
191
192 $this->name = $this->nom; // For compatibility with field name
193 $this->note_private = $this->note; // For compatibility with old field note
194
195 if ($result) {
196 if ($load_members) {
197 $excludefilter = '';
198 $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
199 }
200
201 return 1;
202 } else {
203 $this->error = $this->db->lasterror();
204 return -1;
205 }
206 }
207
208
216 public function listGroupsForUser($userid, $load_members = true)
217 {
218 global $conf, $user;
219
220 $ret = array();
221
222 $sql = "SELECT g.rowid, ug.entity as usergroup_entity";
223 $sql .= " FROM ".$this->db->prefix()."usergroup as g,";
224 $sql .= " ".$this->db->prefix()."usergroup_user as ug";
225 $sql .= " WHERE ug.fk_usergroup = g.rowid";
226 $sql .= " AND ug.fk_user = ".((int) $userid);
227 if (isModEnabled('multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
228 $sql .= " AND g.entity IS NOT NULL";
229 } else {
230 $sql .= " AND g.entity IN (0,".((int) $conf->entity).")";
231 }
232 $sql .= " ORDER BY g.nom";
233
234 dol_syslog(get_class($this)."::listGroupsForUser", LOG_DEBUG);
235 $result = $this->db->query($sql);
236 if ($result) {
237 while ($obj = $this->db->fetch_object($result)) {
238 if (!array_key_exists($obj->rowid, $ret)) {
239 $newgroup = new UserGroup($this->db);
240 $newgroup->fetch($obj->rowid, '', $load_members);
241 $ret[$obj->rowid] = $newgroup;
242 }
243 if (!is_array($ret[$obj->rowid]->usergroup_entity)) {
244 $ret[$obj->rowid]->usergroup_entity = array();
245 }
246 // $ret[$obj->rowid] is instance of UserGroup
247 $ret[$obj->rowid]->usergroup_entity[] = (int) $obj->usergroup_entity;
248 }
249
250 $this->db->free($result);
251
252 return $ret;
253 } else {
254 $this->error = $this->db->lasterror();
255 return -1;
256 }
257 }
258
266 public function listUsersForGroup($excludefilter = '', $mode = 0)
267 {
268 global $conf, $user;
269
270 $ret = array();
271
272 $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";
273 if (!empty($this->id)) {
274 $sql .= ", ug.entity as usergroup_entity";
275 }
276 $sql .= " FROM ".$this->db->prefix()."user as u";
277 if (!empty($this->id)) {
278 $sql .= ", ".$this->db->prefix()."usergroup_user as ug";
279 }
280 $sql .= " WHERE 1 = 1";
281 if (!empty($this->id)) {
282 $sql .= " AND ug.fk_user = u.rowid";
283 }
284 if (!empty($this->id)) {
285 $sql .= " AND ug.fk_usergroup = ".((int) $this->id);
286 }
287 if (isModEnabled('multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
288 $sql .= " AND u.entity IS NOT NULL";
289 } else {
290 $sql .= " AND u.entity IN (0,".((int) $conf->entity).")";
291 }
292 if (!empty($excludefilter)) {
293 $sql .= ' AND ('.$excludefilter.')';
294 }
295
296 dol_syslog(get_class($this)."::listUsersForGroup", LOG_DEBUG);
297 $resql = $this->db->query($sql);
298
299 if ($resql) {
300 while ($obj = $this->db->fetch_object($resql)) {
301 if (!array_key_exists($obj->rowid, $ret)) {
302 if ($mode != 1) {
303 $newuser = new User($this->db);
304 //$newuser->fetch($obj->rowid); // We are inside a loop, no subrequests inside a loop
305 $newuser->id = $obj->rowid;
306 $newuser->login = $obj->login;
307 $newuser->photo = $obj->photo;
308 $newuser->lastname = $obj->lastname;
309 $newuser->firstname = $obj->firstname;
310 $newuser->email = $obj->email;
311 $newuser->socid = $obj->fk_soc;
312 $newuser->entity = $obj->entity;
313 $newuser->employee = $obj->employee;
314 $newuser->status = $obj->status;
315
316 $ret[$obj->rowid] = $newuser;
317 } else {
318 $ret[$obj->rowid] = $obj->rowid;
319 }
320 }
321 if ($mode != 1 && !empty($obj->usergroup_entity)) {
322 // $ret[$obj->rowid] is instance of User
323 if (!is_array($ret[$obj->rowid]->usergroup_entity)) {
324 $ret[$obj->rowid]->usergroup_entity = array();
325 }
326 $ret[$obj->rowid]->usergroup_entity[] = (int) $obj->usergroup_entity;
327 }
328 }
329
330 $this->db->free($resql);
331
332 return $ret;
333 } else {
334 $this->error = $this->db->lasterror();
335 return -1;
336 }
337 }
338
348 public function addrights($rid, $allmodule = '', $allperms = '', $entity = 0)
349 {
350 global $conf, $user, $langs;
351
352 $entity = (!empty($entity) ? $entity : $conf->entity);
353
354 dol_syslog(get_class($this)."::addrights $rid, $allmodule, $allperms, $entity");
355 $error = 0;
356 $whereforadd = '';
357
358 $this->db->begin();
359
360 if (!empty($rid)) {
361 $module = $perms = $subperms = '';
362
363 // Si on a demande ajout d'un droit en particulier, on recupere
364 // les caracteristiques (module, perms et subperms) de ce droit.
365 $sql = "SELECT module, perms, subperms";
366 $sql .= " FROM ".$this->db->prefix()."rights_def";
367 $sql .= " WHERE id = ".((int) $rid);
368 $sql .= " AND entity = ".((int) $entity);
369
370 $result = $this->db->query($sql);
371 if ($result) {
372 $obj = $this->db->fetch_object($result);
373 if ($obj) {
374 $module = $obj->module;
375 $perms = $obj->perms;
376 $subperms = $obj->subperms;
377 }
378 } else {
379 $error++;
380 dol_print_error($this->db);
381 }
382
383 // Where pour la liste des droits a ajouter
384 $whereforadd = "id=".((int) $rid);
385 // Find also rights that are herited to add them too
386 if ($subperms) {
387 $whereforadd .= " OR (module='".$this->db->escape($module)."' AND perms='".$this->db->escape($perms)."' AND (subperms='lire' OR subperms='read'))";
388 } elseif ($perms) {
389 $whereforadd .= " OR (module='".$this->db->escape($module)."' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
390 }
391 } else {
392 // Where pour la liste des droits a ajouter
393 if (!empty($allmodule)) {
394 if ($allmodule == 'allmodules') {
395 $whereforadd = 'allmodules';
396 } else {
397 $whereforadd = "module='".$this->db->escape($allmodule)."'";
398 if (!empty($allperms)) {
399 $whereforadd .= " AND perms='".$this->db->escape($allperms)."'";
400 }
401 }
402 }
403 }
404
405 // Add permission of the list $whereforadd
406 if (!empty($whereforadd)) {
407 //print "$module-$perms-$subperms";
408 $sql = "SELECT id";
409 $sql .= " FROM ".$this->db->prefix()."rights_def";
410 $sql .= " WHERE entity = ".((int) $entity);
411 if (!empty($whereforadd) && $whereforadd != 'allmodules') {
412 $sanitizedwhereforadd = $whereforadd;
413 $sql .= " AND ".$sanitizedwhereforadd;
414 }
415
416 $result = $this->db->query($sql);
417 if ($result) {
418 $num = $this->db->num_rows($result);
419 $i = 0;
420 while ($i < $num) {
421 $obj = $this->db->fetch_object($result);
422 $nid = $obj->id;
423
424 $sql = "DELETE FROM ".$this->db->prefix()."usergroup_rights WHERE fk_usergroup = ".((int) $this->id)." AND fk_id=".((int) $nid)." AND entity = ".((int) $entity);
425 if (!$this->db->query($sql)) {
426 $error++;
427 }
428 $sql = "INSERT INTO ".$this->db->prefix()."usergroup_rights (entity, fk_usergroup, fk_id) VALUES (".((int) $entity).", ".((int) $this->id).", ".((int) $nid).")";
429 if (!$this->db->query($sql)) {
430 $error++;
431 }
432
433 $i++;
434 }
435 } else {
436 $error++;
437 dol_print_error($this->db);
438 }
439
440 if (!$error) {
441 $langs->load("other");
442 $this->context = array('audit' => $langs->trans("PermissionsAdd").($rid ? ' (id='.$rid.')' : ''));
443
444 // Call trigger
445 $result = $this->call_trigger('USERGROUP_MODIFY', $user);
446 if ($result < 0) {
447 $error++;
448 }
449 // End call triggers
450 }
451 }
452
453 if ($error) {
454 $this->db->rollback();
455 return -$error;
456 } else {
457 $this->db->commit();
458 return 1;
459 }
460 }
461
462
472 public function delrights($rid, $allmodule = '', $allperms = '', $entity = 0)
473 {
474 global $conf, $user, $langs;
475
476 $error = 0;
477 $wherefordel = '';
478
479 $entity = (!empty($entity) ? $entity : $conf->entity);
480
481 $this->db->begin();
482
483 if (!empty($rid)) {
484 $module = $perms = $subperms = '';
485
486 // If a specific permission deletion was requested, we retrieve
487 // the module characteristics, perms and subperms of this right.
488 $sql = "SELECT module, perms, subperms";
489 $sql .= " FROM ".$this->db->prefix()."rights_def";
490 $sql .= " WHERE id = ".((int) $rid);
491 $sql .= " AND entity = ".((int) $entity);
492
493 $result = $this->db->query($sql);
494 if ($result) {
495 $obj = $this->db->fetch_object($result);
496 if ($obj) {
497 $module = $obj->module;
498 $perms = $obj->perms;
499 $subperms = $obj->subperms;
500 }
501 } else {
502 $error++;
503 dol_print_error($this->db);
504 }
505
506 // Where for the list of permissions to delete
507 $wherefordel = "id = ".((int) $rid);
508 // Deletion of inherited permissions
509 if ($subperms == 'lire' || $subperms == 'read') {
510 $wherefordel .= " OR (module='".$this->db->escape($module)."' AND perms='".$this->db->escape($perms)."' AND subperms IS NOT NULL)";
511 }
512 if ($perms == 'lire' || $perms == 'read') {
513 $wherefordel .= " OR (module='".$this->db->escape($module)."')";
514 }
515
516 // Pour compatibility, if lowid = 0, we are in removal all mode
517 // TODO To remove when this will be implemented by the caller
518 //if (substr($rid,-1,1) == 0) $wherefordel="module='$module'";
519 } else {
520 // Add permission of the list $wherefordel
521 if (!empty($allmodule)) {
522 if ($allmodule == 'allmodules') {
523 $wherefordel = 'allmodules';
524 } else {
525 $wherefordel = "module='".$this->db->escape($allmodule)."'";
526 if (!empty($allperms)) {
527 $wherefordel .= " AND perms='".$this->db->escape($allperms)."'";
528 }
529 }
530 }
531 }
532
533 // Deletion of permissions of the list wherefordel
534 if (!empty($wherefordel)) {
535 //print "$module-$perms-$subperms";
536 $sql = "SELECT id";
537 $sql .= " FROM ".$this->db->prefix()."rights_def";
538 $sql .= " WHERE entity = ".((int) $entity);
539 if (!empty($wherefordel) && $wherefordel != 'allmodules') {
540 $sanitizedwherefordel = $wherefordel;
541 $sql .= " AND ".$sanitizedwherefordel;
542 }
543
544 $result = $this->db->query($sql);
545 if ($result) {
546 $num = $this->db->num_rows($result);
547 $i = 0;
548 while ($i < $num) {
549 $nid = 0;
550
551 $obj = $this->db->fetch_object($result);
552 if ($obj) {
553 $nid = $obj->id;
554 }
555
556 $sql = "DELETE FROM ".$this->db->prefix()."usergroup_rights";
557 $sql .= " WHERE fk_usergroup = ".((int) $this->id)." AND fk_id=".((int) $nid);
558 $sql .= " AND entity = ".((int) $entity);
559 if (!$this->db->query($sql)) {
560 $error++;
561 }
562
563 $i++;
564 }
565 } else {
566 $error++;
567 dol_print_error($this->db);
568 }
569
570 if (!$error) {
571 $langs->load("other");
572 $this->context = array('audit' => $langs->trans("PermissionsDelete").($rid ? ' (id='.$rid.')' : ''));
573
574 // Call trigger
575 $result = $this->call_trigger('USERGROUP_MODIFY', $user);
576 if ($result < 0) {
577 $error++;
578 }
579 // End call triggers
580 }
581 }
582
583 if ($error) {
584 $this->db->rollback();
585 return -$error;
586 } else {
587 $this->db->commit();
588 return 1;
589 }
590 }
591
602 public function getrights($moduletag = '')
603 {
604 return $this->loadRights($moduletag);
605 }
606
613 public function loadRights($moduletag = '')
614 {
615 global $conf;
616
617 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
618 // Rights for this module are already loaded, so we leave
619 return 0;
620 }
621
622 if (!empty($this->all_permissions_are_loaded)) {
623 // We already loaded all rights for this group, so we leave
624 return 0;
625 }
626
627 // Load permission from group
628 $sql = "SELECT r.module, r.perms, r.subperms ";
629 $sql .= " FROM ".$this->db->prefix()."usergroup_rights as u, ".$this->db->prefix()."rights_def as r";
630 $sql .= " WHERE r.id = u.fk_id";
631 $sql .= " AND r.entity = ".((int) $conf->entity);
632 $sql .= " AND u.entity = ".((int) $conf->entity);
633 $sql .= " AND u.fk_usergroup = ".((int) $this->id);
634 $sql .= " AND r.perms IS NOT NULL";
635 if ($moduletag) {
636 $sql .= " AND r.module = '".$this->db->escape($moduletag)."'";
637 }
638
639 dol_syslog(get_class($this).'::getrights', LOG_DEBUG);
640 $resql = $this->db->query($sql);
641 if ($resql) {
642 $num = $this->db->num_rows($resql);
643 $i = 0;
644 while ($i < $num) {
645 $obj = $this->db->fetch_object($resql);
646
647 if ($obj) {
648 $module = $obj->module;
649 $perms = $obj->perms;
650 $subperms = $obj->subperms;
651
652 if ($perms) {
653 if (!isset($this->rights)) {
654 $this->rights = new stdClass(); // For avoid error
655 }
656 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
657 $this->rights->$module = new stdClass();
658 }
659 if ($subperms) {
660 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
661 $this->rights->$module->$perms = new stdClass();
662 }
663 if (empty($this->rights->$module->$perms->$subperms)) {
664 $this->nb_rights++;
665 }
666 $this->rights->$module->$perms->$subperms = 1;
667 } else {
668 if (empty($this->rights->$module->$perms)) {
669 $this->nb_rights++;
670 }
671 $this->rights->$module->$perms = 1;
672 }
673 }
674 }
675
676 $i++;
677 }
678 $this->db->free($resql);
679 }
680
681 if ($moduletag == '') {
682 // Si module etait non defini, alors on a tout charge, on peut donc considerer
683 // que les droits sont en cache (car tous charges) pour cet instance de group
684 $this->all_permissions_are_loaded = 1;
685 } else {
686 // If module defined, we flag it as loaded into cache
687 $this->_tab_loaded[$moduletag] = 1;
688 }
689
690 return 1;
691 }
692
699 public function delete(User $user)
700 {
701 return $this->deleteCommon($user);
702 }
703
710 public function create($notrigger = 0)
711 {
712 global $user, $conf;
713
714 $this->datec = dol_now();
715 if (!empty($this->name)) {
716 $this->nom = $this->name; // Field for 'name' is called 'nom' in database
717 }
718 if (!empty($this->note_private)) {
719 $this->note = $this->note_private; // Field for 'note_private' is called 'note' in database
720 }
721
722 if (!isset($this->entity)) {
723 $this->entity = $conf->entity; // If not defined, we use default value
724 }
725
726 return $this->createCommon($user, $notrigger);
727 }
728
735 public function update($notrigger = 0)
736 {
737 global $user, $conf;
738
739 if (!empty($this->name)) {
740 $this->nom = $this->name; // Field for 'name' is called 'nom' in database
741 }
742
743 if (!empty($this->note_private)) {
744 $this->note = $this->note_private; // Field for 'note_private' is called 'note' in database
745 }
746
747 return $this->updateCommon($user, $notrigger);
748 }
749
750
760 public function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0)
761 {
762 //print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n";
763 $lastname = $this->lastname;
764 $firstname = $this->firstname;
765 if (empty($lastname)) {
766 $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 : '')))));
767 }
768
769 $ret = '';
770 if (!empty($option) && !empty($this->civility_code)) {
771 if ($langs->transnoentitiesnoconv("Civility".$this->civility_code) != "Civility".$this->civility_code) {
772 $ret .= $langs->transnoentitiesnoconv("Civility".$this->civility_code).' ';
773 } else {
774 $ret .= $this->civility_code.' ';
775 }
776 }
777
778 $ret .= dolGetFirstLastname((string) $firstname, (string) $lastname, $nameorder);
779
780 return dol_trunc($ret, $maxlen);
781 }
782
789 public function getLibStatut($mode = 0)
790 {
791 return $this->LibStatut(0, $mode);
792 }
793
794 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
802 public function LibStatut($status, $mode = 0)
803 {
804 // phpcs:enable
805 global $langs;
806 $langs->load('users');
807 return '';
808 }
809
816 public function getTooltipContentArray($params)
817 {
818 global $conf, $langs, $menumanager;
819
820 $option = $params['option'] ?? '';
821
822 $datas = [];
823 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
824 $langs->load("users");
825 return ['optimize' => $langs->trans("ShowGroup")];
826 }
827 $datas['divopen'] = '<div class="centpercent">';
828 $datas['picto'] = img_picto('', 'group').' <u>'.$langs->trans("Group").'</u><br>';
829 $datas['name'] = '<b>'.$langs->trans('Name').':</b> '.$this->name;
830 $datas['description'] = '<br><b>'.$langs->trans("Description").':</b> '.$this->note;
831 $datas['divclose'] = '</div>';
832
833 return $datas;
834 }
835
847 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
848 {
849 global $langs, $conf, $db, $hookmanager;
850
851 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') && $withpicto) {
852 $withpicto = 0;
853 }
854
855 $result = '';
856 $params = [
857 'id' => $this->id,
858 'objecttype' => $this->element,
859 'option' => $option,
860 ];
861 $classfortooltip = 'classfortooltip';
862 $dataparams = '';
863 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
864 $classfortooltip = 'classforajaxtooltip';
865 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
866 $label = '';
867 } else {
868 $label = implode($this->getTooltipContentArray($params));
869 }
870
871 if ($option == 'permissions') {
872 $baseurl = DOL_URL_ROOT.'/user/group/perms.php';
873 } else {
874 $baseurl = DOL_URL_ROOT.'/user/group/card.php';
875 }
876 $query = ['id' => $this->id];
877
878 if ($option != 'nolink') {
879 // Add param to save lastsearch_values or not
880 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
881 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
882 $add_save_lastsearch_values = 1;
883 }
884 if ($add_save_lastsearch_values) {
885 $query = array_merge($query, ['save_lastsearch_values' => 1]);
886 }
887 }
888 $url = dolBuildUrl($baseurl, $query);
889
890 $linkclose = "";
891 if (empty($notooltip)) {
892 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
893 $langs->load("users");
894 $label = $langs->trans("ShowGroup");
895 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1, 1).'"';
896 }
897 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
898 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
899 }
900
901 $linkstart = '<a href="'.$url.'"';
902 $linkstart .= $linkclose.'>';
903 $linkend = '</a>';
904
905 $result = $linkstart;
906 if ($withpicto) {
907 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
908 }
909 if ($withpicto != 2) {
910 $result .= $this->name;
911 }
912 $result .= $linkend;
913
914 global $action;
915 $hookmanager->initHooks(array('groupdao'));
916 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
917 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
918 if ($reshook > 0) {
919 $result = $hookmanager->resPrint;
920 } else {
921 $result .= $hookmanager->resPrint;
922 }
923
924 return $result;
925 }
926
927 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
928 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
938 public function _load_ldap_dn($info, $mode = 0)
939 {
940 // phpcs:enable
941 global $conf;
942 $dn = '';
943 if ($mode == 0) {
944 $dn = getDolGlobalString('LDAP_KEY_GROUPS') . "=".$info[getDolGlobalString('LDAP_KEY_GROUPS')]."," . getDolGlobalString('LDAP_GROUP_DN');
945 }
946 if ($mode == 1) {
947 $dn = getDolGlobalString('LDAP_GROUP_DN');
948 }
949 if ($mode == 2) {
950 $dn = getDolGlobalString('LDAP_KEY_GROUPS') . "=".$info[getDolGlobalString('LDAP_KEY_GROUPS')];
951 }
952 return $dn;
953 }
954
955
956 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
957 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
963 public function _load_ldap_info()
964 {
965 // phpcs:enable
966 global $conf;
967
968 $info = array();
969
970 // Object classes
971 $info["objectclass"] = explode(',', getDolGlobalString('LDAP_GROUP_OBJECT_CLASS'));
972
973 // Champs
974 if ($this->name && getDolGlobalString('LDAP_GROUP_FIELD_FULLNAME')) {
975 $info[getDolGlobalString('LDAP_GROUP_FIELD_FULLNAME')] = $this->name;
976 }
977 //if ($this->name && !empty($conf->global->LDAP_GROUP_FIELD_NAME)) $info[$conf->global->LDAP_GROUP_FIELD_NAME] = $this->name;
978 if ($this->note && getDolGlobalString('LDAP_GROUP_FIELD_DESCRIPTION')) {
979 $info[getDolGlobalString('LDAP_GROUP_FIELD_DESCRIPTION')] = dol_string_nohtmltag($this->note, 2);
980 }
981 if (getDolGlobalString('LDAP_GROUP_FIELD_GROUPMEMBERS')) {
982 $valueofldapfield = array();
983 foreach ($this->members as $key => $val) { // This is array of users for group into dolibarr database.
984 $muser = new User($this->db);
985 $muser->fetch($val->id);
986 $info2 = $muser->_load_ldap_info();
987 $valueofldapfield[] = $muser->_load_ldap_dn($info2);
988 }
989 $info[getDolGlobalString('LDAP_GROUP_FIELD_GROUPMEMBERS')] = (!empty($valueofldapfield) ? $valueofldapfield : '');
990 }
991 if (getDolGlobalString('LDAP_GROUP_FIELD_GROUPID')) {
992 $info[getDolGlobalString('LDAP_GROUP_FIELD_GROUPID')] = $this->id;
993 }
994 return $info;
995 }
996
997
1005 public function initAsSpecimen()
1006 {
1007 global $conf, $user, $langs;
1008
1009 // Initialise parameters
1010 $this->id = 0;
1011 $this->ref = 'SPECIMEN';
1012 $this->specimen = 1;
1013
1014 $this->name = 'DOLIBARR GROUP SPECIMEN';
1015 $this->note = 'This is a note';
1016 $this->datec = time();
1017 $this->tms = time();
1018
1019 // Members of this group is just me
1020 $this->members = array(
1021 $user->id => $user
1022 );
1023
1024 return 1;
1025 }
1026
1038 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1039 {
1040 global $conf, $user, $langs;
1041
1042 $langs->load("user");
1043
1044 // Positionne le modele sur le nom du modele a utiliser
1045 if (!dol_strlen($modele)) {
1046 if (getDolGlobalString('USERGROUP_ADDON_PDF')) {
1047 $modele = getDolGlobalString('USERGROUP_ADDON_PDF');
1048 } else {
1049 $modele = 'grass';
1050 }
1051 }
1052
1053 $modelpath = "core/modules/usergroup/doc/";
1054
1055 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1056 }
1057
1065 public function getKanbanView($option = '', $arraydata = null)
1066 {
1067 global $langs;
1068
1069 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1070
1071 $return = '<div class="box-flex-item box-flex-grow-zero">';
1072 $return .= '<div class="info-box info-box-sm">';
1073 $return .= '<span class="info-box-icon bg-infobox-action">';
1074 $return .= img_picto('', $this->picto);
1075 $return .= '</span>';
1076 $return .= '<div class="info-box-content">';
1077 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1078 if ($selected >= 0) {
1079 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1080 }
1081 if (property_exists($this, 'members')) {
1082 $return .= '<br><span class="info-box-status opacitymedium">'.(empty($this->nb_users) ? 0 : $this->nb_users).' '.$langs->trans('Users').'</span>';
1083 }
1084 if (property_exists($this, 'nb_rights')) {
1085 $return .= '<br><div class="info-box-status margintoponly opacitymedium">'.$langs->trans('NbOfPermissions').' : '.(empty($this->nb_rights) ? 0 : $this->nb_rights).'</div>';
1086 }
1087 $return .= '</div>';
1088 $return .= '</div>';
1089 $return .= '</div>';
1090 return $return;
1091 }
1092}
$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)
Returns the full DN string in the LDAP directory for the object.
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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)
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
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:140