%
'#################################################################################
'## Copyright (C) 2000-01 Michael Anderson and Pierre Gorissen
'## 
'## This program is free software; you can redistribute it and/or
'## modify it under the terms of the GNU General Public License
'## as published by the Free Software Foundation; either version 2
'## of the License, or any later version.
'##
'## All copyright notices regarding Snitz Forums 2000
'## must remain intact in the scripts and in the outputted HTML
'## The "powered by" text/logo with a link back to 
'## http://forum.snitz.com in the footer of the pages MUST
'## remain visible when the pages are viewed on the internet or intranet.
'## 
'## This program is distributed in the hope that it will be useful,
'## but WITHOUT ANY WARRANTY; without even the implied warranty of
'## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'## GNU General Public License for more details.
'## 
'## You should have received a copy of the GNU General Public License
'## along with this program; if not, write to the Free Software
'## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
'## 
'## Support can be obtained from support forums at:
'## http://forum.snitz.com 
'##
'## Correspondence and Marketing Questions can be sent to:
'## reinhold@bigfoot.com
'## 
'## or
'## 
'## Snitz Communications 
'## C/O: Michael Anderson
'## PO Box 200
'## Harpswell, ME 04079
'#################################################################################
%>
<%
'## Do Cookie stuffs with reload
nRefreshTime = Request.Cookies(strCookieURL & "Reload")
if Request.form("cookie") = "1" then
    if strSetCookieToForum = 1 then	
      Response.Cookies(strCookieURL & "Reload").Path = strCookieURL
	end if
	Response.Cookies(strCookieURL & "Reload") = Request.Form("RefreshTime")
	Response.Cookies(strCookieURL & "Reload").expires = strForumTimeAdjust + 365
	nRefreshTime = Request.Form("RefreshTime")
end if
if nRefreshTime = "" then
	nRefreshTime = 0
end if
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)
	Session(strCookieURL & "last_here_date") = ReadLastHereDate(strDBNTUserName)
	lastDate = Session(strCookieURL & "last_here_date")
	ActiveSince = ""
end if
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 - Get all active topics from last visit
strSql = "SELECT F.F_SUBJECT, " &_
	 "F.F_SUBSCRIPTION,  "  &_
	 "F.F_STATUS, "  &_
	 "F.F_ORDER, "  &_
	 "C.CAT_SUBSCRIPTION, "  &_
	 "C.CAT_STATUS, "  &_
	 "C.CAT_ORDER, "  &_
	 "T.T_STATUS, "  &_
	 "T.T_VIEW_COUNT, "  &_
	 "T.FORUM_ID, "  &_
	 "T.TOPIC_ID, "  &_
	 "T.CAT_ID, "  &_
	 "T.T_SUBJECT, "  &_
	 "T.T_AUTHOR, "  &_
	 "T.T_REPLIES, "  &_
	 "M.M_NAME, "  &_
	 "T.T_LAST_POST_AUTHOR, "   &_
	 "T.T_LAST_POST, "  &_
	 "MEMBERS_1.M_NAME AS LAST_POST_AUTHOR_NAME "  &_
	 "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 & ") "
	strSql = strSql & " ORDER BY C.CAT_ORDER, F.F_ORDER, T.T_LAST_POST DESC;"
	Set rs = Server.CreateObject("ADODB.Recordset")
	rs.open strSql, my_Conn
' Sets up the Tree structure at the top of the page
Response.Write	"
" & vbNewline & _
				"  " & vbNewline & _
				"    | " & vbNewline & _
				"" & vbNewline & _
				" | " & vbNewline & _
				" | " & vbNewline & _
				"		" & vbNewline & _
				"" & vbNewline & _
				" | 
" & vbNewline & _
				"
" & vbNewline
'### Start to build the table
Response.Write	"" & _
				"  " & vbNewline & _
				"	  | " & vbNewline & _
				" " & vbNewline & _
				"" & vbNewline & _
				"			" & vbNewline & _
				"" & vbNewline & _
				"				" & vbNewline 
if rs.EOF or rs.BOF then
	Response.Write	"| " & vbNewline
If not(rs.EOF or rs.BOF) and (mLev > 0) then 
	Response.Write	"" & vbNewline
else 
	Response.Write "			 " & vbNewline
end if
Response.Write	" | " & vbNewline & _
				"		Topic" & vbNewline & _
				"" & vbNewline & _
				" | " & vbNewline & _
				"		Author" & vbNewline & _
				"" & vbNewline & _
				" | " & vbNewline & _
				"		Replies" & vbNewline & _
				"" & vbNewline & _
				" | " & vbNewline & _
				"		Read" & vbNewline & _
				"" & vbNewline & _
				" | " & vbNewline & _
				"		Last Post" & vbNewline & _
				"" & vbNewline
if (mlev > 0) then
	Response.Write	" | " & vbNewline
end if
Response.Write	" |  " & vbNewline & _
					"		" & vbNewline
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??
		if ChkForumAccess(Forum_ID, getNewMemberNumber()) then
			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
			fDisplayCount = fDisplayCount + 1
			' -- Display forum name
			if currForum <> Forum_ID then
				Response.Write	"| " & vbNewline & _
					"			" & _
					"No Active Topics Found" & vbNewline & _
					"" & vbNewline
	Response.Write	" |  " & vbNewline & _
								"		" & vbNewline
			end if 
			Response.Write	"| " & vbNewline & _
								"			" & _
								"" & _
								ChkString(Forum_Subject,"display") & "" & vbNewline & _
								"			" & vbNewline & _
								"" & vbNewline
				if (mlev > 0) then 
					Response.Write	" | "
					if (AdminAllowed = 1) or (lcase(strNoCookies) = "1") then
						ForumAdminOptions()
					else
						ForumMemberOptions()
					end if 
					Response.Write	"" & vbNewline
				elseif (mLev = 3) then
					Response.Write	" | " & vbNewline
				end if
				Response.Write	" |  " & vbNewline
			Response.Write	"		" & vbNewline
		end if	
		currForum = Forum_ID
		rs.MoveNext 
	loop 
	if fDisplayCount = 0 then 
		Response.Write	"| "
			' -- Set up a link to the topic and display the icon appropriate to the status of the post.
			Response.Write ""
			' - If status = 0, topic/forum/category is locked.  If status > 2, posts are unmoderated/rejected
			if CatStatus <> 0 and ForumStatus <> 0 and Topic_Status <> 0 then
				' DEM --> Added code for topic moderation
				if Topic_Status = 2 then
					Response.Write 	" " & vbNewline
			Response.Write	"![]() " & vbNewline
				elseif Topic_Status = 3 then
					Response.Write " ![]() " & vbNewline
					' DEM --> end of code Added for topic moderation
				elseif lcase(strHotTopic) = "1" and Topic_Replies >= intHotTopicNum Then 
					Response.Write	" ![]() " & vbNewline
				else
					Response.Write	" ![]() " & vbNewline
				end if
			else 
				Response.Write	" ![]() " & vbNewline
			end if
			Response.Write	" | " & vbNewline & _
							"			" & _
							ChkString(left(Topic_Subject, 50),"display") & _
							" " & vbNewline
			if strShowPaging = "1" then 
				TopicPaging() 
			end if
			Response.Write	"" & vbNewline
			Response.Write	" | " & ChkString(Member_Name,"display") & "" & vbNewline
			Response.Write	" | " & Topic_Replies & "" & vbNewline
			Response.Write	" | " & Topic_View_Count & "" & vbNewline
			if IsNull(Topic_Last_Post_Author) then
				strLastAuthor = ""
			else
				strLastAuthor = " | by: " 
				if strUseExtendedProfile then
					strLastAuthor = strLastAuthor & ""
				else
					strLastAuthor = strLastAuthor & ""
				end if
				strLastAuthor = strLastAuthor & Topic_Last_Post_Author_Name & ""
			end if
			Response.Write	"
 " & ChkDate(Topic_Last_Post) & " " & _
							ChkTime(Topic_Last_Post) & strLastAuthor & "" & vbNewline
			if (mlev > 0) then 
				Response.Write	" | "
					if (AdminAllowed = 1) or (lcase(strNoCookies) = "1") then
						call TopicAdminOptions
					else
						call TopicMemberOptions
					end if
				Response.Write	"			" & vbNewline & _
								"" & vbNewline
			elseif (mLev = 3) then
				Response.Write	" | " & vbNewline
			end if 
			Response.Write	" |  " & vbNewline & _
						"		" & vbNewline & _
				"| " & vbNewline & _
						"			No Active Topics Found" & vbNewline & _
						"" & vbNewline
		if (AdminAllowed = 1) or (lcase(strNoCookies) = "1") then
			Response.Write	" | " & vbNewline 
		end if
	end if 
 end if 
rs.Close
Set rs = nothing
Response.Write	" |  | 
" & vbNewline & _
				"
" & vbNewline
Response.Write	"" & vbNewline & _
				"	" & vbNewline & _
				"		| " & vbNewline
%>
    
<%
Response.Write 	"" & vbNewline & _
				" | 
" & vbNewline & _
				"
" & vbNewline
%>
<% WriteFooter
sub ForumAdminOptions() 
	if (AdminAllowed = 1) or (lcase(strNoCookies) = "1") then 
		if CatStatus = 0 then 
			if mlev = 4 then 
				Response.Write	"    ![]() " & vbNewline
			else 
				Response.Write	"
" & vbNewline
			else 
				Response.Write	"    ![]() " & vbNewline
			end if 
		else 
			if ForumStatus <> 0 then 
				Response.Write	"    " & _
								"
" & vbNewline
			end if 
		else 
			if ForumStatus <> 0 then 
				Response.Write	"    " & _
								"![]() " & vbNewline
			else 
				Response.Write	"    " & _
								"
" & vbNewline
			else 
				Response.Write	"    " & _
								"![]() " & vbNewline
			end if 
		end if 
		if (CatStatus <> 0 and ForumStatus <> 0) or (AdminAllowed = 1) then 
			Response.Write	"    " & _
							"
" & vbNewline
			end if 
		end if 
		if (CatStatus <> 0 and ForumStatus <> 0) or (AdminAllowed = 1) then 
			Response.Write	"    " & _
							"![]() " & vbNewline
		end if
		Response.Write	"    " & _
						"
" & vbNewline
		end if
		Response.Write	"    " & _
						"![]() "
		Response.Write	"    " & _
						"
"
		Response.Write	"    " & _
						"![]() "
	    ' DEM --> Start of Code added for Full Moderation
		if (CheckForUnModeratedPosts("FORUM", Cat_ID, Forum_ID, 0) > 0) then
			QString = "FORUM_ID=" & Forum_ID & "&CAT_ID=" & Cat_ID
			Response.Write	"
"
	    ' DEM --> Start of Code added for Full Moderation
		if (CheckForUnModeratedPosts("FORUM", Cat_ID, Forum_ID, 0) > 0) then
			QString = "FORUM_ID=" & Forum_ID & "&CAT_ID=" & Cat_ID
			Response.Write	" ![]() " & vbNewline
		end if
		' DEM --> End of Code added for Full Moderation
 		' DEM --> Start of Code added to handle subscription processing.
		if (strSubscription < 4 and strSubscription > 0) and (CatSubscription > 0) and ForumSubscription = 1 then
			CheckSubscription "FORUMNOTEXT", getMemberNumber(strDBNTUserName), Cat_ID, Forum_ID, 0, "", ""
		end if 
	end if 
end sub
sub ForumMemberOptions() 
	if (mlev > 0) then 
		Response.Write	"    " & _
						"
" & vbNewline
		end if
		' DEM --> End of Code added for Full Moderation
 		' DEM --> Start of Code added to handle subscription processing.
		if (strSubscription < 4 and strSubscription > 0) and (CatSubscription > 0) and ForumSubscription = 1 then
			CheckSubscription "FORUMNOTEXT", getMemberNumber(strDBNTUserName), Cat_ID, Forum_ID, 0, "", ""
		end if 
	end if 
end sub
sub ForumMemberOptions() 
	if (mlev > 0) then 
		Response.Write	"    " & _
						"![]() "
 		' DEM --> Start of Code added to handle subscription processing.
	        if (strSubscription > 0 and strSubscription < 4) and CatSubscription > 0 and ForumSubscription = 1 then
			CheckSubscription "FORUMNOTEXT", MemberID, Cat_ID, Forum_ID, -1, "", ""
        	end if
	end if 
end sub
sub TopicAdminOptions()
				if CatStatus = 0 then
					Response.Write	"		" & _
									"
"
 		' DEM --> Start of Code added to handle subscription processing.
	        if (strSubscription > 0 and strSubscription < 4) and CatSubscription > 0 and ForumSubscription = 1 then
			CheckSubscription "FORUMNOTEXT", MemberID, Cat_ID, Forum_ID, -1, "", ""
        	end if
	end if 
end sub
sub TopicAdminOptions()
				if CatStatus = 0 then
					Response.Write	"		" & _
									"![]() "
				elseif ForumStatus = 0 then 
					Response.Write	"		" & _
									"
"
				elseif ForumStatus = 0 then 
					Response.Write	"		" & _
									"![]() " 
				elseif Topic_Status <> 0 then 
					' DEM --> Added code to allow for moderation
					if Topic_Status >= 2 or _ 
					   (CheckForUnModeratedPosts("TOPIC", Cat_ID, Forum_ID, Topic_ID) > 0) then
						ModString = "CAT_ID=" & Cat_ID & "&FORUM_ID=" & Forum_ID & "&TOPIC_ID=" & _
									Topic_ID & "&REPLY_ID=X"
						Response.Write "
" 
				elseif Topic_Status <> 0 then 
					' DEM --> Added code to allow for moderation
					if Topic_Status >= 2 or _ 
					   (CheckForUnModeratedPosts("TOPIC", Cat_ID, Forum_ID, Topic_ID) > 0) then
						ModString = "CAT_ID=" & Cat_ID & "&FORUM_ID=" & Forum_ID & "&TOPIC_ID=" & _
									Topic_ID & "&REPLY_ID=X"
						Response.Write " ![]() = 2 then
							Response.Write "alt=""Approve/Hold/Reject Topic"""
						else
							Response.Write "alt=""Approve/Hold/Reject Replies to Topic"""
						end if
						Response.Write " height=15 width=15 border=0>" & vbNewline
					else ' DEM --> End of Code added for topic moderation
						Response.Write "
= 2 then
							Response.Write "alt=""Approve/Hold/Reject Topic"""
						else
							Response.Write "alt=""Approve/Hold/Reject Replies to Topic"""
						end if
						Response.Write " height=15 width=15 border=0>" & vbNewline
					else ' DEM --> End of Code added for topic moderation
						Response.Write "![]() "
					end if
				else
					Response.Write	"		" & _
									"
"
					end if
				else
					Response.Write	"		" & _
									"![]() "
				end if 
				if	(AdminAllowed = 1) or _
					(CatStatus <> 0 and ForumStatus <> 0 and Topic_Status <> 0) then 
					Response.Write	"		" & _
									"
"
				end if 
				if	(AdminAllowed = 1) or _
					(CatStatus <> 0 and ForumStatus <> 0 and Topic_Status <> 0) then 
					Response.Write	"		" & _
									"![]() "
				end if 
			    	' DEM --> Start of Code added for Full Moderation
'				if (AdminAllowed = 1 and CheckForUnModeratedPosts("TOPIC", Cat_ID, Forum_ID, Topic_ID) > 0) then
'					TopicString = "TOPIC_ID=" & Topic_ID & "&FORUM_ID=" & Forum_ID & "&CAT_ID=" & Cat_ID & "&REPLY_ID=X"
'					Response.Write "
"
				end if 
			    	' DEM --> Start of Code added for Full Moderation
'				if (AdminAllowed = 1 and CheckForUnModeratedPosts("TOPIC", Cat_ID, Forum_ID, Topic_ID) > 0) then
'					TopicString = "TOPIC_ID=" & Topic_ID & "&FORUM_ID=" & Forum_ID & "&CAT_ID=" & Cat_ID & "&REPLY_ID=X"
'					Response.Write " ![]() " & vbNewline
'				End if
				' DEM --> End of Code added for Full Moderation 
				Response.Write	"		" & _
								"
" & vbNewline
'				End if
				' DEM --> End of Code added for Full Moderation 
				Response.Write	"		" & _
								"![]() "
				if Topic_Status <= 1 then
					Response.Write 		"		" & _
								"
"
				if Topic_Status <= 1 then
					Response.Write 		"		" & _
								"![]() "
				end if
				' DEM --> Start of Code added to handle subscription processing.
		    		if (strSubscription < 4 and strSubscription > 0) and (CatSubscription > 0) and ForumSubscription > 0 then
					CheckSubscription "TOPICNOTEXT", MemberID, Cat_ID, Forum_ID, Topic_ID, " ", ""
				    end if 
				' DEM --> End of code added to handle subscription processing.
end sub
sub TopicMemberOptions()
		    if Topic_Status <= 1 then
				Response.Write	"" & _
								"
"
				end if
				' DEM --> Start of Code added to handle subscription processing.
		    		if (strSubscription < 4 and strSubscription > 0) and (CatSubscription > 0) and ForumSubscription > 0 then
					CheckSubscription "TOPICNOTEXT", MemberID, Cat_ID, Forum_ID, Topic_ID, " ", ""
				    end if 
				' DEM --> End of code added to handle subscription processing.
end sub
sub TopicMemberOptions()
		    if Topic_Status <= 1 then
				Response.Write	"" & _
								"![]() "
		    end if
		    if (strSubscription < 4 and strSubscription > 0) and (CatSubscription > 0) and ForumSubscription > 0 then
				CheckSubscription "TOPICNOTEXT", MemberID, Cat_ID, Forum_ID, Topic_ID, "", ""
		    end if 
			' DEM --> End of code added to handle subscription processing.
end sub
sub TopicPaging()
   mxpages = (Topic_Replies / strPageSize)
    if mxPages <> cint(mxPages) then
        mxpages = int(mxpages) + 1
    end if
    if mxpages > 1 then
		Response.Write	"
"
		    end if
		    if (strSubscription < 4 and strSubscription > 0) and (CatSubscription > 0) and ForumSubscription > 0 then
				CheckSubscription "TOPICNOTEXT", MemberID, Cat_ID, Forum_ID, Topic_ID, "", ""
		    end if 
			' DEM --> End of code added to handle subscription processing.
end sub
sub TopicPaging()
   mxpages = (Topic_Replies / strPageSize)
    if mxPages <> cint(mxPages) then
        mxpages = int(mxpages) + 1
    end if
    if mxpages > 1 then
		Response.Write	"| " & _
						"" & _
						" "
		for counter = 1 to mxpages
			ref =	"![]() | " & _
					"" 
			if ((mxpages > 9) and (mxpages > strPageNumberSize)) or _
			   ((counter > 9) and (mxpages < strPageNumberSize)) then
				ref = ref & " "
			end if		
			ref = ref & widenum(counter) & "" & counter & ""
			Response.Write ref 
			if counter mod strPageNumberSize = 0 then
				Response.Write(" | 
| ")
			end if
		next				
		Response.Write(" | 
")
	end if
end sub
%>