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');
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_get_object($group_id));
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_get_object($group_id),$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 = getStringFromRequest('role_name');
74 $role_id=$role->create($role_name,$data);
76 $feedback .= $role->getErrorMessage();
78 $feedback .= ' Successfully Created New Role ';
81 if (!$role->update($role_name,$data)) {
82 $feedback .= $role->getErrorMessage();
84 $feedback .= ' Successfully Updated Role ';
88 //change assistant for webcal
89 $params = getIntFromRequest('group_id');
90 plugin_hook('change_cal_permission_auto',$params);
94 project_admin_header(array('title'=>_('Edit Role'),'group'=>$group_id));
97 // If observer role, show title
99 if ($role_id=='observer') {
100 echo '<h2>'._('Edit Observer').'</h2>';
101 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.');
104 echo '<h2>'._('New Role').'</h2>';
106 echo '<h2>'._('Edit Role').'</h2>';
108 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.');
114 <form action="'.getStringFromServer('PHP_SELF').'?group_id='.$group_id.'&role_id='. $role_id .'" method="post">';
116 if ($role_id != 'observer') {
117 echo '<strong>'._('Role Name').'</strong><br />
118 <input type="text" name="role_name" value="'.$role->getName().'">
122 $titles[]=_('Section');
123 $titles[]=_('Subsection');
124 $titles[]=_('Setting');
126 echo $HTML->listTableTop($titles);
129 // Get the keys for this role and interate to build page
131 // Everything is built on the multi-dimensial arrays in the Role object
134 $keys = array_keys($role->role_values);
135 for ($i=0; $i<count($keys); $i++) {
139 // Handle forum settings for all roles
141 if ($keys[$i] == 'forum' || $keys[$i] == 'forumpublic' || $keys[$i] == 'forumanon') {
143 if ($keys[$i] == 'forumanon') {
144 //skip as we have special case below
146 $res=db_query("SELECT group_forum_id,forum_name,is_public,allow_anonymous
147 FROM forum_group_list WHERE group_id='$group_id'");
148 for ($q=0; $q<db_numrows($res); $q++) {
150 // Special cases - when going through the keys, we want to show trackeranon
151 // on the same line as tracker public
153 if ($keys[$i] == 'forumpublic') {
154 $txt=' '.html_build_select_box_from_assoc(
155 $role->getRoleVals('forumanon'),
156 "data[forumanon][".db_result($res,$q,'group_forum_id')."]",
157 $role->getVal('forumanon',db_result($res,$q,'group_forum_id')),
162 echo '<tr '. $HTML->boxGetAltRowStyle($j++) . '>
163 <td>'.$rbac_edit_section_names[$keys[$i]].'</td>
164 <td>'.db_result($res,$q,'forum_name').'</td>
165 <td>'.html_build_select_box_from_assoc(
166 $role->getRoleVals($keys[$i]),
167 "data[".$keys[$i]."][".db_result($res,$q,'group_forum_id')."]",
168 $role->getVal($keys[$i],db_result($res,$q,'group_forum_id')),
169 false, false ). $txt .'</td></tr>';
173 // Handle task mgr settings for all roles
175 } elseif ($keys[$i] == 'pm' || $keys[$i] == 'pmpublic') {
177 $res=db_query("SELECT group_project_id,project_name,is_public
178 FROM project_group_list WHERE group_id='$group_id'");
179 for ($q=0; $q<db_numrows($res); $q++) {
180 echo '<tr '. $HTML->boxGetAltRowStyle($j++) . '>
181 <td>'.$rbac_edit_section_names[$keys[$i]].'</td>
182 <td>'.db_result($res,$q,'project_name').'</td>
183 <td>'.html_build_select_box_from_assoc(
184 $role->getRoleVals($keys[$i]),
185 "data[".$keys[$i]."][".db_result($res,$q,'group_project_id')."]",
186 $role->getVal($keys[$i],db_result($res,$q,'group_project_id')),
187 false, false ).'</td></tr>';
191 // Handle tracker settings for all roles
193 } elseif ($keys[$i] == 'tracker' || $keys[$i] == 'trackerpublic' || $keys[$i] == 'trackeranon') {
195 if ($keys[$i] == 'trackeranon') {
196 //skip as we have special case below
198 $res=db_query("SELECT group_artifact_id,name,is_public,allow_anon
199 FROM artifact_group_list WHERE group_id='$group_id'");
200 for ($q=0; $q<db_numrows($res); $q++) {
202 // Special cases - when going through the keys, we want to show trackeranon
203 // on the same line as tracker public
205 if ($keys[$i] == 'trackerpublic') {
206 $txt = ' '.html_build_select_box_from_assoc(
207 $role->getRoleVals('trackeranon'),
208 "data[trackeranon][".db_result($res,$q,'group_artifact_id')."]",
209 $role->getVal('trackeranon',db_result($res,$q,'group_artifact_id')),
214 echo '<tr '. $HTML->boxGetAltRowStyle($j++) . '>
215 <td>'.$rbac_edit_section_names[$keys[$i]].'</td>
216 <td>'.db_result($res,$q,'name').'</td>
217 <td>'.html_build_select_box_from_assoc(
218 $role->getRoleVals($keys[$i]),
219 "data[".$keys[$i]."][".db_result($res,$q,'group_artifact_id')."]",
220 $role->getVal($keys[$i],db_result($res,$q,'group_artifact_id')),
221 false, false ). $txt .'</td></tr>';
226 // File release system - each package can be public/private
228 } elseif ($keys[$i] == 'frspackage') {
230 $res=db_query("SELECT package_id,name,is_public
231 FROM frs_package WHERE group_id='$group_id'");
232 for ($q=0; $q<db_numrows($res); $q++) {
233 echo '<tr '. $HTML->boxGetAltRowStyle($j++) . '>
234 <td>'.$rbac_edit_section_names[$keys[$i]].'</td>
235 <td>'.db_result($res,$q,'name').'</td>
236 <td>'.html_build_select_box_from_assoc(
237 $role->getRoleVals($keys[$i]),
238 "data[".$keys[$i]."][".db_result($res,$q,'package_id')."]",
239 $role->getVal($keys[$i],db_result($res,$q,'package_id')),
240 false, false ).'</td></tr>';
244 // Handle all other settings for all roles
248 echo '<tr '. $HTML->boxGetAltRowStyle($j++) . '>
249 <td><strong>'.$rbac_edit_section_names[$keys[$i]].'</strong></td>
251 <td>'.html_build_select_box_from_assoc($role->getRoleVals($keys[$i]), "data[".$keys[$i]."][0]", $role->getVal($keys[$i],0), false, false ).'</td>
258 echo $HTML->listTableBottom();
260 echo '<input type="submit" name="submit" value="'._('Submit').'">
263 project_admin_footer(array());