id";
row2("Create team account URL
Accounts created via this URL will belong to this team and will have the project preferences of its founder", "$url");
}
function team_type_name($type) {
switch ($type) {
case 1: return "Unclassified";
case 2: return "Company";
case 3: return "Primary school";
case 4: return "Secondary school";
case 5: return "Junior college";
case 6: return "University or department";
case 7: return "Government agency";
}
return "Unknown";
}
function display_team_page($team, $offset, $sort_by) {
$n = 20;
// there aren't indices to support sorting by credit.
// set the following to turn off sorted output.
// (though since caching is generally used this shouldn't needed)
//
$nosort = false;
if ($sort_by == "total_credit") {
$sort_clause = "total_credit desc";
} else {
$sort_clause = "expavg_credit desc";
}
page_head("$team->name");
start_table();
row1("Team info");
if (strlen($team->description)) {
row2("Description", sanitize_html($team->description));
}
if (strlen($team->url)) {;
if (strstr($team->url, "http://")) {
$x = $team->url;
} else {
$x = "http://$team->url";
}
row2("Web site", "$x");
}
row2("Members (with AND without Credit)", $team->nusers);
row2("Total credit", format_credit($team->total_credit));
row2("Recent average credit", format_credit($team->expavg_credit));
$user = lookup_user_id($team->userid);
row2("Founder", user_links($user));
row2("Country", $team->country);
row2("Type", team_type_name($team->type));
row2("Join this team", "id>Join");
show_team_create_account_url($team);
echo "";
echo "
";
start_table();
row1("Active members (have gotten Credit)", 4);
echo "
Name |
";
if ($nosort) {
echo "
Total credit |
Recent average credit |
";
} else {
if ($sort_by == "total_credit") {
echo "Total credit | ";
} else {
echo "id&sort_by=total_credit&offset=$offset>Total credit | ";
}
if ($sort_by == "expavg_credit") {
echo "Recent average credit | ";
} else {
echo "id&sort_by=expavg_credit&offset=$offset>Recent average credit | ";
}
}
echo "
Country |
";
if ($nosort) {
$result = mysql_query("select * from user where teamid=$team->id and total_credit>0 limit $offset,$n");
} else {
$result = mysql_query("select * from user where teamid=$team->id and total_credit>0 order by $sort_clause limit $offset,$n");
}
$j = $offset + 1;
while ($user = mysql_fetch_object($result)) {
$user_total_credit = format_credit($user->total_credit);
$user_expavg_credit = format_credit($user->expavg_credit);
$x = user_links($user);
echo "
$j) $x
| $user_total_credit |
$user_expavg_credit |
$user->country |
";
$j++;
}
mysql_free_result($result);
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";
}
}
// requires that the team exist
function require_team($team) {
if (!$team) {
error_page("No such team.");
}
}
// requires that the user is logged in as the founder of
// the team trying to be edited
//
function require_founder_login($user, $team) {
require_team($team);
if ($user->id != $team->userid) {
error_page("Only a team's founder may edit a team.");
}
}
function team_table_start($sort_by,$type_url) {
echo "
".tr(USER_TABLE_RANK)." |
".tr(USER_TABLE_NAME)." |
".tr(TEAM_TABLE_MEMBERS)." |
";
if ($sort_by == "total_credit") {
echo "
".tr(USER_TABLE_EXPAVG)." |
".tr(USER_TABLE_TOTAL_CREDIT)." |
";
} else {
echo "
".tr(USER_TABLE_EXPAVG)." |
".tr(USER_TABLE_TOTAL_CREDIT)." |
";
}
echo "
".tr(USER_TABLE_COUNTRY)." |
";
}
function show_team_row($team, $i) {
$team_expavg_credit = format_credit($team->expavg_credit);
$team_total_credit = format_credit($team->total_credit);
echo"
$i |
id>$team->name |
$team->nusers |
$team_expavg_credit |
$team_total_credit |
$team->country |
\n";
}
function user_join_team($team, $user) {
$old_teamid = $user->teamid;
$res = mysql_query("update user set teamid=$team->id where id=$user->id");
if ($old_teamid != 0) {
$old_team = lookup_team($old_teamid);
team_update_nusers($old_team);
}
team_update_nusers($team);
if ($res) return true;
return false;
}
function team_edit_form($team, $label, $url) {
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);
mysql_query("update team set expavg_credit=$avg, expavg_time=$now where id=$team->id");
}
// 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_update_nusers($team) {
$res = mysql_query("select count(*) as total from user where teamid=$team->id");
$comp = mysql_fetch_object($res);
if (!$comp) return;
$n = $comp->total;
mysql_query("update team set nusers=$n where id=$team->id");
//if ($n == 0) {
// echo "
Team is empty - deleting team.\n";
// mysql_query("delete from team where id=$team->id");
//}
}
?>