00001 <?php
00002 # This file is part of the Savane project
00003 # <http://gna.org/projects/savane/>
00004 #
00005 # $Id: userperms.php 5429 2006-02-17 22:59:20Z toddy $
00006 #
00007 # Copyright 1999-2000 (c) The SourceForge Crew
00008 # Copyright 2000-2003 (c) Free Software Foundation
00009 # Mathieu Roy <yeupou--gnu.org>
00010 #
00011 # Copyright 2004-2005 (c) Mathieu Roy <yeupou--gnu.org>
00012 # Yves Perrin <yves.perrin--cern.ch>
00013 #
00014 # The Savane project is free software; you can redistribute it and/or
00015 # modify it under the terms of the GNU General Public License
00016 # as published by the Free Software Foundation; either version 2
00017 # of the License, or (at your option) any later version.
00018 #
00019 # The Savane project is distributed in the hope that it will be useful,
00020 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00021 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00022 # GNU General Public License for more details.
00023 #
00024 # You should have received a copy of the GNU General Public License
00025 # along with the Savane project; if not, write to the Free Software
00026 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00027
00028
00029 require "../../include/pre.php";
00030
00031 session_require(array('group'=>$group_id,'admin_flags'=>'A'));
00032
00033 if ($update)
00034 {
00035 # ##### Update members permissions
00036
00037 $res_dev = db_query("select user_id FROM user_group WHERE group_id=$group_id AND admin_flags<>'P'");
00038 while ($row_dev = db_fetch_array($res_dev))
00039 {
00040 # site admins are not allowed to changer their own user rights
00041 # on a project they are member of.
00042 # It creates issues (flags erroneously set).
00043 # They should use admin interface instead or end su session
00044 if (user_is_super_user() && $row_dev['user_id'] == user_getid())
00045 {
00046 fb(sprintf(_("Configuration for user #%s (you!) ignored to avoid incoherent flags status. End the superuser session to change your settings in this group or use the admin user interface."), $row_dev['user_id']), 1);
00047 continue;
00048 }
00049
00050
00051 # admin are not allowed to turn off their own admin flag
00052 # it is too dangerous -- set it back to 'A'
00053 $admin_flags="admin_user_$row_dev[user_id]";
00054 if (user_getid() == $row_dev['user_id'])
00055 {
00056 $$admin_flags='A';
00057 }
00058
00059 # If someone is made admin, he got automatically the right to read
00060 # private items
00061 $privacy_flags="privacy_user_$row_dev[user_id]";
00062 if ($$admin_flags == "A")
00063 { $$privacy_flags='1'; }
00064
00065 $bugs_flags="bugs_user_$row_dev[user_id]";
00066 $task_flags="task_user_$row_dev[user_id]";
00067 $patch_flags="patch_user_$row_dev[user_id]";
00068 $support_flags="support_user_$row_dev[user_id]";
00069 $cookbook_flags="cookbook_user_$row_dev[user_id]";
00070 $news_flags="news_user_$row_dev[user_id]";
00071
00072 $sql = 'UPDATE user_group SET '
00073 ."admin_flags='".safeinput($$admin_flags)."',"
00074 ."privacy_flags='".safeinput($$privacy_flags)."',"
00075 ."cookbook_flags=".safeinput($$cookbook_flags).",";
00076
00077 if ($project->Uses("bugs"))
00078 {
00079 $sql .= "bugs_flags=".safeinput($$bugs_flags).",";
00080 }
00081 if ($project->Uses("news"))
00082 {
00083 $sql .= "news_flags=".safeinput($$news_flags).",";
00084 }
00085 if ($project->Uses("task"))
00086 {
00087 $sql .= "task_flags=".safeinput($$task_flags).",";
00088 }
00089 if ($project->Uses("patch"))
00090 {
00091 $sql .= "patch_flags=".safeinput($$patch_flags).",";
00092 }
00093 if ($project->Uses("support"))
00094 {
00095 $sql .= "support_flags=".safeinput($$support_flags).",";
00096 }
00097 $sql = rtrim($sql, ",");
00098 $sql .= " WHERE user_id='$row_dev[user_id]' AND group_id='$group_id'";
00099
00100 $result = db_query($sql);
00101 $name = user_getname($row_dev['user_id']);
00102
00103 if ($result)
00104 {
00105 group_add_history('Changed User Permissions',
00106 $name,
00107 $group_id);
00108 $feedback_able .= $name.", ";
00109 }
00110 else
00111 {
00112 $feedback_unable .= $name.", ";
00113 }
00114 }
00115
00116 if ($feedback_able)
00117 {
00118 fb(sprintf(_("permissions for %s updated."), rtrim($feedback_able, ', ')));
00119
00120 }
00121
00122 if ($feedback_unable)
00123 {
00124 fb(sprintf(_("failed to update %s permissions."), rtrim($feedback_unable, ', ')),1);
00125 }
00126
00127
00128 # ##### Update group default permissions
00129
00130 $bugs_flags="bugs_user_";
00131 $task_flags="task_user_";
00132 $patch_flags="patch_user_";
00133 $support_flags="support_user_";
00134 $cookbook_flags="cookbook_user_";
00135 $news_flags="news_user_";
00136
00137 # If the group entry do not exists, create it
00138 if (!db_result(db_query("SELECT groups_default_permissions_id FROM groups_default_permissions WHERE group_id='$group_id'"), 0, "groups_default_permissions_id"))
00139 {
00140 db_query("INSERT INTO groups_default_permissions (group_id) VALUES ($group_id)");
00141 }
00142
00143 # Update the table
00144 $sql = 'UPDATE groups_default_permissions SET '
00145 ."cookbook_flags=".safeinput($$cookbook_flags).",";
00146
00147 if ($project->Uses("bugs"))
00148 {
00149 $sql .= "bugs_flags=".safeinput($$bugs_flags).",";
00150 }
00151 if ($project->Uses("news"))
00152 {
00153 $sql .= "news_flags=".safeinput($$news_flags).",";
00154 }
00155 if ($project->Uses("task"))
00156 {
00157 $sql .= "task_flags=".safeinput($$task_flags).",";
00158 }
00159 if ($project->Uses("patch"))
00160 {
00161 $sql .= "patch_flags=".safeinput($$patch_flags).",";
00162 }
00163 if ($project->Uses("support"))
00164 {
00165 $sql .= "support_flags=".safeinput($$support_flags).",";
00166 }
00167 $sql = rtrim($sql, ",");
00168 $sql .= " WHERE group_id='$group_id'";
00169
00170 $result = db_query($sql);
00171
00172 if ($result)
00173 {
00174 group_add_history('Changed Group Default Permissions','',$group_id);
00175 fb(_("Permissions for the group updated."));
00176
00177 }
00178 else
00179 {
00180 fb(_("Unable to change group defaults permissions."), 1);
00181 }
00182
00183 # ##### Update posting restrictions
00184 # (if equal to 0, manually set to NULL, since 0 have a different meaning)
00185 $newitem_restrict_event1 = "bugs_restrict_event1";
00186 $newitem_restrict_event2 = "bugs_restrict_event2";
00187 $bugs_flags = ($$newitem_restrict_event2)*100 + $$newitem_restrict_event1;
00188 if (!$bugs_flags)
00189 { $bugs_flags = 'NULL'; }
00190
00191 $newitem_restrict_event1 = "task_restrict_event1";
00192 $newitem_restrict_event2 = "task_restrict_event2";
00193 $task_flags = ($$newitem_restrict_event2)*100 + $$newitem_restrict_event1;
00194 if (!$task_flags)
00195 { $task_flags = 'NULL'; }
00196
00197 $newitem_restrict_event1 = "support_restrict_event1";
00198 $newitem_restrict_event2 = "support_restrict_event2";
00199 $support_flags = ($$newitem_restrict_event2)*100 + $$newitem_restrict_event1;
00200 if (!$support_flags)
00201 { $support_flags = 'NULL'; }
00202
00203 $newitem_restrict_event1 = "patch_restrict_event1";
00204 $newitem_restrict_event2 = "patch_restrict_event2";
00205 $patch_flags = ($$newitem_restrict_event2)*100 + $$newitem_restrict_event1;
00206 if (!$patch_flags)
00207 { $patch_flags = 'NULL'; }
00208
00209 $newitem_restrict_event1 = "cookbook_restrict_event1";
00210 $newitem_restrict_event2 = "cookbook_restrict_event2";
00211 $cookbook_flags = ($$newitem_restrict_event2)*100 + $$newitem_restrict_event1;
00212 if (!$cookbook_flags)
00213 { $cookbook_flags = 'NULL'; }
00214
00215 $news_flags="news_restrict_event1";
00216
00217 # Update the table
00218 $sql = 'UPDATE groups_default_permissions SET '
00219 ."bugs_rflags=".safeinput($bugs_flags).","
00220 ."news_rflags=".safeinput($$news_flags).","
00221 ."cookbook_rflags=".safeinput($cookbook_flags).","
00222 ."task_rflags=".safeinput($task_flags).", "
00223 ."patch_rflags=".safeinput($patch_flags).", "
00224 ."support_rflags=".safeinput($support_flags)." "
00225 ."WHERE group_id='$group_id'";
00226
00227 $result = db_query($sql);
00228
00229 if ($result)
00230 {
00231 group_add_history('Changed Posting Restrictions','',$group_id);
00232 fb(_("Posting restrictions updated."));
00233
00234 }
00235 else
00236 {
00237 fb(_("Unable to change posting restrictions."), 1);
00238 }
00239 }
00240
00241
00242 # start HTML
00243 site_project_header(array('title'=>_("Permissions Management"),'group'=>$group_id,'context'=>'ahome'));
00244
00245
00246 $sql = "select user.user_name AS user_name,"
00247 . "user.realname AS realname, "
00248 . "user.user_id AS user_id, "
00249 . "user_group.admin_flags, "
00250 . "user_group.privacy_flags, "
00251 . "user_group.bugs_flags, "
00252 . "user_group.cookbook_flags, "
00253 . "user_group.forum_flags, "
00254 . "user_group.task_flags, "
00255 . "user_group.patch_flags, "
00256 . "user_group.news_flags, "
00257 . "user_group.support_flags "
00258 . "FROM user,user_group WHERE "
00259 . "user.user_id=user_group.user_id AND user_group.group_id=$group_id AND user_group.admin_flags<>'P'"
00260 . "ORDER BY user.user_name";
00261
00262 $result = db_query($sql);
00263
00264 print '<form action="'.$PHP_SELF.'" method="post">
00265 <input type="hidden" name="group" value="'.$group_name.'" />';
00266
00267 ########################### POSTING RESTRICTIONS
00268 # Exists also in trackers config (missing for news).
00269
00270 $title_arr=array();
00271 $title_arr[]=_("Applies when ...");
00272 if ($project->Uses("support"))
00273 {
00274 $title_arr[]=_("Support Tracker");
00275 }
00276 if ($project->Uses("bugs"))
00277 {
00278 $title_arr[]=_("Bug Tracker");
00279 }
00280 if ($project->Uses("task"))
00281 {
00282 $title_arr[]=_("Task Tracker");
00283 }
00284 if ($project->Uses("patch"))
00285 {
00286 $title_arr[]=_("Patch Tracker");
00287 }
00288 $title_arr[]=_("Cookbook Manager");
00289 if ($project->Uses("news"))
00290 {
00291 $title_arr[]=_("News Manager");
00292 }
00293
00294 print '<h3>'._("Group trackers posting restrictions").'</h3>';
00295
00296 print '<p>';
00297 print _("Here you can set the minimal authentification level required in order to post on the trackers.");
00298 print '</p>';
00299
00300 print html_build_list_table_top ($title_arr);
00301
00302 $i++;
00303 print '
00304 <tr class="'. utils_get_alt_row_color($i) .'">
00305 <td>'._("Posting new items").'</td>';
00306 if ($project->Uses("support"))
00307 {
00308 html_select_restriction_box("support", group_getrestrictions($group_id, "support"));
00309 }
00310 if ($project->Uses("bugs"))
00311 {
00312 html_select_restriction_box("bugs", group_getrestrictions($group_id, "bugs"));
00313 }
00314 if ($project->Uses("task"))
00315 {
00316 html_select_restriction_box("task", group_getrestrictions($group_id, "task"));
00317 }
00318 if ($project->Uses("patch"))
00319 {
00320 html_select_restriction_box("patch", group_getrestrictions($group_id, "patch"));
00321 }
00322 html_select_restriction_box("cookbook", group_getrestrictions($group_id, "cookbook"));
00323 if ($project->Uses("news"))
00324 {
00325 html_select_restriction_box("news", group_getrestrictions($group_id, "news"));
00326 }
00327
00328 print ' </tr>';
00329
00330 $i++;
00331 print '
00332 <tr class="'. utils_get_alt_row_color($i) .'">
00333 <td>'._("Posting comments").'</td>';
00334 if ($project->Uses("support"))
00335 {
00336 html_select_restriction_box("support", group_getrestrictions($group_id, "support", 2),'', '', 2);
00337 }
00338 if ($project->Uses("bugs"))
00339 {
00340 html_select_restriction_box("bugs", group_getrestrictions($group_id, "bugs", 2),'', '', 2);
00341 }
00342 if ($project->Uses("task"))
00343 {
00344 html_select_restriction_box("task", group_getrestrictions($group_id, "task", 2),'', '', 2);
00345 }
00346 if ($project->Uses("patch"))
00347 {
00348 html_select_restriction_box("patch", group_getrestrictions($group_id, "patch", 2),'', '', 2);
00349 }
00350 html_select_restriction_box("cookbook", group_getrestrictions($group_id, "cookbook", 2),'', '', 2);
00351 if ($project->Uses("news"))
00352 {
00353 # not yet effective!
00354 print '<td align="center">---</td>';
00355 # html_select_restriction_box("news", group_getrestrictions($group_id, "news", 2),'', '', 2);
00356 }
00357 print ' </tr>';
00358
00359 print '
00360 </table>
00361 <p align="center"><input type="submit" name="update" value="'._("Update Permissions").'" /></p>';
00362
00363
00364 ########################### GROUP DEFAULTS
00365
00366 $title_arr=array();
00367 if ($project->Uses("support"))
00368 {
00369 $title_arr[]=_("Support Tracker");
00370 }
00371 if ($project->Uses("bugs"))
00372 {
00373 $title_arr[]=_("Bug Tracker");
00374 }
00375 if ($project->Uses("task"))
00376 {
00377 $title_arr[]=_("Task Tracker");
00378 }
00379 if ($project->Uses("patch"))
00380 {
00381 $title_arr[]=_("Patch Tracker");
00382 }
00383 $title_arr[]=_("Cookbook Manager");
00384 if ($project->Uses("news"))
00385 {
00386 $title_arr[]=_("News Manager");
00387 }
00388
00389 print '<h3>'._("Group Default Permissions").'</h3>';
00390 member_explain_roles();
00391 print html_build_list_table_top ($title_arr);
00392
00393 if ($project->Uses("support"))
00394 {
00395 html_select_permission_box("support", group_getpermissions($group_id, "support"), "group");
00396 }
00397 if ($project->Uses("bugs"))
00398 {
00399 html_select_permission_box("bugs", group_getpermissions($group_id, "bugs"), "group");
00400 }
00401 if ($project->Uses("task"))
00402 {
00403 html_select_permission_box("task", group_getpermissions($group_id, "task"), "group");
00404 }
00405 if ($project->Uses("patch"))
00406 {
00407 html_select_permission_box("patch", group_getpermissions($group_id, "patch"), "group");
00408 }
00409 html_select_permission_box("cookbook", group_getpermissions($group_id, "cookbook"), "group");
00410 if ($project->Uses("news"))
00411 {
00412 html_select_permission_box("news", group_getpermissions($group_id, "news"), "group");
00413 }
00414
00415 print ' </tr>
00416 </table>
00417 <p align="center"><input type="submit" name="update" value="'._("Update Permissions").'" /></p>';
00418
00419
00420 ########################### PER MEMBERS
00421
00422 if (!$result || db_numrows($result) < 1)
00423 {
00424 print '<h3>'._("No Members Found").'</h3>';
00425 }
00426 else
00427 {
00428 print '<p> </p>';
00429
00430 $title_arr=array();
00431 $title_arr[]=_("Member");
00432 $title_arr[]=_("General Rights");
00433 if ($project->Uses("support"))
00434 {
00435 $title_arr[]=_("Support Tracker");
00436 }
00437 if ($project->Uses("bugs"))
00438 {
00439 $title_arr[]=_("Bug Tracker");
00440 }
00441 if ($project->Uses("task"))
00442 {
00443 $title_arr[]=_("Task Tracker");
00444 }
00445 if ($project->Uses("patch"))
00446 {
00447 $title_arr[]=_("Patch Tracker");
00448 }
00449 $title_arr[]=_("Cookbook Manager");
00450 if ($project->Uses("news"))
00451 {
00452 $title_arr[]=_("News Manager");
00453 }
00454
00455 print '<h3>'._("Permissions per member").'</h3>';
00456 print '<p class="warn">';
00457 print _("Projects Admins are always allowed to read private items.");
00458 print '</p>';
00459
00460 print html_build_list_table_top ($title_arr);
00461
00462 # a function for this specific stuff that do not require generalization
00463
00464 while ($row = db_fetch_array($result))
00465 {
00466 $i++;
00467 $reprinttitle++;
00468 if ($reprinttitle == 9)
00469 {
00470 print html_build_list_table_top($title_arr, 0, 0);
00471 $reprinttitle = 0;
00472 }
00473 print '
00474 <tr class="'. utils_get_alt_row_color($i) .'">
00475 <td align="center">'.utils_user_link($row['user_name'], $row['realname']).'</td>';
00476 print '
00477 <td class="smaller">';
00478 if ($row['user_id'] == user_getid())
00479 {
00480 print '<em>'._("You are Admin").'</em>';
00481 }
00482 else
00483 {
00484 print '
00485 <input type="checkbox" name="admin_user_'.$row['user_id'].'" value="A" '.(($row['admin_flags']=='A')?'checked="checked"':'').' /> '._("Admin");
00486 }
00487 if ($row['admin_flags'] != 'A')
00488 {
00489 print '<br />
00490 <input type="checkbox" name="privacy_user_'.$row['user_id'].'" value="1" '.(($row['privacy_flags']=='1')?'checked="checked"':'').' /> '._("Private Items");
00491 }
00492 else
00493 {
00494 print form_input("hidden", 'privacy_user_'.$row['user_id'], 1);
00495 }
00496 print '
00497 </td>';
00498
00499 if ($project->Uses("support"))
00500 {
00501 html_select_permission_box("support", $row);
00502 }
00503 if ($project->Uses("bugs"))
00504 {
00505 html_select_permission_box("bugs", $row);
00506 }
00507 if ($project->Uses("task"))
00508 {
00509 html_select_permission_box("task", $row);
00510 }
00511 if ($project->Uses("patch"))
00512 {
00513 html_select_permission_box("patch", $row);
00514 }
00515 html_select_permission_box("cookbook", $row);
00516 if ($project->Uses("news"))
00517 {
00518 html_select_permission_box("news", $row);
00519 }
00520
00521 print ' </tr>';
00522
00523 }
00524
00525 print '
00526 </table>
00527 <p align="center"><input type="submit" name="update" value="'._("Update Permissions").'" /></p></form>';
00528
00529
00530 }
00531
00532 site_project_footer(array());
00533
00534 ?>