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 listing the forums for this project
170 //determine if this person can see private forums or not
171 if (session_loggedin() && user_ismember($group_id)) {
177 //create a pop-up select box showing options for viewing threads
179 $vals=array('nested','flat','threaded','ultimate');
180 $texts=array(_('Nested'), _('Flat'), _('Threaded'), _('Ultimate'));
182 $options_popup=html_build_select_box_from_arrays ($vals,$texts,'style',$style,false);
184 //create a pop-up select box showing options for max_row count
185 $vals=array(25,50,75,100);
186 $texts=array(_('Show').' 25',_('Show').' 50',_('Show').' 75',_('Show').' 100');
188 $max_row_popup=html_build_select_box_from_arrays ($vals,$texts,'max_rows',$max_rows,false);
190 //now show the popup boxes in a form
192 <form action="'. getStringFromServer('PHP_SELF') .'" method="get">
195 <input type="hidden" name="set" value="custom" />
196 <input type="hidden" name="forum_id" value="'.$forum_id.'" />
198 '</td><td>'. $max_row_popup .
199 '</td><td><input type="submit" name="submit" value="'.
200 _('Change View').'" />
205 $am = new AttachManager();
206 $ret_val .= $am->PrintHelperFunctions();
207 if ($style=='nested') {
209 $msg_arr =& $fmf->nestArray($fmf->getNested());
211 if ($fmf->isError()) {
212 echo '<p class="error">'.$fmf->getErrorMessage().'</p>';
213 forum_footer(array());
217 $rows=count($msg_arr["0"]);
218 $avail_rows=$fmf->fetched_rows;
219 if ($rows > $max_rows) {
225 while (($i < $rows) && ($total_rows < $max_rows)) {
229 New slashdot-inspired nested threads,
230 showing all submessages and bodies
232 $ret_val .= $fh->showNestedMessage ( $msg_arr["0"][$i] ).'<br />';
234 if ( $msg_arr["0"][$i]->hasFollowups() ) {
235 //show submessages for this message
236 $tempid=$msg_arr["0"][$i]->getID();
237 // echo "<p>before showNestedMessages() $tempid | ". count( $msg_arr["$tempid"] );
238 $ret_val .= $fh->showNestedMessages ( $msg_arr, $tempid );
243 } else if ($style=='threaded') {
245 $msg_arr =& $fmf->nestArray($fmf->getThreaded());
246 if ($fmf->isError()) {
247 echo '<p class="error">'.$fmf->getErrorMessage().'</p>';
248 forum_footer(array());
253 $title_arr[]=_('Thread');
254 $title_arr[]=_('Author');
255 $title_arr[]=_('Date');
257 $ret_val .= $GLOBALS['HTML']->listTableTop ($title_arr);
259 $rows=count($msg_arr[0]);
260 $avail_rows=$fmf->fetched_rows;
261 if ($rows > $max_rows) {
266 while (($i < $rows) && ($total_rows < $max_rows)) {
267 $msg =& $msg_arr["0"][$i];
270 $ret_val .= '<tr '. $GLOBALS['HTML']->boxGetAltRowStyle($total_rows) .'>
271 <td><a href="'.util_make_url ('/forum/message.php?msg_id='.$msg->getID().
272 '&group_id='.$group_id).'&reply=0">'.
273 html_image('ic/msg.png').' ';
275 See if this message is new or not
276 If so, highlite it in bold
278 if ($f->getSavedDate() < $msg->getPostDate()) {
279 $bold_begin='<strong>';
280 $bold_end='</strong>';
286 show the subject and poster
288 $ret_val .= $bold_begin.$msg->getSubject() .$bold_end.'</a></td>'.
289 '<td>'.util_display_user($msg->getPosterName(), $msg->getPosterID(), $msg->getPosterRealName()).'</td>'.
290 '<td>'.relative_date($msg->getPostDate()).'</td></tr>';
292 if ($msg->hasFollowups()) {
293 $ret_val .= $fh->showSubmessages($msg_arr,$msg->getID(),1);
298 $ret_val .= $GLOBALS['HTML']->listTableBottom();
300 } else if (($style=='flat' && $thread_id) || ($style=='ultimate' && $thread_id)) {
302 $msg_arr =& $fmf->getFlat($thread_id);
303 if ($fmf->isError()) {
304 echo '<p class="error">'.$fmf->getErrorMessage().'</p>';
305 forum_footer(array());
308 $avail_rows=$fmf->fetched_rows;
310 for ($i=0; ($i<count($msg_arr) && ($i < $max_rows)); $i++) {
311 $ret_val .= $fh->showNestedMessage ( $msg_arr[$i] ).'<br />';
316 This is the view that is most similar to the "Ultimate BB view"
319 $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,
320 (count(f2.thread_id)-1) AS followups,max(f2.post_date) AS recent
321 FROM forum f, forum f2, users
322 WHERE f.group_forum_id=$1
323 AND f.is_followup_to=0
324 AND users.user_id=f.posted_by
325 AND f.thread_id=f2.thread_id
326 GROUP BY f.most_recent_date,users.user_name,users.realname,users.user_id,f.msg_id,f.subject,f.thread_id
327 ORDER BY f.most_recent_date DESC',
332 $avail_rows=db_numrows($result);
336 if ($avail_rows > 0) {
338 $title_arr[]=_('Topic');
339 $title_arr[]=_('Topic Starter');
340 $title_arr[]=_('Replies');
341 $title_arr[]=_('Last Post');
343 $ret_val .= $GLOBALS['HTML']->listTableTop ($title_arr);
345 while (($row=db_fetch_array($result)) && ($i < $max_rows)) {
347 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'><td><a href="'.util_make_uri('/forum/forum.php?thread_id='.
348 $row['thread_id'].'&forum_id='.$forum_id.'&group_id='.$group_id).'">'.
349 html_image('ic/cfolder15.png') . ' ';
351 See if this message is new or not
352 If so, highlite it in bold
354 if ($f->getSavedDate() < $row['recent']) {
355 $bold_begin='<strong>';
356 $bold_end='</strong>';
362 show the subject and poster
364 $ret_val .= $bold_begin.$row['subject'] .$bold_end.'</a></td>'.
365 '<td>'.util_display_user($row['user_name'], $row['user_id'], $row['realname']).'</td>'.
366 '<td>'. $row['followups'] .'</td>'.
367 '<td>'. relative_date($row['recent']).'</td></tr>';
371 $ret_val .= $GLOBALS['HTML']->listTableBottom();
377 This code puts the nice next/prev.
379 if (($offset != 0) or ($avail_rows > $max_rows)) {
380 $ret_val .= '<table class="fullwidth">
381 <tr class="tablecontent"><td class="halfwidth">';
383 $ret_val .= '<span class="prev">
384 <a href="javascript:history.back()"><strong>' .
385 html_image('t2.png',"15","15") ._('Newer Messages').'</strong></a></span>';
390 $ret_val .= '</td><td></td><td class="halfwidth align-right">';
392 if ($avail_rows > $max_rows) {
393 $ret_val .= '<span class="next">
394 <a href="'.util_make_uri('/forum/forum.php?max_rows='.$max_rows.'&style='.$style.'&offset='.($offset+$i).
395 '&forum_id='.$forum_id.'&group_id='.$group_id).'">
396 <strong> '._('Older Messages') .
397 html_image('t.png',"15","15") . '</strong></a></span>';
401 $ret_val .= '</td></tr></table>';
405 forum_footer(array());
409 exit_error(_('No forum chosen'),'forums');