<% Option Explicit %>
<!--#include file="../../Inc/Const.asp" -->
<!--#include file="../../Inc/Cls_DB.asp" -->
<!--#include file="../Inc/Cls_Class.asp" -->
<!--#include file="../Inc/Cls_News.asp" -->
<!--#include file="../../Inc/Function.asp" -->
<%
Dim DBC,Conn
Set DBC = New DataBaseClass
Set Conn = DBC.OpenConnection()
Set DBC = Nothing
'==============================================================================
'软件名称：风讯网站信息管理系统
'当前版本：Foosun Content Manager System 2.0 
'最新更新：2004.12
'==============================================================================
'商业注册联系：028-85098980-601,602 技术支持：028-85098980-606、607,客户支持：608
'产品咨询QQ：159410,655071,66252421
'技术支持:所有程序使用问题，请提问到bbs.foosun.net我们将及时回答您
'程序开发：风讯开发组 & 风讯插件开发组
'论坛支持：风讯在线论坛(http://bbs.foosun.net)
'官方网站：www.Foosun.net  演示站点：test.cooin.com    
'网站建设专区：www.cooin.com
'==============================================================================
'免费版本请在新闻首页保留版权信息，并做上本站LOGO友情连接
'==============================================================================
%>
<!--#include file="../../Inc/Session.asp" -->
<!--#include file="../../Inc/CheckPopedom.asp" -->
<%
Dim MoveOrCopyClassPara,ShowStr,i,IDStr
Dim ShowSubmitTF,Result
Result = Request.Form("Result")
ShowSubmitTF = true
MoveOrCopyClassPara = Request("MoveOrCopyClassPara")
if MoveOrCopyClassPara <> "" then
	Dim OperationType,MoveTF,SourceClass,SourceNews,ObjectClass,RsTempObj
	Dim TxtOperationType,TxtMoveTF,TxtSourceClass,TxtSourceNews,TxtObjectClass
	MoveTF = GetParaValue(MoveOrCopyClassPara,"MoveTF")
	if MoveTF = "true" then
		TxtMoveTF = "移动"
	else
		TxtMoveTF = "拷贝"
	end if
	ObjectClass = GetParaValue(MoveOrCopyClassPara,"ObjectClass")
	if ObjectClass <> "0" then
		Set RsTempObj = Conn.Execute("Select ClassCName from NewsClass where ClassID='" & ObjectClass & "'")
		if Not RsTempObj.Eof then
			TxtObjectClass = RsTempObj("ClassCName")
		else
			TxtObjectClass = ""
		end if
		Set RsTempObj = Nothing
	else
		TxtObjectClass = "系统根栏目"
	end if
	OperationType = GetParaValue(MoveOrCopyClassPara,"OperationType")
	if OperationType = "Class" then
		TxtOperationType = "栏目"
		SourceClass = GetParaValue(MoveOrCopyClassPara,"SourceClass")
		IDStr = Replace(SourceClass,",","','")
		Set RsTempObj = Conn.Execute("Select ClassCName from NewsClass where ClassID in ('" & IDStr & "')")
		if Not RsTempObj.Eof then
			do while Not RsTempObj.Eof
				if TxtSourceClass = "" then
					TxtSourceClass = RsTempObj("ClassCName")
				else
					TxtSourceClass = TxtSourceClass & "|" & RsTempObj("ClassCName")
				end if
				RsTempObj.MoveNext
			Loop
		else
			TxtSourceClass = ""
		end if
		Set RsTempObj = Nothing
		SourceNews = ""
		ShowStr = CheckMoveOrCopyClass(SourceClass,ObjectClass)
		if ShowStr <> "" then
			ShowSubmitTF = false
		else
			ShowSubmitTF = true
			ShowStr = "确定要把" & """" & TxtSourceClass & """栏目" & TxtMoveTF & "到""" & TxtObjectClass & """吗？"
		end if
		if Result = "Submit" then
			Dim CClass
			Set CClass = New ClassClass
			if MoveTF = "true" then
				CClass.MoveClass SourceClass,ObjectClass
			else
				CClass.CopyClass SourceClass,ObjectClass 
			end if
			Set CClass = Nothing
			%>
			<script language="JavaScript">
			dialogArguments.parent.frames["MenuWindow"].location.reload();
			dialogArguments.parent.frames["OpreateWindow"].location.reload();
			window.close();
			</script>
			<%
		end if
	else
		TxtOperationType = "下载"
		SourceClass = ""
		SourceNews = Trim(GetParaValue(MoveOrCopyClassPara,"SourceNews"))
		IDStr = Replace(SourceNews,",","','")
		Set RsTempObj = Conn.Execute("Select Name from DownLoad where DownLoadID in ('" & IDStr & "')")
		if Not RsTempObj.Eof then
			do while Not RsTempObj.Eof
				if TxtSourceNews = "" then
					TxtSourceNews = RsTempObj("Name")
				else
					TxtSourceNews = TxtSourceNews & "|" & RsTempObj("Name")
				end if
				RsTempObj.MoveNext
			Loop
		else
			TxtSourceNews = ""
		end if
		Set RsTempObj = Nothing
		ShowStr = CheckMoveOrCopyNews(SourceNews,ObjectClass)
		if ShowStr <> "" then
			ShowSubmitTF = false
		else
			ShowSubmitTF = true
			ShowStr = "确定要把" & """" & TxtSourceNews & TxtMoveTF & "到""" & TxtObjectClass & """吗？"
		end if
		if Result = "Submit" then
			Dim NClass,SourceNewsArray
			SourceNewsArray = Split(SourceNews,",")
			Set NClass = New NewsClass
			if MoveTF = "true" then
				NClass.MoveDownLoad SourceNewsArray,ObjectClass 
			else
				NClass.CopyDownLoad SourceNewsArray,ObjectClass 
			end if
			Set NClass = Nothing
			%>
			<script language="JavaScript">
			dialogArguments.location.reload();
			window.close();
			</script>
			<%
		end if
	end if
else
	ShowSubmitTF = false
	ShowStr = "参数传递错误"
end if

Function CheckMoveOrCopyNews(SourceNewsID,ObjectClassID)
	Dim RsTempObj,TempSourceClassID
	if ObjectClassID = "0" then
		CheckMoveOrCopyNews = "目标不存在，下载移动失败"
		Exit Function
	end if
	Set RsTempObj = Conn.Execute("Select ClassID from DownLoad where DownLoadID in ('" & Replace(SourceNewsID,",","','") & "')")
	if Not JudgePopedomTF(Session("Name"),"P139") then Call ReturnError()
	if Not RsTempObj.Eof then
		TempSourceClassID = RsTempobj("ClassID")
	else
		CheckMoveOrCopyNews = "下载的栏目不存在，下载移动失败"
		Exit Function
	end if
	Set RsTempObj = Nothing
	if TempSourceClassID = ObjectClassID then
		CheckMoveOrCopyNews = "源和目的相同，下载移动失败"
		Exit Function
	end if
End Function

Function CheckMoveOrCopyClass(SourceClassID,ObjectClassID)
if Not JudgePopedomTF(Session("Name"),"P139") then Call ReturnError()
	Dim TempArray,LoopVar
	if ObjectClassID <> "0" then
		if InStr(SourceClassID,ObjectClassID) <> 0 then
			CheckMoveOrCopyClass = "目标栏目和源栏目相同，操作失败"
			Exit Function
		end if
	end if
	if SourceClassID = "" then
		CheckMoveOrCopyClass = "源栏目不存在，操作失败"
		Exit Function
	end if
	if ObjectClassID = "" then
		CheckMoveOrCopyClass = "目标栏目不存在，操作失败"
		Exit Function
	end if
	TempArray = Split(SourceClassID,",")
	for LoopVar = LBound(TempArray) to UBound(TempArray)
		if JudgeSourceObjectClass(TempArray(LoopVar),ObjectClassID) = true then
			CheckMoveOrCopyClass = "不能把父栏目拷贝或者移动到子栏目，操作失败"
			Exit Function
		end if
	Next
End Function

Private Function JudgeSourceObjectClass(SourceClassID,ObjectClassID)
	Dim TempSql,RsTempObj,Temp
	TempSql = "Select ClassID from NewsClass where ParentID ='" & SourceClassID & "'"
	Set RsTempObj = Conn.Execute(TempSql)
	do while Not RsTempObj.Eof
		if RsTempObj("ClassID") = ObjectClassID then
			JudgeSourceObjectClass = True
			Exit do
		end if
		JudgeSourceObjectClass = JudgeSourceObjectClass(RsTempObj("ClassID"),ObjectClassID)
		if JudgeSourceObjectClass = True then Exit do
		RsTempObj.MoveNext
	loop
	RsTempObj.Close
	Set RsTempObj = Nothing
End Function

Function GetParaValue(ParaStr,ParaName)
	Dim BeginIndex,EndIndex
	BeginIndex = InStr(ParaStr,ParaName)+Len(ParaName)+1
	EndIndex = InStr(BeginIndex,ParaStr,";")
	GetParaValue = Mid(ParaStr,BeginIndex,EndIndex-BeginIndex)
End Function
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>移动复制下载</title>
</head>
<link href="../../CSS/ModeWindow.css" rel="stylesheet">
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="5">
  <form name="OperateForm" action="" method="post">
    <tr> 
      <td width="21%"><div align="center"><img src="../Images/Question.gif" width="39" height="37">
          </div></td>
      <td width="79%"><div align="left"></div>
        <div align="left">
          <% = ShowStr %>
      </div></td>
    </tr>
    <tr> 
<%
if ShowSubmitTF = true then
%>
      <td colspan="2"><div align="center"> 
          <input type="submit" name="Submit" value=" 确 定 ">
          <input name="Result" type="hidden" id="Result" value="Submit">
          <input type="button" name="Submit2" onClick="window.close();" value=" 取 消 ">
        </div></td>
<%
end if
%>
    </tr>
  </form>
</table>
</body>
</html>
<%
Set Conn = Nothing
%>
