2002-08-07 18:56:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once("util.inc");
|
|
|
|
require_once("db.inc");
|
2003-02-24 21:25:16 +00:00
|
|
|
require_once("sanitize_html.inc");
|
2002-08-07 18:56:55 +00:00
|
|
|
|
2003-03-21 04:38:55 +00:00
|
|
|
function display_team_page($team, $user) {
|
|
|
|
page_head("$team->name", $user);
|
|
|
|
echo "<h2>Team page for ";
|
|
|
|
if (strlen($team->name_html)) {
|
2002-11-08 17:21:45 +00:00
|
|
|
echo "$team->name_html";
|
2003-03-21 04:38:55 +00:00
|
|
|
} else {
|
|
|
|
echo $team->name;
|
|
|
|
}
|
|
|
|
echo "</h2>";
|
|
|
|
if ($user->teamid == $team->id) {
|
|
|
|
echo "You currently belong to this team
|
|
|
|
<ul>
|
|
|
|
<li><a href=team_quit_form.php?id=$team->id>Quit</a>
|
|
|
|
</ul>
|
|
|
|
";
|
|
|
|
} else {
|
|
|
|
echo "You don't currently belong to this team.
|
|
|
|
<ul>
|
|
|
|
<li><a href=team_join_form.php?id=$team->id>Join this team</a>
|
|
|
|
</ul>
|
|
|
|
";
|
|
|
|
}
|
|
|
|
if ($user->id == $team->userid) {
|
|
|
|
echo "
|
|
|
|
You are the founder of this team.
|
|
|
|
<ul>
|
|
|
|
<li><a href=team_edit_form.php?teamid=$team->id>Edit team info</a>
|
|
|
|
<li><a href=team_remove_inactive_form.php?teamid=$team->id>Remove inactive members</a>
|
|
|
|
<li><a href=team_disband_form.php?teamid=$team->id>Disband team</a>
|
|
|
|
<li><a href=team_email_list.php?teamid=$team->id>View team email addresses</a>
|
|
|
|
</ul>
|
|
|
|
";
|
2002-11-08 17:21:45 +00:00
|
|
|
}
|
2003-03-17 22:37:49 +00:00
|
|
|
start_table();
|
|
|
|
row1("Team info");
|
2002-11-08 17:21:45 +00:00
|
|
|
if (strlen($team->description)) {
|
2003-02-27 22:30:31 +00:00
|
|
|
row2("Description", sanitize_html($team->description));
|
2002-11-08 17:21:45 +00:00
|
|
|
}
|
|
|
|
if (strlen($team->url)) {;
|
2003-02-27 22:30:31 +00:00
|
|
|
row2("Web site", "<a href=http://$team->url>http://$team->url</a>");
|
2002-11-08 17:21:45 +00:00
|
|
|
}
|
2003-02-27 22:30:31 +00:00
|
|
|
row2("Members", $team->nusers);
|
2002-08-12 20:16:55 +00:00
|
|
|
|
2003-03-17 22:37:49 +00:00
|
|
|
$result = mysql_query("select * from user where teamid=$team->id");
|
2002-11-08 17:21:45 +00:00
|
|
|
$total_credit = 0;
|
|
|
|
for ($i = 0; $i < $team->nusers; $i++) {
|
|
|
|
$user = mysql_fetch_object($result);
|
|
|
|
$total_credit = $total_credit + $user->total_credit;
|
|
|
|
}
|
2002-08-07 18:56:55 +00:00
|
|
|
|
2003-03-17 22:37:49 +00:00
|
|
|
row2("Total credit", $total_credit);
|
|
|
|
$result = mysql_query("select * from user where id=$team->userid");
|
2002-08-07 18:56:55 +00:00
|
|
|
$user = mysql_fetch_object($result);
|
2003-03-17 22:37:49 +00:00
|
|
|
row2("Founder", "<a href=show_user.php?userid=$user->id>$user->name</a>");
|
|
|
|
row2("Country", $team->country);
|
2002-11-08 17:21:45 +00:00
|
|
|
echo "</table>";
|
|
|
|
echo "<p>";
|
2003-03-17 22:37:49 +00:00
|
|
|
start_table();
|
|
|
|
row1("Team members", 4);
|
|
|
|
echo "<tr>
|
|
|
|
<th>Name</th>
|
|
|
|
<th>Total credit</th>
|
|
|
|
<th>Recent average credit</th>
|
|
|
|
<th>Country</th>
|
|
|
|
</tr>
|
|
|
|
";
|
2002-08-07 18:56:55 +00:00
|
|
|
|
2003-03-17 22:37:49 +00:00
|
|
|
$result = mysql_query("select * from user where teamid=$team->id order by expavg_credit desc");
|
2002-08-07 18:56:55 +00:00
|
|
|
|
2003-03-17 22:37:49 +00:00
|
|
|
$j = 1;
|
|
|
|
while (true) {
|
2002-11-08 17:21:45 +00:00
|
|
|
$user = mysql_fetch_object($result);
|
2003-03-17 22:37:49 +00:00
|
|
|
if (!$user) break;
|
|
|
|
echo "<tr>
|
|
|
|
<td align=left>$j) <a href=show_user.php?userid=$user->id>$user->name</a>
|
|
|
|
<td align=center>$user->total_credit</td>
|
|
|
|
<td align=center>$user->expavg_credit</td>
|
|
|
|
<td align=center>$user->country</td>
|
|
|
|
</tr>
|
|
|
|
";
|
|
|
|
$j++;
|
2002-11-08 17:21:45 +00:00
|
|
|
}
|
2003-03-17 22:37:49 +00:00
|
|
|
mysql_free_result($result);
|
2002-11-08 17:21:45 +00:00
|
|
|
echo "</table>";
|
|
|
|
page_tail();
|
2002-08-07 18:56:55 +00:00
|
|
|
}
|
|
|
|
|
2002-12-16 21:41:41 +00:00
|
|
|
// requires that the team exist
|
|
|
|
function require_team($team) {
|
|
|
|
if (!$team) {
|
|
|
|
page_head("Error");
|
|
|
|
echo "Team does not exist.";
|
|
|
|
page_tail();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
page_head("Permission denied");
|
|
|
|
echo "Only a team's founder may edit a team.";
|
|
|
|
page_tail();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-17 22:37:49 +00:00
|
|
|
function team_table_start() {
|
|
|
|
echo "<tr>
|
|
|
|
<th>Name</th>
|
|
|
|
<th>Members</th>
|
|
|
|
<th>Average credit</th>
|
|
|
|
<th>Total credit</th>
|
|
|
|
<th>Country</th>
|
|
|
|
</tr>
|
|
|
|
";
|
|
|
|
}
|
|
|
|
|
|
|
|
function show_team_row($team, $i) {
|
2003-05-14 23:23:48 +00:00
|
|
|
printf( "<tr>
|
|
|
|
<td>%d) <a href=team_display.php?teamid=%d>%s</a></td>
|
|
|
|
<td>%d</td>
|
|
|
|
<td>%.4f</td>
|
|
|
|
<td>%.4f</td>
|
|
|
|
<td>%s</td>
|
|
|
|
</tr>\n", $i, $team->id, $team->name, $team->nusers, $team->expavg_credit,
|
|
|
|
$team->total_credit, $team->country );
|
2003-03-17 22:37:49 +00:00
|
|
|
}
|
|
|
|
|
2003-05-20 22:20:08 +00:00
|
|
|
function user_join_team($team, $user) {
|
|
|
|
if ($user->teamid != 0) {
|
|
|
|
$query_team_other = sprintf(
|
|
|
|
"select * from team where id = %d",
|
|
|
|
$user->teamid
|
|
|
|
);
|
|
|
|
$result_team_other = mysql_query($query_team_other);
|
|
|
|
$first_team = mysql_fetch_object($result_team_other);
|
|
|
|
$first_nusers = $first_team->nusers;
|
|
|
|
$first_new_nusers = $first_nusers - 1;
|
|
|
|
$query_team_table_other = sprintf(
|
|
|
|
"update team set nusers = %d where id = %d",
|
|
|
|
$first_new_nusers,
|
|
|
|
$first_team->id
|
|
|
|
);
|
|
|
|
$result_team_table_other = mysql_query($query_team_table_other);
|
|
|
|
}
|
|
|
|
$query_user_table = sprintf(
|
|
|
|
"update user set teamid = %d where id = %d",
|
|
|
|
$team->id,
|
|
|
|
$user->id
|
|
|
|
);
|
|
|
|
$result_user_table = mysql_query($query_user_table);
|
|
|
|
$nusers = $team->nusers;
|
|
|
|
$new_nusers = $nusers + 1;
|
|
|
|
$query_team_table = sprintf(
|
|
|
|
"update team set nusers = %d where id = %d",
|
|
|
|
$new_nusers,
|
|
|
|
$team->id
|
|
|
|
);
|
|
|
|
$result_team_table = mysql_query($query_team_table);
|
|
|
|
if ($result_user_table && $result_team_table) return true;
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
|
2003-03-21 04:38:55 +00:00
|
|
|
function team_edit_form($team, $label, $url) {
|
|
|
|
echo "<form method=post action=$url>\n";
|
|
|
|
if ($team) {
|
|
|
|
echo "<input type=hidden name=teamid value=$team->id>\n";
|
|
|
|
}
|
|
|
|
start_table();
|
|
|
|
row1("Create a team");
|
|
|
|
row2( "Team name (text version)
|
|
|
|
<br><font size=2>
|
|
|
|
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'>"
|
|
|
|
);
|
|
|
|
row2("Team name (HTML version)
|
|
|
|
<br><font size=2>
|
|
|
|
You may include HTML formatting, link, and image tags.
|
|
|
|
If you don't know HTML, just leave this box blank.",
|
|
|
|
"<input name=name_html type=text size=50 value='$team->name_html'>"
|
|
|
|
);
|
|
|
|
row2("URL of team web page, if any:<br><font size=2>(without \"http://\")
|
|
|
|
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>"
|
|
|
|
);
|
|
|
|
$x1 = $team->type==1?"checked":"";
|
|
|
|
$x2 = $team->type==2?"checked":"";
|
|
|
|
$x3 = $team->type==3?"checked":"";
|
|
|
|
$x4 = $team->type==4?"checked":"";
|
|
|
|
$x5 = $team->type==5?"checked":"";
|
|
|
|
$x6 = $team->type==6?"checked":"";
|
|
|
|
$x7 = $team->type==7?"checked":"";
|
|
|
|
if ($team==null) $x1 = "checked";
|
|
|
|
row2("Type of team:",
|
|
|
|
"<input type=radio name=type value=1 $x1> Other
|
|
|
|
<br>
|
|
|
|
<input type=radio name=type value=2 $x2> Company
|
|
|
|
<br>
|
|
|
|
<input type=radio name=type value=3 $x3> Primary School
|
|
|
|
<br>
|
|
|
|
<input type=radio name=type value=4 $x4> Secondary School
|
|
|
|
<br>
|
|
|
|
<input type=radio name=type value=5 $x5> Junior College
|
|
|
|
<br>
|
|
|
|
<input type=radio name=type value=6 $x6> University or Department
|
|
|
|
<br>
|
|
|
|
<input type=radio name=type value=7 $x7> Government Agency"
|
|
|
|
);
|
|
|
|
row2_init("Country",
|
|
|
|
"<select name=country>"
|
|
|
|
);
|
|
|
|
print_country_select($team->country);
|
|
|
|
|
|
|
|
echo "</select></b></td></tr>\n";
|
|
|
|
row2("",
|
|
|
|
"<input type=submit name=new value='$label'>"
|
|
|
|
);
|
|
|
|
end_table();
|
|
|
|
echo "</form>\n";
|
|
|
|
}
|
|
|
|
|
2002-08-07 18:56:55 +00:00
|
|
|
?>
|