5 * Copyright 1999-2001, Tim Perdue - Sourceforge
6 * Copyright 2002, Tim Perdue - GForge, LLC
7 * Copyright 2010 (c) 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 $forum_id = getIntFromRequest('forum_id');
38 $style = getStringFromRequest('style');
39 $thread_id = getIntFromRequest('thread_id');
40 $offset = getIntFromRequest('offset');
41 $max_rows = getIntFromRequest('max_rows');
42 $set = getStringFromRequest('set');
47 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');
59 // Set up local objects
61 $g = group_get_object($group_id);
62 if (!$g || !is_object($g) || $g->isError()) {
66 $f=new Forum($g,$forum_id);
67 if (!$f || !is_object($f)) {
68 exit_error(_('Error getting new Forum'),'forums');
69 } elseif ($f->isError()) {
70 exit_error($f->getErrorMessage(),'forums');
74 if necessary, insert a new message into the forum
76 if (getStringFromRequest('post_message')) {
77 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
78 exit_form_double_submit('forums');
80 $subject = getStringFromRequest('subject');
81 $body = getStringFromRequest('body');
82 $is_followup_to = getStringFromRequest('is_followup_to');
84 $fm=new ForumMessage($f);
85 if (!$fm || !is_object($fm)) {
86 form_release_key(getStringFromRequest("form_key"));
87 exit_error(_('Error getting new ForumMessage'),'forums');
88 } elseif ($fm->isError()) {
89 form_release_key(getStringFromRequest("form_key"));
90 exit_error(_('Error getting new ForumMessage:'.' '.$fm->getErrorMessage()),'forums');
93 if (getStringFromRequest('_body_content_type') == 'html') {
94 $body = TextSanitizer::purify($body);
96 $body = htmlspecialchars($body);
99 $attach = getUploadedFile("attachment1");
100 if ($attach['size']) {
106 if (!$fm->create($subject, $body, $thread_id, $is_followup_to,$has_attach) || $fm->isError()) {
107 form_release_key(getStringFromRequest("form_key"));
108 exit_error(_('Error creating ForumMessage:').' '.$fm->getErrorMessage(),'forums');
110 if ($fm->isPending() ) {
111 $feedback=_('Message Queued for moderation -> Please wait until the admin approves/rejects it');
113 $feedback=_('Message Posted Successfully');
115 $am = NEW AttachManager();//object that will handle and insert the attachment into the db
116 $am->SetForumMsg($fm);
117 $am->attach($attach,$group_id,0,$fm->getID());
118 foreach ($am->Getmessages() as $item) {
119 $feedback .= "<br />" . $item;
123 if (getStringFromRequest('monitor')) {
130 $fmf = new ForumMessageFactory($f);
131 if (!$fmf || !is_object($fmf)) {
132 form_release_key(getStringFromRequest("form_key"));
133 exit_error(_('Error getting new ForumMessageFactory'),'forums');
134 } elseif ($fmf->isError()) {
135 form_release_key(getStringFromRequest("form_key"));
136 exit_error($fmf->getErrorMessage(),'forums');
139 //echo "<br /> style: $style|max_rows: $max_rows|offset: $offset+";
140 $fmf->setUp($offset,$style,$max_rows,$set);
142 $style=$fmf->getStyle();
143 $max_rows=$fmf->max_rows;
144 $offset=$fmf->offset;
146 //echo "<br /> style: $style|max_rows: $max_rows|offset: $offset+";
148 $fh = new ForumHTML($f);
149 if (!$fh || !is_object($fh)) {
150 exit_error(_('Error getting new ForumHTML'),'forums');
151 } elseif ($fh->isError()) {
152 exit_error($fh->getErrorMessage(),'forums');
155 forum_header(array('title'=>_('Forum: ') . $f->getName(),'forum_id'=>$forum_id));
159 * Forum styles include Nested, threaded, flat, ultimate
161 * threaded indents and shows subjects/authors of all messages/followups
162 * nested indents and shows the entirety of all messages/followups
163 * flat shows entiretly of messages in date order descending
164 * ultimate is based roughly on "Ultimate BB"
168 //create a pop-up select box listing the forums for this project
169 //determine if this person can see private forums or not
170 if (session_loggedin() && user_ismember($group_id)) {
176 //create a pop-up select box showing options for viewing threads
178 $vals=array('nested','flat','threaded','ultimate');
179 $texts=array(_('Nested'), _('Flat'), _('Threaded'), _('Ultimate'));
181 $options_popup=html_build_select_box_from_arrays ($vals,$texts,'style',$style,false);
183 //create a pop-up select box showing options for max_row count
184 $vals=array(25,50,75,100);
185 $texts=array(_('Show').' 25',_('Show').' 50',_('Show').' 75',_('Show').' 100');
187 $max_row_popup=html_build_select_box_from_arrays ($vals,$texts,'max_rows',$max_rows,false);
189 //now show the popup boxes in a form
191 <form action="'. getStringFromServer('PHP_SELF') .'" method="get">
192 <table border="0" width="33%">
194 <input type="hidden" name="set" value="custom" />
195 <input type="hidden" name="forum_id" value="'.$forum_id.'" />
197 '</td><td>'. $max_row_popup .
198 '</td><td><input type="submit" name="submit" value="'.
199 _('Change View').'" />
203 $am = new AttachManager();
204 $ret_val .= $am->PrintHelperFunctions();
205 if ($style=='nested') {
207 $msg_arr =& $fmf->nestArray($fmf->getNested());
209 if ($fmf->isError()) {
210 echo '<div class="error">'.$fmf->getErrorMessage().'</div>';
211 forum_footer(array());
215 $rows=count($msg_arr["0"]);
216 $avail_rows=$fmf->fetched_rows;
217 if ($rows > $max_rows) {
223 while (($i < $rows) && ($total_rows < $max_rows)) {
227 New slashdot-inspired nested threads,
228 showing all submessages and bodies
230 $ret_val .= $fh->showNestedMessage ( $msg_arr["0"][$i] ).'<br />';
232 if ( $msg_arr["0"][$i]->hasFollowups() ) {
233 //show submessages for this message
234 $tempid=$msg_arr["0"][$i]->getID();
235 // echo "<p>before showNestedMessages() $tempid | ". count( $msg_arr["$tempid"] );
236 $ret_val .= $fh->showNestedMessages ( $msg_arr, $tempid );
241 } else if ($style=='threaded') {
243 $msg_arr =& $fmf->nestArray($fmf->getThreaded());
244 if ($fmf->isError()) {
245 echo '<div class="error">'.$fmf->getErrorMessage().'</div>';
246 forum_footer(array());
251 $title_arr[]=_('Thread');
252 $title_arr[]=_('Author');
253 $title_arr[]=_('Date');
255 $ret_val .= $GLOBALS['HTML']->listTableTop ($title_arr);
257 $rows=count($msg_arr[0]);
258 $avail_rows=$fmf->fetched_rows;
259 if ($rows > $max_rows) {
264 while (($i < $rows) && ($total_rows < $max_rows)) {
265 $msg =& $msg_arr["0"][$i];
268 $ret_val .= '<tr '. $GLOBALS['HTML']->boxGetAltRowStyle($total_rows) .'>
269 <td><a href="'.util_make_url ('/forum/message.php?msg_id='.$msg->getID().
270 '&group_id='.$group_id).'&reply=0">'.
271 html_image('ic/msg.png').' ';
273 See if this message is new or not
274 If so, highlite it in bold
276 if ($f->getSavedDate() < $msg->getPostDate()) {
277 $bold_begin='<strong>';
278 $bold_end='</strong>';
284 show the subject and poster
286 $ret_val .= $bold_begin.$msg->getSubject() .$bold_end.'</a></td>'.
287 '<td>'.util_display_user($msg->getPosterName(), $msg->getPosterID(), $msg->getPosterRealName()).'</td>'.
288 '<td>'. date(_('Y-m-d H:i'),$msg->getPostDate()) .'</td></tr>';
290 if ($msg->hasFollowups()) {
291 $ret_val .= $fh->showSubmessages($msg_arr,$msg->getID(),1);
296 $ret_val .= $GLOBALS['HTML']->listTableBottom();
298 } else if (($style=='flat' && $thread_id) || ($style=='ultimate' && $thread_id)) {
300 $msg_arr =& $fmf->getFlat($thread_id);
301 if ($fmf->isError()) {
302 echo '<div class="error">'.$fmf->getErrorMessage().'</div>';
303 forum_footer(array());
306 $avail_rows=$fmf->fetched_rows;
308 for ($i=0; ($i<count($msg_arr) && ($i < $max_rows)); $i++) {
309 $ret_val .= $fh->showNestedMessage ( $msg_arr[$i] ).'<br />';
314 This is the view that is most similar to the "Ultimate BB view"
317 $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,
318 (count(f2.thread_id)-1) AS followups,max(f2.post_date) AS recent
319 FROM forum f, forum f2, users
320 WHERE f.group_forum_id=$1
321 AND f.is_followup_to=0
322 AND users.user_id=f.posted_by
323 AND f.thread_id=f2.thread_id
324 GROUP BY f.most_recent_date,users.user_name,users.realname,users.user_id,f.msg_id,f.subject,f.thread_id
325 ORDER BY f.most_recent_date DESC',
330 $avail_rows=db_numrows($result);
334 if ($avail_rows > 0) {
336 $title_arr[]=_('Topic');
337 $title_arr[]=_('Topic Starter');
338 $title_arr[]=_('Replies');
339 $title_arr[]=_('Last Post');
341 $ret_val .= $GLOBALS['HTML']->listTableTop ($title_arr);
343 while (($row=db_fetch_array($result)) && ($i < $max_rows)) {
345 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'><td><a href="'.util_make_uri('/forum/forum.php?thread_id='.
346 $row['thread_id'].'&forum_id='.$forum_id.'&group_id='.$group_id).'">'.
347 html_image('ic/cfolder15.png') . ' ';
349 See if this message is new or not
350 If so, highlite it in bold
352 if ($f->getSavedDate() < $row['recent']) {
353 $bold_begin='<strong>';
354 $bold_end='</strong>';
360 show the subject and poster
362 $ret_val .= $bold_begin.$row['subject'] .$bold_end.'</a></td>'.
363 '<td>'.util_display_user($row['user_name'], $row['user_id'], $row['realname']).'</td>'.
364 '<td>'. $row['followups'] .'</td>'.
365 '<td>'.date(_('Y-m-d H:i'),$row['recent']).'</td></tr>';
369 $ret_val .= $GLOBALS['HTML']->listTableBottom();
375 This code puts the nice next/prev.
377 if (($offset != 0) or ($avail_rows > $max_rows)) {
378 $ret_val .= '<table width="100%" border="0">
379 <tr class="tablecontent"><td width="50%">';
381 $ret_val .= '<span class="prev">
382 <a href="javascript:history.back()"><strong>' .
383 html_image('t2.png',"15","15") ._('Newer Messages').'</strong></a></span>';
385 $ret_val .= ' ';
388 $ret_val .= '</td><td> </td><td align="right" width="50%">';
390 if ($avail_rows > $max_rows) {
391 $ret_val .= '<span class="next">
392 <a href="'.util_make_uri('/forum/forum.php?max_rows='.$max_rows.'&style='.$style.'&offset='.($offset+$i).
393 '&forum_id='.$forum_id.'&group_id='.$group_id).'">
394 <strong> '._('Older Messages') .
395 html_image('t.png',"15","15") . '</strong></a></span>';
397 $ret_val .= ' ';
399 $ret_val .= '</td></tr></table>';
408 // Viewing an entire message forum in a given format
410 echo '<center><h3>'._('Start New Thread').'</h3></center>';
414 forum_footer(array());
418 exit_error(_('No forum chosen'),'forums');