dolibarr 21.0.0-alpha
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 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
75 public $globalgroup; // Global group
76
81 public $usergroup_entity;
82
88 public $datec;
89
93 public $note;
94
98 public $members = array(); // Array of users
99
100 public $nb_rights; // Number of rights granted to the user
101 public $nb_users; // Number of users in the group
102
103 public $rights; // Permissions of the group
104
105 private $_tab_loaded = array(); // Array of cache of already loaded permissions
106
110 public $all_permissions_are_loaded;
111
112 public $oldcopy; // To contains a clone of this when we need to save old properties of object
113
114 public $fields = array(
115 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'index' => 1, 'position' => 1, 'comment' => 'Id'),
116 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'default' => '1', 'index' => 1, 'position' => 5),
117 'nom' => array('type' => 'varchar(180)', 'label' => 'Name', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'showoncombobox' => 1, 'index' => 1, 'position' => 10, 'searchall' => 1, 'comment' => 'Group name'),
118 'note' => array('type' => 'html', 'label' => 'Description', 'enabled' => 1, 'visible' => 1, 'position' => 20, 'notnull' => -1, 'searchall' => 1),
119 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -2, 'position' => 50, 'notnull' => 1,),
120 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -2, 'position' => 60, 'notnull' => 1,),
121 'model_pdf' => array('type' => 'varchar(255)', 'label' => 'ModelPDF', 'enabled' => 1, 'visible' => 0, 'position' => 100),
122 );
123
127 public $fk_element = 'fk_usergroup';
128
132 protected $childtables = array();
133
137 protected $childtablesoncascade = array('usergroup_rights', 'usergroup_user');
138
139
145 public function __construct($db)
146 {
147 $this->db = $db;
148
149 $this->ismultientitymanaged = 1;
150 $this->nb_rights = 0;
151 }
152
153
162 public function fetch($id = 0, $groupname = '', $load_members = false)
163 {
164 global $conf;
165
166 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
167 if (!empty($groupname)) {
168 $result = $this->fetchCommon(0, '', ' AND nom = \''.$this->db->escape($groupname).'\'');
169 } else {
170 $result = $this->fetchCommon($id);
171 }
172
173 $this->name = $this->nom; // For compatibility with field name
174
175 if ($result) {
176 if ($load_members) {
177 $this->members = $this->listUsersForGroup(); // This make a lot of subrequests
178 }
179
180 return 1;
181 } else {
182 $this->error = $this->db->lasterror();
183 return -1;
184 }
185 }
186
187
195 public function listGroupsForUser($userid, $load_members = true)
196 {
197 global $conf, $user;
198
199 $ret = array();
200
201 $sql = "SELECT g.rowid, ug.entity as usergroup_entity";
202 $sql .= " FROM ".$this->db->prefix()."usergroup as g,";
203 $sql .= " ".$this->db->prefix()."usergroup_user as ug";
204 $sql .= " WHERE ug.fk_usergroup = g.rowid";
205 $sql .= " AND ug.fk_user = ".((int) $userid);
206 if (isModEnabled('multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
207 $sql .= " AND g.entity IS NOT NULL";
208 } else {
209 $sql .= " AND g.entity IN (0,".$conf->entity.")";
210 }
211 $sql .= " ORDER BY g.nom";
212
213 dol_syslog(get_class($this)."::listGroupsForUser", LOG_DEBUG);
214 $result = $this->db->query($sql);
215 if ($result) {
216 while ($obj = $this->db->fetch_object($result)) {
217 if (!array_key_exists($obj->rowid, $ret)) {
218 $newgroup = new UserGroup($this->db);
219 $newgroup->fetch($obj->rowid, '', $load_members);
220 $ret[$obj->rowid] = $newgroup;
221 }
222 if (!is_array($ret[$obj->rowid]->usergroup_entity)) {
223 $ret[$obj->rowid]->usergroup_entity = array();
224 }
225 // $ret[$obj->rowid] is instance of UserGroup
226 $ret[$obj->rowid]->usergroup_entity[] = (int) $obj->usergroup_entity;
227 }
228
229 $this->db->free($result);
230
231 return $ret;
232 } else {
233 $this->error = $this->db->lasterror();
234 return -1;
235 }
236 }
237
245 public function listUsersForGroup($excludefilter = '', $mode = 0)
246 {
247 global $conf, $user;
248
249 $ret = array();
250
251 $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";
252 if (!empty($this->id)) {
253 $sql .= ", ug.entity as usergroup_entity";
254 }
255 $sql .= " FROM ".$this->db->prefix()."user as u";
256 if (!empty($this->id)) {
257 $sql .= ", ".$this->db->prefix()."usergroup_user as ug";
258 }
259 $sql .= " WHERE 1 = 1";
260 if (!empty($this->id)) {
261 $sql .= " AND ug.fk_user = u.rowid";
262 }
263 if (!empty($this->id)) {
264 $sql .= " AND ug.fk_usergroup = ".((int) $this->id);
265 }
266 if (isModEnabled('multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
267 $sql .= " AND u.entity IS NOT NULL";
268 } else {
269 $sql .= " AND u.entity IN (0,".$conf->entity.")";
270 }
271 if (!empty($excludefilter)) {
272 $sql .= ' AND ('.$excludefilter.')';
273 }
274
275 dol_syslog(get_class($this)."::listUsersForGroup", LOG_DEBUG);
276 $resql = $this->db->query($sql);
277
278 if ($resql) {
279 while ($obj = $this->db->fetch_object($resql)) {
280 if (!array_key_exists($obj->rowid, $ret)) {
281 if ($mode != 1) {
282 $newuser = new User($this->db);
283 //$newuser->fetch($obj->rowid); // We are inside a loop, no subrequests inside a loop
284 $newuser->id = $obj->rowid;
285 $newuser->login = $obj->login;
286 $newuser->photo = $obj->photo;
287 $newuser->lastname = $obj->lastname;
288 $newuser->firstname = $obj->firstname;
289 $newuser->email = $obj->email;
290 $newuser->socid = $obj->fk_soc;
291 $newuser->entity = $obj->entity;
292 $newuser->employee = $obj->employee;
293 $newuser->status = $obj->status;
294
295 $ret[$obj->rowid] = $newuser;
296 } else {
297 $ret[$obj->rowid] = $obj->rowid;
298 }
299 }
300 if ($mode != 1 && !empty($obj->usergroup_entity)) {
301 // $ret[$obj->rowid] is instance of User
302 if (!is_array($ret[$obj->rowid]->usergroup_entity)) {
303 $ret[$obj->rowid]->usergroup_entity = array();
304 }
305 $ret[$obj->rowid]->usergroup_entity[] = (int) $obj->usergroup_entity;
306 }
307 }
308
309 $this->db->free($resql);
310
311 return $ret;
312 } else {
313 $this->error = $this->db->lasterror();
314 return -1;
315 }
316 }
317
327 public function addrights($rid, $allmodule = '', $allperms = '', $entity = 0)
328 {
329 global $conf, $user, $langs;
330
331 $entity = (!empty($entity) ? $entity : $conf->entity);
332
333 dol_syslog(get_class($this)."::addrights $rid, $allmodule, $allperms, $entity");
334 $error = 0;
335 $whereforadd = '';
336
337 $this->db->begin();
338
339 if (!empty($rid)) {
340 $module = $perms = $subperms = '';
341
342 // Si on a demande ajout d'un droit en particulier, on recupere
343 // les caracteristiques (module, perms et subperms) de ce droit.
344 $sql = "SELECT module, perms, subperms";
345 $sql .= " FROM ".$this->db->prefix()."rights_def";
346 $sql .= " WHERE id = ".((int) $rid);
347 $sql .= " AND entity = ".((int) $entity);
348
349 $result = $this->db->query($sql);
350 if ($result) {
351 $obj = $this->db->fetch_object($result);
352 if ($obj) {
353 $module = $obj->module;
354 $perms = $obj->perms;
355 $subperms = $obj->subperms;
356 }
357 } else {
358 $error++;
359 dol_print_error($this->db);
360 }
361
362 // Where pour la liste des droits a ajouter
363 $whereforadd = "id=".((int) $rid);
364 // Find also rights that are herited to add them too
365 if ($subperms) {
366 $whereforadd .= " OR (module='".$this->db->escape($module)."' AND perms='".$this->db->escape($perms)."' AND (subperms='lire' OR subperms='read'))";
367 } elseif ($perms) {
368 $whereforadd .= " OR (module='".$this->db->escape($module)."' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
369 }
370 } else {
371 // Where pour la liste des droits a ajouter
372 if (!empty($allmodule)) {
373 if ($allmodule == 'allmodules') {
374 $whereforadd = 'allmodules';
375 } else {
376 $whereforadd = "module='".$this->db->escape($allmodule)."'";
377 if (!empty($allperms)) {
378 $whereforadd .= " AND perms='".$this->db->escape($allperms)."'";
379 }
380 }
381 }
382 }
383
384 // Add permission of the list $whereforadd
385 if (!empty($whereforadd)) {
386 //print "$module-$perms-$subperms";
387 $sql = "SELECT id";
388 $sql .= " FROM ".$this->db->prefix()."rights_def";
389 $sql .= " WHERE entity = ".((int) $entity);
390 if (!empty($whereforadd) && $whereforadd != 'allmodules') {
391 $sql .= " AND ".$whereforadd;
392 }
393
394 $result = $this->db->query($sql);
395 if ($result) {
396 $num = $this->db->num_rows($result);
397 $i = 0;
398 while ($i < $num) {
399 $obj = $this->db->fetch_object($result);
400 $nid = $obj->id;
401
402 $sql = "DELETE FROM ".$this->db->prefix()."usergroup_rights WHERE fk_usergroup = ".((int) $this->id)." AND fk_id=".((int) $nid)." AND entity = ".((int) $entity);
403 if (!$this->db->query($sql)) {
404 $error++;
405 }
406 $sql = "INSERT INTO ".$this->db->prefix()."usergroup_rights (entity, fk_usergroup, fk_id) VALUES (".((int) $entity).", ".((int) $this->id).", ".((int) $nid).")";
407 if (!$this->db->query($sql)) {
408 $error++;
409 }
410
411 $i++;
412 }
413 } else {
414 $error++;
415 dol_print_error($this->db);
416 }
417
418 if (!$error) {
419 $langs->load("other");
420 $this->context = array('audit' => $langs->trans("PermissionsAdd").($rid ? ' (id='.$rid.')' : ''));
421
422 // Call trigger
423 $result = $this->call_trigger('USERGROUP_MODIFY', $user);
424 if ($result < 0) {
425 $error++;
426 }
427 // End call triggers
428 }
429 }
430
431 if ($error) {
432 $this->db->rollback();
433 return -$error;
434 } else {
435 $this->db->commit();
436 return 1;
437 }
438 }
439
440
450 public function delrights($rid, $allmodule = '', $allperms = '', $entity = 0)
451 {
452 global $conf, $user, $langs;
453
454 $error = 0;
455 $wherefordel = '';
456
457 $entity = (!empty($entity) ? $entity : $conf->entity);
458
459 $this->db->begin();
460
461 if (!empty($rid)) {
462 $module = $perms = $subperms = '';
463
464 // Si on a demande suppression d'un droit en particulier, on recupere
465 // les caracteristiques module, perms et subperms de ce droit.
466 $sql = "SELECT module, perms, subperms";
467 $sql .= " FROM ".$this->db->prefix()."rights_def";
468 $sql .= " WHERE id = ".((int) $rid);
469 $sql .= " AND entity = ".((int) $entity);
470
471 $result = $this->db->query($sql);
472 if ($result) {
473 $obj = $this->db->fetch_object($result);
474 if ($obj) {
475 $module = $obj->module;
476 $perms = $obj->perms;
477 $subperms = $obj->subperms;
478 }
479 } else {
480 $error++;
481 dol_print_error($this->db);
482 }
483
484 // Where for the list of permissions to delete
485 $wherefordel = "id = ".((int) $rid);
486 // Suppression des droits induits
487 if ($subperms == 'lire' || $subperms == 'read') {
488 $wherefordel .= " OR (module='".$this->db->escape($module)."' AND perms='".$this->db->escape($perms)."' AND subperms IS NOT NULL)";
489 }
490 if ($perms == 'lire' || $perms == 'read') {
491 $wherefordel .= " OR (module='".$this->db->escape($module)."')";
492 }
493
494 // Pour compatibilite, si lowid = 0, on est en mode suppression de tout
495 // TODO To remove when this will be implemented by the caller
496 //if (substr($rid,-1,1) == 0) $wherefordel="module='$module'";
497 } else {
498 // Add permission of the list $wherefordel
499 if (!empty($allmodule)) {
500 if ($allmodule == 'allmodules') {
501 $wherefordel = 'allmodules';
502 } else {
503 $wherefordel = "module='".$this->db->escape($allmodule)."'";
504 if (!empty($allperms)) {
505 $wherefordel .= " AND perms='".$this->db->escape($allperms)."'";
506 }
507 }
508 }
509 }
510
511 // Suppression des droits de la liste wherefordel
512 if (!empty($wherefordel)) {
513 //print "$module-$perms-$subperms";
514 $sql = "SELECT id";
515 $sql .= " FROM ".$this->db->prefix()."rights_def";
516 $sql .= " WHERE entity = ".((int) $entity);
517 if (!empty($wherefordel) && $wherefordel != 'allmodules') {
518 $sql .= " AND ".$wherefordel;
519 }
520
521 $result = $this->db->query($sql);
522 if ($result) {
523 $num = $this->db->num_rows($result);
524 $i = 0;
525 while ($i < $num) {
526 $nid = 0;
527
528 $obj = $this->db->fetch_object($result);
529 if ($obj) {
530 $nid = $obj->id;
531 }
532
533 $sql = "DELETE FROM ".$this->db->prefix()."usergroup_rights";
534 $sql .= " WHERE fk_usergroup = $this->id AND fk_id=".((int) $nid);
535 $sql .= " AND entity = ".((int) $entity);
536 if (!$this->db->query($sql)) {
537 $error++;
538 }
539
540 $i++;
541 }
542 } else {
543 $error++;
544 dol_print_error($this->db);
545 }
546
547 if (!$error) {
548 $langs->load("other");
549 $this->context = array('audit' => $langs->trans("PermissionsDelete").($rid ? ' (id='.$rid.')' : ''));
550
551 // Call trigger
552 $result = $this->call_trigger('USERGROUP_MODIFY', $user);
553 if ($result < 0) {
554 $error++;
555 }
556 // End call triggers
557 }
558 }
559
560 if ($error) {
561 $this->db->rollback();
562 return -$error;
563 } else {
564 $this->db->commit();
565 return 1;
566 }
567 }
568
569
576 public function getrights($moduletag = '')
577 {
578 global $conf;
579
580 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
581 // Rights for this module are already loaded, so we leave
582 return 0;
583 }
584
585 if (!empty($this->all_permissions_are_loaded)) {
586 // We already loaded all rights for this group, so we leave
587 return 0;
588 }
589
590 /*
591 * Recuperation des droits
592 */
593 $sql = "SELECT r.module, r.perms, r.subperms ";
594 $sql .= " FROM ".$this->db->prefix()."usergroup_rights as u, ".$this->db->prefix()."rights_def as r";
595 $sql .= " WHERE r.id = u.fk_id";
596 $sql .= " AND r.entity = ".((int) $conf->entity);
597 $sql .= " AND u.entity = ".((int) $conf->entity);
598 $sql .= " AND u.fk_usergroup = ".((int) $this->id);
599 $sql .= " AND r.perms IS NOT NULL";
600 if ($moduletag) {
601 $sql .= " AND r.module = '".$this->db->escape($moduletag)."'";
602 }
603
604 dol_syslog(get_class($this).'::getrights', LOG_DEBUG);
605 $resql = $this->db->query($sql);
606 if ($resql) {
607 $num = $this->db->num_rows($resql);
608 $i = 0;
609 while ($i < $num) {
610 $obj = $this->db->fetch_object($resql);
611
612 if ($obj) {
613 $module = $obj->module;
614 $perms = $obj->perms;
615 $subperms = $obj->subperms;
616
617 if ($perms) {
618 if (!isset($this->rights)) {
619 $this->rights = new stdClass(); // For avoid error
620 }
621 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
622 $this->rights->$module = new stdClass();
623 }
624 if ($subperms) {
625 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
626 $this->rights->$module->$perms = new stdClass();
627 }
628 if (empty($this->rights->$module->$perms->$subperms)) {
629 $this->nb_rights++;
630 }
631 $this->rights->$module->$perms->$subperms = 1;
632 } else {
633 if (empty($this->rights->$module->$perms)) {
634 $this->nb_rights++;
635 }
636 $this->rights->$module->$perms = 1;
637 }
638 }
639 }
640
641 $i++;
642 }
643 $this->db->free($resql);
644 }
645
646 if ($moduletag == '') {
647 // Si module etait non defini, alors on a tout charge, on peut donc considerer
648 // que les droits sont en cache (car tous charges) pour cet instance de group
649 $this->all_permissions_are_loaded = 1;
650 } else {
651 // If module defined, we flag it as loaded into cache
652 $this->_tab_loaded[$moduletag] = 1;
653 }
654
655 return 1;
656 }
657
664 public function delete(User $user)
665 {
666 return $this->deleteCommon($user);
667 }
668
675 public function create($notrigger = 0)
676 {
677 global $user, $conf;
678
679 $this->datec = dol_now();
680 if (!empty($this->name)) {
681 $this->nom = $this->name; // Field for 'name' is called 'nom' in database
682 }
683
684 if (!isset($this->entity)) {
685 $this->entity = $conf->entity; // If not defined, we use default value
686 }
687
688 return $this->createCommon($user, $notrigger);
689 }
690
697 public function update($notrigger = 0)
698 {
699 global $user, $conf;
700
701 if (!empty($this->name)) {
702 $this->nom = $this->name; // Field for 'name' is called 'nom' in database
703 }
704
705 return $this->updateCommon($user, $notrigger);
706 }
707
708
718 public function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0)
719 {
720 //print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n";
721 $lastname = $this->lastname;
722 $firstname = $this->firstname;
723 if (empty($lastname)) {
724 $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 : '')))));
725 }
726
727 $ret = '';
728 if (!empty($option) && !empty($this->civility_code)) {
729 if ($langs->transnoentitiesnoconv("Civility".$this->civility_code) != "Civility".$this->civility_code) {
730 $ret .= $langs->transnoentitiesnoconv("Civility".$this->civility_code).' ';
731 } else {
732 $ret .= $this->civility_code.' ';
733 }
734 }
735
736 $ret .= dolGetFirstLastname($firstname, $lastname, $nameorder);
737
738 return dol_trunc($ret, $maxlen);
739 }
740
747 public function getLibStatut($mode = 0)
748 {
749 return $this->LibStatut(0, $mode);
750 }
751
752 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
760 public function LibStatut($status, $mode = 0)
761 {
762 // phpcs:enable
763 global $langs;
764 $langs->load('users');
765 return '';
766 }
767
775 public function getTooltipContentArray($params)
776 {
777 global $conf, $langs, $menumanager;
778
779 $option = $params['option'] ?? '';
780
781 $datas = [];
782 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
783 $langs->load("users");
784 return ['optimize' => $langs->trans("ShowGroup")];
785 }
786 $datas['divopen'] = '<div class="centpercent">';
787 $datas['picto'] = img_picto('', 'group').' <u>'.$langs->trans("Group").'</u><br>';
788 $datas['name'] = '<b>'.$langs->trans('Name').':</b> '.$this->name;
789 $datas['description'] = '<br><b>'.$langs->trans("Description").':</b> '.$this->note;
790 $datas['divclose'] = '</div>';
791
792 return $datas;
793 }
794
806 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
807 {
808 global $langs, $conf, $db, $hookmanager;
809
810 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') && $withpicto) {
811 $withpicto = 0;
812 }
813
814 $result = '';
815 $params = [
816 'id' => $this->id,
817 'objecttype' => $this->element,
818 'option' => $option,
819 ];
820 $classfortooltip = 'classfortooltip';
821 $dataparams = '';
822 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
823 $classfortooltip = 'classforajaxtooltip';
824 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
825 $label = '';
826 } else {
827 $label = implode($this->getTooltipContentArray($params));
828 }
829
830 if ($option == 'permissions') {
831 $url = DOL_URL_ROOT.'/user/group/perms.php?id='.$this->id;
832 } else {
833 $url = DOL_URL_ROOT.'/user/group/card.php?id='.$this->id;
834 }
835
836 if ($option != 'nolink') {
837 // Add param to save lastsearch_values or not
838 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
839 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
840 $add_save_lastsearch_values = 1;
841 }
842 if ($add_save_lastsearch_values) {
843 $url .= '&save_lastsearch_values=1';
844 }
845 }
846
847 $linkclose = "";
848 if (empty($notooltip)) {
849 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
850 $langs->load("users");
851 $label = $langs->trans("ShowGroup");
852 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1, 1).'"';
853 }
854 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
855 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
856 }
857
858 $linkstart = '<a href="'.$url.'"';
859 $linkstart .= $linkclose.'>';
860 $linkend = '</a>';
861
862 $result = $linkstart;
863 if ($withpicto) {
864 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
865 }
866 if ($withpicto != 2) {
867 $result .= $this->name;
868 }
869 $result .= $linkend;
870
871 global $action;
872 $hookmanager->initHooks(array('groupdao'));
873 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
874 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
875 if ($reshook > 0) {
876 $result = $hookmanager->resPrint;
877 } else {
878 $result .= $hookmanager->resPrint;
879 }
880
881 return $result;
882 }
883
884 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
885 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
895 public function _load_ldap_dn($info, $mode = 0)
896 {
897 // phpcs:enable
898 global $conf;
899 $dn = '';
900 if ($mode == 0) {
901 $dn = getDolGlobalString('LDAP_KEY_GROUPS') . "=".$info[getDolGlobalString('LDAP_KEY_GROUPS')]."," . getDolGlobalString('LDAP_GROUP_DN');
902 }
903 if ($mode == 1) {
904 $dn = getDolGlobalString('LDAP_GROUP_DN');
905 }
906 if ($mode == 2) {
907 $dn = getDolGlobalString('LDAP_KEY_GROUPS') . "=".$info[getDolGlobalString('LDAP_KEY_GROUPS')];
908 }
909 return $dn;
910 }
911
912
913 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
914 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
920 public function _load_ldap_info()
921 {
922 // phpcs:enable
923 global $conf;
924
925 $info = array();
926
927 // Object classes
928 $info["objectclass"] = explode(',', getDolGlobalString('LDAP_GROUP_OBJECT_CLASS'));
929
930 // Champs
931 if ($this->name && getDolGlobalString('LDAP_GROUP_FIELD_FULLNAME')) {
932 $info[getDolGlobalString('LDAP_GROUP_FIELD_FULLNAME')] = $this->name;
933 }
934 //if ($this->name && !empty($conf->global->LDAP_GROUP_FIELD_NAME)) $info[$conf->global->LDAP_GROUP_FIELD_NAME] = $this->name;
935 if ($this->note && getDolGlobalString('LDAP_GROUP_FIELD_DESCRIPTION')) {
936 $info[getDolGlobalString('LDAP_GROUP_FIELD_DESCRIPTION')] = dol_string_nohtmltag($this->note, 2);
937 }
938 if (getDolGlobalString('LDAP_GROUP_FIELD_GROUPMEMBERS')) {
939 $valueofldapfield = array();
940 foreach ($this->members as $key => $val) { // This is array of users for group into dolibarr database.
941 $muser = new User($this->db);
942 $muser->fetch($val->id);
943 $info2 = $muser->_load_ldap_info();
944 $valueofldapfield[] = $muser->_load_ldap_dn($info2);
945 }
946 $info[getDolGlobalString('LDAP_GROUP_FIELD_GROUPMEMBERS')] = (!empty($valueofldapfield) ? $valueofldapfield : '');
947 }
948 if (getDolGlobalString('LDAP_GROUP_FIELD_GROUPID')) {
949 $info[getDolGlobalString('LDAP_GROUP_FIELD_GROUPID')] = $this->id;
950 }
951 return $info;
952 }
953
954
962 public function initAsSpecimen()
963 {
964 global $conf, $user, $langs;
965
966 // Initialise parameters
967 $this->id = 0;
968 $this->ref = 'SPECIMEN';
969 $this->specimen = 1;
970
971 $this->name = 'DOLIBARR GROUP SPECIMEN';
972 $this->note = 'This is a note';
973 $this->datec = time();
974 $this->tms = time();
975
976 // Members of this group is just me
977 $this->members = array(
978 $user->id => $user
979 );
980
981 return 1;
982 }
983
995 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
996 {
997 global $conf, $user, $langs;
998
999 $langs->load("user");
1000
1001 // Positionne le modele sur le nom du modele a utiliser
1002 if (!dol_strlen($modele)) {
1003 if (getDolGlobalString('USERGROUP_ADDON_PDF')) {
1004 $modele = getDolGlobalString('USERGROUP_ADDON_PDF');
1005 } else {
1006 $modele = 'grass';
1007 }
1008 }
1009
1010 $modelpath = "core/modules/usergroup/doc/";
1011
1012 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1013 }
1014
1022 public function getKanbanView($option = '', $arraydata = null)
1023 {
1024 global $langs;
1025
1026 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1027
1028 $return = '<div class="box-flex-item box-flex-grow-zero">';
1029 $return .= '<div class="info-box info-box-sm">';
1030 $return .= '<span class="info-box-icon bg-infobox-action">';
1031 $return .= img_picto('', $this->picto);
1032 $return .= '</span>';
1033 $return .= '<div class="info-box-content">';
1034 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1035 if ($selected >= 0) {
1036 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1037 }
1038 if (property_exists($this, 'members')) {
1039 $return .= '<br><span class="info-box-status opacitymedium">'.(empty($this->nb_users) ? 0 : $this->nb_users).' '.$langs->trans('Users').'</span>';
1040 }
1041 if (property_exists($this, 'nb_rights')) {
1042 $return .= '<br><div class="info-box-status margintoponly opacitymedium">'.$langs->trans('NbOfPermissions').' : '.(empty($this->nb_rights) ? 0 : $this->nb_rights).'</div>';
1043 }
1044 $return .= '</div>';
1045 $return .= '</div>';
1046 $return .= '</div>';
1047 return $return;
1048 }
1049}
$object ref
Definition info.php:79
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)
Charge un object group avec toutes ses caracteristiques (except ->members array)
listUsersForGroup($excludefilter='', $mode=0)
Return array of User objects for group this->id (or all if this->id not defined)
getKanbanView($option='', $arraydata=null)
Return clicable 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_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
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.
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 dolibarr global constant string value.
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:142