5 * Copyright 1999-2001, Tim Perdue - Sourceforge
6 * Copyright 2002, Tim Perdue - GForge, LLC
7 * Copyright 2010 (c) Franck Villaume - Capgemini
8 * http://fusionforge.org
10 * This file is part of FusionForge. FusionForge is free software;
11 * you can redistribute it and/or modify it under the terms of the
12 * GNU General Public License as published by the Free Software
13 * Foundation; either version 2 of the Licence, or (at your option)
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 require_once('../env.inc.php');
27 require_once $gfcommon.'include/pre.php';
28 require_once $gfwww.'forum/include/ForumHTML.class.php';
29 require_once $gfcommon.'forum/Forum.class.php';
30 require_once $gfcommon.'forum/ForumFactory.class.php';
31 require_once $gfcommon.'forum/ForumMessageFactory.class.php';
32 require_once $gfcommon.'forum/ForumMessage.class.php';
33 require_once $gfwww.'forum/include/AttachManager.class.php'; //attachent manager
34 require_once $gfcommon.'include/TextSanitizer.class.php'; // to make the HTML input by the user safe to store
36 $forum_id = getIntFromRequest('forum_id');
37 $style = getStringFromRequest('style');
38 $thread_id = getIntFromRequest('thread_id');
39 $offset = getIntFromRequest('offset');
40 $max_rows = getIntFromRequest('max_rows');
41 $set = getStringFromRequest('set');
42 $feedback = htmlspecialchars(getStringFromRequest('feedback'));
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 $sanitizer = new TextSanitizer();
94 $body = $sanitizer->SanitizeHtml($body);
96 $attach = getUploadedFile("attachment1");
97 if ($attach['size']) {
103 if (!$fm->create($subject, $body, $thread_id, $is_followup_to,$has_attach) || $fm->isError()) {
104 form_release_key(getStringFromRequest("form_key"));
105 exit_error(_('Error creating ForumMessage:').' '.$fm->getErrorMessage(),'forums');
107 if ($fm->isPending() ) {
108 $feedback=_('Message Queued for moderation -> Please wait until the admin approves/rejects it');
110 $feedback=_('Message Posted Successfully');
112 $am = NEW AttachManager();//object that will handle and insert the attachment into the db
113 $am->SetForumMsg($fm);
114 $am->attach($attach,$group_id,0,$fm->getID());
115 foreach ($am->Getmessages() as $item) {
116 $feedback .= "<br />" . $item;
120 if (getStringFromRequest('monitor')) {
127 $fmf = new ForumMessageFactory($f);
128 if (!$fmf || !is_object($fmf)) {
129 form_release_key(getStringFromRequest("form_key"));
130 exit_error(_('Error getting new ForumMessageFactory'),'forums');
131 } elseif ($fmf->isError()) {
132 form_release_key(getStringFromRequest("form_key"));
133 exit_error($fmf->getErrorMessage(),'forums');
136 //echo "<br /> style: $style|max_rows: $max_rows|offset: $offset+";
137 $fmf->setUp($offset,$style,$max_rows,$set);
139 $style=$fmf->getStyle();
140 $max_rows=$fmf->max_rows;
141 $offset=$fmf->offset;
143 //echo "<br /> style: $style|max_rows: $max_rows|offset: $offset+";
145 $fh = new ForumHTML($f);
146 if (!$fh || !is_object($fh)) {
147 exit_error(_('Error getting new ForumHTML'),'forums');
148 } elseif ($fh->isError()) {
149 exit_error($fh->getErrorMessage(),'forums');
152 forum_header(array('title'=>_('Forum: ') . $f->getName(),'forum_id'=>$forum_id));
156 * Forum styles include Nested, threaded, flat, ultimate
158 * threaded indents and shows subjects/authors of all messages/followups
159 * nested indents and shows the entirety of all messages/followups
160 * flat shows entiretly of messages in date order descending
161 * ultimate is based roughly on "Ultimate BB"
165 //create a pop-up select box listing the forums for this project
166 //determine if this person can see private forums or not
167 if (session_loggedin() && user_ismember($group_id)) {
173 //create a pop-up select box showing options for viewing threads
175 $vals=array('nested','flat','threaded','ultimate');
176 $texts=array(_('Nested'), _('Flat'), _('Threaded'), _('Ultimate'));
178 $options_popup=html_build_select_box_from_arrays ($vals,$texts,'style',$style,false);
180 //create a pop-up select box showing options for max_row count
181 $vals=array(25,50,75,100);
182 $texts=array(_('Show').' 25',_('Show').' 50',_('Show').' 75',_('Show').' 100');
184 $max_row_popup=html_build_select_box_from_arrays ($vals,$texts,'max_rows',$max_rows,false);
186 //now show the popup boxes in a form
188 <form action="'. getStringFromServer('PHP_SELF') .'" method="get">
189 <input type="hidden" name="set" value="custom" />
190 <input type="hidden" name="forum_id" value="'.$forum_id.'" />
191 <table border="0" width="33%">
192 <tr><td>'. $options_popup .
193 '</td><td>'. $max_row_popup .
194 '</td><td><input type="submit" name="submit" value="'.
195 _('Change View').'" />
199 $am = new AttachManager();
200 $ret_val .= $am->PrintHelperFunctions();
201 if ($style=='nested') {
203 $msg_arr =& $fmf->nestArray($fmf->getNested());
205 if ($fmf->isError()) {
206 echo '<div class="error">'.$fmf->getErrorMessage().'</div>';
207 forum_footer(array());
211 $rows=count($msg_arr["0"]);
212 $avail_rows=$fmf->fetched_rows;
213 if ($rows > $max_rows) {
219 while (($i < $rows) && ($total_rows < $max_rows)) {
223 New slashdot-inspired nested threads,
224 showing all submessages and bodies
226 $ret_val .= $fh->showNestedMessage ( $msg_arr["0"][$i] ).'<br />';
228 if ( $msg_arr["0"][$i]->hasFollowups() ) {
229 //show submessages for this message
230 $tempid=$msg_arr["0"][$i]->getID();
231 // echo "<p>before showNestedMessages() $tempid | ". count( $msg_arr["$tempid"] );
232 $ret_val .= $fh->showNestedMessages ( $msg_arr, $tempid );
237 } else if ($style=='threaded') {
239 $msg_arr =& $fmf->nestArray($fmf->getThreaded());
240 if ($fmf->isError()) {
241 echo '<div class="error">'.$fmf->getErrorMessage().'</div>';
242 forum_footer(array());
247 $title_arr[]=_('Thread');
248 $title_arr[]=_('Author');
249 $title_arr[]=_('Date');
251 $ret_val .= $GLOBALS['HTML']->listTableTop ($title_arr);
253 $rows=count($msg_arr[0]);
254 $avail_rows=$fmf->fetched_rows;
255 if ($rows > $max_rows) {
260 while (($i < $rows) && ($total_rows < $max_rows)) {
261 $msg =& $msg_arr["0"][$i];
264 $ret_val .= '<tr '. $GLOBALS['HTML']->boxGetAltRowStyle($total_rows) .'>
265 <td><a href="'.util_make_url ('/forum/message.php?msg_id='.$msg->getID().
266 '&group_id='.$group_id).'&reply=0">'.
267 html_image('ic/msg.png',"10","12").' ';
269 See if this message is new or not
270 If so, highlite it in bold
272 if ($f->getSavedDate() < $msg->getPostDate()) {
273 $bold_begin='<strong>';
274 $bold_end='</strong>';
280 show the subject and poster
282 $ret_val .= $bold_begin.$msg->getSubject() .$bold_end.'</a></td>'.
283 '<td>'.util_display_user($msg->getPosterName(), $msg->getPosterID(), $msg->getPosterRealName()).'</td>'.
284 '<td>'. date(_('Y-m-d H:i'),$msg->getPostDate()) .'</td></tr>';
286 if ($msg->hasFollowups()) {
287 $ret_val .= $fh->showSubmessages($msg_arr,$msg->getID(),1);
292 $ret_val .= $GLOBALS['HTML']->listTableBottom();
294 } else if (($style=='flat' && $thread_id) || ($style=='ultimate' && $thread_id)) {
296 $msg_arr =& $fmf->getFlat($thread_id);
297 if ($fmf->isError()) {
298 echo '<div class="error">'.$fmf->getErrorMessage().'</div>';
299 forum_footer(array());
302 $avail_rows=$fmf->fetched_rows;
304 for ($i=0; ($i<count($msg_arr) && ($i < $max_rows)); $i++) {
305 $ret_val .= $fh->showNestedMessage ( $msg_arr[$i] ).'<br />';
310 This is the view that is most similar to the "Ultimate BB view"
313 $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,
314 (count(f2.thread_id)-1) AS followups,max(f2.post_date) AS recent
315 FROM forum f, forum f2, users
316 WHERE f.group_forum_id=$1
317 AND f.is_followup_to=0
318 AND users.user_id=f.posted_by
319 AND f.thread_id=f2.thread_id
320 GROUP BY f.most_recent_date,users.user_name,users.realname,users.user_id,f.msg_id,f.subject,f.thread_id
321 ORDER BY f.most_recent_date DESC',
326 $avail_rows=db_numrows($result);
330 if ($avail_rows > 0) {
332 $title_arr[]=_('Topic');
333 $title_arr[]=_('Topic Starter');
334 $title_arr[]=_('Replies');
335 $title_arr[]=_('Last Post');
337 $ret_val .= $GLOBALS['HTML']->listTableTop ($title_arr);
339 while (($row=db_fetch_array($result)) && ($i < $max_rows)) {
341 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'><td><a href="'.util_make_url ('/forum/forum.php?thread_id='.
342 $row['thread_id'].'&forum_id='.$forum_id.'&group_id='.$group_id).'">'.
343 html_image('ic/cfolder15.png',"15","13") . ' ';
345 See if this message is new or not
346 If so, highlite it in bold
348 if ($f->getSavedDate() < $row['recent']) {
349 $bold_begin='<strong>';
350 $bold_end='</strong>';
356 show the subject and poster
358 $ret_val .= $bold_begin.$row['subject'] .$bold_end.'</a></td>'.
359 '<td>'.util_display_user($row['user_name'], $row['user_id'], $row['realname']).'</td>'.
360 '<td>'. $row['followups'] .'</td>'.
361 '<td>'.date(_('Y-m-d H:i'),$row['recent']).'</td></tr>';
365 $ret_val .= $GLOBALS['HTML']->listTableBottom();
371 This code puts the nice next/prev.
373 $ret_val .= '<table width="100%" border="0">
374 <tr class="tablecontent"><td width="50%">';
376 $ret_val .= '<span class="prev">
377 <a href="javascript:history.back()"><strong>' .
378 html_image('t2.png',"15","15") ._('Newer Messages').'</strong></a></span>';
380 $ret_val .= ' ';
383 $ret_val .= '</td><td> </td><td align="right" width="50%">';
385 if ($avail_rows > $max_rows) {
386 $ret_val .= '<span class="next">
387 <a href="'.util_make_url ('/forum/forum.php?max_rows='.$max_rows.'&style='.$style.'&offset='.($offset+$i).
388 '&forum_id='.$forum_id.'&group_id='.$group_id).'">
389 <strong> '._('Older Messages') .
390 html_image('t.png',"15","15") . '</strong></a></span>';
392 $ret_val .= ' ';
394 $ret_val .= '</td></tr></table>';
402 // Viewing an entire message forum in a given format
404 echo '<center><h3>'._('Start New Thread').'</h3></center>';
408 forum_footer(array());
412 exit_error(_('No forum chosen'),'forums');