perms.php 6.2 KB

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