perms.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  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. /**
  24. * \file htdocs/user/perms.php
  25. * \brief Page to set permission of a user record
  26. */
  27. if (!defined('CSRFCHECK_WITH_TOKEN')) {
  28. define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
  29. }
  30. require '../main.inc.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  34. // Load translation files required by page
  35. $langs->loadLangs(array('users', 'admin'));
  36. $id = GETPOST('id', 'int');
  37. $action = GETPOST('action', 'aZ09');
  38. $confirm = GETPOST('confirm', 'alpha');
  39. $module = GETPOST('module', 'alpha');
  40. $rights = GETPOST('rights', 'int');
  41. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'userperms'; // To manage different context of search
  42. if (!isset($id) || empty($id)) {
  43. accessforbidden();
  44. }
  45. // Define if user can read permissions
  46. $canreaduser = ($user->admin || $user->rights->user->user->lire);
  47. // Define if user can modify other users and permissions
  48. $caneditperms = ($user->admin || $user->rights->user->user->creer);
  49. // Advanced permissions
  50. if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
  51. $canreaduser = ($user->admin || ($user->rights->user->user->lire && $user->rights->user->user_advance->readperms));
  52. $caneditselfperms = ($user->id == $id && $user->rights->user->self_advance->writeperms);
  53. $caneditperms = (($caneditperms || $caneditselfperms) ? 1 : 0);
  54. }
  55. // Security check
  56. $socid = 0;
  57. if (isset($user->socid) && $user->socid > 0) {
  58. $socid = $user->socid;
  59. }
  60. $feature2 = (($socid && $user->rights->user->self->creer) ? '' : 'user');
  61. // A user can always read its own card if not advanced perms enabled, or if he has advanced perms, except for admin
  62. if ($user->id == $id && (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->user->self_advance->readperms) && empty($user->admin))) {
  63. accessforbidden();
  64. }
  65. $result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
  66. if ($user->id <> $id && !$canreaduser) {
  67. accessforbidden();
  68. }
  69. $object = new User($db);
  70. $object->fetch($id, '', '', 1);
  71. $object->getrights();
  72. $entity = $conf->entity;
  73. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  74. $hookmanager->initHooks(array('usercard', 'userperms', 'globalcard'));
  75. /*
  76. * Actions
  77. */
  78. $parameters = array('socid'=>$socid);
  79. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  80. if ($reshook < 0) {
  81. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  82. }
  83. if (empty($reshook)) {
  84. if ($action == 'addrights' && $caneditperms && $confirm == 'yes') {
  85. $edituser = new User($db);
  86. $edituser->fetch($object->id);
  87. $result = $edituser->addrights($rights, $module, '', $entity);
  88. if ($result < 0) {
  89. setEventMessages($edituser->error, $edituser->errors, 'errors');
  90. }
  91. // If we are changing our own permissions, we reload permissions and menu
  92. if ($object->id == $user->id) {
  93. $user->clearrights();
  94. $user->getrights();
  95. $menumanager->loadMenu();
  96. }
  97. $object->clearrights();
  98. $object->getrights();
  99. }
  100. if ($action == 'delrights' && $caneditperms && $confirm == 'yes') {
  101. $edituser = new User($db);
  102. $edituser->fetch($object->id);
  103. $result = $edituser->delrights($rights, $module, '', $entity);
  104. if ($result < 0) {
  105. setEventMessages($edituser->error, $edituser->errors, 'errors');
  106. }
  107. // If we are changing our own permissions, we reload permissions and menu
  108. if ($object->id == $user->id) {
  109. $user->clearrights();
  110. $user->getrights();
  111. $menumanager->loadMenu();
  112. }
  113. $object->clearrights();
  114. $object->getrights();
  115. }
  116. }
  117. /*
  118. * View
  119. */
  120. $form = new Form($db);
  121. llxHeader('', $langs->trans("Permissions"));
  122. $head = user_prepare_head($object);
  123. $title = $langs->trans("User");
  124. print dol_get_fiche_head($head, 'rights', $title, -1, 'user');
  125. $db->begin();
  126. // Search all modules with permission and reload permissions def.
  127. $modules = array();
  128. $modulesdir = dolGetModulesDirs();
  129. foreach ($modulesdir as $dir) {
  130. $handle = @opendir(dol_osencode($dir));
  131. if (is_resource($handle)) {
  132. while (($file = readdir($handle)) !== false) {
  133. if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') {
  134. $modName = substr($file, 0, dol_strlen($file) - 10);
  135. if ($modName) {
  136. include_once $dir.$file;
  137. $objMod = new $modName($db);
  138. // Load all lang files of module
  139. if (isset($objMod->langfiles) && is_array($objMod->langfiles)) {
  140. foreach ($objMod->langfiles as $domain) {
  141. $langs->load($domain);
  142. }
  143. }
  144. // Load all permissions
  145. if ($objMod->rights_class) {
  146. $ret = $objMod->insert_permissions(0, $entity);
  147. $modules[$objMod->rights_class] = $objMod;
  148. //print "modules[".$objMod->rights_class."]=$objMod;";
  149. }
  150. }
  151. }
  152. }
  153. }
  154. }
  155. $db->commit();
  156. // Read permissions of user
  157. $permsuser = array();
  158. $sql = "SELECT DISTINCT ur.fk_id";
  159. $sql .= " FROM ".MAIN_DB_PREFIX."user_rights as ur";
  160. $sql .= " WHERE ur.entity = ".((int) $entity);
  161. $sql .= " AND ur.fk_user = ".((int) $object->id);
  162. dol_syslog("get user perms", LOG_DEBUG);
  163. $result = $db->query($sql);
  164. if ($result) {
  165. $num = $db->num_rows($result);
  166. $i = 0;
  167. while ($i < $num) {
  168. $obj = $db->fetch_object($result);
  169. array_push($permsuser, $obj->fk_id);
  170. $i++;
  171. }
  172. $db->free($result);
  173. } else {
  174. dol_print_error($db);
  175. }
  176. // Lecture des droits groupes
  177. $permsgroupbyentity = array();
  178. $sql = "SELECT DISTINCT gr.fk_id, gu.entity";
  179. $sql .= " FROM ".MAIN_DB_PREFIX."usergroup_rights as gr,";
  180. $sql .= " ".MAIN_DB_PREFIX."usergroup_user as gu";
  181. $sql .= " WHERE gr.entity = ".((int) $entity);
  182. $sql .= " AND gr.fk_usergroup = gu.fk_usergroup";
  183. $sql .= " AND gu.fk_user = ".((int) $object->id);
  184. dol_syslog("get user perms", LOG_DEBUG);
  185. $result = $db->query($sql);
  186. if ($result) {
  187. $num = $db->num_rows($result);
  188. $i = 0;
  189. while ($i < $num) {
  190. $obj = $db->fetch_object($result);
  191. if (!isset($permsgroupbyentity[$obj->entity])) {
  192. $permsgroupbyentity[$obj->entity] = array();
  193. }
  194. array_push($permsgroupbyentity[$obj->entity], $obj->fk_id);
  195. $i++;
  196. }
  197. $db->free($result);
  198. } else {
  199. dol_print_error($db);
  200. }
  201. /*
  202. * Part to add/remove permissions
  203. */
  204. $linkback = '';
  205. if ($user->rights->user->user->lire || $user->admin) {
  206. $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  207. }
  208. $morehtmlref = '<a href="'.DOL_URL_ROOT.'/user/vcard.php?id='.$object->id.'" class="refid">';
  209. $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
  210. $morehtmlref .= '</a>';
  211. dol_banner_tab($object, 'id', $linkback, $user->rights->user->user->lire || $user->admin, 'rowid', 'ref', $morehtmlref);
  212. print '<div class="fichecenter">';
  213. print '<div class="underbanner clearboth"></div>';
  214. print '<table class="border centpercent tableforfield">';
  215. // Login
  216. print '<tr><td class="titlefield">'.$langs->trans("Login").'</td>';
  217. if (!empty($object->ldap_sid) && $object->statut == 0) {
  218. print '<td class="error">';
  219. print $langs->trans("LoginAccountDisableInDolibarr");
  220. print '</td>';
  221. } else {
  222. print '<td>';
  223. $addadmin = '';
  224. if (property_exists($object, 'admin')) {
  225. if (!empty($conf->multicompany->enabled) && !empty($object->admin) && empty($object->entity)) {
  226. $addadmin .= img_picto($langs->trans("SuperAdministratorDesc"), "redstar", 'class="paddingleft"');
  227. } elseif (!empty($object->admin)) {
  228. $addadmin .= img_picto($langs->trans("AdministratorDesc"), "star", 'class="paddingleft"');
  229. }
  230. }
  231. print showValueWithClipboardCPButton($object->login).$addadmin;
  232. print '</td>';
  233. }
  234. print '</tr>'."\n";
  235. print '</table>';
  236. print '</div>';
  237. print '<br>';
  238. if ($user->admin) {
  239. print info_admin($langs->trans("WarningOnlyPermissionOfActivatedModules"));
  240. }
  241. // If edited user is an extern user, we show warning for external users
  242. if (! empty($object->socid)) {
  243. print info_admin(showModulesExludedForExternal($modules))."\n";
  244. }
  245. $parameters = array('permsgroupbyentity'=>$permsgroupbyentity);
  246. $reshook = $hookmanager->executeHooks('insertExtraHeader', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  247. if ($reshook < 0) {
  248. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  249. }
  250. print "\n";
  251. print '<div class="div-table-responsive-no-min">';
  252. print '<table class="noborder centpercent">';
  253. print '<tr class="liste_titre">';
  254. print '<td>'.$langs->trans("Module").'</td>';
  255. if ($caneditperms) {
  256. print '<td class="center nowrap">';
  257. print '<a class="reposition commonlink" 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>";
  258. print ' / ';
  259. print '<a class="reposition commonlink" 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>";
  260. print '</td>';
  261. }
  262. print '<td class="center" width="24">&nbsp;</td>';
  263. print '<td>'.$langs->trans("Permissions").'</td>';
  264. if ($user->admin) {
  265. print '<td class="right"></td>';
  266. }
  267. print '</tr>'."\n";
  268. // Fix bad value for module_position in table
  269. // ------------------------------------------
  270. $sql = "SELECT r.id, r.libelle as label, r.module, r.perms, r.subperms, r.module_position, r.bydefault";
  271. $sql .= " FROM ".MAIN_DB_PREFIX."rights_def as r";
  272. $sql .= " WHERE r.libelle NOT LIKE 'tou%'"; // On ignore droits "tous"
  273. $sql .= " AND r.entity = ".((int) $entity);
  274. $sql .= " ORDER BY r.family_position, r.module_position, r.module, r.id";
  275. $result = $db->query($sql);
  276. if ($result) {
  277. $num = $db->num_rows($result);
  278. $i = 0;
  279. $oldmod = '';
  280. while ($i < $num) {
  281. $obj = $db->fetch_object($result);
  282. // If line is for a module that does not exist anymore (absent of includes/module), we ignore it
  283. if (!isset($obj->module) || empty($modules[$obj->module])) {
  284. $i++;
  285. continue;
  286. }
  287. // Special cases
  288. if (!empty($conf->reception->enabled)) {
  289. // The 2 permissions in fournisseur modules are replaced by permissions into reception module
  290. if ($obj->module == 'fournisseur' && $obj->perms == 'commande' && $obj->subperms == 'receptionner') {
  291. $i++;
  292. continue;
  293. }
  294. if ($obj->module == 'fournisseur' && $obj->perms == 'commande_advance' && $obj->subperms == 'check') {
  295. $i++;
  296. continue;
  297. }
  298. }
  299. $objMod = $modules[$obj->module];
  300. // Save field module_position in database if value is wrong
  301. if (empty($obj->module_position) || (is_object($objMod) && $objMod->isCoreOrExternalModule() == 'external' && $obj->module_position < 100000)) {
  302. if (is_object($modules[$obj->module]) && ($modules[$obj->module]->module_position > 0)) {
  303. // TODO Define familyposition
  304. //$familyposition = $modules[$obj->module]->family_position;
  305. $familyposition = 0;
  306. $newmoduleposition = $modules[$obj->module]->module_position;
  307. // Correct $newmoduleposition position for external modules
  308. $objMod = $modules[$obj->module];
  309. if (is_object($objMod) && $objMod->isCoreOrExternalModule() == 'external' && $newmoduleposition < 100000) {
  310. $newmoduleposition += 100000;
  311. }
  312. $sqlupdate = 'UPDATE '.MAIN_DB_PREFIX."rights_def SET module_position = ".((int) $newmoduleposition).",";
  313. $sqlupdate .= " family_position = ".((int) $familyposition);
  314. $sqlupdate .= " WHERE module_position = ".((int) $obj->module_position)." AND module = '".$db->escape($obj->module)."'";
  315. $db->query($sqlupdate);
  316. }
  317. }
  318. }
  319. }
  320. //print "xx".$conf->global->MAIN_USE_ADVANCED_PERMS;
  321. $sql = "SELECT r.id, r.libelle as label, r.module, r.perms, r.subperms, r.module_position, r.bydefault";
  322. $sql .= " FROM ".MAIN_DB_PREFIX."rights_def as r";
  323. $sql .= " WHERE r.libelle NOT LIKE 'tou%'"; // On ignore droits "tous"
  324. $sql .= " AND r.entity = ".((int) $entity);
  325. if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
  326. $sql .= " AND r.perms NOT LIKE '%_advance'"; // Hide advanced perms if option is not enabled
  327. }
  328. $sql .= " ORDER BY r.family_position, r.module_position, r.module, r.id";
  329. $result = $db->query($sql);
  330. if ($result) {
  331. $num = $db->num_rows($result);
  332. $i = 0;
  333. $oldmod = '';
  334. while ($i < $num) {
  335. $obj = $db->fetch_object($result);
  336. // If line is for a module that does not exist anymore (absent of includes/module), we ignore it
  337. if (empty($modules[$obj->module])) {
  338. $i++;
  339. continue;
  340. }
  341. // Special cases
  342. if (!empty($conf->reception->enabled)) {
  343. // The 2 permission in fournisseur modules has been replaced by permissions into reception module
  344. if ($obj->module == 'fournisseur' && $obj->perms == 'commande' && $obj->subperms == 'receptionner') {
  345. $i++;
  346. continue;
  347. }
  348. if ($obj->module == 'fournisseur' && $obj->perms == 'commande_advance' && $obj->subperms == 'check') {
  349. $i++;
  350. continue;
  351. }
  352. }
  353. $objMod = $modules[$obj->module];
  354. // Save field module_position in database if value is wrong
  355. /*
  356. if (empty($obj->module_position) || (is_object($objMod) && $objMod->isCoreOrExternalModule() == 'external' && $obj->module_position < 100000)) {
  357. if (is_object($modules[$obj->module]) && ($modules[$obj->module]->module_position > 0)) {
  358. // TODO Define familyposition
  359. //$familyposition = $modules[$obj->module]->family_position;
  360. $familyposition = 0;
  361. $newmoduleposition = $modules[$obj->module]->module_position;
  362. // Correct $newmoduleposition position for external modules
  363. $objMod = $modules[$obj->module];
  364. if (is_object($objMod) && $objMod->isCoreOrExternalModule() == 'external' && $newmoduleposition < 100000) {
  365. $newmoduleposition += 100000;
  366. }
  367. $sqlupdate = 'UPDATE '.MAIN_DB_PREFIX."rights_def SET module_position = ".((int) $newmoduleposition).",";
  368. $sqlupdate .= " family_position = ".((int) $familyposition);
  369. $sqlupdate .= " WHERE module_position = ".((int) $obj->module_position)." AND module = '".$db->escape($obj->module)."'";
  370. $db->query($sqlupdate);
  371. }
  372. }
  373. */
  374. // Break found, it's a new module to catch
  375. if (isset($obj->module) && ($oldmod <> $obj->module)) {
  376. $oldmod = $obj->module;
  377. // Break detected, we get objMod
  378. $objMod = $modules[$obj->module];
  379. $picto = ($objMod->picto ? $objMod->picto : 'generic');
  380. // Show break line
  381. print '<tr class="oddeven trforbreak">';
  382. print '<td class="maxwidthonsmartphone tdoverflowonsmartphone">';
  383. print img_object('', $picto, 'class="pictoobjectwidth paddingright"').' '.$objMod->getName();
  384. print '<a name="'.$objMod->getName().'"></a>';
  385. print '</td>';
  386. if (($caneditperms && empty($objMod->rights_admin_allowed)) || empty($object->admin)) {
  387. if ($caneditperms) {
  388. print '<td class="center nowrap">';
  389. print '<a class="reposition" 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">'.$langs->trans("All")."</a>";
  390. print ' / ';
  391. print '<a class="reposition" 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">'.$langs->trans("None")."</a>";
  392. print '</td>';
  393. }
  394. print '<td>&nbsp;</td>';
  395. } else {
  396. if ($caneditperms) {
  397. print '<td>&nbsp;</td>';
  398. }
  399. print '<td>&nbsp;</td>';
  400. }
  401. print '<td>&nbsp;</td>';
  402. // Permission id
  403. if ($user->admin) {
  404. print '<td class="right"></td>';
  405. }
  406. print '</tr>'."\n";
  407. }
  408. print '<!-- '.$obj->module.'->'.$obj->perms.($obj->subperms ? '->'.$obj->subperms : '').' -->'."\n";
  409. print '<tr class="oddeven">';
  410. // Picto and label of module
  411. print '<td class="maxwidthonsmartphone tdoverflowonsmartphone">';
  412. //print img_object('', $picto, 'class="inline-block pictoobjectwidth"').' '.$objMod->getName();
  413. print '</td>';
  414. // Permission and tick
  415. if (!empty($object->admin) && !empty($objMod->rights_admin_allowed)) { // Permission granted because admin
  416. if ($caneditperms) {
  417. print '<td class="center">'.img_picto($langs->trans("Administrator"), 'star').'</td>';
  418. }
  419. print '<td class="center nowrap">';
  420. print img_picto($langs->trans("Active"), 'tick');
  421. print '</td>';
  422. } elseif (in_array($obj->id, $permsuser)) { // Permission granted by user
  423. if ($caneditperms) {
  424. print '<td class="center"><a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delrights&token='.newToken().'&entity='.$entity.'&rights='.$obj->id.'&confirm=yes">';
  425. //print img_edit_remove($langs->trans("Remove"));
  426. print img_picto($langs->trans("Remove"), 'switch_on');
  427. print '</a></td>';
  428. }
  429. print '<td class="center nowrap">';
  430. print img_picto($langs->trans("Active"), 'tick');
  431. print '</td>';
  432. } elseif (isset($permsgroupbyentity[$entity]) && is_array($permsgroupbyentity[$entity])) {
  433. if (in_array($obj->id, $permsgroupbyentity[$entity])) { // Permission granted by group
  434. if ($caneditperms) {
  435. print '<td class="center">';
  436. print $form->textwithtooltip($langs->trans("Inherited"), $langs->trans("PermissionInheritedFromAGroup"));
  437. print '</td>';
  438. }
  439. print '<td class="center nowrap">';
  440. print img_picto($langs->trans("Active"), 'tick');
  441. print '</td>';
  442. } else {
  443. // Do not own permission
  444. if ($caneditperms) {
  445. print '<td class="center"><a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=addrights&entity='.$entity.'&rights='.$obj->id.'&confirm=yes&token='.newToken().'">';
  446. //print img_edit_add($langs->trans("Add"));
  447. print img_picto($langs->trans("Add"), 'switch_off');
  448. print '</a></td>';
  449. }
  450. print '<td>&nbsp;</td>';
  451. }
  452. } else {
  453. // Do not own permission
  454. if ($caneditperms) {
  455. print '<td class="center"><a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=addrights&entity='.$entity.'&rights='.$obj->id.'&confirm=yes&token='.newToken().'">';
  456. //print img_edit_add($langs->trans("Add"));
  457. print img_picto($langs->trans("Add"), 'switch_off');
  458. print '</a></td>';
  459. }
  460. print '<td>&nbsp;</td>';
  461. }
  462. // Description of permission
  463. $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)));
  464. print '<td>';
  465. print $permlabel;
  466. if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
  467. if (preg_match('/_advance$/', $obj->perms)) {
  468. print ' <span class="opacitymedium">('.$langs->trans("AdvancedModeOnly").')</span>';
  469. }
  470. }
  471. print '</td>';
  472. // Permission id
  473. if ($user->admin) {
  474. print '<td class="right">';
  475. $htmltext = $langs->trans("ID").': '.$obj->id;
  476. $htmltext .= '<br>'.$langs->trans("Permission").': user->rights->'.$obj->module.'->'.$obj->perms.($obj->subperms ? '->'.$obj->subperms : '');
  477. print $form->textwithpicto('', $htmltext);
  478. //print '<span class="opacitymedium">'.$obj->id.'</span>';
  479. print '</td>';
  480. }
  481. print '</tr>'."\n";
  482. $i++;
  483. }
  484. } else {
  485. dol_print_error($db);
  486. }
  487. print '</table>';
  488. print '</div>';
  489. $parameters = array();
  490. $reshook = $hookmanager->executeHooks('insertExtraFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  491. if ($reshook < 0) {
  492. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  493. }
  494. print dol_get_fiche_end();
  495. // End of page
  496. llxFooter();
  497. $db->close();