<%@language=vbscript codepage=936 %>
<%
option explicit
response.buffer=true	
Const PurviewLevel=2
Const CheckChannelID=4
Const PurviewLevel_Photo=3
%>
<!--#include file="inc/conn1.asp"-->
<!--#include file="inc/config.asp"-->
<!--#include file="Admin_ChkPurview.asp"-->
<!--#include file="inc/ubbcode.asp"-->
<!--#include file="inc/function.asp"-->
<!--#include file="inc/admin_code_Flv.asp"-->


<LINK 
href="Common/Stylee.css" type=text/css rel=stylesheet>
<DIV id=All>


<%
dim Action,rs,sql,ErrMsg,FoundErr,ObjInstalled
dim PhotoID,ClassID,PhotoName,Keyword,Author,AuthorEmail,AuthorHomepage
dim PhotoUrl_Thumb,PhotoUrl_Thumbsm,PhotoUrl,PhotoUrl2,PhotoUrl3,PhotoUrl4,PhotoSize_Thumb,PhotoSize,PhotoSize2,PhotoSize3,PhotoSize4
dim PhotoIntro,OnTop,Elite,Stars,Hits,DayHits,WeekHits,MonthHits,PhotoLevel,PhotoPoint,UpdateTime,Passed,Editor
dim tClass,ClassName,Depth,ParentPath,Child,i
ObjInstalled=IsObjInstalled("Scripting.FileSystemObject")
FoundErr=false
Action=trim(request("Action"))
PhotoID=Trim(Request.Form("PhotoID"))
ClassID=trim(request.form("ClassID"))
'SpecialID=trim(request.Form("SpecialID"))
PhotoName=trim(request.form("PhotoName"))
Keyword=trim(request.form("Keyword"))
Author=trim(request.form("Author"))
AuthorEmail=trim(request.form("AuthorEmail"))
AuthorHomepage=trim(request.form("AuthorHomePage"))
PhotoUrl_Thumb=trim(request.form("PhotoUrl_Thumb"))
PhotoUrl_Thumbsm=trim(request.form("PhotoUrl_Thumbsm"))
PhotoUrl=trim(request.form("PhotoUrl"))
PhotoUrl2=trim(request.form("PhotoUrl2"))
PhotoUrl3=trim(request.form("PhotoUrl3"))
PhotoUrl4=trim(request.form("PhotoUrl4"))
PhotoSize_Thumb=trim(request.form("PhotoSize_Thumb"))
PhotoSize=trim(request.form("PhotoSize"))
PhotoSize2=trim(request.form("PhotoSize2"))
PhotoSize3=trim(request.form("PhotoSize3"))
PhotoSize4=trim(request.form("PhotoSize4"))
PhotoIntro=trim(request.form("PhotoIntro"))
OnTop=trim(request.form("OnTop"))
Elite=trim(request.form("Elite"))
Stars=trim(request.form("Stars"))
Hits=trim(request.form("Hits"))
DayHits=trim(request.form("DayHits"))
WeekHits=trim(request.form("WeekHits"))
MonthHits=trim(request.form("MonthHits"))
PhotoLevel=trim(request.form("PhotoLevel"))
PhotoPoint=trim(request.form("PhotoPoint"))
UpdateTime=trim(request.form("UpdateTime"))
Passed=trim(request.form("Passed"))
Editor=AdminName

if Action="" then
	FoundErr=True
	ErrMsg=ErrMsg & "<br><li>参数不足</li>"
else
	call SavePhoto()
end if
if founderr=true then
	call WriteErrMsg()
else
	call SaveSuccess()
end if
call CloseConn()


sub SavePhoto()
	dim PurviewChecked
	if ClassID="" then
		founderr=true
		errmsg=errmsg & "<br><li>未指定视屏所属栏目或者指定的栏目有下属子栏目</li>"
	else
		ClassID=CLng(ClassID)
		if ClassID<=0 then
			FoundErr=True
			ErrMsg=ErrMsg & "<br><li>指定了非法的栏目（外部栏目或不存在的栏目）</li>"
		else
			set tClass=conn.execute("select ClassName,Depth,ParentPath,Child,LinkUrl,ParentID,ClassInputer From FlvClass where ClassID=" & ClassID)
			if tClass.bof and tClass.eof then
				FoundErr=True
				ErrMsg=ErrMsg & "<br><li>找不到指定的栏目</li>"
			else
				ClassName=tClass(0)
				Depth=tClass(1)
				ParentPath=tClass(2)
				Child=tClass(3)
				if Child>0 then
					FoundErr=True
					ErrMsg=ErrMsg & "<br><li>指定的栏目有下属子栏目</li>"
				end if
				if tClass(4)<>"" then
					FoundErr=True
					ErrMsg=ErrMsg & "<br><li>不能指定外部栏目</li>"
				end if
				if AdminPurview=2 and AdminPurview_Photo=3 then
					PurviewChecked=CheckClassMaster(tClass(6),AdminName)
					if PurviewChecked=False and tClass(5)>0 then
						set tClass=conn.execute("select ClassInputer from FlvClass where ClassID in (" & ParentPath & ")")
						do while not tClass.eof
							PurviewChecked=CheckClassMaster(tClass(0),AdminName)
							if PurviewChecked=True then exit do
							tClass.movenext
						loop
					end if
					if PurviewChecked=False then
						FoundErr=True
						ErrMsg=ErrMsg & "<br><li>对不起，你没有在此栏目添加视屏的权限！</li>"
					end if
				end if
			end if
		end if
	end if
	if PhotoName="" then
		founderr=true
		errmsg=ErrMsg & "<br><li>视屏名称不能为空</li>"
	end if
	if Keyword="" then
		founderr=true
		errmsg=errmsg & "<br><li>请输入视屏关键字</li>"
	end if
	if PhotoUrl_Thumb="" then
		founderr=true
		errmsg=ErrMsg & "<br><li>缩略图地址不能为空</li>"
	end if
	if PhotoSize_Thumb="" then
		founderr=true
		errmsg=ErrMsg & "<br><li>缩略图文件大小不能为空</li>"
	else
		PhotoSize_Thumb=Clng(PhotoSize_Thumb)
	end if
	if PhotoUrl="" then
		founderr=true
		errmsg=errmsg & "<br><li>原始视屏地址不能为空</li>"
	end if
	if PhotoSize="" then
		founderr=true
		errmsg=errmsg & "<br><li>原始视屏文件大小不能为空</li>"
	else
		PhotoSize=Clng(PhotoSize)
	end if
	
	if FoundErr=True then
		exit sub
	end if
		
	Keyword="|" & ReplaceBadChar(Keyword) & "|"
	if PhotoSize2="" then
		PhotoSize2=0
	else
		PhotoSize2=Clng(PhotoSize2)
	end if
	if PhotoSize3="" then
		PhotoSize3=0
	else
		PhotoSize3=Clng(PhotoSize3)
	end if
	if PhotoSize4="" then
		PhotoSize4=0
	else
		PhotoSize4=Clng(PhotoSize4)
	end if
	if UpdateTime<>"" and IsDate(UpdateTime)=true then
		UpdateTime=CDate(UpdateTime)
	else
		UpdateTime=now()
	end if
	if Hits<>"" then
		Hits=CLng(Hits)
	else
		Hits=0
	end if
	if DayHits<>"" then
		DayHits=CLng(DayHits)
	else
		DayHits=0
	end if
	if WeekHits<>"" then
		WeekHits=CLng(WeekHits)
	else
		WeekHits=0
	end if
	if MonthHits<>"" then
		MonthHits=CLng(MonthHits)
	else
		MonthHits=0
	end if
	if PhotoLevel="" then
		PhotoLevel=9999
	else
		PhotoLevel=CInt(PhotoLevel)
	end if
	if PhotoPoint="" then
		PhotoPoint=0
	else
		PhotoPoint=Cint(PhotoPoint)
	end if
	if Stars="" then
		Stars=0
	else
		Stars=CInt(Stars)
	end if
	
	set rs=server.createobject("adodb.recordset")
	if Action="Add" then
		sql="select * from Flv" 
		rs.open sql,conn,1,3
		rs.addnew
		call SaveData()
		rs("Editor")=Editor
		rs.update
		rs.close
		sql="select top 1 * from Flv order by PhotoID desc" 
		rs.open sql,conn,1,1		
		PhotoID=rs("PhotoID")
		Passed=rs("Passed")
		rs.close
	elseif Action="Modify" then
  		if PhotoID="" then
			founderr=true
			errmsg=errmsg & "<br><li>不能确定PhotoID的值</li>"
		else
			PhotoID=Clng(PhotoID)
			sql="select * from Flv where Photoid=" & PhotoID
			rs.open sql,conn,1,3
			if rs.bof and rs.eof then
				founderr=true
				errmsg=errmsg & "<br><li>找不到此视屏，可能已经被其他人删除。</li>"
 			else
				call SaveData()
				rs.update
				Passed=rs("Passed")
				rs.close
			end if
		end if
	else
		FoundErr=True
		ErrMsg="<br><li>参数错误!</li>"
	end if
	set rs=nothing
end sub

sub SaveData()
	rs("ClassID")=ClassID
	'rs("SpecialID")=SpecialID
	rs("PhotoName")=PhotoName
	rs("Keyword")=Keyword
	rs("Author")=Author
	rs("AuthorEmail")=AuthorEmail
	rs("AuthorHomepage")=AuthorHomepage
	rs("PhotoUrl_Thumb")=PhotoUrl_Thumb
	rs("PhotoUrl_Thumbsm")=PhotoUrl_Thumbsm
	rs("PhotoUrl")=PhotoUrl
	rs("PhotoUrl2")=PhotoUrl2
	rs("PhotoUrl3")=PhotoUrl3
	rs("PhotoUrl4")=PhotoUrl4
	rs("PhotoSize_Thumb")=PhotoSize_Thumb
	rs("PhotoSize")=PhotoSize
	rs("PhotoSize2")=PhotoSize2
	rs("PhotoSize3")=PhotoSize3
	rs("PhotoSize4")=PhotoSize4
	rs("PhotoIntro")=PhotoIntro
	rs("Hits")=Hits
	rs("DayHits")=DayHits
	rs("WeekHits")=WeekHits
	rs("MonthHits")=MonthHits
	rs("PhotoLevel")=PhotoLevel
	rs("PhotoPoint")=PhotoPoint
	rs("Stars")=Stars
	rs("UpdateTime")=UpdateTime
	if Passed="yes" then
		rs("Passed")=1
	else
		rs("Passed")=0
	end if
	if OnTop="yes" then
		rs("OnTop")=1
	else
		rs("OnTop")=0
	end if
	if Elite="yes" then
		rs("Elite")=1
	else
		rs("Elite")=0
	end if
	
end sub
	
sub SaveSuccess()
%>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="Admin_Style.css">
</head>
<body leftmargin="2" topmargin="0" marginwidth="0" marginheight="0">
<br><br>
<table width="500" border="0" align=center cellpadding="6" cellspacing="1" bordercolor="#999999" bgcolor="#CCCCCC">
  <tr align=center> 
    <td  height="22" colspan="2" align="center" bgcolor="#F2f2f2" class="title"><b> 
      <%if action="Add"then%>
      添加 
      <%else%>
      修改 
      <%end if%>
    视屏成功</b></td>
  </tr>

  <tr> 
    <td width='150' align="center" valign="top" bgcolor="#FFFFFF"><img src="<%=PhotoUrl_Thumb%>" width="150"></td>
    <td width="350" valign="top" bgcolor="#FFFFFF"><table width="100%" border="0" cellpadding="5" cellspacing="0">
        <tr> 
          <td width="87" align="center"><strong>&nbsp;所属栏目：</strong></td>
          <td width="228"><%call Admin_ShowPath2(ParentPath,ClassName,Depth)%></td>
        </tr>
        <tr> 
          <td width="87" align="center"><strong>&nbsp;视屏名称：</strong></td>
          <td><%= dvHtmlEncode(PhotoName) %></td>
        </tr>
        <tr> 
          <td width="87" align="center"><strong>&nbsp;视屏作者：</strong></td>
          <td><%= dvHtmlEncode(editor) %></td>
        </tr>
        <tr> 
          <td width="87" align="center"><strong>&nbsp;关 键 字：</strong></td>
          <td><%= mid(Keyword,2,len(Keyword)-2) %></td>
        </tr>
    </table></td>
  </tr>
  <tr> 
    <td height="40" colspan="2" align="center" bgcolor="#FFFFFF">【<a href="Admin_FlvModify.asp?PhotoID=<%=PhotoID%>">修改此视屏</a>】&nbsp;【<a href="Admin_FlvAdd.asp">继续添加视屏</a>】&nbsp;【<a href="Admin_FlvManage.asp">视屏管理</a>】&nbsp;【<a href="Admin_FlvShow.asp?PhotoID=<%=PhotoID%>">预览视屏下载页面</a>】</td>
  </tr>
</table>
</body>
</html>
<%
end sub
%>