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.
13 * FusionForge is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * FusionForge is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with FusionForge; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 require_once('../../env.inc.php');
29 require_once $gfcommon.'include/pre.php';
30 require_once $gfcommon.'forum/ForumHTML.class.php';
31 require_once $gfcommon.'forum/Forum.class.php';
32 require_once $gfcommon.'forum/ForumAdmin.class.php';
33 require_once $gfcommon.'forum/ForumFactory.class.php';
34 require_once $gfcommon.'forum/ForumMessageFactory.class.php';
35 require_once $gfcommon.'forum/ForumMessage.class.php';
36 require_once $gfcommon.'include/TextSanitizer.class.php'; // to make the HTML input by the user safe to store
38 $group_id = getIntFromRequest('group_id');
39 $group_forum_id = getIntFromRequest('group_forum_id');
40 $deleteforum = getStringFromRequest('deleteforum');
41 $feedback = htmlspecialchars(getStringFromRequest('feedback'));
50 // Set up local objects
52 $g = group_get_object($group_id);
53 if (!$g || !is_object($g) || $g->isError()) {
57 session_require_perm ('forum_admin', $group_id) ;
59 if (getStringFromRequest('post_changes')) {
61 Update the DB to reflect the changes
68 $fa = new ForumAdmin($group_id);
69 $feedback .= $fa->ExecuteAction("delete_forum");
72 } else if (getStringFromRequest('add_forum')) {
73 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
74 exit_form_double_submit('forums');
77 if (check_email_available($g, $g->getUnixName() . '-' . getStringFromRequest('forum_name'), $error_msg)) {
78 $fa = new ForumAdmin($group_id);
79 $feedback .= $fa->ExecuteAction("add_forum");
80 $g->normalizeAllRoles () ;
82 } else if (getStringFromRequest('change_status')) {
83 $fa = new ForumAdmin($group_id);
84 $feedback .= $fa->ExecuteAction("change_status");
88 if (getStringFromRequest('add_forum')) {
90 Show the form for adding forums
92 forum_header(array('title'=>_('Add forum')));
95 <form method="post" action="'.getStringFromServer('PHP_SELF').'">
97 <input type="hidden" name="post_changes" value="y" />
98 <input type="hidden" name="add_forum" value="y" />
99 <input type="hidden" name="group_id" value="'.$group_id.'" />
100 <input type="hidden" name="form_key" value="' . form_generate_key() . '" />
101 <strong>'._('Forum Name').':</strong><br />
102 <input type="text" name="forum_name" value="" size="20" maxlength="30" />
105 <strong>'._('Description').':</strong><br />
106 <input type="text" name="description" value="" size="40" maxlength="80" />
109 <strong>'._('Is Public?').'</strong><br />
110 <input type="radio" name="is_public" value="1" checked="checked" />'._('Yes').' <br />
111 <input type="radio" name="is_public" value="0" />'._('No').'
114 <strong>'._('Allow Anonymous Posts?').'</strong><br />
115 <input type="radio" name="allow_anonymous" value="1" />'._('Yes').'<br />
116 <input type="radio" name="allow_anonymous" value="0" checked="checked" />'._('No').'
120 html_build_select_box_from_assoc(array("0" => _('No Moderation') ,"1" => _('Moderated Level 1'),"2" => _('Moderated Level 2') ),"moderation_level",0) . '
121 <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>
123 <strong>'._('Email All Posts To:').'</strong><br />
124 <input type="text" name="send_all_posts_to" value="" size="60" />
127 <input type="submit" name="submit" value="'._('Add This Forum').'" />
131 forum_footer(array());
133 } else if (getStringFromRequest('change_status')) {
138 $f = new Forum ($g,$group_forum_id);
140 forum_header(array('title'=>_('Change forum status')));
141 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>';
142 $fa = new ForumAdmin($f->Group->getID());
143 $fa->PrintAdminPendingOption($group_forum_id);
146 <form action="'.getStringFromServer('PHP_SELF').'" method="post">
148 <input type="hidden" name="post_changes" value="y" />
149 <input type="hidden" name="change_status" value="y" />
150 <input type="hidden" name="group_forum_id" value="'. $f->getID() .'" />
151 <input type="hidden" name="group_id" value="'.$group_id.'" />
153 <strong>'._('Allow Anonymous Posts?').'</strong><br />
154 <input type="radio" name="allow_anonymous" value="1"'.(($f->AllowAnonymous() == 1)?' checked="checked"':'').' /> '._('Yes').'<br />
155 <input type="radio" name="allow_anonymous" value="0"'.(($f->AllowAnonymous() == 0)?' checked="checked"':'').'/> '._('No').'
158 <strong>'._('Is Public?').'</strong><br />
159 <input type="radio" name="is_public" value="1"'.(($f->isPublic() == 1)?' checked="checked"':'').' /> '._('Yes').'<br />
160 <input type="radio" name="is_public" value="0"'.(($f->isPublic() == 0)?' checked="checked"':'').' /> '._('No').'<br />
161 <input type="radio" name="is_public" value="9"'.(($f->isPublic() == 9)?' checked="checked"':'').' />'._('Suspended').'<br />
163 html_build_select_box_from_assoc(array("0" => _('No Moderation') ,"1" => _('Moderated Level 1'),"2" => _('Moderated Level 2') ),"moderation_level",$f->getModerationLevel()) . '
164 <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>
167 <strong>'._('Forum Name').':</strong><br />
168 <input type="text" name="forum_name" value="'. $f->getName() .'" size="20" maxlength="30" />
171 <strong>'._('Email All Posts To:').'</strong><br />
172 <input type="text" name="send_all_posts_to" value="'. $f->getSendAllPostsTo() .'" size="60" />
175 <strong>'._('Description').':</strong><br />
176 <input type="text" name="description" value="'. $f->getDescription() .'" size="60" maxlength="80" /><br />
179 <input type="submit" name="submit" value="'._('Update').'" />
182 //echo '<a href="'.getStringFromServer('PHP_SELF').'?group_id='.$group_id.'&group_forum_id='.$group_forum_id.'&delete=1">'._('Delete Message').'</a><br />';
183 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>';
184 forum_footer(array());
186 } elseif ($deleteforum && $group_forum_id) {
188 $f = new Forum ($g,$group_forum_id);
190 forum_header(array('title'=>_('Delete')));
192 <strong>'._('You are about to permanently and irretrievably delete this entire forum and all its contents!').'</strong><br />
194 <form method="post" action="'.getStringFromServer('PHP_SELF').'">
195 <input type="hidden" name="post_changes" value="y" />
196 <input type="hidden" name="deleteforum" value="y" />
197 <input type="hidden" name="group_id" value="'.$group_id.'" />
198 <input type="hidden" name="group_forum_id" value="'.$group_forum_id.'" />
199 <input type="checkbox" name="sure" value="1" />'._('I\'m Sure').'<br />
200 <input type="checkbox" name="really_sure" value="1" />'._('I\'m Really Sure').'<br />
201 <input type="submit" name="submit" value="'._('Delete').'" />
203 forum_footer(array());
205 } elseif ( getStringFromRequest("deletemsg") ) {
206 // delete message handling
208 $forum_id = getIntFromRequest("forum_id");
209 $thread_id = getIntFromRequest("thread_id");
210 $msg_id = getIntFromRequest("deletemsg");
212 $f = forum_get_object ($forum_id) ;
214 $fa = new ForumAdmin($f->Group->getID());
216 if (getStringFromRequest("ok")) {
217 //actually delete the message
218 $feedback .= $fa->ExecuteAction("delete");
219 forum_header(array('title'=>_('Delete a Message')));
220 echo '<p>'.util_make_link ('/forum/forum.php?forum_id=' . $forum_id, _("Return to the forum")) . '</p>';
221 forum_footer(array());
222 } elseif (getStringFromRequest("cancel")) {
223 // the user cancelled the request, go back to forum
224 //if thread_id is 0, then we came from message.php. else, we came from forum.php
226 session_redirect('/forum/message.php?msg_id='.$msg_id);
228 session_redirect('/forum/forum.php?thread_id='.$thread_id.'&forum_id='.$forum_id);
232 //print the delete message confirmation
233 forum_header(array('title'=>_('Delete a Message')));
235 <form action="'.getStringFromServer('PHP_SELF').'" method="post">
236 <h3>' . _('WARNING! You are about to permanently delete a message and all of its followups!!') . '</h3><p>
238 <input type="submit" name="ok" value="' . _('Yes') . '" />
239 <input type="submit" name="cancel" value="' . _('No') . '" />
240 <input type="hidden" name="deletemsg" value="'.$msg_id.'" />
241 <input type="hidden" name="group_id" value="'.$group_id.'" />
242 <input type="hidden" name="forum_id" value="'.$forum_id.'" />
243 <input type="hidden" name="thread_id" value="'.$thread_id.'" />
247 forum_footer(array());
249 } elseif (getStringFromRequest("editmsg")) {
250 // edit message handling
251 $forum_id = getIntFromRequest("forum_id");
252 $thread_id = getIntFromRequest("thread_id");
253 $msg_id = getIntFromRequest("editmsg");
255 $f = forum_get_object ($forum_id) ;
256 $fa = new ForumAdmin($f->Group->getID());
258 if (getStringFromRequest("ok")) {
259 //actually finish editing the message and save the contents
260 $f = new Forum ($fa->GetGroupObject(),$forum_id);
261 if (!$f || !is_object($f)) {
262 exit_error(_('Error Getting Forum'),'forums');
263 } elseif ($f->isError()) {
264 exit_error($f->getErrorMessage(),'forums');
266 $fm=new ForumMessage($f,$msg_id,false,false);
267 if (!$fm || !is_object($fm)) {
268 exit_error(_('Error getting new forum message'),'forums');
269 } elseif ($fm->isError()) {
270 exit_error($fm->getErrorMessage(),'forums');
272 $subject = getStringFromRequest('subject');
273 $body = getStringFromRequest('body');
275 $sanitizer = new TextSanitizer();
276 $body = $sanitizer->SanitizeHtml($body);
278 $is_followup_to = getStringFromRequest('is_followup_to');
279 $form_key = getStringFromRequest('form_key');
280 $posted_by = getStringFromRequest('posted_by');
281 $post_date = getStringFromRequest('post_date');
282 $is_followup_to = getStringFromRequest('is_followup_to');
283 $has_followups = getStringFromRequest('has_followups');
284 $most_recent_date = getStringFromRequest('most_recent_date');
285 if ($fm->updatemsg($forum_id,$posted_by,$subject,$body,$post_date,$is_followup_to,$thread_id,$has_followups,$most_recent_date)) {
286 $feedback .= _('Message Edited Successfully');
288 $error_msg .= $fm->getErrorMessage();
290 forum_header(array('title'=>_('Edit a Message')));
291 echo '<p>'.util_make_link ('/forum/forum.php?forum_id=' . $forum_id, _("Return to the forum")) ;
292 forum_footer(array());
293 } elseif (getStringFromRequest("cancel")) {
294 // the user cancelled the request, go back to forum
295 session_redirect('/forum/message.php?msg_id='.$msg_id);
297 //print the edit message confirmation
299 $f = new Forum ($fa->GetGroupObject(),$forum_id);
300 if (!$f || !is_object($f)) {
301 exit_error(_('Error Getting Forum'),'forums');
302 } elseif ($f->isError()) {
303 exit_error($f->getErrorMessage(),'forums');
306 $fm=new ForumMessage($f,$msg_id,false,false);
307 if (!$fm || !is_object($fm)) {
308 exit_error(_('Error Getting ForumMessage'),'forums');
309 } elseif ($fm->isError()) {
310 exit_error($fm->getErrorMessage(),'forums');
313 $fh = new ForumHTML($f);
314 if (!$fh || !is_object($fh)) {
315 exit_error(_('Error Getting ForumHTML'),'forums');
316 } elseif ($fh->isError()) {
317 exit_error($fh->getErrorMessage(),'forums');
320 forum_header(array('title'=>_('Edit a Message')));
321 $fh->showEditForm($fm);
322 forum_footer(array());
324 } elseif (getStringFromRequest("movethread")) {
325 $thread_id = getIntFromRequest("movethread");
326 $msg_id = getStringFromRequest("msg_id");
327 $forum_id = getIntFromRequest("forum_id");
328 $return_to_message = getIntFromRequest("return_to_message");
329 $new_forum_id = getIntFromRequest("new_forum_id");
330 $f = forum_get_object ($forum_id) ;
331 $fa = new ForumAdmin($f->Group->getID());
333 if (getStringFromRequest("ok")) {
334 if ($forum_id == $new_forum_id) {
335 $feedback .= _('Thread not moved');
338 // Move message in another forum
339 $f_from = new Forum ($fa->GetGroupObject(),$forum_id);
340 if (!$f_from || !is_object($f_from)) {
341 exit_error(_('Could Not Get Forum Object'),'forums');
342 } elseif ($f_from->isError()) {
343 exit_error($f_from->getErrorMessage(),'forums');
345 $f_to = new Forum ($fa->GetGroupObject(),$new_forum_id);
346 if (!$f_to || !is_object($f_to)) {
347 exit_error(_('Could Not Get Forum Object'),'forums');
348 } elseif ($f_to->isError()) {
349 exit_error($f_to->getErrorMessage(),'forums');
352 $ff = new ForumFactory($g);
353 if (!$ff || !is_object($ff) || $ff->isError()) {
354 exit_error($ff->getErrorMessage(),'forums');
357 if ($ff->moveThread($new_forum_id,$thread_id,$forum_id)) {
358 $feedback .= sprintf(_('Thread successfully moved from %1$s forum to %2$s forum'), $f_from->getName(),$f_to->getName());
360 $error_msg .= $ff->getErrorMessage();
364 forum_header(array('title'=>_('Edit a Message')));
365 echo '<p><a href="/forum/forum.php?forum_id=' . $new_forum_id . '">Return to the forum</a></p>';
366 echo '<p><a href="/forum/forum.php?thread_id='.$thread_id.'&forum_id=' . $new_forum_id . '">Return to the thread</a></p>';
367 forum_footer(array());
368 } elseif (getStringFromRequest("cancel")) {
369 // the user cancelled the request, go back to forum
370 if ($return_to_message) {
371 session_redirect('/forum/message.php?msg_id='.$msg_id);
373 session_redirect('/forum/forum.php?thread_id='.$thread_id.'&forum_id='.$forum_id);
377 // Display select box to select new forum
379 forum_header(array('title'=>_('Move Thread')));
381 $ff = new ForumFactory($g);
382 if (!$ff || !is_object($ff) || $ff->isError()) {
383 exit_error($ff->getErrorMessage(),'forums');
386 $farr = $ff->getForums();
388 if ($ff->isError()) {
389 echo '<p class="error">'.sprintf(_('No Forums Found For %s'), $g->getPublicName())
390 . $ff->getErrorMessage().'</p>';
391 forum_footer(array());
396 List the existing forums so they can be edited.
400 for ($j = 0; $j < count($farr); $j++) {
401 if (!is_object($farr[$j])) {
402 //just skip it - this object should never have been placed here
403 } elseif ($farr[$j]->isError()) {
404 echo $farr[$j]->getErrorMessage();
406 $forums[$farr[$j]->getID()] = $farr[$j]->getName();
410 $f_from = new Forum ($fa->GetGroupObject(),$forum_id);
411 if (!$f_from || !is_object($f_from)) {
412 exit_error(_('Could Not Get Forum Object'),'forums');
413 } elseif ($f_from->isError()) {
414 exit_error($f_from->getErrorMessage(),'forums');
418 <form action="'.getStringFromServer('PHP_SELF').'" method="post">
419 <p><strong>' . sprintf(_('Move thread from %s forum to the following forum:'), $f_from->getName()) . '</strong></p>
421 <input type="hidden" name="movethread" value="'.$thread_id.'" />
422 <input type="hidden" name="group_id" value="'.$group_id.'" />
423 <input type="hidden" name="forum_id" value="'.$forum_id.'" />
424 <input type="hidden" name="msg_id" value="'.$msg_id.'" />
425 <input type="hidden" name="return_to_message" value="'.$return_to_message.'" />' .
426 html_build_select_box_from_assoc($forums,'new_forum_id',$forum_id) .
428 <input type="submit" name="ok" value="' . _("Submit") . '" />
429 <input type="submit" name="cancel" value="' . _("Cancel") . '" />
434 forum_footer(array());
439 Show main page for choosing
440 either moderator or delete
442 forum_header(array('title'=>_('Forums Administration')));
447 $fa = new ForumAdmin($g->getID());
449 $fa->PrintAdminOptions();
452 plugin_hook ("blocks", "forum index");
455 // Get existing forums
457 $ff=new ForumFactory($g);
458 if (!$ff || !is_object($ff) || $ff->isError()) {
459 exit_error($ff->getErrorMessage(),'forums');
462 $farr = $ff->getForumsAdmin();
464 if ($ff->isError()) {
465 echo '<p class="error">'.sprintf(_('No Forums Found For %s'), $g->getPublicName())
466 . $ff->getErrorMessage().'</p>';
467 forum_footer(array());
472 List the existing forums so they can be edited.
475 for ($j = 0; $j < count($farr); $j++) {
476 if (!is_object($farr[$j])) {
477 //just skip it - this object should never have been placed here
478 } elseif ($farr[$j]->isError()) {
479 echo $farr[$j]->getErrorMessage();
481 echo '<p><a href="'.getStringFromServer('PHP_SELF').'?group_id='.$group_id.'&change_status=1&group_forum_id='. $farr[$j]->getID() .'">'.
482 $farr[$j]->getName() .'</a><br />'.$farr[$j]->getDescription().'<br /><a href="monitor.php?group_id='.$group_id.'&group_forum_id='. $farr[$j]->getID() .'">'.
483 _('Monitoring Users').'</a></p>';
487 forum_footer(array());
492 // c-file-style: "bsd"