perms.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?php
  2. /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2013 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2011 Herve Prot <herve.prot@symeos.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/admin/perms.php
  22. * \ingroup core
  23. * \brief Page d'administration/configuration des permissions par defaut
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  28. // Load translation files required by the page
  29. $langs->loadLangs(array('admin', 'users', 'other'));
  30. $action=GETPOST('action','aZ09');
  31. if (!$user->admin) accessforbidden();
  32. /*
  33. * Actions
  34. */
  35. if ($action == 'add')
  36. {
  37. $sql = "UPDATE ".MAIN_DB_PREFIX."rights_def SET bydefault=1";
  38. $sql.= " WHERE id = ".GETPOST("pid",'int');
  39. $sql.= " AND entity = ".$conf->entity;
  40. $db->query($sql);
  41. }
  42. if ($action == 'remove')
  43. {
  44. $sql = "UPDATE ".MAIN_DB_PREFIX."rights_def SET bydefault=0";
  45. $sql.= " WHERE id = ".GETPOST('pid','int');
  46. $sql.= " AND entity = ".$conf->entity;
  47. $db->query($sql);
  48. }
  49. /*
  50. * View
  51. */
  52. $wikihelp='EN:Setup_Security|FR:Paramétrage_Sécurité|ES:Configuración_Seguridad';
  53. llxHeader('',$langs->trans("DefaultRights"), $wikihelp);
  54. print load_fiche_titre($langs->trans("SecuritySetup"),'','title_setup');
  55. print $langs->trans("DefaultRightsDesc");
  56. print " ".$langs->trans("OnlyActiveElementsAreShown")."<br><br>\n";
  57. $db->begin();
  58. // Charge les modules soumis a permissions
  59. $modules = array();
  60. $modulesdir = dolGetModulesDirs();
  61. foreach ($modulesdir as $dir)
  62. {
  63. // Load modules attributes in arrays (name, numero, orders) from dir directory
  64. //print $dir."\n<br>";
  65. $handle=@opendir(dol_osencode($dir));
  66. if (is_resource($handle))
  67. {
  68. while (($file = readdir($handle))!==false)
  69. {
  70. if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php')
  71. {
  72. $modName = substr($file, 0, dol_strlen($file) - 10);
  73. if ($modName)
  74. {
  75. include_once $dir.$file;
  76. $objMod = new $modName($db);
  77. // Load all lang files of module
  78. if (isset($objMod->langfiles) && is_array($objMod->langfiles))
  79. {
  80. foreach($objMod->langfiles as $domain)
  81. {
  82. $langs->load($domain);
  83. }
  84. }
  85. // Load all permissions
  86. if ($objMod->rights_class)
  87. {
  88. $ret=$objMod->insert_permissions(0);
  89. $modules[$objMod->rights_class]=$objMod;
  90. //print "modules[".$objMod->rights_class."]=$objMod;";
  91. }
  92. }
  93. }
  94. }
  95. }
  96. }
  97. $db->commit();
  98. $head=security_prepare_head();
  99. dol_fiche_head($head, 'default', $langs->trans("Security"), -1);
  100. // Show warning about external users
  101. print info_admin(showModulesExludedForExternal($modules)).'<br>'."\n";
  102. print '<div class="div-table-responsive-no-min">';
  103. print '<table class="noborder" width="100%">';
  104. // Show permissions lines
  105. $sql = "SELECT r.id, r.libelle, r.module, r.perms, r.subperms, r.bydefault";
  106. $sql.= " FROM ".MAIN_DB_PREFIX."rights_def as r";
  107. $sql.= " WHERE r.libelle NOT LIKE 'tou%'"; // On ignore droits "tous"
  108. $sql.= " AND entity = ".$conf->entity;
  109. if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) $sql.= " AND r.perms NOT LIKE '%_advance'"; // Hide advanced perms if option is not enabled
  110. $sql.= " ORDER BY r.module, r.id";
  111. $result = $db->query($sql);
  112. if ($result)
  113. {
  114. $num = $db->num_rows($result);
  115. $i = 0;
  116. $oldmod = "";
  117. while ($i < $num)
  118. {
  119. $obj = $db->fetch_object($result);
  120. // Si la ligne correspond a un module qui n'existe plus (absent de includes/module), on l'ignore
  121. if (! $modules[$obj->module])
  122. {
  123. $i++;
  124. continue;
  125. }
  126. // Check if permission we found is inside a module definition. If not, we discard it.
  127. $found=false;
  128. foreach($modules[$obj->module]->rights as $key => $val)
  129. {
  130. $rights_class=$objMod->rights_class;
  131. if ($val[4] == $obj->perms && (empty($val[5]) || $val[5] == $obj->subperms))
  132. {
  133. $found=true;
  134. break;
  135. }
  136. }
  137. if (! $found)
  138. {
  139. $i++;
  140. continue;
  141. }
  142. // Break found, it's a new module to catch
  143. if ($oldmod <> $obj->module)
  144. {
  145. $oldmod = $obj->module;
  146. $objMod = $modules[$obj->module];
  147. $picto = ($objMod->picto?$objMod->picto:'generic');
  148. print '<tr class="liste_titre">';
  149. print '<td>'.$langs->trans("Module").'</td>';
  150. print '<td>'.$langs->trans("Permission").'</td>';
  151. print '<td align="center">'.$langs->trans("Default").'</td>';
  152. print '<td align="center">&nbsp;</td>';
  153. print "</tr>\n";
  154. }
  155. print '<tr class="oddeven">';
  156. print '<td>';
  157. print img_object('',$picto,'class="pictoobjectwidth"').' '.$objMod->getName();
  158. print '<a name="'.$objMod->getName().'">&nbsp;</a>';
  159. print '</td>';
  160. $perm_libelle=($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):$obj->libelle));
  161. print '<td>'.$perm_libelle. '</td>';
  162. print '<td align="center">';
  163. if ($obj->bydefault == 1)
  164. {
  165. print img_picto($langs->trans("Active"),'tick');
  166. print '</td><td>';
  167. print '<a class="reposition" href="perms.php?pid='.$obj->id.'&amp;action=remove">'.img_edit_remove().'</a>';
  168. }
  169. else
  170. {
  171. print '&nbsp;';
  172. print '</td><td>';
  173. print '<a class="reposition" href="perms.php?pid='.$obj->id.'&amp;action=add">'.img_edit_add().'</a>';
  174. }
  175. print '</td></tr>';
  176. $i++;
  177. }
  178. }
  179. print '</table>';
  180. print '</div>';
  181. dol_fiche_end();
  182. // End of page
  183. llxFooter();
  184. $db->close();