name_html)) { page_head("$team->name_html"); } else { page_head("$team->name"); } echo "id>Join 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); 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); echo ""; echo "

"; start_table(); row1("Team members", 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 $n offset $offset"); } else { $result = mysql_query("select * from user where teamid=$team->id and total_credit>0 order by $sort_clause limit $n offset $offset"); } $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"; } 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($sort_by) { echo " Rank Name Members "; if ($sort_by == "total_credit") { echo " Recent average credit Total credit "; } else { echo " Recent average credit Total credit "; } echo " 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); $result_team_table = mysql_query("update team set nusers=nusers+1 where id = $team->id"); 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(); 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"; } ?>