3 * GForge Forums Facility
5 * Copyright 2002 GForge, LLC
14 By Tim Perdue, Sourceforge, 11/99
16 Massive rewrite by Tim Perdue 7/2000 (nested/views/save)
18 Complete OO rewrite by Tim Perdue 12/2002
21 require_once('../env.inc.php');
22 require_once('pre.php');
23 require_once('www/forum/include/ForumHTML.class');
24 require_once('common/forum/Forum.class');
25 require_once('common/forum/ForumFactory.class');
26 require_once('common/forum/ForumMessageFactory.class');
27 require_once('common/forum/ForumMessage.class');
28 require_once('www/forum/include/AttachManager.class'); //attachent manager
29 require_once('common/include/TextSanitizer.class'); // to make the HTML input by the user safe to store
31 $forum_id = getIntFromRequest('forum_id');
32 $style = getStringFromRequest('style');
33 $thread_id = getIntFromRequest('thread_id');
34 $offset = getIntFromRequest('offset');
35 $max_rows = getIntFromRequest('max_rows');
36 $set = getStringFromRequest('set');
41 Get the group_id based on this forum_id
43 $result=db_query("SELECT group_id
45 WHERE group_forum_id='$forum_id'");
46 if (!$result || db_numrows($result) < 1) {
47 exit_error(_('Error'),_('Error').' '.db_error());
49 $group_id=db_result($result,0,'group_id');
52 // Set up local objects
54 $g =& group_get_object($group_id);
55 if (!$g || !is_object($g) || $g->isError()) {
59 $f=new Forum($g,$forum_id);
60 if (!$f || !is_object($f)) {
61 exit_error(_('Error'),"Error getting new Forum");
62 } elseif ($f->isError()) {
63 exit_error(_('Error'),$f->getErrorMessage());
67 if necessary, insert a new message into the forum
69 if (getStringFromRequest('post_message')) {
70 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
71 exit_form_double_submit();
73 $subject = getStringFromRequest('subject');
74 $body = getStringFromRequest('body');
75 $is_followup_to = getStringFromRequest('is_followup_to');
77 $fm=new ForumMessage($f);
78 if (!$fm || !is_object($fm)) {
79 form_release_key(getStringFromRequest("form_key"));
80 exit_error(_('Error'), "Error getting new ForumMessage");
81 } elseif ($fm->isError()) {
82 form_release_key(getStringFromRequest("form_key"));
83 exit_error(_('Error'),"Error getting new ForumMessage: ".$fm->getErrorMessage());
86 $sanitizer = new TextSanitizer();
87 $body = $sanitizer->SanitizeHtml($body);
89 $attach = getUploadedFile("attachment1");
90 if ($attach['size']) {
96 if (!$fm->create($subject, $body, $thread_id, $is_followup_to,$has_attach) || $fm->isError()) {
97 form_release_key(getStringFromRequest("form_key"));
98 exit_error(_('Error'),'Error creating ForumMessage: '.$fm->getErrorMessage());
100 if ($fm->isPending() ) {
101 $feedback=_('Message Queued for moderation -> Please wait until the admin approves/rejects it');
103 $feedback=_('Message Posted Successfully');
105 $am = NEW AttachManager();//object that will handle and insert the attachment into the db
106 $am->SetForumMsg($fm);
107 $am->attach($attach,$group_id,0,$fm->getID());
108 foreach ($am->Getmessages() as $item) {
109 $feedback .= "<br>" . $item;
113 if (getStringFromRequest('monitor')) {
120 $fmf = new ForumMessageFactory($f);
121 if (!$fmf || !is_object($fmf)) {
122 form_release_key(getStringFromRequest("form_key"));
123 exit_error(_('Error'), "Error getting new ForumMessageFactory");
124 } elseif ($fmf->isError()) {
125 form_release_key(getStringFromRequest("form_key"));
126 exit_error(_('Error'),$fmf->getErrorMessage());
129 //echo "<br /> style: $style|max_rows: $max_rows|offset: $offset+";
130 $fmf->setUp($offset,$style,$max_rows,$set);
132 $style=$fmf->getStyle();
133 $max_rows=$fmf->max_rows;
134 $offset=$fmf->offset;
136 //echo "<br /> style: $style|max_rows: $max_rows|offset: $offset+";
138 $fh = new ForumHTML($f);
139 if (!$fh || !is_object($fh)) {
140 exit_error(_('Error'), "Error getting new ForumHTML");
141 } elseif ($fh->isError()) {
142 exit_error(_('Error'),$fh->getErrorMessage());
145 forum_header(array('title'=>$f->getName(),'forum_id'=>$forum_id));
149 * Forum styles include Nested, threaded, flat, ultimate
151 * threaded indents and shows subjects/authors of all messages/followups
152 * nested indents and shows the entirety of all messages/followups
153 * flat shows entiretly of messages in date order descending
154 * ultimate is based roughly on "Ultimate BB"
158 //create a pop-up select box listing the forums for this project
159 //determine if this person can see private forums or not
160 if (session_loggedin() && user_ismember($group_id)) {
166 //create a pop-up select box showing options for viewing threads
168 $vals=array('nested','flat','threaded','ultimate');
169 $texts=array(_('Nested'), _('Nested'), _('Nested'), _('Nested'));
171 $options_popup=html_build_select_box_from_arrays ($vals,$texts,'style',$style,false);
173 //create a pop-up select box showing options for max_row count
174 $vals=array(25,50,75,100);
175 $texts=array(_('Show').' 25',_('Show').' 50',_('Show').' 75',_('Show').' 100');
177 $max_row_popup=html_build_select_box_from_arrays ($vals,$texts,'max_rows',$max_rows,false);
179 //now show the popup boxes in a form
181 <form action="'. getStringFromServer('PHP_SELF') .'" method="get">
182 <input type="hidden" name="set" value="custom" />
183 <input type="hidden" name="forum_id" value="'.$forum_id.'" />
184 <table border="0" width="33%">
185 <tr><td>'. $options_popup .
186 '</td><td>'. $max_row_popup .
187 '</td><td><input type="submit" name="submit" value="'.
188 _('Change View').'" />
192 $am = new AttachManager();
193 $ret_val .= $am->PrintHelperFunctions();
194 if ($style=='nested') {
196 $msg_arr =& $fmf->nestArray($fmf->getNested());
198 if ($fmf->isError()) {
199 echo $fmf->getErrorMessage();
202 $rows=count($msg_arr["0"]);
203 $avail_rows=$fmf->fetched_rows;
204 if ($rows > $max_rows) {
209 while (($i < $rows) && ($total_rows < $max_rows)) {
213 New slashdot-inspired nested threads,
214 showing all submessages and bodies
216 $ret_val .= $fh->showNestedMessage ( $msg_arr["0"][$i] ).'<br />';
218 if ( $msg_arr["0"][$i]->hasFollowups() ) {
219 //show submessages for this message
220 $tempid=$msg_arr["0"][$i]->getID();
221 // echo "<p>before showNestedMessages() $tempid | ". count( $msg_arr["$tempid"] );
222 $ret_val .= $fh->showNestedMessages ( $msg_arr, $tempid );
227 } else if ($style=='threaded') {
229 $msg_arr =& $fmf->nestArray($fmf->getThreaded());
230 if ($fmf->isError()) {
231 echo $fmf->getErrorMessage();
235 $title_arr[]=_('Thread');
236 $title_arr[]=_('Author');
237 $title_arr[]=_('Date');
239 $ret_val .= $GLOBALS['HTML']->listTableTop ($title_arr);
241 $rows=count($msg_arr[0]);
242 $avail_rows=$fmf->fetched_rows;
243 if ($rows > $max_rows) {
247 while (($i < $rows) && ($total_rows < $max_rows)) {
248 $msg =& $msg_arr["0"][$i];
251 $ret_val .= '<tr '. $GLOBALS['HTML']->boxGetAltRowStyle($total_rows) .'>
252 <td><a href="'.$GLOBALS['sys_urlprefix'].'/forum/message.php?msg_id='.$msg->getID().
253 '&group_id='.$group_id.'">'.
254 html_image('ic/msg.png',"10","12",array("border"=>"0"));
256 See if this message is new or not
257 If so, highlite it in bold
259 if ($f->getSavedDate() < $msg->getPostDate()) {
260 $bold_begin='<strong>';
261 $bold_end='</strong>';
267 show the subject and poster
269 $ret_val .= $bold_begin.$msg->getSubject() .$bold_end.'</a></td>'.
270 '<td>'. $msg->getPosterRealName() .'</td>'.
271 '<td>'. date($sys_datefmt,$msg->getPostDate()) .'</td></tr>';
273 if ($msg->hasFollowups()) {
274 $ret_val .= $fh->showSubmessages($msg_arr,$msg->getID(),1);
279 $ret_val .= $GLOBALS['HTML']->listTableBottom();
281 } else if (($style=='flat' && $thread_id) || ($style=='ultimate' && $thread_id)) {
283 $msg_arr =& $fmf->getFlat($thread_id);
284 if ($fmf->isError()) {
285 echo $fmf->getErrorMessage();
287 $avail_rows=$fmf->fetched_rows;
289 for ($i=0; ($i<count($msg_arr) && ($i < $max_rows)); $i++) {
290 $ret_val .= $fh->showNestedMessage ( $msg_arr[$i] ).'<br />';
295 This is the view that is most similar to the "Ultimate BB view"
298 $sql="SELECT f.most_recent_date,users.user_name,users.realname,users.user_id,f.msg_id,f.subject,f.thread_id,".
299 "(count(f2.thread_id)-1) AS followups,max(f2.post_date) AS recent ".
300 "FROM forum f, forum f2, users ".
301 "WHERE f.group_forum_id='$forum_id' ".
302 "AND f.is_followup_to=0 ".
303 "AND users.user_id=f.posted_by ".
304 "AND f.thread_id=f2.thread_id ".
305 "GROUP BY f.most_recent_date,users.user_name,users.realname,users.user_id,f.msg_id,f.subject,f.thread_id ".
306 "ORDER BY f.most_recent_date DESC";
308 $result=db_query($sql,($max_rows+1),$offset);
310 $avail_rows=db_numrows($result);
315 $title_arr[]=_('Topic');
316 $title_arr[]=_('Topic Starter');
317 $title_arr[]=_('Replies');
318 $title_arr[]=_('Last Post');
320 $ret_val .= $GLOBALS['HTML']->listTableTop ($title_arr);
322 while (($row=db_fetch_array($result)) && ($i < $max_rows)) {
324 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'><td><a href="'.$GLOBALS['sys_urlprefix'].'/forum/forum.php?thread_id='.
325 $row['thread_id'].'&forum_id='.$forum_id.'&group_id='.$group_id.'">'.
326 html_image('ic/cfolder15.png',"15","13",array("border"=>"0")) . ' ';
328 See if this message is new or not
329 If so, highlite it in bold
331 if ($f->getSavedDate() < $row['recent']) {
332 $bold_begin='<strong>';
333 $bold_end='</strong>';
339 show the subject and poster
341 $ret_val .= $bold_begin.$row['subject'] .$bold_end.'</a></td>'.
342 '<td>'. $row['realname'] .'</td>'.
343 '<td>'. $row['followups'] .'</td>'.
344 '<td>'.date($sys_datefmt,$row['recent']).'</td></tr>';
348 $ret_val .= $GLOBALS['HTML']->listTableBottom();
353 This code puts the nice next/prev.
355 $ret_val .= '<table width="100%" border="0">
356 <tr class="tablecontent"><td width="50%">';
358 $ret_val .= '<span class="prev">
359 <a href="javascript:history.back()"><strong>' .
360 html_image('t2.png',"15","15",array("border"=>"0","ALIGN"=>"MIDDLE")) ._('Previous Messages').'</a></strong></span>';
362 $ret_val .= ' ';
365 $ret_val .= '</td><td> </td><td align="right" width="50%">';
367 if ($avail_rows > $max_rows) {
368 $ret_val .= '<span class="next">
369 <a href="'.$GLOBALS['sys_urlprefix'].'/forum/forum.php?max_rows='.$max_rows.'&style='.$style.'&offset='.($offset+$i).
370 '&forum_id='.$forum_id.'&group_id='.$group_id.'">
371 <strong> '._('Next Messages') .
372 html_image('t.png',"15","15",array("border"=>"0","ALIGN"=>"MIDDLE")) . '</strong></a>';
374 $ret_val .= ' ';
377 $ret_val .= '</td></tr></table>';
385 // Viewing an entire message forum in a given format
387 echo '<CENTER><h3>'._('Start New Thread').'</h3></CENTER>';
391 forum_footer(array());
395 exit_error(_('Error'),_('Error'));