5 * Copyright 2004 (c) GForge LLC
7 * @author Tim Perdue tim@gforge.org
10 * This file is part of GForge.
12 * GForge is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * GForge 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
23 * along with GForge; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 require_once('../../env.inc.php');
28 require_once $gfwww.'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(array('group'=>$group_id,'admin_flags'=>'A'));
37 $role_id = getStringFromRequest('role_id');
38 $data = getStringFromRequest('data');
40 $group = group_get_object($group_id);
43 // The observer is a special role, which is actually
44 // just controlling the is_public/allow anon flags
46 // Get observer role instead of regular role
48 if ($role_id=='observer') {
49 $role = new RoleObserver($group);
50 if (!$role || !is_object($role)) {
51 exit_error('Error','Could Not Get RoleObserver');
52 } elseif ($role->isError()) {
53 exit_error('Error',$role->getErrorMessage());
56 if (getStringFromRequest('submit')) {
57 if (!$role->update($data)) {
58 $feedback = $role->getErrorMessage();
60 $feedback = _('Successfully Updated Role');
64 $role = new Role($group,$role_id);
65 if (!$role || !is_object($role)) {
66 exit_error('Error',_('Could Not Get Role'));
67 } elseif ($role->isError()) {
68 exit_error('Error',$role->getErrorMessage());
71 if (getStringFromRequest('submit')) {
72 $role_name = trim(getStringFromRequest('role_name'));
74 $feedback .= ' Missing Role Name ';
77 $role_id=$role->create($role_name,$data);
79 $feedback .= $role->getErrorMessage();
81 $feedback = _('Successfully Created New Role');
84 if (!$role->update($role_name,$data)) {
85 $feedback .= $role->getErrorMessage();
87 $feedback = _('Successfully Updated Role');
91 //change assistant for webcal
92 $params = getIntFromRequest('group_id');
93 plugin_hook('change_cal_permission_auto',$params);
98 project_admin_header(array('title'=>_('Edit Role'),'group'=>$group_id));
101 // If observer role, show title
103 if ($role_id=='observer') {
104 echo '<h1>'._('Edit Observer').'</h1>';
105 echo _('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.');
108 echo '<h1>'._('New Role').'</h1>';
110 echo '<h1>'._('Edit Role').'</h1>';
112 echo _('Use this page to edit your project\'s Roles. Note that each member has at least as much access as the Observer. For example, if the Observer can read CVS, so can any other role in the project.');
118 <form action="'.getStringFromServer('PHP_SELF').'?group_id='.$group_id.'&role_id='. $role_id .'" method="post">';
120 if ($role_id != 'observer') {
121 echo '<p><strong>'._('Role Name').'</strong><br />
122 <input type="text" name="role_name" value="'.$role->getName().'">
126 $titles[]=_('Section');
127 $titles[]=_('Subsection');
128 $titles[]=_('Setting');
130 echo $HTML->listTableTop($titles);
133 // Get the keys for this role and interate to build page
135 // Everything is built on the multi-dimensial arrays in the Role object
138 $keys = array_keys($role->role_values);
139 for ($i=0; $i<count($keys); $i++) {
140 if ((!$group->usesForum() && ereg("forum", $keys[$i])) ||
141 (!$group->usesTracker() && ereg("tracker", $keys[$i])) ||
142 (!$group->usesPM() && ereg("pm", $keys[$i])) ||
143 (!$group->usesFRS() && ereg("frs", $keys[$i])) ||
144 (!$group->usesSCM() && ereg("scm", $keys[$i])) ||
145 (!$group->usesDocman() && ereg("docman", $keys[$i]))) {
147 //We don't display modules not used
151 // Handle forum settings for all roles
153 } elseif ($keys[$i] == 'forum' || $keys[$i] == 'forumpublic' || $keys[$i] == 'forumanon') {
155 if ($keys[$i] == 'forumanon') {
156 //skip as we have special case below
158 $res=db_query_params ('SELECT group_forum_id,forum_name,is_public,allow_anonymous
159 FROM forum_group_list WHERE group_id=$1',
161 for ($q=0; $q<db_numrows($res); $q++) {
163 // Special cases - when going through the keys, we want to show trackeranon
164 // on the same line as tracker public
166 if ($keys[$i] == 'forumpublic') {
167 $txt=' '.html_build_select_box_from_assoc(
168 $role->getRoleVals('forumanon'),
169 "data[forumanon][".db_result($res,$q,'group_forum_id')."]",
170 $role->getVal('forumanon',db_result($res,$q,'group_forum_id')),
175 echo '<tr '. $HTML->boxGetAltRowStyle($j++) . '>
176 <td>'.$rbac_edit_section_names[$keys[$i]].'</td>
177 <td>'.db_result($res,$q,'forum_name').'</td>
178 <td>'.html_build_select_box_from_assoc(
179 $role->getRoleVals($keys[$i]),
180 "data[".$keys[$i]."][".db_result($res,$q,'group_forum_id')."]",
181 $role->getVal($keys[$i],db_result($res,$q,'group_forum_id')),
182 false, false ). $txt .'</td></tr>';
186 // Handle task mgr settings for all roles
188 } elseif ($keys[$i] == 'pm' || $keys[$i] == 'pmpublic') {
190 $res=db_query_params ('SELECT group_project_id,project_name,is_public
191 FROM project_group_list WHERE group_id=$1',
193 for ($q=0; $q<db_numrows($res); $q++) {
194 echo '<tr '. $HTML->boxGetAltRowStyle($j++) . '>
195 <td>'.$rbac_edit_section_names[$keys[$i]].'</td>
196 <td>'.db_result($res,$q,'project_name').'</td>
197 <td>'.html_build_select_box_from_assoc(
198 $role->getRoleVals($keys[$i]),
199 "data[".$keys[$i]."][".db_result($res,$q,'group_project_id')."]",
200 $role->getVal($keys[$i],db_result($res,$q,'group_project_id')),
201 false, false ).'</td></tr>';
205 // Handle tracker settings for all roles
207 } elseif ($keys[$i] == 'tracker' || $keys[$i] == 'trackerpublic' || $keys[$i] == 'trackeranon') {
209 if ($keys[$i] == 'trackeranon') {
210 //skip as we have special case below
212 $res=db_query_params ('SELECT group_artifact_id,name,is_public,allow_anon
213 FROM artifact_group_list WHERE group_id=$1',
215 for ($q=0; $q<db_numrows($res); $q++) {
217 // Special cases - when going through the keys, we want to show trackeranon
218 // on the same line as tracker public
220 if ($keys[$i] == 'trackerpublic') {
221 $txt = ' '.html_build_select_box_from_assoc(
222 $role->getRoleVals('trackeranon'),
223 "data[trackeranon][".db_result($res,$q,'group_artifact_id')."]",
224 $role->getVal('trackeranon',db_result($res,$q,'group_artifact_id')),
229 echo '<tr '. $HTML->boxGetAltRowStyle($j++) . '>
230 <td>'.$rbac_edit_section_names[$keys[$i]].'</td>
231 <td>'.db_result($res,$q,'name').'</td>
232 <td>'.html_build_select_box_from_assoc(
233 $role->getRoleVals($keys[$i]),
234 "data[".$keys[$i]."][".db_result($res,$q,'group_artifact_id')."]",
235 $role->getVal($keys[$i],db_result($res,$q,'group_artifact_id')),
236 false, false ). $txt .'</td></tr>';
241 // File release system - each package can be public/private
243 } elseif ($keys[$i] == 'frspackage') {
245 $res=db_query_params ('SELECT package_id,name,is_public
246 FROM frs_package WHERE group_id=$1',
248 for ($q=0; $q<db_numrows($res); $q++) {
249 echo '<tr '. $HTML->boxGetAltRowStyle($j++) . '>
250 <td>'.$rbac_edit_section_names[$keys[$i]].'</td>
251 <td>'.db_result($res,$q,'name').'</td>
252 <td>'.html_build_select_box_from_assoc(
253 $role->getRoleVals($keys[$i]),
254 "data[".$keys[$i]."][".db_result($res,$q,'package_id')."]",
255 $role->getVal($keys[$i],db_result($res,$q,'package_id')),
256 false, false ).'</td></tr>';
260 // Handle all other settings for all roles
264 echo '<tr '. $HTML->boxGetAltRowStyle($j++) . '>
265 <td colspan="2"><strong>'.$rbac_edit_section_names[$keys[$i]].'</strong></td>
266 <td>'.html_build_select_box_from_assoc($role->getRoleVals($keys[$i]), "data[".$keys[$i]."][0]", $role->getVal($keys[$i],0), false, false ).'</td>
273 echo $HTML->listTableBottom();
275 echo '<p><input type="submit" name="submit" value="'._('Submit').'" /></p>
278 project_admin_footer(array());