<%@language=vbscript codepage=936 %>
<%
option explicit
response.buffer=true	
Const PurviewLevel=2    '操作权限
%>
<!--#include file="Admin_ChkPurview.asp"-->
<!--#include file="inc/conn.asp"-->
<!--#include file="inc/ubbcode.asp"-->
<!--#include file="inc/function.asp"-->
<%
dim sql,rs
dim Action,FoundErr,ErrMsg
Action=Trim(Request("Action"))
%>
<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 leftmargin="2" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" Class="border">
  <tr class="topbg"> 
    <td height="22" colspan=2 align=center><strong>广 告 管 理</strong></td>
  </tr>
  <tr class="tdbg"> 
    <td width="70" height="30"><strong>管理导航：</strong></td>
    <td height="30"><a href="Admin_Advertisement.asp">横幅广告管理</a> | <a href="Admin_Advertisement.asp?Action=Add">添加新广告</a></td>
  </tr>
</table>
<%
if Action="Add" then
	call Add()
elseif Action="SaveAdd" then
	call SaveAdd()
elseif Action="Modify" then
	call Modify()
elseif Action="SaveModify" then
	call SaveModify()
elseif Action="Set" then
	call SetNew()
elseif Action="Del" then
	call DelAD()
else
	call main()
end if
if FoundErr=True then
	call WriteErrMsg()
end if
call CloseConn()


sub main()
	sql="select * from Advertisement order by id desc"
	set rs=server.createobject("adodb.recordset")
	rs.open sql,conn,1,1
%>
<form method="POST" action="Admin_Advertisement.asp">
  <table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" Class="border">
    <tr class="title"> 
      <td width="30" height="22" align="center"><strong>选择</strong></td>
      <td width="30" height="22" align="center"><strong>ID</strong></td>
      <td width="100" height="22" align="center"><strong>网站名称</strong></td>
      <td height="22" align="center"><strong>广告图片</strong></td>
      <td width="60" height="22" align="center"><strong>操作</strong></td>
    </tr>
    <%
if not(rs.bof and rs.eof) then
	do while not rs.eof
%>
    <tr class="tdbg" onmouseout="this.style.backgroundColor=''" onmouseover="this.style.backgroundColor='#BFDFFF'"> 
      <td width="30" align="center"><input type="radio" value=<%=rs("ID")%><%if rs("IsSelected")=true then%> checked<%end if%> name="ID"></td>
      <td width="30" align="center"><%=rs("ID")%></td>
      <td width="100"><a href="<%=rs("SiteUrl")%>" target='blank' title="网站地址：<%=rs("SiteUrl") & vbcrlf %>网站简介：<%=vbcrlf & rs("SiteIntro")%>"><%=rs("SiteName")%></a></td>
      <td align="center"> <%
if lcase(right(rs("ImgUrl"),4))=".swf" then
	Response.Write "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0'"
	if rs("ImgWidth")>0 then 
		response.write " width='" & rs("ImgWidth") & "'"
		if rs("ImgHeight")>0 then response.write " height='" & rs("ImgHeight") & "'"
	end if
	response.write "><param name='movie' value='" & rs("ImgUrl") & "'><param name='quality' value='high'><embed src='" & rs("ImgUrl") & "' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash'"
	if rs("ImgWidth")>0 then 
		response.write " width='" & rs("ImgWidth") & "'"
		if rs("ImgHeight")>0 then response.write " height='" & rs("ImgHeight") & "'"
	end if
	response.write "></embed></object>"
else
	response.write "<a href='" & rs("SiteUrl") & "' target='_blank' title='图片地址：" & rs("ImgUrl") & vbcrlf & "图片宽度：" & rs("ImgWidth") & "像素" & vbcrlf & "图片高度：" & rs("ImgHeight") & "像素'><img src='" & rs("ImgUrl") & "'"
	if rs("ImgWidth")>0 then 
		response.write " width='" & rs("ImgWidth") & "'"
		if rs("ImgHeight")>0 then response.write " height='" & rs("ImgHeight") & "'"
	end if
	response.write " border='0'></a>"
end if
%> </td>
      <td width="60" align="center"><%
	  response.write "<a href='Admin_Advertisement.asp?Action=Modify&ID=" & rs("ID") & "'>修改</a>&nbsp;&nbsp;"
	  if rs("IsSelected")=False then
      	response.write "<a href='Admin_Advertisement.asp?Action=Del&ID=" & rs("ID") & "'>删除</a>"
	  else
	  	response.write "&nbsp;&nbsp;&nbsp;&nbsp;"
	  end if
	  %>
	  </td>
    </tr>
    <%
rs.movenext
loop
%>
    <tr class="tdbg"> 
      <td colspan=5 align=center><input name="Action" type="hidden" id="Action" value="Set"> 
        <input type="submit" value="将选定的广告设为最新广告" name="submit"> </td>
    </tr>
    <% end if%>
  </table>
</form>
<%
	rs.close
	set rs=nothing
end sub

sub Add()
%>
<form name="form1" method="post" action="Admin_Advertisement.asp">
  <table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="border">
    <tr class="title"> 
      <td height="22" colspan="2" align="center"><strong>添 加 广 告</strong></td>
    </tr>
    <tr class="tdbg"> 
      <td width="350"><strong>网站名称：</strong></td>
      <td width="400"> <input name="SiteName" type="text" id="SiteName" value="" size="50" maxlength="255"></td>
    </tr>
    <tr class="tdbg"> 
      <td width="350"><strong>网站地址：</strong></td>
      <td width="400"> <input name="SiteUrl" type="text" id="SiteUrl" value="http://" size="50" maxlength="255"></td>
    </tr>
    <tr class="tdbg"> 
      <td width="350"><strong>网站简介：</strong></td>
      <td width="400"> <input name="SiteIntro" type="text" id="SiteIntro" size="50" maxlength="255"></td>
    </tr>
    <tr class="tdbg"> 
      <td width="350"><strong>图片地址：</strong></td>
      <td> <input name="ImgUrl" type="text" id="ImgUrl" size="50" maxlength="255"></td>
    </tr>
    <tr class="tdbg"> 
      <td width="350"><strong>图片大小：</strong></td>
      <td>宽： 
        <input name="ImgWidth" type="text" id="ImgWidth" value="480" size="6" maxlength="5">
        像素&nbsp;&nbsp;&nbsp;&nbsp;高： 
        <input name="ImgHeight" type="text" id="ImgHeight" value="60" size="6" maxlength="5">
        像素</td>
    </tr>
    <tr class="tdbg"> 
      <td width="350"><strong>是否FLASH：</strong></td>
      <td><input type="radio" name="IsFlash" value="True">
        是&nbsp;&nbsp;&nbsp;&nbsp; <input name="IsFlash" type="radio" value="False" checked>
        否</td>
    </tr>
    <tr class="tdbg"> 
      <td width="350">&nbsp;</td>
      <td><input name="IsSelected" type="checkbox" id="IsSelected" value="True" checked>
        设为最新广告 </td>
    </tr>
    <tr class="tdbg"> 
      <td height="40" colspan="2" align="center"><input name="Action" type="hidden" id="Action" value="SaveAdd"> 
        <input type="submit" name="Submit" value=" 添 加 "></td>
    </tr>
  </table>
</form>
<%
end sub

sub Modify()
	dim ID
	ID=trim(request("ID"))
	if ID="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>请指定广告ID</li>"
		exit sub
	else
		ID=Clng(ID)
	end if
	sql="select * from Advertisement where ID=" & ID
	set rs=server.createobject("adodb.recordset")
	rs.open sql,conn,1,1
	if rs.bof and rs.eof then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>找不到指定的广告！</li>"
		rs.close
		set rs=nothing
		exit sub
	end if
%>
<form name="form1" method="post" action="Admin_Advertisement.asp">
  <table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="border">
    <tr class="title"> 
      <td height="22" colspan="2" align="center"><strong>修 改 广 告</strong></td>
    </tr>
    <tr class="tdbg"> 
      <td width="350"><strong>网站名称：</strong></td>
      <td width="400"> <input name="SiteName" type="text" id="SiteName" value="<%=rs("SiteName")%>" size="50" maxlength="255"></td>
    </tr>
    <tr class="tdbg"> 
      <td width="350"><strong>网站地址：</strong></td>
      <td width="400"> <input name="SiteUrl" type="text" id="SiteUrl" value="<%=rs("SiteUrl")%>" size="50" maxlength="255"></td>
    </tr>
    <tr class="tdbg"> 
      <td width="350"><strong>网站简介：</strong></td>
      <td width="400"> <input name="SiteIntro" type="text" id="SiteIntro" value="<%=rs("SiteIntro")%>" size="50" maxlength="255"></td>
    </tr>
    <tr class="tdbg"> 
      <td width="350"><strong>图片地址：</strong></td>
      <td> <input name="ImgUrl" type="text" id="ImgUrl" value="<%=rs("ImgUrl")%>" size="50" maxlength="255"></td>
    </tr>
    <tr class="tdbg"> 
      <td width="350"><strong>图片大小：</strong></td>
      <td>宽： 
        <input name="ImgWidth" type="text" id="ImgWidth" value="<%=rs("ImgWidth")%>" size="6" maxlength="5">
        像素&nbsp;&nbsp;&nbsp;&nbsp;高： 
        <input name="ImgHeight" type="text" id="ImgHeight" value="<%=rs("ImgHeight")%>" size="6" maxlength="5">
        像素</td>
    </tr>
    <tr class="tdbg"> 
      <td width="350"><strong>是否FLASH：</strong></td>
      <td><input type="radio" name="IsFlash" value="True" <% if rs("IsFlash")=true then response.write "checked"%>>
        是&nbsp;&nbsp;&nbsp;&nbsp; <input name="IsFlash" type="radio" value="False" <% if rs("IsFlash")=false then response.write "checked"%>>
        否</td>
    </tr>
    <tr class="tdbg"> 
      <td width="350">&nbsp;</td>
      <td><input name="IsSelected" type="checkbox" id="IsSelected" value="True" <% if rs("IsSelected")=true then response.write "checked"%>>
        设为最新广告 </td>
    </tr>
    <tr class="tdbg"> 
      <td height="40" colspan="2" align="center"><input name="Action" type="hidden" id="Action" value="SaveModify">
        <input name="ID" type="hidden" id="ID" value="<%=rs("ID")%>"> 
        <input type="submit" name="Submit" value=" 保 存 "></td>
    </tr>
  </table>
</form>
<%
	rs.close
	set rs=nothing
end sub
%>
</body>
</html>
<%
sub SaveAdd()
	dim SiteName,SiteUrl,SiteIntro,ImgUrl,ImgWidth,ImgHeight,IsFlash,IsSelected
	SiteName=trim(request("SiteName"))
	SiteUrl=trim(request("SiteUrl"))
	SiteIntro=trim(request("SiteIntro"))
	ImgUrl=trim(request("ImgUrl"))
	ImgWidth=trim(request("ImgWidth"))
	ImgHeight=Trim(request("ImgHeight"))
	IsFlash=trim(request("IsFlash"))
	IsSelected=trim(request("IsSelected"))
	if SiteName="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>网站名称不能为空！</li>"
	end if
	if SiteUrl="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>网站地址不能为空！</li>"
	end if
	if SiteIntro="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>网站简介不能为空！</li>"
	end if
	if ImgUrl="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>广告图片不能为空！</li>"
	end if
	if FoundErr=True then
		exit sub
	end if
	
	if SiteUrl="http://" then SiteUrl="http://www.asp163.net"
	if ImgWidth="" then 
		ImgWidth=0
	else
		ImgWidth=Cint(ImgWidth)
	end if
	if ImgHeight="" then
		ImgHeight=0
	else
		ImgHeight=Cint(ImgHeight)
	end if
	if IsFlash="" then IsFlash=false
	if IsSelected="" then IsSelected=false
	if IsSelected="True" then conn.execute "Update Advertisement set IsSelected=False where IsSelected=True"
	sql="Insert Into Advertisement (SiteName,SiteUrl,SiteIntro,ImgUrl,ImgWidth,ImgHeight,IsFlash,IsSelected) values ('" & SiteName & "','" & SiteUrl & "','" & SiteIntro & "','" & ImgUrl  & "'," & ImgWidth & "," & ImgHeight & "," & IsFlash & "," & IsSelected & ")"
	conn.execute sql
	call CloseConn()
	response.redirect "Admin_Advertisement.asp"
end sub

sub SaveModify()
	dim ID,SiteName,SiteUrl,SiteIntro,ImgUrl,ImgWidth,ImgHeight,IsFlash,IsSelected,sql,rs
	ID=trim(request("ID"))
	SiteName=trim(request("SiteName"))
	SiteUrl=trim(request("SiteUrl"))
	SiteIntro=trim(request("SiteIntro"))
	ImgUrl=trim(request("ImgUrl"))
	ImgWidth=trim(request("ImgWidth"))
	ImgHeight=Trim(request("ImgHeight"))
	IsFlash=trim(request("IsFlash"))
	IsSelected=trim(request("IsSelected"))
	if ID="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>请指定广告ID</li>"
	else
		ID=Clng(ID)
	end if
	if SiteName="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>网站名称不能为空！</li>"
	end if
	if SiteUrl="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>网站地址不能为空！</li>"
	end if
	if SiteIntro="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>网站简介不能为空！</li>"
	end if
	if ImgUrl="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>广告图片不能为空！</li>"
	end if
	if FoundErr=True then
		exit sub
	end if

	if IsSelected="True" then
		conn.execute "Update Advertisement set IsSelected=False where IsSelected=True"
	end if
	sql="select * from Advertisement where ID=" & ID
	set rs=server.createobject("adodb.recordset")
	rs.open sql,conn,1,3
	if rs.bof and rs.eof then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>找不到指定的广告！</li>"
		rs.close
		set rs=nothing
		exit sub
	end if

	if SiteUrl="http://" then SiteUrl="http://www.asp163.net"
	if ImgWidth="" then 
		ImgWidth=0
	else
		ImgWidth=Cint(ImgWidth)
	end if
	if ImgHeight="" then
		ImgHeight=0
	else
		ImgHeight=Cint(ImgHeight)
	end if
	if IsFlash="" then IsFlash=false
	if IsSelected="" then IsSelected=false
	rs("SiteName")=SiteName
	rs("SiteUrl")=SiteUrl
	rs("SiteIntro")=SiteIntro
	rs("ImgUrl")=ImgUrl
	rs("ImgWidth")=ImgWidth
	rs("ImgHeight")=ImgHeight
	rs("IsFlash")=IsFlash
	rs("IsSelected")=IsSelected
	rs.update
	rs.close
	set rs=nothing
	call CloseConn()
	response.redirect "Admin_Advertisement.asp"
end sub

sub SetNew()
	dim ID
	ID=Trim(Request("ID"))
	if ID="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>请指定广告ID</li>"
		exit sub
	end if
	conn.execute "Update Advertisement set IsSelected=False where IsSelected=True"
	if Instr(ID,",")>0 then
		dim arrID,i
		arrID=split(ID,",")
		for i=0 to Ubound(arrID)
			conn.execute "Update Advertisement set IsSelected=True Where ID=" & CLng(arrID(i))
		next
	else
		conn.execute "Update Advertisement set IsSelected=True Where ID=" & CLng(ID)
	end if
	response.Write "<script language='JavaScript' type='text/JavaScript'>alert('设置成功！');</script>"
	call main()
end sub

sub DelAD()
	dim ID
	ID=trim(Request("ID"))
	if ID="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>请指定要删除的广告ID！</li>"
		exit sub
	else
		ID=Clng(ID)
	end if
	
	sql="delete from Advertisement where ID=" & ID
	conn.Execute sql
	call CloseConn()      
	response.redirect "Admin_Advertisement.asp"
end sub
%>
