5 * Copyright 1999-2001 (c) VA Linux Systems
6 * Copyright 2002-2004 (c) GForge Team
7 * Copyright 2010 (c) Franck Villaume - Capgemini
8 * http://fusionforge.org/
10 * This file is part of FusionForge.
12 * FusionForge is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
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
23 * along with FusionForge; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 require_once('../../env.inc.php');
28 require_once $gfcommon.'include/pre.php';
29 require_once $gfwww.'forum/include/ForumHTML.class.php';
30 require_once $gfcommon.'forum/Forum.class.php';
31 require_once $gfwww.'forum/admin/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");
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>'._('Is Public?').'</strong><br />
108 <input type="radio" name="is_public" value="1" checked="checked" />'._('Yes').' <br />
109 <input type="radio" name="is_public" value="0" />'._('No').'
112 <strong>'._('Allow Anonymous Posts?').'</strong><br />
113 <input type="radio" name="allow_anonymous" value="1" />'._('Yes').'<br />
114 <input type="radio" name="allow_anonymous" value="0" checked="checked" />'._('No').'
118 html_build_select_box_from_assoc(array("0" => _('No Moderation') ,"1" => _('Moderated Level 1'),"2" => _('Moderated Level 2') ),"moderation_level",0) . '
119 <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>
121 <strong>'._('Email All Posts To:').'</strong><br />
122 <input type="text" name="send_all_posts_to" value="" size="60" />
125 <input type="submit" name="submit" value="'._('Add This Forum').'" />
129 forum_footer(array());
131 } else if (getStringFromRequest('change_status')) {
136 $f = new Forum ($g,$group_forum_id);
138 forum_header(array('title'=>_('Change forum status')));
139 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>';
140 $fa = new ForumAdmin($f->Group->getID());
141 $fa->PrintAdminPendingOption($group_forum_id);
144 <form action="'.getStringFromServer('PHP_SELF').'" method="post">
146 <input type="hidden" name="post_changes" value="y" />
147 <input type="hidden" name="change_status" value="y" />
148 <input type="hidden" name="group_forum_id" value="'. $f->getID() .'" />
149 <input type="hidden" name="group_id" value="'.$group_id.'" />
151 <strong>'._('Allow Anonymous Posts?').'</strong><br />
152 <input type="radio" name="allow_anonymous" value="1"'.(($f->AllowAnonymous() == 1)?' checked="checked"':'').' /> '._('Yes').'<br />
153 <input type="radio" name="allow_anonymous" value="0"'.(($f->AllowAnonymous() == 0)?' checked="checked"':'').'/> '._('No').'
156 <strong>'._('Is Public?').'</strong><br />
157 <input type="radio" name="is_public" value="1"'.(($f->isPublic() == 1)?' checked="checked"':'').' /> '._('Yes').'<br />
158 <input type="radio" name="is_public" value="0"'.(($f->isPublic() == 0)?' checked="checked"':'').' /> '._('No').'<br />
159 <input type="radio" name="is_public" value="9"'.(($f->isPublic() == 9)?' checked="checked"':'').' />'._('Suspended').'<br />
161 html_build_select_box_from_assoc(array("0" => _('No Moderation') ,"1" => _('Moderated Level 1'),"2" => _('Moderated Level 2') ),"moderation_level",$f->getModerationLevel()) . '
162 <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>
165 <strong>'._('Forum Name').':</strong><br />
166 <input type="text" name="forum_name" value="'. $f->getName() .'" size="20" maxlength="30" />
169 <strong>'._('Email All Posts To:').'</strong><br />
170 <input type="text" name="send_all_posts_to" value="'. $f->getSendAllPostsTo() .'" size="60" />
173 <strong>'._('Description').':</strong><br />
174 <input type="text" name="description" value="'. $f->getDescription() .'" size="60" maxlength="80" /><br />
177 <input type="submit" name="submit" value="'._('Update').'" />
180 //echo '<a href="'.getStringFromServer('PHP_SELF').'?group_id='.$group_id.'&group_forum_id='.$group_forum_id.'&delete=1">'._('Delete Message').'</a><br />';
181 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>';
182 forum_footer(array());
184 } elseif ($deleteforum && $group_forum_id) {
186 $f = new Forum ($g,$group_forum_id);
188 forum_header(array('title'=>_('Delete')));
190 <strong>'._('You are about to permanently and irretrievably delete this entire forum and all its contents!').'</strong><br />
192 <form method="post" action="'.getStringFromServer('PHP_SELF').'">
193 <input type="hidden" name="post_changes" value="y" />
194 <input type="hidden" name="deleteforum" value="y" />
195 <input type="hidden" name="group_id" value="'.$group_id.'" />
196 <input type="hidden" name="group_forum_id" value="'.$group_forum_id.'" />
197 <input type="checkbox" name="sure" value="1" />'._('I\'m Sure').'<br />
198 <input type="checkbox" name="really_sure" value="1" />'._('I\'m Really Sure').'<br />
199 <input type="submit" name="submit" value="'._('Delete').'" />
201 forum_footer(array());
203 } elseif ( getStringFromRequest("deletemsg") ) {
204 // delete message handling
206 $forum_id = getIntFromRequest("forum_id");
207 $thread_id = getIntFromRequest("thread_id");
208 $msg_id = getIntFromRequest("deletemsg");
210 $f = forum_get_object ($forum_id) ;
212 $fa = new ForumAdmin($f->Group->getID());
214 if (getStringFromRequest("ok")) {
215 //actually delete the message
216 $feedback .= $fa->ExecuteAction("delete");
217 forum_header(array('title'=>_('Delete a Message')));
218 echo '<p>'.util_make_link ('/forum/forum.php?forum_id=' . $forum_id, _("Return to the forum")) . '</p>';
219 forum_footer(array());
220 } elseif (getStringFromRequest("cancel")) {
221 // the user cancelled the request, go back to forum
222 //if thread_id is 0, then we came from message.php. else, we came from forum.php
224 session_redirect('/forum/message.php?msg_id='.$msg_id);
226 session_redirect('/forum/forum.php?thread_id='.$thread_id.'&forum_id='.$forum_id);
230 //print the delete message confirmation
231 forum_header(array('title'=>_('Delete a Message')));
233 <form action="'.getStringFromServer('PHP_SELF').'" method="post">
234 <h3>' . _('WARNING! You are about to permanently delete a message and all of its followups!!') . '</h3><p>
236 <input type="submit" name="ok" value="' . _('Yes') . '" />
237 <input type="submit" name="cancel" value="' . _('No') . '" />
238 <input type="hidden" name="deletemsg" value="'.$msg_id.'" />
239 <input type="hidden" name="group_id" value="'.$group_id.'" />
240 <input type="hidden" name="forum_id" value="'.$forum_id.'" />
241 <input type="hidden" name="thread_id" value="'.$thread_id.'" />
245 forum_footer(array());
247 } elseif (getStringFromRequest("editmsg")) {
248 // edit message handling
249 $forum_id = getIntFromRequest("forum_id");
250 $thread_id = getIntFromRequest("thread_id");
251 $msg_id = getIntFromRequest("editmsg");
253 $f = forum_get_object ($forum_id) ;
254 $fa = new ForumAdmin($f->Group->getID());
256 if (getStringFromRequest("ok")) {
257 //actually finish editing the message and save the contents
258 $f = new Forum ($fa->GetGroupObject(),$forum_id);
259 if (!$f || !is_object($f)) {
260 exit_error(_('Error Getting Forum'),'forums');
261 } elseif ($f->isError()) {
262 exit_error($f->getErrorMessage(),'forums');
264 $fm=new ForumMessage($f,$msg_id,false,false);
265 if (!$fm || !is_object($fm)) {
266 exit_error(_('Error getting new forum message'),'forums');
267 } elseif ($fm->isError()) {
268 exit_error($fm->getErrorMessage(),'forums');
270 $subject = getStringFromRequest('subject');
271 $body = getStringFromRequest('body');
273 $sanitizer = new TextSanitizer();
274 $body = $sanitizer->SanitizeHtml($body);
276 $is_followup_to = getStringFromRequest('is_followup_to');
277 $form_key = getStringFromRequest('form_key');
278 $posted_by = getStringFromRequest('posted_by');
279 $post_date = getStringFromRequest('post_date');
280 $is_followup_to = getStringFromRequest('is_followup_to');
281 $has_followups = getStringFromRequest('has_followups');
282 $most_recent_date = getStringFromRequest('most_recent_date');
283 if ($fm->updatemsg($forum_id,$posted_by,$subject,$body,$post_date,$is_followup_to,$thread_id,$has_followups,$most_recent_date)) {
284 $feedback .= _('Message Edited Successfully');
286 $error_msg .= $fm->getErrorMessage();
288 forum_header(array('title'=>_('Edit a Message')));
289 echo '<p>'.util_make_link ('/forum/forum.php?forum_id=' . $forum_id, _("Return to the forum")) ;
290 forum_footer(array());
291 } elseif (getStringFromRequest("cancel")) {
292 // the user cancelled the request, go back to forum
293 session_redirect('/forum/message.php?msg_id='.$msg_id);
295 //print the edit message confirmation
297 $f = new Forum ($fa->GetGroupObject(),$forum_id);
298 if (!$f || !is_object($f)) {
299 exit_error(_('Error Getting Forum'),'forums');
300 } elseif ($f->isError()) {
301 exit_error($f->getErrorMessage(),'forums');
304 $fm=new ForumMessage($f,$msg_id,false,false);
305 if (!$fm || !is_object($fm)) {
306 exit_error(_('Error Getting ForumMessage'),'forums');
307 } elseif ($fm->isError()) {
308 exit_error($fm->getErrorMessage(),'forums');
311 $fh = new ForumHTML($f);
312 if (!$fh || !is_object($fh)) {
313 exit_error(_('Error Getting ForumHTML'),'forums');
314 } elseif ($fh->isError()) {
315 exit_error($fh->getErrorMessage(),'forums');
318 forum_header(array('title'=>_('Edit a Message')));
319 $fh->showEditForm($fm);
320 forum_footer(array());
322 } elseif (getStringFromRequest("movethread")) {
323 $thread_id = getIntFromRequest("movethread");
324 $msg_id = getStringFromRequest("msg_id");
325 $forum_id = getIntFromRequest("forum_id");
326 $return_to_message = getIntFromRequest("return_to_message");
327 $new_forum_id = getIntFromRequest("new_forum_id");
328 $f = forum_get_object ($forum_id) ;
329 $fa = new ForumAdmin($f->Group->getID());
331 if (getStringFromRequest("ok")) {
332 if ($forum_id == $new_forum_id) {
333 $feedback .= _('Thread not moved');
336 // Move message in another forum
337 $f_from = new Forum ($fa->GetGroupObject(),$forum_id);
338 if (!$f_from || !is_object($f_from)) {
339 exit_error(_('Could Not Get Forum Object'),'forums');
340 } elseif ($f_from->isError()) {
341 exit_error($f_from->getErrorMessage(),'forums');
343 $f_to = new Forum ($fa->GetGroupObject(),$new_forum_id);
344 if (!$f_to || !is_object($f_to)) {
345 exit_error(_('Could Not Get Forum Object'),'forums');
346 } elseif ($f_to->isError()) {
347 exit_error($f_to->getErrorMessage(),'forums');
350 $ff = new ForumFactory($g);
351 if (!$ff || !is_object($ff) || $ff->isError()) {
352 exit_error($ff->getErrorMessage(),'forums');
355 if ($ff->moveThread($new_forum_id,$thread_id,$forum_id)) {
356 $feedback .= sprintf(_('Thread successfully moved from %1$s forum to %2$s forum'), $f_from->getName(),$f_to->getName());
358 $error_msg .= $ff->getErrorMessage();
362 forum_header(array('title'=>_('Edit a Message')));
363 echo '<p><a href="/forum/forum.php?forum_id=' . $new_forum_id . '">Return to the forum</a></p>';
364 echo '<p><a href="/forum/forum.php?thread_id='.$thread_id.'&forum_id=' . $new_forum_id . '">Return to the thread</a></p>';
365 forum_footer(array());
366 } elseif (getStringFromRequest("cancel")) {
367 // the user cancelled the request, go back to forum
368 if ($return_to_message) {
369 session_redirect('/forum/message.php?msg_id='.$msg_id);
371 session_redirect('/forum/forum.php?thread_id='.$thread_id.'&forum_id='.$forum_id);
375 // Display select box to select new forum
377 forum_header(array('title'=>_('Forums: Administration')));
379 $ff = new ForumFactory($g);
380 if (!$ff || !is_object($ff) || $ff->isError()) {
381 exit_error($ff->getErrorMessage(),'forums');
384 $farr =& $ff->getForums();
386 if ($ff->isError()) {
387 echo '<h1>'.sprintf(_('No Forums Found For %s'), $g->getPublicName()) .'</h1>';
388 echo '<div class="error">'.$ff->getErrorMessage().'</div>';
389 forum_footer(array());
394 List the existing forums so they can be edited.
398 for ($j = 0; $j < count($farr); $j++) {
399 if (!is_object($farr[$j])) {
400 //just skip it - this object should never have been placed here
401 } elseif ($farr[$j]->isError()) {
402 echo $farr[$j]->getErrorMessage();
404 $forums[$farr[$j]->getID()] = $farr[$j]->getName();
408 $f_from = new Forum ($fa->GetGroupObject(),$forum_id);
409 if (!$f_from || !is_object($f_from)) {
410 exit_error(_('Could Not Get Forum Object'),'forums');
411 } elseif ($f_from->isError()) {
412 exit_error($f_from->getErrorMessage(),'forums');
416 <form action="'.getStringFromServer('PHP_SELF').'" method="post">
417 <p><strong>' . sprintf(_('Move thread from %s forum to the following forum:'), $f_from->getName()) . '</strong></p>
419 <input type="hidden" name="movethread" value="'.$thread_id.'" />
420 <input type="hidden" name="group_id" value="'.$group_id.'" />
421 <input type="hidden" name="forum_id" value="'.$forum_id.'" />
422 <input type="hidden" name="msg_id" value="'.$msg_id.'" />
423 <input type="hidden" name="return_to_message" value="'.$return_to_message.'" />' .
424 html_build_select_box_from_assoc($forums,'new_forum_id',$forum_id) .
426 <input type="submit" name="ok" value="' . _("Submit") . '" />
427 <input type="submit" name="cancel" value="' . _("Cancel") . '" />
432 forum_footer(array());
437 Show main page for choosing
438 either moderator or delete
440 forum_header(array('title'=>_('Forums: Administration')));
445 $fa = new ForumAdmin($g->getID());
447 $fa->PrintAdminOptions();
450 plugin_hook ("blocks", "forum index");
453 // Get existing forums
455 $ff=new ForumFactory($g);
456 if (!$ff || !is_object($ff) || $ff->isError()) {
457 exit_error($ff->getErrorMessage(),'forums');
460 $farr =& $ff->getForumsAdmin();
462 if ($ff->isError()) {
463 echo '<h1>'.sprintf(_('No Forums Found For %1$s'), $g->getPublicName()) .'</h1>';
464 echo '<div class="error">'.$ff->getErrorMessage().'</div>';
465 forum_footer(array());
470 List the existing forums so they can be edited.
473 for ($j = 0; $j < count($farr); $j++) {
474 if (!is_object($farr[$j])) {
475 //just skip it - this object should never have been placed here
476 } elseif ($farr[$j]->isError()) {
477 echo $farr[$j]->getErrorMessage();
479 echo '<p><a href="'.getStringFromServer('PHP_SELF').'?group_id='.$group_id.'&change_status=1&group_forum_id='. $farr[$j]->getID() .'">'.
480 $farr[$j]->getName() .'</a><br />'.$farr[$j]->getDescription().'<br /><a href="monitor.php?group_id='.$group_id.'&group_forum_id='. $farr[$j]->getID() .'">'.
481 _('Monitoring Users').'</a></p>';
485 forum_footer(array());
490 // c-file-style: "bsd"