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