2004-02-02 23:34:39 +00:00
< ? php
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 " );
2004-02-02 23:34:39 +00:00
2004-10-16 04:12:11 +00:00
function show_team_create_account_url ( $team ) {
$url = URL_BASE . " create_account_form.php?teamid= $team->id " ;
row2 ( " Create team account URL<br><font size=-2>Accounts created via this URL will belong to this team and will have the project preferences of its founder</font> " , " <a href= $url > $url </a> " );
}
2004-12-08 22:05:56 +00:00
function team_type_name ( $type ) {
switch ( $type ) {
case 1 : return " Unclassified " ;
case 2 : return " Company " ;
case 3 : return " Primary school " ;
case 4 : return " Secondary school " ;
case 5 : return " Junior college " ;
case 6 : return " University or department " ;
case 7 : return " Government agency " ;
}
return " Unknown " ;
}
2004-06-07 03:34:07 +00:00
function display_team_page ( $team , $offset , $sort_by ) {
$n = 20 ;
2004-06-16 19:10:24 +00:00
// there aren't indices to support sorting by credit.
// set the following to turn off sorted output.
2005-05-05 21:12:26 +00:00
// (though since caching is generally used this shouldn't needed)
2004-06-16 19:10:24 +00:00
//
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
2004-02-02 23:34:39 +00:00
if ( strlen ( $team -> name_html )) {
2005-05-12 21:33:18 +00:00
page_head ( " $team->name_html " , " " , " $team->name " );
2004-02-02 23:34:39 +00:00
} else {
2004-05-14 22:57:59 +00:00
page_head ( " $team->name " );
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
}
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 );
2004-12-08 22:05:56 +00:00
row2 ( " Type " , team_type_name ( $team -> type ));
2004-10-16 04:12:11 +00:00
row2 ( " Join this team " , " <a href=team_join_form.php?id= $team->id >Join</a> " );
show_team_create_account_url ( $team );
2004-02-02 23:34:39 +00:00
echo " </table> " ;
echo " <p> " ;
start_table ();
2005-01-08 19:45:26 +00:00
row1 ( " Active members " , 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 )) {
$user_total_credit = format_credit ( $user -> total_credit );
$user_expavg_credit = format_credit ( $user -> expavg_credit );
$x = user_links ( $user );
echo " <tr class=row1>
< td align = left > $j ) $x
< td align = center > $user_total_credit </ td >
< td align = center > $user_expavg_credit </ td >
< 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
}
// requires that the team exist
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
}
}
// requires that the user is logged in as the founder of
// the team trying to be edited
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
}
}
2004-05-31 00:50:06 +00:00
function team_table_start ( $sort_by ) {
2004-02-02 23:34:39 +00:00
echo " <tr>
< th > Rank </ th >
< th > Name </ th >
< th > Members </ th >
2004-05-31 00:50:06 +00:00
" ;
if ( $sort_by == " total_credit " ) {
echo "
< th >< a href = top_teams . php ? sort_by = expavg_credit > Recent average credit </ a ></ th >
< th > Total credit </ th >
" ;
} else {
echo "
< th > Recent average credit </ th >
< th >< a href = top_teams . php ? sort_by = total_credit > Total credit </ a ></ th >
" ;
}
echo "
2004-02-02 23:34:39 +00:00
< th > Country </ th >
</ tr >
" ;
}
function show_team_row ( $team , $i ) {
$team_expavg_credit = format_credit ( $team -> expavg_credit );
$team_total_credit = format_credit ( $team -> total_credit );
echo " <tr class=row1>
< td > $i </ td >
< td >< a href = team_display . php ? teamid = $team -> id > $team -> name </ a ></ td >
< td > $team -> nusers </ td >
< td > $team_expavg_credit </ td >
< td > $team_total_credit </ td >
< td > $team -> country </ td >
</ tr > \n " ;
}
function user_join_team ( $team , $user ) {
2004-11-21 18:56:30 +00:00
$old_teamid = $user -> teamid ;
$res = mysql_query ( " update user set teamid= $team->id where id= $user->id " );
if ( $old_teamid != 0 ) {
$old_team = lookup_team ( $old_teamid );
team_update_nusers ( $old_team );
2004-02-02 23:34:39 +00:00
}
2004-11-21 18:56:30 +00:00
team_update_nusers ( $team );
if ( $res ) return true ;
return false ;
2004-02-02 23:34:39 +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 " ;
}
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 . " ,
" <input name=name_html type=text size=50 value= \" $team->name_html\ " > "
);
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> "
);
$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 " ;
}
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 ;
}
2004-11-21 18:56:30 +00:00
function team_update_nusers ( $team ) {
$res = mysql_query ( " select count(*) as total from user where teamid= $team->id " );
$comp = mysql_fetch_object ( $res );
if ( ! $comp ) return ;
$n = $comp -> total ;
2005-03-23 23:58:43 +00:00
mysql_query ( " update team set nusers= $n where id= $team->id " );
//if ($n == 0) {
// echo "<br>Team is empty - deleting team.\n";
// mysql_query("delete from team where id=$team->id");
//}
2004-11-21 18:56:30 +00:00
}
2004-02-02 23:34:39 +00:00
?>