dolibarr 21.0.0-beta
usergroup.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (c) 2005-2018 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (c) 2005-2018 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2012 Florian Henry <florian.henry@open-concept.pro>
6 * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2014 Alexis Algoud <alexis@atm-consulting.fr>
8 * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
9 * Copyright (C) 2019 Abbes Bahfir <dolipar@dolipar.org>
10 * Copyright (C) 2023-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
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
153
159 public function __construct($db)
160 {
161 $this->db = $db;
162
163 $this->ismultientitymanaged = 1;
164 $this->nb_rights = 0;
165 }
166
167
176 public function fetch($id = 0, $groupname = '', $load_members = false)
177 {
178 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
179 if (!empty($groupname)) {
180 $result = $this->fetchCommon(0, '', ' AND nom = \''.$this->db->escape($groupname).'\'');
181 } else {
182 $result = $this->fetchCommon($id);
183 }
184
185 $this->name = $this->nom; // For compatibility with field name
186
187 if ($result) {
188 if ($load_members) {
189 $excludefilter = '';
190 $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
191 }
192
193 return 1;
194 } else {
195 $this->error = $this->db->lasterror();
196 return -1;
197 }
198 }
199
200
208 public function listGroupsForUser($userid, $load_members = true)
209 {
210 global $conf, $user;
211
212 $ret = array();
213
214 $sql = "SELECT g.rowid, ug.entity as usergroup_entity";
215 $sql .= " FROM ".$this->db->prefix()."usergroup as g,";
216 $sql .= " ".$this->db->prefix()."usergroup_user as ug";
217 $sql .= " WHERE ug.fk_usergroup = g.rowid";
218 $sql .= " AND ug.fk_user = ".((int) $userid);
219 if (isModEnabled('multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
220 $sql .= " AND g.entity IS NOT NULL";
221 } else {
222 $sql .= " AND g.entity IN (0,".$conf->entity.")";
223 }
224 $sql .= " ORDER BY g.nom";
225
226 dol_syslog(get_class($this)."::listGroupsForUser", LOG_DEBUG);
227 $result = $this->db->query($sql);
228 if ($result) {
229 while ($obj = $this->db->fetch_object($result)) {
230 if (!array_key_exists($obj->rowid, $ret)) {
231 $newgroup = new UserGroup($this->db);
232 $newgroup->fetch($obj->rowid, '', $load_members);
233 $ret[$obj->rowid] = $newgroup;
234 }
235 if (!is_array($ret[$obj->rowid]->usergroup_entity)) {
236 $ret[$obj->rowid]->usergroup_entity = array();
237 }
238 // $ret[$obj->rowid] is instance of UserGroup
239 $ret[$obj->rowid]->usergroup_entity[] = (int) $obj->usergroup_entity;
240 }
241
242 $this->db->free($result);
243
244 return $ret;
245 } else {
246 $this->error = $this->db->lasterror();
247 return -1;
248 }
249 }
250
258 public function listUsersForGroup($excludefilter = '', $mode = 0)
259 {
260 global $conf, $user;
261
262 $ret = array();
263
264 $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";
265 if (!empty($this->id)) {
266 $sql .= ", ug.entity as usergroup_entity";
267 }
268 $sql .= " FROM ".$this->db->prefix()."user as u";
269 if (!empty($this->id)) {
270 $sql .= ", ".$this->db->prefix()."usergroup_user as ug";
271 }
272 $sql .= " WHERE 1 = 1";
273 if (!empty($this->id)) {
274 $sql .= " AND ug.fk_user = u.rowid";
275 }
276 if (!empty($this->id)) {
277 $sql .= " AND ug.fk_usergroup = ".((int) $this->id);
278 }
279 if (isModEnabled('multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
280 $sql .= " AND u.entity IS NOT NULL";
281 } else {
282 $sql .= " AND u.entity IN (0,".$conf->entity.")";
283 }
284 if (!empty($excludefilter)) {
285 $sql .= ' AND ('.$excludefilter.')';
286 }
287
288 dol_syslog(get_class($this)."::listUsersForGroup", LOG_DEBUG);
289 $resql = $this->db->query($sql);
290
291 if ($resql) {
292 while ($obj = $this->db->fetch_object($resql)) {
293 if (!array_key_exists($obj->rowid, $ret)) {
294 if ($mode != 1) {
295 $newuser = new User($this->db);
296 //$newuser->fetch($obj->rowid); // We are inside a loop, no subrequests inside a loop
297 $newuser->id = $obj->rowid;
298 $newuser->login = $obj->login;
299 $newuser->photo = $obj->photo;
300 $newuser->lastname = $obj->lastname;
301 $newuser->firstname = $obj->firstname;
302 $newuser->email = $obj->email;
303 $newuser->socid = $obj->fk_soc;
304 $newuser->entity = $obj->entity;
305 $newuser->employee = $obj->employee;
306 $newuser->status = $obj->status;
307
308 $ret[$obj->rowid] = $newuser;
309 } else {
310 $ret[$obj->rowid] = $obj->rowid;
311 }
312 }
313 if ($mode != 1 && !empty($obj->usergroup_entity)) {
314 // $ret[$obj->rowid] is instance of User
315 if (!is_array($ret[$obj->rowid]->usergroup_entity)) {
316 $ret[$obj->rowid]->usergroup_entity = array();
317 }
318 $ret[$obj->rowid]->usergroup_entity[] = (int) $obj->usergroup_entity;
319 }
320 }
321
322 $this->db->free($resql);
323
324 return $ret;
325 } else {
326 $this->error = $this->db->lasterror();
327 return -1;
328 }
329 }
330
340 public function addrights($rid, $allmodule = '', $allperms = '', $entity = 0)
341 {
342 global $conf, $user, $langs;
343
344 $entity = (!empty($entity) ? $entity : $conf->entity);
345
346 dol_syslog(get_class($this)."::addrights $rid, $allmodule, $allperms, $entity");
347 $error = 0;
348 $whereforadd = '';
349
350 $this->db->begin();
351
352 if (!empty($rid)) {
353 $module = $perms = $subperms = '';
354
355 // Si on a demande ajout d'un droit en particulier, on recupere
356 // les caracteristiques (module, perms et subperms) de ce droit.
357 $sql = "SELECT module, perms, subperms";
358 $sql .= " FROM ".$this->db->prefix()."rights_def";
359 $sql .= " WHERE id = ".((int) $rid);
360 $sql .= " AND entity = ".((int) $entity);
361
362 $result = $this->db->query($sql);
363 if ($result) {
364 $obj = $this->db->fetch_object($result);
365 if ($obj) {
366 $module = $obj->module;
367 $perms = $obj->perms;
368 $subperms = $obj->subperms;
369 }
370 } else {
371 $error++;
372 dol_print_error($this->db);
373 }
374
375 // Where pour la liste des droits a ajouter
376 $whereforadd = "id=".((int) $rid);
377 // Find also rights that are herited to add them too
378 if ($subperms) {
379 $whereforadd .= " OR (module='".$this->db->escape($module)."' AND perms='".$this->db->escape($perms)."' AND (subperms='lire' OR subperms='read'))";
380 } elseif ($perms) {
381 $whereforadd .= " OR (module='".$this->db->escape($module)."' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
382 }
383 } else {
384 // Where pour la liste des droits a ajouter
385 if (!empty($allmodule)) {
386 if ($allmodule == 'allmodules') {
387 $whereforadd = 'allmodules';
388 } else {
389 $whereforadd = "module='".$this->db->escape($allmodule)."'";
390 if (!empty($allperms)) {
391 $whereforadd .= " AND perms='".$this->db->escape($allperms)."'";
392 }
393 }
394 }
395 }
396
397 // Add permission of the list $whereforadd
398 if (!empty($whereforadd)) {
399 //print "$module-$perms-$subperms";
400 $sql = "SELECT id";
401 $sql .= " FROM ".$this->db->prefix()."rights_def";
402 $sql .= " WHERE entity = ".((int) $entity);
403 if (!empty($whereforadd) && $whereforadd != 'allmodules') {
404 $sql .= " AND ".$whereforadd;
405 }
406
407 $result = $this->db->query($sql);
408 if ($result) {
409 $num = $this->db->num_rows($result);
410 $i = 0;
411 while ($i < $num) {
412 $obj = $this->db->fetch_object($result);
413 $nid = $obj->id;
414
415 $sql = "DELETE FROM ".$this->db->prefix()."usergroup_rights WHERE fk_usergroup = ".((int) $this->id)." AND fk_id=".((int) $nid)." AND entity = ".((int) $entity);
416 if (!$this->db->query($sql)) {
417 $error++;
418 }
419 $sql = "INSERT INTO ".$this->db->prefix()."usergroup_rights (entity, fk_usergroup, fk_id) VALUES (".((int) $entity).", ".((int) $this->id).", ".((int) $nid).")";
420 if (!$this->db->query($sql)) {
421 $error++;
422 }
423
424 $i++;
425 }
426 } else {
427 $error++;
428 dol_print_error($this->db);
429 }
430
431 if (!$error) {
432 $langs->load("other");
433 $this->context = array('audit' => $langs->trans("PermissionsAdd").($rid ? ' (id='.$rid.')' : ''));
434
435 // Call trigger
436 $result = $this->call_trigger('USERGROUP_MODIFY', $user);
437 if ($result < 0) {
438 $error++;
439 }
440 // End call triggers
441 }
442 }
443
444 if ($error) {
445 $this->db->rollback();
446 return -$error;
447 } else {
448 $this->db->commit();
449 return 1;
450 }
451 }
452
453
463 public function delrights($rid, $allmodule = '', $allperms = '', $entity = 0)
464 {
465 global $conf, $user, $langs;
466
467 $error = 0;
468 $wherefordel = '';
469
470 $entity = (!empty($entity) ? $entity : $conf->entity);
471
472 $this->db->begin();
473
474 if (!empty($rid)) {
475 $module = $perms = $subperms = '';
476
477 // Si on a demande suppression d'un droit en particulier, on recupere
478 // les caracteristiques module, perms et subperms de ce droit.
479 $sql = "SELECT module, perms, subperms";
480 $sql .= " FROM ".$this->db->prefix()."rights_def";
481 $sql .= " WHERE id = ".((int) $rid);
482 $sql .= " AND entity = ".((int) $entity);
483
484 $result = $this->db->query($sql);
485 if ($result) {
486 $obj = $this->db->fetch_object($result);
487 if ($obj) {
488 $module = $obj->module;
489 $perms = $obj->perms;
490 $subperms = $obj->subperms;
491 }
492 } else {
493 $error++;
494 dol_print_error($this->db);
495 }
496
497 // Where for the list of permissions to delete
498 $wherefordel = "id = ".((int) $rid);
499 // Suppression des droits induits
500 if ($subperms == 'lire' || $subperms == 'read') {
501 $wherefordel .= " OR (module='".$this->db->escape($module)."' AND perms='".$this->db->escape($perms)."' AND subperms IS NOT NULL)";
502 }
503 if ($perms == 'lire' || $perms == 'read') {
504 $wherefordel .= " OR (module='".$this->db->escape($module)."')";
505 }
506
507 // Pour compatibilite, si lowid = 0, on est en mode suppression de tout
508 // TODO To remove when this will be implemented by the caller
509 //if (substr($rid,-1,1) == 0) $wherefordel="module='$module'";
510 } else {
511 // Add permission of the list $wherefordel
512 if (!empty($allmodule)) {
513 if ($allmodule == 'allmodules') {
514 $wherefordel = 'allmodules';
515 } else {
516 $wherefordel = "module='".$this->db->escape($allmodule)."'";
517 if (!empty($allperms)) {
518 $wherefordel .= " AND perms='".$this->db->escape($allperms)."'";
519 }
520 }
521 }
522 }
523
524 // Suppression des droits de la liste wherefordel
525 if (!empty($wherefordel)) {
526 //print "$module-$perms-$subperms";
527 $sql = "SELECT id";
528 $sql .= " FROM ".$this->db->prefix()."rights_def";
529 $sql .= " WHERE entity = ".((int) $entity);
530 if (!empty($wherefordel) && $wherefordel != 'allmodules') {
531 $sql .= " AND ".$wherefordel;
532 }
533
534 $result = $this->db->query($sql);
535 if ($result) {
536 $num = $this->db->num_rows($result);
537 $i = 0;
538 while ($i < $num) {
539 $nid = 0;
540
541 $obj = $this->db->fetch_object($result);
542 if ($obj) {
543 $nid = $obj->id;
544 }
545
546 $sql = "DELETE FROM ".$this->db->prefix()."usergroup_rights";
547 $sql .= " WHERE fk_usergroup = $this->id AND fk_id=".((int) $nid);
548 $sql .= " AND entity = ".((int) $entity);
549 if (!$this->db->query($sql)) {
550 $error++;
551 }
552
553 $i++;
554 }
555 } else {
556 $error++;
557 dol_print_error($this->db);
558 }
559
560 if (!$error) {
561 $langs->load("other");
562 $this->context = array('audit' => $langs->trans("PermissionsDelete").($rid ? ' (id='.$rid.')' : ''));
563
564 // Call trigger
565 $result = $this->call_trigger('USERGROUP_MODIFY', $user);
566 if ($result < 0) {
567 $error++;
568 }
569 // End call triggers
570 }
571 }
572
573 if ($error) {
574 $this->db->rollback();
575 return -$error;
576 } else {
577 $this->db->commit();
578 return 1;
579 }
580 }
581
592 public function getrights($moduletag = '')
593 {
594 return $this->loadRights($moduletag);
595 }
596
603 public function loadRights($moduletag = '')
604 {
605 global $conf;
606
607 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
608 // Rights for this module are already loaded, so we leave
609 return 0;
610 }
611
612 if (!empty($this->all_permissions_are_loaded)) {
613 // We already loaded all rights for this group, so we leave
614 return 0;
615 }
616
617 // Load permission from group
618 $sql = "SELECT r.module, r.perms, r.subperms ";
619 $sql .= " FROM ".$this->db->prefix()."usergroup_rights as u, ".$this->db->prefix()."rights_def as r";
620 $sql .= " WHERE r.id = u.fk_id";
621 $sql .= " AND r.entity = ".((int) $conf->entity);
622 $sql .= " AND u.entity = ".((int) $conf->entity);
623 $sql .= " AND u.fk_usergroup = ".((int) $this->id);
624 $sql .= " AND r.perms IS NOT NULL";
625 if ($moduletag) {
626 $sql .= " AND r.module = '".$this->db->escape($moduletag)."'";
627 }
628
629 dol_syslog(get_class($this).'::getrights', LOG_DEBUG);
630 $resql = $this->db->query($sql);
631 if ($resql) {
632 $num = $this->db->num_rows($resql);
633 $i = 0;
634 while ($i < $num) {
635 $obj = $this->db->fetch_object($resql);
636
637 if ($obj) {
638 $module = $obj->module;
639 $perms = $obj->perms;
640 $subperms = $obj->subperms;
641
642 if ($perms) {
643 if (!isset($this->rights)) {
644 $this->rights = new stdClass(); // For avoid error
645 }
646 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
647 $this->rights->$module = new stdClass();
648 }
649 if ($subperms) {
650 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
651 $this->rights->$module->$perms = new stdClass();
652 }
653 if (empty($this->rights->$module->$perms->$subperms)) {
654 $this->nb_rights++;
655 }
656 $this->rights->$module->$perms->$subperms = 1;
657 } else {
658 if (empty($this->rights->$module->$perms)) {
659 $this->nb_rights++;
660 }
661 $this->rights->$module->$perms = 1;
662 }
663 }
664 }
665
666 $i++;
667 }
668 $this->db->free($resql);
669 }
670
671 if ($moduletag == '') {
672 // Si module etait non defini, alors on a tout charge, on peut donc considerer
673 // que les droits sont en cache (car tous charges) pour cet instance de group
674 $this->all_permissions_are_loaded = 1;
675 } else {
676 // If module defined, we flag it as loaded into cache
677 $this->_tab_loaded[$moduletag] = 1;
678 }
679
680 return 1;
681 }
682
689 public function delete(User $user)
690 {
691 return $this->deleteCommon($user);
692 }
693
700 public function create($notrigger = 0)
701 {
702 global $user, $conf;
703
704 $this->datec = dol_now();
705 if (!empty($this->name)) {
706 $this->nom = $this->name; // Field for 'name' is called 'nom' in database
707 }
708
709 if (!isset($this->entity)) {
710 $this->entity = $conf->entity; // If not defined, we use default value
711 }
712
713 return $this->createCommon($user, $notrigger);
714 }
715
722 public function update($notrigger = 0)
723 {
724 global $user, $conf;
725
726 if (!empty($this->name)) {
727 $this->nom = $this->name; // Field for 'name' is called 'nom' in database
728 }
729
730 return $this->updateCommon($user, $notrigger);
731 }
732
733
743 public function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0)
744 {
745 //print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n";
746 $lastname = $this->lastname;
747 $firstname = $this->firstname;
748 if (empty($lastname)) {
749 $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 : '')))));
750 }
751
752 $ret = '';
753 if (!empty($option) && !empty($this->civility_code)) {
754 if ($langs->transnoentitiesnoconv("Civility".$this->civility_code) != "Civility".$this->civility_code) {
755 $ret .= $langs->transnoentitiesnoconv("Civility".$this->civility_code).' ';
756 } else {
757 $ret .= $this->civility_code.' ';
758 }
759 }
760
761 $ret .= dolGetFirstLastname($firstname, $lastname, $nameorder);
762
763 return dol_trunc($ret, $maxlen);
764 }
765
772 public function getLibStatut($mode = 0)
773 {
774 return $this->LibStatut(0, $mode);
775 }
776
777 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
785 public function LibStatut($status, $mode = 0)
786 {
787 // phpcs:enable
788 global $langs;
789 $langs->load('users');
790 return '';
791 }
792
799 public function getTooltipContentArray($params)
800 {
801 global $conf, $langs, $menumanager;
802
803 $option = $params['option'] ?? '';
804
805 $datas = [];
806 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
807 $langs->load("users");
808 return ['optimize' => $langs->trans("ShowGroup")];
809 }
810 $datas['divopen'] = '<div class="centpercent">';
811 $datas['picto'] = img_picto('', 'group').' <u>'.$langs->trans("Group").'</u><br>';
812 $datas['name'] = '<b>'.$langs->trans('Name').':</b> '.$this->name;
813 $datas['description'] = '<br><b>'.$langs->trans("Description").':</b> '.$this->note;
814 $datas['divclose'] = '</div>';
815
816 return $datas;
817 }
818
830 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
831 {
832 global $langs, $conf, $db, $hookmanager;
833
834 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') && $withpicto) {
835 $withpicto = 0;
836 }
837
838 $result = '';
839 $params = [
840 'id' => $this->id,
841 'objecttype' => $this->element,
842 'option' => $option,
843 ];
844 $classfortooltip = 'classfortooltip';
845 $dataparams = '';
846 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
847 $classfortooltip = 'classforajaxtooltip';
848 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
849 $label = '';
850 } else {
851 $label = implode($this->getTooltipContentArray($params));
852 }
853
854 if ($option == 'permissions') {
855 $url = DOL_URL_ROOT.'/user/group/perms.php?id='.$this->id;
856 } else {
857 $url = DOL_URL_ROOT.'/user/group/card.php?id='.$this->id;
858 }
859
860 if ($option != 'nolink') {
861 // Add param to save lastsearch_values or not
862 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
863 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
864 $add_save_lastsearch_values = 1;
865 }
866 if ($add_save_lastsearch_values) {
867 $url .= '&save_lastsearch_values=1';
868 }
869 }
870
871 $linkclose = "";
872 if (empty($notooltip)) {
873 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
874 $langs->load("users");
875 $label = $langs->trans("ShowGroup");
876 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1, 1).'"';
877 }
878 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
879 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
880 }
881
882 $linkstart = '<a href="'.$url.'"';
883 $linkstart .= $linkclose.'>';
884 $linkend = '</a>';
885
886 $result = $linkstart;
887 if ($withpicto) {
888 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
889 }
890 if ($withpicto != 2) {
891 $result .= $this->name;
892 }
893 $result .= $linkend;
894
895 global $action;
896 $hookmanager->initHooks(array('groupdao'));
897 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
898 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
899 if ($reshook > 0) {
900 $result = $hookmanager->resPrint;
901 } else {
902 $result .= $hookmanager->resPrint;
903 }
904
905 return $result;
906 }
907
908 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
909 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
919 public function _load_ldap_dn($info, $mode = 0)
920 {
921 // phpcs:enable
922 global $conf;
923 $dn = '';
924 if ($mode == 0) {
925 $dn = getDolGlobalString('LDAP_KEY_GROUPS') . "=".$info[getDolGlobalString('LDAP_KEY_GROUPS')]."," . getDolGlobalString('LDAP_GROUP_DN');
926 }
927 if ($mode == 1) {
928 $dn = getDolGlobalString('LDAP_GROUP_DN');
929 }
930 if ($mode == 2) {
931 $dn = getDolGlobalString('LDAP_KEY_GROUPS') . "=".$info[getDolGlobalString('LDAP_KEY_GROUPS')];
932 }
933 return $dn;
934 }
935
936
937 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
938 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
944 public function _load_ldap_info()
945 {
946 // phpcs:enable
947 global $conf;
948
949 $info = array();
950
951 // Object classes
952 $info["objectclass"] = explode(',', getDolGlobalString('LDAP_GROUP_OBJECT_CLASS'));
953
954 // Champs
955 if ($this->name && getDolGlobalString('LDAP_GROUP_FIELD_FULLNAME')) {
956 $info[getDolGlobalString('LDAP_GROUP_FIELD_FULLNAME')] = $this->name;
957 }
958 //if ($this->name && !empty($conf->global->LDAP_GROUP_FIELD_NAME)) $info[$conf->global->LDAP_GROUP_FIELD_NAME] = $this->name;
959 if ($this->note && getDolGlobalString('LDAP_GROUP_FIELD_DESCRIPTION')) {
960 $info[getDolGlobalString('LDAP_GROUP_FIELD_DESCRIPTION')] = dol_string_nohtmltag($this->note, 2);
961 }
962 if (getDolGlobalString('LDAP_GROUP_FIELD_GROUPMEMBERS')) {
963 $valueofldapfield = array();
964 foreach ($this->members as $key => $val) { // This is array of users for group into dolibarr database.
965 $muser = new User($this->db);
966 $muser->fetch($val->id);
967 $info2 = $muser->_load_ldap_info();
968 $valueofldapfield[] = $muser->_load_ldap_dn($info2);
969 }
970 $info[getDolGlobalString('LDAP_GROUP_FIELD_GROUPMEMBERS')] = (!empty($valueofldapfield) ? $valueofldapfield : '');
971 }
972 if (getDolGlobalString('LDAP_GROUP_FIELD_GROUPID')) {
973 $info[getDolGlobalString('LDAP_GROUP_FIELD_GROUPID')] = $this->id;
974 }
975 return $info;
976 }
977
978
986 public function initAsSpecimen()
987 {
988 global $conf, $user, $langs;
989
990 // Initialise parameters
991 $this->id = 0;
992 $this->ref = 'SPECIMEN';
993 $this->specimen = 1;
994
995 $this->name = 'DOLIBARR GROUP SPECIMEN';
996 $this->note = 'This is a note';
997 $this->datec = time();
998 $this->tms = time();
999
1000 // Members of this group is just me
1001 $this->members = array(
1002 $user->id => $user
1003 );
1004
1005 return 1;
1006 }
1007
1019 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1020 {
1021 global $conf, $user, $langs;
1022
1023 $langs->load("user");
1024
1025 // Positionne le modele sur le nom du modele a utiliser
1026 if (!dol_strlen($modele)) {
1027 if (getDolGlobalString('USERGROUP_ADDON_PDF')) {
1028 $modele = getDolGlobalString('USERGROUP_ADDON_PDF');
1029 } else {
1030 $modele = 'grass';
1031 }
1032 }
1033
1034 $modelpath = "core/modules/usergroup/doc/";
1035
1036 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1037 }
1038
1046 public function getKanbanView($option = '', $arraydata = null)
1047 {
1048 global $langs;
1049
1050 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1051
1052 $return = '<div class="box-flex-item box-flex-grow-zero">';
1053 $return .= '<div class="info-box info-box-sm">';
1054 $return .= '<span class="info-box-icon bg-infobox-action">';
1055 $return .= img_picto('', $this->picto);
1056 $return .= '</span>';
1057 $return .= '<div class="info-box-content">';
1058 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1059 if ($selected >= 0) {
1060 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1061 }
1062 if (property_exists($this, 'members')) {
1063 $return .= '<br><span class="info-box-status opacitymedium">'.(empty($this->nb_users) ? 0 : $this->nb_users).' '.$langs->trans('Users').'</span>';
1064 }
1065 if (property_exists($this, 'nb_rights')) {
1066 $return .= '<br><div class="info-box-status margintoponly opacitymedium">'.$langs->trans('NbOfPermissions').' : '.(empty($this->nb_rights) ? 0 : $this->nb_rights).'</div>';
1067 }
1068 $return .= '</div>';
1069 $return .= '</div>';
1070 $return .= '</div>';
1071 return $return;
1072 }
1073}
$object ref
Definition info.php:89
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_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 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:152