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