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) 2020 Tobias Sekan <tobias.sekan@startmail.com>
8 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
9 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
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';
44require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
45require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
46require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
47require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
48require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.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') : 'groupperms'; // To manage different context of search
60
61if (!isset($id) || empty($id)) {
63}
64
65// Define if user can read permissions
66$permissiontoread = ($user->admin || $user->hasRight("user", "user", "read"));
67// Define if user can modify group permissions
68$permissiontoedit = ($user->admin || $user->hasRight("user", "user", "write"));
69// Advanced permissions
70$advancedpermsactive = false;
71if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) {
72 $advancedpermsactive = true;
73 $permissiontoread = ($user->admin || ($user->hasRight("user", "group_advance", "read") && $user->hasRight("user", "group_advance", "readperms")));
74 $permissiontoedit = ($user->admin || $user->hasRight("user", "group_advance", "write"));
75}
76
77// Security check
78$socid = 0;
79if (!empty($user->socid) && $user->socid > 0) {
80 $socid = $user->socid;
81}
82//restrictedArea($user, 'user', $id, 'usergroup', '');
83if (!$permissiontoread) {
85}
86
87$object = new UserGroup($db);
88$object->fetch($id);
89$object->loadRights();
90
91$entity = $conf->entity;
92
93// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
94$hookmanager->initHooks(array('groupperms', 'globalcard'));
95
96
97/*
98 * Actions
99 */
100
101$parameters = array('socid' => $socid);
102$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
103if ($reshook < 0) {
104 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
105}
106
107if (empty($reshook)) {
108 if ($action == 'addrights' && $permissiontoedit) {
109 $editgroup = new UserGroup($db);
110 $result = $editgroup->fetch($object->id);
111 if ($result > 0) {
112 $result = $editgroup->addrights($rights, $module, '', $entity);
113 if ($result < 0) {
114 setEventMessages($editgroup->error, $editgroup->errors, 'errors');
115 }
116 } else {
117 dol_print_error($db);
118 }
119
120 $user->clearrights();
121 $user->loadRights();
122
123 // We redirect to avoid to get an URL with token inside
124 $qs = $_SERVER["QUERY_STRING"];
125 $qs = preg_replace('/&action=addrights/', '', $qs);
126 $qs = preg_replace('/&token=[0-9a-f]+/i', '', $qs);
127 $qs = preg_replace('/&confirm=yes/', '', $qs);
128 //var_dump($qs);exit;
129 header("Location: ".$_SERVER["PHP_SELF"].($qs ? "?".$qs : ""));
130 exit;
131 }
132
133 if ($action == 'delrights' && $permissiontoedit) {
134 $editgroup = new UserGroup($db);
135 $result = $editgroup->fetch($id);
136 if ($result > 0) {
137 $result = $editgroup->delrights($rights, $module, '', $entity);
138 if ($result < 0) {
139 setEventMessages($editgroup->error, $editgroup->errors, 'errors');
140 }
141 } else {
142 dol_print_error($db);
143 }
144
145 $user->clearrights();
146 $user->loadRights();
147
148 // We redirect to avoid to get an URL with token inside
149 $qs = $_SERVER["QUERY_STRING"];
150 $qs = preg_replace('/&action=delrights/', '', $qs);
151 $qs = preg_replace('/&token=[0-9a-f]+/i', '', $qs);
152 $qs = preg_replace('/&confirm=yes/', '', $qs);
153 //var_dump($qs);exit;
154 header("Location: ".$_SERVER["PHP_SELF"].($qs ? "?".$qs : ""));
155 exit;
156 }
157}
158
159
160/*
161 * View
162 */
163
164$form = new Form($db);
165$formother = new FormOther($db);
166
167$title = $object->name." - ".$langs->trans('Permissions');
168$help_url = '';
169llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-user page-group_perms');
170
171if ($object->id <= 0) {
172 accessforbidden('Group not found');
173}
174
176$title = $langs->trans("Group");
177print dol_get_fiche_head($head, 'rights', $title, -1, 'group');
178
179// Charge les modules soumis a permissions
180$modules = array();
181$modulesdir = dolGetModulesDirs();
182
183$db->begin();
184
185foreach ($modulesdir as $dir) {
186 $handle = @opendir(dol_osencode($dir));
187 if (is_resource($handle)) {
188 while (($file = readdir($handle)) !== false) {
189 if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') {
190 $modName = substr($file, 0, dol_strlen($file) - 10);
191
192 if ($modName) {
193 include_once $dir.$file;
194 $objMod = new $modName($db);
195 '@phan-var-force DolibarrModules $objMod';
198 // Load all lang files of module
199 if (isset($objMod->langfiles) && is_array($objMod->langfiles)) {
200 foreach ($objMod->langfiles as $domain) {
201 $langs->load($domain);
202 }
203 }
204 // Load all permissions
205 if ($objMod->rights_class) {
206 $objMod->insert_permissions(0, $entity);
207 $modules[$objMod->rights_class] = $objMod;
208 }
209 }
210 }
211 }
212 }
213}
214
215$db->commit();
216
217// Read permissions of group
218$permsgroupbyentity = array();
219
220$sql = "SELECT DISTINCT r.id, r.libelle, r.module, r.perms, r.subperms, r.module_position, r.family, r.family_position, gr.entity";
221$sql .= " FROM ".MAIN_DB_PREFIX."rights_def as r,";
222$sql .= " ".MAIN_DB_PREFIX."usergroup_rights as gr";
223$sql .= " WHERE gr.fk_id = r.id";
224$sql .= " AND gr.entity = ".((int) $entity);
225$sql .= " AND gr.fk_usergroup = ".((int) $object->id);
226
227dol_syslog("get user perms", LOG_DEBUG);
228$result = $db->query($sql);
229if ($result) {
230 $num = $db->num_rows($result);
231 $i = 0;
232 while ($i < $num) {
233 $obj = $db->fetch_object($result);
234 if (!isset($permsgroupbyentity[(int) $obj->entity])) {
235 $permsgroupbyentity[(int) $obj->entity] = array();
236 }
237 array_push($permsgroupbyentity[(int) $obj->entity], (int) $obj->id);
238 $i++;
239 }
240 $db->free($result);
241} else {
242 dol_print_error($db);
243}
244
245/*
246 * Part to add/remove permissions
247 */
248
249$linkback = '<a href="'.DOL_URL_ROOT.'/user/group/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
250
251dol_banner_tab($object, 'id', $linkback, $user->hasRight("user", "user", "read") || $user->admin);
252
253
254print '<div class="fichecenter">';
255print '<div class="fichehalfleft">';
256
257print '<div class="underbanner clearboth"></div>';
258print '<table class="border centpercent tableforfield">';
259
260// Name (already in dol_banner, we keep it to have the GlobalGroup picto, but we should move it in dol_banner)
261if (isModEnabled('multicompany')) {
262 print '<tr><td class="titlefield">'.$langs->trans("Name").'</td>';
263 print '<td class="valeur">'.dol_escape_htmltag($object->name);
264 if (empty($object->entity)) {
265 print img_picto($langs->trans("GlobalGroup"), 'superadmin');
266 }
267 print "</td></tr>\n";
268}
269
270// Multicompany
271if (isModEnabled('multicompany') && is_object($mc) && !getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE') && $conf->entity == 1 && $user->admin && !$user->entity) {
272 $mc->getInfo($object->entity);
273 print "<tr>".'<td class="titlefield">'.$langs->trans("Entity").'</td>';
274 print '<td class="valeur">'.dol_escape_htmltag($mc->label);
275 print "</td></tr>\n";
276}
277
278unset($object->fields['nom']); // Name already displayed in banner
279unset($object->fields['color']);
280
281// Common attributes
282$keyforbreak = '';
283include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
284
285print '<tr><td>'.$langs->trans("ColorGroup").'</td>';
286print '<td>';
287print $formother->showColor($object->color, '');
288print '</td></tr>';
289
290// Other attributes
291include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
292
293print '</table>';
294
295print '</div>';
296print '</div>';
297
298print '<div class="clearboth"></div>';
299
300print '<br>';
301
302
303if ($user->admin) {
304 $s = $langs->trans("WarningOnlyPermissionOfActivatedModules")." ".$langs->trans("YouCanEnableModulesFrom");
305 if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) {
306 $s .= '<br>';
307 $s .= img_picto($langs->trans('InfoAdmin'), 'info-circle').' ';
308 $s .= $langs->trans("YouAreUsingTheAdvancedPermissionsMode");
309 } else {
310 $s .= '<br>';
311 $s .= img_picto($langs->trans('InfoAdmin'), 'info-circle').' ';
312 $s .= $langs->trans("YouAreUsingTheSimplePermissionsMode");
313 }
314 print info_admin($s);
315
316 print '<br>';
317}
318
319$parameters = array();
320$reshook = $hookmanager->executeHooks('insertExtraHeader', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
321if ($reshook < 0) {
322 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
323}
324
325print "\n";
326print '<div class="div-table-responsive-no-min">';
327print '<table class="noborder centpercent">';
328print '<tr class="liste_titre">';
329print '<td>'.$langs->trans("Module").'</td>';
330if ($permissiontoedit) {
331 print '<td class="center nowrap">';
332 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>";
333 print '/';
334 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>";
335 print '</td>';
336} else {
337 print '<td></td>';
338}
339print '<td></td>';
340print '<td class="right nowrap" colspan="2">';
341print '<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>';
342print ' | ';
343print '<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>';
344print '</td>';
345print '</tr>'."\n";
346
347// Get list of all permissions
348$sql = "SELECT r.id, r.libelle as label, r.module, r.perms, r.subperms, r.module_position, r.bydefault, r.family, r.family_position";
349$sql .= " FROM ".MAIN_DB_PREFIX."rights_def as r";
350$sql .= " WHERE r.libelle NOT LIKE 'tou%'"; // We ignore permission "tous les tiers". Why ?
351$sql .= " AND r.entity = ".((int) $entity);
352if (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) {
353 $sql .= " AND r.perms NOT LIKE '%_advance'"; // Hide advanced perms if option is not enabled
354}
355$sql .= " ORDER BY r.family_position, r.module_position, r.module, r.id";
356
357$familyinfo = array(
358 'hr' => array('position' => '001', 'label' => $langs->trans("ModuleFamilyHr")),
359 'crm' => array('position' => '006', 'label' => $langs->trans("ModuleFamilyCrm")),
360 'srm' => array('position' => '007', 'label' => $langs->trans("ModuleFamilySrm")),
361 'financial' => array('position' => '009', 'label' => $langs->trans("ModuleFamilyFinancial")),
362 'products' => array('position' => '012', 'label' => $langs->trans("ModuleFamilyProducts")),
363 'projects' => array('position' => '015', 'label' => $langs->trans("ModuleFamilyProjects")),
364 'ecm' => array('position' => '018', 'label' => $langs->trans("ModuleFamilyECM")),
365 'technic' => array('position' => '021', 'label' => $langs->trans("ModuleFamilyTechnic")),
366 'portal' => array('position' => '040', 'label' => $langs->trans("ModuleFamilyPortal")),
367 'interface' => array('position' => '050', 'label' => $langs->trans("ModuleFamilyInterface")),
368 'base' => array('position' => '060', 'label' => $langs->trans("ModuleFamilyBase")),
369 'other' => array('position' => '100', 'label' => $langs->trans("ModuleFamilyOther")),
370);
371
372$arrayofpermission = array();
373$cookietohidegroup = (empty($_COOKIE["DOLUSER_PERMS_HIDE_GRP"]) ? '' : preg_replace('/^,/', '', $_COOKIE["DOLUSER_PERMS_HIDE_GRP"]));
374$cookietohidegrouparray = explode(',', $cookietohidegroup);
375
376$result = $db->query($sql);
377if ($result) {
378 $num = $db->num_rows($result);
379 $i = 0;
380
381 //var_dump($cookietohidegrouparray);
382
383 while ($i < $num) {
384 $obj = $db->fetch_object($result);
385
386 if (empty($obj->family)) {
387 $obj->family = 'other';
388 }
389
390 if (empty($obj->family_position)) {
391 $obj->family_position = $familyinfo[$obj->family]['position'];
392 if ($obj->module_position < 100000) {
393 $obj->module_position = intval($obj->module_position) + 100000;
394 } else {
395 $obj->module_position = intval($obj->module_position);
396 }
397 }
398
399 $obj->position = $obj->family_position.'_'.$obj->module_position.'_'.$obj->id;
400
401 $arrayofpermission[$i] = $obj;
402 $i++;
403 }
404} else {
405 dol_print_error($db);
406}
407
408$arrayofpermission = dol_sort_array($arrayofpermission, 'position');
409
410$j = 0;
411$oldmod = '';
412
413foreach ($arrayofpermission as $i => $obj) {
414 // If line is for a module that does not exist anymore (absent of includes/module), we ignore it
415 if (empty($modules[$obj->module])) {
416 $i++;
417 continue;
418 }
419
420 // Special cases
421 if (isModEnabled("reception")) {
422 // The 2 permission in fournisseur modules has been replaced by permissions into reception module
423 if ($obj->module == 'fournisseur' && $obj->perms == 'commande' && $obj->subperms == 'receptionner') {
424 $i++;
425 continue;
426 }
427 if ($obj->module == 'fournisseur' && $obj->perms == 'commande_advance' && $obj->subperms == 'check') {
428 $i++;
429 continue;
430 }
431 }
432
433 $objMod = $modules[$obj->module];
434
435 if (GETPOSTISSET('forbreakperms_'.$obj->module)) {
436 $ishidden = GETPOSTINT('forbreakperms_'.$obj->module);
437 } elseif (in_array($j, $cookietohidegrouparray)) { // If j is among list of hidden group
438 $ishidden = 1;
439 } else {
440 $ishidden = 0;
441 }
442 $isexpanded = ! $ishidden;
443 //var_dump("isexpanded=".$isexpanded);
444
445 $permsgroupbyentitypluszero = array();
446 if (!empty($permsgroupbyentity[0])) {
447 $permsgroupbyentitypluszero = array_merge($permsgroupbyentitypluszero, $permsgroupbyentity[0]);
448 }
449 if (!empty($permsgroupbyentity[$entity])) {
450 $permsgroupbyentitypluszero = array_merge($permsgroupbyentitypluszero, $permsgroupbyentity[$entity]);
451 }
452 //var_dump($permsgroupbyentitypluszero);
453
454 // Break found, it's a new module to catch
455 if (isset($obj->module) && ($oldmod != $obj->module)) {
456 $oldmod = $obj->module;
457
458 $j++;
459 if (GETPOSTISSET('forbreakperms_'.$obj->module)) {
460 $ishidden = GETPOSTINT('forbreakperms_'.$obj->module);
461 } elseif (in_array($j, $cookietohidegrouparray)) { // If j is among list of hidden group
462 $ishidden = 1;
463 } else {
464 $ishidden = 0;
465 }
466 $isexpanded = ! $ishidden;
467 //var_dump('$obj->module='.$obj->module.' isexpanded='.$isexpanded);
468
469 // Break detected, we get objMod
470 $objMod = $modules[$obj->module];
471 $picto = ($objMod->picto ? $objMod->picto : 'generic');
472
473 // Show break line
474 print '<tr class="oddeven trforbreakperms trforbreaknobg" data-hide-perms="'.$obj->module.'" data-j="'.$j.'">';
475 // Picto and label of module
476 print '<td class="maxwidthonsmartphone tdoverflowmax200 tdforbreakperms" data-hide-perms="'.dol_escape_htmltag($obj->module).'" title="'.dol_escape_htmltag($objMod->getName()).'">';
477 print '<input type="hidden" name="forbreakperms_'.$obj->module.'" id="idforbreakperms_'.$obj->module.'" css="cssforfieldishiden" data-j="'.$j.'" value="'.($isexpanded ? '0' : "1").'">';
478 print img_object('', $picto, 'class="pictoobjectwidth paddingright"').' '.$objMod->getName();
479 print '<a name="'.$objMod->getName().'"></a>';
480 print '</td>';
481
482 // Permission and tick (2 columns)
483 if ($permissiontoedit) {
484 print '<td class="tdforbreakperms tdforbreakpermsifnotempty center width50 nowraponall" data-hide-perms="'.dol_escape_htmltag($obj->module).'">';
485 print '<span class="permtohide_'.dol_escape_htmltag($obj->module).'" '.(!$isexpanded ? ' style="display:none"' : '').'>';
486 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>";
487 print ' / ';
488 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>";
489 print '</span>';
490 print '</td>';
491 print '<td class="tdforbreakperms" data-hide-perms="'.dol_escape_htmltag($obj->module).'">';
492 print '</td>';
493 } else {
494 print '<td class="tdforbreakperms" data-hide-perms="'.dol_escape_htmltag($obj->module).'"></td>';
495 print '<td class="tdforbreakperms" data-hide-perms="'.dol_escape_htmltag($obj->module).'"></td>';
496 }
497 // Description of permission (2 columns)
498 print '<td class="tdforbreakperms" data-hide-perms="'.dol_escape_htmltag($obj->module).'"></td>';
499 print '<td class="maxwidthonsmartphone right tdforbreakperms" data-hide-perms="'.dol_escape_htmltag($obj->module).'">';
500 print '<div class="switchfolderperms inline-block marginrightonly folderperms_'.dol_escape_htmltag($obj->module).'"'.($isexpanded ? ' style="display:none;"' : '').'>';
501 print img_picto('', 'folder', 'class="marginright"');
502 print '</div>';
503 print '<div class="switchfolderperms inline-block marginrightonly folderopenperms_'.dol_escape_htmltag($obj->module).'"'.(!$isexpanded ? ' style="display:none;"' : '').'>';
504 print img_picto('', 'folder-open', 'class="marginright"');
505 print '</div>';
506 print '</td>'; //Add picto + / - when open en closed
507 print '</tr>'."\n";
508 }
509
510 $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)));
511
512 print '<!-- '.$obj->module.'->'.$obj->perms.($obj->subperms ? '->'.$obj->subperms : '').' -->'."\n";
513 print '<tr class="oddeven trtohide_'.$obj->module.'"'.(!$isexpanded ? ' style="display:none"' : '').'>';
514
515
516 // Picto and label of module
517 print '<td class="maxwidthonsmartphone">';
518 print '</td>';
519
520 // Permission and tick (2 columns)
521 print '<!-- permsgroupbyentitypluszero -->';
522 // @phan-suppress-next-line PhanTypeMismatchArgumentNullableInternal
523 if (in_array($obj->id, $permsgroupbyentitypluszero)) {
524 // Own permission by group
525 if ($permissiontoedit) {
526 print '<td class="center nowrap">';
527 print '<a class="reposition" id="'.$obj->id.'" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delrights&token='.newToken().'&entity='.$entity.'&rights='.$obj->id.'&confirm=yes&updatedmodulename='.$obj->module.'">';
528 //print img_edit_remove($langs->trans("Remove"));
529 print img_picto($langs->trans("Remove"), 'switch_on');
530 print '</a>';
531 print '</td>';
532 } else {
533 print '<td></td>';
534 }
535 print '<td class="center nowrap">';
536 print img_picto($langs->trans("Active"), 'tick');
537 print '</td>';
538 } else {
539 // Do not own permission
540 if ($permissiontoedit) {
541 print '<td class="center nowrap">';
542 print '<a class="reposition addexpandedmodulesinparamlist" id="'.$obj->id.'" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=addrights&token='.newToken().'&entity='.$entity.'&rights='.$obj->id.'&confirm=yes&updatedmodulename='.$obj->module.'">';
543 //print img_edit_add($langs->trans("Add"));
544 print img_picto($langs->trans("Add"), 'switch_off');
545 print '</a>';
546 print '</td>';
547 } else {
548 print '<td></td>';
549 }
550 print '<td>';
551 print '</td>';
552 }
553
554 // Description of permission (1 or 2 columns)
555 print '<td>';
556 print $permlabel;
557 $idtouse = $obj->id;
558 if (in_array($idtouse, array(121, 122, 125, 126))) { // Force message for the 3 permission on third parties
559 $idtouse = 122;
560 }
561 if ($langs->trans("Permission".$idtouse.'b') != "Permission".$idtouse.'b') {
562 print '<br><span class="opacitymedium">'.$langs->trans("Permission".$idtouse.'b').'</span>';
563 }
564 if ($langs->trans("Permission".$obj->id.'c') != "Permission".$obj->id.'c') {
565 print '<br><span class="opacitymedium">'.$langs->trans("Permission".$obj->id.'c').'</span>';
566 }
567 if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) {
568 if (preg_match('/_advance$/', $obj->perms)) {
569 print ' <span class="opacitymedium">('.$langs->trans("AdvancedModeOnly").')</span>';
570 }
571 }
572 print '</td>';
573
574 // Permission id
575 if ($user->admin) {
576 print '<td class="right">';
577 $htmltext = $langs->trans("ID").': '.$obj->id;
578 $htmltext .= '<br>'.$langs->trans("Permission").': user->hasRight(\''.dol_escape_htmltag($obj->module).'\', \''.dol_escape_htmltag($obj->perms).'\''.($obj->subperms ? ', \''.dol_escape_htmltag($obj->subperms).'\'' : '').')';
579 print $form->textwithpicto('', $htmltext, 1, 'help', 'inline-block marginrightonly');
580 //print '<span class="opacitymedium">'.$obj->id.'</span>';
581 print '</td>';
582 } else {
583 print '<td></td>';
584 }
585
586 print '</tr>'."\n";
587
588 $i++;
589}
590
591print '</table>';
592print '</div>';
593
594print '<script>';
595print '$(".tdforbreakperms:not(.alink)").on("click", function(){
596 console.log("Click on tdforbreakperms");
597 moduletohide = $(this).data("hide-perms");
598 j = $(this).data("j");
599 if ($("#idforbreakperms_"+moduletohide).val() == 1) {
600 console.log("idforbreakperms_"+moduletohide+" has value hidden=1, so we show all lines");
601 $(".trtohide_"+moduletohide).show();
602 $(".permtoshow_"+moduletohide).hide();
603 $(".permtohide_"+moduletohide).show();
604 $(".folderperms_"+moduletohide).hide();
605 $(".folderopenperms_"+moduletohide).show();
606 $("#idforbreakperms_"+moduletohide).val("0");
607 } else if (! $(this).hasClass("tdforbreakpermsifnotempty")) {
608 console.log("idforbreakperms_"+moduletohide+" has value hidden=0, so we hide all lines");
609 $(".trtohide_"+moduletohide).hide();
610 $(".folderopenperms_"+moduletohide).hide();
611 $(".folderperms_"+moduletohide).show();
612 $(".permtoshow_"+moduletohide).show();
613 $(".permtohide_"+moduletohide).hide();
614 $("#idforbreakperms_"+moduletohide).val("1");
615 }
616
617 // Now rebuild the value for cookie
618 var hideuserperm="";
619 $(".trforbreakperms").each(function(index) {
620 //console.log( index + ": " + $( this ).data("j") + " " + $( this ).data("hide-perms") + " " + $("input[data-j="+(index+1)+"]").val());
621 if ($("input[data-j="+(index+1)+"]").val() == 1) {
622 hideuserperm=hideuserperm+","+(index+1);
623 }
624 });
625 // set cookie by js
626 date = new Date(); date.setTime(date.getTime()+(30*86400000));
627 if (hideuserperm) {
628 console.log("set cookie DOLUSER_PERMS_HIDE_GRP="+hideuserperm);
629 document.cookie = "DOLUSER_PERMS_HIDE_GRP=" + hideuserperm + "; expires=" + date.toGMTString() + "; path=/ ";
630 } else {
631 console.log("delete cookie DOLUSER_PERMS_HIDE_GRP");
632 document.cookie = "DOLUSER_PERMS_HIDE_GRP=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/ ";
633 }
634});';
635print "\n";
636
637// Button expand / collapse all
638print '$(".showallperms").on("click", function(){
639 console.log("Click on showallperms");
640
641 console.log("delete cookie DOLUSER_PERMS_HIDE_GRP from showallperms click");
642 document.cookie = "DOLUSER_PERMS_HIDE_GRP=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/ ";
643 $(".tdforbreakperms").each( function(){
644 moduletohide = $(this).data("hide-perms");
645 //console.log(moduletohide);
646 if ($("#idforbreakperms_"+moduletohide).val() != 0) {
647 $(this).trigger("click"); // emulate the click, so the cooki will be resaved
648 }
649 })
650});
651
652$(".hideallperms").on("click", function(){
653 console.log("Click on hideallperms");
654
655 $(".tdforbreakperms").each( function(){
656 moduletohide = $(this).data("hide-perms");
657 //console.log(moduletohide);
658 if ($("#idforbreakperms_"+moduletohide).val() != 1) {
659 $(this).trigger("click"); // emulate the click, so the cooki will be resaved
660 }
661 })
662});';
663print "\n";
664print '</script>';
665
666print '<style>';
667print '.switchfolderperms{
668 cursor: pointer;
669}';
670print '</style>';
671
672$parameters = array();
673$reshook = $hookmanager->executeHooks('insertExtraFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
674if ($reshook < 0) {
675 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
676}
677
678print dol_get_fiche_end();
679
680
681// End of page
682llxFooter();
683$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
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 permettant la generation de composants html autre Only common components are here.
Class to manage user groups.
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_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.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
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...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
group_prepare_head($object)
Prepare array with list of tabs.