[ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?php 2 /* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org> 4 * Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net> 5 * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.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, write to the Free Software 19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 * 21 * $Id: perms.php,v 1.15 2005/12/03 20:54:02 eldy Exp $ 22 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/user/perms.php,v $ 23 */ 24 25 /** 26 \file htdocs/user/perms.php 27 \brief Onglet user et permissions de la fiche utilisateur 28 \version $Revision: 1.15 $ 29 */ 30 31 32 require ("./pre.inc.php"); 33 34 $langs->load("users"); 35 36 37 $form = new Form($db); 38 39 $module=isset($_GET["module"])?$_GET["module"]:$_POST["module"]; 40 41 // Defini si peux modifier utilisateurs et permisssions 42 $caneditperms=($user->admin || $user->rights->user->user->creer); 43 44 45 46 /** 47 * Actions 48 */ 49 if ($_GET["action"] == 'addrights' && $caneditperms) 50 { 51 $edituser = new User($db,$_GET["id"]); 52 $edituser->addrights($_GET["rights"],$module); 53 } 54 55 if ($_GET["action"] == 'delrights' && $caneditperms) 56 { 57 $edituser = new User($db,$_GET["id"]); 58 $edituser->delrights($_GET["rights"],$module); 59 } 60 61 62 63 llxHeader('',$langs->trans("Permissions")); 64 65 66 /* ************************************************************************** */ 67 /* */ 68 /* Visu et edition */ 69 /* */ 70 /* ************************************************************************** */ 71 72 if ($_GET["id"]) 73 { 74 $fuser = new User($db, $_GET["id"]); 75 $fuser->fetch(); 76 $fuser->getrights(); 77 78 /* 79 * Affichage onglets 80 */ 81 82 $h = 0; 83 84 $head[$h][0] = DOL_URL_ROOT.'/user/fiche.php?id='.$fuser->id; 85 $head[$h][1] = $langs->trans("UserCard"); 86 $h++; 87 88 $head[$h][0] = DOL_URL_ROOT.'/user/perms.php?id='.$fuser->id; 89 $head[$h][1] = $langs->trans("UserRights"); 90 $hselected=$h; 91 $h++; 92 93 $head[$h][0] = DOL_URL_ROOT.'/user/param_ihm.php?id='.$fuser->id; 94 $head[$h][1] = $langs->trans("UserGUISetup"); 95 $h++; 96 97 if ($conf->bookmark4u->enabled) 98 { 99 $head[$h][0] = DOL_URL_ROOT.'/user/addon.php?id='.$fuser->id; 100 $head[$h][1] = $langs->trans("Bookmark4u"); 101 $h++; 102 } 103 104 if ($conf->clicktodial->enabled) 105 { 106 $head[$h][0] = DOL_URL_ROOT.'/user/clicktodial.php?id='.$fuser->id; 107 $head[$h][1] = $langs->trans("ClickToDial"); 108 $h++; 109 } 110 111 dolibarr_fiche_head($head, $hselected, $langs->trans("User").": ".$fuser->fullname); 112 113 $db->begin(); 114 115 // Charge les modules soumis a permissions 116 $dir = DOL_DOCUMENT_ROOT . "/includes/modules/"; 117 $handle=opendir($dir); 118 $modules = array(); 119 while (($file = readdir($handle))!==false) 120 { 121 if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, strlen($file) - 10) == '.class.php') 122 { 123 $modName = substr($file, 0, strlen($file) - 10); 124 125 if ($modName) 126 { 127 include_once("../includes/modules/$file"); 128 $objMod = new $modName($db); 129 if ($objMod->rights_class) { 130 131 $ret=$objMod->insert_permissions(); 132 133 $modules[$objMod->rights_class]=$objMod; 134 //print "modules[".$objMod->rights_class."]=$objMod;"; 135 } 136 } 137 } 138 } 139 140 $db->commit(); 141 142 // Lecture des droits utilisateurs 143 $permsuser = array(); 144 145 $sql = "SELECT r.id, r.libelle, r.module"; 146 $sql .= " FROM ".MAIN_DB_PREFIX."rights_def as r,"; 147 $sql .= " ".MAIN_DB_PREFIX."user_rights as ur"; 148 $sql .= " WHERE ur.fk_id = r.id AND ur.fk_user = ".$fuser->id; 149 150 $result=$db->query($sql); 151 if ($result) 152 { 153 $num = $db->num_rows($result); 154 $i = 0; 155 while ($i < $num) 156 { 157 $obj = $db->fetch_object($result); 158 array_push($permsuser,$obj->id); 159 $i++; 160 } 161 $db->free($result); 162 } 163 else 164 { 165 dolibarr_print_error($db); 166 } 167 168 // Lecture des droits groupes 169 $permsgroup = array(); 170 171 $sql = "SELECT r.id, r.libelle, r.module"; 172 $sql .= " FROM ".MAIN_DB_PREFIX."rights_def as r,"; 173 $sql .= " ".MAIN_DB_PREFIX."usergroup_rights as gr,"; 174 $sql .= " ".MAIN_DB_PREFIX."usergroup_user as gu"; 175 $sql .= " WHERE gr.fk_id = r.id AND gr.fk_usergroup = gu.fk_usergroup AND gu.fk_user = ".$fuser->id; 176 177 $result=$db->query($sql); 178 if ($result) 179 { 180 $num = $db->num_rows($result); 181 $i = 0; 182 while ($i < $num) 183 { 184 $obj = $db->fetch_object($result); 185 array_push($permsgroup,$obj->id); 186 $i++; 187 } 188 $db->free($result); 189 } 190 else 191 { 192 dolibarr_print_error($db); 193 } 194 195 196 /* 197 * Ecran ajout/suppression permission 198 */ 199 200 print '<table width="100%" class="noborder">'; 201 print '<tr class="liste_titre">'; 202 print '<td>'.$langs->trans("Module").'</td>'; 203 if ($caneditperms) print '<td width="24"> </td>'; 204 print '<td align="center" width="24"> </td>'; 205 print '<td>'.$langs->trans("Permissions").'</td>'; 206 print '</tr>'; 207 208 $sql ="SELECT r.id, r.libelle, r.module"; 209 $sql.=" FROM ".MAIN_DB_PREFIX."rights_def as r"; 210 $sql.=" WHERE r.libelle NOT LIKE 'tou%'"; // On ignore droits "tous" 211 $sql.=" ORDER BY r.module, r.id"; 212 213 $result=$db->query($sql); 214 if ($result) 215 { 216 $num = $db->num_rows($result); 217 $i = 0; 218 $var = True; 219 while ($i < $num) 220 { 221 $obj = $db->fetch_object($result); 222 223 // Si la ligne correspond a un module qui n'existe plus (absent de includes/module), on l'ignore 224 if (! $modules[$obj->module]) 225 { 226 $i++; 227 continue; 228 } 229 230 if ($oldmod <> $obj->module) 231 { 232 $oldmod = $obj->module; 233 $var = !$var; 234 235 // Rupture détectée, on récupère objMod 236 $objMod=$modules[$obj->module]; 237 $picto=($objMod->picto?$objMod->picto:'generic'); 238 239 if ($caneditperms && ($obj->module != 'user' || ! $fuser->admin)) 240 { 241 // On affiche ligne pour modifier droits 242 print '<tr '. $bc[$var].'>'; 243 print '<td>'.img_object('',$picto).' '.$objMod->getName(); 244 print '<a name="'.$objMod->getName().'"> </a></td>'; 245 print '<td align="center" nowrap>'; 246 print '<a title='.$langs->trans("All").' alt='.$langs->trans("All").' href="perms.php?id='.$fuser->id.'&action=addrights&module='.$obj->module.'">'.$langs->trans("All")."</a>"; 247 print '/'; 248 print '<a title='.$langs->trans("None").' alt='.$langs->trans("None").' href="perms.php?id='.$fuser->id.'&action=delrights&module='.$obj->module.'">'.$langs->trans("None")."</a>"; 249 print '</td>'; 250 print '<td colspan="2"> </td>'; 251 print '</tr>'; 252 } 253 } 254 255 print '<tr '. $bc[$var].'>'; 256 257 print '<td>'.img_object('',$picto).' '.$objMod->getName(); 258 print '</td>'; 259 260 if ($fuser->admin && $obj->module == 'user') 261 { 262 // Permission own because admin 263 if ($caneditperms) 264 { 265 print '<td align="center">'.img_picto($langs->trans("Administrator"),'star').'</td>'; 266 } 267 print '<td align="center" nowrap>'; 268 print img_tick(); 269 print '</td>'; 270 } 271 else if (in_array($obj->id, $permsuser)) 272 { 273 // Permission own by user 274 if ($caneditperms) 275 { 276 print '<td align="center"><a href="perms.php?id='.$fuser->id.'&action=delrights&rights='.$obj->id.'">'.img_edit_remove($langs->trans("Remove")).'</a></td>'; 277 } 278 print '<td align="center">'; 279 print img_tick(); 280 print '</td>'; 281 } 282 else if (in_array($obj->id, $permsgroup)) { 283 // Permission own by group 284 if ($caneditperms) 285 { 286 print '<td align="center">'.$langs->trans("Group").'</td>'; 287 } 288 print '<td align="center" nowrap>'; 289 print img_tick(); 290 print '</td>'; 291 } 292 else 293 { 294 // Do not own permission 295 if ($caneditperms) 296 { 297 print '<td align="center"><a href="perms.php?id='.$fuser->id.'&action=addrights&rights='.$obj->id.'">'.img_edit_add($langs->trans("Add")).'</a></td>'; 298 } 299 print '<td> </td>'; 300 } 301 302 $perm_libelle=(($langs->trans("Permission".$obj->id)!=("Permission".$obj->id))?$langs->trans("Permission".$obj->id):$obj->libelle); 303 print '<td>'.$perm_libelle. '</td>'; 304 305 print '</tr>'; 306 307 $i++; 308 } 309 } 310 print '</table>'; 311 } 312 313 $db->close(); 314 315 llxFooter('$Date: 2005/12/03 20:54:02 $ - $Revision: 1.15 $'); 316 317 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 12:29:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |