5 * Copyright 2010-2011, Roland Mas
6 * Copyright (c) 2011 Thorsten Glaser <t.glaser@tarent.de>
8 * This file is part of FusionForge. FusionForge is free software;
9 * you can redistribute it and/or modify it under the terms of the
10 * GNU General Public License as published by the Free Software
11 * Foundation; either version 2 of the Licence, or (at your option)
14 * FusionForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 require_once '../env.inc.php';
25 require_once $gfcommon.'include/pre.php';
26 require_once $gfwww.'admin/admin_utils.php';
27 require_once $gfwww.'include/role_utils.php';
29 $role_id = getIntFromRequest('role_id');
30 $data = getStringFromRequest('data');
32 if (getStringFromRequest('add')) {
33 $role_name = trim(getStringFromRequest('role_name')) ;
34 $role = new Role (NULL) ;
35 $role_id=$role->createDefault($role_name) ;
37 $role = RBACEngine::getInstance()->getRoleById($role_id) ;
40 if (!$role || !is_object($role)) {
41 exit_error(_('Could Not Get Role'),'admin');
42 } elseif ($role->isError()) {
43 exit_error($role->getErrorMessage(),'admin');
46 $old_data = $role->getGlobalSettings () ;
47 $new_data = array () ;
49 if (!is_array ($data)) {
52 foreach ($old_data as $section => $values) {
53 if (!array_key_exists ($section, $data)) {
56 foreach ($values as $ref_id => $val) {
57 if (!array_key_exists ($ref_id, $data[$section])) {
60 $new_data[$section][$ref_id] = $data[$section][$ref_id] ;
65 if (getStringFromRequest('submit')) {
66 if ($role instanceof RoleExplicit) {
67 $role_name = trim(getStringFromRequest('role_name'));
68 $public = getIntFromRequest('public') ? true : false ;
70 $role_name = $role->getName() ;
71 $public = $role->isPublic () ;
74 $warning_msg .= ' Missing Role Name ';
77 $role_id=$role->create($role_name,$data);
79 $error_msg .= $role->getErrorMessage();
81 $feedback = _('Successfully Created New Role');
84 if ($role instanceof RoleExplicit) {
85 $role->setPublic($public) ;
87 if (!$role->update($role_name,$data)) {
88 $error_msg .= $role->getErrorMessage();
90 $feedback = _('Successfully Updated Role');
96 if (getStringFromRequest('adduser')) {
97 if ($role instanceof RoleExplicit) {
98 $user_name = getStringFromRequest ('form_unix_name') ;
99 $u = user_get_object_by_name ($user_name) ;
100 if ($u && $u instanceof GFUser && !$u->isError()) {
101 if ($role->addUser ($u)) {
102 $feedback .= _('User added successfully') ;
104 $error_msg .= _("Error while adding user to role") ;
108 $error_msg .= _("Can't add user to this type of role") ;
112 if (getStringFromRequest('dormusers')) {
113 $reallyremove = getStringFromRequest('reallyremove');
114 if (!$reallyremove) {
115 $error_msg .= _('ERROR: You did not tick the “really remove” box!');
116 } elseif ($role instanceof RoleExplicit) {
117 $rmlist = getArrayFromRequest('rmusers');
118 foreach ($rmlist as $user_id) {
119 $u = user_get_object ($user_id) ;
120 if ($u && $u instanceof GFUser && !$u->isError()) {
121 if ($role->removeUser ($u)) {
122 $feedback .= sprintf(
123 _('User %s removed successfully') . "\n",
126 $error_msg .= sprintf(
127 _("Error while removing user %s from role") . "\n",
133 $error_msg .= _("Can't remove user from this type of role") ;
138 site_admin_header(array('title'=>_('Site Admin')));
140 if ($role instanceof RoleExplicit) {
141 $users = $role->getUsers () ;
142 if (count ($users) > 0) {
143 echo '<p><strong>'._('Current users with this role').'</strong></p>' ;
146 <form action="'.util_make_url('/admin/globalroleedit.php').'" method="post">
147 <input type="hidden" name="role_id" value="'.$role_id.'" />
149 <th>'._('User name').'</th>
150 <th>'._('Remove').'</th>
151 </tr></thead><tbody>';
153 foreach ($users as $user) {
156 <td style="white-space:nowrap;">
157 <a href="/users/'.$user->getUnixName().'">';
158 $display = $user->getRealName();
159 if (empty($display)) {
160 $display = $user->getUnixName();
162 echo $display . '</a>
164 <input type="checkbox" name="rmusers[]" value="' .
165 $user->getID() . '" /> ' . _('Remove') . '
171 <input type="checkbox" name="reallyremove" value="1" />
172 ' . _('Really remove ticked users from role?') . '
173 </td></tr><tr><td colspan="2">
174 <input type="submit" name="dormusers" value="' .
177 </tbody></table></form>';
179 echo '<p><strong>'._('No users currently have this role').'</strong></p>' ;
184 action="<?php echo util_make_url('/admin/globalroleedit.php'); ?>"
186 <p><input type="text"
187 name="form_unix_name" size="10" value="" />
188 <input type="submit" name="adduser"
189 value="<?php echo _("Add User") ?>" />
190 <input type="hidden" name="role_id" value="<?php echo $role_id; ?>" />
197 <form action="'.util_make_url('/admin/globalroleedit.php').'" method="post">';
198 echo '<input type="hidden" name="role_id" value="'.$role_id.'" />';
200 if ($role instanceof RoleExplicit) {
201 echo '<p><strong>'._('Role Name').'</strong><br /><input type="text" name="role_name" value="'.$role->getName().'" /></p>';
202 echo '<input type="checkbox" name="public" value="1"' ;
203 if ($role->isPublic()) {
204 echo ' checked="checked"' ;
206 echo '/> '._('Public role (can be referenced by projects)');
208 echo '<p><strong>'._('Role Name').'</strong><br />'.$role->getName().'</p>';
211 $titles[]=_('Section');
212 $titles[]=_('Subsection');
213 $titles[]=_('Setting');
215 setup_rbac_strings () ;
217 echo $HTML->listTableTop($titles);
220 // Get the keys for this role and interate to build page
222 // Everything is built on the multi-dimensial arrays in the Role object
226 $keys = array_keys($role->getGlobalSettings ()) ;
228 foreach ($keys as $key) {
229 if (in_array ($key, $role->global_settings)) {
235 for ($i=0; $i<count($keys); $i++) {
236 echo '<tr '. $HTML->boxGetAltRowStyle($j++) . '>
237 <td colspan="2"><strong>'.$rbac_edit_section_names[$keys[$i]].'</strong></td>
239 echo html_build_select_box_from_assoc($role->getRoleVals($keys[$i]), "data[".$keys[$i]."][-1]", $role->getVal($keys[$i],-1), false, false ) ;
245 echo $HTML->listTableBottom();
247 echo '<p><input type="submit" name="submit" value="'._('Submit').'" /></p>
251 <form action="'.util_make_url('/admin/globalroledelete.php').'" method="post">';
252 echo '<input type="hidden" name="role_id" value="'.$role_id.'" />';
254 echo '<p><strong>'._('Delete role').'</strong></p>';
255 echo '<p><input type="checkbox" name="sure" value="1"/> '._("Really delete this role?");
256 echo '<input type="submit" name="submit" value="'._('Delete role').'" /></p>
259 site_admin_footer(array());
263 // c-file-style: "bsd"