dolibarr 21.0.3
perms.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
4 * Copyright (C) 2004-2020 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
6 * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@inodbox.com>
7 * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
8 * Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com>
9 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
10 * Copyright (C) 2024 Frédéric France <frederic.france@free.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
31if (!defined('CSRFCHECK_WITH_TOKEN')) {
32 define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
33}
34
35// Load Dolibarr environment
36require '../main.inc.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
40
49// Load translation files required by page
50$langs->loadLangs(array('users', 'admin'));
51
52$id = GETPOSTINT('id');
53$action = GETPOST('action', 'aZ09');
54$confirm = GETPOST('confirm', 'alpha');
55$module = GETPOST('module', 'alpha');
56$rights = GETPOSTINT('rights');
57$updatedmodulename = GETPOST('updatedmodulename', 'alpha');
58$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'userperms'; // To manage different context of search
59
60if (!isset($id) || empty($id)) {
62}
63
64// Define if user can read permissions
65$canreaduser = ($user->admin || $user->hasRight("user", "user", "read"));
66// Define if user can modify other users and permissions
67$caneditperms = ($user->admin || $user->hasRight("user", "user", "write"));
68// Advanced permissions
69if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) {
70 $canreaduser = ($user->admin || ($user->hasRight("user", "user", "read") && $user->hasRight("user", "user_advance", "readperms")));
71 $caneditselfperms = ($user->id == $id && $user->hasRight("user", "self_advance", "writeperms"));
72 $caneditperms = (($caneditperms || $caneditselfperms) ? 1 : 0);
73}
74
75// Security check
76$socid = 0;
77if (!empty($user->socid) && $user->socid > 0) {
78 $socid = $user->socid;
79}
80$feature2 = (($socid && $user->hasRight("user", "self", "write")) ? '' : 'user');
81// A user can always read its own card if not advanced perms enabled, or if he has advanced perms, except for admin
82if ($user->id == $id && (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight("user", "self_advance", "readperms") && empty($user->admin))) {
84}
85
86// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
87$hookmanager->initHooks(array('usercard', 'userperms', 'globalcard'));
88
89$result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
90if ($user->id != $id && !$canreaduser) {
92}
93
94$object = new User($db);
95$object->fetch($id, '', '', 1);
96$object->loadRights();
97
98$entity = $conf->entity;
99
100/*
101 * Actions
102 */
103
104$parameters = array('socid' => $socid);
105$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
106if ($reshook < 0) {
107 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
108}
109
110if (empty($reshook)) {
111 if ($action == 'addrights' && $caneditperms && $confirm == 'yes') {
112 $edituser = new User($db);
113 $edituser->fetch($object->id);
114 $result = $edituser->addrights($rights, $module, '', $entity);
115 if ($result < 0) {
116 setEventMessages($edituser->error, $edituser->errors, 'errors');
117 }
118
119 // If we are changing our own permissions, we reload permissions and menu
120 if ($object->id == $user->id) {
121 $user->clearrights();
122 $user->loadRights();
123 // @phan-suppress-next-line PhanRedefinedClassReference
124 $menumanager->loadMenu();
125 }
126
127 $object->clearrights();
128 $object->loadRights();
129 }
130
131 if ($action == 'delrights' && $caneditperms && $confirm == 'yes') {
132 $edituser = new User($db);
133 $edituser->fetch($object->id);
134 $result = $edituser->delrights($rights, $module, '', $entity);
135 if ($result < 0) {
136 setEventMessages($edituser->error, $edituser->errors, 'errors');
137 }
138
139 // If we are changing our own permissions, we reload permissions and menu
140 if ($object->id == $user->id) {
141 $user->clearrights();
142 $user->loadRights();
143 // @phan-suppress-next-line PhanRedefinedClassReference
144 $menumanager->loadMenu();
145 }
146
147 $object->clearrights();
148 $object->loadRights();
149 }
150}
151
152
153/*
154 * View
155 */
156
157$form = new Form($db);
158
159$person_name = !empty($object->firstname) ? $object->lastname.", ".$object->firstname : $object->lastname;
160$title = $person_name." - ".$langs->trans('Permissions');
161$help_url = '';
162llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-user page-card_perms');
163
165
166$title = $langs->trans("User");
167print dol_get_fiche_head($head, 'rights', $title, -1, 'user');
168
169
170$db->begin();
171
172// Search all modules with permission and reload permissions def.
173$modules = array();
174$modulesdir = dolGetModulesDirs();
175
176foreach ($modulesdir as $dir) {
177 $handle = @opendir(dol_osencode($dir));
178 if (is_resource($handle)) {
179 while (($file = readdir($handle)) !== false) {
180 if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') {
181 $modName = substr($file, 0, dol_strlen($file) - 10);
182
183 if ($modName) {
184 include_once $dir.$file;
185 $objMod = new $modName($db);
186 '@phan-var-force DolibarrModules $objMod';
187
188 // Load all lang files of module
189 if (isset($objMod->langfiles) && is_array($objMod->langfiles)) {
190 foreach ($objMod->langfiles as $domain) {
191 $langs->load($domain);
192 }
193 }
194 // Load all permissions
195 if ($objMod->rights_class) {
196 $ret = $objMod->insert_permissions(0, $entity);
197 $modules[$objMod->rights_class] = $objMod;
198 //print "modules[".$objMod->rights_class."]=$objMod;";
199 }
200 }
201 }
202 }
203 }
204}
205
206$db->commit();
207
208'@phan-var-force DolibarrModules[] $modules';
209
210// Read permissions of edited user
211$permsuser = array();
212
213$sql = "SELECT DISTINCT ur.fk_id";
214$sql .= " FROM ".MAIN_DB_PREFIX."user_rights as ur";
215$sql .= " WHERE ur.entity = ".((int) $entity);
216$sql .= " AND ur.fk_user = ".((int) $object->id);
217
218dol_syslog("get user perms", LOG_DEBUG);
219$result = $db->query($sql);
220if ($result) {
221 $num = $db->num_rows($result);
222 $i = 0;
223 while ($i < $num) {
224 $obj = $db->fetch_object($result);
225 array_push($permsuser, $obj->fk_id);
226 $i++;
227 }
228 $db->free($result);
229} else {
230 dol_print_error($db);
231}
232
233// Read the permissions of a user inherited by its groups
234$permsgroupbyentity = array();
235
236$sql = "SELECT DISTINCT gr.fk_id, gu.entity"; // fk_id are permission id and entity is entity of the group
237$sql .= " FROM ".MAIN_DB_PREFIX."usergroup_rights as gr,";
238$sql .= " ".MAIN_DB_PREFIX."usergroup_user as gu"; // all groups of a user
239$sql .= " WHERE gr.entity = ".((int) $entity);
240// The entity on the table gu=usergroup_user should be useless and should never be used because it is already into gr and r.
241// but when using MULTICOMPANY_TRANSVERSE_MODE, we may have inserted record that make rubbish result here due to the duplicate record of
242// other entities, so we are forced to add a filter on gu here
243$sql .= " AND gu.entity IN (0,".$conf->entity.")";
244$sql .= " AND gr.fk_usergroup = gu.fk_usergroup";
245$sql .= " AND gu.fk_user = ".((int) $object->id);
246
247dol_syslog("get user perms", LOG_DEBUG);
248$result = $db->query($sql);
249if ($result) {
250 $num = $db->num_rows($result);
251 $i = 0;
252 while ($i < $num) {
253 $obj = $db->fetch_object($result);
254 if (!isset($permsgroupbyentity[$obj->entity])) {
255 $permsgroupbyentity[$obj->entity] = array();
256 }
257 array_push($permsgroupbyentity[$obj->entity], $obj->fk_id);
258 $i++;
259 }
260 $db->free($result);
261} else {
262 dol_print_error($db);
263}
264
265
266
267/*
268 * Part to add/remove permissions
269 */
270
271$linkback = '';
272
273if ($user->hasRight("user", "user", "read") || $user->admin) {
274 $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
275}
276
277$morehtmlref = '<a href="'.DOL_URL_ROOT.'/user/vcard.php?id='.$object->id.'&output=file&file='.urlencode(dol_sanitizeFileName($object->getFullName($langs).'.vcf')).'" class="refid" rel="noopener">';
278$morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
279$morehtmlref .= '</a>';
280
281$urltovirtualcard = '/user/virtualcard.php?id='.((int) $object->id);
282$morehtmlref .= dolButtonToOpenUrlInDialogPopup('publicvirtualcard', $langs->transnoentitiesnoconv("PublicVirtualCardUrl").' - '.$object->getFullName($langs), img_picto($langs->trans("PublicVirtualCardUrl"), 'card', 'class="valignmiddle marginleftonly paddingrightonly"'), $urltovirtualcard, '', 'nohover');
283
284dol_banner_tab($object, 'id', $linkback, $user->hasRight("user", "user", "read") || $user->admin, 'rowid', 'ref', $morehtmlref);
285
286
287print '<div class="fichecenter">';
288
289print '<div class="underbanner clearboth"></div>';
290print '<table class="border centpercent tableforfield">';
291
292// Login
293print '<tr><td id="anchorforperms" class="titlefield">'.$langs->trans("Login").'</td>';
294if (!empty($object->ldap_sid) && $object->statut == 0) {
295 print '<td class="error">';
296 print $langs->trans("LoginAccountDisableInDolibarr");
297 print '</td>';
298} else {
299 print '<td>';
300 $addadmin = '';
301 if (property_exists($object, 'admin')) {
302 if (isModEnabled('multicompany') && !empty($object->admin) && empty($object->entity)) {
303 $addadmin .= img_picto($langs->trans("SuperAdministratorDesc"), "redstar", 'class="paddingleft"');
304 } elseif (!empty($object->admin)) {
305 $addadmin .= img_picto($langs->trans("AdministratorDesc"), "star", 'class="paddingleft"');
306 }
307 }
308 print showValueWithClipboardCPButton($object->login).$addadmin;
309 print '</td>';
310}
311print '</tr>'."\n";
312
313// Type
314print '<tr><td>';
315$text = $langs->trans("Type");
316print $form->textwithpicto($text, $langs->trans("InternalExternalDesc"));
317print '</td><td>';
318$type = $langs->trans("Internal");
319if ($object->socid > 0) {
320 $type = $langs->trans("External");
321}
322print '<span class="badgeneutral">';
323print $type;
324if ($object->ldap_sid) {
325 print ' ('.$langs->trans("DomainUser").')';
326}
327print '</span>';
328print '</td></tr>'."\n";
329
330print '</table>';
331
332print '</div>';
333print '<br>';
334
335if ($user->admin) {
336 print info_admin($langs->trans("WarningOnlyPermissionOfActivatedModules"));
337}
338// If edited user is an extern user, we show warning for external users
339if (!empty($object->socid)) {
340 print info_admin(showModulesExludedForExternal($modules))."\n";
341}
342print '<br>';
343
344$parameters = array('permsgroupbyentity' => $permsgroupbyentity);
345$reshook = $hookmanager->executeHooks('insertExtraHeader', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
346if ($reshook < 0) {
347 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
348}
349
350//$listofexpandedmodules = array();
351
352
353print "\n";
354print '<div class="div-table-responsive-no-min">';
355print '<table class="noborder centpercent">';
356
357print '<tr class="liste_titre">';
358print '<td>'.$langs->trans("Module").'</td>';
359if ($caneditperms) {
360 print '<td class="center nowrap">';
361 print '<a class="reposition commonlink addexpandedmodulesinparamlist" title="'.dol_escape_htmltag($langs->trans("All")).'" alt="'.dol_escape_htmltag($langs->trans("All")).'" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=addrights&token='.newToken().'&entity='.$entity.'&module=allmodules&confirm=yes">'.$langs->trans("All")."</a>";
362 print ' / ';
363 print '<a class="reposition commonlink addexpandedmodulesinparamlist" title="'.dol_escape_htmltag($langs->trans("None")).'" alt="'.dol_escape_htmltag($langs->trans("None")).'" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delrights&token='.newToken().'&entity='.$entity.'&module=allmodules&confirm=yes">'.$langs->trans("None")."</a>";
364 print '</td>';
365} else {
366 print '<td></td>';
367}
368print '<td></td>';
369//print '<td></td>';
370print '<td class="right nowrap" colspan="2">';
371print '<a class="showallperms" title="'.dol_escape_htmltag($langs->trans("ShowAllPerms")).'" alt="'.dol_escape_htmltag($langs->trans("ShowAllPerms")).'" href="#">'.img_picto('', 'folder-open', 'class="paddingright"').'<span class="hideonsmartphone">'.$langs->trans("ExpandAll").'</span></a>';
372print ' | ';
373print '<a class="hideallperms" title="'.dol_escape_htmltag($langs->trans("HideAllPerms")).'" alt="'.dol_escape_htmltag($langs->trans("HideAllPerms")).'" href="#">'.img_picto('', 'folder', 'class="paddingright"').'<span class="hideonsmartphone">'.$langs->trans("UndoExpandAll").'</span></a>';
374print '</td>';
375print '</tr>'."\n";
376
377
378// Fix bad value for module_position in table
379// ------------------------------------------
380$sql = "SELECT r.id, r.libelle as label, r.module, r.perms, r.subperms, r.module_position, r.bydefault";
381$sql .= " FROM ".MAIN_DB_PREFIX."rights_def as r";
382$sql .= " WHERE r.libelle NOT LIKE 'tou%'"; // On ignore droits "tous"
383$sql .= " AND r.entity = ".((int) $entity);
384$sql .= " ORDER BY r.family_position, r.module_position, r.module, r.id";
385
386$result = $db->query($sql);
387if ($result) {
388 $num = $db->num_rows($result);
389 $i = 0;
390 $oldmod = '';
391
392 while ($i < $num) {
393 $obj = $db->fetch_object($result);
394
395 // If line is for a module that does not exist anymore (absent of includes/module), we ignore it
396 if (!isset($obj->module) || empty($modules[$obj->module])) {
397 $i++;
398 continue;
399 }
400
401 // Special cases
402 if (isModEnabled("reception")) {
403 // The 2 permissions in fournisseur modules are replaced by permissions into reception module
404 if ($obj->module == 'fournisseur' && $obj->perms == 'commande' && $obj->subperms == 'receptionner') {
405 $i++;
406 continue;
407 }
408 if ($obj->module == 'fournisseur' && $obj->perms == 'commande_advance' && $obj->subperms == 'check') {
409 $i++;
410 continue;
411 }
412 }
413
414 $objMod = $modules[$obj->module];
415
416 // Save field module_position in database if value is wrong
417 if (empty($obj->module_position) || (is_object($objMod) && $objMod->isCoreOrExternalModule() == 'external' && $obj->module_position < 100000)) {
418 if (is_object($modules[$obj->module]) && ($modules[$obj->module]->module_position > 0)) {
419 // TODO Define familyposition
420 //$familyposition = $modules[$obj->module]->family_position;
421 $familyposition = 0;
422
423 $newmoduleposition = $modules[$obj->module]->module_position;
424
425 // Correct $newmoduleposition position for external modules
426 $objMod = $modules[$obj->module];
427 if (is_object($objMod) && $objMod->isCoreOrExternalModule() == 'external' && $newmoduleposition < 100000) {
428 $newmoduleposition += 100000;
429 }
430
431 $sqlupdate = 'UPDATE '.MAIN_DB_PREFIX."rights_def SET module_position = ".((int) $newmoduleposition).",";
432 $sqlupdate .= " family_position = ".((int) $familyposition);
433 $sqlupdate .= " WHERE module_position = ".((int) $obj->module_position)." AND module = '".$db->escape($obj->module)."'";
434
435 $db->query($sqlupdate);
436 }
437 }
438 }
439}
440
441
442
443//print "xx".$conf->global->MAIN_USE_ADVANCED_PERMS;
444$sql = "SELECT r.id, r.libelle as label, r.module, r.perms, r.subperms, r.module_position, r.bydefault";
445$sql .= " FROM ".MAIN_DB_PREFIX."rights_def as r";
446$sql .= " WHERE r.libelle NOT LIKE 'tou%'"; // On ignore droits "tous"
447$sql .= " AND r.entity = ".((int) $entity);
448if (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) {
449 $sql .= " AND r.perms NOT LIKE '%_advance'"; // Hide advanced perms if option is not enabled
450}
451$sql .= " ORDER BY r.family_position, r.module_position, r.module, r.id";
452
453$result = $db->query($sql);
454if ($result) {
455 $num = $db->num_rows($result);
456 $i = 0;
457 $j = 0;
458 $oldmod = '';
459
460 $cookietohidegroup = (empty($_COOKIE["DOLUSER_PERMS_HIDE_GRP"]) ? '' : preg_replace('/^,/', '', $_COOKIE["DOLUSER_PERMS_HIDE_GRP"]));
461 $cookietohidegrouparray = explode(',', $cookietohidegroup);
462 //var_dump($cookietohidegrouparray);
463
464 while ($i < $num) {
465 $obj = $db->fetch_object($result);
466
467 // If line is for a module that does not exist anymore (absent of includes/module), we ignore it
468 if (empty($modules[$obj->module])) {
469 $i++;
470 continue;
471 }
472
473 // Special cases
474 if (isModEnabled("reception")) {
475 // The 2 permission in fournisseur modules has been replaced by permissions into reception module
476 if ($obj->module == 'fournisseur' && $obj->perms == 'commande' && $obj->subperms == 'receptionner') {
477 $i++;
478 continue;
479 }
480 if ($obj->module == 'fournisseur' && $obj->perms == 'commande_advance' && $obj->subperms == 'check') {
481 $i++;
482 continue;
483 }
484 }
485
486 $objMod = $modules[$obj->module];
487
488 // Save field module_position in database if value is wrong
489 /*
490 if (empty($obj->module_position) || (is_object($objMod) && $objMod->isCoreOrExternalModule() == 'external' && $obj->module_position < 100000)) {
491 if (is_object($modules[$obj->module]) && ($modules[$obj->module]->module_position > 0)) {
492 // TODO Define familyposition
493 //$familyposition = $modules[$obj->module]->family_position;
494 $familyposition = 0;
495
496 $newmoduleposition = $modules[$obj->module]->module_position;
497
498 // Correct $newmoduleposition position for external modules
499 $objMod = $modules[$obj->module];
500 if (is_object($objMod) && $objMod->isCoreOrExternalModule() == 'external' && $newmoduleposition < 100000) {
501 $newmoduleposition += 100000;
502 }
503
504 $sqlupdate = 'UPDATE '.MAIN_DB_PREFIX."rights_def SET module_position = ".((int) $newmoduleposition).",";
505 $sqlupdate .= " family_position = ".((int) $familyposition);
506 $sqlupdate .= " WHERE module_position = ".((int) $obj->module_position)." AND module = '".$db->escape($obj->module)."'";
507
508 $db->query($sqlupdate);
509 }
510 }
511 */
512
513 if (GETPOSTISSET('forbreakperms_'.$obj->module)) {
514 $ishidden = GETPOSTINT('forbreakperms_'.$obj->module);
515 } elseif (in_array($j, $cookietohidegrouparray)) { // If j is among list of hidden group
516 $ishidden = 1;
517 } else {
518 $ishidden = 0;
519 }
520 $isexpanded = ! $ishidden;
521 //var_dump("isexpanded=".$isexpanded);
522
523 $permsgroupbyentitypluszero = array();
524 if (!empty($permsgroupbyentity[0])) {
525 $permsgroupbyentitypluszero = array_merge($permsgroupbyentitypluszero, $permsgroupbyentity[0]);
526 }
527 if (!empty($permsgroupbyentity[$entity])) {
528 $permsgroupbyentitypluszero = array_merge($permsgroupbyentitypluszero, $permsgroupbyentity[$entity]);
529 }
530 //var_dump($permsgroupbyentitypluszero);
531
532 // Break found, it's a new module to catch
533 if (isset($obj->module) && ($oldmod != $obj->module)) {
534 $oldmod = $obj->module;
535
536 $j++;
537 if (GETPOSTISSET('forbreakperms_'.$obj->module)) {
538 $ishidden = GETPOSTINT('forbreakperms_'.$obj->module);
539 } elseif (in_array($j, $cookietohidegrouparray)) { // If j is among list of hidden group
540 $ishidden = 1;
541 } else {
542 $ishidden = 0;
543 }
544 $isexpanded = ! $ishidden;
545 //var_dump('$obj->module='.$obj->module.' isexpanded='.$isexpanded);
546
547 // Break detected, we get objMod
548 $objMod = $modules[$obj->module];
549 $picto = ($objMod->picto ? $objMod->picto : 'generic');
550
551 // Show break line
552 print '<tr class="oddeven trforbreakperms" data-hide-perms="'.$obj->module.'" data-j="'.$j.'">';
553 // Picto and label of module
554 print '<td class="maxwidthonsmartphone tdoverflowmax150 tdforbreakperms" data-hide-perms="'.dol_escape_htmltag($obj->module).'" title="'.dol_escape_htmltag($objMod->getName()).'">';
555 print '<input type="hidden" name="forbreakperms_'.$obj->module.'" id="idforbreakperms_'.$obj->module.'" css="cssforfieldishiden" data-j="'.$j.'" value="'.($isexpanded ? '0' : "1").'">';
556 print img_object('', $picto, 'class="pictoobjectwidth paddingright"').' '.$objMod->getName();
557 print '<a name="'.$objMod->getName().'"></a>';
558 print '</td>';
559 // Permission and tick (2 columns)
560 if (($caneditperms && empty($objMod->rights_admin_allowed)) || empty($object->admin)) {
561 if ($caneditperms) {
562 print '<td class="center wraponsmartphone">';
563 print '<span class="permtohide_'.$obj->module.'" '.(!$isexpanded ? ' style="display:none"' : '').'>';
564 print '<a class="reposition alink addexpandedmodulesinparamlist" title="'.dol_escape_htmltag($langs->trans("All")).'" alt="'.dol_escape_htmltag($langs->trans("All")).'" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=addrights&token='.newToken().'&entity='.$entity.'&module='.$obj->module.'&confirm=yes&updatedmodulename='.$obj->module.'">'.$langs->trans("All")."</a>";
565 print ' / ';
566 print '<a class="reposition alink addexpandedmodulesinparamlist" title="'.dol_escape_htmltag($langs->trans("None")).'" alt="'.dol_escape_htmltag($langs->trans("None")).'" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delrights&token='.newToken().'&entity='.$entity.'&module='.$obj->module.'&confirm=yes&updatedmodulename='.$obj->module.'">'.$langs->trans("None")."</a>";
567 print '</span>';
568 print '</td>';
569 print '<td class="tdforbreakperms" data-hide-perms="'.dol_escape_htmltag($obj->module).'">';
570 print '</td>';
571 } else {
572 print '<td class="tdforbreakperms" data-hide-perms="'.dol_escape_htmltag($obj->module).'">&nbsp;</td>';
573 print '<td class="tdforbreakperms" data-hide-perms="'.dol_escape_htmltag($obj->module).'">&nbsp;</td>';
574 }
575 } else {
576 if ($caneditperms) {
577 print '<td class="center wraponsmartphone">';
578 /*print '<a class="reposition alink" title="'.dol_escape_htmltag($langs->trans("All")).'" alt="'.dol_escape_htmltag($langs->trans("All")).'" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=addrights&token='.newToken().'&entity='.$entity.'&module='.$obj->module.'&confirm=yes&updatedmodulename='.$obj->module.'">'.$langs->trans("All")."</a>";
579 print ' / ';
580 print '<a class="reposition alink" title="'.dol_escape_htmltag($langs->trans("None")).'" alt="'.dol_escape_htmltag($langs->trans("None")).'" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delrights&token='.newToken().'&entity='.$entity.'&module='.$obj->module.'&confirm=yes&updatedmodulename='.$obj->module.'">'.$langs->trans("None")."</a>";
581 */
582 print '</td>';
583 print '<td class="tdforbreakperms" data-hide-perms="'.dol_escape_htmltag($obj->module).'">';
584 print '</td>';
585 } else {
586 print '<td class="right tdforbreakperms" data-hide-perms="'.dol_escape_htmltag($obj->module).'"></td>';
587 print '<td class="tdforbreakperms" data-hide-perms="'.dol_escape_htmltag($obj->module).'">&nbsp;</td>';
588 }
589 }
590 // Description of permission (2 columns)
591 print '<td class="tdforbreakperms" data-hide-perms="'.dol_escape_htmltag($obj->module).'">&nbsp;</td>';
592 print '<td class="maxwidthonsmartphone right tdforbreakperms" data-hide-perms="'.dol_escape_htmltag($obj->module).'">';
593 print '<div class="switchfolderperms folderperms_'.$obj->module.'"'.($isexpanded ? ' style="display:none;"' : '').'>';
594 print img_picto('', 'folder', 'class="marginright"');
595 print '</div>';
596 print '<div class="switchfolderperms folderopenperms_'.$obj->module.'"'.(!$isexpanded ? ' style="display:none;"' : '').'>';
597 print img_picto('', 'folder-open', 'class="marginright"');
598 print '</div>';
599 print '</td>'; //Add picto + / - when open en closed
600 print '</tr>'."\n";
601 }
602
603 print '<!-- '.$obj->module.'->'.$obj->perms.($obj->subperms ? '->'.$obj->subperms : '').' -->'."\n";
604 print '<tr class="oddeven trtohide_'.$obj->module.'"'.(!$isexpanded ? ' style="display:none"' : '').'>';
605
606 // Picto and label of module
607 print '<td class="maxwidthonsmartphone tdoverflowmax200">';
608 print '</td>';
609
610 // Permission and tick (2 columns)
611 if (!empty($object->admin) && !empty($objMod->rights_admin_allowed)) { // Permission granted because admin
612 print '<!-- perm is a perm allowed to any admin -->';
613 if ($caneditperms) {
614 print '<td class="center">'.img_picto($langs->trans("AdministratorDesc"), 'star').'</td>';
615 } else {
616 print '<td class="center nowrap">';
617 print img_picto($langs->trans("Active"), 'switch_on', '', 0, 0, 0, '', 'opacitymedium');
618 print '</td>';
619 }
620 print '<td>';
621 print '</td>';
622 } elseif (in_array($obj->id, $permsuser)) { // Permission granted by user
623 print '<!-- user has perm -->';
624 if ($caneditperms) {
625 print '<td class="center">';
626 print '<a class="reposition addexpandedmodulesinparamlist" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delrights&token='.newToken().'&entity='.$entity.'&rights='.$obj->id.'&confirm=yes&updatedmodulename='.$obj->module.'">';
627 //print img_edit_remove($langs->trans("Remove"));
628 print img_picto($langs->trans("Remove"), 'switch_on');
629 print '</a></td>';
630 } else {
631 print '<td class="center nowrap">';
632 print img_picto($langs->trans("Active"), 'switch_on', '', 0, 0, 0, '', 'opacitymedium');
633 print '</td>';
634 }
635 print '<td>';
636 print '</td>';
637 } elseif (isset($permsgroupbyentitypluszero) && is_array($permsgroupbyentitypluszero)) {
638 print '<!-- permsgroupbyentitypluszero -->';
639 if (in_array($obj->id, $permsgroupbyentitypluszero)) { // Permission granted by group
640 print '<td class="center nowrap">';
641 print img_picto($langs->trans("Active"), 'switch_on', '', 0, 0, 0, '', 'opacitymedium');
642 //print img_picto($langs->trans("Active"), 'tick');
643 print '</td>';
644 print '<td>';
645 print $form->textwithtooltip($langs->trans("Inherited"), $langs->trans("PermissionInheritedFromAGroup"));
646 print '</td>';
647 } else {
648 // Do not own permission
649 if ($caneditperms) {
650 print '<td class="center nowrap">';
651 print '<a class="reposition addexpandedmodulesinparamlist" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=addrights&entity='.$entity.'&rights='.$obj->id.'&confirm=yes&token='.newToken().'&updatedmodulename='.$obj->module.'">';
652 //print img_edit_add($langs->trans("Add"));
653 print img_picto($langs->trans("Add"), 'switch_off');
654 print '</a></td>';
655 } else {
656 print '<td class="center nowrap">';
657 print img_picto($langs->trans("Disabled"), 'switch_off', '', 0, 0, 0, '', 'opacitymedium');
658 print '</td>';
659 }
660 print '<td>';
661 print '</td>';
662 }
663 } else {
664 // Do not own permission
665 print '<!-- do not own permission -->';
666 if ($caneditperms) {
667 print '<td class="center">';
668 print '<a class="reposition addexpandedmodulesinparamlist" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=addrights&entity='.$entity.'&rights='.$obj->id.'&confirm=yes&token='.newToken().'&updatedmodulename='.$obj->module.'">';
669 //print img_edit_add($langs->trans("Add"));
670 print img_picto($langs->trans("Add"), 'switch_off');
671 print '</a></td>';
672 } else {
673 print '<td>';
674 print img_picto($langs->trans("Disabled"), 'switch_off', '', 0, 0, 0, '', 'opacitymedium');
675 print '</td>';
676 }
677 print '<td class="center">';
678 print '</td>';
679 }
680
681 // Description of permission (2 columns)
682 $permlabel = (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && ($langs->trans("PermissionAdvanced".$obj->id) != "PermissionAdvanced".$obj->id) ? $langs->trans("PermissionAdvanced".$obj->id) : (($langs->trans("Permission".$obj->id) != "Permission".$obj->id) ? $langs->trans("Permission".$obj->id) : $langs->trans($obj->label)));
683 if (!$user->admin) {
684 print '<td colspan="2">';
685 } else {
686 print '<td>';
687 }
688 print $permlabel;
689 $idtouse = $obj->id;
690 if (in_array($idtouse, array(121, 122, 125, 126))) { // Force message for the 3 permission on third parties
691 $idtouse = 122;
692 }
693 if ($langs->trans("Permission".$idtouse.'b') != "Permission".$idtouse.'b') {
694 print '<br><span class="opacitymedium">'.$langs->trans("Permission".$idtouse.'b').'</span>';
695 }
696 if ($langs->trans("Permission".$obj->id.'c') != "Permission".$obj->id.'c') {
697 print '<br><span class="opacitymedium">'.$langs->trans("Permission".$obj->id.'c').'</span>';
698 }
699 if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) {
700 if (preg_match('/_advance$/', $obj->perms)) {
701 print ' <span class="opacitymedium">('.$langs->trans("AdvancedModeOnly").')</span>';
702 }
703 }
704 // Special warning case for the permission "Allow to modify other users password"
705 if ($obj->module == 'user' && $obj->perms == 'user' && $obj->subperms == 'password') {
706 if ((!empty($object->admin) && !empty($objMod->rights_admin_allowed)) ||
707 in_array($obj->id, $permsuser) /* if edited user owns this permissions */ ||
708 (isset($permsgroupbyentitypluszero) && is_array($permsgroupbyentitypluszero) && in_array($obj->id, $permsgroupbyentitypluszero))) {
709 print ' '.img_warning($langs->trans("AllowPasswordResetBySendingANewPassByEmail"));
710 }
711 }
712 // Special warning case for the permission "Create/modify other users, groups and permissions"
713 if ($obj->module == 'user' && $obj->perms == 'user' && ($obj->subperms == 'creer' || $obj->subperms == 'create')) {
714 if ((!empty($object->admin) && !empty($objMod->rights_admin_allowed)) ||
715 in_array($obj->id, $permsuser) /* if edited user owns this permissions */ ||
716 (isset($permsgroupbyentitypluszero) && is_array($permsgroupbyentitypluszero) && in_array($obj->id, $permsgroupbyentitypluszero))) {
717 print ' '.img_warning($langs->trans("AllowAnyPrivileges"));
718 }
719 }
720 // Special case for reading bank account when you have permission to manage Chart of account
721 if ($obj->module == 'banque' && $obj->perms == 'lire') {
722 if (isModEnabled("accounting") && $object->hasRight('accounting', 'chartofaccount')) {
723 print ' '.img_warning($langs->trans("WarningReadBankAlsoAllowedIfUserHasPermission"));
724 }
725 }
726
727 print '</td>';
728
729 // Permission id
730 if ($user->admin) {
731 print '<td class="right">';
732 $htmltext = $langs->trans("ID").': '.$obj->id;
733 $htmltext .= '<br>'.$langs->trans("Permission").': user->hasRight(\''.dol_escape_htmltag($obj->module).'\', \''.dol_escape_htmltag($obj->perms).'\''.($obj->subperms ? ', \''.dol_escape_htmltag($obj->subperms).'\'' : '').')';
734 print $form->textwithpicto('', $htmltext);
735 //print '<span class="opacitymedium">'.$obj->id.'</span>';
736 print '</td>';
737 }
738
739 print '</tr>'."\n";
740
741 $i++;
742 }
743} else {
744 dol_print_error($db);
745}
746print '</table>';
747print '</div>';
748
749print '<script>';
750print '$(".tdforbreakperms:not(.alink)").on("click", function(){
751 console.log("Click on tdforbreakperms");
752 moduletohide = $(this).data("hide-perms");
753 j = $(this).data("j");
754 if ($("#idforbreakperms_"+moduletohide).val() == 1) {
755 console.log("idforbreakperms_"+moduletohide+" has value hidden=1");
756 $(".trtohide_"+moduletohide).show();
757 $(".permtoshow_"+moduletohide).hide();
758 $(".permtohide_"+moduletohide).show();
759 $(".folderperms_"+moduletohide).hide();
760 $(".folderopenperms_"+moduletohide).show();
761 $("#idforbreakperms_"+moduletohide).val("0");
762 } else {
763 console.log("idforbreakperms_"+moduletohide+" has value hidden=0");
764 $(".trtohide_"+moduletohide).hide();
765 $(".folderopenperms_"+moduletohide).hide();
766 $(".folderperms_"+moduletohide).show();
767 $(".permtoshow_"+moduletohide).show();
768 $(".permtohide_"+moduletohide).hide();
769 $("#idforbreakperms_"+moduletohide).val("1");
770 }
771
772 // Now rebuild the value for cookie
773 var hideuserperm="";
774 $(".trforbreakperms").each(function(index) {
775 //console.log( index + ": " + $( this ).data("j") + " " + $( this ).data("hide-perms") + " " + $("input[data-j="+(index+1)+"]").val());
776 if ($("input[data-j="+(index+1)+"]").val() == 1) {
777 hideuserperm=hideuserperm+","+(index+1);
778 }
779 });
780 // set cookie by js
781 date = new Date(); date.setTime(date.getTime()+(30*86400000));
782 if (hideuserperm) {
783 console.log("set cookie DOLUSER_PERMS_HIDE_GRP="+hideuserperm);
784 document.cookie = "DOLUSER_PERMS_HIDE_GRP=" + hideuserperm + "; expires=" + date.toGMTString() + "; path=/ ";
785 } else {
786 console.log("delete cookie DOLUSER_PERMS_HIDE_GRP");
787 document.cookie = "DOLUSER_PERMS_HIDE_GRP=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/ ";
788 }
789});';
790print "\n";
791
792// Button expand / collapse all
793print '$(".showallperms").on("click", function(){
794 console.log("Click on showallperms");
795
796 console.log("delete cookie DOLUSER_PERMS_HIDE_GRP from showallperms click");
797 document.cookie = "DOLUSER_PERMS_HIDE_GRP=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/ ";
798 $(".tdforbreakperms").each( function(){
799 moduletohide = $(this).data("hide-perms");
800 //console.log(moduletohide);
801 if ($("#idforbreakperms_"+moduletohide).val() != 0) {
802 $(this).trigger("click"); // emulate the click, so the cooki will be resaved
803 }
804 })
805});
806
807$(".hideallperms").on("click", function(){
808 console.log("Click on hideallperms");
809
810 $(".tdforbreakperms").each( function(){
811 moduletohide = $(this).data("hide-perms");
812 //console.log(moduletohide);
813 if ($("#idforbreakperms_"+moduletohide).val() != 1) {
814 $(this).trigger("click"); // emulate the click, so the cooki will be resaved
815 }
816 })
817});';
818print "\n";
819print '</script>';
820
821print '<style>';
822print '.switchfolderperms{
823 cursor: pointer;
824}';
825print '</style>';
826
827$parameters = array();
828$reshook = $hookmanager->executeHooks('insertExtraFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
829if ($reshook < 0) {
830 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
831}
832
833
834print dol_get_fiche_end();
835
836// End of page
837llxFooter();
838$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
showModulesExludedForExternal($modules)
Show array with constants to edit.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class to manage generation of HTML components Only common components must be here.
Class to manage Dolibarr users.
dolGetModulesDirs($subdir='')
Return list of directories that contain modules.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $disabled='', $morecss='classlink button bordertransp', $jsonopen='', $backtopagejsfields='', $accesskey='')
Return HTML code to output a button to open a dialog popup box.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
user_prepare_head(User $object)
Prepare array with list of tabs.