5 * Copyright 2004 (c) GForge LLC
6 * Copyright 2010, Roland Mas
7 * Copyright (C) 2011 Alain Peyrat - Alcatel-Lucent
9 * Thorsten Glaser <t.glaser@tarent.de>
11 * This file is part of FusionForge. FusionForge is free software;
12 * you can redistribute it and/or modify it under the terms of the
13 * GNU General Public License as published by the Free Software
14 * Foundation; either version 2 of the Licence, or (at your option)
17 * FusionForge is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 require_once '../../env.inc.php';
28 require_once $gfcommon.'include/pre.php';
29 require_once $gfwww.'project/admin/project_admin_utils.php';
30 require_once $gfcommon.'include/Role.class.php';
31 require_once $gfcommon.'include/rbac_texts.php';
33 $group_id = getIntFromRequest('group_id');
34 session_require_perm ('project_admin', $group_id) ;
36 $role_id = getStringFromRequest('role_id');
37 $data = getStringFromRequest('data');
39 $group = group_get_object($group_id);
41 if (getStringFromRequest('delete')) {
42 session_redirect('/project/admin/roledelete.php?group_id='.$group_id.'&role_id='.$role_id);
45 if (getStringFromRequest('add')) {
46 $role_name = trim(getStringFromRequest('role_name')) ;
47 $role = new Role ($group) ;
48 $role_id=$role->createDefault($role_name) ;
50 $role = RBACEngine::getInstance()->getRoleById($role_id) ;
52 if (!$role || !is_object($role)) {
53 exit_error(_('Could Not Get Role'),'admin');
54 } elseif ($role->isError()) {
55 exit_error($role->getErrorMessage(),'admin');
58 $old_data = $role->getSettingsForProject ($group) ;
59 $new_data = array () ;
61 if (!is_array ($data)) {
64 foreach ($old_data as $section => $values) {
65 if (!array_key_exists ($section, $data)) {
68 foreach ($values as $ref_id => $val) {
69 if (!array_key_exists ($ref_id, $data[$section])) {
72 $new_data[$section][$ref_id] = $data[$section][$ref_id] ;
76 if (getStringFromRequest('submit')) {
77 if (($role->getHomeProject() != NULL)
78 && ($role->getHomeProject()->getID() == $group_id)) {
79 $role_name = trim(getStringFromRequest('role_name'));
80 $public = getIntFromRequest('public') ? true : false ;
82 $role_name = $role->getName() ;
83 $public = $role->isPublic() ;
86 $error_msg .= ' Missing Role Name ';
89 $role_id = $role->create($role_name, $data);
91 $error_msg .= $role->getErrorMessage();
93 $feedback = _('Successfully Created New Role');
96 if ($role instanceof RoleExplicit) {
97 $role->setPublic($public) ;
99 if (!$role->update($role_name, $data, false)) {
100 $error_msg .= $role->getErrorMessage();
102 $feedback = _('Successfully Updated Role');
106 //change assistant for webcal
107 $params = getIntFromRequest('group_id');
108 plugin_hook('change_cal_permission_auto', $params);
113 $title= _('New Role');
115 $title= _('Edit Role');
117 $msg = _('Use this page to edit the permissions attached to each role. Note that each role has at least as much access as the Anonymous and LoggedIn roles. For example, if the Anonymous role has read access to a forum, all other roles will have it too.');
119 project_admin_header(array('title'=> $title, 'group'=>$group_id));
121 echo '<p>'.$msg.'</p>';
123 <form action="'.getStringFromServer('PHP_SELF').'?group_id='.$group_id.'&role_id='. $role_id .'" method="post">';
125 if ($role->getHomeProject() == NULL
126 || $role->getHomeProject()->getID() != $group_id) {
127 echo '<p><strong>'._('Role Name').'</strong></p>' ;
128 echo $role->getDisplayableName ($group) ;
130 echo '<p><strong>'._('Role Name').'</strong><br /><input type="text" name="role_name" value="'.$role->getName().'" /><br />' ;
131 echo '<input type="checkbox" name="public" value="1"' ;
132 if ($role->isPublic()) {
133 echo ' checked="checked"' ;
135 echo ' /> '._('Shared role (can be referenced by other projects)').'</p>' ;
138 $titles[]=_('Section');
139 $titles[]=_('Subsection');
140 $titles[]=_('Setting');
142 setup_rbac_strings();
144 echo $HTML->listTableTop($titles);
147 // Get the keys for this role and interate to build page
149 // Everything is built on the multi-dimensial arrays in the Role object
152 $keys = array_keys($role->getSettingsForProject ($group)) ;
154 foreach ($keys as $key) {
155 if (!in_array ($key, $role->global_settings)) {
160 for ($i=0; $i<count($keys); $i++) {
161 if ((!$group->usesForum() && preg_match("/forum/", $keys[$i])) ||
162 (!$group->usesTracker() && preg_match("/tracker/", $keys[$i])) ||
163 (!$group->usesPM() && preg_match("/pm/", $keys[$i])) ||
164 (!$group->usesFRS() && preg_match("/frs/", $keys[$i])) ||
165 (!$group->usesSCM() && preg_match("/scm/", $keys[$i])) ||
166 (!$group->usesDocman() && preg_match("/docman/", $keys[$i]))) {
167 // We don't display modules not used
171 if ($keys[$i] == 'webcal') continue;
173 if (preg_match("/^plugin_([a-z]*)/", $keys[$i], $matches)) {
175 if (!$group->usesPlugin($p)) {
176 // We don't display settings for unused plugins either
181 if ($keys[$i] == 'forum' || $keys[$i] == 'forumpublic' || $keys[$i] == 'forumanon') {
183 // Handle forum settings for all roles
186 if ($keys[$i] == 'forumanon') {
187 //skip as we have special case below
189 $res=db_query_params ('SELECT group_forum_id,forum_name
190 FROM forum_group_list WHERE group_id=$1',
192 for ($q=0; $q<db_numrows($res); $q++) {
194 // Special cases - when going through the keys, we want to show trackeranon
195 // on the same line as tracker public
197 if ($keys[$i] == 'forumpublic') {
198 $txt=' '.html_build_select_box_from_assoc(
199 $role->getRoleVals('forumanon'),
200 "data[forumanon][".db_result($res,$q,'group_forum_id')."]",
201 $role->getVal('forumanon',db_result($res,$q,'group_forum_id')),
206 echo '<tr ' . $HTML->boxGetAltRowStyle($j++) . '>
207 <td style="padding-left: 4em;">'.$rbac_edit_section_names[$keys[$i]].'</td>
208 <td>'.db_result($res,$q,'forum_name').'</td>
209 <td>'.html_build_select_box_from_assoc(
210 $role->getRoleVals($keys[$i]),
211 "data[".$keys[$i]."][".db_result($res,$q,'group_forum_id')."]",
212 $role->getVal($keys[$i],db_result($res,$q,'group_forum_id')),
213 false, false ). $txt .'</td></tr>';
217 // Handle task mgr settings for all roles
219 } elseif ($keys[$i] == 'pm' || $keys[$i] == 'pmpublic') {
221 $res=db_query_params ('SELECT group_project_id,project_name
222 FROM project_group_list WHERE group_id=$1',
224 for ($q=0; $q<db_numrows($res); $q++) {
225 echo '<tr '. $HTML->boxGetAltRowStyle($j++) . '>
226 <td style="padding-left: 4em;">'.$rbac_edit_section_names[$keys[$i]].'</td>
227 <td>'.db_result($res,$q,'project_name').'</td>
228 <td>'.html_build_select_box_from_assoc(
229 $role->getRoleVals($keys[$i]),
230 "data[".$keys[$i]."][".db_result($res,$q,'group_project_id')."]",
231 $role->getVal($keys[$i],db_result($res,$q,'group_project_id')),
232 false, false ).'</td></tr>';
236 // Handle tracker settings for all roles
238 } elseif ($keys[$i] == 'tracker' || $keys[$i] == 'trackerpublic' || $keys[$i] == 'trackeranon') {
240 if ($keys[$i] == 'trackeranon') {
241 //skip as we have special case below
243 $res=db_query_params ('SELECT group_artifact_id,name
244 FROM artifact_group_list WHERE group_id=$1',
246 for ($q=0; $q<db_numrows($res); $q++) {
248 // Special cases - when going through the keys, we want to show trackeranon
249 // on the same line as tracker public
251 if ($keys[$i] == 'trackerpublic') {
252 $txt = ' '.html_build_select_box_from_assoc(
253 $role->getRoleVals('trackeranon'),
254 "data[trackeranon][".db_result($res,$q,'group_artifact_id')."]",
255 $role->getVal('trackeranon',db_result($res,$q,'group_artifact_id')),
260 echo '<tr '. $HTML->boxGetAltRowStyle($j++) . '>
261 <td style="padding-left: 4em;">'.$rbac_edit_section_names[$keys[$i]].'</td>
262 <td>'.db_result($res,$q,'name').'</td>
263 <td>'.html_build_select_box_from_assoc(
264 $role->getRoleVals($keys[$i]),
265 "data[".$keys[$i]."][".db_result($res,$q,'group_artifact_id')."]",
266 $role->getVal($keys[$i],db_result($res,$q,'group_artifact_id')),
267 false, false ). $txt .'</td></tr>';
272 // File release system - each package can be public/private
274 } elseif ($keys[$i] == 'frspackage') {
276 $res=db_query_params ('SELECT package_id,name,is_public
277 FROM frs_package WHERE group_id=$1',
279 for ($q=0; $q<db_numrows($res); $q++) {
280 echo '<tr '. $HTML->boxGetAltRowStyle($j++) . '>
281 <td>'.$rbac_edit_section_names[$keys[$i]].'</td>
282 <td>'.db_result($res,$q,'name').'</td>
283 <td>'.html_build_select_box_from_assoc(
284 $role->getRoleVals($keys[$i]),
285 "data[".$keys[$i]."][".db_result($res,$q,'package_id')."]",
286 $role->getVal($keys[$i],db_result($res,$q,'package_id')),
287 false, false ).'</td></tr>';
291 // Handle all other settings for all roles
295 echo '<tr '. $HTML->boxGetAltRowStyle($j++) . '>
296 <td colspan="2"><strong>'.$rbac_edit_section_names[$keys[$i]].'</strong></td>
298 echo html_build_select_box_from_assoc($role->getRoleVals($keys[$i]), "data[".$keys[$i]."][$group_id]", $role->getVal($keys[$i],$group_id), false, false ) ;
306 echo $HTML->listTableBottom();
308 echo '<p><input type="submit" name="submit" value="'._('Submit').'" /></p>
311 project_admin_footer(array());
315 // c-file-style: "bsd"