<!--#include virtual="inc/General.inc.asp"-->
<%
CheckManageUser()
code = request("code")
id = clng("0"&request("id"))
set rs = server.createobject("adodb.recordset")
p = cint("0"&request("p"))
if p<1 then p=1
pagesize=8
rs.open "select count(id) from AD",conn,1,1
totalcount=rs(0)
rs.cancel:rs.close
pagecount=totalcount / pagesize
if totalpage mod pagesize>0 then pagecount=pagecount+1
if p=1 then
strsql = "select top " & pagesize & " a.*,b.MenuName from AD a left join [Menu] b on b.MenuCode=a.MenuCode"
if code&""<>"" then strsql = strsql & " where a.TypeCode='" & code & "'"
strsql = strsql & " order by a.TypeCode asc,a.AdOrder asc,a.id desc"
else
strsql = "select top " & pagesize & " a.*,b.MenuName from AD a left join [Menu] b on b.MenuCode=a.MenuCode where a.id not in (select top " & ((p-1)*pagesize) & " id from AD"
if code&""<>"" then strsql = strsql & " where TypeCode='" & code & "'"
strsql = strsql & " order by TypeCode asc,AdOrder asc,id desc)"
if code&""<>"" then strsql = strsql & " and a.TypeCode='" & code & "'"
strsql = strsql & " order by a.TypeCode asc,a.AdOrder asc,a.id desc"
end if
rs.open strsql,conn,1,1
dim listtype(4)
listtype(0)="首页通栏广告"
listtype(1)="次页通栏广告"
listtype(2)="友情链接"
listtype(3)="相关主题"
listtype(4)="文字链接"
%>
<html>

<head>
<title>后台管理系统</title>
<link rel="stylesheet" href="../../css/main.css">
<script language="javascript" src="../../js/yzqm.js.asp"></script>
</head>

<body topmargin="0" leftmargin="0">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
  <tr>
	<td height="25" bgcolor="#EFEFEF" class="dtd" style="color:#FF6600">&nbsp;当前位置：广告管理</td>
  </tr>
  <tr>
	<td>
	  <table border="0" cellpadding="1" cellspacing="0" width="99%" align="right">
		<form name="AddForm" method="post" enctype="multipart/form-data" action="SaveAD.asp">
		<tr>
		  <td height="25">位置：<select name="TypeCode" class="inbox">
			<%for i=0 to ubound(listtype)%>
			<option value="<%=i%>"><%=listtype(i)%></option>
			<%next%>
			</select>　广告：<input type="file" name="PicPath" onchange="this.value=this.value.replace(/(^\s*)|(\s*$)|[\']/gi,'')" size="10" class="inbox">　链接：<input type="text" name="LinkUrl" onchange="this.value=this.value.replace(/(^\s*)|(\s*$)|[\']/gi,'')" size="10" class="inbox">　文字说明：<input type="text" name="AltText" onchange="this.value=this.value.replace(/(^\s*)|(\s*$)|[\']/gi,'')" size="10" class="inbox">　顺序：<input type="text" name="AdOrder" onchange="this.value=this.value.replace(/\D/gi,'')" size="4" class="inbox">　<input type="submit" value=" 添加 " class="in1"></td>
		</tr>
		</form>
		<tr>
		  <td height="25"></td>
		</tr>
		<tr>
		  <td>
			<table border="0" cellpadding="1" cellspacing="1" width="100%" bgcolor="#00599C">
			  <tr bgcolor="#A5CCFF">
				<td height="23" align="center">ID号</td>
				<td align="center"><select class="inbox" onchange="window.location.href='AD.asp?code=' + this.value">
				  <option value="">所有广告</option>
				  <%for i=0 to ubound(listtype)%>
				  <option value="<%=i%>"<%if code&""=""&i then Response.write " selected" end if%>><%=listtype(i)%></option>
				  <%next%>
				  </select></td>
				<td align="center">图片</td>
				<td align="center">位置</td>
				<td align="center">链接</td>
				<td align="center">提示</td>
				<td align="center">顺序</td>
				<td align="center">修改</td>
				<td align="center">删除</td>
			  </tr>
			  <%while not rs.eof%>
			  <%if id&""=rs("id")&"" then%>
			  <form name="EditForm" method="post" enctype="multipart/form-data" action="SaveAD.asp">
			  <tr bgcolor="#FFFFFF">
				<td height="25" align="center">&nbsp;<input type="hidden" name="idh" value="<%=rs("id")%>"><%=rs("id")%>&nbsp;&nbsp;</td>
				<td align="center">&nbsp;<select name="TypeCode" class="inbox">
				  <%for i=0 to ubound(listtype)%>
				  <option value="<%=i%>"<%if rs("TypeCode")&""=""&i then Response.write " selected" end if%>><%=listtype(i)%></option>
				  <%next%>
				  </select>&nbsp;&nbsp;</td>
				<td align="center"><%if rs("LinkUrl")&""<>"" then%><a href="<%=rs("LinkUrl")%>" target="_blank"><%end if%><%=ShowPicture(rs("PicPath"),200,60,"")%></a><br>重新上传：<input type="file" name="PicPath" onchange="this.value=this.value.replace(/(^\s*)|(\s*$)|[\']/gi,'')" size="20" class="inbox"></td>
				<td align="center"><select name="MenuCode" class="inbox">
				  <%set rs1=server.createobject("adodb.recordset")
				  rs1.open "select * from Menu order by MenuCode",conn,1,1
				  while not rs1.eof%>
				  <option value="<%=rs1("MenuCode")%>" <%if MenuCode&""=rs1("MenuCode")&"" then response.write " selected" end if%>><%=replace(space((len(rs1("MenuCode"))-2) \ 2) & rs1("MenuName")," ","　")%></option>
				  <%rs1.movenext
				  wend
				  rs1.cancel:rs1.close
				  set rs1=nothing%>
				</select></td>
				<td align="center"><input type="text" name="LinkUrl" onchange="this.value=this.value.replace(/(^\s*)|(\s*$)|[\']/gi,'')" size="10" class="inbox" value="<%=rs("LinkUrl")%>"></td>
				<td align="center"><input type="text" name="AltText" onchange="this.value=this.value.replace(/(^\s*)|(\s*$)|[\']/gi,'')" size="10" class="inbox" value="<%=rs("AltText")%>"></td>
				<td align="center"><input type="text" name="AdOrder" onchange="this.value=this.value.replace(/\D/gi,'')" class="inbox" size="3" value="<%=rs("AdOrder")%>"><input type="hidden" name="aduser"></td>
				<td align="center"><a href="#" onclick="javascirpt:EditForm.submit()">确定</a></td>
				<td align="center"><a href="AD.asp?p=<%=p%>&code=<%=code%>">取消</a></td>
			  </tr>
			  </form>
			  <%else%>
			  <tr bgcolor="#FFFFFF">
				<td height="25" align="center">&nbsp;<%=rs("id")%>&nbsp;&nbsp;</td>
				<td align="center">&nbsp;<%=listtype(right(rs("TypeCode")&"",1))%>&nbsp;&nbsp;</td>
				<td align="center"><%if rs("LinkUrl")&""<>"" then%><a href="<%=rs("LinkUrl")%>" target="_blank"><%end if%><%=ShowPicture(rs("PicPath"),200,60,"")%></a></td>
				<td align="center"><%=rs("MenuName")%></td>
				<td align="center" style="word-break:break-all"><%=rs("LinkUrl")%></td>
				<td align="center" style="word-break:break-all"><%=rs("AltText")%></td>
				<td align="center"><%=rs("AdOrder")%></td>
				<td align="center"><a href="AD.asp?id=<%=rs("id")%>&p=<%=p%>&code=<%=code%>">修改</a></td>
				<td align="center"><a href="javascript:if(confirm('你确定要删除此广告吗？')) window.location.href='DeleteAD.asp?id=<%=rs("id")%>'">删除</a></td>
			  </tr>
			  <%end if%>
			  <%rs.movenext
			  wend%>
			</table>
			<%rs.cancel:rs.close%>
		  </td>
		</tr>
		<tr>
		  <td height="25" align="right"><%if p>1 then%><a href="AD.asp?p=1&code=<%=code%>">首页</a>　<a href="AD.asp?p=<%=p-1%>&code=<%=code%>">上一页</a>　<%end if%><%if p<pagecount then%><a href="AD.asp?p=<%=p+1%>&code=<%=code%>">下一页</a>　<a href="AD.asp?p=<%=pagecount%>&code=<%=code%>">末页</a><%end if%></td>
		</tr>
	  </table>
	</td>
  </tr>
</table>
</body>

<html>
<%CloseConnection()%>