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/RoleObserver.class.php';
32 require_once $gfcommon.'include/rbac_texts.php';
34 $group_id = getIntFromRequest('group_id');
35 session_require_perm ('project_admin', $group_id) ;
37 $role_id = getStringFromRequest('role_id');
38 $data = getStringFromRequest('data');
40 $group = group_get_object($group_id);
42 if (getStringFromRequest('delete')) {
43 session_redirect('/project/admin/roledelete.php?group_id='.$group_id.'&role_id='.$role_id);
47 // The observer is a special role, which is actually
48 // just controlling the is_public/allow anon flags
50 // Get observer role instead of regular role
52 if ($role_id=='observer') {
53 $role = new RoleObserver($group);
54 if (!$role || !is_object($role)) {
55 exit_error(_('Could Not Get RoleObserver'),'admin');
56 } elseif ($role->isError()) {
57 exit_error($role->getErrorMessage(),'admin');
60 if (getStringFromRequest('submit')) {
61 if (!$role->update($data)) {
62 $error_msg = $role->getErrorMessage();
64 $feedback = _('Successfully Updated Role');
68 if (getStringFromRequest('add')) {
69 $role_name = trim(getStringFromRequest('role_name')) ;
70 $role = new Role ($group) ;
71 $role_id=$role->createDefault($role_name) ;
73 $role = RBACEngine::getInstance()->getRoleById($role_id) ;
75 if (!$role || !is_object($role)) {
76 exit_error(_('Could Not Get Role'),'admin');
77 } elseif ($role->isError()) {
78 exit_error($role->getErrorMessage(),'admin');
81 $old_data = $role->getSettingsForProject ($group) ;
82 $new_data = array () ;
84 if (!is_array ($data)) {
87 foreach ($old_data as $section => $values) {
88 if (!array_key_exists ($section, $data)) {
91 foreach ($values as $ref_id => $val) {
92 if (!array_key_exists ($ref_id, $data[$section])) {
95 $new_data[$section][$ref_id] = $data[$section][$ref_id] ;
99 if (getStringFromRequest('submit')) {
100 if (($role->getHomeProject() != NULL)
101 && ($role->getHomeProject()->getID() == $group_id)) {
102 $role_name = trim(getStringFromRequest('role_name'));
103 $public = getIntFromRequest('public') ? true : false ;
105 $role_name = $role->getName() ;
106 $public = $role->isPublic() ;
109 $error_msg .= ' Missing Role Name ';
112 $role_id=$role->create($role_name,$data);
114 $error_msg .= $role->getErrorMessage();
116 $feedback = _('Successfully Created New Role');
119 if ($role instanceof RoleExplicit) {
120 $role->setPublic($public) ;
122 if (!$role->update($role_name,$data,false)) {
123 $error_msg .= $role->getErrorMessage();
125 $feedback = _('Successfully Updated Role');
129 //change assistant for webcal
130 $params = getIntFromRequest('group_id');
131 plugin_hook('change_cal_permission_auto',$params);
136 if ($role_id=='observer') {
137 $title= _('Edit Observer');
138 $msg = _('Use this page to edit the permissions and access levels of non-members of your project. Non-members includes users who are not logged in.');
141 $title= _('New Role');
143 $title= _('Edit Role');
145 $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 the Anonymous role has read access to a forum, all other roles will have it too.');
148 project_admin_header(array('title'=> $title,'group'=>$group_id));
150 echo '<p>'.$msg.'</p>';
152 <form action="'.getStringFromServer('PHP_SELF').'?group_id='.$group_id.'&role_id='. $role_id .'" method="post">';
154 if ($role->getHomeProject() == NULL
155 || $role->getHomeProject()->getID() != $group_id) {
156 echo '<p><strong>'._('Role Name').'</strong></p>' ;
157 echo $role->getDisplayableName ($group) ;
159 echo '<p><strong>'._('Role Name').'</strong><br /><input type="text" name="role_name" value="'.$role->getName().'" /><br />' ;
160 echo '<input type="checkbox" name="public" value="1"' ;
161 if ($role->isPublic()) {
162 echo ' checked="checked"' ;
164 echo ' /> '._('Shared role (can be referenced by other projects)').'</p>' ;
167 $titles[]=_('Section');
168 $titles[]=_('Subsection');
169 $titles[]=_('Setting');
171 setup_rbac_strings () ;
173 echo $HTML->listTableTop($titles);
176 // Get the keys for this role and interate to build page
178 // Everything is built on the multi-dimensial arrays in the Role object
181 $keys = array_keys($role->getSettingsForProject ($group)) ;
183 foreach ($keys as $key) {
184 if (!in_array ($key, $role->global_settings)) {
189 for ($i=0; $i<count($keys); $i++) {
190 if ((!$group->usesForum() && preg_match("/forum/", $keys[$i])) ||
191 (!$group->usesTracker() && preg_match("/tracker/", $keys[$i])) ||
192 (!$group->usesPM() && preg_match("/pm/", $keys[$i])) ||
193 (!$group->usesFRS() && preg_match("/frs/", $keys[$i])) ||
194 (!$group->usesSCM() && preg_match("/scm/", $keys[$i])) ||
195 (!$group->usesDocman() && preg_match("/docman/", $keys[$i]))) {
196 // We don't display modules not used
200 if (preg_match("/^plugin_([a-z]*)/", $keys[$i], $matches)) {
202 if (!$group->usesPlugin($p)) {
203 // We don't display settings for unused plugins either
208 if ($keys[$i] == 'forum' || $keys[$i] == 'forumpublic' || $keys[$i] == 'forumanon') {
210 // Handle forum settings for all roles
213 if ($keys[$i] == 'forumanon') {
214 //skip as we have special case below
216 $res=db_query_params ('SELECT group_forum_id,forum_name,is_public,allow_anonymous
217 FROM forum_group_list WHERE group_id=$1',
219 for ($q=0; $q<db_numrows($res); $q++) {
221 // Special cases - when going through the keys, we want to show trackeranon
222 // on the same line as tracker public
224 if ($keys[$i] == 'forumpublic') {
225 $txt=' '.html_build_select_box_from_assoc(
226 $role->getRoleVals('forumanon'),
227 "data[forumanon][".db_result($res,$q,'group_forum_id')."]",
228 $role->getVal('forumanon',db_result($res,$q,'group_forum_id')),
233 echo '<tr ' . $HTML->boxGetAltRowStyle($j++) . '>
234 <td style="padding-left: 4em;">'.$rbac_edit_section_names[$keys[$i]].'</td>
235 <td>'.db_result($res,$q,'forum_name').'</td>
236 <td>'.html_build_select_box_from_assoc(
237 $role->getRoleVals($keys[$i]),
238 "data[".$keys[$i]."][".db_result($res,$q,'group_forum_id')."]",
239 $role->getVal($keys[$i],db_result($res,$q,'group_forum_id')),
240 false, false ). $txt .'</td></tr>';
244 // Handle task mgr settings for all roles
246 } elseif ($keys[$i] == 'pm' || $keys[$i] == 'pmpublic') {
248 $res=db_query_params ('SELECT group_project_id,project_name,is_public
249 FROM project_group_list WHERE group_id=$1',
251 for ($q=0; $q<db_numrows($res); $q++) {
252 echo '<tr '. $HTML->boxGetAltRowStyle($j++) . '>
253 <td style="padding-left: 4em;">'.$rbac_edit_section_names[$keys[$i]].'</td>
254 <td>'.db_result($res,$q,'project_name').'</td>
255 <td>'.html_build_select_box_from_assoc(
256 $role->getRoleVals($keys[$i]),
257 "data[".$keys[$i]."][".db_result($res,$q,'group_project_id')."]",
258 $role->getVal($keys[$i],db_result($res,$q,'group_project_id')),
259 false, false ).'</td></tr>';
263 // Handle tracker settings for all roles
265 } elseif ($keys[$i] == 'tracker' || $keys[$i] == 'trackerpublic' || $keys[$i] == 'trackeranon') {
267 if ($keys[$i] == 'trackeranon') {
268 //skip as we have special case below
270 $res=db_query_params ('SELECT group_artifact_id,name,is_public,allow_anon
271 FROM artifact_group_list WHERE group_id=$1',
273 for ($q=0; $q<db_numrows($res); $q++) {
275 // Special cases - when going through the keys, we want to show trackeranon
276 // on the same line as tracker public
278 if ($keys[$i] == 'trackerpublic') {
279 $txt = ' '.html_build_select_box_from_assoc(
280 $role->getRoleVals('trackeranon'),
281 "data[trackeranon][".db_result($res,$q,'group_artifact_id')."]",
282 $role->getVal('trackeranon',db_result($res,$q,'group_artifact_id')),
287 echo '<tr '. $HTML->boxGetAltRowStyle($j++) . '>
288 <td style="padding-left: 4em;">'.$rbac_edit_section_names[$keys[$i]].'</td>
289 <td>'.db_result($res,$q,'name').'</td>
290 <td>'.html_build_select_box_from_assoc(
291 $role->getRoleVals($keys[$i]),
292 "data[".$keys[$i]."][".db_result($res,$q,'group_artifact_id')."]",
293 $role->getVal($keys[$i],db_result($res,$q,'group_artifact_id')),
294 false, false ). $txt .'</td></tr>';
299 // File release system - each package can be public/private
301 } elseif ($keys[$i] == 'frspackage') {
303 $res=db_query_params ('SELECT package_id,name,is_public
304 FROM frs_package WHERE group_id=$1',
306 for ($q=0; $q<db_numrows($res); $q++) {
307 echo '<tr '. $HTML->boxGetAltRowStyle($j++) . '>
308 <td>'.$rbac_edit_section_names[$keys[$i]].'</td>
309 <td>'.db_result($res,$q,'name').'</td>
310 <td>'.html_build_select_box_from_assoc(
311 $role->getRoleVals($keys[$i]),
312 "data[".$keys[$i]."][".db_result($res,$q,'package_id')."]",
313 $role->getVal($keys[$i],db_result($res,$q,'package_id')),
314 false, false ).'</td></tr>';
318 // Handle all other settings for all roles
322 echo '<tr '. $HTML->boxGetAltRowStyle($j++) . '>
323 <td colspan="2"><strong>'.$rbac_edit_section_names[$keys[$i]].'</strong></td>
325 echo html_build_select_box_from_assoc($role->getRoleVals($keys[$i]), "data[".$keys[$i]."][$group_id]", $role->getVal($keys[$i],$group_id), false, false ) ;
333 echo $HTML->listTableBottom();
335 echo '<p><input type="submit" name="submit" value="'._('Submit').'" /></p>
338 project_admin_footer(array());
342 // c-file-style: "bsd"