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