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
19require_once("../inc/util.inc");
20require_once("../inc/team.inc");
21require_once("../inc/sanitize_html.inc");
22require_once("../inc/boinc_db.inc");
23
24if (DISABLE_TEAMS) error_page("Teams are disabled");
25
26check_get_args(array());
27
28$user = get_logged_in_user();
29$teamid = post_int("teamid");
30$team = BoincTeam::lookup_id($teamid);
31
32if (!$team) error_page(tra("no such team"));
33require_admin($user, $team);
34
35$team_url = BoincDb::escape_string(sanitize_tags(post_str("url", true)));
36$x = strstr($team_url, "http://");
37if ($x) {
38    $team_url = substr($team_url, 7);
39}
40$team_name = BoincDb::escape_string(sanitize_tags(post_str("name")));
41$team_name_lc = strtolower($team_name);
42
43$tnh = post_str("name_html", true);
44$team_name_html = sanitize_html($tnh);
45
46$team_name_html = BoincDb::escape_string($team_name_html);
47
48$team_description = BoincDb::escape_string(post_str("description", true));
49$type = BoincDb::escape_string(post_str("type", true));
50$country = BoincDb::escape_string(post_str("country", true));
51if ($country == "") {
52    $country = "International";
53}
54if (!is_valid_country($country)) {
55    error_page(tra("bad country"));
56}
57$joinable = post_str('joinable', true)?1:0;
58
59$t = BoincTeam::lookup("name='$team_name'");
60if ($t && $t->id != $teamid) {
61    error_page(tra("The name '%1' is being used by another team.", $team_name));
62}
63if (strlen($team_name) == 0) {
64    error_page(tra("Must specify team name"));
65    // Should be caught up with the post_str("name"),
66    // but you can never be too safe.
67}
68
69$clause = sprintf(
70    "name = '%s',
71    name_lc = '%s',
72    name_html = '%s',
73    url = '%s',
74    description = '%s',
75    type = %d,
76    country='%s',
77    joinable=%d",
78    $team_name,
79    $team_name_lc,
80    $team_name_html,
81    $team_url,
82    $team_description,
83    $type,
84    $country,
85    $joinable
86);
87
88$ret = $team->update($clause);
89if ($ret) {
90    Header("Location: team_display.php?teamid=$team->id");
91} else {
92    error_page(tra("Could not update team - please try again later."));
93}
94
95?>
96