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