";
$j++;
}
echo "";
if ($offset > 0) {
$new_offset = $offset - $n;
echo "id&sort_by=$sort_by&offset=$new_offset>Last $n | ";
}
if ($j == $offset + $n + 1) {
$new_offset = $offset + $n;
echo "id&sort_by=$sort_by&offset=$new_offset>Next $n";
}
}
// check that the team exists
//
function require_team($team) {
if (!$team) {
error_page("No such team.");
}
}
function is_team_founder($user, $team) {
return $user->id == $team->userid;
}
// check that the user is founder of the team
//
function require_founder_login($user, $team) {
require_team($team);
if ($user->id != $team->userid) {
error_page("This operation requires foundership.");
}
}
function is_team_admin($user, $team) {
if (!$user) return false;
if ($user->id == $team->userid) return true;
$admin = BoincTeamAdmin::lookup($team->id, $user->id);
if ($admin) return true;
return false;
}
// use this when you're displaying a long list of users
// and don't want to do a lookup for each one
//
function is_team_admin_aux($user, $admins) {
foreach ($admins as $a) {
if ($a->userid == $user->id) return true;
}
return false;
}
function require_admin($user, $team) {
if (!is_team_admin($user, $team)) {
error_page("This operation requires team admin privileges");
}
}
function new_member_list($teamid) {
$new_members = array();
$yesterday = time() - 86400;
$deltas = BoincTeamDelta::enum("teamid=$teamid and timestamp>$yesterday and joining=1 group by userid");
foreach ($deltas as $delta) {
$u = BoincUser::lookup_id($delta->userid);
if ($u->teamid == $teamid) {
$new_members[] = $u; // they might have later quit
}
}
return $new_members;
}
function admin_list($teamid) {
$u = array();
$admins = BoincTeamAdmin::enum("teamid=$teamid");
foreach ($admins as $admin) {
$user = BoincUser::lookup_id($admin->userid);
$u[] = $user;
}
return $u;
}
function team_table_start($sort_by, $type_url) {
echo "
\n";
}
function user_join_team($team, $user) {
user_quit_team($user);
$res = $user->update("teamid=$team->id");
if ($res) {
$now = time();
BoincTeamDelta::insert("(userid, teamid, timestamp, joining, total_credit) values ($user->id, $team->id, $now, 1, $user->total_credit)");
return true;
}
return false;
}
function user_quit_team($user) {
if (!$user->teamid) return;
$user->update("teamid=0");
$team = BoincTeam::lookup_id($user->teamid);
if ($team && $team->ping_user=$user->id) {
$team->update("ping_user=-ping_user");
}
BoincTeamAdmin::delete("teamid=$user->teamid and userid=$user->id");
$now = time();
BoincTeamDelta::insert("(userid, teamid, timestamp, joining, total_credit) values ($user->id, $user->teamid, $now, 0, $user->total_credit)");
}
function team_edit_form($team, $label, $url) {
global $team_types;
echo "\n";
}
// decay a team's average credit
//
function team_decay_credit($team) {
$avg = $team->expavg_credit;
$avg_time = $team->expavg_time;
$now = time(0);
update_average($now, 0, 0, $avg, $avg_time);
$team->update("expavg_credit=$avg, expavg_time=$now");
}
// if the team hasn't received new credit for ndays,
// decay its average and return true
//
function team_inactive_ndays($team, $ndays) {
$diff = time() - $team->expavg_time;
if ($diff > $ndays*86400) {
team_decay_credit($team);
return true;
}
return false;
}
function team_count_members($teamid) {
return BoincUser::count("teamid=$teamid");
}
// These functions determine the rules for foundership transfer, namely:
// - A transfer request is allowed if either:
// - there is no active request, and it's been at least 60 days
// since the last request (this protects the founder from
// being bombarded with frequest requests)
// - there's an active request older than 90 days
// (this lets a 2nd requester eventually get a chance)
// - Suppose someone (X) requests foundership at time T.
// An email is sent to the founder (Y).
// The request is "active" (ping_user is set to X's ID)
// - If Y declines the change, an email is sent to X,
// and the request is cleared.
// - If Y accepts the change, an email is sent to X
// and the request is cleared.
// - After T + 60 days, X can become founder
// - After T + 90 days, new requests are allowed even if there's
// an active request, i.e. after the 60 days elapse X has another
// 30 days to assume foundership before someone elase can request it
//
function new_transfer_request_ok($team, $now) {
if ($team->ping_user <= 0) {
if ($team->ping_time < $now - 60 * 86400) {
return true;
}
return false;
}
if ($team->ping_time < $now - 90 * 86400) {
return true;
}
return false;
}
// the time at which we can actually change foundership
// if the founder hasn't responded
//
function transfer_ok_time($team) {
return $team->ping_time + 60*86400;
}
function transfer_ok($team, $now) {
if ($now > transfer_ok_time($team)) return true;
return false;
}
// Make a team; args are untrusted, so cleanse and validate them
//
function make_team(
$userid, $name, $url, $type, $name_html, $description, $country
) {
$name = process_user_text(strip_tags($name));
if (strlen($name) == 0) return null;
$name_lc = strtolower($name);
$url = process_user_text(strip_tags($url));
if (strstr($url, "http://")) {
$url = substr($url, 7);
}
$name_html = process_user_text($name_html);
$description = process_user_text($description);
$country = process_user_text($country);
if (!is_valid_country($country)) {
$country = 'None';
}
$country = boinc_real_escape_string($country); // for Cote d'Ivoire
$clause = sprintf(
"(userid, create_time, name, name_lc, url, type, name_html, description, country, nusers, expavg_time) values(%d, %d, '%s', '%s', '%s', %d, '%s', '%s', '%s', %d, unix_timestamp())",
$userid,
time(),
$name,
$name_lc,
$url,
$type,
$name_html,
$description,
$country,
0
);
$result = BoincTeam::insert($clause);
if ($result) {
$db = BoincDb::get();
return BoincTeam::lookup_id($db->insert_id());
} else {
return null;
}
}
$cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit
?>