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');
48 // Set up local objects
50 $g = group_get_object($group_id);
51 if (!$g || !is_object($g) || $g->isError()) {
54 if (!$g->usesForum()) {
55 exit_error(sprintf(_('%s does not use the Forum tool'),
56 $g->getPublicName()), 'forums');
59 session_require_perm ('forum_admin', $group_id) ;
61 if (getStringFromRequest('post_changes')) {
63 Update the DB to reflect the changes
70 $fa = new ForumAdmin($group_id);
71 $feedback .= $fa->ExecuteAction("delete_forum");
74 } else if (getStringFromRequest('add_forum')) {
75 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
76 exit_form_double_submit('forums');
79 if (check_email_available($g, $g->getUnixName() . '-' . getStringFromRequest('forum_name'), $error_msg)) {
80 $fa = new ForumAdmin($group_id);
81 $feedback .= $fa->ExecuteAction("add_forum");
82 $g->normalizeAllRoles () ;
84 } else if (getStringFromRequest('change_status')) {
85 $fa = new ForumAdmin($group_id);
86 $feedback .= $fa->ExecuteAction("change_status");
90 if (getStringFromRequest('add_forum')) {
92 Show the form for adding forums
94 forum_header(array('title'=>_('Add forum')));
97 <form method="post" action="'.getStringFromServer('PHP_SELF').'">
99 <input type="hidden" name="post_changes" value="y" />
100 <input type="hidden" name="add_forum" value="y" />
101 <input type="hidden" name="group_id" value="'.$group_id.'" />
102 <input type="hidden" name="form_key" value="' . form_generate_key() . '" />
103 <strong>'._('Forum Name').':</strong><br />
104 <input type="text" name="forum_name" value="" size="20" maxlength="30" />
107 <strong>'._('Description').':</strong><br />
108 <input type="text" name="description" value="" size="40" maxlength="80" />
111 <strong>'._('Email All Posts To:').'</strong><br />
112 <input type="text" name="send_all_posts_to" value="" size="60" />
115 <input type="submit" name="submit" value="'._('Add This Forum').'" />
119 forum_footer(array());
121 } else if (getStringFromRequest('change_status')) {
126 $f = new Forum ($g,$group_forum_id);
128 forum_header(array('title'=>_('Change forum status')));
129 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>';
130 $fa = new ForumAdmin($f->Group->getID());
131 $fa->PrintAdminPendingOption($group_forum_id);
134 <form action="'.getStringFromServer('PHP_SELF').'" method="post">
136 <input type="hidden" name="post_changes" value="y" />
137 <input type="hidden" name="change_status" value="y" />
138 <input type="hidden" name="group_forum_id" value="'. $f->getID() .'" />
139 <input type="hidden" name="group_id" value="'.$group_id.'" />
140 <strong>'._('Forum Name').':</strong><br />
141 <input type="text" name="forum_name" value="'. $f->getName() .'" size="20" maxlength="30" />
144 <strong>'._('Email All Posts To:').'</strong><br />
145 <input type="text" name="send_all_posts_to" value="'. $f->getSendAllPostsTo() .'" size="60" />
148 <strong>'._('Description').':</strong><br />
149 <input type="text" name="description" value="'. $f->getDescription() .'" size="60" maxlength="80" /><br />
152 <input type="submit" name="submit" value="'._('Update').'" />
155 //echo '<a href="'.getStringFromServer('PHP_SELF').'?group_id='.$group_id.'&group_forum_id='.$group_forum_id.'&delete=1">'._('Delete Message').'</a><br />';
156 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>';
157 forum_footer(array());
159 } elseif ($deleteforum && $group_forum_id) {
161 $f = new Forum ($g,$group_forum_id);
163 forum_header(array('title'=>_('Delete')));
165 <strong>'._('You are about to permanently and irretrievably delete this entire forum and all its contents!').'</strong><br />
167 <form method="post" action="'.getStringFromServer('PHP_SELF').'">
168 <input type="hidden" name="post_changes" value="y" />
169 <input type="hidden" name="deleteforum" value="y" />
170 <input type="hidden" name="group_id" value="'.$group_id.'" />
171 <input type="hidden" name="group_forum_id" value="'.$group_forum_id.'" />
172 <input type="checkbox" name="sure" value="1" />'._('I\'m Sure').'<br />
173 <input type="checkbox" name="really_sure" value="1" />'._('I\'m Really Sure').'<br />
174 <input type="submit" name="submit" value="'._('Delete').'" />
176 forum_footer(array());
178 } elseif ( getStringFromRequest("deletemsg") ) {
179 // delete message handling
181 $forum_id = getIntFromRequest("forum_id");
182 $thread_id = getIntFromRequest("thread_id");
183 $msg_id = getIntFromRequest("deletemsg");
185 $f = forum_get_object ($forum_id) ;
187 $fa = new ForumAdmin($f->Group->getID());
189 if (getStringFromRequest("ok")) {
190 //actually delete the message
191 $feedback .= $fa->ExecuteAction("delete");
192 forum_header(array('title'=>_('Delete a Message')));
193 echo '<p>'.util_make_link ('/forum/forum.php?forum_id=' . $forum_id, _("Return to the forum")) . '</p>';
194 forum_footer(array());
195 } elseif (getStringFromRequest("cancel")) {
196 // the user cancelled the request, go back to forum
197 //if thread_id is 0, then we came from message.php. else, we came from forum.php
199 session_redirect('/forum/message.php?msg_id='.$msg_id);
201 session_redirect('/forum/forum.php?thread_id='.$thread_id.'&forum_id='.$forum_id);
205 //print the delete message confirmation
206 forum_header(array('title'=>_('Delete a Message')));
208 <form action="'.getStringFromServer('PHP_SELF').'" method="post">
209 <h3>' . _('WARNING! You are about to permanently delete a message and all of its followups!!') . '</h3>
211 <input type="submit" name="ok" value="' . _('Yes') . '" />
212 <input type="submit" name="cancel" value="' . _('No') . '" />
213 <input type="hidden" name="deletemsg" value="'.$msg_id.'" />
214 <input type="hidden" name="group_id" value="'.$group_id.'" />
215 <input type="hidden" name="forum_id" value="'.$forum_id.'" />
216 <input type="hidden" name="thread_id" value="'.$thread_id.'" />
220 forum_footer(array());
222 } elseif (getStringFromRequest("editmsg")) {
223 // edit message handling
224 $forum_id = getIntFromRequest("forum_id");
225 $thread_id = getIntFromRequest("thread_id");
226 $msg_id = getIntFromRequest("editmsg");
228 $f = forum_get_object ($forum_id) ;
229 $fa = new ForumAdmin($f->Group->getID());
231 if (getStringFromRequest("ok")) {
232 //actually finish editing the message and save the contents
233 $f = new Forum ($fa->GetGroupObject(),$forum_id);
234 if (!$f || !is_object($f)) {
235 exit_error(_('Error Getting Forum'),'forums');
236 } elseif ($f->isError()) {
237 exit_error($f->getErrorMessage(),'forums');
239 $fm=new ForumMessage($f,$msg_id,false,false);
240 if (!$fm || !is_object($fm)) {
241 exit_error(_('Error getting new forum message'),'forums');
242 } elseif ($fm->isError()) {
243 exit_error($fm->getErrorMessage(),'forums');
245 $subject = getStringFromRequest('subject');
246 $body = getStringFromRequest('body');
248 $sanitizer = new TextSanitizer();
249 $body = $sanitizer->SanitizeHtml($body);
251 $is_followup_to = getStringFromRequest('is_followup_to');
252 $form_key = getStringFromRequest('form_key');
253 $posted_by = getStringFromRequest('posted_by');
254 $post_date = getStringFromRequest('post_date');
255 $is_followup_to = getStringFromRequest('is_followup_to');
256 $has_followups = getStringFromRequest('has_followups');
257 $most_recent_date = getStringFromRequest('most_recent_date');
258 if ($fm->updatemsg($forum_id,$posted_by,$subject,$body,$post_date,$is_followup_to,$thread_id,$has_followups,$most_recent_date)) {
259 $feedback .= _('Message Edited Successfully');
261 $error_msg .= $fm->getErrorMessage();
263 forum_header(array('title'=>_('Edit a Message')));
264 echo '<p>'.util_make_link ('/forum/forum.php?forum_id=' . $forum_id, _("Return to the forum")) ;
265 forum_footer(array());
266 } elseif (getStringFromRequest("cancel")) {
267 // the user cancelled the request, go back to forum
268 session_redirect('/forum/message.php?msg_id='.$msg_id);
270 //print the edit message confirmation
272 $f = new Forum ($fa->GetGroupObject(),$forum_id);
273 if (!$f || !is_object($f)) {
274 exit_error(_('Error Getting Forum'),'forums');
275 } elseif ($f->isError()) {
276 exit_error($f->getErrorMessage(),'forums');
279 $fm=new ForumMessage($f,$msg_id,false,false);
280 if (!$fm || !is_object($fm)) {
281 exit_error(_('Error Getting ForumMessage'),'forums');
282 } elseif ($fm->isError()) {
283 exit_error($fm->getErrorMessage(),'forums');
286 $fh = new ForumHTML($f);
287 if (!$fh || !is_object($fh)) {
288 exit_error(_('Error Getting ForumHTML'),'forums');
289 } elseif ($fh->isError()) {
290 exit_error($fh->getErrorMessage(),'forums');
293 forum_header(array('title'=>_('Edit a Message')));
294 $fh->showEditForm($fm);
295 forum_footer(array());
297 } elseif (getStringFromRequest("movethread")) {
298 $thread_id = getIntFromRequest("movethread");
299 $msg_id = getStringFromRequest("msg_id");
300 $forum_id = getIntFromRequest("forum_id");
301 $return_to_message = getIntFromRequest("return_to_message");
302 $new_forum_id = getIntFromRequest("new_forum_id");
303 $f = forum_get_object ($forum_id) ;
304 $fa = new ForumAdmin($f->Group->getID());
306 if (getStringFromRequest("ok")) {
307 if ($forum_id == $new_forum_id) {
308 $feedback .= _('Thread not moved');
311 // Move message in another forum
312 $f_from = new Forum ($fa->GetGroupObject(),$forum_id);
313 if (!$f_from || !is_object($f_from)) {
314 exit_error(_('Could Not Get Forum Object'),'forums');
315 } elseif ($f_from->isError()) {
316 exit_error($f_from->getErrorMessage(),'forums');
318 $f_to = new Forum ($fa->GetGroupObject(),$new_forum_id);
319 if (!$f_to || !is_object($f_to)) {
320 exit_error(_('Could Not Get Forum Object'),'forums');
321 } elseif ($f_to->isError()) {
322 exit_error($f_to->getErrorMessage(),'forums');
325 $ff = new ForumFactory($g);
326 if (!$ff || !is_object($ff) || $ff->isError()) {
327 exit_error($ff->getErrorMessage(),'forums');
330 if ($ff->moveThread($new_forum_id,$thread_id,$forum_id)) {
331 $feedback .= sprintf(_('Thread successfully moved from %1$s forum to %2$s forum'), $f_from->getName(),$f_to->getName());
333 $error_msg .= $ff->getErrorMessage();
337 forum_header(array('title'=>_('Edit a Message')));
338 echo '<p><a href="/forum/forum.php?forum_id=' . $new_forum_id . '">Return to the forum</a></p>';
339 echo '<p><a href="/forum/forum.php?thread_id='.$thread_id.'&forum_id=' . $new_forum_id . '">Return to the thread</a></p>';
340 forum_footer(array());
341 } elseif (getStringFromRequest("cancel")) {
342 // the user cancelled the request, go back to forum
343 if ($return_to_message) {
344 session_redirect('/forum/message.php?msg_id='.$msg_id);
346 session_redirect('/forum/forum.php?thread_id='.$thread_id.'&forum_id='.$forum_id);
350 // Display select box to select new forum
352 forum_header(array('title'=>_('Move Thread')));
354 $ff = new ForumFactory($g);
355 if (!$ff || !is_object($ff) || $ff->isError()) {
356 exit_error($ff->getErrorMessage(),'forums');
359 $farr = $ff->getForums();
361 if ($ff->isError()) {
362 echo '<p class="error">'.sprintf(_('No Forums Found For %s'), $g->getPublicName())
363 . $ff->getErrorMessage().'</p>';
364 forum_footer(array());
369 List the existing forums so they can be edited.
373 for ($j = 0; $j < count($farr); $j++) {
374 if (!is_object($farr[$j])) {
375 //just skip it - this object should never have been placed here
376 } elseif ($farr[$j]->isError()) {
377 echo $farr[$j]->getErrorMessage();
379 $forums[$farr[$j]->getID()] = $farr[$j]->getName();
383 $f_from = new Forum ($fa->GetGroupObject(),$forum_id);
384 if (!$f_from || !is_object($f_from)) {
385 exit_error(_('Could Not Get Forum Object'),'forums');
386 } elseif ($f_from->isError()) {
387 exit_error($f_from->getErrorMessage(),'forums');
391 <form action="'.getStringFromServer('PHP_SELF').'" method="post">
392 <p><strong>' . sprintf(_('Move thread from %s forum to the following forum:'), $f_from->getName()) . '</strong></p>
394 <input type="hidden" name="movethread" value="'.$thread_id.'" />
395 <input type="hidden" name="group_id" value="'.$group_id.'" />
396 <input type="hidden" name="forum_id" value="'.$forum_id.'" />
397 <input type="hidden" name="msg_id" value="'.$msg_id.'" />
398 <input type="hidden" name="return_to_message" value="'.$return_to_message.'" />' .
399 html_build_select_box_from_assoc($forums,'new_forum_id',$forum_id) .
401 <input type="submit" name="ok" value="' . _("Submit") . '" />
402 <input type="submit" name="cancel" value="' . _("Cancel") . '" />
407 forum_footer(array());
412 Show main page for choosing
413 either moderator or delete
415 forum_header(array('title'=>_('Forums Administration')));
420 $fa = new ForumAdmin($g->getID());
422 $fa->PrintAdminOptions();
425 plugin_hook ("blocks", "forum index");
428 // Get existing forums
430 $ff=new ForumFactory($g);
431 if (!$ff || !is_object($ff) || $ff->isError()) {
432 exit_error($ff->getErrorMessage(),'forums');
435 $farr = $ff->getForumsAdmin();
437 if ($ff->isError()) {
438 echo '<p class="error">'.sprintf(_('No Forums Found For %s'), $g->getPublicName())
439 . $ff->getErrorMessage().'</p>';
440 forum_footer(array());
445 List the existing forums so they can be edited.
448 for ($j = 0; $j < count($farr); $j++) {
449 if (!is_object($farr[$j])) {
450 //just skip it - this object should never have been placed here
451 } elseif ($farr[$j]->isError()) {
452 echo $farr[$j]->getErrorMessage();
454 echo '<p><a href="'.getStringFromServer('PHP_SELF').'?group_id='.$group_id.'&change_status=1&group_forum_id='. $farr[$j]->getID() .'">'.
455 $farr[$j]->getName() .'</a><br />'.$farr[$j]->getDescription().'<br /><a href="monitor.php?group_id='.$group_id.'&group_forum_id='. $farr[$j]->getID() .'">'.
456 _('Monitoring Users').'</a></p>';
460 forum_footer(array());
465 // c-file-style: "bsd"