dolibarr 24.0.0-beta
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-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 $sanitizedwhereforadd = $whereforadd;
408 $sql .= " AND ".$sanitizedwhereforadd;
409 }
410
411 $result = $this->db->query($sql);
412 if ($result) {
413 $num = $this->db->num_rows($result);
414 $i = 0;
415 while ($i < $num) {
416 $obj = $this->db->fetch_object($result);
417 $nid = $obj->id;
418
419 $sql = "DELETE FROM ".$this->db->prefix()."usergroup_rights WHERE fk_usergroup = ".((int) $this->id)." AND fk_id=".((int) $nid)." AND entity = ".((int) $entity);
420 if (!$this->db->query($sql)) {
421 $error++;
422 }
423 $sql = "INSERT INTO ".$this->db->prefix()."usergroup_rights (entity, fk_usergroup, fk_id) VALUES (".((int) $entity).", ".((int) $this->id).", ".((int) $nid).")";
424 if (!$this->db->query($sql)) {
425 $error++;
426 }
427
428 $i++;
429 }
430 } else {
431 $error++;
432 dol_print_error($this->db);
433 }
434
435 if (!$error) {
436 $langs->load("other");
437 $this->context = array('audit' => $langs->trans("PermissionsAdd").($rid ? ' (id='.$rid.')' : ''));
438
439 // Call trigger
440 $result = $this->call_trigger('USERGROUP_MODIFY', $user);
441 if ($result < 0) {
442 $error++;
443 }
444 // End call triggers
445 }
446 }
447
448 if ($error) {
449 $this->db->rollback();
450 return -$error;
451 } else {
452 $this->db->commit();
453 return 1;
454 }
455 }
456
457
467 public function delrights($rid, $allmodule = '', $allperms = '', $entity = 0)
468 {
469 global $conf, $user, $langs;
470
471 $error = 0;
472 $wherefordel = '';
473
474 $entity = (!empty($entity) ? $entity : $conf->entity);
475
476 $this->db->begin();
477
478 if (!empty($rid)) {
479 $module = $perms = $subperms = '';
480
481 // If a specific permission deletion was requested, we retrieve
482 // the module characteristics, perms and subperms of this right.
483 $sql = "SELECT module, perms, subperms";
484 $sql .= " FROM ".$this->db->prefix()."rights_def";
485 $sql .= " WHERE id = ".((int) $rid);
486 $sql .= " AND entity = ".((int) $entity);
487
488 $result = $this->db->query($sql);
489 if ($result) {
490 $obj = $this->db->fetch_object($result);
491 if ($obj) {
492 $module = $obj->module;
493 $perms = $obj->perms;
494 $subperms = $obj->subperms;
495 }
496 } else {
497 $error++;
498 dol_print_error($this->db);
499 }
500
501 // Where for the list of permissions to delete
502 $wherefordel = "id = ".((int) $rid);
503 // Deletion of inherited permissions
504 if ($subperms == 'lire' || $subperms == 'read') {
505 $wherefordel .= " OR (module='".$this->db->escape($module)."' AND perms='".$this->db->escape($perms)."' AND subperms IS NOT NULL)";
506 }
507 if ($perms == 'lire' || $perms == 'read') {
508 $wherefordel .= " OR (module='".$this->db->escape($module)."')";
509 }
510
511 // Pour compatibility, if lowid = 0, we are in removal all mode
512 // TODO To remove when this will be implemented by the caller
513 //if (substr($rid,-1,1) == 0) $wherefordel="module='$module'";
514 } else {
515 // Add permission of the list $wherefordel
516 if (!empty($allmodule)) {
517 if ($allmodule == 'allmodules') {
518 $wherefordel = 'allmodules';
519 } else {
520 $wherefordel = "module='".$this->db->escape($allmodule)."'";
521 if (!empty($allperms)) {
522 $wherefordel .= " AND perms='".$this->db->escape($allperms)."'";
523 }
524 }
525 }
526 }
527
528 // Deletion of permissions of the list wherefordel
529 if (!empty($wherefordel)) {
530 //print "$module-$perms-$subperms";
531 $sql = "SELECT id";
532 $sql .= " FROM ".$this->db->prefix()."rights_def";
533 $sql .= " WHERE entity = ".((int) $entity);
534 if (!empty($wherefordel) && $wherefordel != 'allmodules') {
535 $sanitizedwherefordel = $wherefordel;
536 $sql .= " AND ".$sanitizedwherefordel;
537 }
538
539 $result = $this->db->query($sql);
540 if ($result) {
541 $num = $this->db->num_rows($result);
542 $i = 0;
543 while ($i < $num) {
544 $nid = 0;
545
546 $obj = $this->db->fetch_object($result);
547 if ($obj) {
548 $nid = $obj->id;
549 }
550
551 $sql = "DELETE FROM ".$this->db->prefix()."usergroup_rights";
552 $sql .= " WHERE fk_usergroup = $this->id AND fk_id=".((int) $nid);
553 $sql .= " AND entity = ".((int) $entity);
554 if (!$this->db->query($sql)) {
555 $error++;
556 }
557
558 $i++;
559 }
560 } else {
561 $error++;
562 dol_print_error($this->db);
563 }
564
565 if (!$error) {
566 $langs->load("other");
567 $this->context = array('audit' => $langs->trans("PermissionsDelete").($rid ? ' (id='.$rid.')' : ''));
568
569 // Call trigger
570 $result = $this->call_trigger('USERGROUP_MODIFY', $user);
571 if ($result < 0) {
572 $error++;
573 }
574 // End call triggers
575 }
576 }
577
578 if ($error) {
579 $this->db->rollback();
580 return -$error;
581 } else {
582 $this->db->commit();
583 return 1;
584 }
585 }
586
597 public function getrights($moduletag = '')
598 {
599 return $this->loadRights($moduletag);
600 }
601
608 public function loadRights($moduletag = '')
609 {
610 global $conf;
611
612 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
613 // Rights for this module are already loaded, so we leave
614 return 0;
615 }
616
617 if (!empty($this->all_permissions_are_loaded)) {
618 // We already loaded all rights for this group, so we leave
619 return 0;
620 }
621
622 // Load permission from group
623 $sql = "SELECT r.module, r.perms, r.subperms ";
624 $sql .= " FROM ".$this->db->prefix()."usergroup_rights as u, ".$this->db->prefix()."rights_def as r";
625 $sql .= " WHERE r.id = u.fk_id";
626 $sql .= " AND r.entity = ".((int) $conf->entity);
627 $sql .= " AND u.entity = ".((int) $conf->entity);
628 $sql .= " AND u.fk_usergroup = ".((int) $this->id);
629 $sql .= " AND r.perms IS NOT NULL";
630 if ($moduletag) {
631 $sql .= " AND r.module = '".$this->db->escape($moduletag)."'";
632 }
633
634 dol_syslog(get_class($this).'::getrights', LOG_DEBUG);
635 $resql = $this->db->query($sql);
636 if ($resql) {
637 $num = $this->db->num_rows($resql);
638 $i = 0;
639 while ($i < $num) {
640 $obj = $this->db->fetch_object($resql);
641
642 if ($obj) {
643 $module = $obj->module;
644 $perms = $obj->perms;
645 $subperms = $obj->subperms;
646
647 if ($perms) {
648 if (!isset($this->rights)) {
649 $this->rights = new stdClass(); // For avoid error
650 }
651 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
652 $this->rights->$module = new stdClass();
653 }
654 if ($subperms) {
655 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
656 $this->rights->$module->$perms = new stdClass();
657 }
658 if (empty($this->rights->$module->$perms->$subperms)) {
659 $this->nb_rights++;
660 }
661 $this->rights->$module->$perms->$subperms = 1;
662 } else {
663 if (empty($this->rights->$module->$perms)) {
664 $this->nb_rights++;
665 }
666 $this->rights->$module->$perms = 1;
667 }
668 }
669 }
670
671 $i++;
672 }
673 $this->db->free($resql);
674 }
675
676 if ($moduletag == '') {
677 // Si module etait non defini, alors on a tout charge, on peut donc considerer
678 // que les droits sont en cache (car tous charges) pour cet instance de group
679 $this->all_permissions_are_loaded = 1;
680 } else {
681 // If module defined, we flag it as loaded into cache
682 $this->_tab_loaded[$moduletag] = 1;
683 }
684
685 return 1;
686 }
687
694 public function delete(User $user)
695 {
696 return $this->deleteCommon($user);
697 }
698
705 public function create($notrigger = 0)
706 {
707 global $user, $conf;
708
709 $this->datec = dol_now();
710 if (!empty($this->name)) {
711 $this->nom = $this->name; // Field for 'name' is called 'nom' in database
712 }
713 if (!empty($this->note_private)) {
714 $this->note = $this->note_private; // Field for 'note_private' is called 'note' in database
715 }
716
717 if (!isset($this->entity)) {
718 $this->entity = $conf->entity; // If not defined, we use default value
719 }
720
721 return $this->createCommon($user, $notrigger);
722 }
723
730 public function update($notrigger = 0)
731 {
732 global $user, $conf;
733
734 if (!empty($this->name)) {
735 $this->nom = $this->name; // Field for 'name' is called 'nom' in database
736 }
737
738 if (!empty($this->note_private)) {
739 $this->note = $this->note_private; // Field for 'note_private' is called 'note' in database
740 }
741
742 return $this->updateCommon($user, $notrigger);
743 }
744
745
755 public function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0)
756 {
757 //print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n";
758 $lastname = $this->lastname;
759 $firstname = $this->firstname;
760 if (empty($lastname)) {
761 $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 : '')))));
762 }
763
764 $ret = '';
765 if (!empty($option) && !empty($this->civility_code)) {
766 if ($langs->transnoentitiesnoconv("Civility".$this->civility_code) != "Civility".$this->civility_code) {
767 $ret .= $langs->transnoentitiesnoconv("Civility".$this->civility_code).' ';
768 } else {
769 $ret .= $this->civility_code.' ';
770 }
771 }
772
773 $ret .= dolGetFirstLastname((string) $firstname, (string) $lastname, $nameorder);
774
775 return dol_trunc($ret, $maxlen);
776 }
777
784 public function getLibStatut($mode = 0)
785 {
786 return $this->LibStatut(0, $mode);
787 }
788
789 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
797 public function LibStatut($status, $mode = 0)
798 {
799 // phpcs:enable
800 global $langs;
801 $langs->load('users');
802 return '';
803 }
804
811 public function getTooltipContentArray($params)
812 {
813 global $conf, $langs, $menumanager;
814
815 $option = $params['option'] ?? '';
816
817 $datas = [];
818 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
819 $langs->load("users");
820 return ['optimize' => $langs->trans("ShowGroup")];
821 }
822 $datas['divopen'] = '<div class="centpercent">';
823 $datas['picto'] = img_picto('', 'group').' <u>'.$langs->trans("Group").'</u><br>';
824 $datas['name'] = '<b>'.$langs->trans('Name').':</b> '.$this->name;
825 $datas['description'] = '<br><b>'.$langs->trans("Description").':</b> '.$this->note;
826 $datas['divclose'] = '</div>';
827
828 return $datas;
829 }
830
842 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
843 {
844 global $langs, $conf, $db, $hookmanager;
845
846 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') && $withpicto) {
847 $withpicto = 0;
848 }
849
850 $result = '';
851 $params = [
852 'id' => $this->id,
853 'objecttype' => $this->element,
854 'option' => $option,
855 ];
856 $classfortooltip = 'classfortooltip';
857 $dataparams = '';
858 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
859 $classfortooltip = 'classforajaxtooltip';
860 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
861 $label = '';
862 } else {
863 $label = implode($this->getTooltipContentArray($params));
864 }
865
866 if ($option == 'permissions') {
867 $baseurl = DOL_URL_ROOT.'/user/group/perms.php';
868 } else {
869 $baseurl = DOL_URL_ROOT.'/user/group/card.php';
870 }
871 $query = ['id' => $this->id];
872
873 if ($option != 'nolink') {
874 // Add param to save lastsearch_values or not
875 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
876 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
877 $add_save_lastsearch_values = 1;
878 }
879 if ($add_save_lastsearch_values) {
880 $query = array_merge($query, ['save_lastsearch_values' => 1]);
881 }
882 }
883 $url = dolBuildUrl($baseurl, $query);
884
885 $linkclose = "";
886 if (empty($notooltip)) {
887 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
888 $langs->load("users");
889 $label = $langs->trans("ShowGroup");
890 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1, 1).'"';
891 }
892 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
893 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
894 }
895
896 $linkstart = '<a href="'.$url.'"';
897 $linkstart .= $linkclose.'>';
898 $linkend = '</a>';
899
900 $result = $linkstart;
901 if ($withpicto) {
902 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
903 }
904 if ($withpicto != 2) {
905 $result .= $this->name;
906 }
907 $result .= $linkend;
908
909 global $action;
910 $hookmanager->initHooks(array('groupdao'));
911 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
912 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
913 if ($reshook > 0) {
914 $result = $hookmanager->resPrint;
915 } else {
916 $result .= $hookmanager->resPrint;
917 }
918
919 return $result;
920 }
921
922 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
923 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
933 public function _load_ldap_dn($info, $mode = 0)
934 {
935 // phpcs:enable
936 global $conf;
937 $dn = '';
938 if ($mode == 0) {
939 $dn = getDolGlobalString('LDAP_KEY_GROUPS') . "=".$info[getDolGlobalString('LDAP_KEY_GROUPS')]."," . getDolGlobalString('LDAP_GROUP_DN');
940 }
941 if ($mode == 1) {
942 $dn = getDolGlobalString('LDAP_GROUP_DN');
943 }
944 if ($mode == 2) {
945 $dn = getDolGlobalString('LDAP_KEY_GROUPS') . "=".$info[getDolGlobalString('LDAP_KEY_GROUPS')];
946 }
947 return $dn;
948 }
949
950
951 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
952 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
958 public function _load_ldap_info()
959 {
960 // phpcs:enable
961 global $conf;
962
963 $info = array();
964
965 // Object classes
966 $info["objectclass"] = explode(',', getDolGlobalString('LDAP_GROUP_OBJECT_CLASS'));
967
968 // Champs
969 if ($this->name && getDolGlobalString('LDAP_GROUP_FIELD_FULLNAME')) {
970 $info[getDolGlobalString('LDAP_GROUP_FIELD_FULLNAME')] = $this->name;
971 }
972 //if ($this->name && !empty($conf->global->LDAP_GROUP_FIELD_NAME)) $info[$conf->global->LDAP_GROUP_FIELD_NAME] = $this->name;
973 if ($this->note && getDolGlobalString('LDAP_GROUP_FIELD_DESCRIPTION')) {
974 $info[getDolGlobalString('LDAP_GROUP_FIELD_DESCRIPTION')] = dol_string_nohtmltag($this->note, 2);
975 }
976 if (getDolGlobalString('LDAP_GROUP_FIELD_GROUPMEMBERS')) {
977 $valueofldapfield = array();
978 foreach ($this->members as $key => $val) { // This is array of users for group into dolibarr database.
979 $muser = new User($this->db);
980 $muser->fetch($val->id);
981 $info2 = $muser->_load_ldap_info();
982 $valueofldapfield[] = $muser->_load_ldap_dn($info2);
983 }
984 $info[getDolGlobalString('LDAP_GROUP_FIELD_GROUPMEMBERS')] = (!empty($valueofldapfield) ? $valueofldapfield : '');
985 }
986 if (getDolGlobalString('LDAP_GROUP_FIELD_GROUPID')) {
987 $info[getDolGlobalString('LDAP_GROUP_FIELD_GROUPID')] = $this->id;
988 }
989 return $info;
990 }
991
992
1000 public function initAsSpecimen()
1001 {
1002 global $conf, $user, $langs;
1003
1004 // Initialise parameters
1005 $this->id = 0;
1006 $this->ref = 'SPECIMEN';
1007 $this->specimen = 1;
1008
1009 $this->name = 'DOLIBARR GROUP SPECIMEN';
1010 $this->note = 'This is a note';
1011 $this->datec = time();
1012 $this->tms = time();
1013
1014 // Members of this group is just me
1015 $this->members = array(
1016 $user->id => $user
1017 );
1018
1019 return 1;
1020 }
1021
1033 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1034 {
1035 global $conf, $user, $langs;
1036
1037 $langs->load("user");
1038
1039 // Positionne le modele sur le nom du modele a utiliser
1040 if (!dol_strlen($modele)) {
1041 if (getDolGlobalString('USERGROUP_ADDON_PDF')) {
1042 $modele = getDolGlobalString('USERGROUP_ADDON_PDF');
1043 } else {
1044 $modele = 'grass';
1045 }
1046 }
1047
1048 $modelpath = "core/modules/usergroup/doc/";
1049
1050 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1051 }
1052
1060 public function getKanbanView($option = '', $arraydata = null)
1061 {
1062 global $langs;
1063
1064 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1065
1066 $return = '<div class="box-flex-item box-flex-grow-zero">';
1067 $return .= '<div class="info-box info-box-sm">';
1068 $return .= '<span class="info-box-icon bg-infobox-action">';
1069 $return .= img_picto('', $this->picto);
1070 $return .= '</span>';
1071 $return .= '<div class="info-box-content">';
1072 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1073 if ($selected >= 0) {
1074 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1075 }
1076 if (property_exists($this, 'members')) {
1077 $return .= '<br><span class="info-box-status opacitymedium">'.(empty($this->nb_users) ? 0 : $this->nb_users).' '.$langs->trans('Users').'</span>';
1078 }
1079 if (property_exists($this, 'nb_rights')) {
1080 $return .= '<br><div class="info-box-status margintoponly opacitymedium">'.$langs->trans('NbOfPermissions').' : '.(empty($this->nb_rights) ? 0 : $this->nb_rights).'</div>';
1081 }
1082 $return .= '</div>';
1083 $return .= '</div>';
1084 $return .= '</div>';
1085 return $return;
1086 }
1087}
$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:133