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