PageRenderTime 36ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/admin/perms.php

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