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