<%
'#################################################################################
'## Copyright (C) 2000  Michael Anderson
'## 
'## 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.
'## 
'## 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.
'## 
'## Correspondence and Questions can be sent to:
'## reinhold@bigfoot.com
'## 
'## or
'## 
'## Snitz Communications 
'## C/O: Michael Anderson
'## PO Box 200
'## Harpswell, ME 04079
'#################################################################################
%>
<!--#INCLUDE FILE="config.asp" --> 
<!--#INCLUDE FILE="inc_functions.asp" --> 
<!--#INCLUDE FILE="inc_top_short.asp" -->
<% 
if Request.QueryString("mode") = "DeleteReply" then 
	mLev = cint(ChkUser3(Request.Form("User"), Request.Form("Pass"), Request.Form("REPLY_ID"))) 
	if mLev > 0 then  '## is Member
	  if (chkForumModerator(Request.Form("FORUM_ID"), Request.Form("User")) = "1") or (mLev = 1) or (mLev = 4) or (chkForumModerator(Request.Form("FORUM_ID"), session("userid")) = "1") then '## is Allowed

			'## Forum_SQL - Delete reply
			strSql = "DELETE FROM " & strTablePrefix & "REPLY "
			strSql = strSql & " WHERE " & strTablePrefix & "REPLY.REPLY_ID = " & Request.Form("REPLY_ID")

			my_Conn.Execute strSql

			'## Forum_SQL - Decrease count of total replies in Forum by 1
			strSql =  "UPDATE " & strTablePrefix & "FORUM "
			strSql = strSql & " SET " & strTablePrefix & "FORUM.F_COUNT = " & strTablePrefix & "FORUM.F_COUNT - " & 1
			strSql = strSql & " WHERE " & strTablePrefix & "FORUM.FORUM_ID = " & Request.Form("FORUM_ID")

			my_Conn.Execute strSql

			'## FORUM_SQL - Decrease count of replies to individual topic by 1
			strSql = "UPDATE " & strTablePrefix & "TOPICS "
			strSql = strSql & " SET " & strTablePrefix & "TOPICS.T_REPLIES = " & strTablePrefix & "TOPICS.T_REPLIES - " & 1
			strSql = strSql & " WHERE " & strTablePrefix & "TOPICS.TOPIC_ID = " & Request.Form("TOPIC_ID")

			my_Conn.Execute strSql

			'## FORUM_SQL - Decrease count of total replies in Totals table by 1
			strSql = "UPDATE " & strTablePrefix & "TOTALS "
			strSql = strSql & " SET " & strTablePrefix & "TOTALS.P_COUNT = " & strTablePrefix & "TOTALS.P_COUNT - " & 1

			my_Conn.Execute strSql
%>
<P><font face="<% =strDefaultFontFace %>" size="<% =strHeaderFontSize %>">Reply Deleted!</font></p>
<P>(<font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>">Remember to Refresh your browser.</font>)</p>
<%		Else %>
<P><font face="<% =strDefaultFontFace %>" size="<% =strHeaderFontSize %>">No Permissions to Delete Reply</p>
<p><font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>"><a href="JavaScript: onClick= history.go(-1)">Go Back to Re-Authenticate</a></font></p>
<%		end if %>
<%	Else %>
<P><font face="<% =strDefaultFontFace %>" size="<% =strHeaderFontSize %>">No Permissions to Delete Reply</p>
<p><font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>"><a href="JavaScript: onClick= history.go(-1)">Go Back to Re-Authenticate</a></font></p>
<%	end if

else
	if Request.QueryString("mode") = "DeleteTopic" then
		mLev = cint(ChkUser2(Request.Form("User"), Request.Form("Pass"))) 
		if mLev > 0 then  '## is Member
			if (chkForumModerator(Request.Form("FORUM_ID"), Request.Form("User")) = "1") or (mLev = 4) or (chkForumModerator(Request.Form("FORUM_ID"), session("userid")) = "1") then
				delAr = split(Request.Form("TOPIC_ID"), ",")
				for i = 0 to ubound(delAr) 

					'## Forum_SQL - count total number of replies of TOPIC_ID  in Reply table
					set rs = Server.CreateObject("ADODB.Recordset")
					strSql = "SELECT count(" & strTablePrefix & "REPLY.REPLY_ID) AS cnt "
					strSql = strSql & " FROM " & strTablePrefix & "REPLY "
					strSql = strSql & " WHERE " & strTablePrefix & "REPLY.TOPIC_ID = " & cint(delAr(i))	

					rs.Open strSql, my_Conn
					risposte = rs("cnt")
					rs.close
					set rs = nothing

					'## Forum_SQL - Delete the actual topics
					strSql = "DELETE FROM " & strTablePrefix & "TOPICS "
					strSql = strSql & " WHERE " & strTablePrefix & "TOPICS.TOPIC_ID = " & cint(delAr(i))

					my_Conn.Execute strSql
					
					'## Forum_SQL - Delete all replys related to the topics
					strSql = "DELETE FROM " & strTablePrefix & "REPLY "
					strSql = strSql & " WHERE " & strTablePrefix & "REPLY.TOPIC_ID = " & cint(delAr(i))

					my_Conn.Execute strSql

					'## Forum_SQL - Update count of replies to a topic in Forum table
					strSql = "UPDATE " & strTablePrefix & "FORUM "
					strSql = strSql & " SET " & strTablePrefix & "FORUM.F_COUNT = " & strTablePrefix & "FORUM.F_COUNT - " & cint(risposte) + 1
					strSql = strSql & " ,   " & strTablePrefix & "FORUM.F_TOPICS = " & strTablePrefix & "FORUM.F_TOPICS - " & 1
					strSql = strSql & " WHERE " & strTablePrefix & "FORUM.FORUM_ID = " & Request.Form("FORUM_ID")

					my_Conn.Execute strSql  			        
					'## Forum_SQL - Update total TOPICS in Totals table
					strSql = "UPDATE " & strTablePrefix & "TOTALS "
					strSql = strSql & " SET " & strTablePrefix & "TOTALS.T_COUNT = " & strTablePrefix & "TOTALS.T_COUNT - " & 1
					strSql = strSql & ",    " & strTablePrefix & "TOTALS.P_COUNT = " & strTablePrefix & "TOTALS.P_COUNT - " & cint(risposte) + 1

					my_Conn.Execute strSql					

				next
%>
<P align=center><font face="<% =strDefaultFontFace %>" size="<% =strHeaderFontSize %>"><b>Topic Deleted!</b></font></p>
<%			Else %>
<P align=center><font face="<% =strDefaultFontFace %>" size="<% =strHeaderFontSize %>"><b>No Permissions to Delete Topic</font><br>
<br>
<font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>"><a href="JavaScript: onClick= history.go(-1) ">Go Back to Re-Authenticate</a></font></p>
<%			end if %>	  
<%		Else %>
<P align=center><font face="<% =strDefaultFontFace %>" size="<% =strHeaderFontSize %>"><b>No Permissions to Delete Topic</font><br>
<br>
<font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>"><a href="JavaScript: onClick= history.go(-1)">Go Back to Re-Authenticate</a></font></p>
<%
		end if 
	else 
		if Request.QueryString("mode") = "DeleteForum" then
			mLev = cint(ChkUser2(Request.Form("User"), Request.Form("Pass"))) 
			if mLev > 0 then  '## is Member
				if mLev = 4 then
					delAr = split(Request.Form("FORUM_ID"), ",")
					for i = 0 to ubound(delAr) 

						'## Forum_SQL - count total number of replies of FORUM_ID  in Reply table

						set rs = Server.CreateObject("ADODB.Recordset")

						strSql = "SELECT count(" & strTablePrefix & "REPLY.REPLY_ID) AS cnt "
						strSql = strSql & " FROM " & strTablePrefix & "REPLY "
						strSql = strSql & " WHERE " & strTablePrefix & "REPLY.FORUM_ID = " & cint(delAr(i))	

						rs.Open strSql, my_Conn
						risreply = rs("cnt")
						rs.close

						set rs = nothing

						'## Forum_SQL - Delete all replys related to the topics
						strSql = "DELETE FROM " & strTablePrefix & "REPLY "
						strSql = strSql & " WHERE FORUM_ID = " & cint(delAr(i))

						my_Conn.Execute strSql

						'## Forum_SQL - count total number of Topics of FORUM_ID in Topics table
						set rs = Server.CreateObject("ADODB.Recordset")

						strSql = "SELECT count(" & strTablePrefix & "TOPICS.TOPIC_ID) AS cnt "
						strSql = strSql & " FROM " & strTablePrefix & "TOPICS "
						strSql = strSql & " WHERE " & strTablePrefix & "TOPICS.FORUM_ID = " & cint(delAr(i))	

						rs.Open strSql, my_Conn
						rispost = rs("cnt")
						rs.close

						set rs = nothing
  
						'## Forum_SQL - Delete the actual topics
						strSql = "DELETE FROM " & strTablePrefix & "TOPICS "
						strSql = strSql & " WHERE " & strTablePrefix & "TOPICS.FORUM_ID = " & cint(delAr(i))

						my_Conn.Execute strSql

						'## Forum_SQL - Delete the moderators
						strSql = "DELETE FROM " & strTablePrefix & "MODERATOR "
						strSql = strSql & " WHERE " & strTablePrefix & "MODERATOR.FORUM_ID = " & cint(delAr(i))

						my_Conn.Execute strSql

						'## Forum_SQL - Delete the actual forums
						strSql = "DELETE FROM " & strTablePrefix & "FORUM "
						strSql = strSql & " WHERE " & strTablePrefix & "FORUM.FORUM_ID = " & cint(delAr(i))

						my_Conn.Execute strSql

						'## Forum_SQL - Update total topics and posts in Totals table
						strSql = "UPDATE " & strTablePrefix & "TOTALS "
						strSql = strSql & " SET " & strTablePrefix & "TOTALS.P_COUNT = " & strTablePrefix & "TOTALS.P_COUNT - " & cint(rispreply + rispost)
						strSql = strSql & ",    " & strTablePrefix & "TOTALS.T_COUNT = " & strTablePrefix & "TOTALS.T_COUNT - " & cint(respost)

						my_Conn.Execute strSql
					next
%>
<P align=center><font face="<% =strDefaultFontFace %>" size="<% =strHeaderFontSize %>"><b>Forum Deleted!</b></font></p>
<%				Else %>
<P align=center><font face="<% =strDefaultFontFace %>" size="<% =strHeaderFontSize %>"><b>No Permissions to Delete Forum</font><br>
<br>
<font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>"><a href="JavaScript: onClick= history.go(-1) ">Go Back to Re-Authenticate</a></font></p>
<%				end if %>	  
<%			Else %>
<P align=center><font face="<% =strDefaultFontFace %>" size="<% =strHeaderFontSize %>"><b>No Permissions to Delete Forum</font><br>
<br>
<font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>"><a href="JavaScript: onClick= history.go(-1)">Go Back to Re-Authenticate</a></font></p>
<%
			end if 
		else
			if Request.QueryString("mode") = "DeleteCategory" then
				mLev = cint(ChkUser2(Request.Form("User"), Request.Form("Pass"))) 
				if mLev > 0 then  '## is Member
					if mLev = 4 then
						delAr = split(Request.Form("CAT_ID"), ",")
						for i = 0 to ubound(delAr) 

							'## Forum_SQL - Delete all replys related to the topics
							strSql = "DELETE FROM " & strTablePrefix & "REPLY "
							strSql = strSql & " WHERE " & strTablePrefix & "REPLY.CAT_ID = " & cint(delAr(i))

							my_Conn.Execute strSql

							'## Forum_SQL - Delete the actual topics
							strSql = "DELETE FROM " & strTablePrefix & "TOPICS "
							strSql = strSql & " WHERE " & strTablePrefix & "TOPICS.CAT_ID = " & cint(delAr(i))

							my_Conn.Execute strSql

							'## Forum_SQL - Delete the actual forums
							strSql = "DELETE FROM " & strTablePrefix & "FORUM "
							strSql = strSql & " WHERE " & strTablePrefix & "FORUM.CAT_ID = " & cint(delAr(i))

							my_Conn.Execute strSql

							'## Forum_SQL - Delete the actual category
							strSql = "DELETE FROM " & strTablePrefix & "CATEGORY "
							strSql = strSql & " WHERE " & strTablePrefix & "CATEGORY.CAT_ID = " & cint(delAr(i))

							my_Conn.Execute strSql

							'## Forum_SQL - Update total topics and posts in Totals table
							strSql = "UPDATE " & strTablePrefix & "TOTALS "
							strSql = strSql & " SET " & strTablePrefix & "TOTALS.P_COUNT = " & strTablePrefix & "TOTALS.P_COUNT - " & 1

							my_Conn.Execute strSql
						next
%>
<P align=center><font face="<% =strDefaultFontFace %>" size="<% =strHeaderFontSize %>"><b>Category Deleted!</b></font></p>
<%					else %>
<P align=center><font face="<% =strDefaultFontFace %>" size="<% =strHeaderFontSize %>"><b>No Permissions to Delete Category</font><br>
<br>
<font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>"><a href="JavaScript: onClick= history.go(-1) ">Go Back to Re-Authenticate</a></font></p>
<%					end if %>	  
<%				else %>
<P align=center><font face="<% =strDefaultFontFace %>" size="<% =strHeaderFontSize %>"><b>No Permissions to Delete Category</font><br>
<br>
<font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>"><a href="JavaScript: onClick= history.go(-1)">Go Back to Re-Authenticate</a></font></p>
<%
				end if 
			else
				if Request.QueryString("mode") = "DeleteMember" then
					mLev = cint(ChkUser2(Request.Form("User"), Request.Form("Pass"))) 
					if mLev > 0 then  '## is Member
						if mLev = 4 then

							'## Forum_SQL - Select postcount
							strSql = "SELECT " & strMemberTablePrefix & "MEMBERS.M_POSTS "
							strSql = strSql & " FROM " & strMemberTablePrefix & "MEMBERS "
							strSql = strSql & " WHERE MEMBER_ID = " & Request.Form("MEMBER_ID")

							set rs = my_Conn.Execute (strSql)
								
							if (rs("M_POSTS") = 0) then

								'## Forum_SQL - Delete the Member - Member has no posts
								strSql = "DELETE FROM " & strMemberTablePrefix & "MEMBERS "
								strSql = strSql & " WHERE " & strMemberTablePrefix & "MEMBERS.MEMBER_ID = " & Request.Form("MEMBER_ID")

								my_Conn.Execute strSql

							else
																				
								'## Forum_SQL - disable account - Member has posts, cannot delete just disable account
								strSql = "UPDATE " & strMemberTablePrefix & "MEMBERS "
								strSql = strSql & " SET " & strMemberTablePrefix & "MEMBERS.M_STATUS = " & 0
								strSql = strSql & ",    " & strMemberTablePrefix & "MEMBERS.M_EMAIL = ' '"
								strSql = strSql & ",    " & strMemberTablePrefix & "MEMBERS.M_LEVEL = " & 1
								strSql = strSql & ",    " & strMemberTablePrefix & "MEMBERS.M_NAME = 'n/a'"
								strSql = strSql & ",    " & strMemberTablePrefix & "MEMBERS.M_COUNTRY = ' '"
								strSql = strSql & ",    " & strMemberTablePrefix & "MEMBERS.M_TITLE = 'deleted'"
								strSql = strSql & ",    " & strMemberTablePrefix & "MEMBERS.M_HOMEPAGE = ' '"
								strSql = strSql & ",    " & strMemberTablePrefix & "MEMBERS.M_AIM = ' '"
								strSql = strSql & ",    " & strMemberTablePrefix & "MEMBERS.M_YAHOO = ' '"
								strSql = strSql & ",    " & strMemberTablePrefix & "MEMBERS.M_ICQ = ' '"
								strSql = strSql & " WHERE " & strMemberTablePrefix & "MEMBERS.MEMBER_ID = " & Request.Form("MEMBER_ID")

								my_Conn.Execute strSql

							end if

							'## Forum_SQL - Remove the member from the moderator table
							strSql = "DELETE FROM " & strTablePrefix & "MODERATOR "
							strSql = strSql & " WHERE " & strTablePrefix & "MODERATOR.MEMBER_ID = " & Request.Form("MEMBER_ID")

							my_Conn.Execute (strSql)

							'## Forum_SQL - Update total of Members in Totals table
							strSql = "UPDATE " & strTablePrefix & "TOTALS "
							strSql = strSql & " SET " & strTablePrefix & "TOTALS.U_COUNT = " & strTablePrefix & "TOTALS.U_COUNT - " & 1

							my_Conn.Execute strSql
%>
<P align=center><font face="<% =strDefaultFontFace %>" size="<% =strHeaderFontSize %>"><b>Member Deleted!</b></font></p>
<%						else %>
<P align=center><font face="<% =strDefaultFontFace %>" size="<% =strHeaderFontSize %>"><b>No Permissions to Delete a Member</font><br>
<br>
<font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>"><a href="JavaScript: onClick= history.go(-1) ">Go Back to Re-Authenticate</a></font></p>
<%						end if %>	  
<%					else %>
<P align=center><font face="<% =strDefaultFontFace %>" size="<% =strHeaderFontSize %>"><b>No Permissions to Delete a Member</font><br>
<br>
<font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>"><a href="JavaScript: onClick= history.go(-1)">Go Back to Re-Authenticate</a></font></p>
<%
					end if 
				else
%>

<P><font face="<% =strDefaultFontFace %>" size="<% =strHeaderFontSize %>">Delete 
<%				if Request.QueryString("mode") = "Member" then %>
Member
<%				else %>
<%					if Request.QueryString("mode") = "Category" then %>
Category
<%					else %>
<%						if Request.QueryString("mode") = "Forum" then %>
Forum
<%						else %>
<%							if Request.QueryString("mode") = "Topic" then %>
Topic
<%							else %>
<%								if Request.QueryString("mode") = "Reply" then %>
Reply
<%								end if %>
<%							end if %>
<%						end if %>
<%					end if %>
<%				end if %>
</font></p>

<p><font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>"><b><font color=red>NOTE:</font></b>  
<%				if Request.QueryString("mode") = "Member" then %>
Only Administrators can delete a Member.
<%				else %>
<%					if Request.QueryString("mode") = "Category" then %>
Only Administrators can delete a Category.
<%					else %>
<%						if Request.QueryString("mode") = "Forum" then %>
Only Administrators can delete Forums.
<%						else %>
<%							if Request.QueryString("mode") = "Topic" then %>
Only Moderators and Administrators can delete Topics.
<%							else %>
<%								if Request.QueryString("mode") = "Reply" then %>
Only the Author, Moderators and Administrators can delete Replies.
<%								end if %>
<%							end if %>
<%						end if %>
<%					end if %>
<%				end if %>
</font></p>

<form action="pop_delete.asp?mode=<% if Request.QueryString("mode") = "Member" then Response.Write("DeleteMember")%><% if Request.QueryString("mode") = "Category" then Response.Write("DeleteCategory")%><% if Request.QueryString("mode") = "Forum" then Response.Write("DeleteForum")%><% if Request.QueryString("mode") = "Topic" then Response.Write("DeleteTopic")%><%if Request.QueryString("mode") = "Reply" then Response.Write("DeleteReply")%>" method=post id=Form1 name=Form1>
<input type=hidden name="REPLY_ID" value="<% =Request.QueryString("REPLY_ID") %>">
<input type=hidden name="TOPIC_ID" value="<% =Request.QueryString("TOPIC_ID") %>">
<input type=hidden name="FORUM_ID" value="<% =Request.QueryString("FORUM_ID") %>">
<input type=hidden name="CAT_ID" value="<% =Request.QueryString("CAT_ID") %>">
<input type=hidden name="MEMBER_ID" value="<% =Request.QueryString("MEMBER_ID") %>">

<table border="0" width="75%" cellspacing="0" cellpadding="0">
  <tr>
    <td bgcolor="<% =strPopUpBorderColor %>">
    <table border="0" width="100%" cellspacing="1" cellpadding="1">
<%				if strAuthType="db" then %>
      <tr>
        <td bgColor=<% =strPopUpTableColor %> align=right nowrap><b><font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>">User Name:</font></b></td>
        <td bgColor=<% =strPopUpTableColor %>><input type=text name="User" value="<% =Request.Cookies("User")("Name")%>" size=20></td>
      </tr>
      <tr>
        <td bgColor=<% =strPopUpTableColor %> align=right nowrap><b><font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>">Password:</FONT></b></td>
        <td bgColor=<% =strPopUpTableColor %>><input type=Password name="Pass" value="<% =Request.Cookies("User")("Pword")%>" size=20></td>
      </tr>
<%				else %>
<%					if strAuthType="nt" then %>
      <tr>
        <td bgColor=<% =strPopUpTableColor %> align=right nowrap><b><font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>">NT Account:</font></b></td>
        <td bgColor=<% =strPopUpTableColor %>><font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>"><%=Session("userid")%></font></td>
      </tr>
<%					end if %>
<%				end if %>
      <tr>
        <td bgColor=<% =strPopUpTableColor %> colspan=2 align=center><Input type=Submit value="Send" id=Submit1 name=Submit1></td>
      </tr>
    </table>
    </td>
  </tr>
</table>
</form>
<%
				end if
			end if
		end if 
	end if 
end if 
%>
<!--#INCLUDE FILE="inc_footer_short.asp" -->