3 * GForge Forums Facility
5 * Copyright 2002 GForge, LLC
13 By Tim Perdue, Sourceforge, 11/99
15 Massive rewrite by Tim Perdue 7/2000 (nested/views/save)
17 Complete OO rewrite by Tim Perdue 12/2002
20 require_once('../env.inc.php');
21 require_once $gfwww.'include/pre.php';
22 require_once $gfwww.'forum/include/ForumHTML.class.php';
23 require_once $gfcommon.'forum/Forum.class.php';
24 require_once $gfcommon.'forum/ForumFactory.class.php';
25 require_once $gfcommon.'forum/ForumMessageFactory.class.php';
26 require_once $gfcommon.'forum/ForumMessage.class.php';
27 require_once $gfwww.'forum/include/AttachManager.class.php'; //attachent manager
28 require_once $gfcommon.'include/TextSanitizer.class.php'; // to make the HTML input by the user safe to store
30 $forum_id = getIntFromRequest('forum_id');
31 $style = getStringFromRequest('style');
32 $thread_id = getIntFromRequest('thread_id');
33 $offset = getIntFromRequest('offset');
34 $max_rows = getIntFromRequest('max_rows');
35 $set = getStringFromRequest('set');
36 $feedback = htmlspecialchars(getStringFromRequest('feedback'));
41 Get the group_id based on this forum_id
43 $result=db_query_params ('SELECT group_id
45 WHERE group_forum_id=$1',
47 if (!$result || db_numrows($result) < 1) {
48 exit_error(_('Error'),_('Error forum not found ').' '.db_error());
50 $group_id=db_result($result,0,'group_id');
53 // Set up local objects
55 $g =& group_get_object($group_id);
56 if (!$g || !is_object($g) || $g->isError()) {
60 $f=new Forum($g,$forum_id);
61 if (!$f || !is_object($f)) {
62 exit_error(_('Error'),_('Error getting new Forum'));
63 } elseif ($f->isError()) {
64 exit_error(_('Error'),$f->getErrorMessage());
68 if necessary, insert a new message into the forum
70 if (getStringFromRequest('post_message')) {
71 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
72 exit_form_double_submit();
74 $subject = getStringFromRequest('subject');
75 $body = getStringFromRequest('body');
76 $is_followup_to = getStringFromRequest('is_followup_to');
78 $fm=new ForumMessage($f);
79 if (!$fm || !is_object($fm)) {
80 form_release_key(getStringFromRequest("form_key"));
81 exit_error(_('Error'), _('Error getting new ForumMessage'));
82 } elseif ($fm->isError()) {
83 form_release_key(getStringFromRequest("form_key"));
84 exit_error(_('Error'),_('Error getting new ForumMessage: '.$fm->getErrorMessage()));
87 $sanitizer = new TextSanitizer();
88 $body = $sanitizer->SanitizeHtml($body);
90 $attach = getUploadedFile("attachment1");
91 if ($attach['size']) {
97 if (!$fm->create($subject, $body, $thread_id, $is_followup_to,$has_attach) || $fm->isError()) {
98 form_release_key(getStringFromRequest("form_key"));
99 exit_error(_('Error'),_('Error creating ForumMessage: ').$fm->getErrorMessage());
101 if ($fm->isPending() ) {
102 $feedback=_('Message Queued for moderation -> Please wait until the admin approves/rejects it');
104 $feedback=_('Message Posted Successfully');
106 $am = NEW AttachManager();//object that will handle and insert the attachment into the db
107 $am->SetForumMsg($fm);
108 $am->attach($attach,$group_id,0,$fm->getID());
109 foreach ($am->Getmessages() as $item) {
110 $feedback .= "<br />" . $item;
114 if (getStringFromRequest('monitor')) {
121 $fmf = new ForumMessageFactory($f);
122 if (!$fmf || !is_object($fmf)) {
123 form_release_key(getStringFromRequest("form_key"));
124 exit_error(_('Error'),_('Error getting new ForumMessageFactory'));
125 } elseif ($fmf->isError()) {
126 form_release_key(getStringFromRequest("form_key"));
127 exit_error(_('Error'),$fmf->getErrorMessage());
130 //echo "<br /> style: $style|max_rows: $max_rows|offset: $offset+";
131 $fmf->setUp($offset,$style,$max_rows,$set);
133 $style=$fmf->getStyle();
134 $max_rows=$fmf->max_rows;
135 $offset=$fmf->offset;
137 //echo "<br /> style: $style|max_rows: $max_rows|offset: $offset+";
139 $fh = new ForumHTML($f);
140 if (!$fh || !is_object($fh)) {
141 exit_error(_('Error'),_('Error getting new ForumHTML'));
142 } elseif ($fh->isError()) {
143 exit_error(_('Error'),$fh->getErrorMessage());
146 forum_header(array('title'=>$f->getName(),'forum_id'=>$forum_id));
150 * Forum styles include Nested, threaded, flat, ultimate
152 * threaded indents and shows subjects/authors of all messages/followups
153 * nested indents and shows the entirety of all messages/followups
154 * flat shows entiretly of messages in date order descending
155 * ultimate is based roughly on "Ultimate BB"
159 //create a pop-up select box listing the forums for this project
160 //determine if this person can see private forums or not
161 if (session_loggedin() && user_ismember($group_id)) {
167 //create a pop-up select box showing options for viewing threads
169 $vals=array('nested','flat','threaded','ultimate');
170 $texts=array(_('Nested'), _('Flat'), _('Threaded'), _('Ultimate'));
172 $options_popup=html_build_select_box_from_arrays ($vals,$texts,'style',$style,false);
174 //create a pop-up select box showing options for max_row count
175 $vals=array(25,50,75,100);
176 $texts=array(_('Show').' 25',_('Show').' 50',_('Show').' 75',_('Show').' 100');
178 $max_row_popup=html_build_select_box_from_arrays ($vals,$texts,'max_rows',$max_rows,false);
180 //now show the popup boxes in a form
182 <form action="'. getStringFromServer('PHP_SELF') .'" method="get">
183 <input type="hidden" name="set" value="custom" />
184 <input type="hidden" name="forum_id" value="'.$forum_id.'" />
185 <table border="0" width="33%">
186 <tr><td>'. $options_popup .
187 '</td><td>'. $max_row_popup .
188 '</td><td><input type="submit" name="submit" value="'.
189 _('Change View').'" />
193 $am = new AttachManager();
194 $ret_val .= $am->PrintHelperFunctions();
195 if ($style=='nested') {
197 $msg_arr =& $fmf->nestArray($fmf->getNested());
199 if ($fmf->isError()) {
200 echo $fmf->getErrorMessage();
203 $rows=count($msg_arr["0"]);
204 $avail_rows=$fmf->fetched_rows;
205 if ($rows > $max_rows) {
210 while (($i < $rows) && ($total_rows < $max_rows)) {
214 New slashdot-inspired nested threads,
215 showing all submessages and bodies
217 $ret_val .= $fh->showNestedMessage ( $msg_arr["0"][$i] ).'<br />';
219 if ( $msg_arr["0"][$i]->hasFollowups() ) {
220 //show submessages for this message
221 $tempid=$msg_arr["0"][$i]->getID();
222 // echo "<p>before showNestedMessages() $tempid | ". count( $msg_arr["$tempid"] );
223 $ret_val .= $fh->showNestedMessages ( $msg_arr, $tempid );
228 } else if ($style=='threaded') {
230 $msg_arr =& $fmf->nestArray($fmf->getThreaded());
231 if ($fmf->isError()) {
232 echo $fmf->getErrorMessage();
236 $title_arr[]=_('Thread');
237 $title_arr[]=_('Author');
238 $title_arr[]=_('Date');
240 $ret_val .= $GLOBALS['HTML']->listTableTop ($title_arr);
242 $rows=count($msg_arr[0]);
243 $avail_rows=$fmf->fetched_rows;
244 if ($rows > $max_rows) {
248 while (($i < $rows) && ($total_rows < $max_rows)) {
249 $msg =& $msg_arr["0"][$i];
252 $ret_val .= '<tr '. $GLOBALS['HTML']->boxGetAltRowStyle($total_rows) .'>
253 <td><a href="'.util_make_url ('/forum/message.php?msg_id='.$msg->getID().
254 '&group_id='.$group_id).'&reply=0">'.
255 html_image('ic/msg.png',"10","12",array("border"=>"0")).' ';
257 See if this message is new or not
258 If so, highlite it in bold
260 if ($f->getSavedDate() < $msg->getPostDate()) {
261 $bold_begin='<strong>';
262 $bold_end='</strong>';
268 show the subject and poster
270 $ret_val .= $bold_begin.$msg->getSubject() .$bold_end.'</a></td>'.
271 '<td><a href="/users/'.$msg->getPosterName().'/">'.$msg->getPosterRealName().'</a></td>'.
272 '<td>'. date(_('Y-m-d H:i'),$msg->getPostDate()) .'</td></tr>';
274 if ($msg->hasFollowups()) {
275 $ret_val .= $fh->showSubmessages($msg_arr,$msg->getID(),1);
280 $ret_val .= $GLOBALS['HTML']->listTableBottom();
282 } else if (($style=='flat' && $thread_id) || ($style=='ultimate' && $thread_id)) {
284 $msg_arr =& $fmf->getFlat($thread_id);
285 if ($fmf->isError()) {
286 echo $fmf->getErrorMessage();
288 $avail_rows=$fmf->fetched_rows;
290 for ($i=0; ($i<count($msg_arr) && ($i < $max_rows)); $i++) {
291 $ret_val .= $fh->showNestedMessage ( $msg_arr[$i] ).'<br />';
296 This is the view that is most similar to the "Ultimate BB view"
299 $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,
300 (count(f2.thread_id)-1) AS followups,max(f2.post_date) AS recent
301 FROM forum f, forum f2, users
302 WHERE f.group_forum_id=$1
303 AND f.is_followup_to=0
304 AND users.user_id=f.posted_by
305 AND f.thread_id=f2.thread_id
306 GROUP BY f.most_recent_date,users.user_name,users.realname,users.user_id,f.msg_id,f.subject,f.thread_id
307 ORDER BY f.most_recent_date DESC',
312 $avail_rows=db_numrows($result);
316 if ($avail_rows > 0) {
318 $title_arr[]=_('Topic');
319 $title_arr[]=_('Topic Starter');
320 $title_arr[]=_('Replies');
321 $title_arr[]=_('Last Post');
323 $ret_val .= $GLOBALS['HTML']->listTableTop ($title_arr);
325 while (($row=db_fetch_array($result)) && ($i < $max_rows)) {
327 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'><td><a href="'.util_make_url ('/forum/forum.php?thread_id='.
328 $row['thread_id'].'&forum_id='.$forum_id.'&group_id='.$group_id).'">'.
329 html_image('ic/cfolder15.png',"15","13",array("border"=>"0")) . ' ';
331 See if this message is new or not
332 If so, highlite it in bold
334 if ($f->getSavedDate() < $row['recent']) {
335 $bold_begin='<strong>';
336 $bold_end='</strong>';
342 show the subject and poster
344 $ret_val .= $bold_begin.$row['subject'] .$bold_end.'</a></td>'.
345 '<td><a href="/users/'.$row['user_name'].'/">'.$row['realname'].'</a></td>'.
346 '<td>'. $row['followups'] .'</td>'.
347 '<td>'.date(_('Y-m-d H:i'),$row['recent']).'</td></tr>';
351 $ret_val .= $GLOBALS['HTML']->listTableBottom();
357 This code puts the nice next/prev.
359 $ret_val .= '<table width="100%" border="0">
360 <tr class="tablecontent"><td width="50%">';
362 $ret_val .= '<span class="prev">
363 <a href="javascript:history.back()"><strong>' .
364 html_image('t2.png',"15","15",array("border"=>"0","align"=>"middle")) ._('Previous Messages').'</strong></a></span>';
366 $ret_val .= ' ';
369 $ret_val .= '</td><td> </td><td align="right" width="50%">';
371 if ($avail_rows > $max_rows) {
372 $ret_val .= '<span class="next">
373 <a href="'.util_make_url ('/forum/forum.php?max_rows='.$max_rows.'&style='.$style.'&offset='.($offset+$i).
374 '&forum_id='.$forum_id.'&group_id='.$group_id).'">
375 <strong> '._('Next Messages') .
376 html_image('t.png',"15","15",array("border"=>"0","align"=>"middle")) . '</strong></a></span>';
378 $ret_val .= ' ';
381 $ret_val .= '</td></tr></table>';
389 // Viewing an entire message forum in a given format
391 echo '<center><h3>'._('Start New Thread').'</h3></center>';
395 forum_footer(array());
399 exit_error(_('Error'),_('No forum chosen'));