2004-02-02 23:34:39 +00:00
|
|
|
<?php
|
2007-09-26 15:46:54 +00:00
|
|
|
$cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit
|
2004-02-02 23:34:39 +00:00
|
|
|
|
|
|
|
require_once("../inc/util.inc");
|
|
|
|
require_once("../inc/db.inc");
|
|
|
|
require_once("../inc/sanitize_html.inc");
|
2004-03-26 18:32:57 +00:00
|
|
|
require_once("../inc/countries.inc");
|
2004-11-07 02:57:02 +00:00
|
|
|
require_once("../inc/credit.inc");
|
2006-02-01 20:19:51 +00:00
|
|
|
require_once("../inc/team_types.inc");
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2004-06-07 03:34:07 +00:00
|
|
|
function display_team_page($team, $offset, $sort_by) {
|
|
|
|
$n = 20;
|
|
|
|
|
2006-11-04 00:11:46 +00:00
|
|
|
// there aren't indices to support sorting by credit.
|
|
|
|
// set the following variable to disable sorted output.
|
|
|
|
// (though since caching is generally used this shouldn't needed)
|
|
|
|
//
|
2005-05-05 21:12:26 +00:00
|
|
|
$nosort = false;
|
2004-06-16 19:10:24 +00:00
|
|
|
|
2004-06-07 03:34:07 +00:00
|
|
|
if ($sort_by == "total_credit") {
|
|
|
|
$sort_clause = "total_credit desc";
|
|
|
|
} else {
|
|
|
|
$sort_clause = "expavg_credit desc";
|
|
|
|
}
|
2005-05-12 21:33:18 +00:00
|
|
|
|
2005-09-11 21:44:40 +00:00
|
|
|
page_head("$team->name");
|
|
|
|
|
2005-10-13 09:03:43 +00:00
|
|
|
echo sanitize_html($team->name_html);
|
2007-10-26 21:14:35 +00:00
|
|
|
echo "<p>";
|
2004-02-02 23:34:39 +00:00
|
|
|
start_table();
|
|
|
|
row1("Team info");
|
|
|
|
if (strlen($team->description)) {
|
|
|
|
row2("Description", sanitize_html($team->description));
|
|
|
|
}
|
|
|
|
if (strlen($team->url)) {;
|
2004-12-08 22:05:56 +00:00
|
|
|
if (strstr($team->url, "http://")) {
|
|
|
|
$x = $team->url;
|
|
|
|
} else {
|
|
|
|
$x = "http://$team->url";
|
|
|
|
}
|
|
|
|
row2("Web site", "<a href=$x>$x</a>");
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
2006-11-03 18:41:34 +00:00
|
|
|
row2("Members (with credit)", $team->nusers);
|
2006-10-27 16:06:42 +00:00
|
|
|
|
2006-11-02 19:34:02 +00:00
|
|
|
$cache_args = "teamid=".$team->id."&founderid=".$team->userid;
|
|
|
|
$cached_data = get_cached_data(TEAM_PAGE_TTL, $cache_args);
|
|
|
|
if ($cached_data){
|
2006-11-03 04:36:21 +00:00
|
|
|
$founder = unserialize($cached_data);
|
2006-11-02 19:34:02 +00:00
|
|
|
} else {
|
2006-11-03 04:36:21 +00:00
|
|
|
$founder = lookup_user_id($team->userid);
|
|
|
|
set_cache_data(serialize($founder),$cache_args);
|
2006-11-02 19:34:02 +00:00
|
|
|
}
|
|
|
|
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2007-10-07 19:27:59 +00:00
|
|
|
row2("Total credit", format_credit_large($team->total_credit));
|
|
|
|
row2("Recent average credit", format_credit_large($team->expavg_credit));
|
2006-10-27 16:06:42 +00:00
|
|
|
row2("Founder", user_links($founder));
|
2004-02-02 23:34:39 +00:00
|
|
|
row2("Country", $team->country);
|
2004-12-08 22:05:56 +00:00
|
|
|
row2("Type", team_type_name($team->type));
|
2007-10-26 21:14:35 +00:00
|
|
|
$user = get_logged_in_user(false);
|
|
|
|
if ($user) {
|
|
|
|
if ($user->teamid != $team->id) {
|
|
|
|
$tokens = url_tokens($user->authenticator);
|
|
|
|
row2("",
|
|
|
|
"<a href='team_join.php?$tokens&teamid=$team->id'>Join this team</a>
|
|
|
|
<br><span class=note>Note: joining a team gives its founder access to your email address.</span>"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (($user->teamid == $team->id) && ($user->id != $founder->id)) {
|
|
|
|
row2("Request team founder transfer", "<a href=\"team_founder_transfer_form.php\">Initiate transfer</a>");
|
|
|
|
}
|
2006-10-27 16:06:42 +00:00
|
|
|
}
|
2004-02-02 23:34:39 +00:00
|
|
|
echo "</table>";
|
|
|
|
echo "<p>";
|
|
|
|
start_table();
|
2006-11-04 00:11:46 +00:00
|
|
|
row1("Active members (with credit)", 4);
|
2004-02-02 23:34:39 +00:00
|
|
|
echo "<tr>
|
|
|
|
<th>Name</th>
|
2004-06-07 03:34:07 +00:00
|
|
|
";
|
2004-06-16 19:10:24 +00:00
|
|
|
if ($nosort) {
|
|
|
|
echo "
|
|
|
|
<th>Total credit</th>
|
|
|
|
<th>Recent average credit</th>
|
|
|
|
";
|
2004-06-07 03:34:07 +00:00
|
|
|
} else {
|
2004-06-16 19:10:24 +00:00
|
|
|
if ($sort_by == "total_credit") {
|
|
|
|
echo "<th>Total credit</th>";
|
|
|
|
} else {
|
|
|
|
echo "<th><a href=team_display.php?teamid=$team->id&sort_by=total_credit&offset=$offset>Total credit</a></th>";
|
|
|
|
}
|
|
|
|
if ($sort_by == "expavg_credit") {
|
|
|
|
echo "<th>Recent average credit</th>";
|
|
|
|
} else {
|
|
|
|
echo "<th><a href=team_display.php?teamid=$team->id&sort_by=expavg_credit&offset=$offset>Recent average credit</a></th>";
|
|
|
|
}
|
2004-06-07 03:34:07 +00:00
|
|
|
}
|
2004-06-16 19:10:24 +00:00
|
|
|
|
2004-06-07 03:34:07 +00:00
|
|
|
echo "
|
2004-02-02 23:34:39 +00:00
|
|
|
<th>Country</th>
|
|
|
|
</tr>
|
|
|
|
";
|
|
|
|
|
2004-06-16 19:10:24 +00:00
|
|
|
if ($nosort) {
|
2004-08-11 11:24:49 +00:00
|
|
|
$result = mysql_query("select * from user where teamid=$team->id and total_credit>0 limit $offset,$n");
|
2004-06-16 19:10:24 +00:00
|
|
|
} else {
|
2004-08-11 11:24:49 +00:00
|
|
|
$result = mysql_query("select * from user where teamid=$team->id and total_credit>0 order by $sort_clause limit $offset,$n");
|
2004-06-16 19:10:24 +00:00
|
|
|
}
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2004-06-07 03:34:07 +00:00
|
|
|
$j = $offset + 1;
|
2004-02-02 23:34:39 +00:00
|
|
|
while ($user = mysql_fetch_object($result)) {
|
2007-10-07 19:27:59 +00:00
|
|
|
$user_total_credit = format_credit_large($user->total_credit);
|
2004-02-02 23:34:39 +00:00
|
|
|
$user_expavg_credit = format_credit($user->expavg_credit);
|
|
|
|
$x = user_links($user);
|
|
|
|
echo "<tr class=row1>
|
|
|
|
<td align=left>$j) $x
|
2007-10-07 21:32:55 +00:00
|
|
|
<td align=right>$user_total_credit</td>
|
|
|
|
<td align=right>$user_expavg_credit</td>
|
2004-02-02 23:34:39 +00:00
|
|
|
<td align=center>$user->country</td>
|
|
|
|
</tr>
|
|
|
|
";
|
|
|
|
$j++;
|
|
|
|
}
|
|
|
|
mysql_free_result($result);
|
|
|
|
echo "</table>";
|
2004-06-07 03:34:07 +00:00
|
|
|
|
|
|
|
if ($offset > 0) {
|
|
|
|
$new_offset = $offset - $n;
|
|
|
|
echo "<a href=team_display.php?teamid=$team->id&sort_by=$sort_by&offset=$new_offset>Last $n</a> | ";
|
|
|
|
}
|
|
|
|
if ($j == $offset + $n + 1) {
|
|
|
|
$new_offset = $offset + $n;
|
|
|
|
echo "<a href=team_display.php?teamid=$team->id&sort_by=$sort_by&offset=$new_offset>Next $n</a>";
|
|
|
|
}
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2007-10-26 21:14:35 +00:00
|
|
|
// check that the team exist
|
2004-02-02 23:34:39 +00:00
|
|
|
function require_team($team) {
|
|
|
|
if (!$team) {
|
2004-11-21 18:56:30 +00:00
|
|
|
error_page("No such team.");
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-26 21:14:35 +00:00
|
|
|
// check that the user is founder of the team
|
2004-11-21 18:56:30 +00:00
|
|
|
//
|
2004-02-02 23:34:39 +00:00
|
|
|
function require_founder_login($user, $team) {
|
|
|
|
require_team($team);
|
|
|
|
if ($user->id != $team->userid) {
|
2004-11-21 18:56:30 +00:00
|
|
|
error_page("Only a team's founder may edit a team.");
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-16 09:17:49 +00:00
|
|
|
function team_table_start($sort_by,$type_url) {
|
2004-02-02 23:34:39 +00:00
|
|
|
echo "<tr>
|
2005-09-07 15:51:28 +00:00
|
|
|
<th>".tr(USER_TABLE_RANK)."</th>
|
|
|
|
<th>".tr(USER_TABLE_NAME)."</th>
|
|
|
|
<th>".tr(TEAM_TABLE_MEMBERS)."</th>
|
2004-05-31 00:50:06 +00:00
|
|
|
";
|
|
|
|
if ($sort_by == "total_credit") {
|
|
|
|
echo "
|
2005-12-22 08:22:44 +00:00
|
|
|
<th><a href=top_teams.php?sort_by=expavg_credit".$type_url.">".tr(EXPAVG_CREDIT)."</a></th>
|
|
|
|
<th>".tr(TOTAL_CREDIT)."</th>
|
2004-05-31 00:50:06 +00:00
|
|
|
";
|
|
|
|
} else {
|
|
|
|
echo "
|
2005-12-22 21:46:35 +00:00
|
|
|
<th>".tr(EXPAVG_CREDIT)."</th>
|
|
|
|
<th><a href=top_teams.php?sort_by=total_credit".$type_url.">".tr(TOTAL_CREDIT)."</a></th>
|
2004-05-31 00:50:06 +00:00
|
|
|
";
|
|
|
|
}
|
|
|
|
echo "
|
2005-09-07 15:51:28 +00:00
|
|
|
<th>".tr(USER_TABLE_COUNTRY)."</th>
|
2004-02-02 23:34:39 +00:00
|
|
|
</tr>
|
|
|
|
";
|
|
|
|
}
|
|
|
|
|
|
|
|
function show_team_row($team, $i) {
|
2007-10-07 19:27:59 +00:00
|
|
|
$team_expavg_credit = format_credit_large($team->expavg_credit);
|
|
|
|
$team_total_credit = format_credit_large($team->total_credit);
|
2004-02-02 23:34:39 +00:00
|
|
|
echo"<tr class=row1>
|
|
|
|
<td>$i</td>
|
|
|
|
<td><a href=team_display.php?teamid=$team->id>$team->name</a></td>
|
2007-10-07 21:32:55 +00:00
|
|
|
<td align=right>".$team->nusers."</td>
|
|
|
|
<td align=right>$team_expavg_credit</td>
|
|
|
|
<td align=right>$team_total_credit</td>
|
2004-02-02 23:34:39 +00:00
|
|
|
<td>$team->country</td>
|
|
|
|
</tr>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
function user_join_team($team, $user) {
|
2004-11-21 18:56:30 +00:00
|
|
|
$res = mysql_query("update user set teamid=$team->id where id=$user->id");
|
2007-07-27 18:30:10 +00:00
|
|
|
if ($res) {
|
|
|
|
$now = time();
|
|
|
|
mysql_query("insert into team_delta (userid, teamid, timestamp, joining, total_credit) values ($user->id, $team->id, $now, 1, $user->total_credit)");
|
|
|
|
return true;
|
|
|
|
}
|
2004-11-21 18:56:30 +00:00
|
|
|
return false;
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2006-06-13 20:56:05 +00:00
|
|
|
function user_quit_team($user) {
|
2007-07-27 18:30:10 +00:00
|
|
|
if (!$user->teamid) return;
|
2006-06-13 20:56:05 +00:00
|
|
|
mysql_query("update user set teamid=0 where id=$user->id");
|
2007-09-26 15:46:54 +00:00
|
|
|
mysql_query("update team set ping_user=-ping_user where id=".$user->teamid." and ping_user=".$user->id);
|
2007-07-27 18:30:10 +00:00
|
|
|
$now = time();
|
|
|
|
mysql_query("insert into team_delta (userid, teamid, timestamp, joining, total_credit) values ($user->id, $user->teamid, $now, 0, $user->total_credit)");
|
2006-06-13 20:56:05 +00:00
|
|
|
}
|
|
|
|
|
2004-02-02 23:34:39 +00:00
|
|
|
function team_edit_form($team, $label, $url) {
|
2006-02-01 20:19:51 +00:00
|
|
|
global $team_types;
|
2004-02-02 23:34:39 +00:00
|
|
|
echo "<form method=post action=$url>\n";
|
|
|
|
if ($team) {
|
|
|
|
echo "<input type=hidden name=teamid value=$team->id>\n";
|
|
|
|
}
|
2004-10-18 22:08:37 +00:00
|
|
|
echo "
|
|
|
|
<p>
|
|
|
|
<b>Privacy note</b>: if you create a team, your project preferences
|
|
|
|
(resource share, graphics preferences)
|
|
|
|
will be visible to the public.
|
|
|
|
<p>
|
|
|
|
";
|
2004-02-02 23:34:39 +00:00
|
|
|
start_table();
|
2004-10-18 22:08:37 +00:00
|
|
|
row2( "Team name, text version
|
|
|
|
<br><font size=-2>
|
2004-02-02 23:34:39 +00:00
|
|
|
Don't use any HTML tags.
|
|
|
|
This name will be used in the searchable team list.",
|
|
|
|
"<input name=name type=text size=50 value='$team->name'>"
|
|
|
|
);
|
2004-10-18 22:08:37 +00:00
|
|
|
row2("Team name, HTML version
|
|
|
|
<br><font size=-2>
|
2004-02-02 23:34:39 +00:00
|
|
|
You may include HTML formatting, link, and image tags.
|
|
|
|
If you don't know HTML, just leave this box blank.",
|
2005-10-13 09:03:43 +00:00
|
|
|
"<input name=name_html type=text size=50 value=\"".str_replace('"',"'",$team->name_html)."\">"
|
2004-02-02 23:34:39 +00:00
|
|
|
);
|
2004-10-18 22:08:37 +00:00
|
|
|
row2("URL of team web page, if any:<br><font size=-2>(without \"http://\")
|
2004-02-02 23:34:39 +00:00
|
|
|
This URL will be linked to from the team's page on this site.",
|
|
|
|
"<input name=url size=60 value='$team->url'>"
|
|
|
|
);
|
|
|
|
row2("Description of team:",
|
|
|
|
"<textarea name=description cols=60 rows=10>$team->description</textarea>"
|
|
|
|
);
|
2007-01-03 18:07:44 +00:00
|
|
|
|
|
|
|
row2("Type of team:", team_type_select($team));
|
|
|
|
|
2004-02-02 23:34:39 +00:00
|
|
|
row2_init("Country",
|
|
|
|
"<select name=country>"
|
|
|
|
);
|
|
|
|
print_country_select($team->country);
|
2006-10-27 16:06:42 +00:00
|
|
|
|
2004-02-02 23:34:39 +00:00
|
|
|
echo "</select></b></td></tr>\n";
|
|
|
|
row2("",
|
|
|
|
"<input type=submit name=new value='$label'>"
|
|
|
|
);
|
|
|
|
end_table();
|
|
|
|
echo "</form>\n";
|
|
|
|
}
|
|
|
|
|
2004-11-01 23:10:02 +00:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2006-10-31 20:07:09 +00:00
|
|
|
function team_count_nusers($teamid) {
|
|
|
|
$res = mysql_query("select count(*) as total from user where teamid=$teamid and total_credit>0");
|
|
|
|
$cnt = mysql_fetch_object($res);
|
|
|
|
if ($cnt) {
|
2006-11-03 04:36:21 +00:00
|
|
|
return $cnt->total;
|
2006-10-31 20:07:09 +00:00
|
|
|
} else {
|
2006-11-03 04:36:21 +00:00
|
|
|
return null;
|
2006-10-31 20:07:09 +00:00
|
|
|
}
|
2004-11-21 18:56:30 +00:00
|
|
|
}
|
|
|
|
|
2007-07-23 20:30:30 +00:00
|
|
|
// 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) {
|
2007-09-26 15:46:54 +00:00
|
|
|
if ($team->ping_user <= 0) {
|
2007-07-23 20:30:30 +00:00
|
|
|
if ($team->ping_time < $now - 60 * 86400) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ($team->ping_time < $now - 90 * 86400) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-07-25 03:17:31 +00:00
|
|
|
// Make a team; args are untrusted, so cleanse and validate them
|
|
|
|
//
|
|
|
|
function make_team(
|
|
|
|
$userid, $name, $url, $type, $name_html, $description, $country
|
|
|
|
) {
|
2007-10-09 22:58:49 +00:00
|
|
|
$name = process_user_text(strip_tags($name));
|
2007-07-25 03:17:31 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
$query = sprintf(
|
|
|
|
"insert into team (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 = mysql_query($query);
|
|
|
|
if ($result) {
|
|
|
|
$teamid = mysql_insert_id();
|
|
|
|
return lookup_team($teamid);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-02 23:34:39 +00:00
|
|
|
?>
|