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 * Copyright 2013, French Ministry of National Education
10 * Copyright 2013, Franck Villaume - TrivialDev
11 * http://fusionforge.org/
13 * This file is part of FusionForge. FusionForge is free software;
14 * you can redistribute it and/or modify it under the terms of the
15 * GNU General Public License as published by the Free Software
16 * Foundation; either version 2 of the Licence, or (at your option)
19 * FusionForge is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
26 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 require_once '../../env.inc.php';
30 require_once $gfcommon.'include/pre.php';
31 require_once $gfcommon.'forum/ForumHTML.class.php';
32 require_once $gfcommon.'forum/Forum.class.php';
33 require_once $gfcommon.'forum/ForumAdmin.class.php';
34 require_once $gfcommon.'forum/ForumFactory.class.php';
35 require_once $gfcommon.'forum/ForumMessageFactory.class.php';
36 require_once $gfcommon.'forum/ForumMessage.class.php';
37 require_once $gfcommon.'include/TextSanitizer.class.php'; // to make the HTML input by the user safe to store
39 $group_id = getIntFromRequest('group_id');
40 $group_forum_id = getIntFromRequest('group_forum_id');
41 $deleteforum = getStringFromRequest('deleteforum');
42 $error_msg = htmlspecialchars(getStringFromRequest('error_msg'));
51 // Set up local objects
53 $g = group_get_object($group_id);
54 if (!$g || !is_object($g) || $g->isError()) {
57 if (!$g->usesForum()) {
58 exit_error(sprintf(_('%s does not use the Forum tool.'),
59 $g->getPublicName()), 'forums');
62 session_require_perm ('forum_admin', $group_id) ;
64 if (getStringFromRequest('post_changes')) {
66 Update the DB to reflect the changes
73 $fa = new ForumAdmin($group_id);
74 $feedback .= $fa->ExecuteAction("delete_forum");
77 } elseif (getStringFromRequest('add_forum')) {
78 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
79 exit_form_double_submit('forums');
82 if (check_email_available($g, $g->getUnixName() . '-' . getStringFromRequest('forum_name'), $error_msg)) {
83 $fa = new ForumAdmin($group_id);
84 $feedback .= $fa->ExecuteAction("add_forum");
86 $error_msg = $fa->getErrorMessage();
88 $g->normalizeAllRoles();
91 } elseif (getStringFromRequest('change_status')) {
92 $fa = new ForumAdmin($group_id);
93 $feedback .= $fa->ExecuteAction("change_status");
95 $error_msg = $fa->getErrorMessage();
100 if (getStringFromRequest('add_forum')) {
102 Show the form for adding forums
104 forum_header(array('title'=>_('Add Forum')));
107 <form method="post" action="'.getStringFromServer('PHP_SELF').'">
109 <input type="hidden" name="post_changes" value="y" />
110 <input type="hidden" name="add_forum" value="y" />
111 <input type="hidden" name="group_id" value="'.$group_id.'" />
112 <input type="hidden" name="form_key" value="' . form_generate_key() . '" />
113 <strong>'._('Forum Name').':'.utils_requiredField().'</strong><br />
114 <input type="text" name="forum_name" required="required" value="" size="20" maxlength="30" />
117 <strong>'._('Description').':'.utils_requiredField().'</strong><br />
118 <input type="text" name="description" required="required" value="" size="40" maxlength="80" />
121 <strong>'._('Email All Posts To:').'</strong><br />
122 <input type="email" name="send_all_posts_to" value="" size="60" />
125 <input type="submit" name="submit" value="'._('Add This Forum').'" />
128 echo '<span>'.sprintf(_('%s Mandatory fields'), utils_requiredField()).'</span>';
129 forum_footer(array());
131 } elseif (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.'" />
150 <strong>'._('Forum Name').':'.utils_requiredField().'</strong><br />
151 <input type="text" name="forum_name" required="required" value="'. $f->getName() .'" size="20" maxlength="30" />
154 <strong>'._('Email All Posts To:').'</strong><br />
155 <input type="email" name="send_all_posts_to" value="'. $f->getSendAllPostsTo() .'" size="60" />
158 <strong>'._('Description').':'.utils_requiredField().'</strong><br />
159 <input type="text" name="description" required="required" value="'. $f->getDescription() .'" size="60" maxlength="80" /><br />
162 <input type="submit" name="submit" value="'._('Update').'" />
165 //echo '<a href="'.getStringFromServer('PHP_SELF').'?group_id='.$group_id.'&group_forum_id='.$group_forum_id.'&delete=1">'._('Delete Message').'</a><br />';
166 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>';
167 echo '<span>'.sprintf(_('%s Mandatory fields'), utils_requiredField()).'</span>';
168 forum_footer(array());
170 } elseif ($deleteforum && $group_forum_id) {
172 $f = new Forum ($g,$group_forum_id);
174 forum_header(array('title'=>_('Permanently Delete Forum')));
176 <strong>'._('You are about to permanently and irretrievably delete this entire forum and all its contents!').'</strong><br />
178 <form method="post" action="'.getStringFromServer('PHP_SELF').'">
179 <input type="hidden" name="post_changes" value="y" />
180 <input type="hidden" name="deleteforum" value="y" />
181 <input type="hidden" name="group_id" value="'.$group_id.'" />
182 <input type="hidden" name="group_forum_id" value="'.$group_forum_id.'" />
183 <input type="checkbox" name="sure" value="1" />'._('I am Sure').'<br />
184 <input type="checkbox" name="really_sure" value="1" />'._('I am Really Sure').'<br />
185 <input type="submit" name="submit" value="'._('Delete').'" />
187 forum_footer(array());
189 } elseif ( getStringFromRequest("deletemsg") ) {
190 // delete message handling
192 $forum_id = getIntFromRequest("forum_id");
193 $thread_id = getIntFromRequest("thread_id");
194 $msg_id = getIntFromRequest("deletemsg");
196 $f = forum_get_object ($forum_id) ;
198 $fa = new ForumAdmin($f->Group->getID());
200 if (getStringFromRequest("ok")) {
201 //actually delete the message
202 $feedback .= $fa->ExecuteAction("delete");
203 forum_header(array('title'=>_('Delete a Message')));
204 echo '<p>'.util_make_link ('/forum/forum.php?forum_id=' . $forum_id, _("Return to the forum")) . '</p>';
205 forum_footer(array());
206 } elseif (getStringFromRequest("cancel")) {
207 // the user cancelled the request, go back to forum
208 //if thread_id is 0, then we came from message.php. else, we came from forum.php
210 session_redirect('/forum/message.php?msg_id='.$msg_id);
212 session_redirect('/forum/forum.php?thread_id='.$thread_id.'&forum_id='.$forum_id);
216 //print the delete message confirmation
217 forum_header(array('title'=>_('Delete a Message')));
219 <form action="'.getStringFromServer('PHP_SELF').'" method="post">
220 <h3>' . _('WARNING! You are about to permanently delete a message and all of its followups!!') . '</h3>
222 <input type="submit" name="ok" value="' . _('Yes') . '" />
223 <input type="submit" name="cancel" value="' . _('No') . '" />
224 <input type="hidden" name="deletemsg" value="'.$msg_id.'" />
225 <input type="hidden" name="group_id" value="'.$group_id.'" />
226 <input type="hidden" name="forum_id" value="'.$forum_id.'" />
227 <input type="hidden" name="thread_id" value="'.$thread_id.'" />
231 forum_footer(array());
233 } elseif (getStringFromRequest("editmsg")) {
234 // edit message handling
235 $forum_id = getIntFromRequest("forum_id");
236 $thread_id = getIntFromRequest("thread_id");
237 $msg_id = getIntFromRequest("editmsg");
239 $f = forum_get_object ($forum_id) ;
240 $fa = new ForumAdmin($f->Group->getID());
242 if (getStringFromRequest("ok")) {
243 //actually finish editing the message and save the contents
244 $f = new Forum ($fa->GetGroupObject(),$forum_id);
245 if (!$f || !is_object($f)) {
246 exit_error(_('Error getting Forum'),'forums');
247 } elseif ($f->isError()) {
248 exit_error($f->getErrorMessage(),'forums');
250 $fm=new ForumMessage($f,$msg_id,false,false);
251 if (!$fm || !is_object($fm)) {
252 exit_error(_('Error getting new forum message'),'forums');
253 } elseif ($fm->isError()) {
254 exit_error($fm->getErrorMessage(),'forums');
256 $subject = getStringFromRequest('subject');
257 $body = getStringFromRequest('body');
259 $sanitizer = new TextSanitizer();
260 $body = $sanitizer->SanitizeHtml($body);
262 $is_followup_to = getStringFromRequest('is_followup_to');
263 $form_key = getStringFromRequest('form_key');
264 $posted_by = getStringFromRequest('posted_by');
265 $post_date = getStringFromRequest('post_date');
266 $is_followup_to = getStringFromRequest('is_followup_to');
267 $has_followups = getStringFromRequest('has_followups');
268 $most_recent_date = getStringFromRequest('most_recent_date');
269 if ($fm->updatemsg($forum_id,$posted_by,$subject,$body,$post_date,$is_followup_to,$thread_id,$has_followups,$most_recent_date)) {
270 $feedback .= _('Message Edited Successfully');
272 session_redirect('/forum/admin/index.php?editmsg='.$msg_id.'&group_id='.$group_id.'&thread_id='.$thread_id.'&forum_id='.$forum_id.'&error_msg='.urlencode($fm->getErrorMessage()));
274 forum_header(array('title'=>_('Edit a Message')));
275 echo '<p>'.util_make_link ('/forum/forum.php?forum_id=' . $forum_id, _("Return to the forum")) ;
276 forum_footer(array());
277 } elseif (getStringFromRequest("cancel")) {
278 // the user cancelled the request, go back to forum
279 session_redirect('/forum/message.php?msg_id='.$msg_id);
281 //print the edit message confirmation
283 $f = new Forum ($fa->GetGroupObject(),$forum_id);
284 if (!$f || !is_object($f)) {
285 exit_error(_('Error getting Forum'),'forums');
286 } elseif ($f->isError()) {
287 exit_error($f->getErrorMessage(),'forums');
290 $fm=new ForumMessage($f,$msg_id,false,false);
291 if (!$fm || !is_object($fm)) {
292 exit_error(_('Error Getting ForumMessage'),'forums');
293 } elseif ($fm->isError()) {
294 exit_error($fm->getErrorMessage(),'forums');
297 $fh = new ForumHTML($f);
298 if (!$fh || !is_object($fh)) {
299 exit_error(_('Error Getting ForumHTML'),'forums');
300 } elseif ($fh->isError()) {
301 exit_error($fh->getErrorMessage(),'forums');
304 forum_header(array('title'=>_('Edit a Message')));
305 $fh->showEditForm($fm);
306 forum_footer(array());
308 } elseif (getStringFromRequest("movethread")) {
309 $thread_id = getIntFromRequest("movethread");
310 $msg_id = getStringFromRequest("msg_id");
311 $forum_id = getIntFromRequest("forum_id");
312 $return_to_message = getIntFromRequest("return_to_message");
313 $new_forum_id = getIntFromRequest("new_forum_id");
314 $f = forum_get_object ($forum_id) ;
315 $fa = new ForumAdmin($f->Group->getID());
317 if (getStringFromRequest("ok")) {
318 if ($forum_id == $new_forum_id) {
319 $feedback .= _('Thread not moved');
322 // Move message in another forum
323 $f_from = new Forum ($fa->GetGroupObject(),$forum_id);
324 if (!$f_from || !is_object($f_from)) {
325 exit_error(_('Could Not Get Forum Object'),'forums');
326 } elseif ($f_from->isError()) {
327 exit_error($f_from->getErrorMessage(),'forums');
329 $f_to = new Forum ($fa->GetGroupObject(),$new_forum_id);
330 if (!$f_to || !is_object($f_to)) {
331 exit_error(_('Could Not Get Forum Object'),'forums');
332 } elseif ($f_to->isError()) {
333 exit_error($f_to->getErrorMessage(),'forums');
336 $ff = new ForumFactory($g);
337 if (!$ff || !is_object($ff) || $ff->isError()) {
338 exit_error($ff->getErrorMessage(),'forums');
341 if ($ff->moveThread($new_forum_id,$thread_id,$forum_id)) {
342 $feedback .= sprintf(_('Thread successfully moved from %1$s forum to %2$s forum'), $f_from->getName(),$f_to->getName());
344 $error_msg .= $ff->getErrorMessage();
348 forum_header(array('title'=>_('Edit a Message')));
349 echo '<p><a href="/forum/forum.php?forum_id=' . $new_forum_id . '">'._('Return to the forum').'</a></p>';
350 echo '<p><a href="/forum/forum.php?thread_id='.$thread_id.'&forum_id=' . $new_forum_id . '">'._('Return to the thread').'</a></p>';
351 forum_footer(array());
352 } elseif (getStringFromRequest("cancel")) {
353 // the user cancelled the request, go back to forum
354 if ($return_to_message) {
355 session_redirect('/forum/message.php?msg_id='.$msg_id);
357 session_redirect('/forum/forum.php?thread_id='.$thread_id.'&forum_id='.$forum_id);
361 // Display select box to select new forum
363 forum_header(array('title'=>_('Move Thread')));
365 $ff = new ForumFactory($g);
366 if (!$ff || !is_object($ff) || $ff->isError()) {
367 exit_error($ff->getErrorMessage(),'forums');
370 $farr = $ff->getForums();
372 if ($ff->isError()) {
373 echo '<p class="error">'.sprintf(_('No Forums Found for %s'), $g->getPublicName())
374 . $ff->getErrorMessage().'</p>';
375 forum_footer(array());
380 List the existing forums so they can be edited.
384 for ($j = 0; $j < count($farr); $j++) {
385 if (!is_object($farr[$j])) {
386 //just skip it - this object should never have been placed here
387 } elseif ($farr[$j]->isError()) {
388 echo $farr[$j]->getErrorMessage();
390 $forums[$farr[$j]->getID()] = $farr[$j]->getName();
394 $f_from = new Forum ($fa->GetGroupObject(),$forum_id);
395 if (!$f_from || !is_object($f_from)) {
396 exit_error(_('Could Not Get Forum Object'),'forums');
397 } elseif ($f_from->isError()) {
398 exit_error($f_from->getErrorMessage(),'forums');
402 <form action="'.getStringFromServer('PHP_SELF').'" method="post">
403 <p><strong>' . sprintf(_('Move thread from %s forum to the following forum:'), $f_from->getName()) . '</strong></p>
405 <input type="hidden" name="movethread" value="'.$thread_id.'" />
406 <input type="hidden" name="group_id" value="'.$group_id.'" />
407 <input type="hidden" name="forum_id" value="'.$forum_id.'" />
408 <input type="hidden" name="msg_id" value="'.$msg_id.'" />
409 <input type="hidden" name="return_to_message" value="'.$return_to_message.'" />' .
410 html_build_select_box_from_assoc($forums,'new_forum_id',$forum_id) .
412 <input type="submit" name="ok" value="' . _("Submit") . '" />
413 <input type="submit" name="cancel" value="' . _("Cancel") . '" />
418 forum_footer(array());
423 Show main page for choosing
424 either moderator or delete
426 forum_header(array('title'=>_('Forums Administration')));
431 $fa = new ForumAdmin($g->getID());
433 $fa->PrintAdminOptions();
436 plugin_hook ("blocks", "forum index");
439 // Get existing forums
441 $ff=new ForumFactory($g);
442 if (!$ff || !is_object($ff) || $ff->isError()) {
443 exit_error($ff->getErrorMessage(),'forums');
446 $farr = $ff->getForumsAdmin();
448 if ($ff->isError()) {
449 echo '<p class="error">'.sprintf(_('No Forums Found for %s'), $g->getPublicName())
450 . $ff->getErrorMessage().'</p>';
451 forum_footer(array());
456 List the existing forums so they can be edited.
459 for ($j = 0; $j < count($farr); $j++) {
460 if (!is_object($farr[$j])) {
461 //just skip it - this object should never have been placed here
462 } elseif ($farr[$j]->isError()) {
463 echo $farr[$j]->getErrorMessage();
465 echo '<p><a href="'.getStringFromServer('PHP_SELF').'?group_id='.$group_id.'&change_status=1&group_forum_id='. $farr[$j]->getID() .'">'.
466 $farr[$j]->getName() .'</a><br />'.$farr[$j]->getDescription().'<br /><a href="monitor.php?group_id='.$group_id.'&group_forum_id='. $farr[$j]->getID() .'">'.
467 _('Monitoring Users').'</a></p>';
471 forum_footer(array());
476 // c-file-style: "bsd"