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