dolibarr  7.0.0-beta
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@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 
27 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
30 
31 $langs->load("admin");
32 $langs->load("users");
33 $langs->load("other");
34 
35 $action=GETPOST('action','aZ09');
36 
37 if (!$user->admin) accessforbidden();
38 
39 
40 /*
41  * Actions
42  */
43 
44 if ($action == 'add')
45 {
46  $sql = "UPDATE ".MAIN_DB_PREFIX."rights_def SET bydefault=1";
47  $sql.= " WHERE id = ".GETPOST("pid",'int');
48  $sql.= " AND entity = ".$conf->entity;
49  $db->query($sql);
50 }
51 
52 if ($action == 'remove')
53 {
54  $sql = "UPDATE ".MAIN_DB_PREFIX."rights_def SET bydefault=0";
55  $sql.= " WHERE id = ".GETPOST('pid','int');
56  $sql.= " AND entity = ".$conf->entity;
57  $db->query($sql);
58 }
59 
60 
61 /*
62  * View
63  */
64 
65 $wikihelp='EN:Setup_Security|FR:Paramétrage_Sécurité|ES:Configuración_Seguridad';
66 llxHeader('',$langs->trans("DefaultRights"), $wikihelp);
67 
68 print load_fiche_titre($langs->trans("SecuritySetup"),'','title_setup');
69 
70 print $langs->trans("DefaultRightsDesc");
71 print " ".$langs->trans("OnlyActiveElementsAreShown")."<br><br>\n";
72 
73 $db->begin();
74 
75 // Charge les modules soumis a permissions
76 $modules = array();
77 $modulesdir = dolGetModulesDirs();
78 
79 foreach ($modulesdir as $dir)
80 {
81  // Load modules attributes in arrays (name, numero, orders) from dir directory
82  //print $dir."\n<br>";
83  $handle=@opendir(dol_osencode($dir));
84  if (is_resource($handle))
85  {
86  while (($file = readdir($handle))!==false)
87  {
88  if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php')
89  {
90  $modName = substr($file, 0, dol_strlen($file) - 10);
91  if ($modName)
92  {
93  include_once $dir.$file;
94  $objMod = new $modName($db);
95 
96  // Load all lang files of module
97  if (isset($objMod->langfiles) && is_array($objMod->langfiles))
98  {
99  foreach($objMod->langfiles as $domain)
100  {
101  $langs->load($domain);
102  }
103  }
104  // Load all permissions
105  if ($objMod->rights_class)
106  {
107  $ret=$objMod->insert_permissions(0);
108  $modules[$objMod->rights_class]=$objMod;
109  //print "modules[".$objMod->rights_class."]=$objMod;";
110  }
111  }
112  }
113  }
114  }
115 }
116 
117 $db->commit();
118 
119 $head=security_prepare_head();
120 
121 dol_fiche_head($head, 'default', $langs->trans("Security"), -1);
122 
123 
124 // Show warning about external users
125 print info_admin(showModulesExludedForExternal($modules)).'<br>'."\n";
126 
127 print '<div class="div-table-responsive-no-min">';
128 print '<table class="noborder" width="100%">';
129 
130 // Affiche lignes des permissions
131 $sql = "SELECT r.id, r.libelle, r.module, r.perms, r.subperms, r.bydefault";
132 $sql.= " FROM ".MAIN_DB_PREFIX."rights_def as r";
133 $sql.= " WHERE r.libelle NOT LIKE 'tou%'"; // On ignore droits "tous"
134 $sql.= " AND entity = ".$conf->entity;
135 if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) $sql.= " AND r.perms NOT LIKE '%_advance'"; // Hide advanced perms if option is not enabled
136 $sql.= " ORDER BY r.module, r.id";
137 
138 $result = $db->query($sql);
139 if ($result)
140 {
141  $num = $db->num_rows($result);
142  $i = 0;
143  $oldmod = "";
144 
145  while ($i < $num)
146  {
147  $obj = $db->fetch_object($result);
148 
149  // Si la ligne correspond a un module qui n'existe plus (absent de includes/module), on l'ignore
150  if (! $modules[$obj->module])
151  {
152  $i++;
153  continue;
154  }
155 
156  // Check if permission we found is inside a module definition. If not, we discard it.
157  $found=false;
158  foreach($modules[$obj->module]->rights as $key => $val)
159  {
160  $rights_class=$objMod->rights_class;
161  if ($val[4] == $obj->perms && (empty($val[5]) || $val[5] == $obj->subperms))
162  {
163  $found=true;
164  break;
165  }
166  }
167  if (! $found)
168  {
169  $i++;
170  continue;
171  }
172 
173  // Break found, it's a new module to catch
174  if ($oldmod <> $obj->module)
175  {
176  $oldmod = $obj->module;
177  $objMod = $modules[$obj->module];
178  $picto = ($objMod->picto?$objMod->picto:'generic');
179 
180  print '<tr class="liste_titre">';
181  print '<td>'.$langs->trans("Module").'</td>';
182  print '<td>'.$langs->trans("Permission").'</td>';
183  print '<td align="center">'.$langs->trans("Default").'</td>';
184  print '<td align="center">&nbsp;</td>';
185  print "</tr>\n";
186  }
187 
188 
189  print '<tr class="oddeven">';
190  print '<td>';
191  print img_object('',$picto,'class="pictoobjectwidth"').' '.$objMod->getName();
192  print '<a name="'.$objMod->getName().'">&nbsp;</a>';
193  print '</td>';
194 
195  $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));
196  print '<td>'.$perm_libelle. '</td>';
197 
198  print '<td align="center">';
199  if ($obj->bydefault == 1)
200  {
201  print img_picto($langs->trans("Active"),'tick');
202  print '</td><td>';
203  print '<a class="reposition" href="perms.php?pid='.$obj->id.'&amp;action=remove">'.img_edit_remove().'</a>';
204  }
205  else
206  {
207  print '&nbsp;';
208  print '</td><td>';
209  print '<a class="reposition" href="perms.php?pid='.$obj->id.'&amp;action=add">'.img_edit_add().'</a>';
210  }
211 
212  print '</td></tr>';
213  $i++;
214  }
215 }
216 
217 print '</table>';
218 print '</div>';
219 
220 dol_fiche_end();
221 
222 llxFooter();
223 $db->close();
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
llxFooter()
Empty footer.
Definition: wrapper.php:58
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it's its name (generic function)
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
dolGetModulesDirs($subdir='')
Return list of modules directories.
showModulesExludedForExternal($modules)
Show array with constants to edit.
Definition: admin.lib.php:1469
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1')
Show information for admin users or standard users.
if(GETPOST('button_removefilter_x','alpha')||GETPOST('button_removefilter.x','alpha')||GETPOST('button_removefilter','alpha')) if($action=="save"&&empty($cancel)) if(preg_match('/set_(.*)/', $action, $reg)) if(preg_match('/del_(.*)/', $action, $reg) $wikihelp)
View.
Definition: agenda.php:143
dol_fiche_end($notab=0)
Show tab footer of a card.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
security_prepare_head()
Prepare array with list of tabs.
Definition: admin.lib.php:581
img_edit_add($titlealt= 'default', $other= '')
Show logo +.
print
Draft customers invoices.
Definition: index.php:91
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
img_edit_remove($titlealt= 'default', $other='')
Show logo -.