<%@language=vbscript codepage=936 %>
<%
option explicit
response.buffer=true	
Const PurviewLevel=4    '操作权限
%>
<!--#include file="Admin_ChkPurview.asp"-->
<!--#include file="inc/conn.asp"-->
<!--#include file="inc/function.asp"-->
<!--#include file="inc/admin_code.asp"-->
<%
dim ArticleID,Action,sqlProperty,rsProperty,FoundErr,ErrMsg,PurviewChecked
dim ClassID,tClass,ClassName,RootID,ParentID,Depth,ParentPath,Child,ChildID,tID,tChild,ClassMaster
dim ComeUrl
ComeUrl=Request.ServerVariables("HTTP_REFERER")
ArticleID=trim(request("ArticleID"))
Action=Trim(Request("Action"))
FoundErr=False
if ArticleId="" then
	FoundErr=True
	ErrMsg=ErrMsg & "<br><li>请先选定文章！</li>"
end if
if Action="" then
	FoundErr=True
	ErrMsg=ErrMsg & "<br><li>参数不足！</li>"
end if
if FoundErr=False then
	call SetProperty()
end if
if FoundErr=False then
	call CloseConn()
	response.Redirect ComeUrl
else
	call CloseConn()
	call WriteErrMsg()
end if

sub SetProperty()
	if instr(ArticleID,",")>0 then
		ArticleID=replace(ArticleID," ","")
		sqlProperty="select * from Article where ArticleID in (" & ArticleID & ")"
	else
		ArticleID=Clng(ArticleID)
		sqlProperty="select * from article where ArticleID=" & ArticleID
	end if
	Set rsProperty= Server.CreateObject("ADODB.Recordset")
	rsProperty.open sqlProperty,conn,1,3
	do while not rsProperty.eof
		PurviewChecked=False
		ClassID=rsProperty("ClassID")
		if session("purview")<=3 then
			PurviewChecked=True
		else
			set tClass=conn.execute("select ClassName,RootID,ParentID,Depth,ParentPath,Child,ClassMaster From ArticleClass where ClassID=" & ClassID)
			if tClass.bof and tClass.eof then
				FounErr=True
				ErrMsg=ErrMsg & "<br><li>找不到指定的栏目</li>"
			else
				ClassName=tClass(0)
				RootID=tClass(1)
				ParentID=tClass(2)
				Depth=tClass(3)
				ParentPath=tClass(4)
				Child=tClass(5)
				ClassMaster=tClass(6)
				if ParentID>0 then
					set tClass=conn.execute("select ClassMaster from ArticleClass where ClassID in (" & ParentPath & ")")
					do while not tClass.eof
						if tClass(0)<>"" then
							if ClassMaster="" then
								ClassMaster=tClass(0)
							else
								ClassMaster=ClassMaster & "|" & tClass(0)
							end if
						end if
						tClass.movenext
					loop
				end if
				PurviewChecked=CheckClassPurview(ClassMaster,session("Admin"))
			end if
		end if
		if PurviewChecked=False then
			FoundErr=True
			ErrMsg=ErrMsg & "<br><li>对 " & rsProperty("ArticleID") & " 没有操作权限！</li>"
		else
			select case Action
			case "SetOnTop"
				rsProperty("OnTop") = True
			case "CancelOnTop"
				rsProperty("OnTop") = False
			case "SetElite"
				rsProperty("Elite") = True
			case "CancelElite"
				rsProperty("Elite") = False
			case "SetPassed"
				rsProperty("Passed") =True
				conn.execute("update [User] set ArticleChecked=ArticleChecked+1 where UserName='" & rsProperty("Editor") & "'")
			case "CancelPassed"
				rsProPerty("Passed") =False
				conn.execute("update [User] set ArticleChecked=ArticleChecked-1 where UserName='" & rsProperty("Editor") & "'")
			end select
			rsProperty.update
		end if
		rsProperty.movenext
	loop
	rsProperty.close
	set rsProperty=nothing
end sub
%>