dolibarr 22.0.5
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-2024 Frédéric France <frederic.france@free.fr>
11 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <https://www.gnu.org/licenses/>.
25 */
26
32require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
33if (isModEnabled('ldap')) {
34 require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
35}
36
37
42{
46 public $element = 'usergroup';
47
51 public $table_element = 'usergroup';
52
56 public $picto = 'group';
57
61 public $entity;
62
68 public $nom;
69
73 public $name; // Name of group
74
78 public $globalgroup; // Global group
79
84 public $usergroup_entity;
85
91 public $datec;
92
96 public $note;
97
101 public $members = array();
102
106 public $nb_rights;
107
111 public $nb_users;
112
116 public $rights;
117
121 private $_tab_loaded = array(); // Array of cache of already loaded permissions
122
126 public $all_permissions_are_loaded;
127
128 public $fields = array(
129 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'index' => 1, 'position' => 1, 'comment' => 'Id'),
130 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'default' => '1', 'index' => 1, 'position' => 5),
131 'nom' => array('type' => 'varchar(180)', 'label' => 'Name', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'showoncombobox' => 1, 'index' => 1, 'position' => 10, 'searchall' => 1, 'comment' => 'Group name'),
132 'note' => array('type' => 'html', 'label' => 'Description', 'enabled' => 1, 'visible' => 1, 'position' => 20, 'notnull' => -1, 'searchall' => 1),
133 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -2, 'position' => 50, 'notnull' => 1,),
134 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -2, 'position' => 60, 'notnull' => 1,),
135 'model_pdf' => array('type' => 'varchar(255)', 'label' => 'ModelPDF', 'enabled' => 1, 'visible' => 0, 'position' => 100),
136 );
137
141 public $fk_element = 'fk_usergroup';
142
146 protected $childtables = array();
147
151 protected $childtablesoncascade = array('usergroup_rights', 'usergroup_user');
152
156 public $isextrafieldmanaged = 1;
157
158
164 public function __construct($db)
165 {
166 $this->db = $db;
167
168 $this->ismultientitymanaged = 1;
169 $this->nb_rights = 0;
170 }
171
172
181 public function fetch($id = 0, $groupname = '', $load_members = false)
182 {
183 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
184 if (!empty($groupname)) {
185 $result = $this->fetchCommon(0, '', ' AND nom = \''.$this->db->escape($groupname).'\'');
186 } else {
187 $result = $this->fetchCommon($id);
188 }
189
190 $this->name = $this->nom; // For compatibility with field name
191
192 if ($result) {
193 if ($load_members) {
194 $excludefilter = '';
195 $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
196 }
197
198 return 1;
199 } else {
200 $this->error = $this->db->lasterror();
201 return -1;
202 }
203 }
204
205
213 public function listGroupsForUser($userid, $load_members = true)
214 {
215 global $conf, $user;
216
217 $ret = array();
218
219 $sql = "SELECT g.rowid, ug.entity as usergroup_entity";
220 $sql .= " FROM ".$this->db->prefix()."usergroup as g,";
221 $sql .= " ".$this->db->prefix()."usergroup_user as ug";
222 $sql .= " WHERE ug.fk_usergroup = g.rowid";
223 $sql .= " AND ug.fk_user = ".((int) $userid);
224 if (isModEnabled('multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
225 $sql .= " AND g.entity IS NOT NULL";
226 } else {
227 $sql .= " AND g.entity IN (0,".$conf->entity.")";
228 }
229 $sql .= " ORDER BY g.nom";
230
231 dol_syslog(get_class($this)."::listGroupsForUser", LOG_DEBUG);
232 $result = $this->db->query($sql);
233 if ($result) {
234 while ($obj = $this->db->fetch_object($result)) {
235 if (!array_key_exists($obj->rowid, $ret)) {
236 $newgroup = new UserGroup($this->db);
237 $newgroup->fetch($obj->rowid, '', $load_members);
238 $ret[$obj->rowid] = $newgroup;
239 }
240 if (!is_array($ret[$obj->rowid]->usergroup_entity)) {
241 $ret[$obj->rowid]->usergroup_entity = array();
242 }
243 // $ret[$obj->rowid] is instance of UserGroup
244 $ret[$obj->rowid]->usergroup_entity[] = (int) $obj->usergroup_entity;
245 }
246
247 $this->db->free($result);
248
249 return $ret;
250 } else {
251 $this->error = $this->db->lasterror();
252 return -1;
253 }
254 }
255
263 public function listUsersForGroup($excludefilter = '', $mode = 0)
264 {
265 global $conf, $user;
266
267 $ret = array();
268
269 $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";
270 if (!empty($this->id)) {
271 $sql .= ", ug.entity as usergroup_entity";
272 }
273 $sql .= " FROM ".$this->db->prefix()."user as u";
274 if (!empty($this->id)) {
275 $sql .= ", ".$this->db->prefix()."usergroup_user as ug";
276 }
277 $sql .= " WHERE 1 = 1";
278 if (!empty($this->id)) {
279 $sql .= " AND ug.fk_user = u.rowid";
280 }
281 if (!empty($this->id)) {
282 $sql .= " AND ug.fk_usergroup = ".((int) $this->id);
283 }
284 if (isModEnabled('multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
285 $sql .= " AND u.entity IS NOT NULL";
286 } else {
287 $sql .= " AND u.entity IN (0,".$conf->entity.")";
288 }
289 if (!empty($excludefilter)) {
290 $sql .= ' AND ('.$excludefilter.')';
291 }
292
293 dol_syslog(get_class($this)."::listUsersForGroup", LOG_DEBUG);
294 $resql = $this->db->query($sql);
295
296 if ($resql) {
297 while ($obj = $this->db->fetch_object($resql)) {
298 if (!array_key_exists($obj->rowid, $ret)) {
299 if ($mode != 1) {
300 $newuser = new User($this->db);
301 //$newuser->fetch($obj->rowid); // We are inside a loop, no subrequests inside a loop
302 $newuser->id = $obj->rowid;
303 $newuser->login = $obj->login;
304 $newuser->photo = $obj->photo;
305 $newuser->lastname = $obj->lastname;
306 $newuser->firstname = $obj->firstname;
307 $newuser->email = $obj->email;
308 $newuser->socid = $obj->fk_soc;
309 $newuser->entity = $obj->entity;
310 $newuser->employee = $obj->employee;
311 $newuser->status = $obj->status;
312
313 $ret[$obj->rowid] = $newuser;
314 } else {
315 $ret[$obj->rowid] = $obj->rowid;
316 }
317 }
318 if ($mode != 1 && !empty($obj->usergroup_entity)) {
319 // $ret[$obj->rowid] is instance of User
320 if (!is_array($ret[$obj->rowid]->usergroup_entity)) {
321 $ret[$obj->rowid]->usergroup_entity = array();
322 }
323 $ret[$obj->rowid]->usergroup_entity[] = (int) $obj->usergroup_entity;
324 }
325 }
326
327 $this->db->free($resql);
328
329 return $ret;
330 } else {
331 $this->error = $this->db->lasterror();
332 return -1;
333 }
334 }
335
345 public function addrights($rid, $allmodule = '', $allperms = '', $entity = 0)
346 {
347 global $conf, $user, $langs;
348
349 $entity = (!empty($entity) ? $entity : $conf->entity);
350
351 dol_syslog(get_class($this)."::addrights $rid, $allmodule, $allperms, $entity");
352 $error = 0;
353 $whereforadd = '';
354
355 $this->db->begin();
356
357 if (!empty($rid)) {
358 $module = $perms = $subperms = '';
359
360 // Si on a demande ajout d'un droit en particulier, on recupere
361 // les caracteristiques (module, perms et subperms) de ce droit.
362 $sql = "SELECT module, perms, subperms";
363 $sql .= " FROM ".$this->db->prefix()."rights_def";
364 $sql .= " WHERE id = ".((int) $rid);
365 $sql .= " AND entity = ".((int) $entity);
366
367 $result = $this->db->query($sql);
368 if ($result) {
369 $obj = $this->db->fetch_object($result);
370 if ($obj) {
371 $module = $obj->module;
372 $perms = $obj->perms;
373 $subperms = $obj->subperms;
374 }
375 } else {
376 $error++;
377 dol_print_error($this->db);
378 }
379
380 // Where pour la liste des droits a ajouter
381 $whereforadd = "id=".((int) $rid);
382 // Find also rights that are herited to add them too
383 if ($subperms) {
384 $whereforadd .= " OR (module='".$this->db->escape($module)."' AND perms='".$this->db->escape($perms)."' AND (subperms='lire' OR subperms='read'))";
385 } elseif ($perms) {
386 $whereforadd .= " OR (module='".$this->db->escape($module)."' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
387 }
388 } else {
389 // Where pour la liste des droits a ajouter
390 if (!empty($allmodule)) {
391 if ($allmodule == 'allmodules') {
392 $whereforadd = 'allmodules';
393 } else {
394 $whereforadd = "module='".$this->db->escape($allmodule)."'";
395 if (!empty($allperms)) {
396 $whereforadd .= " AND perms='".$this->db->escape($allperms)."'";
397 }
398 }
399 }
400 }
401
402 // Add permission of the list $whereforadd
403 if (!empty($whereforadd)) {
404 //print "$module-$perms-$subperms";
405 $sql = "SELECT id";
406 $sql .= " FROM ".$this->db->prefix()."rights_def";
407 $sql .= " WHERE entity = ".((int) $entity);
408 if (!empty($whereforadd) && $whereforadd != 'allmodules') {
409 $sql .= " AND ".$whereforadd;
410 }
411
412 $result = $this->db->query($sql);
413 if ($result) {
414 $num = $this->db->num_rows($result);
415 $i = 0;
416 while ($i < $num) {
417 $obj = $this->db->fetch_object($result);
418 $nid = $obj->id;
419
420 $sql = "DELETE FROM ".$this->db->prefix()."usergroup_rights WHERE fk_usergroup = ".((int) $this->id)." AND fk_id=".((int) $nid)." AND entity = ".((int) $entity);
421 if (!$this->db->query($sql)) {
422 $error++;
423 }
424 $sql = "INSERT INTO ".$this->db->prefix()."usergroup_rights (entity, fk_usergroup, fk_id) VALUES (".((int) $entity).", ".((int) $this->id).", ".((int) $nid).")";
425 if (!$this->db->query($sql)) {
426 $error++;
427 }
428
429 $i++;
430 }
431 } else {
432 $error++;
433 dol_print_error($this->db);
434 }
435
436 if (!$error) {
437 $langs->load("other");
438 $this->context = array('audit' => $langs->trans("PermissionsAdd").($rid ? ' (id='.$rid.')' : ''));
439
440 // Call trigger
441 $result = $this->call_trigger('USERGROUP_MODIFY', $user);
442 if ($result < 0) {
443 $error++;
444 }
445 // End call triggers
446 }
447 }
448
449 if ($error) {
450 $this->db->rollback();
451 return -$error;
452 } else {
453 $this->db->commit();
454 return 1;
455 }
456 }
457
458
468 public function delrights($rid, $allmodule = '', $allperms = '', $entity = 0)
469 {
470 global $conf, $user, $langs;
471
472 $error = 0;
473 $wherefordel = '';
474
475 $entity = (!empty($entity) ? $entity : $conf->entity);
476
477 $this->db->begin();
478
479 if (!empty($rid)) {
480 $module = $perms = $subperms = '';
481
482 // Si on a demande suppression d'un droit en particulier, on recupere
483 // les caracteristiques module, perms et subperms de ce droit.
484 $sql = "SELECT module, perms, subperms";
485 $sql .= " FROM ".$this->db->prefix()."rights_def";
486 $sql .= " WHERE id = ".((int) $rid);
487 $sql .= " AND entity = ".((int) $entity);
488
489 $result = $this->db->query($sql);
490 if ($result) {
491 $obj = $this->db->fetch_object($result);
492 if ($obj) {
493 $module = $obj->module;
494 $perms = $obj->perms;
495 $subperms = $obj->subperms;
496 }
497 } else {
498 $error++;
499 dol_print_error($this->db);
500 }
501
502 // Where for the list of permissions to delete
503 $wherefordel = "id = ".((int) $rid);
504 // Suppression des droits induits
505 if ($subperms == 'lire' || $subperms == 'read') {
506 $wherefordel .= " OR (module='".$this->db->escape($module)."' AND perms='".$this->db->escape($perms)."' AND subperms IS NOT NULL)";
507 }
508 if ($perms == 'lire' || $perms == 'read') {
509 $wherefordel .= " OR (module='".$this->db->escape($module)."')";
510 }
511
512 // Pour compatibilite, si lowid = 0, on est en mode suppression de tout
513 // TODO To remove when this will be implemented by the caller
514 //if (substr($rid,-1,1) == 0) $wherefordel="module='$module'";
515 } else {
516 // Add permission of the list $wherefordel
517 if (!empty($allmodule)) {
518 if ($allmodule == 'allmodules') {
519 $wherefordel = 'allmodules';
520 } else {
521 $wherefordel = "module='".$this->db->escape($allmodule)."'";
522 if (!empty($allperms)) {
523 $wherefordel .= " AND perms='".$this->db->escape($allperms)."'";
524 }
525 }
526 }
527 }
528
529 // Suppression des droits de la liste wherefordel
530 if (!empty($wherefordel)) {
531 //print "$module-$perms-$subperms";
532 $sql = "SELECT id";
533 $sql .= " FROM ".$this->db->prefix()."rights_def";
534 $sql .= " WHERE entity = ".((int) $entity);
535 if (!empty($wherefordel) && $wherefordel != 'allmodules') {
536 $sql .= " AND ".$wherefordel;
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
714 if (!isset($this->entity)) {
715 $this->entity = $conf->entity; // If not defined, we use default value
716 }
717
718 return $this->createCommon($user, $notrigger);
719 }
720
727 public function update($notrigger = 0)
728 {
729 global $user, $conf;
730
731 if (!empty($this->name)) {
732 $this->nom = $this->name; // Field for 'name' is called 'nom' in database
733 }
734
735 return $this->updateCommon($user, $notrigger);
736 }
737
738
748 public function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0)
749 {
750 //print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n";
751 $lastname = $this->lastname;
752 $firstname = $this->firstname;
753 if (empty($lastname)) {
754 $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 : '')))));
755 }
756
757 $ret = '';
758 if (!empty($option) && !empty($this->civility_code)) {
759 if ($langs->transnoentitiesnoconv("Civility".$this->civility_code) != "Civility".$this->civility_code) {
760 $ret .= $langs->transnoentitiesnoconv("Civility".$this->civility_code).' ';
761 } else {
762 $ret .= $this->civility_code.' ';
763 }
764 }
765
766 $ret .= dolGetFirstLastname($firstname, $lastname, $nameorder);
767
768 return dol_trunc($ret, $maxlen);
769 }
770
777 public function getLibStatut($mode = 0)
778 {
779 return $this->LibStatut(0, $mode);
780 }
781
782 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
790 public function LibStatut($status, $mode = 0)
791 {
792 // phpcs:enable
793 global $langs;
794 $langs->load('users');
795 return '';
796 }
797
804 public function getTooltipContentArray($params)
805 {
806 global $conf, $langs, $menumanager;
807
808 $option = $params['option'] ?? '';
809
810 $datas = [];
811 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
812 $langs->load("users");
813 return ['optimize' => $langs->trans("ShowGroup")];
814 }
815 $datas['divopen'] = '<div class="centpercent">';
816 $datas['picto'] = img_picto('', 'group').' <u>'.$langs->trans("Group").'</u><br>';
817 $datas['name'] = '<b>'.$langs->trans('Name').':</b> '.$this->name;
818 $datas['description'] = '<br><b>'.$langs->trans("Description").':</b> '.$this->note;
819 $datas['divclose'] = '</div>';
820
821 return $datas;
822 }
823
835 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
836 {
837 global $langs, $conf, $db, $hookmanager;
838
839 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') && $withpicto) {
840 $withpicto = 0;
841 }
842
843 $result = '';
844 $params = [
845 'id' => $this->id,
846 'objecttype' => $this->element,
847 'option' => $option,
848 ];
849 $classfortooltip = 'classfortooltip';
850 $dataparams = '';
851 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
852 $classfortooltip = 'classforajaxtooltip';
853 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
854 $label = '';
855 } else {
856 $label = implode($this->getTooltipContentArray($params));
857 }
858
859 if ($option == 'permissions') {
860 $url = DOL_URL_ROOT.'/user/group/perms.php?id='.$this->id;
861 } else {
862 $url = DOL_URL_ROOT.'/user/group/card.php?id='.$this->id;
863 }
864
865 if ($option != 'nolink') {
866 // Add param to save lastsearch_values or not
867 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
868 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
869 $add_save_lastsearch_values = 1;
870 }
871 if ($add_save_lastsearch_values) {
872 $url .= '&save_lastsearch_values=1';
873 }
874 }
875
876 $linkclose = "";
877 if (empty($notooltip)) {
878 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
879 $langs->load("users");
880 $label = $langs->trans("ShowGroup");
881 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1, 1).'"';
882 }
883 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
884 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
885 }
886
887 $linkstart = '<a href="'.$url.'"';
888 $linkstart .= $linkclose.'>';
889 $linkend = '</a>';
890
891 $result = $linkstart;
892 if ($withpicto) {
893 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
894 }
895 if ($withpicto != 2) {
896 $result .= $this->name;
897 }
898 $result .= $linkend;
899
900 global $action;
901 $hookmanager->initHooks(array('groupdao'));
902 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
903 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
904 if ($reshook > 0) {
905 $result = $hookmanager->resPrint;
906 } else {
907 $result .= $hookmanager->resPrint;
908 }
909
910 return $result;
911 }
912
913 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
914 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
924 public function _load_ldap_dn($info, $mode = 0)
925 {
926 // phpcs:enable
927 global $conf;
928 $dn = '';
929 if ($mode == 0) {
930 $dn = getDolGlobalString('LDAP_KEY_GROUPS') . "=".$info[getDolGlobalString('LDAP_KEY_GROUPS')]."," . getDolGlobalString('LDAP_GROUP_DN');
931 }
932 if ($mode == 1) {
933 $dn = getDolGlobalString('LDAP_GROUP_DN');
934 }
935 if ($mode == 2) {
936 $dn = getDolGlobalString('LDAP_KEY_GROUPS') . "=".$info[getDolGlobalString('LDAP_KEY_GROUPS')];
937 }
938 return $dn;
939 }
940
941
942 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
943 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
949 public function _load_ldap_info()
950 {
951 // phpcs:enable
952 global $conf;
953
954 $info = array();
955
956 // Object classes
957 $info["objectclass"] = explode(',', getDolGlobalString('LDAP_GROUP_OBJECT_CLASS'));
958
959 // Champs
960 if ($this->name && getDolGlobalString('LDAP_GROUP_FIELD_FULLNAME')) {
961 $info[getDolGlobalString('LDAP_GROUP_FIELD_FULLNAME')] = $this->name;
962 }
963 //if ($this->name && !empty($conf->global->LDAP_GROUP_FIELD_NAME)) $info[$conf->global->LDAP_GROUP_FIELD_NAME] = $this->name;
964 if ($this->note && getDolGlobalString('LDAP_GROUP_FIELD_DESCRIPTION')) {
965 $info[getDolGlobalString('LDAP_GROUP_FIELD_DESCRIPTION')] = dol_string_nohtmltag($this->note, 2);
966 }
967 if (getDolGlobalString('LDAP_GROUP_FIELD_GROUPMEMBERS')) {
968 $valueofldapfield = array();
969 foreach ($this->members as $key => $val) { // This is array of users for group into dolibarr database.
970 $muser = new User($this->db);
971 $muser->fetch($val->id);
972 $info2 = $muser->_load_ldap_info();
973 $valueofldapfield[] = $muser->_load_ldap_dn($info2);
974 }
975 $info[getDolGlobalString('LDAP_GROUP_FIELD_GROUPMEMBERS')] = (!empty($valueofldapfield) ? $valueofldapfield : '');
976 }
977 if (getDolGlobalString('LDAP_GROUP_FIELD_GROUPID')) {
978 $info[getDolGlobalString('LDAP_GROUP_FIELD_GROUPID')] = $this->id;
979 }
980 return $info;
981 }
982
983
991 public function initAsSpecimen()
992 {
993 global $conf, $user, $langs;
994
995 // Initialise parameters
996 $this->id = 0;
997 $this->ref = 'SPECIMEN';
998 $this->specimen = 1;
999
1000 $this->name = 'DOLIBARR GROUP SPECIMEN';
1001 $this->note = 'This is a note';
1002 $this->datec = time();
1003 $this->tms = time();
1004
1005 // Members of this group is just me
1006 $this->members = array(
1007 $user->id => $user
1008 );
1009
1010 return 1;
1011 }
1012
1024 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1025 {
1026 global $conf, $user, $langs;
1027
1028 $langs->load("user");
1029
1030 // Positionne le modele sur le nom du modele a utiliser
1031 if (!dol_strlen($modele)) {
1032 if (getDolGlobalString('USERGROUP_ADDON_PDF')) {
1033 $modele = getDolGlobalString('USERGROUP_ADDON_PDF');
1034 } else {
1035 $modele = 'grass';
1036 }
1037 }
1038
1039 $modelpath = "core/modules/usergroup/doc/";
1040
1041 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1042 }
1043
1051 public function getKanbanView($option = '', $arraydata = null)
1052 {
1053 global $langs;
1054
1055 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1056
1057 $return = '<div class="box-flex-item box-flex-grow-zero">';
1058 $return .= '<div class="info-box info-box-sm">';
1059 $return .= '<span class="info-box-icon bg-infobox-action">';
1060 $return .= img_picto('', $this->picto);
1061 $return .= '</span>';
1062 $return .= '<div class="info-box-content">';
1063 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1064 if ($selected >= 0) {
1065 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1066 }
1067 if (property_exists($this, 'members')) {
1068 $return .= '<br><span class="info-box-status opacitymedium">'.(empty($this->nb_users) ? 0 : $this->nb_users).' '.$langs->trans('Users').'</span>';
1069 }
1070 if (property_exists($this, 'nb_rights')) {
1071 $return .= '<br><div class="info-box-status margintoponly opacitymedium">'.$langs->trans('NbOfPermissions').' : '.(empty($this->nb_rights) ? 0 : $this->nb_rights).'</div>';
1072 }
1073 $return .= '</div>';
1074 $return .= '</div>';
1075 $return .= '</div>';
1076 return $return;
1077 }
1078}
$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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage user groups.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the user card (with 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.
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.
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.
dol_now($mode='auto')
Return date for now.
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:161