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

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- index9

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

Replying to a message - part 2

This script handles the data from replyto.cfm. Depending on what the user specified it either inserts the new article into the database or emails it to the author of the preceding message.

<CFQUERY NAME="getFields" DATASOURCE="#MyDatabase#">
  SELECT * FROM tblArticles WHERE ArticleID = #oldArticle#
</CFQUERY>
<CFQUERY NAME="GetID" DATASOURCE="#MyDatabase#">
  SELECT Max([ArticleID]) AS high FROM tblArticles;
</CFQUERY>

The getFields query retrieves various information relating to the message the user was replying to. The fields are:

The getID query returns the highest articleID in the tblArticles table. Incrementing this by one will give the value for the new articleID.

<CFIF #form.via# eq "board">

<CFQUERY NAME="NewArticle" DATASOURCE="#MyDatabase#">
  INSERT INTO tblArticles (GroupID, ThreadID, ThreadName, [Link], Posted, UserName, UserEmail, Message)
  VALUES (#GetFields.GroupID#,#GetFields.ThreadID#,'#GetFields.ThreadName#', '#GetFields.link#, #evaluate("#GetID.high# + 1")#', #now()#, '#UserName#', '#UserEmail#', '#Message#')
</CFQUERY>

<CFQUERY NAME="Email" DATASOURCE="#MyDatabase#">
  SELECT Distribution FROM tblThreads WHERE ThreadID = #GetFields.ThreadID#
</CFQUERY>

<CFIF listlen(Email.Distribution, ",") gt 0>
  <CFLOOP INDEX="loop1" FROM="1" TO = "#listlen(Email.Distribution)#">
    <CFMAIL FROM="#ListGetAt(Email.Distribution,loop1)#" TO="#ListGetAt(Email.Distribution,loop1)#" SUBJECT="re: #getFields.ThreadName#">
*** A new message has been posted on the My first Forum Board ***

#UserName# wrote:
#message#

http://www.myforum.com/
    </CFMAIL>
  </CFLOOP>
</CFIF>

This section is executed if the user opted to post their message to the bulletin board as opposed to emailing the author of the preceding message.

The first query is a straightforward INSERT query to enter the message into the tblArticles table.

The second query (Email) retrieves the contents of the Distribution field for this particular thread. This field is a comma-delimited list recording the email address of all the previous people who posted to this thread and checked the "Notify by email" checkbox on the input form.

If the second query returns a positive result, the script loops through the list of addresses and sends an email to each person.

<CFIF isDefined("notify")>
  <CFIF ListFindNoCase(Email.Distribution,form.UserEmail,",") eq 0>
    <CFQUERY NAME="UpdateDistribution" DATASOURCE="#MyDatabase#">
      UPDATE tblThreads SET Distribution = '#Email.Distribution#,#form.UserEmail#' WHERE ThreadID = #GetFields.ThreadID#
    </CFQUERY>
  </CFIF>
</CFIF>

We now check if the user has checked the "Notify by email" checkbox and, if so, add the user's email address to the distribution field for this thread.

<CFELSE>

<CFMAIL FROM="#form.UserEmail#" TO="#getFields.UserEmail#" SUBJECT="re: #GetFields.ThreadName#">
#Form.message#
</CFMAIL>
</CFIF>

If the user opted to reply directly to the author of the preceding message instead of posting their article publically, then the code shown above is processed.

<CFLOCATION URL="openthread.cfm?forum=#getFields.GroupID#&threadID=#getFields.threadID#">

Just as in the post.cfm file, all of this script is run on the server without any user interaction. The CFLOCATION tag directs the server to a new file so that the application can continue.

Back to Replying to a message - part 1, or forward to Cancelling a message - part 1

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