Author |
Topic |
|
Dan Martin
Average Member
USA
528 Posts |
Posted - 30 June 2002 : 17:36:03
|
In my inc_functions.asp, I've added a function using code from active.asp to get the number of active topics. It works, except that it shows the number regardless of whether the user has access to the post. If anyone knows how to accomplish that, or already has done it, please let me know. The idea is that my Active Topics link looks like "Active Topics (4)".
Here's the code I used:
function getActiveCount() 'Returns the number of Active Topics dim lastDate if IsEmpty(Session(strCookieURL & "last_here_date")) then Session(strCookieURL & "last_here_date") = ReadLastHereDate(strDBNTUserName) end if lastDate = Session(strCookieURL & "last_here_date") dim strSql dim rs_chk
if mlev = 3 then strSql = "SELECT FORUM_ID FROM " & strTablePrefix & "MODERATOR " & _ " WHERE MEMBER_ID = " & getNewMemberNumber() Set rsMod = Server.CreateObject("ADODB.Recordset") rsMod.open strSql, my_Conn if RsMod.EOF or RsMod.BOF then ' Do Nothing - User is not an active moderator else modcount = 0 ModOfForums = "(" do until RsMod.EOF modcount = modcount + 1 if modcount > 1 then ModOfForums = ModOfForums & ", " end if ModOfForums = ModOfForums & rsmod("FORUM_ID") RsMod.MoveNext loop ModOfForums = ModOfForums & ")" end if RsMod.close set RsMod = nothing end if '## Forum_SQL strSql = "SELECT COUNT(*) as activeCount " &_ "FROM " & strMemberTablePrefix & "MEMBERS M, " &_ strTablePrefix & "FORUM F, " &_ strTablePrefix & "TOPICS T, " &_ strTablePrefix & "CATEGORY C, " &_ strMemberTablePrefix & "MEMBERS MEMBERS_1 " &_ "WHERE T.T_LAST_POST_AUTHOR = MEMBERS_1.MEMBER_ID " &_ "AND F.FORUM_ID = T.FORUM_ID " &_ "AND F.CAT_ID = T.CAT_ID " &_ "AND F.CAT_ID = C.CAT_ID " &_ "AND M.MEMBER_ID = T.T_AUTHOR " &_ "AND (T.T_LAST_POST > '" & lastDate & "'"
' DEM --> if not an admin, all unapproved posts should not be viewed. if mlev <> 4 then strSql = strSql & " AND ((T.T_AUTHOR <> " & MemberID &_ " AND T.T_STATUS < 2)" ' Ignore unapproved/held posts if mlev = 3 and ModofForums <> "" then strSql = strSql & " OR T.FORUM_ID IN " & ModOfForums end if strSql = strSql & " OR T.T_AUTHOR = " & MemberID & ")" end if strSql = strSql & ") "
Set rs = Server.CreateObject("ADODB.Recordset") rs.open strSql, my_Conn If NOT rs.EOF Then getActiveCount = rs("activeCount") End If rs.close set rs = nothing end function
Thanks, Dan
|
|
ruirib
Snitz Forums Admin
Portugal
26364 Posts |
Posted - 30 June 2002 : 18:06:41
|
Check inc_jump_to.asp. There is code there to show only the forums to which the user has access to. Maybe you can get some inspiration to help you with the current problem.
I've also seem the exact same feature in HuwR's and Crash's sites. You can try to download their forum's code and check on how they do it.
------------------------------------------------- Installation Guide | Do's and Dont's | MODs |
|
|
blackinwhite
Average Member
Turkey
657 Posts |
Posted - 30 June 2002 : 18:54:08
|
quote:
Check inc_jump_to.asp. There is code there to show only the forums to which the user has access to. Maybe you can get some inspiration to help you with the current problem.
I've also seem the exact same feature in HuwR's and Crash's sites. You can try to download their forum's code and check on how they do it.
------------------------------------------------- Installation Guide | Do's and Dont's | MODs
Huwr's and Crash's codes use "Slash Mod" and it shows all the active topics regardless of user accesses.
|
|
|
ruirib
Snitz Forums Admin
Portugal
26364 Posts |
Posted - 30 June 2002 : 19:05:20
|
quote:
Huwr's and Crash's codes use "Slash Mod" and it shows all the active topics regardless of user accesses.
Ok, I wasn't sure about that, thanks for the info.
------------------------------------------------- Installation Guide | Do's and Dont's | MODs |
|
|
Dan Martin
Average Member
USA
528 Posts |
Posted - 14 July 2002 : 20:47:23
|
I think I figured it out. In case anyone else wants to change their Active Topics to look like "Active Topics(4)", the function I ended up with is:
function getActiveCount() 'Returns the number of Active Topics dim lastDate if IsEmpty(Session(strCookieURL & "last_here_date")) then Session(strCookieURL & "last_here_date") = ReadLastHereDate(strDBNTUserName) end if lastDate = Session(strCookieURL & "last_here_date") dim strSql dim rs_chk
if mlev = 3 then strSql = "SELECT FORUM_ID FROM " & strTablePrefix & "MODERATOR " & _ " WHERE MEMBER_ID = " & getNewMemberNumber() Set rsMod = Server.CreateObject("ADODB.Recordset") rsMod.open strSql, my_Conn if RsMod.EOF or RsMod.BOF then ' Do Nothing - User is not an active moderator else modcount = 0 ModOfForums = "(" do until RsMod.EOF modcount = modcount + 1 if modcount > 1 then ModOfForums = ModOfForums & ", " end if ModOfForums = ModOfForums & rsmod("FORUM_ID") RsMod.MoveNext loop ModOfForums = ModOfForums & ")" end if RsMod.close set RsMod = nothing end if '## Forum_SQL strSql = "SELECT COUNT(*) as activeCount " &_ "FROM " & strMemberTablePrefix & "MEMBERS M, " &_ strTablePrefix & "FORUM F, " &_ strTablePrefix & "TOPICS T, " &_ strTablePrefix & "CATEGORY C, " &_ strMemberTablePrefix & "MEMBERS MEMBERS_1 " &_ "WHERE T.T_LAST_POST_AUTHOR = MEMBERS_1.MEMBER_ID " &_ "AND F.FORUM_ID = T.FORUM_ID " &_ "AND F.CAT_ID = T.CAT_ID " &_ "AND F.CAT_ID = C.CAT_ID " &_ "AND M.MEMBER_ID = T.T_AUTHOR " if mlev < 4 then 'Limit to FORUMS that the user has access to. forumSQL = "SELECT FORUM_ID " & _ " FROM " & strTablePrefix & "FORUM " set rsForum = my_Conn.Execute (forumSql) if rsForum.eof or rsForum.bof then 'nothing else i = 0 do until rsForum.Eof ForumID = rsForum("FORUM_ID") if ChkForumAccess(ForumID, getNewMemberNumber()) then i = i + 1 if i = 1 Then strSql = strSql & " AND (" else strSql = strSql & " OR " end If strSQL = strSQL & "F.FORUM_ID=" & ForumID end if rsForum.MoveNext loop rsForum.close set rsForum = Nothing if i > 0 Then strSql = strSql & ") " end If end if end If strSql = strSql & "AND (T.T_LAST_POST > '" & lastDate & "'"
' DEM --> if not an admin, all unapproved posts should not be viewed. if mlev <> 4 then strSql = strSql & " AND ((T.T_AUTHOR <> " & MemberID &_ " AND T.T_STATUS < 2)" ' Ignore unapproved/held posts if mlev = 3 and ModofForums <> "" then strSql = strSql & " OR T.FORUM_ID IN " & ModOfForums end if strSql = strSql & " OR T.T_AUTHOR = " & MemberID & ")" end if strSql = strSql & ") "
Set rs = Server.CreateObject("ADODB.Recordset") rs.open strSql, my_Conn If NOT rs.EOF Then getActiveCount = rs("activeCount") End If rs.close set rs = nothing end function
I was a bit worried about all that occuring on every page hit, but I really haven't noticed an impact. If anyone sees anything wrong with that function, let me know. I honestly hacked it together.
|
|
|
Dan Martin
Average Member
USA
528 Posts |
Posted - 14 July 2002 : 20:52:09
|
Also, thanks go to ruirib for his suggestion. The code from inc_jump_to.asp is what I used to limit the forums to those someone has access to. Well, actually I changed it quite a bit, but it was definitely the starting point.
Edited by - Dan Martin on 14 July 2002 20:56:55 |
|
|
ruirib
Snitz Forums Admin
Portugal
26364 Posts |
Posted - 14 July 2002 : 21:41:06
|
Well, glad to know that the info was useful to you. And that surely your mod brings an interesting change, because I think the usual versions of similar mods fail exactly where this one does not fail: counting only the topics the user has access to.
------------------------------------------------- Installation Guide | Do's and Dont's | MODs |
|
|
dayve
Forum Moderator
USA
5820 Posts |
Posted - 14 July 2002 : 22:54:48
|
good job Dan, after looking at your code I then realized that the version I made was innacurate... I am now using your version instead.
http://www.nineinchnailz.com |
|
|
dayve
Forum Moderator
USA
5820 Posts |
Posted - 16 July 2002 : 22:45:46
|
I don't know if this would be considered a bug, BUT... if you change the active topics dropdown to anything other than Last Visit, the active topics number does not change. would that be considered normal or logical?
http://www.nineinchnailz.com |
|
|
Dan Martin
Average Member
USA
528 Posts |
Posted - 17 July 2002 : 00:26:15
|
One could argue either way, but why not post both?
function getActiveCount() 'Returns the number of Active Topics ActiveSince = Request.Cookies(strCookieURL & "ActiveSince") '## Do Cookie stuffs with show last date if Request.form("cookie") = "2" then ActiveSince = Request.Form("ShowSinceDateTime") if strSetCookieToForum = 1 then Response.Cookies(strCookieURL & "ActiveSince").Path = strCookieURL end if Response.Cookies(strCookieURL & "ActiveSince") = ActiveSince end if Select Case ActiveSince Case "LastVisit" lastDate = "" Case "LastFifteen" lastDate = DateToStr(DateAdd("n",-15,strForumTimeAdjust)) Case "LastThirty" lastDate = DateToStr(DateAdd("n",-30,strForumTimeAdjust)) Case "LastFourtyFive" lastDate = DateToStr(DateAdd("n",-45,strForumTimeAdjust)) Case "LastHour" lastDate = DateToStr(DateAdd("h",-1,strForumTimeAdjust)) Case "TwoHour" lastDate = DateToStr(DateAdd("h",-2,strForumTimeAdjust)) Case "LastDay" lastDate = DateToStr(DateAdd("d",-1,strForumTimeAdjust)) Case "LastWeek" lastDate = DateToStr(DateAdd("ww",-1,strForumTimeAdjust)) Case "LastMonth" lastDate = DateToStr(DateAdd("m",-1,strForumTimeAdjust)) Case Else lastDate = "" End Select if IsEmpty(Session(strCookieURL & "last_here_date")) then Session(strCookieURL & "last_here_date") = ReadLastHereDate(strDBNTUserName) end if if lastDate = "" then lastDate = Session(strCookieURL & "last_here_date") end if if Request.Form("AllRead") = "Y" then Session(strCookieURL & "last_here_date") = ReadLastHereDate(strDBNTUserName) lastDate = Session(strCookieURL & "last_here_date") ActiveSince = "" end if
dim strSql dim rs_chk
if mlev = 3 then strSql = "SELECT FORUM_ID FROM " & strTablePrefix & "MODERATOR " & _ " WHERE MEMBER_ID = " & getNewMemberNumber() Set rsMod = Server.CreateObject("ADODB.Recordset") rsMod.open strSql, my_Conn if RsMod.EOF or RsMod.BOF then ' Do Nothing - User is not an active moderator else modcount = 0 ModOfForums = "(" do until RsMod.EOF modcount = modcount + 1 if modcount > 1 then ModOfForums = ModOfForums & ", " end if ModOfForums = ModOfForums & rsmod("FORUM_ID") RsMod.MoveNext loop ModOfForums = ModOfForums & ")" end if RsMod.close set RsMod = nothing end if '## Forum_SQL strSql = "SELECT COUNT(*) as activeCount " &_ "FROM " & strMemberTablePrefix & "MEMBERS M, " &_ strTablePrefix & "FORUM F, " &_ strTablePrefix & "TOPICS T, " &_ strTablePrefix & "CATEGORY C, " &_ strMemberTablePrefix & "MEMBERS MEMBERS_1 " &_ "WHERE T.T_LAST_POST_AUTHOR = MEMBERS_1.MEMBER_ID " &_ "AND F.FORUM_ID = T.FORUM_ID " &_ "AND F.CAT_ID = T.CAT_ID " &_ "AND F.CAT_ID = C.CAT_ID " &_ "AND M.MEMBER_ID = T.T_AUTHOR " if mlev < 4 then 'Limit to FORUMS that the user has access to. forumSQL = "SELECT FORUM_ID " & _ " FROM " & strTablePrefix & "FORUM " set rsForum = my_Conn.Execute (forumSql) if rsForum.eof or rsForum.bof then 'nothing else i = 0 do until rsForum.Eof ForumID = rsForum("FORUM_ID") if ChkForumAccess(ForumID, getNewMemberNumber()) then i = i + 1 if i = 1 Then strSql = strSql & " AND (" else strSql = strSql & " OR " end If strSQL = strSQL & "F.FORUM_ID=" & ForumID end if rsForum.MoveNext loop rsForum.close set rsForum = Nothing if i > 0 Then strSql = strSql & ") " end If end if end If strSql = strSql & "AND (T.T_LAST_POST > '" & lastDate & "'"
' DEM --> if not an admin, all unapproved posts should not be viewed. if mlev <> 4 then strSql = strSql & " AND ((T.T_AUTHOR <> " & MemberID &_ " AND T.T_STATUS < 2)" ' Ignore unapproved/held posts if mlev = 3 and ModofForums <> "" then strSql = strSql & " OR T.FORUM_ID IN " & ModOfForums end if strSql = strSql & " OR T.T_AUTHOR = " & MemberID & ")" end if strSql = strSql & ") "
Set rs = Server.CreateObject("ADODB.Recordset") rs.open strSql, my_Conn If NOT rs.EOF Then getActiveCount = rs("activeCount") End If rs.close set rs = nothing end function
|
|
|
Dan Martin
Average Member
USA
528 Posts |
Posted - 17 July 2002 : 00:27:44
|
Do you think I should re-post this in the MOD W/Code forum?
|
|
|
Dan Martin
Average Member
USA
528 Posts |
Posted - 17 July 2002 : 00:35:52
|
Wow, that works even better than I had relized. Once you change the "Active Topics Since" dropdown, the function continues to show the new count. Even if you view other pages, and even if you leave the site, and come back.
I guess it makes sense that way? I think it does now that I'm using it.
|
|
|
dayve
Forum Moderator
USA
5820 Posts |
|
Dan Martin
Average Member
USA
528 Posts |
Posted - 17 July 2002 : 00:52:34
|
LOL, I check Burning Souls and the code is running 20 minutes after I posted. I knew you had it there before I saw your reply here.
|
|
|
dayve
Forum Moderator
USA
5820 Posts |
Posted - 17 July 2002 : 00:55:25
|
quote:
LOL, I check Burning Souls and the code is running 20 minutes after I posted. I knew you had it there before I saw your reply here.
hey, I know what I like :)
http://www.nineinchnailz.com |
|
|
Dan Martin
Average Member
USA
528 Posts |
|
|
Topic |
|