QuoteReplyTopic: Active Topics Posted: 08 October 2003 at 5:50pm
Hi all...
This isn't really a bug but a question of functionality. The active topics page doesn't show all of the active topics! mainly in the case of forums being locked for members (registered users) only.
What's strange to me is that if i'm logged in as a member, i should be able to see all of the posts that i have access to... not just the ones that the "guests" can see...
Well i found some mods that were supposed to do this but they just went and grabbed the group permissions and didn't take into account "guest" (read = 1) "members" (read<=2) and "admin" (read=all) in the forums themselves.
so i decided to work out some fancy SQL statement that would fix it... and it works great! (passing in the userID and the ActiveFrom)
CREATE PROCEDURE [dbo].[wwfspActiveTopics] ( @AuthorID int, @dblActiveFrom int ) as
set nocount on
IF @AuthorID = 1 --admin (get everything) SELECT --dbo.tblCategory.Cat_ID AS Cat_ID,dbo.tblCategory.Cat_name AS Cat_name, dbo.tblForum.Forum_name AS Forum_name, dbo.tblForum.Password AS Password, dbo.tblForum.Forum_code AS Forum_code, dbo.tblForum.[Read] AS [Read], dbo.tblTopic.* FROM dbo.tblCategory RIGHT OUTER JOIN dbo.tblForum ON dbo.tblCategory.Cat_ID = dbo.tblForum.Cat_ID RIGHT OUTER JOIN dbo.tblTopic ON dbo.tblForum.Forum_ID = dbo.tblTopic.Forum_ID WHERE AND (tblTopic.Last_entry_date > GetDate() - @dblActiveFrom ) ORDER BY tblCategory.Cat_order ASC, tblForum.Forum_Order ASC, tblTopic.Last_entry_date DESC
ELSE IF @AuthorID = 2 --guest (only get read = 1 for all) SELECT --dbo.tblCategory.Cat_ID AS Cat_ID,dbo.tblCategory.Cat_name AS Cat_name, dbo.tblForum.Forum_name AS Forum_name, dbo.tblForum.Password AS Password, dbo.tblForum.Forum_code AS Forum_code, dbo.tblForum.[Read] AS [Read], dbo.tblTopic.* FROM dbo.tblCategory RIGHT OUTER JOIN dbo.tblForum ON dbo.tblCategory.Cat_ID = dbo.tblForum.Cat_ID RIGHT OUTER JOIN dbo.tblTopic ON dbo.tblForum.Forum_ID = dbo.tblTopic.Forum_ID WHERE (tblForum.[Read] = 1 OR (tblTopic.Forum_ID in (select Forum_ID from tblPermissions where Author_ID=@AuthorID or Group_ID in (select Group_ID from tblAuthor where Author_ID= @AuthorID) and [Read]=1))) AND (tblTopic.Last_entry_date > GetDate() - @dblActiveFrom ) AND NOT tblForum.Forum_ID in (select Forum_ID from tblPermissions where Author_ID=@AuthorID or Group_ID in (select Group_ID from tblAuthor where Author_ID= @AuthorID) and [Read]=0) ORDER BY tblCategory.Cat_order ASC, tblForum.Forum_Order ASC, tblTopic.Last_entry_date DESC
ELSE IF @AuthorID > 2 --Registered user (only get read =< 2 applies)
SELECT --dbo.tblCategory.Cat_ID AS Cat_ID,dbo.tblCategory.Cat_name AS Cat_name, dbo.tblForum.Forum_name AS Forum_name, dbo.tblForum.Password AS Password, dbo.tblForum.Forum_code AS Forum_code, dbo.tblForum.[Read] AS [Read], dbo.tblTopic.* FROM dbo.tblCategory RIGHT OUTER JOIN dbo.tblForum ON dbo.tblCategory.Cat_ID = dbo.tblForum.Cat_ID RIGHT OUTER JOIN dbo.tblTopic ON dbo.tblForum.Forum_ID = dbo.tblTopic.Forum_ID WHERE (tblForum.[Read] <= 2 OR (tblTopic.Forum_ID in (select Forum_ID from tblPermissions where Author_ID=@AuthorID or Group_ID in (select Group_ID from tblAuthor where Author_ID= @AuthorID) and [Read]<=2))) AND (tblTopic.Last_entry_date > GetDate() - @dblActiveFrom ) AND NOT tblForum.Forum_ID in (select Forum_ID from tblPermissions where Author_ID=@AuthorID or Group_ID in (select Group_ID from tblAuthor where Author_ID= @AuthorID) and [Read]=0) ORDER BY tblCategory.Cat_order ASC, tblForum.Forum_Order ASC, tblTopic.Last_entry_date DESC
ELSE SELECT --dbo.tblCategory.Cat_ID AS Cat_ID,dbo.tblCategory.Cat_name AS Cat_name, dbo.tblForum.Forum_name AS Forum_name, dbo.tblForum.Password AS Password, dbo.tblForum.Forum_code AS Forum_code, dbo.tblForum.[Read] AS [Read], dbo.tblTopic.* FROM dbo.tblCategory RIGHT OUTER JOIN dbo.tblForum ON dbo.tblCategory.Cat_ID = dbo.tblForum.Cat_ID RIGHT OUTER JOIN dbo.tblTopic ON dbo.tblForum.Forum_ID = dbo.tblTopic.Forum_ID WHERE (tblForum.[Read] = 1 OR (tblTopic.Forum_ID in (select Forum_ID from tblPermissions where Author_ID=@AuthorID or Group_ID in (select Group_ID from tblAuthor where Author_ID= @AuthorID) and [Read]=1))) AND (tblTopic.Last_entry_date > GetDate() - @dblActiveFrom ) AND NOT tblForum.Forum_ID in (select Forum_ID from tblPermissions where Author_ID=@AuthorID or Group_ID in (select Group_ID from tblAuthor where Author_ID= @AuthorID) and [Read]=0) ORDER BY tblCategory.Cat_order ASC, tblForum.Forum_Order ASC, tblTopic.Last_entry_date DESC GO
note: that you can add this Stored procedure without too much trouble because of the fact that the original is named wwfspActiveToipcs.
alright... test it in Query Analyzer...
EXECUTE wwfSpActiveTopics '1','1' (admin)
EXECUTE wwfSpActiveTopics '2','1' (guest)
EXECUTE wwfSpActiveTopics '24','1' (a random member)
beautiful!
now fix the ASP to pass the new variable... on line 258 of active_topics.asp, comment out the old one and add the new one: (both lines shown here)
Well borg... i figured out the issue. It has to do with the cursorlocation being set BEFORE the DB was queried (it doesn't work when you put in the actual recordset.open). stupid, i know.
The stored procedures work great now. If you want to use/mod it be my guest.
for those that want to use this... grab the SP from above (all of that works) and modify active_topics.asp (at line 256):
(changes in BLUE, comments in PURPLE)
'Initalise the strSQL variable with an SQL statement to query the database to get the Author and subject from the database for the topic If strDatabaseType = "SQLServer" Then 'strSQL = "EXECUTE " & strDbProc & "ActiveToipcs @dblActiveFrom = " & dblActiveFrom strSQL = "EXECUTE " & strDbProc & "ActiveTopics " & lngLoggedInUserID & "," & dblActiveFrom & "" Else ' all of the Access stuff needs to be fixed... but since i dont use it i dont care. strSQL = "SELECT " & strDbTable & "Forum.Forum_name, " & strDbTable & "Forum.Password, " & strDbTable & "Forum.Forum_code, " & strDbTable & "Forum.[Read], " & strDbTable & "Topic.* " strSQL = strSQL & "FROM " & strDbTable & "Category, " & strDbTable & "Forum, " & strDbTable & "Topic " strSQL = strSQL & "WHERE ((" & strDbTable & "Category.Cat_ID = " & strDbTable & "Forum.Cat_ID AND " & strDbTable & "Forum.Forum_ID = " & strDbTable & "Topic.Forum_ID) AND (" & strDbTable & "Forum.[Read] = True) AND (" & strDbTable & "Topic.Last_entry_date > " & strDatabaseDateFunction & " - " & dblActiveFrom & "))" strSQL = strSQL & "ORDER BY " & strDbTable & "Category.Cat_order ASC, " & strDbTable & "Forum.Forum_Order ASC, " & strDbTable & "Topic.Last_entry_date DESC;" End If
' ADDED BY glyph rsForum.Cursorlocation = 3
'Query the database rsForum.Open strSQL, adoCon
that's it... everything seems to be working like a champ!!!
Hey i tweaked the Stored Procedure a bit I wanted to post it here.
CREATE PROCEDURE [dbo].[wwfspActiveTopics] ( @AuthorID int, @dblActiveFrom int ) as
set nocount on
IF @AuthorID = 1 --admin (get everything) SELECT --dbo.tblCategory.Cat_ID AS Cat_ID,dbo.tblCategory.Cat_name AS Cat_name, dbo.tblForum.Forum_name AS Forum_name, dbo.tblForum.Password AS Password, dbo.tblForum.Forum_code AS Forum_code, dbo.tblForum.[Read] AS [Read], dbo.tblTopic.* FROM dbo.tblCategory RIGHT OUTER JOIN dbo.tblForum ON dbo.tblCategory.Cat_ID = dbo.tblForum.Cat_ID RIGHT OUTER JOIN dbo.tblTopic ON dbo.tblForum.Forum_ID = dbo.tblTopic.Forum_ID WHERE (tblTopic.Last_entry_date > GetDate() - @dblActiveFrom ) ORDER BY tblCategory.Cat_order ASC, tblForum.Forum_Order ASC, tblTopic.Last_entry_date DESC
ELSE IF @AuthorID = 2 --guest (only get read = 1 for all) SELECT --dbo.tblCategory.Cat_ID AS Cat_ID,dbo.tblCategory.Cat_name AS Cat_name, dbo.tblForum.Forum_name AS Forum_name, dbo.tblForum.Password AS Password, dbo.tblForum.Forum_code AS Forum_code, dbo.tblForum.[Read] AS [Read], dbo.tblTopic.* FROM dbo.tblCategory RIGHT OUTER JOIN dbo.tblForum ON dbo.tblCategory.Cat_ID = dbo.tblForum.Cat_ID RIGHT OUTER JOIN dbo.tblTopic ON dbo.tblForum.Forum_ID = dbo.tblTopic.Forum_ID WHERE (tblForum.[Read] = 1 OR (tblTopic.Forum_ID in (select Forum_ID from tblPermissions where Author_ID=@AuthorID or Group_ID in (select Group_ID from tblAuthor where Author_ID= @AuthorID) and [Read]=1))) AND (tblTopic.Last_entry_date > GetDate() - @dblActiveFrom ) AND NOT tblForum.Forum_ID in (select Forum_ID from tblPermissions where Group_ID in (select Group_ID from tblAuthor where Author_ID= @authorID and [Read]=0)) AND NOT tblForum.Forum_ID in (select Forum_ID from tblPermissions where Author_ID = @AuthorID and [Read]=0) ORDER BY tblCategory.Cat_order ASC, tblForum.Forum_Order ASC, tblTopic.Last_entry_date DESC
ELSE IF @AuthorID > 2 --Registered user (get read =< 2 applies)
SELECT --dbo.tblCategory.Cat_ID AS Cat_ID,dbo.tblCategory.Cat_name AS Cat_name, dbo.tblForum.Forum_name AS Forum_name, dbo.tblForum.Password AS Password, dbo.tblForum.Forum_code AS Forum_code, dbo.tblForum.[Read] AS [Read], dbo.tblTopic.* FROM dbo.tblCategory RIGHT OUTER JOIN dbo.tblForum ON dbo.tblCategory.Cat_ID = dbo.tblForum.Cat_ID RIGHT OUTER JOIN dbo.tblTopic ON dbo.tblForum.Forum_ID = dbo.tblTopic.Forum_ID WHERE (tblForum.[Read] <= 2 OR (tblTopic.Forum_ID in (select Forum_ID from tblPermissions where Author_ID=@AuthorID or Group_ID in (select Group_ID from tblAuthor where Author_ID= @AuthorID) and [Read]<=2))) AND (tblTopic.Last_entry_date > GetDate() - @dblActiveFrom ) AND NOT tblForum.Forum_ID in (select Forum_ID from tblPermissions where Group_ID in (select Group_ID from tblAuthor where Author_ID= @authorID and [Read]=0)) AND NOT tblForum.Forum_ID in (select Forum_ID from tblPermissions where Author_ID = @AuthorID and [Read]=0)
ORDER BY tblCategory.Cat_order ASC, tblForum.Forum_Order ASC, tblTopic.Last_entry_date DESC
ELSE SELECT --dbo.tblCategory.Cat_ID AS Cat_ID,dbo.tblCategory.Cat_name AS Cat_name, dbo.tblForum.Forum_name AS Forum_name, dbo.tblForum.Password AS Password, dbo.tblForum.Forum_code AS Forum_code, dbo.tblForum.[Read] AS [Read], dbo.tblTopic.* FROM dbo.tblCategory RIGHT OUTER JOIN dbo.tblForum ON dbo.tblCategory.Cat_ID = dbo.tblForum.Cat_ID RIGHT OUTER JOIN dbo.tblTopic ON dbo.tblForum.Forum_ID = dbo.tblTopic.Forum_ID WHERE (tblForum.[Read] = 1 OR (tblTopic.Forum_ID in (select Forum_ID from tblPermissions where Author_ID=@AuthorID or Group_ID in (select Group_ID from tblAuthor where Author_ID= @AuthorID) and [Read]=1))) AND (tblTopic.Last_entry_date > GetDate() - @dblActiveFrom ) AND NOT tblForum.Forum_ID in (select Forum_ID from tblPermissions where Group_ID in (select Group_ID from tblAuthor where Author_ID= @authorID and [Read]=0)) AND NOT tblForum.Forum_ID in (select Forum_ID from tblPermissions where Author_ID = @AuthorID and [Read]=0) ORDER BY tblCategory.Cat_order ASC, tblForum.Forum_Order ASC, tblTopic.Last_entry_date DESC GO
)
AS
SELECT tblForum.Forum_name, tblForum.Password, tblForum.Forum_code, tblTopic.*
FROM tblCategory, tblForum, tblTopic
WHERE ((tblCategory.Cat_ID = tblForum.Cat_ID AND tblForum.Forum_ID =
tblTopic.Forum_ID) AND (tblTopic.Last_entry_date > GetDate() -
@dblActiveFrom))
AND (tblForum.[Read] <= @GroupPerm OR (tblTopic.Forum_ID IN (
SELECT tblPermissions.Forum_ID
FROM tblPermissions
WHERE tblPermissions.Author_ID = @AuthorID OR
tblPermissions.Group_ID = @GroupID AND tblPermissions.[Read]=1))
)
ORDER BY tblCategory.Cat_order ASC, tblForum.Forum_Order ASC, tblTopic.Last_entry_date DESC;
GO
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum
Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.
Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.