1<?php 2// This file is part of BOINC. 3// http://boinc.berkeley.edu 4// Copyright (C) 2014 University of California 5// 6// BOINC is free software; you can redistribute it and/or modify it 7// under the terms of the GNU Lesser General Public License 8// as published by the Free Software Foundation, 9// either version 3 of the License, or (at your option) any later version. 10// 11// BOINC is distributed in the hope that it will be useful, 12// but WITHOUT ANY WARRANTY; without even the implied warranty of 13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 14// See the GNU Lesser General Public License for more details. 15// 16// You should have received a copy of the GNU Lesser General Public License 17// along with BOINC. If not, see <http://www.gnu.org/licenses/>. 18 19// create, manage, or read a team message board 20 21require_once("../inc/util.inc"); 22require_once("../inc/team.inc"); 23require_once("../inc/forum_db.inc"); 24 25if (DISABLE_TEAMS) error_page("Teams are disabled"); 26 27check_get_args(array("tnow", "ttok", "teamid", "cmd")); 28 29function create_confirm($user, $team) { 30 page_head(tra("Create Message Board")); 31 echo tra("You may create a message board for use by %1.", $team->name)." 32 <ul> 33 <li>".tra("Only team members will be able to post.")." 34 <li>".tra("At your option, only members will be able to read.")." 35 <li>".tra("You and your Team Admins will have moderator privileges.")." 36 </ul> 37 "; 38 $tokens = url_tokens($user->authenticator); 39 show_button( 40 "team_forum.php?teamid=$team->id&cmd=create$tokens", 41 tra("Create Message Board"), 42 tra("Create a message board for %1", $team->name) 43 ); 44 page_tail(); 45} 46 47function create_forum($user, $team) { 48 $f = BoincForum::lookup("parent_type=1 and category=$team->id"); 49 if ($f) { 50 error_page(tra("Team already has a message board")); 51 } 52 $id = BoincForum::insert("(category, parent_type) values ($team->id, 1)"); 53 $forum = BoincForum::lookup_id($id); 54 if (!$forum) { 55 error_page("couldn't create message board"); 56 } 57 edit_form($user, $team, $forum, true); 58} 59 60function edit_form($user, $team, $forum, $first) { 61 page_head(tra("Team Message Board")); 62 echo " 63 <form action=team_forum.php method=post> 64 <input type=hidden name=teamid value=$team->id> 65 <input type=hidden name=cmd value=edit_action> 66 "; 67 echo form_tokens($user->authenticator); 68 start_table(); 69 if (!strlen($forum->title)) $forum->title = $team->name; 70 if (!strlen($forum->description)) $forum->description = tra("Discussion among members of %1", $team->name); 71 row2( 72 tra("Title"), 73 '<input class="form-control" name="title" value="'.$forum->title.'">' 74 ); 75 row2(tra("Description"), 76 '<textarea name="description" class="form-control">'.$forum->description.'</textarea>' 77 ); 78 row2(tra("Minimum time between posts (seconds)"), 79 '<input class="form-control" name="post_min_interval" value="'.$forum->post_min_interval.'">' 80 ); 81 row2(tra("Minimum total credit to post"), 82 '<input class="form-control" name="post_min_total_credit" value="'.$forum->post_min_total_credit.'">' 83 ); 84 row2(tra("Minimum average credit to post"), 85 '<input class="form-control" name="post_min_expavg_credit" value="'.$forum->post_min_expavg_credit.'">' 86 ); 87 row2("", "<input class=\"btn btn-success\" type=submit value=".tra("Submit").">"); 88 end_table(); 89 echo " 90 </form> 91 "; 92 if (!$first) { 93 $tokens = url_tokens($user->authenticator); 94 echo " 95 <p> 96 <a href=team_forum.php?teamid=$team->id&cmd=remove_confirm$tokens> 97 ".tra("Remove your team's message board.")."</a> 98 "; 99 } 100 page_tail(); 101} 102 103function remove_confirm($user, $team) { 104 $tokens = url_tokens($user->authenticator); 105 page_head(tra("Really remove message board?")); 106 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).") 107 ."<br /><br /> 108 <a href=team_forum.php?teamid=$team->id&cmd=remove>".tra("Yes - remove message board")."</a> 109 "; 110 page_tail(); 111} 112 113function remove($team) { 114 $forum = BoincForum::lookup("parent_type=1 and category=$team->id"); 115 if (!$forum) error_page("message board not found"); 116 117 // delete threads and posts 118 // 119 $threads = BoincThread::enum("forum=$forum->id"); 120 foreach ($threads as $thread) { 121 $posts = BoincPost::enum("thread=$thread->id"); 122 foreach ($posts as $post) { 123 $post->delete(); 124 } 125 $thread->delete(); 126 } 127 $forum->delete(); 128 129 page_head(tra("Message board removed")); 130 echo "<p>" 131 .tra( 132 "Your team's message board has been removed. You may now %1create a new one%2.", 133 "<a href=team_forum.php?teamid=$team->id&cmd=manage>", 134 "</a>" 135 ) 136 ."</p>" 137 ; 138 page_tail(); 139} 140 141function edit_action($forum) { 142 $title = sanitize_tags(post_str('title')); 143 $title = BoincDb::escape_string($title); 144 $description = sanitize_tags(post_str('description')); 145 $description = BoincDb::escape_string($description); 146 $post_min_interval = post_int('post_min_interval'); 147 $post_min_total_credit = post_int('post_min_total_credit'); 148 $post_min_expavg_credit = post_int('post_min_expavg_credit'); 149 $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"); 150 if ($ret) { 151 page_head(tra("Team Message Board Updated")); 152 echo tra("Update successful"); 153 page_tail(); 154 } else { 155 error_page(tra("Update failed")); 156 } 157} 158 159function show_forum($team) { 160 $forum = BoincForum::lookup("parent_type=1 and category=$team->id"); 161 if (!$forum) { 162 error_page(tra("Team has no forum")); 163 } 164 Header("Location: forum_forum.php?id=$forum->id"); 165} 166 167$teamid = get_int("teamid", true); 168if (!$teamid) $teamid = post_int('teamid'); 169 170$team = BoincTeam::lookup_id($teamid); 171if (!$team) { 172 error_page("no such team"); 173} 174 175$cmd = get_str('cmd', true); 176if (!$cmd) $cmd = post_str('cmd', true); 177 178if ($cmd == 'manage') { 179 $user = get_logged_in_user(); 180 require_founder_login($user, $team); 181 $forum = BoincForum::lookup("parent_type=1 and category=$teamid"); 182 if (!$forum) { 183 create_confirm($user, $team); 184 } else { 185 edit_form($user, $team, $forum, false); 186 } 187} else if ($cmd == 'create') { 188 $user = get_logged_in_user(); 189 check_tokens($user->authenticator); 190 require_founder_login($user, $team); 191 create_forum($user, $team); 192} else if ($cmd == 'edit_action') { 193 $user = get_logged_in_user(); 194 require_founder_login($user, $team); 195 check_tokens($user->authenticator); 196 $forum = BoincForum::lookup("parent_type=1 and category=$teamid"); 197 if (!$forum) error_page("no such forum"); 198 edit_action($forum); 199} else if ($cmd == "remove_confirm") { 200 $user = get_logged_in_user(); 201 require_founder_login($user, $team); 202 remove_confirm($user, $team); 203} else if ($cmd == "remove") { 204 $user = get_logged_in_user(); 205 require_founder_login($user, $team); 206 remove($team); 207} else if ($cmd != "") { 208 error_page("unknown command $cmd"); 209} else { 210 show_forum($team); 211} 212 213?> 214