perms.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  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. // Load Dolibarr environment
  31. require '../main.inc.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. $updatedmodulename = GETPOST('updatedmodulename', 'alpha');
  43. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'userperms'; // To manage different context of search
  44. if (!isset($id) || empty($id)) {
  45. accessforbidden();
  46. }
  47. // Define if user can read permissions
  48. $canreaduser = ($user->admin || $user->hasRight("user", "user", "read"));
  49. // Define if user can modify other users and permissions
  50. $caneditperms = ($user->admin || $user->hasRight("user", "user", "write"));
  51. // Advanced permissions
  52. if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
  53. $canreaduser = ($user->admin || ($user->hasRight("user", "user", "read") && $user->hasRight("user", "user_advance", "readperms")));
  54. $caneditselfperms = ($user->id == $id && $user->hasRight("user", "self_advance", "writeperms"));
  55. $caneditperms = (($caneditperms || $caneditselfperms) ? 1 : 0);
  56. }
  57. // Security check
  58. $socid = 0;
  59. if (isset($user->socid) && $user->socid > 0) {
  60. $socid = $user->socid;
  61. }
  62. $feature2 = (($socid && $user->hasRight("user", "self", "write")) ? '' : 'user');
  63. // A user can always read its own card if not advanced perms enabled, or if he has advanced perms, except for admin
  64. if ($user->id == $id && (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !$user->hasRight("user", "self_advance", "readperms") && empty($user->admin))) {
  65. accessforbidden();
  66. }
  67. $result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
  68. if ($user->id <> $id && !$canreaduser) {
  69. accessforbidden();
  70. }
  71. $object = new User($db);
  72. $object->fetch($id, '', '', 1);
  73. $object->getrights();
  74. $entity = $conf->entity;
  75. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  76. $hookmanager->initHooks(array('usercard', 'userperms', 'globalcard'));
  77. /*
  78. * Actions
  79. */
  80. $parameters = array('socid'=>$socid);
  81. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  82. if ($reshook < 0) {
  83. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  84. }
  85. if (empty($reshook)) {
  86. if ($action == 'addrights' && $caneditperms && $confirm == 'yes') {
  87. $edituser = new User($db);
  88. $edituser->fetch($object->id);
  89. $result = $edituser->addrights($rights, $module, '', $entity);
  90. if ($result < 0) {
  91. setEventMessages($edituser->error, $edituser->errors, 'errors');
  92. }
  93. // If we are changing our own permissions, we reload permissions and menu
  94. if ($object->id == $user->id) {
  95. $user->clearrights();
  96. $user->getrights();
  97. $menumanager->loadMenu();
  98. }
  99. $object->clearrights();
  100. $object->getrights();
  101. }
  102. if ($action == 'delrights' && $caneditperms && $confirm == 'yes') {
  103. $edituser = new User($db);
  104. $edituser->fetch($object->id);
  105. $result = $edituser->delrights($rights, $module, '', $entity);
  106. if ($result < 0) {
  107. setEventMessages($edituser->error, $edituser->errors, 'errors');
  108. }
  109. // If we are changing our own permissions, we reload permissions and menu
  110. if ($object->id == $user->id) {
  111. $user->clearrights();
  112. $user->getrights();
  113. $menumanager->loadMenu();
  114. }
  115. $object->clearrights();
  116. $object->getrights();
  117. }
  118. }
  119. /*
  120. * View
  121. */
  122. $form = new Form($db);
  123. $person_name = !empty($object->firstname) ? $object->lastname.", ".$object->firstname : $object->lastname;
  124. $title = $person_name." - ".$langs->trans('Permissions');
  125. $help_url = '';
  126. llxHeader('', $title, $help_url);
  127. $head = user_prepare_head($object);
  128. $title = $langs->trans("User");
  129. print dol_get_fiche_head($head, 'rights', $title, -1, 'user');
  130. $db->begin();
  131. // Search all modules with permission and reload permissions def.
  132. $modules = array();
  133. $modulesdir = dolGetModulesDirs();
  134. foreach ($modulesdir as $dir) {
  135. $handle = @opendir(dol_osencode($dir));
  136. if (is_resource($handle)) {
  137. while (($file = readdir($handle)) !== false) {
  138. if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') {
  139. $modName = substr($file, 0, dol_strlen($file) - 10);
  140. if ($modName) {
  141. include_once $dir.$file;
  142. $objMod = new $modName($db);
  143. // Load all lang files of module
  144. if (isset($objMod->langfiles) && is_array($objMod->langfiles)) {
  145. foreach ($objMod->langfiles as $domain) {
  146. $langs->load($domain);
  147. }
  148. }
  149. // Load all permissions
  150. if ($objMod->rights_class) {
  151. $ret = $objMod->insert_permissions(0, $entity);
  152. $modules[$objMod->rights_class] = $objMod;
  153. //print "modules[".$objMod->rights_class."]=$objMod;";
  154. }
  155. }
  156. }
  157. }
  158. }
  159. }
  160. $db->commit();
  161. // Read permissions of user
  162. $permsuser = array();
  163. $sql = "SELECT DISTINCT ur.fk_id";
  164. $sql .= " FROM ".MAIN_DB_PREFIX."user_rights as ur";
  165. $sql .= " WHERE ur.entity = ".((int) $entity);
  166. $sql .= " AND ur.fk_user = ".((int) $object->id);
  167. dol_syslog("get user perms", LOG_DEBUG);
  168. $result = $db->query($sql);
  169. if ($result) {
  170. $num = $db->num_rows($result);
  171. $i = 0;
  172. while ($i < $num) {
  173. $obj = $db->fetch_object($result);
  174. array_push($permsuser, $obj->fk_id);
  175. $i++;
  176. }
  177. $db->free($result);
  178. } else {
  179. dol_print_error($db);
  180. }
  181. // Read the permissions of a user inherited by its groups
  182. $permsgroupbyentity = array();
  183. $sql = "SELECT DISTINCT gr.fk_id, gu.entity"; // fk_id are permission id and entity is entity of the group
  184. $sql .= " FROM ".MAIN_DB_PREFIX."usergroup_rights as gr,";
  185. $sql .= " ".MAIN_DB_PREFIX."usergroup_user as gu"; // all groups of a user
  186. $sql .= " WHERE 1 = 1";
  187. // A very strange business rules. Must be same than into user->getrights() user/perms.php and user/group/perms.php
  188. if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY)) {
  189. if (isModEnabled('multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
  190. $sql .= " AND gu.entity IN (0,".$conf->entity.")";
  191. } else {
  192. //$sql .= " AND r.entity = ".((int) $conf->entity);
  193. }
  194. } else {
  195. $sql .= " AND gr.entity = ".((int) $conf->entity); // Only groups created in current entity
  196. // The entity on the table usergroup_user should be useless and should never be used because it is alreay into gr and r.
  197. // but when using MULTICOMPANY_TRANSVERSE_MODE, we may insert record that make rubbish result due to duplicate record of
  198. // other entities, so we are forced to add a filter here
  199. $sql .= " AND gu.entity IN (0,".$conf->entity.")";
  200. //$sql .= " AND r.entity = ".((int) $conf->entity); // Only permission of modules enabled in current entity
  201. }
  202. // End of strange business rule
  203. $sql .= " AND gr.fk_usergroup = gu.fk_usergroup";
  204. $sql .= " AND gu.fk_user = ".((int) $object->id);
  205. dol_syslog("get user perms", LOG_DEBUG);
  206. $result = $db->query($sql);
  207. if ($result) {
  208. $num = $db->num_rows($result);
  209. $i = 0;
  210. while ($i < $num) {
  211. $obj = $db->fetch_object($result);
  212. if (!isset($permsgroupbyentity[$obj->entity])) {
  213. $permsgroupbyentity[$obj->entity] = array();
  214. }
  215. array_push($permsgroupbyentity[$obj->entity], $obj->fk_id);
  216. $i++;
  217. }
  218. $db->free($result);
  219. } else {
  220. dol_print_error($db);
  221. }
  222. /*
  223. * Part to add/remove permissions
  224. */
  225. $linkback = '';
  226. if ($user->hasRight("user", "user", "read") || $user->admin) {
  227. $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  228. }
  229. $morehtmlref = '<a href="'.DOL_URL_ROOT.'/user/vcard.php?id='.$object->id.'&output=file&file='.urlencode(dol_sanitizeFileName($object->getFullName($langs).'.vcf')).'" class="refid" rel="noopener">';
  230. $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
  231. $morehtmlref .= '</a>';
  232. $urltovirtualcard = '/user/virtualcard.php?id='.((int) $object->id);
  233. $morehtmlref .= dolButtonToOpenUrlInDialogPopup('publicvirtualcard', $langs->trans("PublicVirtualCardUrl").' - '.$object->getFullName($langs), img_picto($langs->trans("PublicVirtualCardUrl"), 'card', 'class="valignmiddle marginleftonly paddingrightonly"'), $urltovirtualcard, '', 'nohover');
  234. dol_banner_tab($object, 'id', $linkback, $user->hasRight("user", "user", "read") || $user->admin, 'rowid', 'ref', $morehtmlref);
  235. print '<div class="fichecenter">';
  236. print '<div class="underbanner clearboth"></div>';
  237. print '<table class="border centpercent tableforfield">';
  238. // Login
  239. print '<tr><td id="anchorforperms" class="titlefield">'.$langs->trans("Login").'</td>';
  240. if (!empty($object->ldap_sid) && $object->statut == 0) {
  241. print '<td class="error">';
  242. print $langs->trans("LoginAccountDisableInDolibarr");
  243. print '</td>';
  244. } else {
  245. print '<td>';
  246. $addadmin = '';
  247. if (property_exists($object, 'admin')) {
  248. if (isModEnabled('multicompany') && !empty($object->admin) && empty($object->entity)) {
  249. $addadmin .= img_picto($langs->trans("SuperAdministratorDesc"), "redstar", 'class="paddingleft"');
  250. } elseif (!empty($object->admin)) {
  251. $addadmin .= img_picto($langs->trans("AdministratorDesc"), "star", 'class="paddingleft"');
  252. }
  253. }
  254. print showValueWithClipboardCPButton($object->login).$addadmin;
  255. print '</td>';
  256. }
  257. print '</tr>'."\n";
  258. // Type
  259. print '<tr><td>';
  260. $text = $langs->trans("Type");
  261. print $form->textwithpicto($text, $langs->trans("InternalExternalDesc"));
  262. print '</td><td>';
  263. $type = $langs->trans("Internal");
  264. if ($object->socid > 0) {
  265. $type = $langs->trans("External");
  266. }
  267. print '<span class="badgeneutral">';
  268. print $type;
  269. if ($object->ldap_sid) {
  270. print ' ('.$langs->trans("DomainUser").')';
  271. }
  272. print '</span>';
  273. print '</td></tr>'."\n";
  274. print '</table>';
  275. print '</div>';
  276. print '<br>';
  277. if ($user->admin) {
  278. print info_admin($langs->trans("WarningOnlyPermissionOfActivatedModules"));
  279. }
  280. // If edited user is an extern user, we show warning for external users
  281. if (!empty($object->socid)) {
  282. print info_admin(showModulesExludedForExternal($modules))."\n";
  283. }
  284. $parameters = array('permsgroupbyentity'=>$permsgroupbyentity);
  285. $reshook = $hookmanager->executeHooks('insertExtraHeader', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  286. if ($reshook < 0) {
  287. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  288. }
  289. $listofexpandedmodules = array();
  290. print "\n";
  291. print '<div class="div-table-responsive-no-min">';
  292. print '<table class="noborder centpercent">';
  293. print '<tr class="liste_titre">';
  294. print '<td>'.$langs->trans("Module").'</td>';
  295. if ($caneditperms) {
  296. print '<td class="center nowrap">';
  297. 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>";
  298. print ' / ';
  299. 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>";
  300. print '</td>';
  301. } else {
  302. print '<td></td>';
  303. }
  304. print '<td></td>';
  305. //print '<td></td>';
  306. print '<td class="right nowrap" colspan="2">';
  307. 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>';
  308. print ' | ';
  309. 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>';
  310. print '</td>';
  311. print '</tr>'."\n";
  312. // Fix bad value for module_position in table
  313. // ------------------------------------------
  314. $sql = "SELECT r.id, r.libelle as label, r.module, r.perms, r.subperms, r.module_position, r.bydefault";
  315. $sql .= " FROM ".MAIN_DB_PREFIX."rights_def as r";
  316. $sql .= " WHERE r.libelle NOT LIKE 'tou%'"; // On ignore droits "tous"
  317. $sql .= " AND r.entity = ".((int) $entity);
  318. $sql .= " ORDER BY r.family_position, r.module_position, r.module, r.id";
  319. $result = $db->query($sql);
  320. if ($result) {
  321. $num = $db->num_rows($result);
  322. $i = 0;
  323. $oldmod = '';
  324. while ($i < $num) {
  325. $obj = $db->fetch_object($result);
  326. // If line is for a module that does not exist anymore (absent of includes/module), we ignore it
  327. if (!isset($obj->module) || empty($modules[$obj->module])) {
  328. $i++;
  329. continue;
  330. }
  331. // Special cases
  332. if (isModEnabled("reception")) {
  333. // The 2 permissions in fournisseur modules are replaced by permissions into reception module
  334. if ($obj->module == 'fournisseur' && $obj->perms == 'commande' && $obj->subperms == 'receptionner') {
  335. $i++;
  336. continue;
  337. }
  338. if ($obj->module == 'fournisseur' && $obj->perms == 'commande_advance' && $obj->subperms == 'check') {
  339. $i++;
  340. continue;
  341. }
  342. }
  343. $objMod = $modules[$obj->module];
  344. // Save field module_position in database if value is wrong
  345. if (empty($obj->module_position) || (is_object($objMod) && $objMod->isCoreOrExternalModule() == 'external' && $obj->module_position < 100000)) {
  346. if (is_object($modules[$obj->module]) && ($modules[$obj->module]->module_position > 0)) {
  347. // TODO Define familyposition
  348. //$familyposition = $modules[$obj->module]->family_position;
  349. $familyposition = 0;
  350. $newmoduleposition = $modules[$obj->module]->module_position;
  351. // Correct $newmoduleposition position for external modules
  352. $objMod = $modules[$obj->module];
  353. if (is_object($objMod) && $objMod->isCoreOrExternalModule() == 'external' && $newmoduleposition < 100000) {
  354. $newmoduleposition += 100000;
  355. }
  356. $sqlupdate = 'UPDATE '.MAIN_DB_PREFIX."rights_def SET module_position = ".((int) $newmoduleposition).",";
  357. $sqlupdate .= " family_position = ".((int) $familyposition);
  358. $sqlupdate .= " WHERE module_position = ".((int) $obj->module_position)." AND module = '".$db->escape($obj->module)."'";
  359. $db->query($sqlupdate);
  360. }
  361. }
  362. }
  363. }
  364. //print "xx".$conf->global->MAIN_USE_ADVANCED_PERMS;
  365. $sql = "SELECT r.id, r.libelle as label, r.module, r.perms, r.subperms, r.module_position, r.bydefault";
  366. $sql .= " FROM ".MAIN_DB_PREFIX."rights_def as r";
  367. $sql .= " WHERE r.libelle NOT LIKE 'tou%'"; // On ignore droits "tous"
  368. $sql .= " AND r.entity = ".((int) $entity);
  369. if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
  370. $sql .= " AND r.perms NOT LIKE '%_advance'"; // Hide advanced perms if option is not enabled
  371. }
  372. $sql .= " ORDER BY r.family_position, r.module_position, r.module, r.id";
  373. $result = $db->query($sql);
  374. if ($result) {
  375. $num = $db->num_rows($result);
  376. $i = 0; $j = 0;
  377. $oldmod = '';
  378. $cookietohidegroup = (empty($_COOKIE["DOLUSER_PERMS_HIDE_GRP"]) ? '' : preg_replace('/^,/', '', $_COOKIE["DOLUSER_PERMS_HIDE_GRP"]));
  379. $cookietohidegrouparray = explode(',', $cookietohidegroup);
  380. //var_dump($cookietohidegrouparray);
  381. while ($i < $num) {
  382. $obj = $db->fetch_object($result);
  383. // If line is for a module that does not exist anymore (absent of includes/module), we ignore it
  384. if (empty($modules[$obj->module])) {
  385. $i++;
  386. continue;
  387. }
  388. // Special cases
  389. if (isModEnabled("reception")) {
  390. // The 2 permission in fournisseur modules has been replaced by permissions into reception module
  391. if ($obj->module == 'fournisseur' && $obj->perms == 'commande' && $obj->subperms == 'receptionner') {
  392. $i++;
  393. continue;
  394. }
  395. if ($obj->module == 'fournisseur' && $obj->perms == 'commande_advance' && $obj->subperms == 'check') {
  396. $i++;
  397. continue;
  398. }
  399. }
  400. $objMod = $modules[$obj->module];
  401. // Save field module_position in database if value is wrong
  402. /*
  403. if (empty($obj->module_position) || (is_object($objMod) && $objMod->isCoreOrExternalModule() == 'external' && $obj->module_position < 100000)) {
  404. if (is_object($modules[$obj->module]) && ($modules[$obj->module]->module_position > 0)) {
  405. // TODO Define familyposition
  406. //$familyposition = $modules[$obj->module]->family_position;
  407. $familyposition = 0;
  408. $newmoduleposition = $modules[$obj->module]->module_position;
  409. // Correct $newmoduleposition position for external modules
  410. $objMod = $modules[$obj->module];
  411. if (is_object($objMod) && $objMod->isCoreOrExternalModule() == 'external' && $newmoduleposition < 100000) {
  412. $newmoduleposition += 100000;
  413. }
  414. $sqlupdate = 'UPDATE '.MAIN_DB_PREFIX."rights_def SET module_position = ".((int) $newmoduleposition).",";
  415. $sqlupdate .= " family_position = ".((int) $familyposition);
  416. $sqlupdate .= " WHERE module_position = ".((int) $obj->module_position)." AND module = '".$db->escape($obj->module)."'";
  417. $db->query($sqlupdate);
  418. }
  419. }
  420. */
  421. if (GETPOSTISSET('forbreakperms_'.$obj->module)) {
  422. $ishidden = GETPOST('forbreakperms_'.$obj->module, 'int');
  423. } elseif (in_array($j, $cookietohidegrouparray)) { // If j is among list of hidden group
  424. $ishidden = 1;
  425. } else {
  426. $ishidden = 0;
  427. }
  428. $isexpanded = ! $ishidden;
  429. //var_dump("isexpanded=".$isexpanded);
  430. $permsgroupbyentitypluszero = array();
  431. if (!empty($permsgroupbyentity[0])) {
  432. $permsgroupbyentitypluszero = array_merge($permsgroupbyentitypluszero, $permsgroupbyentity[0]);
  433. }
  434. if (!empty($permsgroupbyentity[$entity])) {
  435. $permsgroupbyentitypluszero = array_merge($permsgroupbyentitypluszero, $permsgroupbyentity[$entity]);
  436. }
  437. //var_dump($permsgroupbyentitypluszero);
  438. // Break found, it's a new module to catch
  439. if (isset($obj->module) && ($oldmod <> $obj->module)) {
  440. $oldmod = $obj->module;
  441. $j++;
  442. if (GETPOSTISSET('forbreakperms_'.$obj->module)) {
  443. $ishidden = GETPOST('forbreakperms_'.$obj->module, 'int');
  444. } elseif (in_array($j, $cookietohidegrouparray)) { // If j is among list of hidden group
  445. $ishidden = 1;
  446. } else {
  447. $ishidden = 0;
  448. }
  449. $isexpanded = ! $ishidden;
  450. //var_dump('$obj->module='.$obj->module.' isexpanded='.$isexpanded);
  451. // Break detected, we get objMod
  452. $objMod = $modules[$obj->module];
  453. $picto = ($objMod->picto ? $objMod->picto : 'generic');
  454. // Show break line
  455. print '<tr class="oddeven trforbreakperms" data-hide-perms="'.$obj->module.'" data-j="'.$j.'">';
  456. // Picto and label of module
  457. print '<td class="maxwidthonsmartphone tdoverflowmax150 tdforbreakperms" data-hide-perms="'.dol_escape_htmltag($obj->module).'" title="'.dol_escape_htmltag($objMod->getName()).'">';
  458. print '<input type="hidden" name="forbreakperms_'.$obj->module.'" id="idforbreakperms_'.$obj->module.'" css="cssforfieldishiden" data-j="'.$j.'" value="'.($isexpanded ? '0' : "1").'">';
  459. print img_object('', $picto, 'class="pictoobjectwidth paddingright"').' '.$objMod->getName();
  460. print '<a name="'.$objMod->getName().'"></a>';
  461. print '</td>';
  462. // Permission and tick (2 columns)
  463. if (($caneditperms && empty($objMod->rights_admin_allowed)) || empty($object->admin)) {
  464. if ($caneditperms) {
  465. print '<td class="center wraponsmartphone">';
  466. print '<span class="permtohide_'.$obj->module.'" '.(!$isexpanded ? ' style="display:none"' : '').'>';
  467. 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>";
  468. print ' / ';
  469. 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>";
  470. print '</span>';
  471. print '</td>';
  472. print '<td class="tdforbreakperms" data-hide-perms="'.dol_escape_htmltag($obj->module).'">';
  473. print '</td>';
  474. } else {
  475. print '<td class="tdforbreakperms" data-hide-perms="'.dol_escape_htmltag($obj->module).'">&nbsp;</td>';
  476. print '<td class="tdforbreakperms" data-hide-perms="'.dol_escape_htmltag($obj->module).'">&nbsp;</td>';
  477. }
  478. } else {
  479. if ($caneditperms) {
  480. print '<td class="center wraponsmartphone">';
  481. /*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>";
  482. print ' / ';
  483. 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>";
  484. */
  485. print '</td>';
  486. print '<td class="tdforbreakperms" data-hide-perms="'.dol_escape_htmltag($obj->module).'">';
  487. print '</td>';
  488. } else {
  489. print '<td class="right tdforbreakperms" data-hide-perms="'.dol_escape_htmltag($obj->module).'"></td>';
  490. print '<td class="tdforbreakperms" data-hide-perms="'.dol_escape_htmltag($obj->module).'">&nbsp;</td>';
  491. }
  492. }
  493. // Description of permission (2 columns)
  494. print '<td class="tdforbreakperms" data-hide-perms="'.dol_escape_htmltag($obj->module).'">&nbsp;</td>';
  495. print '<td class="maxwidthonsmartphone right tdforbreakperms" data-hide-perms="'.dol_escape_htmltag($obj->module).'">';
  496. print '<div class="switchfolderperms folderperms_'.$obj->module.'"'.($isexpanded ? ' style="display:none;"' : '').'>';
  497. print img_picto('', 'folder', 'class="marginright"');
  498. print '</div>';
  499. print '<div class="switchfolderperms folderopenperms_'.$obj->module.'"'.(!$isexpanded ? ' style="display:none;"' : '').'>';
  500. print img_picto('', 'folder-open', 'class="marginright"');
  501. print '</div>';
  502. print '</td>'; //Add picto + / - when open en closed
  503. print '</tr>'."\n";
  504. }
  505. print '<!-- '.$obj->module.'->'.$obj->perms.($obj->subperms ? '->'.$obj->subperms : '').' -->'."\n";
  506. print '<tr class="oddeven trtohide_'.$obj->module.'"'.(!$isexpanded ? ' style="display:none"' : '').'>';
  507. // Picto and label of module
  508. print '<td class="maxwidthonsmartphone tdoverflowonsmartphone">';
  509. print '</td>';
  510. // Permission and tick (2 columns)
  511. if (!empty($object->admin) && !empty($objMod->rights_admin_allowed)) { // Permission granted because admin
  512. if ($caneditperms) {
  513. print '<td class="center">'.img_picto($langs->trans("Administrator"), 'star').'</td>';
  514. } else {
  515. print '<td>&nbsp;</td>';
  516. }
  517. print '<td class="center nowrap">';
  518. if (!$caneditperms) {
  519. print img_picto($langs->trans("Active"), 'switch_on', '', false, 0, 0, '', 'opacitymedium');
  520. //print img_picto($langs->trans("Active"), 'tick');
  521. }
  522. print '</td>';
  523. } elseif (in_array($obj->id, $permsuser)) { // Permission granted by user
  524. if ($caneditperms) {
  525. print '<td class="center">';
  526. 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.'">';
  527. //print img_edit_remove($langs->trans("Remove"));
  528. print img_picto($langs->trans("Remove"), 'switch_on');
  529. print '</a></td>';
  530. } else {
  531. print '<td>&nbsp;</td>';
  532. }
  533. print '<td class="center nowrap">';
  534. if (!$caneditperms) {
  535. print img_picto($langs->trans("Active"), 'switch_on', '', false, 0, 0, '', 'opacitymedium');
  536. //print img_picto($langs->trans("Active"), 'tick');
  537. }
  538. print '</td>';
  539. } elseif (isset($permsgroupbyentitypluszero) && is_array($permsgroupbyentitypluszero)) {
  540. if (in_array($obj->id, $permsgroupbyentitypluszero)) { // Permission granted by group
  541. if ($caneditperms) {
  542. print '<td class="center">';
  543. print $form->textwithtooltip($langs->trans("Inherited"), $langs->trans("PermissionInheritedFromAGroup"));
  544. print '</td>';
  545. } else {
  546. print '<td>&nbsp;</td>';
  547. }
  548. print '<td class="center nowrap">';
  549. print img_picto($langs->trans("Active"), 'switch_on', '', false, 0, 0, '', 'opacitymedium');
  550. //print img_picto($langs->trans("Active"), 'tick');
  551. print '</td>';
  552. } else {
  553. // Do not own permission
  554. if ($caneditperms) {
  555. print '<td class="center">';
  556. 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.'">';
  557. //print img_edit_add($langs->trans("Add"));
  558. print img_picto($langs->trans("Add"), 'switch_off');
  559. print '</a></td>';
  560. } else {
  561. print '<td>';
  562. print '&nbsp;';
  563. print '</td>';
  564. }
  565. print '<td>&nbsp;</td>';
  566. }
  567. } else {
  568. // Do not own permission
  569. if ($caneditperms) {
  570. print '<td class="center">';
  571. 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.'">';
  572. //print img_edit_add($langs->trans("Add"));
  573. print img_picto($langs->trans("Add"), 'switch_off');
  574. print '</a></td>';
  575. } else {
  576. print '<td>&nbsp;</td>';
  577. }
  578. print '<td class="center">';
  579. if (!$caneditperms) {
  580. print img_picto($langs->trans("Disabled"), 'switch_off', '', false, 0, 0, '', 'opacitymedium');
  581. }
  582. //print '&nbsp;';
  583. print '</td>';
  584. }
  585. // Description of permission (2 columns)
  586. $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)));
  587. if (!$user->admin) {
  588. print '<td colspan="2">';
  589. } else {
  590. print '<td>';
  591. }
  592. print $permlabel;
  593. if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
  594. if (preg_match('/_advance$/', $obj->perms)) {
  595. print ' <span class="opacitymedium">('.$langs->trans("AdvancedModeOnly").')</span>';
  596. }
  597. }
  598. print '</td>';
  599. // Permission id
  600. if ($user->admin) {
  601. print '<td class="right">';
  602. $htmltext = $langs->trans("ID").': '.$obj->id;
  603. $htmltext .= '<br>'.$langs->trans("Permission").': user->rights->'.$obj->module.'->'.$obj->perms.($obj->subperms ? '->'.$obj->subperms : '');
  604. print $form->textwithpicto('', $htmltext);
  605. //print '<span class="opacitymedium">'.$obj->id.'</span>';
  606. print '</td>';
  607. }
  608. print '</tr>'."\n";
  609. $i++;
  610. }
  611. } else {
  612. dol_print_error($db);
  613. }
  614. print '</table>';
  615. print '</div>';
  616. print '<script>';
  617. print '$(".tdforbreakperms:not(.alink)").on("click", function(){
  618. console.log("Click on tdforbreakperms");
  619. moduletohide = $(this).data("hide-perms");
  620. j = $(this).data("j");
  621. if ($("#idforbreakperms_"+moduletohide).val() == 1) {
  622. console.log("idforbreakperms_"+moduletohide+" has value hidden=1");
  623. $(".trtohide_"+moduletohide).show();
  624. $(".permtoshow_"+moduletohide).hide();
  625. $(".permtohide_"+moduletohide).show();
  626. $(".folderperms_"+moduletohide).hide();
  627. $(".folderopenperms_"+moduletohide).show();
  628. $("#idforbreakperms_"+moduletohide).val("0");
  629. } else {
  630. console.log("idforbreakperms_"+moduletohide+" has value hidden=0");
  631. $(".trtohide_"+moduletohide).hide();
  632. $(".folderopenperms_"+moduletohide).hide();
  633. $(".folderperms_"+moduletohide).show();
  634. $(".permtoshow_"+moduletohide).show();
  635. $(".permtohide_"+moduletohide).hide();
  636. $("#idforbreakperms_"+moduletohide).val("1");
  637. }
  638. // Now rebuild the value for cookie
  639. var hideuserperm="";
  640. $(".trforbreakperms").each(function(index) {
  641. //console.log( index + ": " + $( this ).data("j") + " " + $( this ).data("hide-perms") + " " + $("input[data-j="+(index+1)+"]").val());
  642. if ($("input[data-j="+(index+1)+"]").val() == 1) {
  643. hideuserperm=hideuserperm+","+(index+1);
  644. }
  645. });
  646. // set cookie by js
  647. date = new Date(); date.setTime(date.getTime()+(30*86400000));
  648. if (hideuserperm) {
  649. console.log("set cookie DOLUSER_PERMS_HIDE_GRP="+hideuserperm);
  650. document.cookie = "DOLUSER_PERMS_HIDE_GRP=" + hideuserperm + "; expires=" + date.toGMTString() + "; path=/ ";
  651. } else {
  652. console.log("delete cookie DOLUSER_PERMS_HIDE_GRP");
  653. document.cookie = "DOLUSER_PERMS_HIDE_GRP=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/ ";
  654. }
  655. });';
  656. print "\n";
  657. // Button expand / collapse all
  658. print '$(".showallperms").on("click", function(){
  659. console.log("Click on showallperms");
  660. console.log("delete cookie DOLUSER_PERMS_HIDE_GRP from showallperms click");
  661. document.cookie = "DOLUSER_PERMS_HIDE_GRP=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/ ";
  662. $(".tdforbreakperms").each( function(){
  663. moduletohide = $(this).data("hide-perms");
  664. //console.log(moduletohide);
  665. if ($("#idforbreakperms_"+moduletohide).val() != 0) {
  666. $(this).trigger("click"); // emulate the click, so the cooki will be resaved
  667. }
  668. })
  669. });
  670. $(".hideallperms").on("click", function(){
  671. console.log("Click on hideallperms");
  672. $(".tdforbreakperms").each( function(){
  673. moduletohide = $(this).data("hide-perms");
  674. //console.log(moduletohide);
  675. if ($("#idforbreakperms_"+moduletohide).val() != 1) {
  676. $(this).trigger("click"); // emulate the click, so the cooki will be resaved
  677. }
  678. })
  679. });';
  680. print "\n";
  681. print '</script>';
  682. print '<style>';
  683. print '.switchfolderperms{
  684. cursor: pointer;
  685. }';
  686. print '</style>';
  687. $parameters = array();
  688. $reshook = $hookmanager->executeHooks('insertExtraFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  689. if ($reshook < 0) {
  690. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  691. }
  692. print dol_get_fiche_end();
  693. // End of page
  694. llxFooter();
  695. $db->close();