dolibarr 18.0.6
perms.php
Go to the documentation of this file.
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 <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
31
32// Load translation files required by the page
33$langs->loadLangs(array('admin', 'users', 'other'));
34
35$action = GETPOST('action', 'aZ09');
36
37if (!$user->admin) {
39}
40
41$entity = $conf->entity;
42
43
44/*
45 * Actions
46 */
47
48if ($action == 'add') {
49 $sql = "UPDATE ".MAIN_DB_PREFIX."rights_def SET bydefault=1";
50 $sql .= " WHERE id = ".GETPOST("pid", 'int');
51 $sql .= " AND entity = ".$conf->entity;
52 $db->query($sql);
53}
54
55if ($action == 'remove') {
56 $sql = "UPDATE ".MAIN_DB_PREFIX."rights_def SET bydefault=0";
57 $sql .= " WHERE id = ".GETPOST('pid', 'int');
58 $sql .= " AND entity = ".$conf->entity;
59 $db->query($sql);
60}
61
62
63/*
64 * View
65 */
66
67$wikihelp = 'EN:Setup_Security|FR:Paramétrage_Sécurité|ES:Configuración_Seguridad';
68
69llxHeader('', $langs->trans("DefaultRights"), $wikihelp);
70
71print load_fiche_titre($langs->trans("SecuritySetup"), '', 'title_setup');
72
73print '<span class="opacitymedium">'.$langs->trans("DefaultRightsDesc")." ".$langs->trans("OnlyActiveElementsAreShown")."</span><br><br>\n";
74
75$db->begin();
76
77// Search all modules with permission and reload permissions def.
78$modules = array();
79$modulesdir = dolGetModulesDirs();
80
81foreach ($modulesdir as $dir) {
82 $handle = @opendir(dol_osencode($dir));
83 if (is_resource($handle)) {
84 while (($file = readdir($handle)) !== false) {
85 if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') {
86 $modName = substr($file, 0, dol_strlen($file) - 10);
87 if ($modName) {
88 include_once $dir.$file;
89 $objMod = new $modName($db);
90
91 // Load all lang files of module
92 if (isset($objMod->langfiles) && is_array($objMod->langfiles)) {
93 foreach ($objMod->langfiles as $domain) {
94 $langs->load($domain);
95 }
96 }
97 // Load all permissions
98 if ($objMod->rights_class) {
99 $ret = $objMod->insert_permissions(0, $entity);
100 $modules[$objMod->rights_class] = $objMod;
101 //print "modules[".$objMod->rights_class."]=$objMod;";
102 }
103 }
104 }
105 }
106 }
107}
108
109$db->commit();
110
111$head = security_prepare_head();
112
113print dol_get_fiche_head($head, 'default', '', -1);
114
115
116// Show warning about external users
117print info_admin(showModulesExludedForExternal($modules)).'<br>'."\n";
118
119print "\n";
120print '<div class="div-table-responsive-no-min">';
121print '<table class="noborder centpercent">';
122
123print '<tr class="liste_titre">';
124print '<td>'.$langs->trans("Module").'</td>';
125print '<td class="center">'.$langs->trans("Default").'</td>';
126print '<td class="center" width="24">&nbsp;</td>';
127print '<td>'.$langs->trans("Permissions").'</td>';
128if ($user->admin) {
129 print '<td class="right"></td>';
130}
131print '</tr>'."\n";
132
133//print "xx".$conf->global->MAIN_USE_ADVANCED_PERMS;
134$sql = "SELECT r.id, r.libelle as label, r.module, r.perms, r.subperms, r.module_position, r.bydefault";
135$sql .= " FROM ".MAIN_DB_PREFIX."rights_def as r";
136$sql .= " WHERE r.libelle NOT LIKE 'tou%'"; // On ignore droits "tous"
137$sql .= " AND r.entity = ".((int) $entity);
138if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
139 $sql .= " AND r.perms NOT LIKE '%_advance'"; // Hide advanced perms if option is not enabled
140}
141$sql .= " ORDER BY r.family_position, r.module_position, r.module, r.id";
142
143$result = $db->query($sql);
144if ($result) {
145 $num = $db->num_rows($result);
146 $i = 0;
147 $oldmod = '';
148
149 while ($i < $num) {
150 $obj = $db->fetch_object($result);
151
152 // If line is for a module that does not exist anymore (absent of includes/module), we ignore it
153 if (empty($modules[$obj->module])) {
154 $i++;
155 continue;
156 }
157
158 $objMod = $modules[$obj->module];
159
160 // Save field module_position in database if value is wrong
161 if (empty($obj->module_position) || (is_object($objMod) && $objMod->isCoreOrExternalModule() == 'external' && $obj->module_position < 100000)) {
162 if (is_object($modules[$obj->module]) && ($modules[$obj->module]->module_position > 0)) {
163 // TODO Define familyposition
164 //$familyposition = $modules[$obj->module]->family_position;
165 $familyposition = 0;
166
167 $newmoduleposition = $modules[$obj->module]->module_position;
168
169 // Correct $newmoduleposition position for external modules
170 $objMod = $modules[$obj->module];
171 if (is_object($objMod) && $objMod->isCoreOrExternalModule() == 'external' && $newmoduleposition < 100000) {
172 $newmoduleposition += 100000;
173 }
174
175 $sqlupdate = 'UPDATE '.MAIN_DB_PREFIX."rights_def SET module_position = ".((int) $newmoduleposition).",";
176 $sqlupdate .= " family_position = ".((int) $familyposition);
177 $sqlupdate .= " WHERE module_position = ".((int) $obj->module_position)." AND module = '".$db->escape($obj->module)."'";
178 $db->query($sqlupdate);
179 }
180 }
181
182 // Check if permission we found is inside a module definition. If not, we discard it.
183 $found = false;
184 foreach ($modules[$obj->module]->rights as $key => $val) {
185 if ($val[4] == $obj->perms && (empty($val[5]) || $val[5] == $obj->subperms)) {
186 $found = true;
187 break;
188 }
189 }
190 if (!$found) {
191 $i++;
192 continue;
193 }
194
195 // Break found, it's a new module to catch
196 if (isset($obj->module) && ($oldmod <> $obj->module)) {
197 $oldmod = $obj->module;
198
199 // Break detected, we get objMod
200 $objMod = $modules[$obj->module];
201 $picto = ($objMod->picto ? $objMod->picto : 'generic');
202
203 // Show break line
204 print '<tr class="oddeven trforbreak">';
205 print '<td class="maxwidthonsmartphone tdoverflowonsmartphone">';
206 print img_object('', $picto, 'class="pictoobjectwidth paddingright"').' '.$objMod->getName();
207 print '<a name="'.$objMod->getName().'"></a>';
208 print '</td>';
209 print '<td>&nbsp;</td>';
210 print '<td>&nbsp;</td>';
211 print '<td>&nbsp;</td>';
212 // Permission id
213 if ($user->admin) {
214 print '<td class="right"></td>';
215 }
216 print '</tr>'."\n";
217 }
218
219 print '<!-- '.$obj->module.'->'.$obj->perms.($obj->subperms ? '->'.$obj->subperms : '').' -->'."\n";
220 print '<tr class="oddeven">';
221
222 // Picto and label of module
223 print '<td class="maxwidthonsmartphone tdoverflowonsmartphone">';
224 //print img_object('', $picto, 'class="pictoobjectwidth"').' '.$objMod->getName();
225 print '</td>';
226
227 // Tick
228 if ($obj->bydefault == 1) {
229 print '<td class="center">';
230 print '<a class="reposition" href="perms.php?pid='.$obj->id.'&action=remove&token='.newToken().'">';
231 //print img_edit_remove();
232 print img_picto('', 'switch_on');
233 print '</a>';
234 print '</td>';
235 print '<td class="center">';
236 //print img_picto($langs->trans("Active"), 'tick');
237 print '</td>';
238 } else {
239 print '<td class="center">';
240 print '<a class="reposition" href="perms.php?pid='.$obj->id.'&action=add&token='.newToken().'">';
241 //print img_edit_add();
242 print img_picto('', 'switch_off');
243 print '</a>';
244 print '</td>';
245 print '<td class="center">';
246 print '&nbsp;';
247 print '</td>';
248 }
249
250 // Permission and tick
251 $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)));
252 print '<td>';
253 print $permlabel;
254 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
255 if (preg_match('/_advance$/', $obj->perms)) {
256 print ' <span class="opacitymedium">('.$langs->trans("AdvancedModeOnly").')</span>';
257 }
258 }
259 print '</td>';
260
261 // Permission id
262 if ($user->admin) {
263 print '<td class="right">';
264 $htmltext = $langs->trans("ID").': '.$obj->id;
265 $htmltext .= '<br>'.$langs->trans("Permission").': user->rights->'.$obj->module.'->'.$obj->perms.($obj->subperms ? '->'.$obj->subperms : '');
266 print $form->textwithpicto('', $htmltext);
267 //print '<span class="opacitymedium">'.$obj->id.'</span>';
268 print '</td>';
269 }
270
271 print '</tr>'."\n";
272
273 $i++;
274 }
275} else {
276 dol_print_error($db);
277}
278print '</table>';
279print '</div>';
280
281$parameters = array();
282$reshook = $hookmanager->executeHooks('insertExtraFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
283if ($reshook < 0) {
284 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
285}
286
287print dol_get_fiche_end();
288
289// End of page
290llxFooter();
291$db->close();
security_prepare_head()
Prepare array with list of tabs.
showModulesExludedForExternal($modules)
Show array with constants to edit.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:56
llxFooter()
Empty footer.
Definition wrapper.php:70
dolGetModulesDirs($subdir='')
Return list of modules directories.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.