0) { $topiccreator = ($topicinfo['creatorid'] == $p_id); } else if ($p_id == 0) { // guests are assumed to be the topic creator if no messages have yet been posted in the current topic. // ASSUMPTION: zero-message topics are not displayed to guests unless they have just created a topic! $topiccreator = (($topicinfo['creatorid'] == 0) and ($topicinfo['totalmessages'] == 0)); } } } determineaccess(); // ====================================================================================================== // PROCESS INPUT FORMS // ====================================================================================================== $newtopic = $_POST["newtopic"]; $newmessage = $_POST["newmessage"]; $delete = $_GET["delete"]; $deleteconfirm = $_GET["deleteconfirm"]; $edit = $_GET["edit"]; // NEW TOPIC if ($newtopic) { if (!is_allowed(ACCESS_FORUM_NEWTOPIC)) { include "accessdenied.php"; } if (!$f) { noteerror ("No message forum was selected for your topic."); } else if ($t) { // topic id stipulated: editing existing topic $now = time(); $q = 'update topics set subject="' . sqlsafe($newtopic) . '",'; $q .= ' lastupdated=' . $now . ' where topicid=' . $t . ';'; $r = query($q) or die ('Error updating topic with query:

' . $q); $_POST["newtopic"] = ''; $topicinfo['subject'] = $newtopic; $changereport = 'Topic updated.'; } else { $now = time(); // create new topic $q = 'insert into topics set subject="' . sqlsafe($newtopic) . '",'; $q .= ' creatorid=' . $p_id . ','; $q .= ' ownerforumid=' . $f . ','; $q .= ' totalmessages=0,'; $q .= ' whencreated=' . $now . ','; $q .= ' lastupdated=' . $now . ';'; $r = query($q) or die ('Error creating new topic with query:

' . $q); // get topic id $r = query('select * from topics where whencreated=' . $now . ';'); $topicinfo = mysql_fetch_array($r, MYSQL_ASSOC) or die ('Error looking up newly-created topic.'); $t = $topicinfo["topicid"]; determineaccess(); $_POST["newtopic"] = ''; } } if ($newmessage) { if (!is_allowed(ACCESS_FORUM_POST)) { include "accessdenied.php"; } if (!$t) { noteerror ("No topic was selected for your message."); } else if ($m) { // message id stipulated: editing existing message $now = time(); $q = 'update messages set message="' . sqlsafe($newmessage) . '",'; $q .= ' lastedited=' . $now . ' where messageid=' . $m . ';'; $r = query($q) or die ('Error updating message with query:

' . $q); $_POST["newmessage"] = ''; // update topic date $q = 'update topics set lastupdated=' . $now . ' where topicid=' . $t . ';'; $r = query($q) or die ('Error updating topic timestamp with query:

' . $q); $change_report = 'Message updated.'; $messageinfo['message'] = $newmessage; } else { $now = time(); $q = 'insert into messages set message="' . sqlsafe($newmessage) . '",'; $q .= ' creatorid=' . $p_id . ','; $q .= ' ownertopicid=' . $t . ','; $q .= ' whencreated=' . $now . ','; $q .= ' lastedited=' . $now . ';'; $r = query($q) or die ('Error creating message with query:

' . $q); // retrieve message id $r = query('select * from messages where whencreated=' . $now . ';'); $messageinfo = mysql_fetch_array($r, MYSQL_ASSOC) or die ('Error looking up newly-created message.'); $m = $messageinfo["messageid"]; // clear POST data $_POST["newmessage"] = ''; // update topic date $q = 'update topics set lastupdated=' . $now . ',totalmessages=totalmessages+1 where topicid=' . $t . ';'; $r = query($q) or die ('Error updating topic timestamp with query:

' . $q); $topicinfo["totalmessages"]++; determineaccess(); // force page number to last page $page = 99999999; } } if ($delete) { if ($m) { $r = query ('select * from messages where messageid=' . $m); $messageinfo = mysql_fetch_array($r, MYSQL_ASSOC) or die ('Error checking message to be deleted.'); $creator = $messageinfo["creatorid"]; if ((($creator == $p_id) and ($u_id)) or is_allowed(ACCESS_FORUM_MODERATE)) { $r = query ('delete from messages where messageid=' . $m); // update topic date $q = 'update topics set lastupdated=' . time() . ',totalmessages=totalmessages-1 where topicid=' . $t . ';'; $r = query($q) or die ('Error updating topic timestamp with query:

' . $q); $topicinfo["totalmessages"]--; determineaccess(); $change_report = 'Message deleted.'; } else { include "accessdenied.php"; } } else if ($t) { $r = query ('select * from topics where topicid=' . $t); $topicinfo = mysql_fetch_array($r, MYSQL_ASSOC) or die ('Error checking topic to be deleted.'); $allowed = ($moderator or ($topiccreator and !$topicinfo['totalmessages'])); if ($allowed) { // delete messages in topic $r = query ('delete from messages where ownertopicid=' . $t); // delete topic $r = query ('delete from topics where topicid=' . $t); $t = 0; determineaccess(); $change_report = 'Topic deleted.'; } else { include "accessdenied.php"; } } // end if deleting } // ====================================================================================================== // FORUM PURGING // ====================================================================================================== function purgeforum () { $DAY = 86400; // number of seconds in a day global $f, $foruminfo; $now = time(); if (($foruminfo["purgetime"]) and ($now > ($foruminfo["lastpurge"] + $DAY))) { // minimum 1-day wait between purges $deletetime = $now - ($foruminfo["purgetime"] * $DAY); $r = query ('select * from forums,topics where ownerforumid=forumid and forumid=' . $f . ' and lastupdated<' . $deletetime . ';'); $topicids = ''; if ($r) { $count = 0; $idlist = ''; while ($info = mysql_fetch_array($r, MYSQL_ASSOC)) { if ($idlist) $idlist .= ','; $idlist .= $info['topicid']; $count++; } if ($count) { $r = query ('delete from messages where ownertopicid in (' . $idlist . ');'); $r = query ('delete from topics where topicid in (' . $idlist . ');'); } } $r = query('update forums set lastpurge=' . $now . ' where forumid=' . $f . ';'); } } // ====================================================================================================== // COMMON PAGE COMPONENTS // ====================================================================================================== function masthead_forum () { global $moderator, $topiccreator, $t, $messagecount, $topicinfo, $g; global $BGCOLOUR_LIGHT, $BGCOLOUR_DARK, $p_id, $u_id, $deleteconfirm, $edit; $availablesearchtypes[SEARCH_MESSAGE_THISGROUP] = 'message (this group)'; $availablesearchtypes[SEARCH_TOPIC_THISGROUP] = 'topic (this group)'; $availablesearchtypes[SEARCH_MESSAGE] = 'message (all groups)'; $availablesearchtypes[SEARCH_TOPIC] = 'topic (all groups)'; $availablesearchtypes[SEARCH_FORUMGROUP] = 'forum (by group name)'; masthead_search($availablesearchtypes); if (($t) and (!$edit)) { $deleteallowed = ($moderator or ($topiccreator and ($topicinfo['totalmessages'] == 0))); $editallowed = ($moderator or $topiccreator); if ($deleteallowed or $editallowed) { print ''; if ($deleteconfirm) { print ' Delete this topic - Are you sure? '; print '| Yes '; print '| No '; print '|'; } else { if ($editallowed) { print ' '; print 'Edit this topic |'; } if ($deleteallowed) { print ' '; print 'Delete this topic |'; } } print ""; } // if ($deleteallowed or $editallowed) // if (($t) and (!$edit)) } else if (!$t) { if (is_allowed(ACCESS_ADMIN)) { print ''; print ' '; print 'Edit forums |'; print ' '; print 'Security |'; print ""; } } } // masthead_forum // printcontext // - displays group, group forums, current forum, and current topic in clickable form // - also calles printeditfeedback() to display update feedback as necessary function printcontext () { global $g, $g_info, $f, $foruminfo, $t, $topicinfo, $edit; printeditfeedback(); print '

' . crunchtext($g_info["groupname"]) . ""; if ($f) { print ': Forums'; } else { print ': Forums'; } print "

\n"; if ($t) { print '

'; print crunchtext($foruminfo["title"]); print ""; } else if ($f) { print '

'; print crunchtext($foruminfo["title"]); } if ($edit) { print ': '; print crunchtext($topicinfo["subject"]); print ""; } print "

\n"; } // message form // - called from within an existing table; spans 2 columns function printmessageform ($formtitle,$contentvarname) { global $m, $f, $t, $page, $edit; print '' . "\n"; formstart(append_url_vars_pg('f,t,page'),"thin"); if ($edit and $m) { $_POST['m'] = $m; formhiddeninput('m'); } print '' . $formtitle . ' '; print '
'; formtextareainput ($contentvarname,76,12,"small"); print '
'; formend(); print '
'; print "\n"; } // ====================================================================================================== // EDIT A MESSAGE // ====================================================================================================== if ($edit and $m) { printhtmlheader ('Edit Message'); printmasthead ('Edit Message','masthead_forum','f,t,page'); printcontext(); $_POST["newmessage"] = $messageinfo["message"]; print ""; printmessageform('Edit your message:','newmessage'); print "
"; // ====================================================================================================== // EDIT A TOPIC // ====================================================================================================== } else if ($edit and $t) { printhtmlheader ('Edit Topic'); printmasthead ('Edit Topic','masthead_forum','f,t,page'); printcontext(); $_POST["newtopic"] = $topicinfo["subject"]; print ""; printmessageform('Edit your topic:','newtopic'); print "
"; } else if ($t > 0) { // ====================================================================================================== // DISPLAY A TOPIC // ====================================================================================================== // establish whether html code is allowed for this forum $allowhtml = $foruminfo["allowhtml"]; // get messages in topic $r = query('select * from messages where ownertopicid=' . $t . ';') or die ("Error looking up messages."); // handle multiple pages $resultcount = mysql_num_rows($r); if ($resultcount > $PAGELIMIT) { // force page number if message specified (from an add or edit) // use page number to calculate start point $pagestart = ($page - 1) * $PAGELIMIT; if ($pagestart >= $resultcount) { $page = $resultcount / $PAGELIMIT; $pagestart = (floor($page)) * $PAGELIMIT; } mysql_data_seek ($r,$pagestart); } // get message data $messagecount = 0; while (($messageinfo = mysql_fetch_array($r, MYSQL_ASSOC)) and ($messagecount < $PAGELIMIT)) { $messagelist[] = $messageinfo; $messagecount++; } printhtmlheader (crunchtext($topicinfo["subject"])); printmasthead (crunchtext($g_info["groupname"]) . ' Forums','masthead_forum','f,t,page'); printcontext(); print '' . "\n"; print ''; // multiple pages function topic_printpagenumbers () { global $BGCOLOUR_LIGHT, $resultcount, $PAGELIMIT, $page, $t; print '\n"; } if ($resultcount > $PAGELIMIT) { topic_printpagenumbers(); } if ($messagecount) { while (list($key,$messageinfo) = each($messagelist)) { print '\n"; print "\n"; print "\n"; } } if ($resultcount > $PAGELIMIT) { topic_printpagenumbers(); } $maypost = $moderator; if (is_allowed(ACCESS_FORUM_POST) and !$maypost) { if ($topicinfo['totalmessages']) { $maypost = TRUE; } else { $maypost = $topiccreator; } } if ($maypost) { printmessageform('Post a message:','newmessage'); } print "
'; print crunchtext($topicinfo["subject"]); print '
'; print ''; print "Pages in Topic: "; // print page numbers $i = 0; $numpages = $resultcount / $PAGELIMIT; while ($i++ < $numpages) { if ($i == $page) { print '' . $i . ' '; } else { print '' . $i . ' '; } } print "
'; $creator = $messageinfo["creatorid"]; if ($creator) { $r = query ('select * from persons where personid=' . $creator . ';') or die ('Error looking up message creator id ' . $creator); $creatorinfo = mysql_fetch_array($r, MYSQL_ASSOC); if (!$creatorinfo) // obsolete person id: treat as 'guest' $creator = 0; } if ($creator) { print ''; print crunchtext($creatorinfo['firstname'] . ' ' . $creatorinfo['lastname']); print ''; } else { print 'Guest'; } print ""; // message header: date/time, edit/delete print ''; print '\n"; if ($moderator or (($creator == $p_id) and $u_id)) { print ''; } print "
'; print date("m-d-y H:i", $messageinfo["whencreated"]); if ($messageinfo["whencreated"] <> $messageinfo["lastedited"]) { print ' (edited ' . date("m-d-y H:i", $messageinfo["lastedited"]) . ")"; } print " '; print ''; print 'Edit | '; print ''; print 'Delete'; print '
\n"; // message body print ''; if ($allowhtml) { print nl2br(stripslashes ($messageinfo["message"])); } else { print nl2br(crunchtext ($messageinfo["message"])); } print '

'; print "

\n\n"; } else if ($f > 0) { // ====================================================================================================== // DISPLAY A FORUM // ====================================================================================================== printhtmlheader (crunchtext($foruminfo["title"])); printmasthead (crunchtext($g_info["groupname"]) . ' Forums','masthead_forum','f,t,page'); printcontext(); // description if ($foruminfo["description"]) { print ''; print nl2br(stripslashes($foruminfo["description"])); print '

' . "\n\n"; } // purge topics purgeforum(); // list topics $q = 'select * from topics where ownerforumid=' . $f ; if ($foruminfo["defaulttopicsort"] == 0) { $q .= ' order by lastupdated desc'; } else if ($foruminfo["defaulttopicsort"] == 1) { $q .= ' order by subject'; } $q .= ';'; $r = query ($q) or die ('Error looking up topics'); print '

' . "\n"; function forum_printpagenumbers () { global $resultcount, $PAGELIMIT, $page, $f, $BGCOLOUR_LIGHT; print '\n"; } // multiple pages $resultcount = mysql_num_rows($r); if ($resultcount > $PAGELIMIT) { // use $page variable to calculate start point $pagestart = ($page - 1) * $PAGELIMIT; if ($pagestart >= $resultcount) { $page = $resultcount / $PAGELIMIT; $pagestart = (floor($page)) * $PAGELIMIT; } mysql_data_seek ($r,$pagestart); // print page numbers forum_printpagenumbers(); } $topiccount = 0; while (($topicinfo = mysql_fetch_array($r, MYSQL_ASSOC)) and ($topiccount < $PAGELIMIT)) { // filter topics with no messages: assume they are still being composed! if ($topicinfo['totalmessages']) { $topiclist[] = $topicinfo; $topiccount++; } else if ($moderator or (($topicinfo['creatorid'] == $p_id) and ($u_id))) { // in zero-message topics, display only to moderators and the topic creator (if known) $topiclist[] = $topicinfo; $topiccount++; } } if ($topiccount) { print ''; print ''; print ''; print '' . "\n"; while (list($key,$topicinfo) = each ($topiclist)) { print '\n"; } print "\n"; print "\n"; print "\n"; print "\n\n"; } } if ($resultcount > $PAGELIMIT) { forum_printpagenumbers(); } print "
'; print ''; print "Pages in Forum: "; // print page numbers $i = 0; $numpages = $resultcount / $PAGELIMIT; while ($i++ < $numpages) { if ($i == $page) { print '' . $i . ' '; } else { print '' . $i . ' '; } } print "
TopicRepliesTopic StarterMost Recent
'; print ''; print crunchtext($topicinfo["subject"]); print ""; if ($topicinfo["totalmessages"] > $PAGELIMIT) { $i = $topicinfo["totalmessages"]; $whichpage = 0; print " Page:"; while ($i > 0) { print ' ' . $whichpage . ''; $i = $i - $PAGELIMIT; } print ""; if ($topicinfo["totalmessages"]) { print $topicinfo["totalmessages"] - 1; } else { print highlighttext('n/a'); } print ""; $creator = $topicinfo["creatorid"]; if ($creator) { $r = query ('select * from persons where personid=' . $creator . ';') or die ('Error looking up message creator id ' . $creator); $creatorinfo = mysql_fetch_array($r, MYSQL_ASSOC); if (!$creatorinfo) // obsolete person id: treat as 'guest' $creator = 0; } if ($creator) { print ''; print crunchtext($creatorinfo['firstname'] . ' ' . $creatorinfo['lastname']); print ''; } else { print 'Guest'; } print "" . date("m-d-y H:i", $topicinfo["lastupdated"]) . "
\n\n

"; if (is_allowed(ACCESS_FORUM_NEWTOPIC)) { print '

' . "\n"; print '\n"; print "
'; $f = $f; formstart(append_url_vars_pg('f'),"thin"); print 'Create New Topic: '; formtextinput ("newtopic",50,"small"); print ''; print " \n"; print "
\n"; } } else { // ====================================================================================================== // LIST FORUMS FOR A GIVEN GROUP // ====================================================================================================== printhtmlheader (crunchtext($g_info["groupname"]) . ' Forums'); printmasthead (crunchtext($g_info["groupname"]) . ' Forums','masthead_forum','f,t,page'); printcontext (); if ($forumcount == 0) { print 'This group does not have any message forums.'; } else { // multiple forums: list them print "\n"; if ($forumcount) { while (list($key,$foruminfo) = each($forumlist)) { print ''; print ''; print ''; print "\n"; } } print "
'; print ''; if ($foruminfo["title"]) { print crunchtext($foruminfo["title"]); } else { print '(Untitled)'; } print '' . nl2br(stripslashes($foruminfo["description"])) . '
\n"; } } ?>