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-2014,2016, 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() and !$g->usesNews()) {
58 exit_error(sprintf(_('%s does not use the Forum tool.'), $g->getPublicName()), 'forums');
61 session_require_perm('forum_admin', $group_id);
63 if (getStringFromRequest('post_changes')) {
65 Update the DB to reflect the changes
72 $fa = new ForumAdmin($group_id);
73 $feedback .= $fa->ExecuteAction("delete_forum");
76 } elseif (getStringFromRequest('add_forum')) {
77 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
78 exit_form_double_submit('forums');
81 if (check_email_available($g, $g->getUnixName() . '-' . getStringFromRequest('forum_name'), $error_msg)) {
82 $fa = new ForumAdmin($group_id);
83 $feedback .= $fa->ExecuteAction("add_forum");
85 $error_msg = $fa->getErrorMessage();
87 $g->normalizeAllRoles();
90 } elseif (getStringFromRequest('change_status')) {
91 $fa = new ForumAdmin($group_id);
92 $feedback .= $fa->ExecuteAction("change_status");
94 $error_msg = $fa->getErrorMessage();
99 if (getStringFromRequest('add_forum')) {
101 Show the form for adding forums
103 forum_header(array('title'=>_('Add Forum')));
105 echo $HTML->openForm(array('method' => 'post', 'action' => getStringFromServer('PHP_SELF')));
107 <input type="hidden" name="post_changes" value="y" />
108 <input type="hidden" name="add_forum" value="y" />
109 <input type="hidden" name="group_id" value="'.$group_id.'" />
110 <input type="hidden" name="form_key" value="' . form_generate_key() . '" />
111 <label for="forum_name"><strong>'._('Forum Name').utils_requiredField()._(':').'</strong></label>
112 <input id="forum_name" type="text" name="forum_name" required="required" value="" size="20" maxlength="30" pattern=".{3,}" />
115 <label for="description"><strong>'._('Description').utils_requiredField()._(':').'</strong></label>
116 <input id="description" type="text" name="description" required="required" value="" size="40" maxlength="80" pattern=".{10,}" />
119 <strong>'._('Email All Posts To:').'</strong><br />
120 <input type="email" name="send_all_posts_to" value="" size="60" />
123 <input type="submit" name="submit" value="'._('Add This Forum').'" />
125 echo $HTML->closeForm();
126 echo '<span>'.sprintf(_('%s Mandatory fields'), utils_requiredField()).'</span>';
129 } elseif (getStringFromRequest('change_status')) {
134 $f = new Forum ($g,$group_forum_id);
136 forum_header(array('title'=>_('Change forum status')));
138 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>';
139 $fa = new ForumAdmin($f->Group->getID());
140 $fa->PrintAdminPendingOption($group_forum_id);
142 echo $HTML->openForm(array('method' => 'post', 'action' => getStringFromServer('PHP_SELF')));
144 <input type="hidden" name="post_changes" value="y" />
145 <input type="hidden" name="change_status" value="y" />
146 <input type="hidden" name="group_forum_id" value="'. $f->getID() .'" />
147 <input type="hidden" name="group_id" value="'.$group_id.'" />
148 <strong>'._('Forum Name').utils_requiredField()._(':').'</strong><br />
149 <input type="text" name="forum_name" required="required" value="'. $f->getName() .'" size="20" maxlength="30" pattern=".{3,}" />
152 <strong>'._('Email All Posts To:').'</strong><br />
153 <input type="email" name="send_all_posts_to" value="'. $f->getSendAllPostsTo() .'" size="60" />
156 <strong>'._('Description').utils_requiredField()._(': ').'</strong><br />
157 <input type="text" name="description" required="required" value="'. $f->getDescription() .'" size="60" maxlength="80" pattern=".{10,}" /><br />
160 <input type="submit" name="submit" value="'._('Update').'" />
162 echo $HTML->closeForm();
163 echo '<p>'.util_make_link(getStringFromServer('PHP_SELF').'?group_id='.$group_id.'&group_forum_id='.$group_forum_id.'&deleteforum=1', _('Delete entire forum and all content')).'</p>';
164 echo '<span>'.sprintf(_('%s Mandatory fields'), utils_requiredField()).'</span>';
167 } elseif ($deleteforum && $group_forum_id) {
169 $f = new Forum ($g,$group_forum_id);
171 forum_header(array('title'=>_('Permanently Delete Forum'), 'modal' => 1));
172 echo '<p><strong>'._('You are about to permanently and irretrievably delete this entire forum and all its contents!').'</strong></p>';
173 echo $HTML->openForm(array('method' => 'post', 'action' => getStringFromServer('PHP_SELF')));
174 echo ' <input type="hidden" name="post_changes" value="y" />
175 <input type="hidden" name="deleteforum" value="y" />
176 <input type="hidden" name="group_id" value="'.$group_id.'" />
177 <input type="hidden" name="group_forum_id" value="'.$group_forum_id.'" />
178 <input id="sure" type="checkbox" name="sure" value="1" /><label for="sure">'._('I am Sure').'</label><br />
179 <input id="really_sure" type="checkbox" name="really_sure" value="1" /><label for="really_sure">'._('I am Really Sure').'</label><br />
180 <input type="submit" name="submit" value="'._('Delete').'" />';
181 echo $HTML->closeForm();
184 } elseif ( getStringFromRequest("deletemsg") ) {
185 // delete message handling
187 $forum_id = getIntFromRequest("forum_id");
188 $thread_id = getIntFromRequest("thread_id");
189 $msg_id = getIntFromRequest("deletemsg");
191 $f = forum_get_object ($forum_id) ;
193 $fa = new ForumAdmin($f->Group->getID());
195 if (getStringFromRequest("ok")) {
196 //actually delete the message
197 $feedback .= $fa->ExecuteAction("delete");
198 forum_header(array('title'=>_('Delete a Message')));
199 echo '<p>'.util_make_link('/forum/forum.php?forum_id=' . $forum_id, _("Return to the forum")) . '</p>';
201 } elseif (getStringFromRequest("cancel")) {
202 // the user cancelled the request, go back to forum
203 //if thread_id is 0, then we came from message.php. else, we came from forum.php
205 session_redirect('/forum/message.php?msg_id='.$msg_id);
207 session_redirect('/forum/forum.php?thread_id='.$thread_id.'&forum_id='.$forum_id);
211 //print the delete message confirmation
212 forum_header(array('title'=>_('Delete a Message')));
214 echo $HTML->openForm(array('action' => getStringFromServer('PHP_SELF'), 'method' => 'post'));
215 echo ' <h3>' . _('WARNING! You are about to permanently delete a message and all of its comments!!') . '</h3>
217 <input type="submit" name="ok" value="' . _('Yes') . '" />
218 <input type="submit" name="cancel" value="' . _('No') . '" />
219 <input type="hidden" name="deletemsg" value="'.$msg_id.'" />
220 <input type="hidden" name="group_id" value="'.$group_id.'" />
221 <input type="hidden" name="forum_id" value="'.$forum_id.'" />
222 <input type="hidden" name="thread_id" value="'.$thread_id.'" />
224 echo $HTML->closeForm();
228 } elseif (getStringFromRequest("editmsg")) {
229 // edit message handling
230 $forum_id = getIntFromRequest("forum_id");
231 $thread_id = getIntFromRequest("thread_id");
232 $msg_id = getIntFromRequest("editmsg");
234 $f = forum_get_object ($forum_id) ;
235 $fa = new ForumAdmin($f->Group->getID());
237 if (getStringFromRequest("ok")) {
238 //actually finish editing the message and save the contents
239 $f = new Forum ($fa->GetGroupObject(),$forum_id);
240 if (!$f || !is_object($f)) {
241 exit_error(_('Error getting Forum'),'forums');
242 } elseif ($f->isError()) {
243 exit_error($f->getErrorMessage(),'forums');
245 $fm=new ForumMessage($f, $msg_id, array(), false);
246 if (!$fm || !is_object($fm)) {
247 exit_error(_('Error getting new forum message'),'forums');
248 } elseif ($fm->isError()) {
249 exit_error($fm->getErrorMessage(),'forums');
251 $subject = getStringFromRequest('subject');
252 $body = getStringFromRequest('body');
254 $sanitizer = new TextSanitizer();
255 $body = $sanitizer->SanitizeHtml($body);
257 $is_followup_to = getStringFromRequest('is_followup_to');
258 $form_key = getStringFromRequest('form_key');
259 $posted_by = getStringFromRequest('posted_by');
260 $post_date = getStringFromRequest('post_date');
261 $is_followup_to = getStringFromRequest('is_followup_to');
262 $has_followups = getStringFromRequest('has_followups');
263 $most_recent_date = getStringFromRequest('most_recent_date');
264 if ($fm->updatemsg($forum_id,$posted_by,$subject,$body,$post_date,$is_followup_to,$thread_id,$has_followups,$most_recent_date)) {
265 $feedback .= _('Message Edited Successfully');
267 $error_msg = $fm->getErrorMessage();
268 session_redirect('/forum/admin/index.php?editmsg='.$msg_id.'&group_id='.$group_id.'&thread_id='.$thread_id.'&forum_id='.$forum_id);
270 forum_header(array('title'=>_('Edit a Message')));
271 echo '<p>'.util_make_link('/forum/forum.php?forum_id=' . $forum_id, _("Return to the forum")) ;
273 } elseif (getStringFromRequest("cancel")) {
274 // the user cancelled the request, go back to forum
275 session_redirect('/forum/message.php?msg_id='.$msg_id);
277 //print the edit message confirmation
279 $f = new Forum ($fa->GetGroupObject(),$forum_id);
280 if (!$f || !is_object($f)) {
281 exit_error(_('Error getting Forum'),'forums');
282 } elseif ($f->isError()) {
283 exit_error($f->getErrorMessage(),'forums');
286 $fm = new ForumMessage($f, $msg_id, array(), false);
287 if (!$fm || !is_object($fm)) {
288 exit_error(_('Error Getting ForumMessage'),'forums');
289 } elseif ($fm->isError()) {
290 exit_error($fm->getErrorMessage(),'forums');
293 $fh = new ForumHTML($f);
294 if (!$fh || !is_object($fh)) {
295 exit_error(_('Error Getting ForumHTML'),'forums');
296 } elseif ($fh->isError()) {
297 exit_error($fh->getErrorMessage(),'forums');
300 forum_header(array('title'=>_('Edit a Message')));
301 $fh->showEditForm($fm);
304 } elseif (getStringFromRequest("movethread")) {
305 $thread_id = getIntFromRequest("movethread");
306 $msg_id = getStringFromRequest("msg_id");
307 $forum_id = getIntFromRequest("forum_id");
308 $return_to_message = getIntFromRequest("return_to_message");
309 $new_forum_id = getIntFromRequest("new_forum_id");
310 $f = forum_get_object ($forum_id) ;
311 $fa = new ForumAdmin($f->Group->getID());
313 if (getStringFromRequest("ok")) {
314 if ($forum_id == $new_forum_id) {
315 $feedback .= _('Thread not moved');
318 // Move message in another forum
319 $f_from = new Forum ($fa->GetGroupObject(),$forum_id);
320 if (!$f_from || !is_object($f_from)) {
321 exit_error(_('Could Not Get Forum Object'),'forums');
322 } elseif ($f_from->isError()) {
323 exit_error($f_from->getErrorMessage(),'forums');
325 $f_to = new Forum ($fa->GetGroupObject(),$new_forum_id);
326 if (!$f_to || !is_object($f_to)) {
327 exit_error(_('Could Not Get Forum Object'),'forums');
328 } elseif ($f_to->isError()) {
329 exit_error($f_to->getErrorMessage(),'forums');
332 $ff = new ForumFactory($g);
333 if (!$ff || !is_object($ff) || $ff->isError()) {
334 exit_error($ff->getErrorMessage(),'forums');
337 if ($ff->moveThread($new_forum_id,$thread_id,$forum_id)) {
338 $feedback .= sprintf(_('Thread successfully moved from %1$s forum to %2$s forum'), $f_from->getName(),$f_to->getName());
340 $error_msg .= $ff->getErrorMessage();
344 forum_header(array('title'=>_('Edit a Message')));
345 echo '<p>'.util_make_link('/forum/forum.php?forum_id='.$new_forum_id, _('Return to the forum')).'</p>';
346 echo '<p>'.util_make_link('/forum/forum.php?thread_id='.$thread_id.'&forum_id='.$new_forum_id, _('Return to the thread')).'</p>';
348 } elseif (getStringFromRequest("cancel")) {
349 // the user cancelled the request, go back to forum
350 if ($return_to_message) {
351 session_redirect('/forum/message.php?msg_id='.$msg_id);
353 session_redirect('/forum/forum.php?thread_id='.$thread_id.'&forum_id='.$forum_id);
357 // Display select box to select new forum
359 forum_header(array('title'=>_('Move Thread')));
361 $ff = new ForumFactory($g);
362 if (!$ff || !is_object($ff) || $ff->isError()) {
363 exit_error($ff->getErrorMessage(),'forums');
366 $farr = $ff->getForums();
368 if (is_array($farr) && empty($farr)) {
369 echo $HTML->error_msg(_('No forums found.'));
375 List the existing forums so they can be edited.
379 for ($j = 0; $j < count($farr); $j++) {
380 if (!is_object($farr[$j])) {
381 //just skip it - this object should never have been placed here
382 } elseif ($farr[$j]->isError()) {
383 echo $farr[$j]->getErrorMessage();
385 $forums[$farr[$j]->getID()] = $farr[$j]->getName();
389 $f_from = new Forum ($fa->GetGroupObject(),$forum_id);
390 if (!$f_from || !is_object($f_from)) {
391 exit_error(_('Could Not Get Forum Object'),'forums');
392 } elseif ($f_from->isError()) {
393 exit_error($f_from->getErrorMessage(),'forums');
397 echo $HTML->openForm(array('action' => getStringFromServer('PHP_SELF'), 'method' => 'post'));
398 echo ' <p><strong>' . sprintf(_('Move thread from %s forum to the following forum:'), $f_from->getName()) . '</strong></p>
400 <input type="hidden" name="movethread" value="'.$thread_id.'" />
401 <input type="hidden" name="group_id" value="'.$group_id.'" />
402 <input type="hidden" name="forum_id" value="'.$forum_id.'" />
403 <input type="hidden" name="msg_id" value="'.$msg_id.'" />
404 <input type="hidden" name="return_to_message" value="'.$return_to_message.'" />' .
405 html_build_select_box_from_assoc($forums,'new_forum_id',$forum_id) .
407 <input type="submit" name="ok" value="' . _("Submit") . '" />
408 <input type="submit" name="cancel" value="' . _("Cancel") . '" />
410 echo $HTML->closeForm();
417 Show main page for choosing
418 either moderator or delete
420 forum_header(array('title'=>_('Forums Administration')));
425 $fa = new ForumAdmin($g->getID());
427 $fa->PrintAdminOptions();
430 plugin_hook ("blocks", "forum index");
433 // Get existing forums
435 $ff=new ForumFactory($g);
436 if (!$ff || !is_object($ff) || $ff->isError()) {
437 exit_error($ff->getErrorMessage(),'forums');
440 $farr = $ff->getForumsAdmin();
443 echo $HTML->error_msg($ff->getErrorMessage());
449 List the existing forums so they can be edited.
452 for ($j = 0; $j < count($farr); $j++) {
453 if (!is_object($farr[$j])) {
454 //just skip it - this object should never have been placed here
455 } elseif ($farr[$j]->isError()) {
456 echo $HTML->error_msg($farr[$j]->getErrorMessage());
458 echo '<p>'.util_make_link('/forum/admin?group_id='.$group_id.'&change_status=1&group_forum_id='.$farr[$j]->getID(), $farr[$j]->getName()) .'<br />'.
459 $farr[$j]->getDescription().'<br />'.
460 util_make_link('/forum/admin/monitor.php?group_id='.$group_id.'&group_forum_id='.$farr[$j]->getID(), _('Monitoring Users')).'</p>';
469 // c-file-style: "bsd"