2004-02-02 23:34:39 +00:00
< ? php
2008-08-05 22:43:14 +00:00
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2008 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
2004-02-02 23:34:39 +00:00
require_once ( " ../inc/util.inc " );
2007-10-29 16:38:25 +00:00
require_once ( " ../inc/boinc_db.inc " );
2007-11-15 22:51:05 +00:00
require_once ( " ../inc/forum_db.inc " );
2007-11-25 04:47:54 +00:00
require_once ( " ../inc/forum.inc " );
2004-02-02 23:34:39 +00:00
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 " );
2006-02-01 20:19:51 +00:00
require_once ( " ../inc/team_types.inc " );
2007-11-16 20:43:07 +00:00
require_once ( " ../inc/time.inc " );
2009-02-05 19:40:01 +00:00
require_once ( " ../inc/stats_sites.inc " );
2004-02-02 23:34:39 +00:00
2007-11-20 22:58:14 +00:00
function team_search_form ( $params ) {
2008-08-04 10:07:09 +00:00
echo '<form name="form" action="team_search.php">' ;
2007-11-20 22:58:14 +00:00
start_table ();
2008-08-04 10:07:09 +00:00
row2 ( '<b>' . tra ( 'Search criteria (use one or more)' ) . '</b>' , '' );
row2 ( tra ( 'Key words' ) . '<br><span class="note">' . tra ( 'Find teams with these words in their names or descriptions' ) . '</span>' ,
2010-11-03 21:48:39 +00:00
'<input type="text" name="keywords" value="' . htmlspecialchars ( $params -> keywords ) . '">' );
2008-08-04 10:07:09 +00:00
row2_init ( tra ( 'Country' ), '' );
2008-05-20 16:42:01 +00:00
echo '<select name="country"><option value="" selected>---</option>' ;
2007-11-20 22:58:14 +00:00
$country = $params -> country ;
if ( ! $country || $country == 'None' ) $country = " XXX " ;
print_country_select ( $country );
echo " </select></td></tr> \n " ;
2008-08-04 10:07:09 +00:00
row2 ( tra ( 'Type of team' ), team_type_select ( $params -> type , true ));
2007-11-20 22:58:14 +00:00
$checked = $params -> active ? " checked " : " " ;
2008-08-16 20:59:53 +00:00
row2 ( tra ( 'Show only active teams' ), " <input type=checkbox name=active $checked > " );
row2 ( " " , " <input type=submit name=submit value= \" " . tra ( 'Search' ) . " \" > " );
2007-11-20 22:58:14 +00:00
end_table ();
2008-08-04 10:07:09 +00:00
echo '</form>' ;
2007-11-20 22:58:14 +00:00
}
2007-11-07 23:59:08 +00:00
function foundership_transfer_link ( $user , $team ) {
$now = time ();
2008-06-13 16:40:51 +00:00
if ( $team -> ping_user == $user -> id ) {
if ( transfer_ok ( $team , $now )) {
2008-08-04 10:07:09 +00:00
return tra ( 'Requested by you, and founder response deadline has passed.' ) . '
2008-06-13 16:40:51 +00:00
< br >
2008-08-04 10:07:09 +00:00
< a href = " team_founder_transfer_form.php " > '.tra(' Complete foundership transfer ').' </ a >.
' ;
2008-06-13 16:40:51 +00:00
} else {
$deadline = date_str ( transfer_ok_time ( $team ));
2008-08-04 10:07:09 +00:00
return '<a href="team_founder_transfer_form.php">' . tra ( 'Requested by you' ) . '</a>; ' . tra ( 'founder response deadline is %1' , $deadline );
2008-06-13 16:40:51 +00:00
}
}
2007-11-07 23:59:08 +00:00
if ( new_transfer_request_ok ( $team , $now )) {
2007-11-20 22:58:14 +00:00
if ( $team -> userid == $user -> id ) {
2008-08-04 10:07:09 +00:00
return tra ( 'None' );
2007-11-20 22:58:14 +00:00
} else {
2008-08-04 10:07:09 +00:00
return '<a href="team_founder_transfer_form.php">' . tra ( 'Initiate request' ) . '</a>' ;
2007-11-20 22:58:14 +00:00
}
2007-11-07 23:59:08 +00:00
}
2008-08-04 10:07:09 +00:00
return '<a href="team_founder_transfer_form.php">' . tra ( 'Deferred' ) . '</a>' ;
2007-11-07 23:59:08 +00:00
}
2007-11-16 20:43:07 +00:00
function display_team_page ( $team , $user ) {
2009-02-05 19:40:01 +00:00
global $team_name_sites ;
2005-09-11 21:44:40 +00:00
page_head ( " $team->name " );
2005-10-13 09:03:43 +00:00
echo sanitize_html ( $team -> name_html );
2007-10-26 21:14:35 +00:00
echo " <p> " ;
2004-02-02 23:34:39 +00:00
start_table ();
2008-08-04 10:07:09 +00:00
row1 ( tra ( 'Team info' ));
2004-02-02 23:34:39 +00:00
if ( strlen ( $team -> description )) {
2008-08-04 10:07:09 +00:00
row2 ( tra ( 'Description' ), sanitize_html ( $team -> description ));
2004-02-02 23:34:39 +00:00
}
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 " ;
}
2008-08-04 10:07:09 +00:00
row2 ( tra ( 'Web site' ), " <a href= $x > $x </a> " );
2004-02-02 23:34:39 +00:00
}
2010-11-03 21:48:39 +00:00
2008-05-15 22:05:05 +00:00
if ( ! no_computing ()) {
2008-08-04 10:07:09 +00:00
row2 ( tra ( 'Total credit' ), format_credit_large ( $team -> total_credit ));
row2 ( tra ( 'Recent average credit' ), format_credit_large ( $team -> expavg_credit ));
2009-02-05 19:40:01 +00:00
$x = " " ;
2009-02-05 20:25:30 +00:00
shuffle ( $team_name_sites );
2009-02-05 19:40:01 +00:00
foreach ( $team_name_sites as $t ) {
$url = $t [ 0 ];
$site_name = $t [ 1 ];
2009-02-05 20:25:30 +00:00
$encoding = $t [ 2 ];
2009-02-05 22:34:10 +00:00
if ( $encoding == " hashlc " ) {
2009-02-05 20:25:30 +00:00
$key = md5 ( strtolower ( $team -> name ));
2009-02-05 22:34:10 +00:00
} else if ( $encoding == 'hash' ) {
$key = md5 ( $team -> name );
2009-02-05 20:25:30 +00:00
} else {
$key = urlencode ( $team -> name );
}
$x .= " <a href= $url " . $key . " > $site_name </a><br> \n " ;
2009-02-05 19:40:01 +00:00
}
2009-03-03 21:58:03 +00:00
row2 ( tra ( 'Cross-project stats' ), $x );
2008-05-15 22:05:05 +00:00
}
2008-08-04 10:07:09 +00:00
row2 ( tra ( 'Country' ), $team -> country );
row2 ( tra ( 'Type' ), team_type_name ( $team -> type ));
2007-11-25 04:47:54 +00:00
if ( $team -> forum && is_forum_visible_to_user ( $team -> forum , $user )) {
2007-11-16 20:43:07 +00:00
$f = $team -> forum ;
2008-08-04 10:07:09 +00:00
row2 ( '<a href="team_forum.php?teamid=' . $team -> id . '">' . tra ( 'Message board' ) . '</a>' ,
tra ( 'Threads' ) . ': ' . $f -> threads . '<br>' . tra ( 'Posts' ) . ': ' . $f -> posts . '<br>' . tra ( 'Last post' ) . ': ' . time_diff_str ( $f -> timestamp , time ())
2007-11-16 20:43:07 +00:00
);
2007-11-15 22:51:05 +00:00
}
2007-10-26 21:14:35 +00:00
if ( $user ) {
if ( $user -> teamid != $team -> id ) {
2008-10-08 16:48:11 +00:00
if ( $team -> joinable ) {
$tokens = url_tokens ( $user -> authenticator );
row2 ( " " ,
'<a href="team_join.php?' . $tokens . '&teamid=' . $team -> id . '">' . tra ( 'Join this team' ) . ' </ a >
< br >< span class = " note " > '.tra(' Note : if \ 'OK to email\' is set in your project preferences, joining a team gives its founder access to your email address.' ) . '</span>'
);
} else {
row2 ( tra ( " Not accepting new members " ), " " );
}
2007-10-26 21:14:35 +00:00
}
2007-11-07 23:59:08 +00:00
if (( $user -> teamid == $team -> id )) {
2007-11-26 03:05:27 +00:00
if (( $user -> id == $team -> userid )) {
2007-11-07 23:59:08 +00:00
if ( $team -> ping_user ) {
$deadline = date_str ( transfer_ok_time ( $team ));
2008-08-04 10:07:09 +00:00
row2 ( tra ( 'Foundership change requested' ),
'<a href="team_change_founder_form.php?teamid=' . $team -> id . '">' . tra ( 'Respond by %1' , $deadline ) . '</a>'
2007-11-07 23:59:08 +00:00
);
}
} else {
2008-08-04 10:07:09 +00:00
row2 ( tra ( 'Team foundership change' ), foundership_transfer_link ( $user , $team ));
2007-11-07 23:59:08 +00:00
}
2007-10-26 21:14:35 +00:00
}
2006-10-27 16:06:42 +00:00
}
2008-08-04 10:07:09 +00:00
row1 ( tra ( 'Members' ));
row2 ( tra ( 'Founder' ), user_links ( $team -> founder ));
2007-11-16 20:43:07 +00:00
if ( count ( $team -> admins )) {
$first = true ;
$x = " " ;
foreach ( $team -> admins as $a ) {
if ( $first ) {
$first = false ;
} else {
$x .= " | " ;
}
$x .= user_links ( $a );
}
2008-08-04 10:07:09 +00:00
row2 ( tra ( 'Admins' ), $x );
2007-11-16 20:43:07 +00:00
}
$x = " 0 " ;
if ( count ( $team -> new_members )) {
$first = true ;
$x = " " ;
foreach ( $team -> new_members as $a ) {
if ( $first ) {
$first = false ;
} else {
$x .= " | " ;
}
$x .= user_links ( $a );
}
}
2008-08-04 10:07:09 +00:00
row2 ( tra ( 'New members in last day' ), $x );
row2 ( tra ( 'Total members' ), " $team->nusers (<a href=team_members.php?teamid= $team->id &offset=0&sort_by=expavg_credit> " . tra ( 'view' ) . " </a>) " );
row2 ( tra ( 'Active members' ), " $team->nusers_active (<a href=team_members.php?teamid= $team->id &offset=0&sort_by=expavg_credit> " . tra ( 'view' ) . " </a>) " );
row2 ( tra ( 'Members with credit' ), " $team->nusers_worked (<a href=team_members.php?teamid= $team->id &offset=0&sort_by=total_credit> " . tra ( 'view' ) . " </a>) " );
2007-11-16 20:43:07 +00:00
end_table ();
}
function display_team_members ( $team , $offset , $sort_by ) {
$n = 20 ;
$admins = BoincTeamAdmin :: enum ( " teamid= $team->id " );
// there aren't indices to support sorting by credit.
// set the following variable to disable sorted output.
// (though since caching is generally used this shouldn't needed)
//
$nosort = false ;
if ( $sort_by == " total_credit " ) {
$sort_clause = " total_credit desc " ;
} else {
$sort_clause = " expavg_credit desc " ;
}
2010-11-03 21:48:39 +00:00
2004-02-02 23:34:39 +00:00
start_table ();
2008-08-04 10:07:09 +00:00
echo ' < tr >
< th > '.tra(' Name ').' </ th >
' ;
2008-05-15 22:05:05 +00:00
if ( ! no_computing ()) {
if ( $nosort ) {
2008-08-04 10:07:09 +00:00
echo '
< th > '.tra(' Total credit ').' </ th >
< th > '.tra(' Recent average credit ').' </ th >
' ;
2004-06-16 19:10:24 +00:00
} else {
2008-05-15 22:05:05 +00:00
if ( $sort_by == " total_credit " ) {
2008-08-04 10:07:09 +00:00
echo '<th>' . tra ( 'Total credit' ) . '</th>' ;
2008-05-15 22:05:05 +00:00
} else {
2008-08-04 10:07:09 +00:00
echo " <th><a href=team_members.php?teamid= $team->id &sort_by=total_credit&offset= $offset > " . tra ( 'Total credit' ) . " </a></th> " ;
2008-05-15 22:05:05 +00:00
}
if ( $sort_by == " expavg_credit " ) {
2008-08-04 10:07:09 +00:00
echo '<th>' . tra ( 'Recent average credit' ) . '</th>' ;
2008-05-15 22:05:05 +00:00
} else {
2008-08-04 10:07:09 +00:00
echo " <th><a href=team_members.php?teamid= $team->id &sort_by=expavg_credit&offset= $offset > " . tra ( 'Recent average credit' ) . '</a></th>' ;
2008-05-15 22:05:05 +00:00
}
2004-06-16 19:10:24 +00:00
}
2004-06-07 03:34:07 +00:00
}
2004-06-16 19:10:24 +00:00
2008-08-04 10:07:09 +00:00
echo '
< th > '.tra(' Country ').' </ th >
2004-02-02 23:34:39 +00:00
</ tr >
2008-08-04 10:07:09 +00:00
' ;
2011-03-13 20:05:25 +00:00
$cache_args = " teamid= " . $team -> id . " &mosort= " . $nosort . " &order= " . $sort_clause . " &limit= " . $offset . " _ " . $n ;
$users = unserialize ( get_cached_data ( TEAM_PAGE_TTL , $cache_args ));
if ( ! $users ) {
if ( $nosort ) {
$users = BoincUser :: enum ( " teamid= $team->id limit $offset , $n " );
} else {
$users = BoincUser :: enum ( " teamid= $team->id order by $sort_clause limit $offset , $n " );
}
set_cached_data ( TEAM_PAGE_TTL , serialize ( $users ), $cache_args );
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 ;
2007-10-29 16:38:25 +00:00
foreach ( $users as $user ) {
2007-10-07 19:27:59 +00:00
$user_total_credit = format_credit_large ( $user -> total_credit );
2004-02-02 23:34:39 +00:00
$user_expavg_credit = format_credit ( $user -> expavg_credit );
$x = user_links ( $user );
2007-11-07 17:23:29 +00:00
if ( $user -> id == $team -> userid ) {
2008-08-04 10:07:09 +00:00
$x .= ' [' . tra ( 'Founder' ) . ']' ;
2007-11-16 20:43:07 +00:00
} else if ( is_team_admin_aux ( $user , $admins )) {
2008-08-04 10:07:09 +00:00
$x .= ' [' . tra ( 'Admin' ) . ']' ;
2007-11-07 17:23:29 +00:00
}
2004-02-02 23:34:39 +00:00
echo " <tr class=row1>
< td align = left > $j ) $x
2008-05-15 22:05:05 +00:00
" ;
if ( ! no_computing ()) {
echo "
< td align = right > $user_total_credit </ td >
< td align = right > $user_expavg_credit </ td >
" ;
}
echo "
2004-02-02 23:34:39 +00:00
< td align = center > $user -> country </ td >
</ tr >
" ;
$j ++ ;
}
echo " </table> " ;
2004-06-07 03:34:07 +00:00
if ( $offset > 0 ) {
$new_offset = $offset - $n ;
2010-02-16 01:06:03 +00:00
echo " <a href=team_members.php?teamid= $team->id &sort_by= $sort_by &offset= $new_offset > " . tra ( 'Previous %1' , $n ) . " </a> | " ;
2004-06-07 03:34:07 +00:00
}
if ( $j == $offset + $n + 1 ) {
$new_offset = $offset + $n ;
2008-08-04 10:07:09 +00:00
echo " <a href=team_members.php?teamid= $team->id &sort_by= $sort_by &offset= $new_offset > " . tra ( 'Next %1' , $n ) . " </a> " ;
2004-06-07 03:34:07 +00:00
}
2004-02-02 23:34:39 +00:00
}
2007-11-07 17:23:29 +00:00
// check that the team exists
//
2004-02-02 23:34:39 +00:00
function require_team ( $team ) {
if ( ! $team ) {
2008-08-04 10:07:09 +00:00
error_page ( tra ( 'No such team.' ));
2004-02-02 23:34:39 +00:00
}
}
2007-11-16 00:26:48 +00:00
function is_team_founder ( $user , $team ) {
return $user -> id == $team -> userid ;
}
2007-10-26 21:14:35 +00:00
// check that the user is founder of the team
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 ) {
2008-08-04 10:07:09 +00:00
error_page ( tra ( 'This operation requires foundership.' ));
2004-02-02 23:34:39 +00:00
}
}
2007-11-15 22:51:05 +00:00
function is_team_admin ( $user , $team ) {
2007-11-16 20:43:07 +00:00
if ( ! $user ) return false ;
2007-11-07 17:23:29 +00:00
if ( $user -> id == $team -> userid ) return true ;
$admin = BoincTeamAdmin :: lookup ( $team -> id , $user -> id );
if ( $admin ) return true ;
return false ;
}
2007-11-16 20:43:07 +00:00
// use this when you're displaying a long list of users
// and don't want to do a lookup for each one
//
function is_team_admin_aux ( $user , $admins ) {
foreach ( $admins as $a ) {
if ( $a -> userid == $user -> id ) return true ;
}
return false ;
}
2007-11-07 17:23:29 +00:00
function require_admin ( $user , $team ) {
2007-11-15 22:51:05 +00:00
if ( ! is_team_admin ( $user , $team )) {
2008-08-04 10:07:09 +00:00
error_page ( tra ( 'This operation requires team admin privileges' ));
2007-11-07 17:23:29 +00:00
}
}
2007-11-16 20:43:07 +00:00
function new_member_list ( $teamid ) {
$new_members = array ();
$yesterday = time () - 86400 ;
$deltas = BoincTeamDelta :: enum ( " teamid= $teamid and timestamp> $yesterday and joining=1 group by userid " );
2007-12-18 20:28:08 +00:00
if ( count ( $deltas )) {
foreach ( $deltas as $delta ) {
$u = BoincUser :: lookup_id ( $delta -> userid );
if ( $u -> teamid == $teamid ) {
$new_members [] = $u ; // they might have later quit
}
2007-11-16 20:43:07 +00:00
}
}
return $new_members ;
}
function admin_list ( $teamid ) {
$u = array ();
$admins = BoincTeamAdmin :: enum ( " teamid= $teamid " );
foreach ( $admins as $admin ) {
$user = BoincUser :: lookup_id ( $admin -> userid );
$u [] = $user ;
}
return $u ;
}
2007-11-20 22:58:14 +00:00
function team_table_start ( $sort_by , $type_url ) {
2004-02-02 23:34:39 +00:00
echo " <tr>
2008-08-04 10:07:09 +00:00
< th > " .tra('Rank'). " </ th >
< th > " .tra('Name'). " </ th >
< th > " .tra('Members'). " </ th >
2004-05-31 00:50:06 +00:00
" ;
if ( $sort_by == " total_credit " ) {
echo "
2008-08-04 10:07:09 +00:00
< th >< a href = top_teams . php ? sort_by = expavg_credit " . $type_url . " > " .tra('Recent average credit'). " </ a ></ th >
< th > " .tra('Total credit'). " </ th >
2004-05-31 00:50:06 +00:00
" ;
} else {
echo "
2008-08-04 10:07:09 +00:00
< th > " .tra('Recent average credit'). " </ th >
< th >< a href = top_teams . php ? sort_by = total_credit " . $type_url . " > " .tra('Total credit'). " </ a ></ th >
2004-05-31 00:50:06 +00:00
" ;
}
echo "
2008-08-04 10:07:09 +00:00
< th > " .tra('Country'). " </ th >
2010-02-16 01:06:03 +00:00
< th > " .tra( " Type " ). " </ th >
2004-02-02 23:34:39 +00:00
</ tr >
" ;
}
function show_team_row ( $team , $i ) {
2007-10-07 19:27:59 +00:00
$team_expavg_credit = format_credit_large ( $team -> expavg_credit );
$team_total_credit = format_credit_large ( $team -> total_credit );
2004-02-02 23:34:39 +00:00
echo " <tr class=row1>
< td > $i </ td >
< td >< a href = team_display . php ? teamid = $team -> id > $team -> name </ a ></ td >
2007-10-07 21:32:55 +00:00
< td align = right > " . $team->nusers . " </ td >
< td align = right > $team_expavg_credit </ td >
< td align = right > $team_total_credit </ td >
2004-02-02 23:34:39 +00:00
< td > $team -> country </ td >
2007-11-20 22:58:14 +00:00
< td > " .team_type_name( $team->type ). " </ td >
2004-02-02 23:34:39 +00:00
</ tr > \n " ;
}
function user_join_team ( $team , $user ) {
2007-11-17 21:59:46 +00:00
user_quit_team ( $user );
2007-10-29 16:38:25 +00:00
$res = $user -> update ( " teamid= $team->id " );
2007-07-27 18:30:10 +00:00
if ( $res ) {
$now = time ();
2007-10-29 16:38:25 +00:00
BoincTeamDelta :: insert ( " (userid, teamid, timestamp, joining, total_credit) values ( $user->id , $team->id , $now , 1, $user->total_credit ) " );
2007-07-27 18:30:10 +00:00
return true ;
}
2004-11-21 18:56:30 +00:00
return false ;
2004-02-02 23:34:39 +00:00
}
2006-06-13 20:56:05 +00:00
function user_quit_team ( $user ) {
2007-07-27 18:30:10 +00:00
if ( ! $user -> teamid ) return ;
2007-10-29 16:38:25 +00:00
$user -> update ( " teamid=0 " );
$team = BoincTeam :: lookup_id ( $user -> teamid );
if ( $team && $team -> ping_user = $user -> id ) {
$team -> update ( " ping_user=-ping_user " );
}
2007-11-07 17:23:29 +00:00
BoincTeamAdmin :: delete ( " teamid= $user->teamid and userid= $user->id " );
2007-07-27 18:30:10 +00:00
$now = time ();
2007-10-29 16:38:25 +00:00
BoincTeamDelta :: insert ( " (userid, teamid, timestamp, joining, total_credit) values ( $user->id , $user->teamid , $now , 0, $user->total_credit ) " );
2006-06-13 20:56:05 +00:00
}
2004-02-02 23:34:39 +00:00
function team_edit_form ( $team , $label , $url ) {
2006-02-01 20:19:51 +00:00
global $team_types ;
2004-02-02 23:34:39 +00:00
echo " <form method=post action= $url > \n " ;
if ( $team ) {
echo " <input type=hidden name=teamid value= $team->id > \n " ;
}
2008-10-21 20:33:16 +00:00
if ( $team -> seti_id ) {
2010-02-16 01:06:03 +00:00
echo " <p><span class=error> " . tra ( " WARNING: this is a BOINC-wide team. If you make changes here, they will soon be overwritten. Edit the %1BOINC-wide team%2 instead. " , " <a href=http://boinc.berkeley.edu/teams/> " , " </a> " )
. " </span>
2008-10-21 20:33:16 +00:00
< p >
" ;
}
2008-08-04 10:07:09 +00:00
echo '
2004-10-18 22:08:37 +00:00
< p >
2008-08-04 10:07:09 +00:00
'.tra(' % 1 Privacy note % 2 : if you create a team , your project preferences ( resource share , graphics preferences ) will be visible to the public . ', ' < b > ', ' </ b > ').'
2004-10-18 22:08:37 +00:00
< p >
2008-08-04 10:07:09 +00:00
' ;
2004-02-02 23:34:39 +00:00
start_table ();
2008-08-04 10:07:09 +00:00
row2 ( tra ( 'Team name, text version' ) . '
< br >< span class = " note " > '.tra(' Don\ 't use HTML tags.' ) . '</span>' ,
2004-02-02 23:34:39 +00:00
" <input name=name type=text size=50 value=' $team->name '> "
);
2008-08-04 10:07:09 +00:00
row2 ( tra ( 'Team name, HTML version' ) . '
< br >< span class = " note " >
'.tra(' You may use % 1 limited HTML tags % 2. ', ' < a href = " html.php " target = " _new " > ', ' </ a > ').'
'.tra(' If you don\ 't know HTML, leave this box blank.' ) . '</span>' ,
2005-10-13 09:03:43 +00:00
" <input name=name_html type=text size=50 value= \" " . str_replace ( '"' , " ' " , $team -> name_html ) . " \" > "
2004-02-02 23:34:39 +00:00
);
2008-08-04 10:07:09 +00:00
row2 ( tra ( 'URL of team web page, if any' ) . ':<br><font size=-2>(' . tra ( 'without "http://"' ) . ' )
'.tra(' This URL will be linked to from the team\ 's page on this site.' ),
2010-11-03 21:48:39 +00:00
" <input type=text name=url size=60 value=' $team->url '> "
2004-02-02 23:34:39 +00:00
);
2008-08-04 10:07:09 +00:00
row2 ( tra ( 'Description of team' ) . ' :
< br >< span class = " note " >
'.tra(' You may use % 1 limited HTML tags % 2. ', ' < a href = " html.php " target = " _new " > ', ' </ a > ').'
</ span > ' ,
2004-02-02 23:34:39 +00:00
" <textarea name=description cols=60 rows=10> $team->description </textarea> "
);
2007-01-03 18:07:44 +00:00
2008-08-04 10:07:09 +00:00
row2 ( tra ( 'Type of team' ) . ':' , team_type_select ( $team -> type ));
2007-01-03 18:07:44 +00:00
2008-08-04 10:07:09 +00:00
row2_init ( tra ( 'Country' ),
2004-02-02 23:34:39 +00:00
" <select name=country> "
);
print_country_select ( $team -> country );
2010-11-03 21:48:39 +00:00
2008-10-08 16:48:11 +00:00
echo " </select></td></tr> \n " ;
$x = $team -> joinable ? " checked " : " " ;
2010-02-16 01:06:03 +00:00
row2 ( tra ( " Accept new members? " ), " <input type=checkbox name=joinable $x > " );
2004-02-02 23:34:39 +00:00
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 );
2007-10-29 16:38:25 +00:00
$team -> update ( " expavg_credit= $avg , expavg_time= $now " );
2004-11-01 23:10:02 +00:00
}
// 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 ;
}
2007-11-07 17:23:29 +00:00
function team_count_members ( $teamid ) {
return BoincUser :: count ( " teamid= $teamid " );
2004-11-21 18:56:30 +00:00
}
2007-07-23 20:30:30 +00:00
// These functions determine the rules for foundership transfer, namely:
// - A transfer request is allowed if either:
// - there is no active request, and it's been at least 60 days
// since the last request (this protects the founder from
// being bombarded with frequest requests)
// - there's an active request older than 90 days
// (this lets a 2nd requester eventually get a chance)
// - Suppose someone (X) requests foundership at time T.
// An email is sent to the founder (Y).
// The request is "active" (ping_user is set to X's ID)
// - If Y declines the change, an email is sent to X,
// and the request is cleared.
// - If Y accepts the change, an email is sent to X
// and the request is cleared.
// - After T + 60 days, X can become founder
// - After T + 90 days, new requests are allowed even if there's
// an active request, i.e. after the 60 days elapse X has another
// 30 days to assume foundership before someone elase can request it
//
function new_transfer_request_ok ( $team , $now ) {
2007-09-26 15:46:54 +00:00
if ( $team -> ping_user <= 0 ) {
2007-07-23 20:30:30 +00:00
if ( $team -> ping_time < $now - 60 * 86400 ) {
return true ;
}
return false ;
}
if ( $team -> ping_time < $now - 90 * 86400 ) {
return true ;
}
return false ;
}
2007-11-07 23:59:08 +00:00
// the time at which we can actually change foundership
// if the founder hasn't responded
//
2007-07-23 20:30:30 +00:00
function transfer_ok_time ( $team ) {
return $team -> ping_time + 60 * 86400 ;
}
function transfer_ok ( $team , $now ) {
if ( $now > transfer_ok_time ( $team )) return true ;
return false ;
}
2007-07-25 03:17:31 +00:00
// Make a team; args are untrusted, so cleanse and validate them
//
function make_team (
$userid , $name , $url , $type , $name_html , $description , $country
) {
2011-08-26 18:30:13 +00:00
$name = BoincDb :: escape_string ( sanitize_tags ( $name ));
2007-07-25 03:17:31 +00:00
if ( strlen ( $name ) == 0 ) return null ;
$name_lc = strtolower ( $name );
2011-08-26 18:30:13 +00:00
$url = BoincDb :: escape_string ( sanitize_tags ( $url ));
2007-07-25 03:17:31 +00:00
if ( strstr ( $url , " http:// " )) {
$url = substr ( $url , 7 );
}
2008-12-14 22:18:49 +00:00
$name_html = BoincDb :: escape_string ( $name_html );
$description = BoincDb :: escape_string ( $description );
2007-07-25 03:17:31 +00:00
if ( ! is_valid_country ( $country )) {
2010-09-07 18:20:29 +00:00
$country = tra ( 'None' );
2007-07-25 03:17:31 +00:00
}
2008-12-14 22:18:49 +00:00
$country = BoincDb :: escape_string ( $country ); // for Cote d'Ivoire
2007-07-25 03:17:31 +00:00
2007-10-29 16:38:25 +00:00
$clause = sprintf (
" (userid, create_time, name, name_lc, url, type, name_html, description, country, nusers, expavg_time) values(%d, %d, '%s', '%s', '%s', %d, '%s', '%s', '%s', %d, unix_timestamp()) " ,
2007-07-25 03:17:31 +00:00
$userid ,
time (),
$name ,
$name_lc ,
$url ,
$type ,
$name_html ,
$description ,
$country ,
0
);
2008-06-24 22:20:40 +00:00
$id = BoincTeam :: insert ( $clause );
if ( $id ) {
return BoincTeam :: lookup_id ( $id );
2007-07-25 03:17:31 +00:00
} else {
return null ;
}
}
2007-11-14 16:03:47 +00:00
$cvs_version_tracker [] = " \$ Id $ " ; //Generated automatically - do not edit
2004-02-02 23:34:39 +00:00
?>