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 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');
40 $feedback = htmlspecialchars(getStringFromRequest('feedback'));
49 // Set up local objects
51 $g = group_get_object($group_id);
52 if (!$g || !is_object($g) || $g->isError()) {
56 session_require_perm ('forum_admin', $group_id) ;
58 if (getStringFromRequest('post_changes')) {
60 Update the DB to reflect the changes
67 $fa = new ForumAdmin($group_id);
68 $feedback .= $fa->ExecuteAction("delete_forum");
71 } else if (getStringFromRequest('add_forum')) {
72 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
73 exit_form_double_submit('forums');
76 if (check_email_available($g, $g->getUnixName() . '-' . getStringFromRequest('forum_name'), $error_msg)) {
77 $fa = new ForumAdmin($group_id);
78 $feedback .= $fa->ExecuteAction("add_forum");
79 $g->normalizeAllRoles () ;
81 } else if (getStringFromRequest('change_status')) {
82 $fa = new ForumAdmin($group_id);
83 $feedback .= $fa->ExecuteAction("change_status");
87 if (getStringFromRequest('add_forum')) {
89 Show the form for adding forums
91 forum_header(array('title'=>_('Add forum')));
94 <form method="post" action="'.getStringFromServer('PHP_SELF').'">
96 <input type="hidden" name="post_changes" value="y" />
97 <input type="hidden" name="add_forum" value="y" />
98 <input type="hidden" name="group_id" value="'.$group_id.'" />
99 <input type="hidden" name="form_key" value="' . form_generate_key() . '" />
100 <strong>'._('Forum Name').':</strong><br />
101 <input type="text" name="forum_name" value="" size="20" maxlength="30" />
104 <strong>'._('Description').':</strong><br />
105 <input type="text" name="description" value="" size="40" maxlength="80" />
108 <strong>'._('Is Public?').'</strong><br />
109 <input type="radio" name="is_public" value="1" checked="checked" />'._('Yes').' <br />
110 <input type="radio" name="is_public" value="0" />'._('No').'
113 <strong>'._('Allow Anonymous Posts?').'</strong><br />
114 <input type="radio" name="allow_anonymous" value="1" />'._('Yes').'<br />
115 <input type="radio" name="allow_anonymous" value="0" checked="checked" />'._('No').'
119 html_build_select_box_from_assoc(array("0" => _('No Moderation') ,"1" => _('Moderated Level 1'),"2" => _('Moderated Level 2') ),"moderation_level",0) . '
120 <br />' . _('Moderated Level 1') . ': ' . _('To moderate anonymous posts (if allowed in public forum) and posts from non-member users.') . '<br />' . _('Moderated Level 2') . ': ' . _('To moderate ALL posts.') . '<p>
122 <strong>'._('Email All Posts To:').'</strong><br />
123 <input type="text" name="send_all_posts_to" value="" size="60" />
126 <input type="submit" name="submit" value="'._('Add This Forum').'" />
130 forum_footer(array());
132 } else if (getStringFromRequest('change_status')) {
137 $f = new Forum ($g,$group_forum_id);
139 forum_header(array('title'=>_('Change forum status')));
140 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>';
141 $fa = new ForumAdmin($f->Group->getID());
142 $fa->PrintAdminPendingOption($group_forum_id);
145 <form action="'.getStringFromServer('PHP_SELF').'" method="post">
147 <input type="hidden" name="post_changes" value="y" />
148 <input type="hidden" name="change_status" value="y" />
149 <input type="hidden" name="group_forum_id" value="'. $f->getID() .'" />
150 <input type="hidden" name="group_id" value="'.$group_id.'" />
152 <strong>'._('Allow Anonymous Posts?').'</strong><br />
153 <input type="radio" name="allow_anonymous" value="1"'.(($f->AllowAnonymous() == 1)?' checked="checked"':'').' /> '._('Yes').'<br />
154 <input type="radio" name="allow_anonymous" value="0"'.(($f->AllowAnonymous() == 0)?' checked="checked"':'').'/> '._('No').'
157 <strong>'._('Is Public?').'</strong><br />
158 <input type="radio" name="is_public" value="1"'.(($f->isPublic() == 1)?' checked="checked"':'').' /> '._('Yes').'<br />
159 <input type="radio" name="is_public" value="0"'.(($f->isPublic() == 0)?' checked="checked"':'').' /> '._('No').'<br />
160 <input type="radio" name="is_public" value="9"'.(($f->isPublic() == 9)?' checked="checked"':'').' />'._('Suspended').'<br />
162 html_build_select_box_from_assoc(array("0" => _('No Moderation') ,"1" => _('Moderated Level 1'),"2" => _('Moderated Level 2') ),"moderation_level",$f->getModerationLevel()) . '
163 <br />' . _('Moderated Level 1') . ': ' . _('To moderate anonymous posts (if allowed in public forum) and posts from non-member users.') . '<br />' . _('Moderated Level 2') . ': ' . _('To moderate ALL posts.') . '<p>
166 <strong>'._('Forum Name').':</strong><br />
167 <input type="text" name="forum_name" value="'. $f->getName() .'" size="20" maxlength="30" />
170 <strong>'._('Email All Posts To:').'</strong><br />
171 <input type="text" name="send_all_posts_to" value="'. $f->getSendAllPostsTo() .'" size="60" />
174 <strong>'._('Description').':</strong><br />
175 <input type="text" name="description" value="'. $f->getDescription() .'" size="60" maxlength="80" /><br />
178 <input type="submit" name="submit" value="'._('Update').'" />
181 //echo '<a href="'.getStringFromServer('PHP_SELF').'?group_id='.$group_id.'&group_forum_id='.$group_forum_id.'&delete=1">'._('Delete Message').'</a><br />';
182 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>';
183 forum_footer(array());
185 } elseif ($deleteforum && $group_forum_id) {
187 $f = new Forum ($g,$group_forum_id);
189 forum_header(array('title'=>_('Delete')));
191 <strong>'._('You are about to permanently and irretrievably delete this entire forum and all its contents!').'</strong><br />
193 <form method="post" action="'.getStringFromServer('PHP_SELF').'">
194 <input type="hidden" name="post_changes" value="y" />
195 <input type="hidden" name="deleteforum" value="y" />
196 <input type="hidden" name="group_id" value="'.$group_id.'" />
197 <input type="hidden" name="group_forum_id" value="'.$group_forum_id.'" />
198 <input type="checkbox" name="sure" value="1" />'._('I\'m Sure').'<br />
199 <input type="checkbox" name="really_sure" value="1" />'._('I\'m Really Sure').'<br />
200 <input type="submit" name="submit" value="'._('Delete').'" />
202 forum_footer(array());
204 } elseif ( getStringFromRequest("deletemsg") ) {
205 // delete message handling
207 $forum_id = getIntFromRequest("forum_id");
208 $thread_id = getIntFromRequest("thread_id");
209 $msg_id = getIntFromRequest("deletemsg");
211 $f = forum_get_object ($forum_id) ;
213 $fa = new ForumAdmin($f->Group->getID());
215 if (getStringFromRequest("ok")) {
216 //actually delete the message
217 $feedback .= $fa->ExecuteAction("delete");
218 forum_header(array('title'=>_('Delete a Message')));
219 echo '<p>'.util_make_link ('/forum/forum.php?forum_id=' . $forum_id, _("Return to the forum")) . '</p>';
220 forum_footer(array());
221 } elseif (getStringFromRequest("cancel")) {
222 // the user cancelled the request, go back to forum
223 //if thread_id is 0, then we came from message.php. else, we came from forum.php
225 session_redirect('/forum/message.php?msg_id='.$msg_id);
227 session_redirect('/forum/forum.php?thread_id='.$thread_id.'&forum_id='.$forum_id);
231 //print the delete message confirmation
232 forum_header(array('title'=>_('Delete a Message')));
234 <form action="'.getStringFromServer('PHP_SELF').'" method="post">
235 <h3>' . _('WARNING! You are about to permanently delete a message and all of its followups!!') . '</h3>
237 <input type="submit" name="ok" value="' . _('Yes') . '" />
238 <input type="submit" name="cancel" value="' . _('No') . '" />
239 <input type="hidden" name="deletemsg" value="'.$msg_id.'" />
240 <input type="hidden" name="group_id" value="'.$group_id.'" />
241 <input type="hidden" name="forum_id" value="'.$forum_id.'" />
242 <input type="hidden" name="thread_id" value="'.$thread_id.'" />
246 forum_footer(array());
248 } elseif (getStringFromRequest("editmsg")) {
249 // edit message handling
250 $forum_id = getIntFromRequest("forum_id");
251 $thread_id = getIntFromRequest("thread_id");
252 $msg_id = getIntFromRequest("editmsg");
254 $f = forum_get_object ($forum_id) ;
255 $fa = new ForumAdmin($f->Group->getID());
257 if (getStringFromRequest("ok")) {
258 //actually finish editing the message and save the contents
259 $f = new Forum ($fa->GetGroupObject(),$forum_id);
260 if (!$f || !is_object($f)) {
261 exit_error(_('Error Getting Forum'),'forums');
262 } elseif ($f->isError()) {
263 exit_error($f->getErrorMessage(),'forums');
265 $fm=new ForumMessage($f,$msg_id,false,false);
266 if (!$fm || !is_object($fm)) {
267 exit_error(_('Error getting new forum message'),'forums');
268 } elseif ($fm->isError()) {
269 exit_error($fm->getErrorMessage(),'forums');
271 $subject = getStringFromRequest('subject');
272 $body = getStringFromRequest('body');
274 $sanitizer = new TextSanitizer();
275 $body = $sanitizer->SanitizeHtml($body);
277 $is_followup_to = getStringFromRequest('is_followup_to');
278 $form_key = getStringFromRequest('form_key');
279 $posted_by = getStringFromRequest('posted_by');
280 $post_date = getStringFromRequest('post_date');
281 $is_followup_to = getStringFromRequest('is_followup_to');
282 $has_followups = getStringFromRequest('has_followups');
283 $most_recent_date = getStringFromRequest('most_recent_date');
284 if ($fm->updatemsg($forum_id,$posted_by,$subject,$body,$post_date,$is_followup_to,$thread_id,$has_followups,$most_recent_date)) {
285 $feedback .= _('Message Edited Successfully');
287 $error_msg .= $fm->getErrorMessage();
289 forum_header(array('title'=>_('Edit a Message')));
290 echo '<p>'.util_make_link ('/forum/forum.php?forum_id=' . $forum_id, _("Return to the forum")) ;
291 forum_footer(array());
292 } elseif (getStringFromRequest("cancel")) {
293 // the user cancelled the request, go back to forum
294 session_redirect('/forum/message.php?msg_id='.$msg_id);
296 //print the edit message confirmation
298 $f = new Forum ($fa->GetGroupObject(),$forum_id);
299 if (!$f || !is_object($f)) {
300 exit_error(_('Error Getting Forum'),'forums');
301 } elseif ($f->isError()) {
302 exit_error($f->getErrorMessage(),'forums');
305 $fm=new ForumMessage($f,$msg_id,false,false);
306 if (!$fm || !is_object($fm)) {
307 exit_error(_('Error Getting ForumMessage'),'forums');
308 } elseif ($fm->isError()) {
309 exit_error($fm->getErrorMessage(),'forums');
312 $fh = new ForumHTML($f);
313 if (!$fh || !is_object($fh)) {
314 exit_error(_('Error Getting ForumHTML'),'forums');
315 } elseif ($fh->isError()) {
316 exit_error($fh->getErrorMessage(),'forums');
319 forum_header(array('title'=>_('Edit a Message')));
320 $fh->showEditForm($fm);
321 forum_footer(array());
323 } elseif (getStringFromRequest("movethread")) {
324 $thread_id = getIntFromRequest("movethread");
325 $msg_id = getStringFromRequest("msg_id");
326 $forum_id = getIntFromRequest("forum_id");
327 $return_to_message = getIntFromRequest("return_to_message");
328 $new_forum_id = getIntFromRequest("new_forum_id");
329 $f = forum_get_object ($forum_id) ;
330 $fa = new ForumAdmin($f->Group->getID());
332 if (getStringFromRequest("ok")) {
333 if ($forum_id == $new_forum_id) {
334 $feedback .= _('Thread not moved');
337 // Move message in another forum
338 $f_from = new Forum ($fa->GetGroupObject(),$forum_id);
339 if (!$f_from || !is_object($f_from)) {
340 exit_error(_('Could Not Get Forum Object'),'forums');
341 } elseif ($f_from->isError()) {
342 exit_error($f_from->getErrorMessage(),'forums');
344 $f_to = new Forum ($fa->GetGroupObject(),$new_forum_id);
345 if (!$f_to || !is_object($f_to)) {
346 exit_error(_('Could Not Get Forum Object'),'forums');
347 } elseif ($f_to->isError()) {
348 exit_error($f_to->getErrorMessage(),'forums');
351 $ff = new ForumFactory($g);
352 if (!$ff || !is_object($ff) || $ff->isError()) {
353 exit_error($ff->getErrorMessage(),'forums');
356 if ($ff->moveThread($new_forum_id,$thread_id,$forum_id)) {
357 $feedback .= sprintf(_('Thread successfully moved from %1$s forum to %2$s forum'), $f_from->getName(),$f_to->getName());
359 $error_msg .= $ff->getErrorMessage();
363 forum_header(array('title'=>_('Edit a Message')));
364 echo '<p><a href="/forum/forum.php?forum_id=' . $new_forum_id . '">Return to the forum</a></p>';
365 echo '<p><a href="/forum/forum.php?thread_id='.$thread_id.'&forum_id=' . $new_forum_id . '">Return to the thread</a></p>';
366 forum_footer(array());
367 } elseif (getStringFromRequest("cancel")) {
368 // the user cancelled the request, go back to forum
369 if ($return_to_message) {
370 session_redirect('/forum/message.php?msg_id='.$msg_id);
372 session_redirect('/forum/forum.php?thread_id='.$thread_id.'&forum_id='.$forum_id);
376 // Display select box to select new forum
378 forum_header(array('title'=>_('Move Thread')));
380 $ff = new ForumFactory($g);
381 if (!$ff || !is_object($ff) || $ff->isError()) {
382 exit_error($ff->getErrorMessage(),'forums');
385 $farr = $ff->getForums();
387 if ($ff->isError()) {
388 echo '<p class="error">'.sprintf(_('No Forums Found For %s'), $g->getPublicName())
389 . $ff->getErrorMessage().'</p>';
390 forum_footer(array());
395 List the existing forums so they can be edited.
399 for ($j = 0; $j < count($farr); $j++) {
400 if (!is_object($farr[$j])) {
401 //just skip it - this object should never have been placed here
402 } elseif ($farr[$j]->isError()) {
403 echo $farr[$j]->getErrorMessage();
405 $forums[$farr[$j]->getID()] = $farr[$j]->getName();
409 $f_from = new Forum ($fa->GetGroupObject(),$forum_id);
410 if (!$f_from || !is_object($f_from)) {
411 exit_error(_('Could Not Get Forum Object'),'forums');
412 } elseif ($f_from->isError()) {
413 exit_error($f_from->getErrorMessage(),'forums');
417 <form action="'.getStringFromServer('PHP_SELF').'" method="post">
418 <p><strong>' . sprintf(_('Move thread from %s forum to the following forum:'), $f_from->getName()) . '</strong></p>
420 <input type="hidden" name="movethread" value="'.$thread_id.'" />
421 <input type="hidden" name="group_id" value="'.$group_id.'" />
422 <input type="hidden" name="forum_id" value="'.$forum_id.'" />
423 <input type="hidden" name="msg_id" value="'.$msg_id.'" />
424 <input type="hidden" name="return_to_message" value="'.$return_to_message.'" />' .
425 html_build_select_box_from_assoc($forums,'new_forum_id',$forum_id) .
427 <input type="submit" name="ok" value="' . _("Submit") . '" />
428 <input type="submit" name="cancel" value="' . _("Cancel") . '" />
433 forum_footer(array());
438 Show main page for choosing
439 either moderator or delete
441 forum_header(array('title'=>_('Forums Administration')));
446 $fa = new ForumAdmin($g->getID());
448 $fa->PrintAdminOptions();
451 plugin_hook ("blocks", "forum index");
454 // Get existing forums
456 $ff=new ForumFactory($g);
457 if (!$ff || !is_object($ff) || $ff->isError()) {
458 exit_error($ff->getErrorMessage(),'forums');
461 $farr = $ff->getForumsAdmin();
463 if ($ff->isError()) {
464 echo '<p class="error">'.sprintf(_('No Forums Found For %s'), $g->getPublicName())
465 . $ff->getErrorMessage().'</p>';
466 forum_footer(array());
471 List the existing forums so they can be edited.
474 for ($j = 0; $j < count($farr); $j++) {
475 if (!is_object($farr[$j])) {
476 //just skip it - this object should never have been placed here
477 } elseif ($farr[$j]->isError()) {
478 echo $farr[$j]->getErrorMessage();
480 echo '<p><a href="'.getStringFromServer('PHP_SELF').'?group_id='.$group_id.'&change_status=1&group_forum_id='. $farr[$j]->getID() .'">'.
481 $farr[$j]->getName() .'</a><br />'.$farr[$j]->getDescription().'<br /><a href="monitor.php?group_id='.$group_id.'&group_forum_id='. $farr[$j]->getID() .'">'.
482 _('Monitoring Users').'</a></p>';
486 forum_footer(array());
491 // c-file-style: "bsd"