BOINC /
boinc
| 1 | <?php |
||
| 2 | // This file is part of BOINC. |
||
| 3 | // http://boinc.berkeley.edu |
||
| 4 | // Copyright (C) 2015 University of California |
||
| 5 | // |
||
| 6 | // BOINC is free software; you can redistribute it and/or modify it |
||
| 7 | // under the terms of the GNU Lesser General Public License |
||
| 8 | // as published by the Free Software Foundation, |
||
| 9 | // either version 3 of the License, or (at your option) any later version. |
||
| 10 | // |
||
| 11 | // BOINC is distributed in the hope that it will be useful, |
||
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 14 | // See the GNU Lesser General Public License for more details. |
||
| 15 | // |
||
| 16 | // You should have received a copy of the GNU Lesser General Public License |
||
| 17 | // along with BOINC. If not, see <http://www.gnu.org/licenses/>. |
||
| 18 | |||
| 19 | require_once('../inc/forum.inc'); |
||
| 20 | |||
| 21 | db_init(); |
||
| 22 | |||
| 23 | function user_permissions_form() { |
||
| 24 | global $special_user_bitfield; |
||
| 25 | page_head('Manage user privileges'); |
||
| 26 | |||
| 27 | start_table('table-striped'); |
||
| 28 | |||
| 29 | $x = ['User']; |
||
| 30 | for ($i=0; $i<S_NFLAGS; $i++) { |
||
| 31 | $x[] = $special_user_bitfield[$i]; |
||
| 32 | } |
||
| 33 | $x[] = ''; |
||
| 34 | row_heading_array($x); |
||
| 35 | |||
| 36 | $prefs = BoincForumPrefs::enum('CONVERT(special_user, DECIMAL) > 0'); |
||
| 37 | foreach ($prefs as $pref) { |
||
| 38 | $user = BoincUser::lookup_id($pref->userid); |
||
| 39 | echo '<form action="user_permissions.php" method="POST">'; |
||
| 40 | echo sprintf( |
||
| 41 | '<input type="hidden" name="userid" value="%s">', |
||
| 42 | $pref->userid |
||
| 43 | ); |
||
| 44 | $x = ["$user->name ($user->id)"]; |
||
| 45 | for ($j=0; $j<S_NFLAGS; $j++) { |
||
| 46 | $bit = substr($pref->special_user, $j, 1); |
||
| 47 | $c = ($bit == 1)?"checked":""; |
||
| 48 | $x[] = sprintf( |
||
| 49 | '<input type="checkbox" name="role%d" value="1" %s>', |
||
| 50 | $j, $c |
||
| 51 | ); |
||
| 52 | } |
||
| 53 | $x[] = '<input class="btn btn-success" type="submit" value="Update">'; |
||
| 54 | row_array($x); |
||
| 55 | echo "</form>\n"; |
||
| 56 | } |
||
| 57 | |||
| 58 | echo '<form action="user_permissions.php" method="POST">'; |
||
| 59 | $x = ['Add User ID: <input type="text" name="userid" size="6">']; |
||
| 60 | for ($j=0; $j<S_NFLAGS; $j++) { |
||
| 61 | $x[] = sprintf( |
||
| 62 | '<input type="checkbox" name="role%d" value="1">', |
||
| 63 | $j |
||
| 64 | ); |
||
| 65 | } |
||
| 66 | $x[] = "<input class=\"btn btn-success\" type=\"submit\" value=\"Update\">"; |
||
| 67 | row_array($x); |
||
| 68 | echo "</form>\n"; |
||
| 69 | |||
| 70 | end_table(); |
||
| 71 | page_tail(); |
||
| 72 | } |
||
| 73 | |||
| 74 | function user_permissions_action($user_id) { |
||
| 75 | $bitset = ''; |
||
| 76 | $user = BoincUser::lookup_id($user_id); |
||
| 77 | if (!$user) error_page('no user'); |
||
| 78 | BoincForumPrefs::lookup($user); |
||
| 79 | |||
| 80 | for ($i=0; $i<S_NFLAGS; $i++) { |
||
| 81 | if (post_int("role$i", true) == 1) { |
||
| 82 | $bitset .= '1'; |
||
| 83 | echo "<br> setting $i"; |
||
| 84 | } else { |
||
| 85 | $bitset .= '0'; |
||
| 86 | } |
||
| 87 | } |
||
| 88 | |||
| 89 | $user->prefs->update("special_user='$bitset'"); |
||
| 90 | Header("Location: user_permissions.php"); |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 91 | } |
||
| 92 | |||
| 93 | $user = get_logged_in_user(); |
||
| 94 | BoincForumPrefs::lookup($user); |
||
| 95 | if (!is_admin($user)) { |
||
| 96 | error_page("no access"); |
||
| 97 | } |
||
| 98 | |||
| 99 | $user_id = post_int("userid", true); |
||
| 100 | if ($user_id) { |
||
| 101 | user_permissions_action($user_id); |
||
| 102 | } else { |
||
| 103 | user_permissions_form(); |
||
| 104 | } |
||
| 105 | |||
| 106 | ?> |
||
| 107 |