5 * Copyright 1999-2001 (c) VA Linux Systems
6 * Copyright 2002-2004 (c) GForge Team
7 * Copyright 2010 (c) Franck Villaume - Capgemini
8 * Copyright (C) 2011-2012 Alain Peyrat - Alcatel-Lucent
9 * http://fusionforge.org/
11 * This file is part of FusionForge. FusionForge is free software;
12 * you can redistribute it and/or modify it under the terms of the
13 * GNU General Public License as published by the Free Software
14 * Foundation; either version 2 of the Licence, or (at your option)
17 * FusionForge is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 require_once('../../env.inc.php');
28 require_once $gfcommon.'include/pre.php';
29 require_once $gfcommon.'forum/ForumHTML.class.php';
30 require_once $gfcommon.'forum/Forum.class.php';
31 require_once $gfcommon.'forum/ForumAdmin.class.php';
32 require_once $gfcommon.'forum/ForumFactory.class.php';
33 require_once $gfcommon.'forum/ForumMessageFactory.class.php';
34 require_once $gfcommon.'forum/ForumMessage.class.php';
35 require_once $gfcommon.'include/TextSanitizer.class.php'; // to make the HTML input by the user safe to store
37 $group_id = getIntFromRequest('group_id');
38 $group_forum_id = getIntFromRequest('group_forum_id');
39 $deleteforum = getStringFromRequest('deleteforum');
48 // Set up local objects
50 $g = group_get_object($group_id);
51 if (!$g || !is_object($g) || $g->isError()) {
55 session_require_perm ('forum_admin', $group_id) ;
57 if (getStringFromRequest('post_changes')) {
59 Update the DB to reflect the changes
66 $fa = new ForumAdmin($group_id);
67 $feedback .= $fa->ExecuteAction("delete_forum");
70 } else if (getStringFromRequest('add_forum')) {
71 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
72 exit_form_double_submit('forums');
75 if (check_email_available($g, $g->getUnixName() . '-' . getStringFromRequest('forum_name'), $error_msg)) {
76 $fa = new ForumAdmin($group_id);
77 $feedback .= $fa->ExecuteAction("add_forum");
78 $g->normalizeAllRoles () ;
80 } else if (getStringFromRequest('change_status')) {
81 $fa = new ForumAdmin($group_id);
82 $feedback .= $fa->ExecuteAction("change_status");
86 if (getStringFromRequest('add_forum')) {
88 Show the form for adding forums
90 forum_header(array('title'=>_('Add forum')));
93 <form method="post" action="'.getStringFromServer('PHP_SELF').'">
95 <input type="hidden" name="post_changes" value="y" />
96 <input type="hidden" name="add_forum" value="y" />
97 <input type="hidden" name="group_id" value="'.$group_id.'" />
98 <input type="hidden" name="form_key" value="' . form_generate_key() . '" />
99 <strong>'._('Forum Name').':</strong><br />
100 <input type="text" name="forum_name" value="" size="20" maxlength="30" />
103 <strong>'._('Description').':</strong><br />
104 <input type="text" name="description" value="" size="40" maxlength="80" />
107 <strong>'._('Email All Posts To:').'</strong><br />
108 <input type="text" name="send_all_posts_to" value="" size="60" />
111 <input type="submit" name="submit" value="'._('Add This Forum').'" />
115 forum_footer(array());
117 } else if (getStringFromRequest('change_status')) {
122 $f = new Forum ($g,$group_forum_id);
124 forum_header(array('title'=>_('Change forum status')));
125 echo '<p>'._('You can adjust forum features from here. Please note that private forums can still be viewed by members of your project, not the general public.').'</p>';
126 $fa = new ForumAdmin($f->Group->getID());
127 $fa->PrintAdminPendingOption($group_forum_id);
130 <form action="'.getStringFromServer('PHP_SELF').'" method="post">
132 <input type="hidden" name="post_changes" value="y" />
133 <input type="hidden" name="change_status" value="y" />
134 <input type="hidden" name="group_forum_id" value="'. $f->getID() .'" />
135 <input type="hidden" name="group_id" value="'.$group_id.'" />
136 <strong>'._('Forum Name').':</strong><br />
137 <input type="text" name="forum_name" value="'. $f->getName() .'" size="20" maxlength="30" />
140 <strong>'._('Email All Posts To:').'</strong><br />
141 <input type="text" name="send_all_posts_to" value="'. $f->getSendAllPostsTo() .'" size="60" />
144 <strong>'._('Description').':</strong><br />
145 <input type="text" name="description" value="'. $f->getDescription() .'" size="60" maxlength="80" /><br />
148 <input type="submit" name="submit" value="'._('Update').'" />
151 //echo '<a href="'.getStringFromServer('PHP_SELF').'?group_id='.$group_id.'&group_forum_id='.$group_forum_id.'&delete=1">'._('Delete Message').'</a><br />';
152 echo '<a href="'.getStringFromServer('PHP_SELF').'?group_id='.$group_id.'&group_forum_id='.$group_forum_id.'&deleteforum=1">'._('Delete entire forum and all content').'</a></p>';
153 forum_footer(array());
155 } elseif ($deleteforum && $group_forum_id) {
157 $f = new Forum ($g,$group_forum_id);
159 forum_header(array('title'=>_('Delete')));
161 <strong>'._('You are about to permanently and irretrievably delete this entire forum and all its contents!').'</strong><br />
163 <form method="post" action="'.getStringFromServer('PHP_SELF').'">
164 <input type="hidden" name="post_changes" value="y" />
165 <input type="hidden" name="deleteforum" value="y" />
166 <input type="hidden" name="group_id" value="'.$group_id.'" />
167 <input type="hidden" name="group_forum_id" value="'.$group_forum_id.'" />
168 <input type="checkbox" name="sure" value="1" />'._('I\'m Sure').'<br />
169 <input type="checkbox" name="really_sure" value="1" />'._('I\'m Really Sure').'<br />
170 <input type="submit" name="submit" value="'._('Delete').'" />
172 forum_footer(array());
174 } elseif ( getStringFromRequest("deletemsg") ) {
175 // delete message handling
177 $forum_id = getIntFromRequest("forum_id");
178 $thread_id = getIntFromRequest("thread_id");
179 $msg_id = getIntFromRequest("deletemsg");
181 $f = forum_get_object ($forum_id) ;
183 $fa = new ForumAdmin($f->Group->getID());
185 if (getStringFromRequest("ok")) {
186 //actually delete the message
187 $feedback .= $fa->ExecuteAction("delete");
188 forum_header(array('title'=>_('Delete a Message')));
189 echo '<p>'.util_make_link ('/forum/forum.php?forum_id=' . $forum_id, _("Return to the forum")) . '</p>';
190 forum_footer(array());
191 } elseif (getStringFromRequest("cancel")) {
192 // the user cancelled the request, go back to forum
193 //if thread_id is 0, then we came from message.php. else, we came from forum.php
195 session_redirect('/forum/message.php?msg_id='.$msg_id);
197 session_redirect('/forum/forum.php?thread_id='.$thread_id.'&forum_id='.$forum_id);
201 //print the delete message confirmation
202 forum_header(array('title'=>_('Delete a Message')));
204 <form action="'.getStringFromServer('PHP_SELF').'" method="post">
205 <h3>' . _('WARNING! You are about to permanently delete a message and all of its followups!!') . '</h3>
207 <input type="submit" name="ok" value="' . _('Yes') . '" />
208 <input type="submit" name="cancel" value="' . _('No') . '" />
209 <input type="hidden" name="deletemsg" value="'.$msg_id.'" />
210 <input type="hidden" name="group_id" value="'.$group_id.'" />
211 <input type="hidden" name="forum_id" value="'.$forum_id.'" />
212 <input type="hidden" name="thread_id" value="'.$thread_id.'" />
216 forum_footer(array());
218 } elseif (getStringFromRequest("editmsg")) {
219 // edit message handling
220 $forum_id = getIntFromRequest("forum_id");
221 $thread_id = getIntFromRequest("thread_id");
222 $msg_id = getIntFromRequest("editmsg");
224 $f = forum_get_object ($forum_id) ;
225 $fa = new ForumAdmin($f->Group->getID());
227 if (getStringFromRequest("ok")) {
228 //actually finish editing the message and save the contents
229 $f = new Forum ($fa->GetGroupObject(),$forum_id);
230 if (!$f || !is_object($f)) {
231 exit_error(_('Error Getting Forum'),'forums');
232 } elseif ($f->isError()) {
233 exit_error($f->getErrorMessage(),'forums');
235 $fm=new ForumMessage($f,$msg_id,false,false);
236 if (!$fm || !is_object($fm)) {
237 exit_error(_('Error getting new forum message'),'forums');
238 } elseif ($fm->isError()) {
239 exit_error($fm->getErrorMessage(),'forums');
241 $subject = getStringFromRequest('subject');
242 $body = getStringFromRequest('body');
244 $sanitizer = new TextSanitizer();
245 $body = $sanitizer->SanitizeHtml($body);
247 $is_followup_to = getStringFromRequest('is_followup_to');
248 $form_key = getStringFromRequest('form_key');
249 $posted_by = getStringFromRequest('posted_by');
250 $post_date = getStringFromRequest('post_date');
251 $is_followup_to = getStringFromRequest('is_followup_to');
252 $has_followups = getStringFromRequest('has_followups');
253 $most_recent_date = getStringFromRequest('most_recent_date');
254 if ($fm->updatemsg($forum_id,$posted_by,$subject,$body,$post_date,$is_followup_to,$thread_id,$has_followups,$most_recent_date)) {
255 $feedback .= _('Message Edited Successfully');
257 $error_msg .= $fm->getErrorMessage();
259 forum_header(array('title'=>_('Edit a Message')));
260 echo '<p>'.util_make_link ('/forum/forum.php?forum_id=' . $forum_id, _("Return to the forum")) ;
261 forum_footer(array());
262 } elseif (getStringFromRequest("cancel")) {
263 // the user cancelled the request, go back to forum
264 session_redirect('/forum/message.php?msg_id='.$msg_id);
266 //print the edit message confirmation
268 $f = new Forum ($fa->GetGroupObject(),$forum_id);
269 if (!$f || !is_object($f)) {
270 exit_error(_('Error Getting Forum'),'forums');
271 } elseif ($f->isError()) {
272 exit_error($f->getErrorMessage(),'forums');
275 $fm=new ForumMessage($f,$msg_id,false,false);
276 if (!$fm || !is_object($fm)) {
277 exit_error(_('Error Getting ForumMessage'),'forums');
278 } elseif ($fm->isError()) {
279 exit_error($fm->getErrorMessage(),'forums');
282 $fh = new ForumHTML($f);
283 if (!$fh || !is_object($fh)) {
284 exit_error(_('Error Getting ForumHTML'),'forums');
285 } elseif ($fh->isError()) {
286 exit_error($fh->getErrorMessage(),'forums');
289 forum_header(array('title'=>_('Edit a Message')));
290 $fh->showEditForm($fm);
291 forum_footer(array());
293 } elseif (getStringFromRequest("movethread")) {
294 $thread_id = getIntFromRequest("movethread");
295 $msg_id = getStringFromRequest("msg_id");
296 $forum_id = getIntFromRequest("forum_id");
297 $return_to_message = getIntFromRequest("return_to_message");
298 $new_forum_id = getIntFromRequest("new_forum_id");
299 $f = forum_get_object ($forum_id) ;
300 $fa = new ForumAdmin($f->Group->getID());
302 if (getStringFromRequest("ok")) {
303 if ($forum_id == $new_forum_id) {
304 $feedback .= _('Thread not moved');
307 // Move message in another forum
308 $f_from = new Forum ($fa->GetGroupObject(),$forum_id);
309 if (!$f_from || !is_object($f_from)) {
310 exit_error(_('Could Not Get Forum Object'),'forums');
311 } elseif ($f_from->isError()) {
312 exit_error($f_from->getErrorMessage(),'forums');
314 $f_to = new Forum ($fa->GetGroupObject(),$new_forum_id);
315 if (!$f_to || !is_object($f_to)) {
316 exit_error(_('Could Not Get Forum Object'),'forums');
317 } elseif ($f_to->isError()) {
318 exit_error($f_to->getErrorMessage(),'forums');
321 $ff = new ForumFactory($g);
322 if (!$ff || !is_object($ff) || $ff->isError()) {
323 exit_error($ff->getErrorMessage(),'forums');
326 if ($ff->moveThread($new_forum_id,$thread_id,$forum_id)) {
327 $feedback .= sprintf(_('Thread successfully moved from %1$s forum to %2$s forum'), $f_from->getName(),$f_to->getName());
329 $error_msg .= $ff->getErrorMessage();
333 forum_header(array('title'=>_('Edit a Message')));
334 echo '<p><a href="/forum/forum.php?forum_id=' . $new_forum_id . '">Return to the forum</a></p>';
335 echo '<p><a href="/forum/forum.php?thread_id='.$thread_id.'&forum_id=' . $new_forum_id . '">Return to the thread</a></p>';
336 forum_footer(array());
337 } elseif (getStringFromRequest("cancel")) {
338 // the user cancelled the request, go back to forum
339 if ($return_to_message) {
340 session_redirect('/forum/message.php?msg_id='.$msg_id);
342 session_redirect('/forum/forum.php?thread_id='.$thread_id.'&forum_id='.$forum_id);
346 // Display select box to select new forum
348 forum_header(array('title'=>_('Move Thread')));
350 $ff = new ForumFactory($g);
351 if (!$ff || !is_object($ff) || $ff->isError()) {
352 exit_error($ff->getErrorMessage(),'forums');
355 $farr = $ff->getForums();
357 if ($ff->isError()) {
358 echo '<p class="error">'.sprintf(_('No Forums Found For %s'), $g->getPublicName())
359 . $ff->getErrorMessage().'</p>';
360 forum_footer(array());
365 List the existing forums so they can be edited.
369 for ($j = 0; $j < count($farr); $j++) {
370 if (!is_object($farr[$j])) {
371 //just skip it - this object should never have been placed here
372 } elseif ($farr[$j]->isError()) {
373 echo $farr[$j]->getErrorMessage();
375 $forums[$farr[$j]->getID()] = $farr[$j]->getName();
379 $f_from = new Forum ($fa->GetGroupObject(),$forum_id);
380 if (!$f_from || !is_object($f_from)) {
381 exit_error(_('Could Not Get Forum Object'),'forums');
382 } elseif ($f_from->isError()) {
383 exit_error($f_from->getErrorMessage(),'forums');
387 <form action="'.getStringFromServer('PHP_SELF').'" method="post">
388 <p><strong>' . sprintf(_('Move thread from %s forum to the following forum:'), $f_from->getName()) . '</strong></p>
390 <input type="hidden" name="movethread" value="'.$thread_id.'" />
391 <input type="hidden" name="group_id" value="'.$group_id.'" />
392 <input type="hidden" name="forum_id" value="'.$forum_id.'" />
393 <input type="hidden" name="msg_id" value="'.$msg_id.'" />
394 <input type="hidden" name="return_to_message" value="'.$return_to_message.'" />' .
395 html_build_select_box_from_assoc($forums,'new_forum_id',$forum_id) .
397 <input type="submit" name="ok" value="' . _("Submit") . '" />
398 <input type="submit" name="cancel" value="' . _("Cancel") . '" />
403 forum_footer(array());
408 Show main page for choosing
409 either moderator or delete
411 forum_header(array('title'=>_('Forums Administration')));
416 $fa = new ForumAdmin($g->getID());
418 $fa->PrintAdminOptions();
421 plugin_hook ("blocks", "forum index");
424 // Get existing forums
426 $ff=new ForumFactory($g);
427 if (!$ff || !is_object($ff) || $ff->isError()) {
428 exit_error($ff->getErrorMessage(),'forums');
431 $farr = $ff->getForumsAdmin();
433 if ($ff->isError()) {
434 echo '<p class="error">'.sprintf(_('No Forums Found For %s'), $g->getPublicName())
435 . $ff->getErrorMessage().'</p>';
436 forum_footer(array());
441 List the existing forums so they can be edited.
444 for ($j = 0; $j < count($farr); $j++) {
445 if (!is_object($farr[$j])) {
446 //just skip it - this object should never have been placed here
447 } elseif ($farr[$j]->isError()) {
448 echo $farr[$j]->getErrorMessage();
450 echo '<p><a href="'.getStringFromServer('PHP_SELF').'?group_id='.$group_id.'&change_status=1&group_forum_id='. $farr[$j]->getID() .'">'.
451 $farr[$j]->getName() .'</a><br />'.$farr[$j]->getDescription().'<br /><a href="monitor.php?group_id='.$group_id.'&group_forum_id='. $farr[$j]->getID() .'">'.
452 _('Monitoring Users').'</a></p>';
456 forum_footer(array());
461 // c-file-style: "bsd"