2007-11-15 22:51:05 +00:00
< ? php
2008-08-05 22:43:14 +00:00
// This file is part of BOINC.
// http://boinc.berkeley.edu
2014-04-18 06:31:51 +00:00
// Copyright (C) 2014 University of California
2008-08-05 22:43:14 +00:00
//
// 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/>.
2007-11-15 22:51:05 +00:00
// create, manage, or read a team message board
require_once ( " ../inc/util.inc " );
require_once ( " ../inc/team.inc " );
require_once ( " ../inc/forum_db.inc " );
2014-04-18 06:31:51 +00:00
if ( DISABLE_TEAMS ) error_page ( " Teams are disabled " );
2011-02-09 22:11:34 +00:00
check_get_args ( array ( " tnow " , " ttok " , " teamid " , " cmd " ));
2007-11-15 22:51:05 +00:00
function create_confirm ( $user , $team ) {
2010-02-16 01:06:03 +00:00
page_head ( tra ( " Create Message Board " ));
echo tra ( " You may create a message board for use by %1. " , $team -> name ) . "
2007-11-15 22:51:05 +00:00
< ul >
2010-02-16 01:06:03 +00:00
< li > " .tra( " Only team members will be able to post . " ). "
< li > " .tra( " At your option , only members will be able to read . " ). "
< li > " .tra( " You and your Team Admins will have moderator privileges . " ). "
2007-11-15 22:51:05 +00:00
</ ul >
" ;
$tokens = url_tokens ( $user -> authenticator );
show_button (
" team_forum.php?teamid= $team->id &cmd=create $tokens " ,
2010-02-16 01:06:03 +00:00
tra ( " Create Message Board " ),
tra ( " Create a message board for %1 " , $team -> name )
2007-11-15 22:51:05 +00:00
);
page_tail ();
}
function create_forum ( $user , $team ) {
2007-11-23 16:26:41 +00:00
$f = BoincForum :: lookup ( " parent_type=1 and category= $team->id " );
if ( $f ) {
2010-02-16 01:06:03 +00:00
error_page ( tra ( " Team already has a message board " ));
2007-11-23 16:26:41 +00:00
}
2007-11-15 22:51:05 +00:00
$id = BoincForum :: insert ( " (category, parent_type) values ( $team->id , 1) " );
$forum = BoincForum :: lookup_id ( $id );
if ( ! $forum ) {
2011-08-25 22:12:48 +00:00
error_page ( " couldn't create message board " );
2007-11-15 22:51:05 +00:00
}
2007-11-16 21:31:43 +00:00
edit_form ( $user , $team , $forum , true );
2007-11-15 22:51:05 +00:00
}
2007-11-16 21:31:43 +00:00
function edit_form ( $user , $team , $forum , $first ) {
2010-02-16 01:06:03 +00:00
page_head ( tra ( " Team Message Board " ));
2007-11-15 22:51:05 +00:00
echo "
< form action = team_forum . php method = post >
< input type = hidden name = teamid value = $team -> id >
< input type = hidden name = cmd value = edit_action >
" ;
echo form_tokens ( $user -> authenticator );
start_table ();
2007-11-16 22:23:16 +00:00
if ( ! strlen ( $forum -> title )) $forum -> title = $team -> name ;
2010-02-16 01:06:03 +00:00
if ( ! strlen ( $forum -> description )) $forum -> description = tra ( " Discussion among members of %1 " , $team -> name );
2016-12-05 05:04:23 +00:00
row2 (
tra ( " Title " ),
'<input class="form-control" name="title" value="' . $forum -> title . '">'
);
2016-11-25 04:32:01 +00:00
row2 ( tra ( " Description " ),
'<textarea name="description" class="form-control">' . $forum -> description . '</textarea>'
);
2010-02-16 01:06:03 +00:00
row2 ( tra ( " Minimum time between posts (seconds) " ),
2016-12-05 05:04:23 +00:00
'<input class="form-control" name="post_min_interval" value="' . $forum -> post_min_interval . '">'
2007-11-15 22:51:05 +00:00
);
2010-02-16 01:06:03 +00:00
row2 ( tra ( " Minimum total credit to post " ),
2016-12-05 05:04:23 +00:00
'<input class="form-control" name="post_min_total_credit" value="' . $forum -> post_min_total_credit . '">'
2007-11-15 22:51:05 +00:00
);
2010-02-16 01:06:03 +00:00
row2 ( tra ( " Minimum average credit to post " ),
2016-12-05 05:04:23 +00:00
'<input class="form-control" name="post_min_expavg_credit" value="' . $forum -> post_min_expavg_credit . '">'
2007-11-15 22:51:05 +00:00
);
2016-12-05 05:04:23 +00:00
row2 ( " " , " <input class= \" btn btn-success \" type=submit value= " . tra ( " Submit " ) . " > " );
2007-11-15 22:51:05 +00:00
end_table ();
echo "
</ form >
" ;
2007-11-16 21:31:43 +00:00
if ( ! $first ) {
2016-10-28 09:59:08 +00:00
$tokens = url_tokens ( $user -> authenticator );
2007-11-16 21:31:43 +00:00
echo "
< p >
< a href = team_forum . php ? teamid = $team -> id & cmd = remove_confirm $tokens >
2010-02-16 01:06:03 +00:00
" .tra( " Remove your team ' s message board . " ). " </ a >
2007-11-16 21:31:43 +00:00
" ;
}
page_tail ();
}
function remove_confirm ( $user , $team ) {
$tokens = url_tokens ( $user -> authenticator );
2010-02-16 01:06:03 +00:00
page_head ( tra ( " Really remove message board? " ));
echo tra ( " Are you sure you want to remove your team's message board? All threads and posts will be permanently removed. (You may, however, create a new message board later). " )
. " <br /><br />
< a href = team_forum . php ? teamid = $team -> id & cmd = remove > " .tra( " Yes - remove message board " ). " </ a >
2007-11-16 21:31:43 +00:00
" ;
page_tail ();
}
function remove ( $team ) {
$forum = BoincForum :: lookup ( " parent_type=1 and category= $team->id " );
2011-08-25 22:12:48 +00:00
if ( ! $forum ) error_page ( " message board not found " );
2007-11-30 00:00:44 +00:00
// delete threads and posts
//
$threads = BoincThread :: enum ( " forum= $forum->id " );
foreach ( $threads as $thread ) {
$posts = BoincPost :: enum ( " thread= $thread->id " );
foreach ( $posts as $post ) {
$post -> delete ();
}
$thread -> delete ();
}
2007-11-16 21:31:43 +00:00
$forum -> delete ();
2010-02-16 01:06:03 +00:00
page_head ( tra ( " Message board removed " ));
2010-02-23 22:09:11 +00:00
echo " <p> "
. tra (
2017-07-04 11:13:01 +00:00
" Your team's message board has been removed. You may now %1 create a new one %2. " ,
2010-02-23 22:09:11 +00:00
" <a href=team_forum.php?teamid= $team->id &cmd=manage> " ,
" </a> "
)
. " </p> "
;
2007-11-15 22:51:05 +00:00
page_tail ();
}
function edit_action ( $forum ) {
2011-08-25 22:12:48 +00:00
$title = sanitize_tags ( post_str ( 'title' ));
2007-11-16 22:23:16 +00:00
$title = BoincDb :: escape_string ( $title );
2011-08-25 22:12:48 +00:00
$description = sanitize_tags ( post_str ( 'description' ));
2007-11-16 22:23:16 +00:00
$description = BoincDb :: escape_string ( $description );
2007-11-15 22:51:05 +00:00
$post_min_interval = post_int ( 'post_min_interval' );
$post_min_total_credit = post_int ( 'post_min_total_credit' );
$post_min_expavg_credit = post_int ( 'post_min_expavg_credit' );
2007-11-16 22:23:16 +00:00
$ret = $forum -> update ( " title=' $title ', description=' $description ', post_min_interval= $post_min_interval , post_min_total_credit= $post_min_total_credit , post_min_expavg_credit= $post_min_expavg_credit " );
2007-11-15 22:51:05 +00:00
if ( $ret ) {
2010-02-16 01:06:03 +00:00
page_head ( tra ( " Team Message Board Updated " ));
echo tra ( " Update successful " );
2007-11-15 22:51:05 +00:00
page_tail ();
} else {
2010-02-16 01:06:03 +00:00
error_page ( tra ( " Update failed " ));
2007-11-15 22:51:05 +00:00
}
}
function show_forum ( $team ) {
$forum = BoincForum :: lookup ( " parent_type=1 and category= $team->id " );
if ( ! $forum ) {
2011-08-25 22:12:48 +00:00
error_page ( tra ( " Team has no forum " ));
2007-11-15 22:51:05 +00:00
}
Header ( " Location: forum_forum.php?id= $forum->id " );
}
$teamid = get_int ( " teamid " , true );
if ( ! $teamid ) $teamid = post_int ( 'teamid' );
$team = BoincTeam :: lookup_id ( $teamid );
if ( ! $team ) {
2011-08-25 22:12:48 +00:00
error_page ( " no such team " );
2007-11-15 22:51:05 +00:00
}
$cmd = get_str ( 'cmd' , true );
if ( ! $cmd ) $cmd = post_str ( 'cmd' , true );
if ( $cmd == 'manage' ) {
$user = get_logged_in_user ();
require_founder_login ( $user , $team );
$forum = BoincForum :: lookup ( " parent_type=1 and category= $teamid " );
if ( ! $forum ) {
create_confirm ( $user , $team );
} else {
2007-11-16 21:31:43 +00:00
edit_form ( $user , $team , $forum , false );
2007-11-15 22:51:05 +00:00
}
} else if ( $cmd == 'create' ) {
$user = get_logged_in_user ();
check_tokens ( $user -> authenticator );
require_founder_login ( $user , $team );
create_forum ( $user , $team );
} else if ( $cmd == 'edit_action' ) {
$user = get_logged_in_user ();
require_founder_login ( $user , $team );
check_tokens ( $user -> authenticator );
$forum = BoincForum :: lookup ( " parent_type=1 and category= $teamid " );
2011-08-25 22:12:48 +00:00
if ( ! $forum ) error_page ( " no such forum " );
2007-11-15 22:51:05 +00:00
edit_action ( $forum );
2007-11-16 21:31:43 +00:00
} else if ( $cmd == " remove_confirm " ) {
$user = get_logged_in_user ();
require_founder_login ( $user , $team );
remove_confirm ( $user , $team );
} else if ( $cmd == " remove " ) {
$user = get_logged_in_user ();
require_founder_login ( $user , $team );
remove ( $team );
2007-11-15 22:51:05 +00:00
} else if ( $cmd != " " ) {
2011-08-25 22:12:48 +00:00
error_page ( " unknown command $cmd " );
2007-11-15 22:51:05 +00:00
} else {
show_forum ( $team );
}
?>