5 * Copyright 2004 (c) GForge LLC
8 * @author Tim Perdue tim@gforge.org
11 * This file is part of GForge.
13 * GForge is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * GForge is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with GForge; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 require_once('pre.php');
29 require_once('www/project/admin/project_admin_utils.php');
30 require_once('common/include/Role.class');
31 require_once('common/include/RoleObserver.class');
33 session_require(array('group'=>$group_id,'admin_flags'=>'A'));
36 // The observer is a special role, which is actually
37 // just controlling the is_public/allow anon flags
39 // Get observer role instead of regular role
41 if ($role_id=='observer') {
42 $role = new RoleObserver(group_get_object($group_id));
43 if (!$role || !is_object($role)) {
44 exit_error('Error','Could Not Get RoleObserver');
45 } elseif ($role->isError()) {
46 exit_error('Error',$role->getErrorMessage());
50 if (!$role->update($data)) {
51 $feedback .= $role->getErrorMessage();
53 $feedback .= ' Successfully Updated Role ';
57 $role = new Role(group_get_object($group_id),$role_id);
58 if (!$role || !is_object($role)) {
59 exit_error('Error','Could Not Get Role');
60 } elseif ($role->isError()) {
61 exit_error('Error',$role->getErrorMessage());
66 $role_id=$role->create($role_name,$data);
68 $feedback .= $role->getErrorMessage();
70 $feedback .= ' Successfully Created New Role ';
73 if (!$role->update($role_name,$data)) {
74 $feedback .= $role->getErrorMessage();
76 $feedback .= ' Successfully Updated Role ';
82 project_admin_header(array('title'=>$Language->getText('rbac_edit','pgtitle'),'group'=>$group_id));
85 // If observer role, show title
87 if ($role_id=='observer') {
88 echo '<h2>'.$Language->getText('rbac_edit','observer').'</h2>';
89 echo $Language->getText('rbac_edit','observerintro');
92 echo '<h2>'.$Language->getText('rbac_edit','newrole').'</h2>';
94 echo '<h2>'.$Language->getText('rbac_edit','pgtitle').'</h2>';
96 echo $Language->getText('rbac_edit','intro');
102 <form action="'.$PHP_SELF.'?group_id='.$group_id.'&role_id='. $role_id .'" method="post">';
104 if ($role_id != 'observer') {
105 echo '<strong>'.$Language->getText('rbac_edit','rolename').'</strong><br />
106 <input type="text" name="role_name" value="'.$role->getName().'">
110 $titles[]=$Language->getText('rbac_edit','title1');
111 $titles[]=$Language->getText('rbac_edit','title2');
112 $titles[]=$Language->getText('rbac_edit','title3');
114 echo $HTML->listTableTop($titles);
117 // Get the keys for this role and interate to build page
119 // Everything is built on the multi-dimensial arrays in the Role object
121 $keys = array_keys($role->role_values);
122 for ($i=0; $i<count($keys); $i++) {
126 // Handle forum settings for all roles
128 if ($keys[$i] == 'forum' || $keys[$i] == 'forumpublic' || $keys[$i] == 'forumanon') {
130 if ($keys[$i] == 'forumanon') {
131 //skip as we have special case below
133 $res=db_query("SELECT group_forum_id,forum_name,is_public,allow_anonymous
134 FROM forum_group_list WHERE group_id='$group_id'");
135 for ($q=0; $q<db_numrows($res); $q++) {
137 // Special cases - when going through the keys, we want to show trackeranon
138 // on the same line as tracker public
140 if ($keys[$i] == 'forumpublic') {
141 $txt=' '.html_build_select_box_from_assoc(
142 $role->getRoleVals('forumanon'),
143 "data[forumanon][".db_result($res,$q,'group_forum_id')."]",
144 $role->getVal('forumanon',db_result($res,$q,'group_forum_id')),
149 echo '<tr '. $HTML->boxGetAltRowStyle($j++) . '>
150 <td>'.$Language->getText('rbac_edit',$keys[$i]).'</td>
151 <td>'.db_result($res,$q,'forum_name').'</td>
152 <td>'.html_build_select_box_from_assoc(
153 $role->getRoleVals($keys[$i]),
154 "data[".$keys[$i]."][".db_result($res,$q,'group_forum_id')."]",
155 $role->getVal($keys[$i],db_result($res,$q,'group_forum_id')),
156 false, false ). $txt .'</td></tr>';
160 // Handle task mgr settings for all roles
162 } elseif ($keys[$i] == 'pm' || $keys[$i] == 'pmpublic') {
164 $res=db_query("SELECT group_project_id,project_name,is_public
165 FROM project_group_list WHERE group_id='$group_id'");
166 for ($q=0; $q<db_numrows($res); $q++) {
167 echo '<tr '. $HTML->boxGetAltRowStyle($j++) . '>
168 <td>'.$Language->getText('rbac_edit',$keys[$i]).'</td>
169 <td>'.db_result($res,$q,'project_name').'</td>
170 <td>'.html_build_select_box_from_assoc(
171 $role->getRoleVals($keys[$i]),
172 "data[".$keys[$i]."][".db_result($res,$q,'group_project_id')."]",
173 $role->getVal($keys[$i],db_result($res,$q,'group_project_id')),
174 false, false ).'</td></tr>';
178 // Handle tracker settings for all roles
180 } elseif ($keys[$i] == 'tracker' || $keys[$i] == 'trackerpublic' || $keys[$i] == 'trackeranon') {
182 if ($keys[$i] == 'trackeranon') {
183 //skip as we have special case below
185 $res=db_query("SELECT group_artifact_id,name,is_public,allow_anon
186 FROM artifact_group_list WHERE group_id='$group_id'");
187 for ($q=0; $q<db_numrows($res); $q++) {
189 // Special cases - when going through the keys, we want to show trackeranon
190 // on the same line as tracker public
192 if ($keys[$i] == 'trackerpublic') {
193 $txt = ' '.html_build_select_box_from_assoc(
194 $role->getRoleVals('trackeranon'),
195 "data[trackeranon][".db_result($res,$q,'group_artifact_id')."]",
196 $role->getVal('trackeranon',db_result($res,$q,'group_artifact_id')),
201 echo '<tr '. $HTML->boxGetAltRowStyle($j++) . '>
202 <td>'.$Language->getText('rbac_edit',$keys[$i]).'</td>
203 <td>'.db_result($res,$q,'name').'</td>
204 <td>'.html_build_select_box_from_assoc(
205 $role->getRoleVals($keys[$i]),
206 "data[".$keys[$i]."][".db_result($res,$q,'group_artifact_id')."]",
207 $role->getVal($keys[$i],db_result($res,$q,'group_artifact_id')),
208 false, false ). $txt .'</td></tr>';
213 // File release system - each package can be public/private
215 } elseif ($keys[$i] == 'frspackage') {
217 $res=db_query("SELECT package_id,name,is_public
218 FROM frs_package WHERE group_id='$group_id'");
219 for ($q=0; $q<db_numrows($res); $q++) {
220 echo '<tr '. $HTML->boxGetAltRowStyle($j++) . '>
221 <td>'.$Language->getText('rbac_edit',$keys[$i]).'</td>
222 <td>'.db_result($res,$q,'name').'</td>
223 <td>'.html_build_select_box_from_assoc(
224 $role->getRoleVals($keys[$i]),
225 "data[".$keys[$i]."][".db_result($res,$q,'package_id')."]",
226 $role->getVal($keys[$i],db_result($res,$q,'package_id')),
227 false, false ).'</td></tr>';
231 // Handle all other settings for all roles
235 echo '<tr '. $HTML->boxGetAltRowStyle($j++) . '>
236 <td><strong>'.$Language->getText('rbac_edit',$keys[$i]).'</strong></td>
238 <td>'.html_build_select_box_from_assoc($role->getRoleVals($keys[$i]), "data[".$keys[$i]."][0]", $role->getVal($keys[$i],0), false, false ).'</td>
245 echo $HTML->listTableBottom();
247 echo '<input type="submit" name="submit" value="'.$Language->getText('general', 'submit').'">
250 project_admin_footer(array());