name", $user); echo "

Team page for "; if (strlen($team->name_html)) { echo "$team->name_html"; } else { echo $team->name; } echo "

"; if ($user->teamid == $team->id) { echo "You currently belong to this team "; } else { echo "You don't currently belong to this team. "; } if ($user->id == $team->userid) { echo " You are the founder of this team. "; } start_table(); row1("Team info"); if (strlen($team->description)) { row2("Description", sanitize_html($team->description)); } if (strlen($team->url)) {; row2("Web site", "url>http://$team->url"); } row2("Members", $team->nusers); $result = mysql_query("select * from user where teamid=$team->id"); $total_credit = 0; for ($i = 0; $i < $team->nusers; $i++) { $user = mysql_fetch_object($result); $total_credit = $total_credit + $user->total_credit; } row2("Total credit", format_credit($total_credit)); $result = mysql_query("select * from user where id=$team->userid"); $user = mysql_fetch_object($result); row2("Founder", "id>$user->name"); row2("Country", $team->country); echo ""; echo "

"; start_table(); row1("Team members", 4); echo " Name Total credit Recent average credit Country "; $result = mysql_query("select * from user where teamid=$team->id order by expavg_credit desc"); $j = 1; while (true) { $user = mysql_fetch_object($result); if (!$user) break; $user_total_credit = format_credit($user->total_credit); $user_expavg_credit = format_credit($user->expavg_credit); echo " $j) id>$user->name $user_total_credit $user_expavg_credit $user->country "; $j++; } mysql_free_result($result); echo ""; page_tail(); } // 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(); } } function team_table_start() { echo " Rank Name Members Recent average credit Total credit 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) { 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; if ($first_new_nusers > 0) { $query_team_table_other = sprintf( "update team set nusers = %d where id = %d", $first_new_nusers, $first_team->id ); } else { // no more users in this team: disband it. $query_team_table_other = sprintf( "delete from team where id = %d", $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; } function team_edit_form($team, $label, $url) { echo "

\n"; if ($team) { echo "id>\n"; } start_table(); row1("Create a team"); row2( "Team name (text version)
Don't use any HTML tags. This name will be used in the searchable team list.", "" ); row2("Team name (HTML version)
You may include HTML formatting, link, and image tags. If you don't know HTML, just leave this box blank.", "name_html\">" ); row2("URL of team web page, if any:
(without \"http://\") This URL will be linked to from the team's page on this site.", "" ); row2("Description of team:", "" ); $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:", " Other
Company
Primary School
Secondary School
Junior College
University or Department
Government Agency" ); row2_init("Country", "\n"; row2("", "" ); end_table(); echo "\n"; } ?>