Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap

Related items

Exporting data to Word with Cold Fusion

How to update/edit data using Cold Fusion

Introduction to Cold Fusion

Diary of a WebObjects Developer

Building an Internet Database

My First Forum - a bulletin board application- index4

You are here: irt.org | Articles | Database | My First Forum - a bulletin board application [ previous next ]

Published on: Thursday 8th April 1999 By: Andrew Shatwell

Opening a group

This script is called from the initial screen listing all the available forums. (board.cfm)

A variable is passed in the URL when this script is called, specifying which forum to display. An example URL used to reach this script would be http://www.myforum.com/cfm/openforum.cfm?forum=1

<CFPARAM NAME = "useraccess" DEFAULT="Public">
<CFIF log eq 1><CFSET useraccess = login.access></CFIF>
<CFQUERY NAME="ForumDetails" DATASOURCE="#MyDatabase#">
  SELECT * FROM tblGroups WHERE GroupID = #forum#

First the check.cfm script is executed.

The CFPARAM tag assigns the user a default value of "public" for their level of access.

If the user has logged on then a new level of access is obtained from the login query (in the check.cfm script) and this replaces the default value.

The ForumDetails query obtains the read and write access levels for the specified forum.

<!doctype html public "-//IETF//DTD HTML 3.2//EN">
<title>My First Forum</title>
<meta name="Generator" content="HTMLed32 Version 2.0a">
<meta name="Author" content="Andrew Shatwell">
<body BGCOLOR="#FFFFFF" BACKGROUND="../images/gridpaperbackground2.gif" link="#000080" vlink="#2f2f4f">
<div align="center">
  <IMG SRC="../images/logo2.gif" BORDER="0" ALT="My First Forum" width="469" height="64">

<table cellpadding="0" cellspacing="0" border="0" width="95%"><tr>
  <font size="2">
    <b><a href="board.cfm">Main Board</a></b><br>
  <font color="#000080">
    <img src="../images/tline.gif" width="12" height="12" border="0" alt=""><b>
    <CFOUTPUT>#forum#. #ForumDetails.GroupName#</CFOUTPUT></b>
<td valign="top" align="right">
  <font size="2"><i>
    <CFOUTPUT><a href="openforum.cfm?forum=#forum#"></CFOUTPUT>Refresh screen</a></i>


The first 12 lines are standard HTML which used to define the background of the page and to display the logo at the top.

The name of the forum is read from the ForumDetails query and displayed on the lefthand side of the screen. On the righthand side, a link to refresh the page is shown. The URL for this link is identical to that used to initially load this page.

<CFIF ListFindNoCase(ForumDetails.ReadAccess, useraccess, ",") eq 0>
  <font face="Verdana, Arial" color="#800000">You do not have permission to view this group.</font>
  <p><a href="board.cfm">Return to main Bulletin Board</a>

The CFIF statement checks to see if the user has permission to view the contents of this forum. The contents of the ReadAccess field is a comma-separated list containing all the usergroups that have permission to view this group, for example: "admin, beta, public"

The ListFindNoCase function tests the first parameter for occurances of the second one. If the second parameter is found, the function returns its position in the list.

In our CFIF statement, if no occurance was found the function returns zero, and a message is subsequently displayed.

Otherwise, the following code is processed . . .

<CFQUERY NAME="Threads" DATASOURCE="#MyDatabase#">
SELECT tblThreads.GroupID, tblThreads.ThreadID, tblThreads.ThreadName, tblThreads.UserName, Count(tblArticles.ThreadID) AS Posts, Last(tblArticles.Posted) AS LastP
FROM tblThreads INNER JOIN tblArticles ON tblThreads.ThreadID = tblArticles.ThreadID
GROUP BY tblThreads.GroupID, tblThreads.ThreadID, tblThreads.ThreadName, tblThreads.UserName
HAVING (((tblThreads.GroupID)=#forum#)) ORDER BY Last(tblArticles.Posted) DESC;

<tr bgcolor="#D5E6E1">
  <td width="43%"><font size="1" face="Verdana, Arial" color="#000080">Topic</font></td>
  <td width="30%"><font size="1" face="Verdana, Arial" color="#000080">Originator</font></td>
  <td width="7%"><font size="1" face="Verdana, Arial" color="#000080">Replies</font></td>
  <td width="20%"><font size="1" face="Verdana, Arial" color="#000080">Last post</font></td>
<CFOUTPUT QUERY="Threads"><tr>
  <td width="43%"><CFIF log eq 1>
        <CFIF Threads.LastP gt login.LastLogin>
              <img src="../images/closedb.gif" width="14" height="11" border="0" alt="New">
              <img src="../images/closed.gif" width="14" height="11" border="0" alt="">
    <font size="2" face="Verdana, Arial">
    <a href="OpenThread.cfm?forum=#forum#&ThreadID=#ThreadID#">#ThreadName#</a></font>
  <td width="30%" bgcolor="##dedfdf">
    <font size="2" face="Verdana, Arial">#UserName#</font>
  <td width="7%" align="center">
    <font size="2" face="Verdana, Arial">
  <td width="20%" bgcolor="##dedfdf">
    <font size="2" face="Verdana, Arial">
    &nbsp;<font size="1" face="Verdana, Arial" color="##000080">
    #timeformat(Threads.LastP,"h:mm tt")#</font>

The Threads query pulls in information from two tables: tblThreads and tblArticles. tblThreads contains the subject header for the first message in each thread. tblArticles contains the body text of all messages along with other posting information.

The fields obtained by this query are:

The code between the <CFOUTPUT>. . .</CFOUTPUT> tags is looped over and over for each record in the query.

The initial conditional stagement checks if the user has logged on. If true, the date/time they last logged on is compared with the date/time a message was lasted posted in each thread. If there are new messages since the user last visited the site, we show a red folder. Otherwise, we show a yellow folder.

The subject of each thread is displayed. The link tag points to the openthread.cfm file each time. However, the parameters passed to the file vary with each record in the query.

When displaying the values of Posts and LastP, the DateFormat and TimeFormat functions are used to modify the default (US) format of the date/time variables.

<spacer size="50" type="vertical">
<img src="../images/closedb.gif" width="14" height="11" border="0" alt="New Posts">
&nbsp;&nbsp;<b>Contains new posts since the last time you logged on.</b><BR>
<img src="../images/closed.gif" width="14" height="11" border="0" alt="No New Posts">
&nbsp;&nbsp;<b>No new posts since the last time you logged on.</b><BR>
<img src="../images/lock.gif" width="9" height="11" border="0" alt="Closed Thread">
&nbsp;&nbsp;&nbsp;<b>A closed thread - no new replies accepted.</b>

<CFIF ListFindNoCase(ForumDetails.WriteAccess, useraccess, ",") neq 0>
  <p><div align="center"><CFOUTPUT><a href="PostNew.cfm?forum=#forum#"></CFOUTPUT>
  <b>Post New Topic</b></a></div>


The final CFIF statement in this script tests if the user has permission to post to this forum and conditionally provides a link to do so.

Back to Including files, or forward to Opening a thread

Related items

Exporting data to Word with Cold Fusion

How to update/edit data using Cold Fusion

Introduction to Cold Fusion

Diary of a WebObjects Developer

Building an Internet Database

©2018 Martin Webb