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