<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
option explicit
response.buffer=true	
Const PurviewLevel=2
Const CheckChannelID=4
Const PurviewLevel_Photo=2
%>
<!--#include file="inc/conn1.asp"-->
<!--#include file="inc/config.asp"-->
<!--#include file="Admin_ChkPurview.asp"-->
<!--#include file="inc/function.asp"-->
<!--#include file="inc/admin_code_Photo.asp"-->
<%
dim PhotoID,ClassID,TargetClassID,SpecialID
dim Action,FoundErr,ErrMsg
dim strComeUrl
dim SkinID,LayoutID,SkinCount,LayoutCount,ClassMaster,BrowsePurview,AddPurview
if trim(request("strComeUrl"))="" then
	strComeUrl=Request.ServerVariables("HTTP_REFERER")
else
	strComeUrl=trim(request("strComeUrl"))
end if
PhotoID=trim(request("PhotoID"))
TargetClassID=trim(request("TargetClassID"))
SpecialID=trim(request("SpecialID"))
Action=Trim(Request("Action"))
if Action="MoveToClass" then
	call MoveToClass()
elseif Action="MoveToSpecial" then
	call MoveToSpecial()
elseif Action="Move" then
	call MovePhoto()
else
	call main()
end if
if FoundErr=True then
	call WriteErrMsg()
end if
call CloseConn()


sub main()
	if PhotoID="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>请选择要移动的图片！</li>"
		exit sub
	else
		PhotoID=CLng(PhotoID)
	end if
	dim sqlPhoto,rsPhoto
	dim PhotoName,PhotoUrl_Thumb,ClassName,ParentPath,Depth
	sqlPhoto="select Photo.ClassID,Photo.PhotoName,PhotoClass.ClassName,PhotoClass.ParentPath,PhotoClass.Depth,Photo.PhotoUrl_Thumb from Photo"
	sqlPhoto=sqlPhoto & " inner join PhotoClass on Photo.ClassID=PhotoClass.ClassID where Photo.PhotoID=" & PhotoID
	set rsPhoto=Server.CreateObject("ADODB.Recordset")
	rsPhoto.open sqlPhoto,conn,1,1
	if rsPhoto.bof and rsPhoto.eof then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>找不到要移到的图片</li>"
	else
		ClassID=rsPhoto(0)
		PhotoName=rsPhoto(1)
		ClassName=rsPhoto(2)
		ParentPath=rsPhoto(3)
		Depth=rsPhoto(4)
		PhotoUrl_Thumb=rsPhoto(5)		
%>
<html>
<head>
<title>图片移动</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" type="text/css" href="Admin_Style.css">
</head>
<body>
<form name="form1" method="post" action="Admin_PhotoMove.asp">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="border">
  <tr class="title">
      <td height="22" align="center"><strong>软 件 移 动</strong></td>
  </tr>
  <tr>
    <td><table width="100%" border="0" cellspacing="1" cellpadding="2">
          <tr class="tdbg"> 
            <td width="200"><strong>缩略图：</strong></td>
            <td><%response.write "<img src='" & PhotoUrl_Thumb & "'>"%></td>
          </tr>
          <tr class="tdbg"> 
            <td width="200"><strong>所属栏目：</strong></td>
            <td><%call Admin_ShowPath2(ParentPath,ClassName,Depth)%></td>
          </tr>
          <tr class="tdbg"> 
            <td width="200"><strong>图片名称：</strong></td>
            <td><%=PhotoName%> <input name="PhotoID" type="hidden" id="PhotoID" value="<%=PhotoID%>"></td>
          </tr>
          <tr class="tdbg"> 
            <td width="200"><strong>移动到：</strong><br>
              不能指定为含有子栏目的栏目<br>
              不能指定为外部栏目 </td>
            <td><select name="TargetClassID" size="2"  style="height:300px;width:400px;">
                <%call Admin_ShowClass_Option(3,ClassID)%>
              </select> </td>
          </tr>
        </table></td>
  </tr>
  <tr class="tdbg">
    <td align="center"><input name="strComeUrl" type="hidden" id="strComeUrl" value="<%=strComeUrl%>">
        <input name="Action" type="hidden" id="Action" value="Move">
        <input type="submit" name="Submit" value=" 确 定 ">
      &nbsp; 
      <input name="Cancel" type="button" id="Cancel" value=" 取 消 " onClick="window.location.href='Admin_PhotoManage.asp'" style="cursor:hand;"></td>
  </tr>
</table>
</form>
</body>
</html>
<%
	end if
	rsPhoto.close
	set rsPhoto=nothing
end sub

sub MovePhoto()
	dim tClass
	if PhotoID="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>请选择要移动的图片！</li>"
	end if
	if TargetClassID="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>请指定目标栏目！</li>"
	else
		TargetClassID=CLng(TargetClassID)
		set tClass=conn.execute("select Child from PhotoClass where ClassID=" & TargetClassID)
		if tClass.bof and tClass.eof then
			FoundErr=True
			ErrMsg=ErrMsg & "<br><li>找不到指定的目标栏目！</li>"
		else
			if tClass(0)>0 then
				FoundErr=True
				ErrMsg=ErrMsg & "<br><li>不能将图片移到有子栏目的栏目中！</li>"
			end if
		end if			
	end if
	if FoundErr=True then exit sub
	if SpecialID="" then
		SpecialID=0
	else
		SpecialID=Clng(SpecialID)
	end if
	PhotoID=replace(PhotoID," ","")
	'conn.execute("update Photo set ClassID=" & TargetClassID & ",SpecialID=" & SpecialID & " where PhotoId in (" & PhotoID & ")")
	conn.execute("update Photo set ClassID=" & TargetClassID & " where PhotoId in (" & PhotoID & ")")
	conn.execute("update PhotoComment set ClassID=" & TargetClassID & " where PhotoID in (" & PhotoID & ")")
	call CloseConn()
	response.Redirect strComeUrl
end sub

sub MoveToClass()
	dim tClass
	if PhotoID="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>请选择要移动的图片！</li>"
	end if
	if TargetClassID="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>请指定目标栏目！</li>"
	else
		TargetClassID=CLng(TargetClassID)
		set tClass=conn.execute("select Child from PhotoClass where ClassID=" & TargetClassID)
		if tClass.bof and tClass.eof then
			FoundErr=True
			ErrMsg=ErrMsg & "<br><li>找不到指定的目标栏目！</li>"
		else
			if tClass(0)>0 then
				FoundErr=True
				ErrMsg=ErrMsg & "<br><li>不能将图片移到有子栏目的栏目中！</li>"
			end if
		end if			
	end if
	if FoundErr=True then exit sub
	PhotoID=replace(PhotoID," ","")
	conn.execute("update Photo set ClassID=" & TargetClassID & " where PhotoId in (" & PhotoID & ")")
	conn.execute("update PhotoComment set ClassID=" & TargetClassID & " where PhotoId in (" & PhotoID & ")")
	call CloseConn()
	response.Redirect strComeUrl
end sub

sub MoveToSpecial()
	if SpecialID="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>请指定目标专题！</li>"
		exit sub
	else
		SpecialID=CLng(SpecialID)
	end if
	PhotoID=replace(PhotoID," ","")
	conn.execute("update Photo set SpecialID=" & SpecialID & " where PhotoID in (" & PhotoID & ")")
	call CloseConn()
	response.Redirect strComeUrl
end sub

%>
