dolibarr 19.0.3
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 Frédéric France <frederic.france@netlogic.fr>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
31require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
32if (isModEnabled('ldap')) {
33 require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
34}
35
36
41{
45 public $element = 'usergroup';
46
50 public $table_element = 'usergroup';
51
56 public $ismultientitymanaged = 1;
57
61 public $picto = 'group';
62
66 public $entity;
67
73 public $nom;
74
78 public $name; // Name of group
79
80 public $globalgroup; // Global group
81
86 public $usergroup_entity;
87
93 public $datec;
94
100 public $tms;
101
105 public $note;
106
110 public $members = array(); // Array of users
111
112 public $nb_rights; // Number of rights granted to the user
113 public $nb_users; // Number of users in the group
114
115 public $rights; // Permissions of the group
116
117 private $_tab_loaded = array(); // Array of cache of already loaded permissions
118
122 public $all_permissions_are_loaded;
123
124 public $oldcopy; // To contains a clone of this when we need to save old properties of object
125
126 public $fields = array(
127 'rowid'=>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'),
128 'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'notnull'=> 1, 'default'=>1, 'index'=>1, 'position'=>5),
129 'nom'=>array('type'=>'varchar(180)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Group name'),
130 'note' => array('type'=>'html', 'label'=>'Description', 'enabled'=>1, 'visible'=>1, 'position'=>20, 'notnull'=>-1, 'searchall'=>1),
131 'datec' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>50, 'notnull'=>1,),
132 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'position'=>60, 'notnull'=>1,),
133 'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'ModelPDF', 'enabled'=>1, 'visible'=>0, 'position'=>100),
134 );
135
139 public $fk_element = 'fk_usergroup';
140
144 protected $childtables = array();
145
149 protected $childtablesoncascade = array('usergroup_rights', 'usergroup_user');
150
151
157 public function __construct($db)
158 {
159 $this->db = $db;
160 $this->nb_rights = 0;
161 }
162
163
172 public function fetch($id = 0, $groupname = '', $load_members = false)
173 {
174 global $conf;
175
176 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
177 if (!empty($groupname)) {
178 $result = $this->fetchCommon(0, '', ' AND nom = \''.$this->db->escape($groupname).'\'');
179 } else {
180 $result = $this->fetchCommon($id);
181 }
182
183 $this->name = $this->nom; // For compatibility with field name
184
185 if ($result) {
186 if ($load_members) {
187 $this->members = $this->listUsersForGroup(); // This make a lot of subrequests
188 }
189
190 return 1;
191 } else {
192 $this->error = $this->db->lasterror();
193 return -1;
194 }
195 }
196
197
205 public function listGroupsForUser($userid, $load_members = true)
206 {
207 global $conf, $user;
208
209 $ret = array();
210
211 $sql = "SELECT g.rowid, ug.entity as usergroup_entity";
212 $sql .= " FROM ".$this->db->prefix()."usergroup as g,";
213 $sql .= " ".$this->db->prefix()."usergroup_user as ug";
214 $sql .= " WHERE ug.fk_usergroup = g.rowid";
215 $sql .= " AND ug.fk_user = ".((int) $userid);
216 if (isModEnabled('multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
217 $sql .= " AND g.entity IS NOT NULL";
218 } else {
219 $sql .= " AND g.entity IN (0,".$conf->entity.")";
220 }
221 $sql .= " ORDER BY g.nom";
222
223 dol_syslog(get_class($this)."::listGroupsForUser", LOG_DEBUG);
224 $result = $this->db->query($sql);
225 if ($result) {
226 while ($obj = $this->db->fetch_object($result)) {
227 if (!array_key_exists($obj->rowid, $ret)) {
228 $newgroup = new UserGroup($this->db);
229 $newgroup->fetch($obj->rowid, '', $load_members);
230 $ret[$obj->rowid] = $newgroup;
231 }
232
233 if (!is_array($ret[$obj->rowid]->usergroup_entity)) {
234 $ret[$obj->rowid]->usergroup_entity = array();
235 }
236 $ret[$obj->rowid]->usergroup_entity[] = $obj->usergroup_entity;
237 }
238
239 $this->db->free($result);
240
241 return $ret;
242 } else {
243 $this->error = $this->db->lasterror();
244 return -1;
245 }
246 }
247
255 public function listUsersForGroup($excludefilter = '', $mode = 0)
256 {
257 global $conf, $user;
258
259 $ret = array();
260
261 $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";
262 if (!empty($this->id)) {
263 $sql .= ", ug.entity as usergroup_entity";
264 }
265 $sql .= " FROM ".$this->db->prefix()."user as u";
266 if (!empty($this->id)) {
267 $sql .= ", ".$this->db->prefix()."usergroup_user as ug";
268 }
269 $sql .= " WHERE 1 = 1";
270 if (!empty($this->id)) {
271 $sql .= " AND ug.fk_user = u.rowid";
272 }
273 if (!empty($this->id)) {
274 $sql .= " AND ug.fk_usergroup = ".((int) $this->id);
275 }
276 if (isModEnabled('multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
277 $sql .= " AND u.entity IS NOT NULL";
278 } else {
279 $sql .= " AND u.entity IN (0,".$conf->entity.")";
280 }
281 if (!empty($excludefilter)) {
282 $sql .= ' AND ('.$excludefilter.')';
283 }
284
285 dol_syslog(get_class($this)."::listUsersForGroup", LOG_DEBUG);
286 $resql = $this->db->query($sql);
287
288 if ($resql) {
289 while ($obj = $this->db->fetch_object($resql)) {
290 if (!array_key_exists($obj->rowid, $ret)) {
291 if ($mode != 1) {
292 $newuser = new User($this->db);
293 //$newuser->fetch($obj->rowid); // We are inside a loop, no subrequests inside a loop
294 $newuser->id = $obj->rowid;
295 $newuser->login = $obj->login;
296 $newuser->photo = $obj->photo;
297 $newuser->lastname = $obj->lastname;
298 $newuser->firstname = $obj->firstname;
299 $newuser->email = $obj->email;
300 $newuser->socid = $obj->fk_soc;
301 $newuser->entity = $obj->entity;
302 $newuser->employee = $obj->employee;
303 $newuser->status = $obj->status;
304
305 $ret[$obj->rowid] = $newuser;
306 } else {
307 $ret[$obj->rowid] = $obj->rowid;
308 }
309 }
310 if ($mode != 1 && !empty($obj->usergroup_entity)) {
311 if (!is_array($ret[$obj->rowid]->usergroup_entity)) {
312 $ret[$obj->rowid]->usergroup_entity = array();
313 }
314 $ret[$obj->rowid]->usergroup_entity[] = $obj->usergroup_entity;
315 }
316 }
317
318 $this->db->free($resql);
319
320 return $ret;
321 } else {
322 $this->error = $this->db->lasterror();
323 return -1;
324 }
325 }
326
336 public function addrights($rid, $allmodule = '', $allperms = '', $entity = 0)
337 {
338 global $conf, $user, $langs;
339
340 $entity = (!empty($entity) ? $entity : $conf->entity);
341
342 dol_syslog(get_class($this)."::addrights $rid, $allmodule, $allperms, $entity");
343 $error = 0;
344 $whereforadd = '';
345
346 $this->db->begin();
347
348 if (!empty($rid)) {
349 $module = $perms = $subperms = '';
350
351 // Si on a demande ajout d'un droit en particulier, on recupere
352 // les caracteristiques (module, perms et subperms) de ce droit.
353 $sql = "SELECT module, perms, subperms";
354 $sql .= " FROM ".$this->db->prefix()."rights_def";
355 $sql .= " WHERE id = ".((int) $rid);
356 $sql .= " AND entity = ".((int) $entity);
357
358 $result = $this->db->query($sql);
359 if ($result) {
360 $obj = $this->db->fetch_object($result);
361 if ($obj) {
362 $module = $obj->module;
363 $perms = $obj->perms;
364 $subperms = $obj->subperms;
365 }
366 } else {
367 $error++;
368 dol_print_error($this->db);
369 }
370
371 // Where pour la liste des droits a ajouter
372 $whereforadd = "id=".((int) $rid);
373 // Find also rights that are herited to add them too
374 if ($subperms) {
375 $whereforadd .= " OR (module='".$this->db->escape($module)."' AND perms='".$this->db->escape($perms)."' AND (subperms='lire' OR subperms='read'))";
376 } elseif ($perms) {
377 $whereforadd .= " OR (module='".$this->db->escape($module)."' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
378 }
379 } else {
380 // Where pour la liste des droits a ajouter
381 if (!empty($allmodule)) {
382 if ($allmodule == 'allmodules') {
383 $whereforadd = 'allmodules';
384 } else {
385 $whereforadd = "module='".$this->db->escape($allmodule)."'";
386 if (!empty($allperms)) {
387 $whereforadd .= " AND perms='".$this->db->escape($allperms)."'";
388 }
389 }
390 }
391 }
392
393 // Add permission of the list $whereforadd
394 if (!empty($whereforadd)) {
395 //print "$module-$perms-$subperms";
396 $sql = "SELECT id";
397 $sql .= " FROM ".$this->db->prefix()."rights_def";
398 $sql .= " WHERE entity = ".((int) $entity);
399 if (!empty($whereforadd) && $whereforadd != 'allmodules') {
400 $sql .= " AND ".$whereforadd;
401 }
402
403 $result = $this->db->query($sql);
404 if ($result) {
405 $num = $this->db->num_rows($result);
406 $i = 0;
407 while ($i < $num) {
408 $obj = $this->db->fetch_object($result);
409 $nid = $obj->id;
410
411 $sql = "DELETE FROM ".$this->db->prefix()."usergroup_rights WHERE fk_usergroup = ".((int) $this->id)." AND fk_id=".((int) $nid)." AND entity = ".((int) $entity);
412 if (!$this->db->query($sql)) {
413 $error++;
414 }
415 $sql = "INSERT INTO ".$this->db->prefix()."usergroup_rights (entity, fk_usergroup, fk_id) VALUES (".((int) $entity).", ".((int) $this->id).", ".((int) $nid).")";
416 if (!$this->db->query($sql)) {
417 $error++;
418 }
419
420 $i++;
421 }
422 } else {
423 $error++;
424 dol_print_error($this->db);
425 }
426
427 if (!$error) {
428 $langs->load("other");
429 $this->context = array('audit'=>$langs->trans("PermissionsAdd").($rid ? ' (id='.$rid.')' : ''));
430
431 // Call trigger
432 $result = $this->call_trigger('USERGROUP_MODIFY', $user);
433 if ($result < 0) {
434 $error++;
435 }
436 // End call triggers
437 }
438 }
439
440 if ($error) {
441 $this->db->rollback();
442 return -$error;
443 } else {
444 $this->db->commit();
445 return 1;
446 }
447 }
448
449
459 public function delrights($rid, $allmodule = '', $allperms = '', $entity = 0)
460 {
461 global $conf, $user, $langs;
462
463 $error = 0;
464 $wherefordel = '';
465
466 $entity = (!empty($entity) ? $entity : $conf->entity);
467
468 $this->db->begin();
469
470 if (!empty($rid)) {
471 $module = $perms = $subperms = '';
472
473 // Si on a demande supression d'un droit en particulier, on recupere
474 // les caracteristiques module, perms et subperms de ce droit.
475 $sql = "SELECT module, perms, subperms";
476 $sql .= " FROM ".$this->db->prefix()."rights_def";
477 $sql .= " WHERE id = ".((int) $rid);
478 $sql .= " AND entity = ".((int) $entity);
479
480 $result = $this->db->query($sql);
481 if ($result) {
482 $obj = $this->db->fetch_object($result);
483 if ($obj) {
484 $module = $obj->module;
485 $perms = $obj->perms;
486 $subperms = $obj->subperms;
487 }
488 } else {
489 $error++;
490 dol_print_error($this->db);
491 }
492
493 // Where for the list of permissions to delete
494 $wherefordel = "id = ".((int) $rid);
495 // Suppression des droits induits
496 if ($subperms == 'lire' || $subperms == 'read') {
497 $wherefordel .= " OR (module='".$this->db->escape($module)."' AND perms='".$this->db->escape($perms)."' AND subperms IS NOT NULL)";
498 }
499 if ($perms == 'lire' || $perms == 'read') {
500 $wherefordel .= " OR (module='".$this->db->escape($module)."')";
501 }
502
503 // Pour compatibilite, si lowid = 0, on est en mode suppression de tout
504 // TODO A virer quand sera gere par l'appelant
505 //if (substr($rid,-1,1) == 0) $wherefordel="module='$module'";
506 } else {
507 // Add permission of the list $wherefordel
508 if (!empty($allmodule)) {
509 if ($allmodule == 'allmodules') {
510 $wherefordel = 'allmodules';
511 } else {
512 $wherefordel = "module='".$this->db->escape($allmodule)."'";
513 if (!empty($allperms)) {
514 $wherefordel .= " AND perms='".$this->db->escape($allperms)."'";
515 }
516 }
517 }
518 }
519
520 // Suppression des droits de la liste wherefordel
521 if (!empty($wherefordel)) {
522 //print "$module-$perms-$subperms";
523 $sql = "SELECT id";
524 $sql .= " FROM ".$this->db->prefix()."rights_def";
525 $sql .= " WHERE entity = ".((int) $entity);
526 if (!empty($wherefordel) && $wherefordel != 'allmodules') {
527 $sql .= " AND ".$wherefordel;
528 }
529
530 $result = $this->db->query($sql);
531 if ($result) {
532 $num = $this->db->num_rows($result);
533 $i = 0;
534 while ($i < $num) {
535 $nid = 0;
536
537 $obj = $this->db->fetch_object($result);
538 if ($obj) {
539 $nid = $obj->id;
540 }
541
542 $sql = "DELETE FROM ".$this->db->prefix()."usergroup_rights";
543 $sql .= " WHERE fk_usergroup = $this->id AND fk_id=".((int) $nid);
544 $sql .= " AND entity = ".((int) $entity);
545 if (!$this->db->query($sql)) {
546 $error++;
547 }
548
549 $i++;
550 }
551 } else {
552 $error++;
553 dol_print_error($this->db);
554 }
555
556 if (!$error) {
557 $langs->load("other");
558 $this->context = array('audit'=>$langs->trans("PermissionsDelete").($rid ? ' (id='.$rid.')' : ''));
559
560 // Call trigger
561 $result = $this->call_trigger('USERGROUP_MODIFY', $user);
562 if ($result < 0) {
563 $error++;
564 }
565 // End call triggers
566 }
567 }
568
569 if ($error) {
570 $this->db->rollback();
571 return -$error;
572 } else {
573 $this->db->commit();
574 return 1;
575 }
576 }
577
578
585 public function getrights($moduletag = '')
586 {
587 global $conf;
588
589 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
590 // Rights for this module are already loaded, so we leave
591 return 0;
592 }
593
594 if (!empty($this->all_permissions_are_loaded)) {
595 // We already loaded all rights for this group, so we leave
596 return 0;
597 }
598
599 /*
600 * Recuperation des droits
601 */
602 $sql = "SELECT r.module, r.perms, r.subperms ";
603 $sql .= " FROM ".$this->db->prefix()."usergroup_rights as u, ".$this->db->prefix()."rights_def as r";
604 $sql .= " WHERE r.id = u.fk_id";
605 $sql .= " AND r.entity = ".((int) $conf->entity);
606 $sql .= " AND u.entity = ".((int) $conf->entity);
607 $sql .= " AND u.fk_usergroup = ".((int) $this->id);
608 $sql .= " AND r.perms IS NOT NULL";
609 if ($moduletag) {
610 $sql .= " AND r.module = '".$this->db->escape($moduletag)."'";
611 }
612
613 dol_syslog(get_class($this).'::getrights', LOG_DEBUG);
614 $resql = $this->db->query($sql);
615 if ($resql) {
616 $num = $this->db->num_rows($resql);
617 $i = 0;
618 while ($i < $num) {
619 $obj = $this->db->fetch_object($resql);
620
621 if ($obj) {
622 $module = $obj->module;
623 $perms = $obj->perms;
624 $subperms = $obj->subperms;
625
626 if ($perms) {
627 if (!isset($this->rights)) {
628 $this->rights = new stdClass(); // For avoid error
629 }
630 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
631 $this->rights->$module = new stdClass();
632 }
633 if ($subperms) {
634 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
635 $this->rights->$module->$perms = new stdClass();
636 }
637 if (empty($this->rights->$module->$perms->$subperms)) {
638 $this->nb_rights++;
639 }
640 $this->rights->$module->$perms->$subperms = 1;
641 } else {
642 if (empty($this->rights->$module->$perms)) {
643 $this->nb_rights++;
644 }
645 $this->rights->$module->$perms = 1;
646 }
647 }
648 }
649
650 $i++;
651 }
652 $this->db->free($resql);
653 }
654
655 if ($moduletag == '') {
656 // Si module etait non defini, alors on a tout charge, on peut donc considerer
657 // que les droits sont en cache (car tous charges) pour cet instance de group
658 $this->all_permissions_are_loaded = 1;
659 } else {
660 // If module defined, we flag it as loaded into cache
661 $this->_tab_loaded[$moduletag] = 1;
662 }
663
664 return 1;
665 }
666
673 public function delete(User $user)
674 {
675 return $this->deleteCommon($user);
676 }
677
684 public function create($notrigger = 0)
685 {
686 global $user, $conf;
687
688 $this->datec = dol_now();
689 if (!empty($this->name)) {
690 $this->nom = $this->name; // Field for 'name' is called 'nom' in database
691 }
692
693 if (!isset($this->entity)) {
694 $this->entity = $conf->entity; // If not defined, we use default value
695 }
696
697 return $this->createCommon($user, $notrigger);
698 }
699
706 public function update($notrigger = 0)
707 {
708 global $user, $conf;
709
710 if (!empty($this->name)) {
711 $this->nom = $this->name; // Field for 'name' is called 'nom' in database
712 }
713
714 return $this->updateCommon($user, $notrigger);
715 }
716
717
727 public function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0)
728 {
729 //print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n";
730 $lastname = $this->lastname;
731 $firstname = $this->firstname;
732 if (empty($lastname)) {
733 $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 : '')))));
734 }
735
736 $ret = '';
737 if (!empty($option) && !empty($this->civility_code)) {
738 if ($langs->transnoentitiesnoconv("Civility".$this->civility_code) != "Civility".$this->civility_code) {
739 $ret .= $langs->transnoentitiesnoconv("Civility".$this->civility_code).' ';
740 } else {
741 $ret .= $this->civility_code.' ';
742 }
743 }
744
745 $ret .= dolGetFirstLastname($firstname, $lastname, $nameorder);
746
747 return dol_trunc($ret, $maxlen);
748 }
749
756 public function getLibStatut($mode = 0)
757 {
758 return $this->LibStatut(0, $mode);
759 }
760
761 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
769 public function LibStatut($status, $mode = 0)
770 {
771 // phpcs:enable
772 global $langs;
773 $langs->load('users');
774 return '';
775 }
776
784 public function getTooltipContentArray($params)
785 {
786 global $conf, $langs, $menumanager;
787
788 $option = $params['option'] ?? '';
789
790 $datas = [];
791 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
792 $langs->load("users");
793 return ['optimize' => $langs->trans("ShowGroup")];
794 }
795 $datas['divopen'] = '<div class="centpercent">';
796 $datas['picto'] = img_picto('', 'group').' <u>'.$langs->trans("Group").'</u><br>';
797 $datas['name'] = '<b>'.$langs->trans('Name').':</b> '.$this->name;
798 $datas['description'] = '<br><b>'.$langs->trans("Description").':</b> '.$this->note;
799 $datas['divclose'] = '</div>';
800
801 return $datas;
802 }
803
815 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
816 {
817 global $langs, $conf, $db, $hookmanager;
818
819 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') && $withpicto) {
820 $withpicto = 0;
821 }
822
823 $result = '';
824 $params = [
825 'id' => $this->id,
826 'objecttype' => $this->element,
827 'option' => $option,
828 ];
829 $classfortooltip = 'classfortooltip';
830 $dataparams = '';
831 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
832 $classfortooltip = 'classforajaxtooltip';
833 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
834 $label = '';
835 } else {
836 $label = implode($this->getTooltipContentArray($params));
837 }
838
839 if ($option == 'permissions') {
840 $url = DOL_URL_ROOT.'/user/group/perms.php?id='.$this->id;
841 } else {
842 $url = DOL_URL_ROOT.'/user/group/card.php?id='.$this->id;
843 }
844
845 if ($option != 'nolink') {
846 // Add param to save lastsearch_values or not
847 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
848 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
849 $add_save_lastsearch_values = 1;
850 }
851 if ($add_save_lastsearch_values) {
852 $url .= '&save_lastsearch_values=1';
853 }
854 }
855
856 $linkclose = "";
857 if (empty($notooltip)) {
858 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
859 $langs->load("users");
860 $label = $langs->trans("ShowGroup");
861 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1, 1).'"';
862 }
863 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
864 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
865 }
866
867 $linkstart = '<a href="'.$url.'"';
868 $linkstart .= $linkclose.'>';
869 $linkend = '</a>';
870
871 $result = $linkstart;
872 if ($withpicto) {
873 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
874 }
875 if ($withpicto != 2) {
876 $result .= $this->name;
877 }
878 $result .= $linkend;
879
880 global $action;
881 $hookmanager->initHooks(array('groupdao'));
882 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
883 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
884 if ($reshook > 0) {
885 $result = $hookmanager->resPrint;
886 } else {
887 $result .= $hookmanager->resPrint;
888 }
889
890 return $result;
891 }
892
893 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
894 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
904 public function _load_ldap_dn($info, $mode = 0)
905 {
906 // phpcs:enable
907 global $conf;
908 $dn = '';
909 if ($mode == 0) {
910 $dn = getDolGlobalString('LDAP_KEY_GROUPS') . "=".$info[getDolGlobalString('LDAP_KEY_GROUPS')]."," . getDolGlobalString('LDAP_GROUP_DN');
911 }
912 if ($mode == 1) {
913 $dn = $conf->global->LDAP_GROUP_DN;
914 }
915 if ($mode == 2) {
916 $dn = getDolGlobalString('LDAP_KEY_GROUPS') . "=".$info[getDolGlobalString('LDAP_KEY_GROUPS')];
917 }
918 return $dn;
919 }
920
921
922 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
923 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
929 public function _load_ldap_info()
930 {
931 // phpcs:enable
932 global $conf;
933
934 $info = array();
935
936 // Object classes
937 $info["objectclass"] = explode(',', getDolGlobalString('LDAP_GROUP_OBJECT_CLASS'));
938
939 // Champs
940 if ($this->name && getDolGlobalString('LDAP_GROUP_FIELD_FULLNAME')) {
941 $info[getDolGlobalString('LDAP_GROUP_FIELD_FULLNAME')] = $this->name;
942 }
943 //if ($this->name && !empty($conf->global->LDAP_GROUP_FIELD_NAME)) $info[$conf->global->LDAP_GROUP_FIELD_NAME] = $this->name;
944 if ($this->note && getDolGlobalString('LDAP_GROUP_FIELD_DESCRIPTION')) {
945 $info[getDolGlobalString('LDAP_GROUP_FIELD_DESCRIPTION')] = dol_string_nohtmltag($this->note, 2);
946 }
947 if (getDolGlobalString('LDAP_GROUP_FIELD_GROUPMEMBERS')) {
948 $valueofldapfield = array();
949 foreach ($this->members as $key => $val) { // This is array of users for group into dolibarr database.
950 $muser = new User($this->db);
951 $muser->fetch($val->id);
952 $info2 = $muser->_load_ldap_info();
953 $valueofldapfield[] = $muser->_load_ldap_dn($info2);
954 }
955 $info[getDolGlobalString('LDAP_GROUP_FIELD_GROUPMEMBERS')] = (!empty($valueofldapfield) ? $valueofldapfield : '');
956 }
957 if (getDolGlobalString('LDAP_GROUP_FIELD_GROUPID')) {
958 $info[getDolGlobalString('LDAP_GROUP_FIELD_GROUPID')] = $this->id;
959 }
960 return $info;
961 }
962
963
971 public function initAsSpecimen()
972 {
973 global $conf, $user, $langs;
974
975 // Initialise parametres
976 $this->id = 0;
977 $this->ref = 'SPECIMEN';
978 $this->specimen = 1;
979
980 $this->name = 'DOLIBARR GROUP SPECIMEN';
981 $this->note = 'This is a note';
982 $this->datec = time();
983 $this->tms = time();
984
985 // Members of this group is just me
986 $this->members = array(
987 $user->id => $user
988 );
989 }
990
1002 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1003 {
1004 global $conf, $user, $langs;
1005
1006 $langs->load("user");
1007
1008 // Positionne le modele sur le nom du modele a utiliser
1009 if (!dol_strlen($modele)) {
1010 if (getDolGlobalString('USERGROUP_ADDON_PDF')) {
1011 $modele = $conf->global->USERGROUP_ADDON_PDF;
1012 } else {
1013 $modele = 'grass';
1014 }
1015 }
1016
1017 $modelpath = "core/modules/usergroup/doc/";
1018
1019 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1020 }
1021
1029 public function getKanbanView($option = '', $arraydata = null)
1030 {
1031 global $langs;
1032
1033 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1034
1035 $return = '<div class="box-flex-item box-flex-grow-zero">';
1036 $return .= '<div class="info-box info-box-sm">';
1037 $return .= '<span class="info-box-icon bg-infobox-action">';
1038 $return .= img_picto('', $this->picto);
1039 $return .= '</span>';
1040 $return .= '<div class="info-box-content">';
1041 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1042 if ($selected >= 0) {
1043 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1044 }
1045 if (property_exists($this, 'members')) {
1046 $return .= '<br><span class="info-box-status opacitymedium">'.(empty($this->nb_users) ? 0 : $this->nb_users).' '.$langs->trans('Users').'</span>';
1047 }
1048 if (property_exists($this, 'nb_rights')) {
1049 $return .= '<br><div class="info-box-status margintoponly opacitymedium">'.$langs->trans('NbOfPermissions').' : '.(empty($this->nb_rights) ? 0 : $this->nb_rights).'</div>';
1050 }
1051 $return .= '</div>';
1052 $return .= '</div>';
1053 $return .= '</div>';
1054 return $return;
1055 }
1056}
$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=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
updateCommon(User $user, $notrigger=false)
Update object into database.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the 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 optionaly the picto) Use this->id,this->lastname,...
fetch($id=0, $groupname='', $load_members=false)
Charge un objet group avec toutes ses caracteristiques (except ->members array)
listUsersForGroup($excludefilter='', $mode=0)
Return array of User objects for group this->id (or all if this->id not defined)
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
_load_ldap_info()
Initialize the info array (array of LDAP values) that will be used to call LDAP functions.
_load_ldap_dn($info, $mode=0)
Retourne chaine DN complete dans l'annuaire LDAP pour l'objet.
LibStatut($status, $mode=0)
Return the label of a given status.
delrights($rid, $allmodule='', $allperms='', $entity=0)
Remove a permission from group.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
listGroupsForUser($userid, $load_members=true)
Return array of groups objects for a particular user.
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+' '+name+' '+lastname)
addrights($rid, $allmodule='', $allperms='', $entity=0)
Add a permission to a group.
initAsSpecimen()
Initialise an instance with random values.
create($notrigger=0)
Create group into database.
getrights($moduletag='')
Charge dans l'objet group, la liste des permissions auquels le groupe a droit.
getLibStatut($mode=0)
Return the label of the status.
getTooltipContentArray($params)
getTooltipContentArray
__construct($db)
Constructor de la classe.
update($notrigger=0)
Update group into database.
Class to manage Dolibarr users.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
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:124