5 * Copyright 1999-2001, Tim Perdue - Sourceforge
6 * Copyright 2002, Tim Perdue - GForge, LLC
7 * Copyright 2010-2011, Franck Villaume - Capgemini
8 * Copyright (C) 2010-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/ForumFactory.class.php';
32 require_once $gfcommon.'forum/ForumMessageFactory.class.php';
33 require_once $gfcommon.'forum/ForumMessage.class.php';
34 require_once $gfcommon.'forum/AttachManager.class.php'; //attachent manager
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 $forum_id = getIntFromRequest('forum_id');
39 $style = getStringFromRequest('style');
40 $thread_id = getIntFromRequest('thread_id');
41 $offset = getIntFromRequest('offset');
42 $max_rows = getIntFromRequest('max_rows');
43 $set = getStringFromRequest('set');
48 // Get the group_id based on this forum_id
49 $result=db_query_params ('SELECT group_id
51 WHERE group_forum_id=$1',
53 if (!$result || db_numrows($result) < 1) {
54 exit_error(_('Error forum not found: ').db_error(),'forums');
56 $group_id=db_result($result,0,'group_id');
60 // Set up local objects
62 $g = group_get_object($group_id);
63 if (!$g || !is_object($g) || $g->isError()) {
67 $f=new Forum($g, $forum_id);
68 if (!$f || !is_object($f)) {
69 exit_error(_('Error getting new Forum'), 'forums');
70 } elseif ($f->isError()) {
71 exit_error($f->getErrorMessage(), 'forums');
75 if necessary, insert a new message into the forum
77 if (getStringFromRequest('post_message')) {
78 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
79 exit_form_double_submit('forums');
81 $subject = getStringFromRequest('subject');
82 $body = getStringFromRequest('body');
83 $is_followup_to = getStringFromRequest('is_followup_to');
85 $fm = new ForumMessage($f);
86 if (!$fm || !is_object($fm)) {
87 form_release_key(getStringFromRequest("form_key"));
88 exit_error(_('Error getting new ForumMessage'), 'forums');
89 } elseif ($fm->isError()) {
90 form_release_key(getStringFromRequest("form_key"));
91 exit_error(_('Error getting new ForumMessage:'.' '.$fm->getErrorMessage()), 'forums');
94 if (getStringFromRequest('_body_content_type') == 'html') {
95 $body = TextSanitizer::purify($body);
97 $body = htmlspecialchars($body);
100 $attach = getUploadedFile("attachment1");
101 if ($attach['size']) {
107 if (!$fm->create($subject, $body, $thread_id, $is_followup_to,$has_attach) || $fm->isError()) {
108 form_release_key(getStringFromRequest("form_key"));
109 exit_error(_('Error creating ForumMessage:').' '.$fm->getErrorMessage(), 'forums');
111 if ($fm->isPending() ) {
112 $feedback = _('Message Queued for moderation -> Please wait until the admin approves/rejects it');
114 $feedback = _('Message Posted Successfully');
116 $am = new AttachManager();//object that will handle and insert the attachment into the db
117 $am->SetForumMsg($fm);
118 $am->attach($attach, $group_id, 0, $fm->getID());
119 foreach ($am->Getmessages() as $item) {
120 $feedback .= "<br />" . $item;
124 if (getStringFromRequest('monitor')) {
131 $fmf = new ForumMessageFactory($f);
132 if (!$fmf || !is_object($fmf)) {
133 form_release_key(getStringFromRequest("form_key"));
134 exit_error(_('Error getting new ForumMessageFactory'), 'forums');
135 } elseif ($fmf->isError()) {
136 form_release_key(getStringFromRequest("form_key"));
137 exit_error($fmf->getErrorMessage(), 'forums');
140 //echo "<br /> style: $style|max_rows: $max_rows|offset: $offset+";
141 $fmf->setUp($offset, $style, $max_rows, $set);
143 $style=$fmf->getStyle();
144 $max_rows=$fmf->max_rows;
145 $offset=$fmf->offset;
147 //echo "<br /> style: $style|max_rows: $max_rows|offset: $offset+";
149 $fh = new ForumHTML($f);
150 if (!$fh || !is_object($fh)) {
151 exit_error(_('Error getting new ForumHTML'), 'forums');
152 } elseif ($fh->isError()) {
153 exit_error($fh->getErrorMessage(), 'forums');
156 forum_header(array('title'=>_('Forum: ') . $f->getName(), 'forum_id'=>$forum_id));
160 * Forum styles include Nested, threaded, flat, ultimate
162 * threaded indents and shows subjects/authors of all messages/followups
163 * nested indents and shows the entirety of all messages/followups
164 * flat shows entiretly of messages in date order descending
165 * ultimate is based roughly on "Ultimate BB"
169 //create a pop-up select box showing options for viewing threads
171 $vals=array('nested','flat','threaded','ultimate');
172 $texts=array(_('Nested'), _('Flat'), _('Threaded'), _('Ultimate'));
174 $options_popup=html_build_select_box_from_arrays ($vals,$texts,'style',$style,false);
176 //create a pop-up select box showing options for max_row count
177 $vals=array(25,50,75,100);
178 $texts=array(_('Show').' 25',_('Show').' 50',_('Show').' 75',_('Show').' 100');
180 $max_row_popup=html_build_select_box_from_arrays ($vals,$texts,'max_rows',$max_rows,false);
182 //now show the popup boxes in a form
184 <form action="'. getStringFromServer('PHP_SELF') .'" method="get">
187 <input type="hidden" name="set" value="custom" />
188 <input type="hidden" name="forum_id" value="'.$forum_id.'" />
190 '</td><td>'. $max_row_popup .
191 '</td><td><input type="submit" name="submit" value="'.
192 _('Change View').'" />
197 $am = new AttachManager();
198 $ret_val .= $am->PrintHelperFunctions();
199 if ($style=='nested') {
201 $msg_arr =& $fmf->nestArray($fmf->getNested());
203 if ($fmf->isError()) {
204 echo '<p class="error">'.$fmf->getErrorMessage().'</p>';
205 forum_footer(array());
209 $rows=count($msg_arr["0"]);
210 $avail_rows=$fmf->fetched_rows;
211 if ($rows > $max_rows) {
217 while (($i < $rows) && ($total_rows < $max_rows)) {
221 New slashdot-inspired nested threads,
222 showing all submessages and bodies
224 $ret_val .= $fh->showNestedMessage ( $msg_arr["0"][$i] ).'<br />';
226 if ( $msg_arr["0"][$i]->hasFollowups() ) {
227 //show submessages for this message
228 $tempid=$msg_arr["0"][$i]->getID();
229 // echo "<p>before showNestedMessages() $tempid | ". count( $msg_arr["$tempid"] );
230 $ret_val .= $fh->showNestedMessages ( $msg_arr, $tempid );
235 } else if ($style=='threaded') {
237 $msg_arr =& $fmf->nestArray($fmf->getThreaded());
238 if ($fmf->isError()) {
239 echo '<p class="error">'.$fmf->getErrorMessage().'</p>';
240 forum_footer(array());
245 $title_arr[]=_('Thread');
246 $title_arr[]=_('Author');
247 $title_arr[]=_('Date');
249 $ret_val .= $GLOBALS['HTML']->listTableTop ($title_arr);
251 $rows=count($msg_arr[0]);
252 $avail_rows=$fmf->fetched_rows;
253 if ($rows > $max_rows) {
258 while (($i < $rows) && ($total_rows < $max_rows)) {
259 $msg =& $msg_arr["0"][$i];
262 $ret_val .= '<tr '. $GLOBALS['HTML']->boxGetAltRowStyle($total_rows) .'>
263 <td><a href="'.util_make_url ('/forum/message.php?msg_id='.$msg->getID().
264 '&group_id='.$group_id).'&reply=0">'.
265 html_image('ic/msg.png').' ';
267 See if this message is new or not
268 If so, highlite it in bold
270 if ($f->getSavedDate() < $msg->getPostDate()) {
271 $bold_begin='<strong>';
272 $bold_end='</strong>';
278 show the subject and poster
280 $ret_val .= $bold_begin.$msg->getSubject() .$bold_end.'</a></td>'.
281 '<td>'.util_display_user($msg->getPosterName(), $msg->getPosterID(), $msg->getPosterRealName()).'</td>'.
282 '<td>'.relative_date($msg->getPostDate()).'</td></tr>';
284 if ($msg->hasFollowups()) {
285 $ret_val .= $fh->showSubmessages($msg_arr,$msg->getID(),1);
290 $ret_val .= $GLOBALS['HTML']->listTableBottom();
292 } else if (($style=='flat' && $thread_id) || ($style=='ultimate' && $thread_id)) {
294 $msg_arr =& $fmf->getFlat($thread_id);
295 if ($fmf->isError()) {
296 echo '<p class="error">'.$fmf->getErrorMessage().'</p>';
297 forum_footer(array());
300 $avail_rows=$fmf->fetched_rows;
302 for ($i=0; ($i<count($msg_arr) && ($i < $max_rows)); $i++) {
303 $ret_val .= $fh->showNestedMessage ( $msg_arr[$i] ).'<br />';
308 This is the view that is most similar to the "Ultimate BB view"
311 $result = db_query_params ('SELECT f.most_recent_date,users.user_name,users.realname,users.user_id,f.msg_id,f.subject,f.thread_id,
312 (count(f2.thread_id)-1) AS followups,max(f2.post_date) AS recent
313 FROM forum f, forum f2, users
314 WHERE f.group_forum_id=$1
315 AND f.is_followup_to=0
316 AND users.user_id=f.posted_by
317 AND f.thread_id=f2.thread_id
318 GROUP BY f.most_recent_date,users.user_name,users.realname,users.user_id,f.msg_id,f.subject,f.thread_id
319 ORDER BY f.most_recent_date DESC',
324 $avail_rows=db_numrows($result);
328 if ($avail_rows > 0) {
330 $title_arr[]=_('Topic');
331 $title_arr[]=_('Topic Starter');
332 $title_arr[]=_('Replies');
333 $title_arr[]=_('Last Post');
335 $ret_val .= $GLOBALS['HTML']->listTableTop ($title_arr);
337 while (($row=db_fetch_array($result)) && ($i < $max_rows)) {
339 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'><td><a href="'.util_make_uri('/forum/forum.php?thread_id='.
340 $row['thread_id'].'&forum_id='.$forum_id.'&group_id='.$group_id).'">'.
341 html_image('ic/cfolder15.png') . ' ';
343 See if this message is new or not
344 If so, highlite it in bold
346 if ($f->getSavedDate() < $row['recent']) {
347 $bold_begin='<strong>';
348 $bold_end='</strong>';
354 show the subject and poster
356 $ret_val .= $bold_begin.$row['subject'] .$bold_end.'</a></td>'.
357 '<td>'.util_display_user($row['user_name'], $row['user_id'], $row['realname']).'</td>'.
358 '<td>'. $row['followups'] .'</td>'.
359 '<td>'. relative_date($row['recent']).'</td></tr>';
363 $ret_val .= $GLOBALS['HTML']->listTableBottom();
369 This code puts the nice next/prev.
371 if (($offset != 0) or ($avail_rows > $max_rows)) {
372 $ret_val .= '<table class="fullwidth">
373 <tr class="tablecontent"><td class="halfwidth">';
375 $ret_val .= '<span class="prev">
376 <a href="javascript:history.back()"><strong>' .
377 html_image('t2.png',"15","15") ._('Newer Messages').'</strong></a></span>';
382 $ret_val .= '</td><td></td><td class="halfwidth align-right">';
384 if ($avail_rows > $max_rows) {
385 $ret_val .= '<span class="next">
386 <a href="'.util_make_uri('/forum/forum.php?max_rows='.$max_rows.'&style='.$style.'&offset='.($offset+$i).
387 '&forum_id='.$forum_id.'&group_id='.$group_id).'">
388 <strong> '._('Older Messages') .
389 html_image('t.png',"15","15") . '</strong></a></span>';
393 $ret_val .= '</td></tr></table>';
397 forum_footer(array());
401 exit_error(_('No forum chosen'),'forums');