I'll bundle my changes up in to a Mod for a standard 3.3 forum over the next coupld of days for those of us who are going to be stuckon 3.3 for some time to come. It's certainly worth the effort of changing.
Right now I've left the changes as instr rathern than ubound becuase I think it works out a little more efficent. Whilst the string concatenation to create the string is a fairly 'expensive' task, so is ReDiming an array (which you may have to do multiple times to create the final array) and then you also need a small loop to check an ID against the array, so the instr code IMO has worked out probably a little cheaper.
Summary of changes
1) Placed new code at the top of getNewMemberNumber, and getMemberNumber and getMemberId
if MemberID <> 0 then
getNewMemberNumber = MemberID ' needs to change for each function
exit functio
end if
2) Created two new small functions in inc_functions to do my Instr work.
function fCanModerate(zForumId)
fCanModerate = 0
fCanModerate = instr(AllowForumModerate,"|" & zForumId & "|")
end function
function fAllowedForumAccess(zForumId)
fAllowedForumAccess = 0
fAllowedForumAccess = instr(AllowForumList,"|" & zForumId & "|")
end function
3) Updated chkForumModeator Procedure
function chkForumModerator(fMember_Name)
'## Forum_SQL
strSql = "SELECT mo.FORUM_ID "
strSql = strSql & " FROM " & strTablePrefix & "MODERATOR mo, " & strMemberTablePrefix & "MEMBERS me "
'strSql = strSql & " WHERE mo.FORUM_ID = " & fForum_ID & " "
strSql = strSql & " WHERE mo.MEMBER_ID = me.MEMBER_ID "
if strAuthType = "db" then
strSql = strSql & " AND me.M_NAME = '" & fMember_Name & "'"
elseif strAuthType = "nt" then
strSql = strSql & " AND me.M_USERNAME = '" & fMember_Name & "'"
end if
Set rsChk = Server.CreateObject("ADODB.Recordset")
rsChk.open strSql, my_Conn
if rsChk.bof or rsChk.eof then
y = ""
rsChk.Close()
set rsChk = nothing
else
ModeratorList = rsChk.GetRows()
rsChk.Close()
set rsChk = nothing
for RowCount = 0 to ubound(ModeratorList,2)
chkForumModerator = chkForumModerator & "|" & ModeratorList(0,RowCount)
next
chkForumModerator = chkForumModerator & "|" ' Add last Pipe to string.
end if
end function
4) Add one line to inc_top.asp to build pipe list
AllowForumModerate = chkForumModerator(MemberId) ' Pip Delimited list of Forums Member is Moderator of.
5) Replace every call to chkForumModerator with a call instead to fCanModerate (this is the biggest change about 15 different pages it occured in 50+ places in my modified forum) ie Lines 361 - 368 in active.asp (just the first example I picked) I changed from
if (mLev = 4) or _
((chkForumModerator(Forum_ID, Session(strCookieURL & "username"))= "1") and mLev = 3) or _
((chkForumModerator(Forum_ID, strDBNTUserName) = "1") and mlev = 3) or _
(lcase(strNoCookies) = "1") then
AdminAllowed = 1
else
AdminAllowed = 0
end if
To
if (mLev = 4) or ((fCanModerate(Forum_ID) = 1) and mLev = 3) or (lcase(strNoCookies) = "1") then
AdminAllowed = 1
else
AdminAllowed = 0
end if
6) Function isAllowedMember (inc_functions.asp) changed to
function isAllowedMember(fMemberID)
isAllowedMember = ""
on error resume next
strSql = "SELECT FORUM_ID FROM " & strTablePrefix & "ALLOWED_MEMBERS "
strSql = strSql & " WHERE " & strTablePrefix & "ALLOWED_MEMBERS.MEMBER_ID = " & ChkString(fMemberID, "SQLString")
Set rsAllowedMember = Server.CreateObject("ADODB.Recordset")
rsAllowedMember.open strSql, my_Conn
if not rsAllowedMember.EOF then
AllowedForums = rsAllowedMember.GetRows()
rsAllowedMember.Close()
set rsAllowedMember = nothing
For AllowCount = 0 to ubound(AllowedForums,2) ' Total Numer of Rows
isAllowedMember = isAllowedMember & "|" & AllowedForums(0,AllowCount)
next
isAllowedMember = isAllowedMember & "|" ' Add last pipe
end if
end function
7) New Line in inc_top.asp added
AllowForumList = isAllowedMember(MemberID) ' Pipe Delimited list of Forums Member has Access too
8) Did as for step 5 except this time changing all calls to IsAllowedMember and replacing them with calls to fAllowedForumAccess (I think most of those changes were all restricted to inc_functions.asp)
9) Function ChkForumAccess, removed the top part of the function
function chkForumAccess(fForum, UserNum)
chkForumAccess = false
strSql = "SELECT " & strMemberTablePrefix & "MEMBERS.M_LEVEL "
strSql = strSql & " FROM " & strMemberTablePrefix & "MEMBERS "
strSql = strSql & " WHERE " & strMemberTablePrefix & "MEMBERS.MEMBER_ID=" & UserNum
Set rsCheck = Server.CreateObject("ADODB.Recordset")
rsCheck.open strSql, my_Conn
if rsCheck.BOF or rsCheck.EOF then
chkForumAccess = false
elseif rsCheck("M_LEVEL") = 3 then
chkForumAccess = true
rsCheck.close
set rsCheck = nothing
exit function
end if
rsCheck.close
'## Forum_SQL
strSql = "SELECT " & strTablePrefix & "FORUM.F_PRIVATEFORUMS, " & strTablePrefix & "FORUM.F_SUBJECT, " & strTablePrefix & "FORUM.F_PASSWORD_NEW "
strSql = strSql & " FROM " & strTablePrefix & "FORUM "
strSql = strSql & " WHERE " & strTablePrefix & "FORUM.Forum_ID = " & ChkString(fForum, "SQLString")
and Replaced with
function chkForumAccess(fForum, UserNum)
chkForumAccess = false
if mLev = 4 then
chkForumAccess = true
exit function
end if
'## Forum_SQL
strSql = "SELECT " & strTablePrefix & "FORUM.F_PRIVATEFORUMS, " & strTablePrefix & "FORUM.F_SUBJECT, " & strTablePrefix & "FORUM.F_PASSWORD_NEW "
strSql = strSql & " FROM " & strTablePrefix & "FORUM "
strSql = strSql & " WHERE " & strTablePrefix & "FORUM.Forum_ID = " & ChkString(fForum, "SQLString")
10) Converted active.asp to use GetRows(). I think if you just change the following it will work for you also. Lines 333 - 358 look like this
else
currForum = 0
fDisplayCount = 0
do until rs.EOF
'## Store all the recordvalues in variables first.
Forum_ID = rs("FORUM_ID")
Forum_Subject = rs("F_SUBJECT")
Topic_Status = rs("T_STATUS")
Topic_View_Count = rs("T_VIEW_COUNT")
Topic_ID = rs("TOPIC_ID")
Cat_ID = rs("CAT_ID")
Topic_Subject = rs("T_SUBJECT")
Topic_Author = rs("T_AUTHOR")
Topic_Replies = rs("T_REPLIES")
Member_Name = rs("M_NAME")
Topic_Last_Post_Author = rs("T_LAST_POST_AUTHOR")
Topic_Last_Post = rs("T_LAST_POST")
Topic_Last_Post_Author_Name = rs("LAST_POST_AUTHOR_NAME")
CatSubscription = rs("CAT_SUBSCRIPTION")
CatStatus = rs("CAT_STATUS")
ForumSubscription = rs("F_SUBSCRIPTION")
ForumStatus = rs("F_STATUS")
' Does user have access to the forum??
Replace them with
else
currForum = 0
fDisplayCount = 0
ActiveTopics = rs.GetRows()
fF_SUBJECT = 0
fF_SUBSCRIPTION = 1
fF_STATUS = 2
fF_ORDER = 3
fCAT_SUBSCRIPTION = 4
fCAT_STATUS = 5
fCAT_ORDER = 6
fT_STATUS = 7
fT_VIEW_COUNT = 8
fFORUM_ID = 9
fTOPIC_ID = 10
fCAT_ID = 11
fT_SUBJECT = 12
fT_AUTHOR = 13
fT_REPLIES = 14
fM_NAME = 15
fT_LAST_POST_AUTHOR = 16
fT_LAST_POST = 17
fLAST_POST_AUTHOR_NAME = 18
for RowCount = 0 to ubound(ActiveTopics,2)
'## Store all the recordvalues in variables first.
Forum_Subject = ActiveTopics(fF_SUBJECT,RowCount)
ForumSubscription = ActiveTopics(fF_SUBSCRIPTION,RowCount)
ForumStatus = ActiveTopics(fF_STATUS,RowCount)
Forum_Order = ActiveTopics(fF_ORDER,RowCount)
CatSubscription = ActiveTopics(fCAT_SUBSCRIPTION,RowCount)
CatStatus = ActiveTopics(fCAT_STATUS,RowCount)
CatOrder = ActiveTopics(fCAT_ORDER,RowCount)
Topic_Status = ActiveTopics(fT_STATUS,RowCount)
Topic_View_Count = ActiveTopics(fT_VIEW_COUNT,RowCount)
Forum_ID = ActiveTopics(fFORUM_ID,RowCount)
Topic_ID = ActiveTopics(fTOPIC_ID,RowCount)
Cat_ID = ActiveTopics(fCAT_ID,RowCount)
Topic_Subject = ActiveTopics(fT_SUBJECT,RowCount)
Topic_Author = ActiveTopics(fT_AUTHOR,RowCount)
Topic_Replies = ActiveTopics(fT_REPLIES,RowCount)
Member_Name = ActiveTopics(fM_NAME,RowCount)
Topic_Last_Post_Author = ActiveTopics(fT_LAST_POST_AUTHOR,RowCount)
Topic_Last_Post = ActiveTopics(fT_LAST_POST,RowCount)
Topic_Last_Post_Author_Name = ActiveTopics(fLAST_POST_AUTHOR_NAME,RowCount)
' Does user have access to the forum??
And Finally replace the rs.MoveNext on line 471 with Next
I "think" thats all the changes I made yesterday, please note I'm still testing that forum access etc still works and that I've not inadvertantly screwed something up and allowed people access to forums that are restricted. So far everything looks good.
I said at the start of this I'd bundle it up as a Mod, but I think this post pretty much covers it off well enough anyway so I won't.
I'll post any errors I encounter here, and if anyone else could do the same that would be appreciated. The clean may not be the best or purest way of doing things as I was really just working in a "proof of concept" mode to see what could be improved. However I'm personally satisfied enough with the savings in roundtrips to the DB that these changes will be going out on my live server as soon as I've finished testing them throughly.
www.daoc-halo.com