perms.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/user/group/perms.php
  24. * \brief Page to set permissions of a user group record
  25. */
  26. if (!defined('CSRFCHECK_WITH_TOKEN')) {
  27. define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
  28. }
  29. // Load Dolibarr environment
  30. require '../../main.inc.php';
  31. require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  35. // Load translation files required by page
  36. $langs->loadLangs(array('users', 'admin'));
  37. $id = GETPOST('id', 'int');
  38. $action = GETPOST('action', 'aZ09');
  39. $confirm = GETPOST('confirm', 'alpha');
  40. $module = GETPOST('module', 'alpha');
  41. $rights = GETPOST('rights', 'int');
  42. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'groupperms'; // To manage different context of search
  43. if (!isset($id) || empty($id)) {
  44. accessforbidden();
  45. }
  46. // Define if user can read permissions
  47. $canreadperms = ($user->admin || $user->hasRight("user", "user", "read"));
  48. // Define if user can modify group permissions
  49. $caneditperms = ($user->admin || $user->hasRight("user", "user", "write"));
  50. // Advanced permissions
  51. $advancedpermsactive = false;
  52. if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) {
  53. $advancedpermsactive = true;
  54. $canreadperms = ($user->admin || ($user->hasRight("user", "group_advance", "read") && $user->hasRight("user", "group_advance", "readperms")));
  55. $caneditperms = ($user->admin || $user->hasRight("user", "group_advance", "write"));
  56. }
  57. // Security check
  58. //$result = restrictedArea($user, 'user', $id, 'usergroup', '');
  59. if (!$canreadperms) {
  60. accessforbidden();
  61. }
  62. $object = new UserGroup($db);
  63. $object->fetch($id);
  64. $object->getrights();
  65. $entity = $conf->entity;
  66. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  67. $hookmanager->initHooks(array('groupperms', 'globalcard'));
  68. /**
  69. * Actions
  70. */
  71. $parameters = array();
  72. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  73. if ($reshook < 0) {
  74. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  75. }
  76. if (empty($reshook)) {
  77. if ($action == 'addrights' && $caneditperms) {
  78. $editgroup = new UserGroup($db);
  79. $result = $editgroup->fetch($object->id);
  80. if ($result > 0) {
  81. $result = $editgroup->addrights($rights, $module, '', $entity);
  82. if ($result < 0) {
  83. setEventMessages($editgroup->error, $editgroup->errors, 'errors');
  84. }
  85. } else {
  86. dol_print_error($db);
  87. }
  88. $user->clearrights();
  89. $user->getrights();
  90. }
  91. if ($action == 'delrights' && $caneditperms) {
  92. $editgroup = new UserGroup($db);
  93. $result = $editgroup->fetch($id);
  94. if ($result > 0) {
  95. $result = $editgroup->delrights($rights, $module, '', $entity);
  96. if ($result < 0) {
  97. setEventMessages($editgroup->error, $editgroup->errors, 'errors');
  98. }
  99. } else {
  100. dol_print_error($db);
  101. }
  102. $user->clearrights();
  103. $user->getrights();
  104. }
  105. }
  106. /*
  107. * View
  108. */
  109. $form = new Form($db);
  110. $title = $object->name." - ".$langs->trans('Permissions');
  111. $help_url = '';
  112. llxHeader('', $title, $help_url);
  113. if ($object->id > 0) {
  114. $head = group_prepare_head($object);
  115. $title = $langs->trans("Group");
  116. print dol_get_fiche_head($head, 'rights', $title, -1, 'group');
  117. // Charge les modules soumis a permissions
  118. $modules = array();
  119. $modulesdir = dolGetModulesDirs();
  120. $db->begin();
  121. foreach ($modulesdir as $dir) {
  122. $handle = @opendir(dol_osencode($dir));
  123. if (is_resource($handle)) {
  124. while (($file = readdir($handle)) !== false) {
  125. if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') {
  126. $modName = substr($file, 0, dol_strlen($file) - 10);
  127. if ($modName) {
  128. include_once $dir.$file;
  129. $objMod = new $modName($db);
  130. // Load all lang files of module
  131. if (isset($objMod->langfiles) && is_array($objMod->langfiles)) {
  132. foreach ($objMod->langfiles as $domain) {
  133. $langs->load($domain);
  134. }
  135. }
  136. // Load all permissions
  137. if ($objMod->rights_class) {
  138. $ret = $objMod->insert_permissions(0, $entity);
  139. $modules[$objMod->rights_class] = $objMod;
  140. }
  141. }
  142. }
  143. }
  144. }
  145. }
  146. $db->commit();
  147. // Read permissions of group
  148. $permsgroupbyentity = array();
  149. $sql = "SELECT DISTINCT r.id, r.libelle, r.module, gr.entity";
  150. $sql .= " FROM ".MAIN_DB_PREFIX."rights_def as r,";
  151. $sql .= " ".MAIN_DB_PREFIX."usergroup_rights as gr";
  152. $sql .= " WHERE gr.fk_id = r.id";
  153. $sql .= " AND gr.entity = ".((int) $entity);
  154. $sql .= " AND gr.fk_usergroup = ".((int) $object->id);
  155. dol_syslog("get user perms", LOG_DEBUG);
  156. $result = $db->query($sql);
  157. if ($result) {
  158. $num = $db->num_rows($result);
  159. $i = 0;
  160. while ($i < $num) {
  161. $obj = $db->fetch_object($result);
  162. if (!isset($permsgroupbyentity[$obj->entity])) {
  163. $permsgroupbyentity[$obj->entity] = array();
  164. }
  165. array_push($permsgroupbyentity[$obj->entity], $obj->id);
  166. $i++;
  167. }
  168. $db->free($result);
  169. } else {
  170. dol_print_error($db);
  171. }
  172. /*
  173. * Part to add/remove permissions
  174. */
  175. $linkback = '<a href="'.DOL_URL_ROOT.'/user/group/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  176. dol_banner_tab($object, 'id', $linkback, $user->hasRight("user", "user", "read") || $user->admin);
  177. print '<div class="fichecenter">';
  178. print '<div class="fichehalfleft">';
  179. print '<div class="underbanner clearboth"></div>';
  180. print '<table class="border centpercent tableforfield">';
  181. // Name (already in dol_banner, we keep it to have the GlobalGroup picto, but we should move it in dol_banner)
  182. if (!empty($conf->mutlicompany->enabled)) {
  183. print '<tr><td class="titlefield">'.$langs->trans("Name").'</td>';
  184. print '<td class="valeur">'.dol_escape_htmltag($object->name);
  185. if (empty($object->entity)) {
  186. print img_picto($langs->trans("GlobalGroup"), 'redstar');
  187. }
  188. print "</td></tr>\n";
  189. }
  190. // Multicompany
  191. if (isModEnabled('multicompany') && is_object($mc) && !getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE') && $conf->entity == 1 && $user->admin && !$user->entity) {
  192. $mc->getInfo($object->entity);
  193. print "<tr>".'<td class="titlefield">'.$langs->trans("Entity").'</td>';
  194. print '<td class="valeur">'.dol_escape_htmltag($mc->label);
  195. print "</td></tr>\n";
  196. }
  197. unset($object->fields['nom']); // Name already displayed in banner
  198. // Common attributes
  199. $keyforbreak = '';
  200. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
  201. // Other attributes
  202. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  203. print '</table>';
  204. print '</div>';
  205. print '</div>';
  206. print '<div class="clearboth"></div>';
  207. print '<br>';
  208. if ($user->admin) {
  209. print info_admin($langs->trans("WarningOnlyPermissionOfActivatedModules"));
  210. }
  211. $parameters = array();
  212. $reshook = $hookmanager->executeHooks('insertExtraHeader', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  213. if ($reshook < 0) {
  214. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  215. }
  216. print "\n";
  217. print '<div class="div-table-responsive-no-min">';
  218. print '<table class="noborder centpercent">';
  219. print '<tr class="liste_titre">';
  220. print '<td>'.$langs->trans("Module").'</td>';
  221. if ($caneditperms) {
  222. print '<td class="center nowrap">';
  223. 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>";
  224. print '/';
  225. 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>";
  226. print '</td>';
  227. } else {
  228. print '<td></td>';
  229. }
  230. print '<td class="center" width="24"></td>';
  231. //print '<td>'.$langs->trans("Permissions").'</td>';
  232. print '<td class="center"></td>';
  233. print '<td class="right nowrap">';
  234. 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>';
  235. print ' | ';
  236. 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>';
  237. print '</td>';
  238. print '</tr>'."\n";
  239. $sql = "SELECT r.id, r.libelle as label, r.module, r.perms, r.subperms, r.module_position, r.bydefault";
  240. $sql .= " FROM ".MAIN_DB_PREFIX."rights_def as r";
  241. $sql .= " WHERE r.libelle NOT LIKE 'tou%'"; // On ignore droits "tous"
  242. $sql .= " AND r.entity = ".((int) $entity);
  243. if (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) {
  244. $sql .= " AND r.perms NOT LIKE '%_advance'"; // Hide advanced perms if option is disable
  245. }
  246. $sql .= " ORDER BY r.family_position, r.module_position, r.module, r.id";
  247. $result = $db->query($sql);
  248. if ($result) {
  249. $num = $db->num_rows($result);
  250. $i = 0;$j = 0;
  251. $oldmod = '';
  252. $cookietohidegroup = (empty($_COOKIE["DOLUSER_PERMS_HIDE_GRP"]) ? '' : preg_replace('/^,/', '', $_COOKIE["DOLUSER_PERMS_HIDE_GRP"]));
  253. $cookietohidegrouparray = explode(',', $cookietohidegroup);
  254. while ($i < $num) {
  255. $obj = $db->fetch_object($result);
  256. // If line is for a module that does not exist anymore (absent of includes/module), we ignore it
  257. if (empty($modules[$obj->module])) {
  258. $i++;
  259. continue;
  260. }
  261. $objMod = $modules[$obj->module];
  262. if (GETPOSTISSET('forbreakperms_'.$obj->module)) {
  263. $ishidden = GETPOST('forbreakperms_'.$obj->module, 'int');
  264. } elseif (in_array($j, $cookietohidegrouparray)) { // If j is among list of hidden group
  265. $ishidden = 1;
  266. } else {
  267. $ishidden = 0;
  268. }
  269. $isexpanded = ! $ishidden;
  270. // Break found, it's a new module to catch
  271. if (isset($obj->module) && ($oldmod <> $obj->module)) {
  272. $oldmod = $obj->module;
  273. $j++;
  274. if (GETPOSTISSET('forbreakperms_'.$obj->module)) {
  275. $ishidden = GETPOST('forbreakperms_'.$obj->module, 'int');
  276. } elseif (in_array($j, $cookietohidegrouparray)) { // If j is among list of hidden group
  277. $ishidden = 1;
  278. } else {
  279. $ishidden = 0;
  280. }
  281. $isexpanded = ! $ishidden;
  282. // Break detected, we get objMod
  283. $objMod = $modules[$obj->module];
  284. $picto = ($objMod->picto ? $objMod->picto : 'generic');
  285. // Show break line
  286. print '<tr class="oddeven trforbreakperms" data-hide-perms="'.$obj->module.'" data-j="'.$j.'">';
  287. // Picto and label of module
  288. print '<td class="maxwidthonsmartphone tdoverflowonsmartphone tdforbreakperms" data-hide-perms="'.$obj->module.'">';
  289. print img_object('', $picto, 'class="pictoobjectwidth paddingright"').' '.$objMod->getName();
  290. print '<a name="'.$objMod->getName().'"></a>';
  291. print '</td>';
  292. // Permission and tick (2 columns)
  293. if ($caneditperms) {
  294. print '<td class="center wraponsmartphone">';
  295. print '<span class="permtohide_'.$obj->module.'" '.(!$isexpanded ? ' style="display:none"' : '').'>';
  296. 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>";
  297. print ' / ';
  298. 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>";
  299. print '</span>';
  300. print '</td>';
  301. print '<td class="tdforbreakperms" data-hide-perms="'.$obj->module.'">';
  302. print '</td>';
  303. } else {
  304. print '<td class="tdforbreakperms" data-hide-perms="'.$obj->module.'"></td>';
  305. print '<td class="tdforbreakperms" data-hide-perms="'.$obj->module.'"></td>';
  306. }
  307. // Description of permission (2 columns)
  308. print '<td class="tdforbreakperms" data-hide-perms="'.$obj->module.'"></td>';
  309. print '<td class="maxwidthonsmartphone right tdforbreakperms" data-hide-perms="'.$obj->module.'">';
  310. print '<div class="switchfolderperms folderperms_'.$obj->module.'"'.($isexpanded ? ' style="display:none;"' : '').'>';
  311. print img_picto('', 'folder', 'class="marginright"');
  312. print '</div>';
  313. print '<div class="switchfolderperms folderopenperms_'.$obj->module.'"'.(!$isexpanded ? ' style="display:none;"' : '').'>';
  314. print img_picto('', 'folder-open', 'class="marginright"');
  315. print '</div>';
  316. print '</td>'; //Add picto + / - when open en closed
  317. print '</tr>'."\n";
  318. }
  319. print '<!-- '.$obj->module.'->'.$obj->perms.($obj->subperms ? '->'.$obj->subperms : '').' -->'."\n";
  320. print '<tr class="oddeven trtohide_'.$obj->module.'"'.(!$isexpanded ? ' style="display:none"' : '').'>';
  321. // Picto and label of module
  322. print '<td class="maxwidthonsmartphone tdoverflowonsmartphone">';
  323. print '<input type="hidden" name="forbreakperms_'.$obj->module.'" id="idforbreakperms_'.$obj->module.'" css="cssforfieldishiden" data-j="'.$j.'" value="'.($isexpanded ? '0' : "1").'">';
  324. //print img_object('', $picto, 'class="inline-block pictoobjectwidth"').' '.$objMod->getName();
  325. print '</td>';
  326. // Permission and tick (2 columns)
  327. if (!empty($permsgroupbyentity[$entity]) && is_array($permsgroupbyentity[$entity])) {
  328. if (in_array($obj->id, $permsgroupbyentity[$entity])) {
  329. // Own permission by group
  330. if ($caneditperms) {
  331. print '<td class="center"><a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delrights&token='.newToken().'&entity='.$entity.'&rights='.$obj->id.'&confirm=yes">';
  332. //print img_edit_remove($langs->trans("Remove"));
  333. print img_picto($langs->trans("Remove"), 'switch_on');
  334. print '</a></td>';
  335. }
  336. print '<td class="center nowrap">';
  337. print img_picto($langs->trans("Active"), 'tick');
  338. print '</td>';
  339. } else {
  340. // Do not own permission
  341. if ($caneditperms) {
  342. print '<td class="center"><a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=addrights&token='.newToken().'&entity='.$entity.'&rights='.$obj->id.'&confirm=yes">';
  343. //print img_edit_add($langs->trans("Add"));
  344. print img_picto($langs->trans("Add"), 'switch_off');
  345. print '</a></td>';
  346. }
  347. print '<td>&nbsp;</td>';
  348. }
  349. } else {
  350. // Do not own permission
  351. if ($caneditperms) {
  352. 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().'">';
  353. //print img_edit_add($langs->trans("Add"));
  354. print img_picto($langs->trans("Add"), 'switch_off');
  355. print '</a></td>';
  356. } else {
  357. print '<td>&nbsp;</td>';
  358. }
  359. print '<td>&nbsp;</td>';
  360. }
  361. // Description of permission (2 columns)
  362. $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)));
  363. print '<td>';
  364. print $permlabel;
  365. if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) {
  366. if (preg_match('/_advance$/', $obj->perms)) {
  367. print ' <span class="opacitymedium">('.$langs->trans("AdvancedModeOnly").')</span>';
  368. }
  369. }
  370. print '</td>';
  371. // Permission id
  372. if ($user->admin) {
  373. print '<td class="right">';
  374. $htmltext = $langs->trans("ID").': '.$obj->id;
  375. $htmltext .= '<br>'.$langs->trans("Permission").': user->rights->'.$obj->module.'->'.$obj->perms.($obj->subperms ? '->'.$obj->subperms : '');
  376. print $form->textwithpicto('', $htmltext);
  377. //print '<span class="opacitymedium">'.$obj->id.'</span>';
  378. print '</td>';
  379. } else {
  380. print '<td>&nbsp;</td>';
  381. }
  382. print '</tr>'."\n";
  383. $i++;
  384. }
  385. }
  386. print '</table>';
  387. print '</div>';
  388. print '<script>';
  389. print '$(".tdforbreakperms:not(.alink)").on("click", function(){
  390. console.log("Click on tdforbreakperms");
  391. moduletohide = $(this).data("hide-perms");
  392. j = $(this).data("j");
  393. if ($("#idforbreakperms_"+moduletohide).val() == 1) {
  394. console.log("idforbreakperms_"+moduletohide+" has value hidden=1");
  395. $(".trtohide_"+moduletohide).show();
  396. $(".permtoshow_"+moduletohide).hide();
  397. $(".permtohide_"+moduletohide).show();
  398. $(".folderperms_"+moduletohide).hide();
  399. $(".folderopenperms_"+moduletohide).show();
  400. $("#idforbreakperms_"+moduletohide).val("0");
  401. } else {
  402. console.log("idforbreakperms_"+moduletohide+" has value hidden=0");
  403. $(".trtohide_"+moduletohide).hide();
  404. $(".folderopenperms_"+moduletohide).hide();
  405. $(".folderperms_"+moduletohide).show();
  406. $(".permtoshow_"+moduletohide).show();
  407. $(".permtohide_"+moduletohide).hide();
  408. $("#idforbreakperms_"+moduletohide).val("1");
  409. }
  410. // Now rebuild the value for cookie
  411. var hideuserperm="";
  412. $(".trforbreakperms").each(function(index) {
  413. //console.log( index + ": " + $( this ).data("j") + " " + $( this ).data("hide-perms") + " " + $("input[data-j="+(index+1)+"]").val());
  414. if ($("input[data-j="+(index+1)+"]").val() == 1) {
  415. hideuserperm=hideuserperm+","+(index+1);
  416. }
  417. });
  418. // set cookie by js
  419. date = new Date(); date.setTime(date.getTime()+(30*86400000));
  420. if (hideuserperm) {
  421. console.log("set cookie DOLUSER_PERMS_HIDE_GRP="+hideuserperm);
  422. document.cookie = "DOLUSER_PERMS_HIDE_GRP=" + hideuserperm + "; expires=" + date.toGMTString() + "; path=/ ";
  423. } else {
  424. console.log("delete cookie DOLUSER_PERMS_HIDE_GRP");
  425. document.cookie = "DOLUSER_PERMS_HIDE_GRP=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/ ";
  426. }
  427. });';
  428. // Button expand / collapse all
  429. print '$(".showallperms").on("click", function(){
  430. console.log("Click on showallperms");
  431. console.log("delete cookie DOLUSER_PERMS_HIDE_GRP from showallperms click");
  432. document.cookie = "DOLUSER_PERMS_HIDE_GRP=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/ ";
  433. $(".tdforbreakperms").each( function(){
  434. moduletohide = $(this).data("hide-perms");
  435. //console.log(moduletohide);
  436. if ($("#idforbreakperms_"+moduletohide).val() != 0) {
  437. $(this).trigger("click"); // emulate the click, so the cooki will be resaved
  438. }
  439. })
  440. });
  441. $(".hideallperms").on("click", function(){
  442. console.log("Click on hideallperms");
  443. $(".tdforbreakperms").each( function(){
  444. moduletohide = $(this).data("hide-perms");
  445. //console.log(moduletohide);
  446. if ($("#idforbreakperms_"+moduletohide).val() != 1) {
  447. $(this).trigger("click"); // emulate the click, so the cooki will be resaved
  448. }
  449. })
  450. });';
  451. print "\n";
  452. print '</script>';
  453. print '<style>';
  454. print '.switchfolderperms{
  455. cursor: pointer;
  456. }';
  457. print '</style>';
  458. print '</div>';
  459. $parameters = array();
  460. $reshook = $hookmanager->executeHooks('insertExtraFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  461. if ($reshook < 0) {
  462. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  463. }
  464. print dol_get_fiche_end();
  465. }
  466. // End of page
  467. llxFooter();
  468. $db->close();