<% ' returns the ID number of the new post. ' error codes returned: ' -1 message you are trying to post reply to doesn't exsist ' -2 subthread is full, start a new thread. ' -3 maximum debth for thread, start a new thread. function AddReply(ByRef pobjCon, ByVal pstrName, ByVal pstrEmail, ByVal pstrSubject, _ ByVal pstrMessage, ByVal pdtmTime, ByVal pintAuthorID, ByVal pintParentMessageID, _ ByVal pblnApproved, ByVal pblnIsTest) Dim objRs, intMessageID, intGroupID, intThreadID, strSubThread, intDepth, strSQL, _ strNewThreadSubthread, strNewSubthread set objRs = server.CreateObject("ADODB.recordset") strSQL = "SELECT thegroup,thread,subthread,debth FROM forumMessages WHERE ID=" & pintParentMessageID call objRs.Open(strSQL, pobjCon, adOpenStatic, adLockReadOnly, adCmdText) if objRs.EOF then 'the message we want to post a reply to didn't exist! objRs.close 'close the recordset NOT containing the parent message set objRs = Nothing AddReply = -1 'return error exit function end if intGroupID = objRs.Fields.Item("thegroup").Value intDepth = objRs.Fields.Item("debth").Value+1 intThreadID = objRs.Fields.Item("thread").Value strSubThread = objRs.Fields.Item("subthread").Value objRs.close set objRs = Nothing if intDepth>10 then 'the debth is above maximum AddReply = -3 ' return error exit function end if 'now we update the subthreads table and allocate our subthread call BeginTransaction(pobjCon, "AddReply") strSQL = "SELECT subthread FROM forumSubthreads WHERE ID=" & intThreadID set objRs = OpenRS(pobjCon, strSQL) strNewThreadSubthread = subthreadPlusOne(objRs.Fields.Item("subthread").Value, intDepth) 'update the subthread counter objRs.Close 'close the recordset containing the subtreads set objRs = Nothing if strNewThreadSubthread=-2 then 'the subthread is full and we can not post the reply AddReply = -2 ' return error exit function end if strSQL = "UPDATE forumSubthreads SET subthread = '" & strNewThreadSubthread & "', lastposted = " & strSQLCurrentDate & " WHERE ID=" & intThreadID call pobjCon.execute(strSQL) 'mark parent message as having replies strSQL = "UPDATE forumMessages SET anyreplies=1 WHERE ID=" & pintParentMessageID call pobjCon.execute(strSQL) 'calculate the subthread for our new post strNewSubthread = subthreadMerge(strSubThread, strNewThreadSubthread, intDepth) 'insert the new reply in the database Set objRs = Server.CreateObject ("ADODB.Recordset") call objRs.Open("forumMessages", pobjCon, adOpenKeySet, adLockPessimistic, adCmdTable) call objRs.AddNew() objRs.Fields.Item("thegroup").Value = intGroupID objRs.Fields.Item("thread").Value = intThreadID objRs.Fields.Item("subthread").Value = strNewSubthread objRs.Fields.Item("debth").Value = intDepth objRs.Fields.Item("replyto").Value = pintParentMessageID objRs.Fields.Item("author").Value = pstrName objRs.Fields.Item("email").Value = pstrEmail objRs.Fields.Item("subject").Value = pstrSubject objRs.Fields.Item("message").Value = pstrMessage objRs.Fields.Item("timestamp").Value = pdtmTime objRs.Fields.Item("authorID").Value = pintAuthorID objRs.Fields.Item("anyreplies").Value = 0 objRs.Fields.Item("postingIP").Value = Request.ServerVariables("REMOTE_ADDR") objRs.Fields.Item("isApproved").Value = pblnApproved objRs.Fields.Item("isTest").Value = pblnIsTest call objRs.Update() intMessageID = GetNewID(pobjCon, objRs) objRs.Close set objRs = Nothing AddReply = intMessageID call CommitTransaction(pobjCon, "AddReply") end function %>