"; start_table(); row2("Key words
Find teams with these words in their names or descriptions", ""); row2_init("Country", ""); echo "\n"; row2("Type of team", team_type_select(0, true)); row2("Show only active teams", ""); row2("", ""); end_table(); echo " "; } // Merge list1 into list2. // list entries are of the form id => team, // where team includes a field "refcnt". // function merge_lists($list1, &$list2) { foreach($list1 as $id=>$team) { if (array_key_exists($id, $list2)) { $list2[$id]->refcnt++; } else { $list2[$id] = $team; $list2[$id]->refcnt = 0; } } } function compare($t1, $t2) { if ($t1->refcnt > $t2->refcnt) return -1; if ($t1->refcnt < $t2->refcnt) return 1; if ($t1->expavg_credit > $t2->rnd) return -1; if ($t1->expavg_credit < $t2->rnd) return 1; return 0; } // Sort list by decreasing refcnt // function sort_list(&$list) { foreach ($list as $a=>$b) $b->rnd = rand(); usort($list, compare); } function get_teams($clause, $active) { if ($active) $c2 = "and expavg_credit>0.1"; $query = "select * from team where $clause $c2 order by expavg_credit desc limit 20"; $result = mysql_query($query); $list = array(); while ($team = mysql_fetch_object($result)) { $list[$team->id] = $team; } return $list; } function show_list($list) { start_table(); echo " Team name Description Average credit Type Country "; foreach ($list as $team) { $type = team_type_name($team->type); echo " id>$team->name ".sanitize_html($team->description)." ".format_credit($team->expavg_credit)." $type $team->country "; } echo ""; } function search($user) { $keywords = $_GET['keywords']; $country = $_GET['country']; $type = $_GET['type']; $active = $_GET['active']; $list = array(); if (strlen($keywords)) { $list2 = get_teams("match(name, description) against ('$keywords')", $active); //echo "
keyword matches: ",sizeof($list2); merge_lists($list2, $list); } if (strlen($country) && $country!='None') { $list2 = get_teams("country = '$country'", $active); //echo "
country matches: ",sizeof($list2); merge_lists($list2, $list); } if ($type and $type>1) { $list2 = get_teams("type=$type", $active); //echo "
type matches: ",sizeof($list2); merge_lists($list2, $list); } if (sizeof($list) == 0) { echo " No teams were found matching your criteria. Try another search.

Or you can create a new team.

"; print_form($user); } else { echo " The following teams match your search criteria. To join a team, click its name to go to the team page, then click Join this team.

"; sort_list($list); show_list($list); } } $user = get_logged_in_user(false); if ($_GET['submit']) { page_head("Team search results"); search($user); } else { page_head("Find a team", 'document.form.keywords.focus()'); echo " You can team up with other people with similar interests, or from the same country, company, or school.

Use this form to find teams that might be right for you.

"; print_form($user); if (isset($_COOKIE['init'])) { echo "

Click here if you're not interested in joining a team right now. "; } } page_tail(); ?>