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