perms.php 6.5 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@capnetworks.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. $langs->load("admin");
  29. $langs->load("users");
  30. $langs->load("other");
  31. $action=GETPOST('action','aZ09');
  32. if (!$user->admin) accessforbidden();
  33. /*
  34. * Actions
  35. */
  36. if ($action == 'add')
  37. {
  38. $sql = "UPDATE ".MAIN_DB_PREFIX."rights_def SET bydefault=1";
  39. $sql.= " WHERE id = ".GETPOST("pid",'int');
  40. $sql.= " AND entity = ".$conf->entity;
  41. $db->query($sql);
  42. }
  43. if ($action == 'remove')
  44. {
  45. $sql = "UPDATE ".MAIN_DB_PREFIX."rights_def SET bydefault=0";
  46. $sql.= " WHERE id = ".GETPOST('pid','int');
  47. $sql.= " AND entity = ".$conf->entity;
  48. $db->query($sql);
  49. }
  50. /*
  51. * View
  52. */
  53. $wikihelp='EN:Setup_Security|FR:Paramétrage_Sécurité|ES:Configuración_Seguridad';
  54. llxHeader('',$langs->trans("DefaultRights"), $wikihelp);
  55. print load_fiche_titre($langs->trans("SecuritySetup"),'','title_setup');
  56. print $langs->trans("DefaultRightsDesc");
  57. print " ".$langs->trans("OnlyActiveElementsAreShown")."<br><br>\n";
  58. $db->begin();
  59. // Charge les modules soumis a permissions
  60. $modules = array();
  61. $modulesdir = dolGetModulesDirs();
  62. foreach ($modulesdir as $dir)
  63. {
  64. // Load modules attributes in arrays (name, numero, orders) from dir directory
  65. //print $dir."\n<br>";
  66. $handle=@opendir(dol_osencode($dir));
  67. if (is_resource($handle))
  68. {
  69. while (($file = readdir($handle))!==false)
  70. {
  71. if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php')
  72. {
  73. $modName = substr($file, 0, dol_strlen($file) - 10);
  74. if ($modName)
  75. {
  76. include_once $dir.$file;
  77. $objMod = new $modName($db);
  78. // Load all lang files of module
  79. if (isset($objMod->langfiles) && is_array($objMod->langfiles))
  80. {
  81. foreach($objMod->langfiles as $domain)
  82. {
  83. $langs->load($domain);
  84. }
  85. }
  86. // Load all permissions
  87. if ($objMod->rights_class)
  88. {
  89. $ret=$objMod->insert_permissions(0);
  90. $modules[$objMod->rights_class]=$objMod;
  91. //print "modules[".$objMod->rights_class."]=$objMod;";
  92. }
  93. }
  94. }
  95. }
  96. }
  97. }
  98. $db->commit();
  99. $head=security_prepare_head();
  100. dol_fiche_head($head, 'default', $langs->trans("Security"), -1);
  101. // Show warning about external users
  102. print info_admin(showModulesExludedForExternal($modules)).'<br>'."\n";
  103. print '<div class="div-table-responsive-no-min">';
  104. print '<table class="noborder" width="100%">';
  105. // Affiche lignes des permissions
  106. $sql = "SELECT r.id, r.libelle, r.module, r.perms, r.subperms, r.bydefault";
  107. $sql.= " FROM ".MAIN_DB_PREFIX."rights_def as r";
  108. $sql.= " WHERE r.libelle NOT LIKE 'tou%'"; // On ignore droits "tous"
  109. $sql.= " AND entity = ".$conf->entity;
  110. if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) $sql.= " AND r.perms NOT LIKE '%_advance'"; // Hide advanced perms if option is not enabled
  111. $sql.= " ORDER BY r.module, r.id";
  112. $result = $db->query($sql);
  113. if ($result)
  114. {
  115. $num = $db->num_rows($result);
  116. $i = 0;
  117. $oldmod = "";
  118. while ($i < $num)
  119. {
  120. $obj = $db->fetch_object($result);
  121. // Si la ligne correspond a un module qui n'existe plus (absent de includes/module), on l'ignore
  122. if (! $modules[$obj->module])
  123. {
  124. $i++;
  125. continue;
  126. }
  127. // Check if permission we found is inside a module definition. If not, we discard it.
  128. $found=false;
  129. foreach($modules[$obj->module]->rights as $key => $val)
  130. {
  131. $rights_class=$objMod->rights_class;
  132. if ($val[4] == $obj->perms && (empty($val[5]) || $val[5] == $obj->subperms))
  133. {
  134. $found=true;
  135. break;
  136. }
  137. }
  138. if (! $found)
  139. {
  140. $i++;
  141. continue;
  142. }
  143. // Break found, it's a new module to catch
  144. if ($oldmod <> $obj->module)
  145. {
  146. $oldmod = $obj->module;
  147. $objMod = $modules[$obj->module];
  148. $picto = ($objMod->picto?$objMod->picto:'generic');
  149. print '<tr class="liste_titre">';
  150. print '<td>'.$langs->trans("Module").'</td>';
  151. print '<td>'.$langs->trans("Permission").'</td>';
  152. print '<td align="center">'.$langs->trans("Default").'</td>';
  153. print '<td align="center">&nbsp;</td>';
  154. print "</tr>\n";
  155. }
  156. print '<tr class="oddeven">';
  157. print '<td>'
  158. print img_object('',$picto,'class="pictoobjectwidth"').' '.$objMod->getName();
  159. print '<a name="'.$objMod->getName().'">&nbsp;</a>';
  160. print '</td>';
  161. $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));
  162. print '<td>'.$perm_libelle. '</td>';
  163. print '<td align="center">';
  164. if ($obj->bydefault == 1)
  165. {
  166. print img_picto($langs->trans("Active"),'tick');
  167. print '</td><td>';
  168. print '<a class="reposition" href="perms.php?pid='.$obj->id.'&amp;action=remove">'.img_edit_remove().'</a>';
  169. }
  170. else
  171. {
  172. print '&nbsp;';
  173. print '</td><td>';
  174. print '<a class="reposition" href="perms.php?pid='.$obj->id.'&amp;action=add">'.img_edit_add().'</a>';
  175. }
  176. print '</td></tr>';
  177. $i++;
  178. }
  179. }
  180. print '</table>';
  181. print '</div>';
  182. dol_fiche_end();
  183. llxFooter();
  184. $db->close();