/
perms.php
400 lines (341 loc) · 12.6 KB
/
perms.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
<?php
/* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/user/perms.php
* \brief Onglet user et permissions de la fiche utilisateur
* \version $Id: perms.php,v 1.57 2011/08/01 13:15:54 hregis Exp $
*/
require("../main.inc.php");
require_once(DOL_DOCUMENT_ROOT."/lib/usergroups.lib.php");
$langs->load("users");
$langs->load("admin");
$module=isset($_GET["module"])?$_GET["module"]:$_POST["module"];
$id = GETPOST('id','int');
if (! $id) accessforbidden();
// Defini si peux lire les permissions
$canreaduser=($user->admin || $user->rights->user->user->lire);
// Defini si peux modifier les autres utilisateurs et leurs permisssions
$caneditperms=($user->admin || $user->rights->user->user->creer);
// Advanced permissions
if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS))
{
$canreaduser=($user->admin || ($user->rights->user->user->lire && $user->rights->user->user_advance->readperms));
$caneditselfperms=($user->id == $id && $user->rights->user->self_advance->writeperms);
$caneditperms = (($caneditperms || $caneditselfperms) ? 0 : 1);
}
// Security check
$socid=0;
if ($user->societe_id > 0) $socid = $user->societe_id;
$feature2 = (($socid && $user->rights->user->self->creer)?'':'user');
if ($user->id == $id && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->user->self_advance->readperms)) // A user can always read its own card if not advanced perms enabled, or if he has advanced perms
{
$feature2='';
$canreaduser=1;
}
$result = restrictedArea($user, 'user', $id, '', $feature2);
if ($user->id <> $_REQUEST["id"] && ! $canreaduser) accessforbidden();
/**
* Actions
*/
if ($_GET["action"] == 'addrights' && $caneditperms)
{
$edituser = new User($db);
$edituser->fetch($id);
$edituser->addrights($_GET["rights"],$module);
// Si on a touche a ses propres droits, on recharge
if ($id == $user->id)
{
$user->clearrights();
$user->getrights();
}
}
if ($_GET["action"] == 'delrights' && $caneditperms)
{
$edituser = new User($db);
$edituser->fetch($id);
$edituser->delrights($_GET["rights"],$module);
// Si on a touche a ses propres droits, on recharge
if ($id == $user->id)
{
$user->clearrights();
$user->getrights();
}
}
/* ************************************************************************** */
/* */
/* Visu et edition */
/* */
/* ************************************************************************** */
llxHeader('',$langs->trans("Permissions"));
$form=new Form($db);
$fuser = new User($db);
$fuser->fetch($id);
$fuser->getrights();
/*
* Affichage onglets
*/
$head = user_prepare_head($fuser);
$title = $langs->trans("User");
dol_fiche_head($head, 'rights', $title, 0, 'user');
$db->begin();
// Search all modules with permission and reload permissions def.
$modules = array();
$modulesdir = array();
foreach ($conf->file->dol_document_root as $type => $dirroot)
{
$modulesdir[] = $dirroot . "/includes/modules/";
if ($type == 'alt')
{
$handle=@opendir($dirroot);
if (is_resource($handle))
{
while (($file = readdir($handle))!==false)
{
if (is_dir($dirroot.'/'.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && $file != 'includes')
{
if (is_dir($dirroot . '/' . $file . '/includes/modules/'))
{
$modulesdir[] = $dirroot . '/' . $file . '/includes/modules/';
}
}
}
closedir($handle);
}
}
}
foreach($modulesdir as $dir)
{
$handle=@opendir($dir);
if (is_resource($handle))
{
while (($file = readdir($handle))!==false)
{
if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php')
{
$modName = substr($file, 0, dol_strlen($file) - 10);
if ($modName)
{
include_once($dir.$file);
$objMod = new $modName($db);
// Load all lang files of module
if (isset($objMod->langfiles) && is_array($objMod->langfiles))
{
foreach($objMod->langfiles as $domain)
{
$langs->load($domain);
}
}
// Load all permissions
if ($objMod->rights_class) {
$ret=$objMod->insert_permissions(0);
$modules[$objMod->rights_class]=$objMod;
//print "modules[".$objMod->rights_class."]=$objMod;";
}
}
}
}
}
}
$db->commit();
// Lecture des droits utilisateurs
$permsuser = array();
$sql = "SELECT r.id, r.libelle, r.module";
$sql.= " FROM ".MAIN_DB_PREFIX."rights_def as r,";
$sql.= " ".MAIN_DB_PREFIX."user_rights as ur";
$sql.= " WHERE ur.fk_id = r.id";
$sql.= " AND r.entity = ".$conf->entity;
$sql.= " AND ur.fk_user = ".$fuser->id;
$result=$db->query($sql);
if ($result)
{
$num = $db->num_rows($result);
$i = 0;
while ($i < $num)
{
$obj = $db->fetch_object($result);
array_push($permsuser,$obj->id);
$i++;
}
$db->free($result);
}
else
{
dol_print_error($db);
}
// Lecture des droits groupes
$permsgroup = array();
$sql = "SELECT r.id, r.libelle, r.module";
$sql.= " FROM ".MAIN_DB_PREFIX."rights_def as r,";
$sql.= " ".MAIN_DB_PREFIX."usergroup_rights as gr,";
$sql.= " ".MAIN_DB_PREFIX."usergroup_user as gu";
$sql.= " WHERE gr.fk_id = r.id";
$sql.= " AND r.entity = ".$conf->entity;
$sql.= " AND gu.entity IN (0,".$conf->entity.")";
$sql.= " AND gr.fk_usergroup = gu.fk_usergroup";
$sql.= " AND gu.fk_user = ".$fuser->id;
$result=$db->query($sql);
if ($result)
{
$num = $db->num_rows($result);
$i = 0;
while ($i < $num)
{
$obj = $db->fetch_object($result);
array_push($permsgroup,$obj->id);
$i++;
}
$db->free($result);
}
else
{
dol_print_error($db);
}
/*
* Ecran ajout/suppression permission
*/
print '<table class="border" width="100%">';
// Ref
print '<tr><td width="25%" valign="top">'.$langs->trans("Ref").'</td>';
print '<td>';
print $form->showrefnav($fuser,'id','',$user->rights->user->user->lire || $user->admin);
print '</td>';
print '</tr>'."\n";
// Nom
print '<tr><td width="25%" valign="top">'.$langs->trans("Lastname").'</td>';
print '<td>'.$fuser->nom.'</td>';
print '</tr>'."\n";
// Prenom
print '<tr><td width="25%" valign="top">'.$langs->trans("Firstname").'</td>';
print '<td>'.$fuser->prenom.'</td>';
print '</tr>'."\n";
print '</table><br>';
if ($user->admin) print info_admin($langs->trans("WarningOnlyPermissionOfActivatedModules"));
print "\n";
print '<table width="100%" class="noborder">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Module").'</td>';
if ($caneditperms) print '<td> </td>';
print '<td align="center" width="24"> </td>';
print '<td>'.$langs->trans("Permissions").'</td>';
print '</tr>'."\n";
//print "xx".$conf->global->MAIN_USE_ADVANCED_PERMS;
$sql = "SELECT r.id, r.libelle, r.module";
$sql.= " FROM ".MAIN_DB_PREFIX."rights_def as r";
$sql.= " WHERE r.libelle NOT LIKE 'tou%'"; // On ignore droits "tous"
$sql.= " AND r.entity = ".$conf->entity;
if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) $sql.= " AND r.perms NOT LIKE '%_advance'"; // Hide advanced perms if option is disable
$sql.= " ORDER BY r.module, r.id";
$result=$db->query($sql);
if ($result)
{
$num = $db->num_rows($result);
$i = 0;
$var = True;
while ($i < $num)
{
$obj = $db->fetch_object($result);
// Si la ligne correspond a un module qui n'existe plus (absent de includes/module), on l'ignore
if (! $modules[$obj->module])
{
$i++;
continue;
}
if ($oldmod <> $obj->module)
{
$oldmod = $obj->module;
$var = !$var;
// Rupture detectee, on recupere objMod
$objMod=$modules[$obj->module];
$picto=($objMod->picto?$objMod->picto:'generic');
if ($caneditperms && (! $objMod->rights_admin_allowed || ! $fuser->admin))
{
// On affiche ligne pour modifier droits
print '<tr '. $bc[$var].'>';
print '<td nowrap="nowrap">'.img_object('',$picto).' '.$objMod->getName();
print '<a name="'.$objMod->getName().'"> </a></td>';
print '<td align="center" nowrap="nowrap">';
print '<a title="'.dol_escape_htmltag($langs->trans("All")).'" alt="'.dol_escape_htmltag($langs->trans("All")).'" href="perms.php?id='.$fuser->id.'&action=addrights&module='.$obj->module.'#'.$objMod->getName().'">'.$langs->trans("All")."</a>";
print '/';
print '<a title="'.dol_escape_htmltag($langs->trans("None")).'" alt="'.dol_escape_htmltag($langs->trans("None")).'" href="perms.php?id='.$fuser->id.'&action=delrights&module='.$obj->module.'#'.$objMod->getName().'">'.$langs->trans("None")."</a>";
print '</td>';
print '<td colspan="2"> </td>';
print '</tr>'."\n";
}
}
print '<tr '. $bc[$var].'>';
// Picto and label of permission
print '<td>'.img_object('',$picto).' '.$objMod->getName();
print '</td>';
// Permission and tick
if ($fuser->admin && $objMod->rights_admin_allowed)
{
// Permission own because admin
if ($caneditperms)
{
print '<td align="center">'.img_picto($langs->trans("Administrator"),'star').'</td>';
}
print '<td align="center" nowrap="nowrap">';
print img_tick();
print '</td>';
}
else if (in_array($obj->id, $permsuser))
{
// Permission own by user
if ($caneditperms)
{
print '<td align="center"><a href="perms.php?id='.$fuser->id.'&action=delrights&rights='.$obj->id.'#'.$objMod->getName().'">'.img_edit_remove($langs->trans("Remove")).'</a></td>';
}
print '<td align="center" nowrap="nowrap">';
print img_tick();
print '</td>';
}
else if (in_array($obj->id, $permsgroup)) {
// Permission own by group
if ($caneditperms)
{
print '<td align="center">';
print $form->textwithtooltip($langs->trans("Inherited"),$langs->trans("PermissionInheritedFromAGroup"));
//print '<a href="'.DOL_URL_ROOT.'/user/fiche.php?id='.$fuser->id.'" title="'.$langs->trans("PermissionInheritedFromAGroup").'">';
print '</td>';
}
print '<td align="center" nowrap="nowrap">';
print img_tick();
print '</td>';
}
else
{
// Do not own permission
if ($caneditperms)
{
print '<td align="center"><a href="perms.php?id='.$fuser->id.'&action=addrights&rights='.$obj->id.'#'.$objMod->getName().'">'.img_edit_add($langs->trans("Add")).'</a></td>';
}
print '<td> </td>';
}
$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));
print '<td>'.$perm_libelle. '</td>';
print '</tr>'."\n";
$i++;
}
}
print '</table>';
$db->close();
llxFooter('$Date: 2011/08/01 13:15:54 $ - $Revision: 1.57 $');
?>