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/cache.inc");
20require_once("../inc/util.inc");
21require_once("../inc/boinc_db.inc");
22require_once("../inc/team.inc");
23
24if (DISABLE_TEAMS) error_page("Teams are disabled");
25
26check_get_args(array("teamid"));
27
28$teamid = get_int("teamid");
29$team = BoincTeam::lookup_id($teamid);
30if (!$team) {
31    error_page("no such team");
32}
33
34$get_from_db = false;
35
36$user = get_logged_in_user(false);
37
38// always show fresh copy to admins; they might be editing info
39//
40if (is_team_admin($user, $team)) {
41    $get_from_db = true;
42}
43if ($user && $user->id == $team->ping_user) {
44    $get_from_db = true;
45}
46
47// Cache the team record, its forum record, its new members,
48// its admins, and its member counts
49
50$cache_args = "teamid=$teamid";
51if (!$get_from_db) {
52    $cached_data = get_cached_data(TEAM_PAGE_TTL, $cache_args);
53    if ($cached_data) {
54        // We found some old but non-stale data, let's use it
55        $team = unserialize($cached_data);
56    } else {
57        $get_from_db = true;
58    }
59}
60if ($get_from_db) {
61    $team->nusers = BoincUser::count("teamid=$teamid");
62    $team->nusers_worked = BoincUser::count("teamid=$teamid and total_credit>0");
63    $team->nusers_active = BoincUser::count("teamid=$teamid and expavg_credit>0.1");
64    $team->forum = BoincForum::lookup("parent_type=1 and category=$team->id");
65    $team->new_members = new_member_list($teamid);
66    $team->admins = admin_list($teamid);
67    $team->founder = BoincUser::lookup_id($team->userid);
68    set_cached_data(TEAM_PAGE_TTL, serialize($team), $cache_args);
69}
70
71if (!$team) {
72    error_page(tra("no such team"));
73}
74
75display_team_page($team, $user);
76
77page_tail(true);
78
79?>
80