Main Page | Directories | File List | File Members

include/news/forum.php File Reference

Go to the source code of this file.

Functions

 forum_show_a_nested_message ($result, $row=0)
 forum_show_nested_messages ($thread_id, $msg_id)
 forum_header ($params)
 forum_footer ($params)
 forum_create_forum ($group_id, $forum_name, $is_public=1, $create_default_message=1, $description='')
 get_forum_name ($id)
 show_thread ($thread_id, $et=0)
 show_submessages ($thread_id, $msg_id, $level, $et=0)
 get_next_thread_id ()
 get_forum_saved_date ($forum_id)
 post_message ($thread_id, $is_followup_to, $subject, $body, $group_forum_id)


Function Documentation

forum_create_forum group_id,
forum_name,
is_public = 1,
create_default_message = 1,
description = ''
 

Definition at line 218 of file include/news/forum.php.

References $feedback, $forum_id, $result, $result2, $sql, db_insertid(), db_query(), and get_next_thread_id().

00219 {
00220         global $feedback;
00221         /*
00222                 Adding forums to this group
00223         */
00224         $sql="INSERT INTO forum_group_list (group_id,forum_name,is_public,description) ".
00225                 "VALUES ('$group_id','". htmlspecialchars($forum_name) ."','$is_public','". htmlspecialchars($description) ."')";
00226 
00227         $result=db_query($sql);
00228         if (!$result)
00229         {
00230             " Error Adding Forum ";
00231         }
00232         else
00233         {
00234             " Forum Added ";
00235         }
00236         $forum_id=db_insertid($result);
00237 
00238         if ($create_default_message)
00239         {
00240             #set up a cheap default message
00241             $result2=db_query("INSERT INTO forum ".
00242                               "(group_forum_id,posted_by,subject,body,date,is_followup_to,thread_id) ".
00243                               "VALUES ('$forum_id','100','Welcome to $forum_name',".
00244                               "'Welcome to $forum_name','".time()."','0','".get_next_thread_id()."')");
00245         }
00246         return $forum_id;
00247 }

forum_footer params  ) 
 

Definition at line 214 of file include/news/forum.php.

00214                               {
00215         site_project_footer($params);
00216 }

forum_header params  ) 
 

Definition at line 114 of file include/news/forum.php.

References $forum_id, $forum_name, $group_id, $HTML, $msg_id, $result, $sql, $thread_id, db_numrows(), db_query(), db_result, format_date(), group, group_id, news_show_latest(), print, s, site_project_header(), summary, and user_isloggedin().

00115 {
00116         global $DOCUMENT_ROOT,$HTML,$group_id,$forum_name,$thread_id,$msg_id,$forum_id,$REQUEST_URI,$sys_datefmt,$et,$et_cookie;
00117 
00118         $params['group']=$group_id;
00119         $params['toptab']='forum';
00120 
00121         # NEWS ADMIN
00122         #this is a news item for the whole system or a for a project,
00123         # not a regular forum: forum are deactivated in savannah
00124         if ($forum_id)
00125         {
00126             # Show this news item at the top of the page
00127             $sql="SELECT * FROM news_bytes WHERE forum_id='$forum_id'";
00128             $result=db_query($sql);
00129 
00130             # if the result is empty, this is not a news item, but a forum.
00131             if (!$result || db_numrows($result) < 1)
00132                 {
00133                     $is_news=0;
00134                     #print '<span class="error">'._("Error").' - '._("This news item was not found").'</span>';
00135                     #print "forum_name=$forum_name<br />";
00136                     site_project_header($params);
00137                     #site_project_header(array('group'=>$group_id,'context'=>'forum'));
00138 
00139                 }
00140             else
00141                 {
00142                     $is_news=1;
00143                     #backwards shim for all "generic news" that used to be submitted
00144                     #as of may, "generic news" is not permitted - only project-specific news
00145 
00146                     # FIXME: group_name is not set, it brokes the top menu.
00147 
00148                     $params['group']=db_result($result,0,'group_id');
00149 
00150                     $group_id = db_result($result,0,'group_id');
00151                     $params['toptab']='news';
00152                     site_project_header($params);
00153 
00154                     print '
00155 <div class="indexright">
00156 ';
00157                     print $HTML->box_top(_("Latest News"));
00158                     print news_show_latest(db_result($result,0,'group_id'),5, "false");
00159                     print $HTML->box_bottom();
00160                     print '</div>
00161 <div class="indexcenter">
00162 ';
00163 
00164                     print '<h3>'.html_anchor(db_result($result,0,'summary'), "content").'</h3>';
00165                     print '<p><em>'.sprintf(_("Item posted by %s on %s."),
00166                         utils_user_link(user_getname(db_result($result,0,'submitted_by')),
00167                         user_getrealname(db_result($result,0,'submitted_by'))),
00168                         format_date($sys_datefmt,db_result($result,0,'date')))
00169                         .'</em></p>';
00170                     print utils_rich_markup(db_result($result,0,'details'));
00171 
00172 # could this fix the bug #409 ?
00173                     $forum_name = db_result($result,0,'summary');
00174                     print '</div>
00175 ';
00176 
00177                 }
00178         }
00179 
00180 
00181         /*
00182                 Show horizontal forum links
00183         */
00184         if ($forum_id && $forum_name && $is_news)
00185         {
00186             print '<h3 class="clearr">'.html_anchor(_("Comments:"), "comments").'</h3>';
00187         }
00188         print '<P><strong>';
00189 
00190         if ($forum_id && user_isloggedin())
00191         {
00192             print '<a href="'.$GLOBALS['sys_home'].'forum/monitor.php?forum_id='.$forum_id.'">' .
00193                 #'<img src="'.$GLOBALS['sys_home'].'images/ic/check.png" alt="monitor" />
00194                 _("Monitor Forum (toggle)").'</a> | '.
00195                 '<a href="'.$GLOBALS['sys_home'].'forum/save.php?forum_id='.$forum_id.'">'.
00196                 #'<img src="'.$GLOBALS['sys_home'].'images/ic/save.png" alt="save" />
00197                 _("Save Place").'</a> | '.
00198                 '<A HREF="'.$GLOBALS['sys_home'].'forum/who_monitors.php?forum_id='.$forum_id.'?group_id='.$group_id.'">'.
00199                 'Who\'s monitoring</A> | '.
00200                 '<A HREF="'.$GLOBALS['sys_home'].'forum/forum.php?forum_id='.$forum_id.'">'.
00201                 'View Forum</A>';
00202         }
00203 
00204         /*  This functionality is depreated
00205     if (user_is_super_user()) alternatively: user_ismember($group_id, "F2")
00206       {
00207         print ' | <A HREF="'.$GLOBALS['sys_home'].'forum/admin/?group_id='.$group_id.'">Admin</A></strong>';
00208       }
00209         */
00210         print '</P>';
00211 }

forum_show_a_nested_message result,
row = 0
 

Definition at line 26 of file include/news/forum.php.

References db_query(), db_result, format_date(), and group_id.

Referenced by forum_show_nested_messages().

00027 {
00028         /*
00029 
00030         accepts a database result handle to display a single message
00031                 in the format appropriate for the nested messages
00032 
00033                 second param is which row in that result set to use
00034 
00035         */
00036         global $sys_datefmt;
00037 
00038         $g_id =  db_result($result,$row,'group_id');
00039 
00040         # if the forum is a piece of news then get the real group_id from the
00041         # news_byte table
00042         if ($g_id == $GLOBALS['sys_group_id'])
00043         {
00044             $f_id =  db_result($result,$row,'group_forum_id');
00045             $gr = db_query("SELECT group_id FROM news_bytes WHERE forum_id='$f_id'");
00046             $g_id = db_result($gr,0,'group_id');
00047         }
00048 
00049         $ret_val = '
00050                 <table border="0" width="100%">
00051                         <tr>
00052                                 <td class="boxitem">'.
00053                 '<strong>'.db_result($result, $row, 'subject').'</strong>'.
00054                 ' ('._("posted by").' <a href="'.$GLOBALS['sys_home'].'users/'.
00055                 db_result($result, $row, 'user_name') .'/">'.
00056                 db_result($result, $row, 'realname') .'</a>, '.
00057                 format_date($sys_datefmt,db_result($result,$row,'date')).')'.
00058                 '                           </td>
00059                         </tr><tr>
00060                                 <td>
00061                                         '. utils_rich_markup(db_result($result,$row,'body')) .
00062                 '                                   <p><a href="'.$GLOBALS['sys_home'].'forum/message.php?msg_id='.db_result($result, $row, 'msg_id') .'#followup">[ '._("Reply").' ]</a>'.
00063                 '                           </p></td>
00064                         </tr>
00065                 </table>';
00066         return $ret_val;
00067 }

forum_show_nested_messages thread_id,
msg_id
 

Definition at line 69 of file include/news/forum.php.

References $result, $rows, $sql, db_numrows(), db_query(), db_result, and forum_show_a_nested_message().

00069                                                           {
00070         global $total_rows,$sys_datefmt;
00071 
00072         $sql="SELECT user.user_name,forum.has_followups,user.realname,user.user_id,forum.msg_id,forum.group_forum_id,forum.subject,forum.thread_id,forum.body,forum.date,forum.is_followup_to, forum_group_list.group_id  ".
00073                 "FROM forum,user,forum_group_list WHERE forum.thread_id='$thread_id' AND user.user_id=forum.posted_by AND forum.is_followup_to='$msg_id'  AND forum_group_list.group_forum_id = forum.group_forum_id ".
00074                 "ORDER BY forum.date ASC;";
00075 
00076         $result=db_query($sql);
00077         $rows=db_numrows($result);
00078 
00079         $ret_val='';
00080 
00081         if ($result && $rows > 0)
00082         {
00083             $ret_val .= '
00084                         <UL>';
00085 
00086             /*
00087 
00088             iterate and show the messages in this result
00089 
00090                         for each message, recurse to show any submessages
00091 
00092             */
00093             for ($i=0; $i<$rows; $i++)
00094                 {
00095                     #   increment the global total count
00096                     $total_rows++;
00097 
00098                     #   show the actual nested message
00099                     $ret_val .= forum_show_a_nested_message ($result,$i).'<P>';
00100                     if (db_result($result,$i,'has_followups') > 0)
00101                         {
00102                             #   Call yourself if there are followups
00103                             $ret_val .= forum_show_nested_messages ( $thread_id, db_result($result,$i,'msg_id') );
00104                         }
00105                 }
00106             $ret_val .= '
00107                         </UL>';
00108         }
00109 
00110         return $ret_val;
00111 }

get_forum_name id  ) 
 

Definition at line 249 of file include/news/forum.php.

References $result, $sql, db_numrows(), db_query(), and db_result.

00249                             {
00250         /*
00251                 Takes an ID and returns the corresponding forum name
00252         */
00253         $sql="SELECT forum_name FROM forum_group_list WHERE group_forum_id='$id'";
00254         $result=db_query($sql);
00255         if (!$result || db_numrows($result) < 1)
00256         {
00257             return "Not Found";
00258         }
00259         else
00260         {
00261             return db_result($result, 0, "forum_name");
00262         }
00263 
00264 }

get_forum_saved_date forum_id  ) 
 

Definition at line 440 of file include/news/forum.php.

References $result, $sql, db_numrows(), db_query(), and db_result.

Referenced by show_submessages(), and show_thread().

00441 {
00442         /*
00443                 return the save_date for this user
00444         */
00445         global $forum_saved_date;
00446 
00447 
00448         if ($forum_saved_date)
00449         {
00450             return $forum_saved_date;
00451         }
00452         else
00453         {
00454             $sql="SELECT save_date FROM forum_saved_place WHERE user_id='".user_getid()."' AND forum_id='$forum_id';";
00455             $result = db_query($sql);
00456             if ($result && db_numrows($result) > 0)
00457                 {
00458                     $forum_saved_date=db_result($result,0,'save_date');
00459                     return $forum_saved_date;
00460                 }
00461             else
00462                 {
00463                     #highlight new messages from the past week only
00464                     $forum_saved_date=(time()-604800);
00465                     return $forum_saved_date;
00466                 }
00467         }
00468 }

get_next_thread_id  ) 
 

Definition at line 421 of file include/news/forum.php.

References $result, db_error(), db_insertid(), db_query(), Error, exit, and print.

Referenced by forum_create_forum(), and post_message().

00422 {
00423         /*
00424                 Get around limitation in MySQL - Must use a separate table with an auto-increment
00425         */
00426         $result=db_query("INSERT INTO forum_thread_id VALUES ('')");
00427 
00428         if (!$result)
00429         {
00430             print '<H1>Error!</H1>';
00431             print db_error();
00432             exit;
00433         }
00434         else
00435         {
00436             return db_insertid($result);
00437         }
00438 }

post_message thread_id,
is_followup_to,
subject,
body,
group_forum_id
 

Definition at line 470 of file include/news/forum.php.

References $feedback, $msg_id, $result, $sql, $thread_id, db_error(), db_insertid(), db_numrows(), db_query(), db_result, Error, exit_error(), get_next_thread_id(), print, and user_isloggedin().

show_submessages thread_id,
msg_id,
level,
et = 0
 

Definition at line 342 of file include/news/forum.php.

References $current_message, $forum_id, $result, $rows, $sql, db_numrows(), db_query(), db_result, get_forum_saved_date(), and nbsp.

Referenced by show_thread().

00343 {
00344         /*
00345                 Recursive. Selects this message's id in this thread,
00346                 then checks if any messages are nested underneath it.
00347                 If there are, it calls itself, incrementing $level
00348                 $level is used for indentation of the threads.
00349         */
00350         global $total_rows,$sys_datefmt,$forum_id,$current_message;
00351 
00352         $sql="SELECT user.user_name,forum.has_followups,forum.msg_id,forum.subject,forum.thread_id,forum.body,forum.date,forum.is_followup_to ".
00353                 "FROM forum,user WHERE forum.thread_id='$thread_id' AND user.user_id=forum.posted_by AND forum.is_followup_to='$msg_id' ".
00354                 "ORDER BY forum.msg_id ASC;";
00355 
00356         $result=db_query($sql);
00357         $rows=db_numrows($result);
00358 
00359         if ($result && $rows > 0) {
00360         /*   US changed treatment of background color. Messages belonging to the same thread get the same background color as the first
00361                message of that threat
00362         */
00363                 for ($i=0; $i<$rows; $i++) {
00364                         /*
00365                                 Is this row's background shaded or not?
00366                                 $total_rows++;
00367                         */
00368             $total_rows++;
00369 
00370             $ret_val .= '<TR class="'. utils_get_alt_row_color($total_rows) .'"><TD NOWRAP>';
00371                         /*
00372                                 How far should it indent?
00373                         */
00374 
00375                         for ($i2=0; $i2<$level; $i2++)
00376                 {
00377                     $ret_val .= ' &nbsp; &nbsp; &nbsp; ';
00378                 }
00379 
00380 
00381             $ret_val .= '<IMG SRC="'.$GLOBALS['sys_home'].'images/'.SV_THEME.'.theme/mail.png" BORDER=0 HEIGHT=12 WIDTH=12 /> ';
00382 
00383                         /*
00384                                 If it this is the message being displayed, don't show a link to it
00385                         */
00386 
00387             $ret_val .= (($current_message != db_result($result, $i, 'msg_id'))?
00388                          '<A HREF="'.$GLOBALS['sys_home'].'forum/message.php?msg_id='.db_result($result, $i, 'msg_id').'">':'');
00389                         /*
00390                                 See if this message is new or not
00391                         */
00392                         if (get_forum_saved_date($forum_id) < db_result($result,$i,'date'))
00393                 { $ret_val .= '<strong>'; }
00394 
00395                         $ret_val .= db_result($result, $i, 'subject').'</A></TD>'.
00396                                 '<TD>'.db_result($result, $i, 'user_name').'</TD>'.
00397                                 '<TD>'.format_date($sys_datefmt,db_result($result,$i,'date')).'</TD></TR>';
00398 
00399                         /*
00400                                 Show the body/message if requested
00401                         */
00402                         if ($et == 1)
00403                 {
00404                     $ret_val .= '
00405                                         <TR class="'. utils_get_alt_row_color($total_rows) .'"><TD>&nbsp;</TD><TD COLSPAN=2>'.
00406                         nl2br(db_result($result, $i, 'body')).'</TD><TR>';
00407                 }
00408 
00409                         if (db_result($result,$i,'has_followups') > 0)
00410                 {
00411                     /*
00412                                         Call yourself, incrementing the level
00413                     */
00414                     $ret_val .= show_submessages($thread_id,db_result($result, $i, 'msg_id'),($level+1),$et);
00415                 }
00416                 }
00417         }
00418         return $ret_val;
00419 }

show_thread thread_id,
et = 0
 

Definition at line 266 of file include/news/forum.php.

References $current_message, $forum_id, $result, $rows, $sql, $subject, $title_arr, db_numrows(), db_query(), db_result, get_forum_saved_date(), nbsp, and show_submessages().

00267 {
00268         /*
00269                 Takes a thread_id and fetches it, then invokes show_submessages to nest the threads
00270 
00271                 $et is whether or not the forum is "expanded" or in flat mode
00272         */
00273         global $total_rows,$sys_datefmt,$is_followup_to,$subject,$forum_id,$current_message;
00274 
00275         $sql="SELECT user.user_name,forum.has_followups,forum.msg_id,forum.subject,forum.thread_id,forum.body,forum.date,forum.is_followup_to ".
00276                 "FROM forum,user WHERE forum.thread_id='$thread_id' AND user.user_id=forum.posted_by AND forum.is_followup_to='0' ".
00277                 "ORDER BY forum.msg_id DESC;";
00278 
00279         $result=db_query($sql);
00280 
00281         $total_rows=0;
00282 
00283         if (!$result || db_numrows($result) < 1)
00284         {
00285             return 'Broken Thread';
00286         }
00287         else
00288         {
00289 
00290             $title_arr=array();
00291             $title_arr[]='Thread';
00292             $title_arr[]='Author';
00293             $title_arr[]='Date';
00294 
00295             $ret_val .= html_build_list_table_top ($title_arr);
00296 
00297             $rows=db_numrows($result);
00298             $is_followup_to=db_result($result, ($rows-1), 'msg_id');
00299             $subject=db_result($result, ($rows-1), 'subject');
00300             /*
00301         Short - term compatibility fix. Leaving the iteration in for now -
00302         will remove in the future. If we remove now, some messages will become hidden
00303 
00304         No longer iterating here. There should only be one root message per thread now.
00305         Messages posted at the thread level are shown as followups to the first message
00306                         */
00307                         for ($i=0; $i<$rows; $i++)
00308                 {
00309                     $total_rows++;
00310                     $ret_val .= '<TR class="'. utils_get_alt_row_color($total_rows) .'"><TD>'.
00311                         (($current_message != db_result($result, $i, 'msg_id'))?'<A HREF="'.$GLOBALS['sys_home'].'forum/message.php?msg_id='.db_result($result, $i, 'msg_id').'">':'').
00312                         '<IMG SRC="'.$GLOBALS['sys_home'].'images/'.SV_THEME.'.theme/mail.png" BORDER=0 HEIGHT=12 WIDTH=12 /> ';
00313                     /*
00314                                 See if this message is new or not
00315                     */
00316                     if (get_forum_saved_date($forum_id) < db_result($result,$i,'date'))
00317                         { $ret_val .= '<strong>'; }
00318 
00319                     $ret_val .= db_result($result, $i, 'subject') .'</A></TD>'.
00320                         '<TD>'.db_result($result, $i, 'user_name').'</TD>'.
00321                         '<TD>'.format_date($sys_datefmt,db_result($result,$i,'date')).'</TD></TR>';
00322                     /*
00323                                 Show the body/message if requested
00324                     */
00325                     if ($et == 1)
00326                         {
00327                             $ret_val .= '
00328                                 <TR class="'. utils_get_alt_row_color($total_rows) .'"><TD>&nbsp;</TD><TD COLSPAN=2>'.
00329                                 nl2br(db_result($result, $i, 'body')).'</TD><TR>';
00330                         }
00331 
00332                     if (db_result($result,$i,'has_followups') > 0)
00333                         {
00334                             $ret_val .= show_submessages($thread_id,db_result($result, $i, 'msg_id'),1,$et);
00335                         }
00336                 }
00337                         $ret_val .= '</TABLE>';
00338         }
00339         return $ret_val;
00340 }


Generated on Sun Feb 26 13:23:05 2006 for Savane PHP Frontend Developer Reference by  doxygen 1.4.4