3 // SourceForge: Breaking Down the Barriers to Open Source Development
4 // Copyright 1999-2000 (c) The SourceForge Crew
5 // http://sourceforge.net
11 Forum written 11/99 by Tim Perdue
12 Massive re-write 7/2000 by Tim Perdue (nesting/multiple views/etc)
14 Massive optimization 11/00 to eliminate recursive queries
19 require('../forum/forum_utils.php');
23 Set up global vars that are expected by some forum functions
25 $result=db_query("SELECT group_id,forum_name,is_public,allow_anonymous,send_all_posts_to ".
26 "FROM forum_group_list ".
27 "WHERE group_forum_id='$forum_id'");
28 if (!$result || db_numrows($result) < 1) {
29 exit_error('ERROR','Forum not found '.db_error());
31 $group_id=db_result($result,0,'group_id');
32 $forum_name=db_result($result,0,'forum_name');
33 $allow_anonymous=db_result($result,0,'allow_anonymous');
34 $send_all_posts_to=db_result($result,0,'send_all_posts_to');
37 if (!db_result($result,0,'is_public')) {
38 if (!user_isloggedin() || !user_ismember($group_id)) {
40 If this is a private forum, kick 'em out
42 exit_error('ERROR','Forum is restricted to members of this group');
48 if necessary, insert a new message into the forum
51 if (!post_message($thread_id, $is_followup_to, $subject, $body, $forum_id)) {
52 exit_error('ERROR',$feedback);
54 $feedback='Message Posted Successfully';
61 set up some defaults if they aren't provided
63 if ((!$offset) || ($offset < 0)) {
69 if (!$style || ($style != 'ultimate' && $style != 'flat' && $style != 'nested' && $style != 'threaded')) {
73 if (!$max_rows || $max_rows < 5) {
78 take care of setting up/saving prefs
80 If they're logged in and a "custom set" was NOT just POSTed,
81 see if they have a pref set
83 if it was a custom set just posted && logged in, set pref if it's changed
85 if (!$thread_id && user_isloggedin()) {
86 $_pref=$style.'|'.$max_rows;
88 //echo "<P>checking pref";
89 if (user_get_preference('forum_style')) {
90 //echo "<P>pref exists";
91 if ($_pref == user_get_preference('forum_style')) {
92 //echo "<P>pref same: $_pref";
93 //do nothing - pref already stored
95 //echo "<P>setting pref: $_pref";
97 user_set_preference ('forum_style',$_pref);
100 //echo "<P>setting pref";
102 user_set_preference ('forum_style',$_pref);
105 if (user_get_preference('forum_style')) {
106 $_pref_arr=explode ('|',user_get_preference('forum_style'));
107 $style=$_pref_arr[0];
108 $max_rows=$_pref_arr[1];
110 //no saved pref and we're not setting
111 //one because this is all default settings
115 if (!$style || ($style != 'ultimate' && $style != 'flat' && $style != 'nested' && $style != 'threaded')) {
120 //echo "<P>style: $style";
121 forum_header(array('title'=>$forum_name));
125 * Forum styles include Nested, threaded, flat, ultimate
127 * threaded indents and shows subjects/authors of all messages/followups
128 * nested indents and shows the entirety of all messages/followups
129 * flat shows entiretly of messages in date order descending
130 * ultimate is based roughly on "Ultimate BB"
135 // Don't show the forum view prefs in thread mode
138 //create a pop-up select box listing the forums for this project
139 //determine if this person can see private forums or not
140 if (user_isloggedin() && user_ismember($group_id)) {
145 if ($group_id==$GLOBALS['sys_news_group']) {
146 echo '<INPUT TYPE="HIDDEN" NAME="forum_id" VALUE="'.$forum_id.'">';
148 $res=db_query("SELECT group_forum_id,forum_name ".
149 "FROM forum_group_list ".
150 "WHERE group_id='$group_id' AND is_public IN ($public_flag)");
151 $vals=util_result_column_to_array($res,0);
152 $texts=util_result_column_to_array($res,1);
154 $forum_popup = html_build_select_box_from_arrays ($vals,$texts,'forum_id',$forum_id,false);
156 //create a pop-up select box showing options for viewing threads
158 $vals=array('nested','flat','threaded','ultimate');
159 $texts=array('Nested','Flat','Threaded','Ultimate');
161 $options_popup=html_build_select_box_from_arrays ($vals,$texts,'style',$style,false);
163 //create a pop-up select box showing options for max_row count
164 $vals=array(25,50,75,100);
165 $texts=array('Show 25','Show 50','Show 75','Show 100');
167 $max_row_popup=html_build_select_box_from_arrays ($vals,$texts,'max_rows',$max_rows,false);
169 //now show the popup boxes in a form
171 <TABLE BORDER="0" WIDTH="50%">
172 <FORM ACTION="'. $PHP_SELF .'" METHOD="POST">
173 <INPUT TYPE="HIDDEN" NAME="set" VALUE="custom">
174 <TR><TD><FONT SIZE="-1">'. $forum_popup .
175 '</TD><TD><FONT SIZE="-1">'. $options_popup .
176 '</TD><TD><FONT SIZE="-1">'. $max_row_popup .
177 '</TD><TD><FONT SIZE="-1"><INPUT TYPE="SUBMIT" NAME="SUBMIT" VALUE="Change View">
182 if ($style=='nested') {
184 // if viewing a particular thread, add some limiting SQL
187 $thread_sql=" AND forum.thread_id='$thread_id' ";
190 $sql="SELECT users.user_name,users.realname,forum.has_followups, ".
191 "users.user_id,forum.msg_id,forum.subject,forum.thread_id, ".
192 "forum.body,forum.date,forum.is_followup_to,forum.most_recent_date,forum.group_forum_id ".
194 "WHERE forum.group_forum_id='$forum_id' ".
196 "AND users.user_id=forum.posted_by ".
197 "ORDER BY forum.most_recent_date DESC";
199 $result=db_query($sql,($max_rows+25),$offset);
200 while ($row=db_fetch_array($result)) {
201 $msg_arr["$row[is_followup_to]"][]=$row;
204 $rows=count($msg_arr[0]);
205 if ($rows > $max_rows) {
209 while (($i < $rows) && ($total_rows < $max_rows)) {
210 $thread=$msg_arr["0"][$i];
214 New slashdot-inspired nested threads,
215 showing all submessages and bodies
217 $ret_val .= forum_show_a_nested_message ( $thread ).'<BR>';
219 if ($thread['has_followups'] > 0) {
220 //show submessages for this message
221 $ret_val .= forum_show_nested_messages ( $msg_arr, $thread['msg_id'] );
226 } else if ($style=='threaded') {
228 $sql="SELECT users.user_name,users.realname,forum.has_followups, ".
229 "users.user_id,forum.msg_id,forum.subject,forum.thread_id, ".
230 "forum.body,forum.date,forum.is_followup_to,forum.most_recent_date,forum.group_forum_id ".
232 "WHERE forum.group_forum_id='$forum_id' AND users.user_id=forum.posted_by ".
233 "ORDER BY forum.most_recent_date DESC";
235 $result=db_query($sql,($max_rows+25),$offset);
236 while ($row=db_fetch_array($result)) {
237 $msg_arr["$row[is_followup_to]"][]=$row;
241 $title_arr[]='Thread';
242 $title_arr[]='Author';
245 $ret_val .= html_build_list_table_top ($title_arr);
247 $rows=count($msg_arr[0]);
249 if ($rows > $max_rows) {
253 while (($i < $rows) && ($total_rows < $max_rows)) {
254 $thread=$msg_arr["0"][$i];
257 $ret_val .= '<TR BGCOLOR="'. html_get_alt_row_color($total_rows) .'"><TD><A HREF="/forum/message.php?msg_id='.
258 $thread['msg_id'].'">'.
259 html_image("images/msg.gif","12","10",array("BORDER"=>"0"));
261 See if this message is new or not
262 If so, highlite it in bold
264 if (get_forum_saved_date($forum_id) < $thread['date']) {
268 show the subject and poster
270 $ret_val .= $thread['subject'] .'</A></TD>'.
271 '<TD>'. $thread['user_name'] .'</TD>'.
272 '<TD>'.date($sys_datefmt,$thread['date']).'</TD></TR>';
276 Show subjects for submessages in this thread
278 show_submessages() is recursive
281 if ($thread['has_followups'] > 0) {
282 $ret_val .= show_submessages($msg_arr,$thread['msg_id'],1);
287 $ret_val .= '</TABLE>';
289 } else if ($style=='flat') {
291 $sql="SELECT users.user_name,users.realname,forum.has_followups, ".
292 "users.user_id,forum.msg_id,forum.subject,forum.thread_id, ".
293 "forum.body,forum.date,forum.is_followup_to,forum.group_forum_id ".
295 "WHERE forum.group_forum_id='$forum_id' AND users.user_id=forum.posted_by ".
296 "ORDER BY forum.msg_id DESC";
298 $result=db_query($sql,($max_rows+1),$offset);
300 while (($row=db_fetch_array($result)) && ($i < $max_rows)) {
301 $ret_val .= forum_show_a_nested_message ( $row ).'<BR>';
308 This is the view that is most similar to the "Ultimate BB view"
311 $sql="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.date) AS recent ".
313 "FROM forum f, forum f2, users ".
314 "WHERE f.group_forum_id='$forum_id' ".
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";
321 $result=db_query($sql,($max_rows+1),$offset);
323 //echo "In Ultimate View";
325 $title_arr[]='Topic';
326 $title_arr[]='Topic Starter';
327 $title_arr[]='Replies';
328 $title_arr[]='Last Post';
330 $ret_val .= html_build_list_table_top ($title_arr);
332 while (($row=db_fetch_array($result)) && ($i < $max_rows)) {
334 <TR BGCOLOR="'. html_get_alt_row_color($i) .'"><TD><A HREF="/forum/forum.php?thread_id='.
335 $row['thread_id'].'&forum_id='.$forum_id.'">'.
336 html_image("images/ic/cfolder15.png","15","13",array("border"=>"0")) . ' ';
338 See if this message is new or not
339 If so, highlite it in bold
341 if (get_forum_saved_date($forum_id) < $row['recent']) {
345 show the subject and poster
347 $ret_val .= $row['subject'] .'</A></TD>'.
348 '<TD>'. $row['user_name'] .'</TD>'.
349 '<TD>'. $row['followups'] .'</TD>'.
350 '<TD>'.date($sys_datefmt,$row['recent']).'</TD></TR>';
354 $ret_val .= '</TABLE>';
359 This code puts the nice next/prev.
361 $ret_val .= '<TABLE WIDTH="100%" BORDER="0">
362 <TR BGCOLOR="#EEEEEE"><TD WIDTH="50%">';
364 $ret_val .= '<FONT face="Arial, Helvetica" SIZE="3" STYLE="text-decoration: none"><B>
365 <A HREF="javascript:history.back()"><B>' .
366 html_image("images/t2.gif","15","15",array("BORDER"=>"0","ALIGN"=>"MIDDLE")) . ' Previous Messages</A></B></FONT>';
368 $ret_val .= ' ';
371 $ret_val .= '</TD><TD> </TD><TD ALIGN="RIGHT" WIDTH="50%">';
373 if (db_numrows($result) > $max_rows) {
374 $ret_val .= '<FONT face="Arial, Helvetica" SIZE=3 STYLE="text-decoration: none"><B>
375 <A HREF="/forum/forum.php?max_rows='.$max_rows.'&style='.$style.'&offset='.($offset+$i).'&forum_id='.$forum_id.'">
377 html_image("images/t.gif","15","15",array("BORDER"=>"0","ALIGN"=>"MIDDLE")) . '</A>';
379 $ret_val .= ' ';
382 $ret_val .= '</TABLE>';
390 // Viewing a particular thread in nested view
392 echo '<CENTER><h3>Post A Message To This Thread:</H3></CENTER>';
393 show_post_form($forum_id,$thread_id,$msg_arr["0"][0]['msg_id'],$msg_arr["0"][0]['subject']);
396 // Viewing an entire message forum in a given format
398 echo '<CENTER><h3>Start a New Thread:</H3></CENTER>';
399 show_post_form($forum_id);
402 forum_footer(array());
406 exit_error('ERROR','No Forum Chosen');