BOINC /
boinc
| 1 | <?php |
||
| 2 | // This file is part of BOINC. |
||
| 3 | // http://boinc.berkeley.edu |
||
| 4 | // Copyright (C) 2014 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/boinc_db.inc"); |
||
| 20 | require_once("../inc/util.inc"); |
||
| 21 | require_once("../inc/team.inc"); |
||
| 22 | |||
| 23 | if (DISABLE_TEAMS) error_page("Teams are disabled"); |
||
| 24 | |||
| 25 | check_get_args(array("tnow", "ttok", "userid", "email_addr", "teamid", "action")); |
||
| 26 | |||
| 27 | function show_admin($user, $admin) { |
||
| 28 | $admin_user = BoincUser::lookup_id($admin->userid); |
||
| 29 | if (!$admin_user) return; |
||
| 30 | $tokens = url_tokens($user->authenticator); |
||
| 31 | $date = date_str($admin->create_time); |
||
| 32 | echo "<tr> |
||
| 33 | <td>".user_links($admin_user, BADGE_HEIGHT_MEDIUM)."</td> |
||
| 34 | <td>$date</td> |
||
| 35 | <td> |
||
| 36 | "; |
||
| 37 | show_button("team_admins.php?teamid=$admin->teamid&action=remove&userid=$admin_user->id".$tokens, tra("Remove"), tra("Remove Team Admin status from this member")); |
||
| 38 | echo "</td></tr> |
||
| 39 | "; |
||
| 40 | } |
||
| 41 | |||
| 42 | function show_admins($user, $teamid) { |
||
| 43 | page_head(tra("Add or remove Team Admins")); |
||
| 44 | echo tra("You can select team members as 'Team Admins'. Team Admins can:")." |
||
| 45 | <ul> |
||
| 46 | <li>".tra("Edit team information (name, URL, description, country)")." |
||
| 47 | <li>".tra("View the team's join/quit history")." |
||
| 48 | <li>".tra("Send messages to the team")." |
||
| 49 | <li>".tra("Moderate the team forum, if any (admins get email notification of moderation events and red X reports)")." |
||
| 50 | </ul> |
||
| 51 | ".tra("Team Admins cannot:")." |
||
| 52 | <ul> |
||
| 53 | <li>".tra("Change the team founder")." |
||
| 54 | <li>".tra("Remove members")." |
||
| 55 | <li>".tra("Add or remove Team Admins")." |
||
| 56 | </ul> |
||
| 57 | ".tra("If a Team Admin quits the team, they cease to be a Team Admin.")." |
||
| 58 | <br /><br />".tra("We recommend that you select only people you know and trust very well as Team Admins.") |
||
| 59 | ; |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 60 | $admins = BoincTeamAdmin::enum("teamid=$teamid"); |
||
| 61 | start_table(); |
||
| 62 | if (count($admins)==0) { |
||
| 63 | row1(tra("There are currently no Team Admins")); |
||
| 64 | } else { |
||
| 65 | row1(tra("Current Team Admins"), 3); |
||
| 66 | table_header(tra("Name"), tra("Became Team Admin on"), ""); |
||
| 67 | foreach ($admins as $admin) { |
||
| 68 | show_admin($user, $admin); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | end_table(); |
||
| 72 | |||
| 73 | echo " |
||
| 74 | <p> |
||
| 75 | <form action=team_admins.php> |
||
| 76 | <input type=hidden name=action value=add> |
||
| 77 | <input type=hidden name=teamid value=$teamid> |
||
| 78 | "; |
||
| 79 | echo form_tokens($user->authenticator); |
||
| 80 | start_table(); |
||
| 81 | row1(tra("Add Team Admin")); |
||
| 82 | row2(tra("Email address of team member:"), '<input class="form-control" name="email_addr">'); |
||
| 83 | row2("", |
||
| 84 | sprintf('<input class="btn" %s type=submit action value="%s">', |
||
| 85 | button_style(), |
||
| 86 | tra("Add") |
||
| 87 | ) |
||
| 88 | ); |
||
| 89 | end_table(); |
||
| 90 | echo "</form>"; |
||
| 91 | |||
| 92 | page_tail(); |
||
| 93 | } |
||
| 94 | |||
| 95 | function remove_admin($team) { |
||
| 96 | $userid = get_int('userid'); |
||
| 97 | $ret = BoincTeamAdmin::delete("teamid=$team->id and userid=$userid"); |
||
| 98 | if (!$ret) { |
||
| 99 | error_page(tra("failed to remove admin")); |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 103 | function add_admin($team) { |
||
| 104 | $email_addr = get_str('email_addr'); |
||
| 105 | $email_addr = BoincDb::escape_string($email_addr); |
||
|
0 ignored issues
–
show
|
|||
| 106 | $user = BoincUser::lookup("email_addr='$email_addr'"); |
||
| 107 | if (!$user) error_page(tra("no such user")); |
||
| 108 | if ($user->teamid != $team->id) error_page(tra("User is not member of team")); |
||
| 109 | if (is_team_admin($user, $team)) { |
||
| 110 | error_page(tra("%1 is already an admin of %2", $email_addr, $team->name)); |
||
| 111 | } |
||
| 112 | $now = time(); |
||
| 113 | $ret = BoincTeamAdmin::insert("(teamid, userid, create_time) values ($team->id, $user->id, $now)"); |
||
| 114 | if (!$ret) error_page(tra("Couldn't add admin")); |
||
| 115 | } |
||
| 116 | |||
| 117 | $user = get_logged_in_user(); |
||
| 118 | $teamid = get_int('teamid'); |
||
| 119 | $team = BoincTeam::lookup_id($teamid); |
||
| 120 | if (!$team) error_page(tra("No such team")); |
||
| 121 | require_founder_login($user, $team); |
||
| 122 | |||
| 123 | $action = get_str('action', true); |
||
| 124 | switch($action) { |
||
| 125 | case 'remove': |
||
| 126 | check_tokens($user->authenticator); |
||
| 127 | remove_admin($team); |
||
| 128 | Header("Location: team_admins.php?teamid=$teamid"); |
||
|
0 ignored issues
–
show
|
|||
| 129 | exit(); |
||
| 130 | case 'add': |
||
| 131 | check_tokens($user->authenticator); |
||
| 132 | add_admin($team); |
||
| 133 | Header("Location: team_admins.php?teamid=$teamid"); |
||
|
0 ignored issues
–
show
|
|||
| 134 | exit(); |
||
| 135 | } |
||
| 136 | show_admins($user, $teamid); |
||
| 137 | |||
| 138 | ?> |
||
| 139 |