<!--#include file="../../Conn.asp" -->
<!--#include file="../../Comm/Site_Class.asp" -->
<!--#include file="../../Comm/Function.asp" -->
<%
PagePath = "../../"

Set Qsite = New Site_Class

Qsite.SiteConfig_Master()
%>
<!--#include file="../Check_Login.asp" -->
<%
Qsite.Check_AdminFlag(arrAdminFlag(5 , 2))

If Request.Form <> "" Then
	Response.Redirect("Ad_List.asp?Keyword="& Qsite.chgStr(Trim(Request.Form("Keyword"))))
	Response.End()
End If

Dim CurrentPage,FileName
Dim Keyword,AdTypeId,AdId,strAdTypeId
Dim Act,TodayDate
Dim AdShow

Set Rs = server.createobject("ADODB.Recordset")

Keyword = Qsite.chgStr(Trim(Request.QueryString("Keyword")))
AdTypeId = Qsite.chgStr(Trim(Request.QueryString("AdTypeId")))

TodayDate = Qsite.FormatDate(Date())

If AdTypeId = "" Or IsNull(AdTypeId) Or Not IsNumeric(AdTypeId) Then AdTypeId = ""

If Keyword <> "" Then
	Sql = "select * from AdTbl where AdName like '%"& Keyword &"%' or ComName like '%"& Keyword &"%' order by AdId asc"
Else
	If AdTypeId <> "" Then
		strAdTypeId = "|" & AdTypeId & "|"
		Sql = "select * from AdTbl where AdWz like '%"& strAdTypeId &"%' order by AdId asc"
	Else
		Sql = "select * from AdTbl order by AdId asc"
	End If
End If

FileName = "Ad_List.asp?Keyword="& Keyword &"&AdTypeId="& AdTypeId

Act = Qsite.chgStr(Trim(Request.QueryString("action")))

If Act = "yq" Then
	AdId = Qsite.chgStr(Trim(Request.QueryString("AdId")))
	CurrentPage = Qsite.chgStr(Trim(Request.QueryString("Page")))
	If AdId = "" Or Not IsNumeric(AdId) Then AdId = 0
	If CurrentPage = "" Or Not IsNumeric(CurrentPage) Then CurrentPage = 1
	
	Conn.Execute("update AdTbl set ValidityDate = '"& Qsite.FormatDate(Date() + 30) &"' where AdId = "& AdId)
	
	Response.Redirect(FileName & "&page="& CurrentPage)
	Response.End()
End If

If Act = "kq" Then
	AdId = Qsite.chgStr(Trim(Request.QueryString("AdId")))
	CurrentPage = Qsite.chgStr(Trim(Request.QueryString("Page")))
	If AdId = "" Or Not IsNumeric(AdId) Then AdId = 0
	If CurrentPage = "" Or Not IsNumeric(CurrentPage) Then CurrentPage = 1
	
	Conn.Execute("update AdTbl set AdPause = '0' where AdId = "& AdId)
	
	Response.Redirect(FileName & "&page="& CurrentPage)
	Response.End()
End If

If Act = "zt" Then
	AdId = Qsite.chgStr(Trim(Request.QueryString("AdId")))
	CurrentPage = Qsite.chgStr(Trim(Request.QueryString("Page")))
	If AdId = "" Or Not IsNumeric(AdId) Then AdId = 0
	If CurrentPage = "" Or Not IsNumeric(CurrentPage) Then CurrentPage = 1
	
	Conn.Execute("update AdTbl set AdPause = '1' where AdId = "& AdId)
	
	Response.Redirect(FileName & "&page="& CurrentPage)
	Response.End()
End If

If Act = "del" Then
	AdId = Qsite.chgStr(Trim(Request.QueryString("AdId")))
	CurrentPage = Qsite.chgStr(Trim(Request.QueryString("Page")))
	If AdId = "" Or Not IsNumeric(AdId) Then AdId = 0
	If CurrentPage = "" Or Not IsNumeric(CurrentPage) Then CurrentPage = 1
	
	Conn.Execute("delete from AdTbl where AdId = "& AdId)
	
	Response.Redirect(FileName & "&page="& CurrentPage)
	Response.End()
End If
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>广告管理</title>
<link href="../skins/css/main.css" rel="stylesheet" type="text/css">
<script language="javascript">
function AdDel(AdId , strPage)
{
	var fn = "<%=FileName%>"
	var question = confirm("你确定要删除此条记录吗？");
	if (question !="0")
	{
		location.href = fn + "&action=del&AdId=" + AdId + "&page=" + strPage;
	}
}
</script>
</head>

<body>
<form name="PosForm" method="post" action="Ad_List.asp" style="margin:0">
	<table width="100%" border="0" cellspacing="1" cellpadding="5">
		<tr>
			<td height="25" class="td_title">广告搜索</td>
		</tr>
		<tr>
			<td height="23" class="td_content">广告名称/客户名称：
				<input name="Keyword" type="text" class="input_1" id="Keyword" size="50" value="<%=Keyword%>">
				<input name="Submit" type="submit" class="input_1" value="搜索"></td>
		</tr>
	</table>
	<br>
</form>
	<table width="100%" border="0" cellspacing="1" cellpadding="5">
		<tr>
			<td height="25" colspan="5" class="td_title">广告列表 -- [<a href="Ad_List.asp">所有广告</a>
			<%
			Rs.Open "select * from AdTypeTbl order by AdTypeId asc" , Conn , 1 , 1
			Do While Not Rs.Eof
				Response.Write(" | <a href=""Ad_List.asp?AdTypeId="& Rs("AdTypeId") &""">"& Rs("AdName") &"</a>")
			Rs.MoveNext
			Loop
			Rs.Close
			%>] </td>
		</tr>
		<tr>
			<td width="16%" height="23" class="td_content"><strong>广告名称</strong></td>
			<td width="29%" class="td_content"><strong>客户名称</strong></td>
			<td width="29%" class="td_content"><strong>广告位置</strong></td>
			<td width="12%" class="td_content"><strong>广告状态</strong></td>
			<td width="14%" class="td_content"><strong>操作</strong></td>
		</tr>
<%
Rs.Open Sql , Conn , 1 , 1
If Rs.Eof Then
%>
		<tr>
			<td height="23" colspan="5" class="td_content">暂无广告信息</td>
		</tr>
<%
Else
	Rs.PageSize = 20
	CurrentPage = Clng(Request("page"))
	If CurrentPage < 1 Then CurrentPage = 1
	If CurrentPage > Rs.PageCount Then CurrentPage = Rs.PageCount
	Rs.AbsolutePage = CurrentPage
	i = 0
	Do While Not Rs.Eof
		If InStr(Rs("AdPicUrl") , "http://") > 0 Then
			AdShow = Rs("AdPicUrl")
		Else
			AdShow = "../../"& Rs("AdPicUrl")
		End If
%>
		<tr>
			<td height="23" class="td_content"><a href="<%=AdShow%>" target="_blank"><%=Rs("AdName")%></a></td>
			<td height="23" class="td_content"><%=Rs("ComName")%></td>
			<td height="23" class="td_content"><%=AdWz_Name(Rs("AdWz"))%></td>
			<td class="td_content">
			<%
			If Rs("ValidityDate") < TodayDate Then
				Response.Write("<font color=""#FF0000"">过期</font> (<a href="""& FileName &"&action=yq&AdId="& Rs("AdId") &"&page="& CurrentPage &""">延期</a>)")
			Else
				If Rs("AdPause") = "1" Then
					Response.Write("<font color=""#FF0000"">暂停</font> (<a href="""& FileName &"&action=kq&AdId="& Rs("AdId") &"&page="& CurrentPage &""">开启</a>)")
				Else
					Response.Write("正常 (<a href="""& FileName &"&action=zt&AdId="& Rs("AdId") &"&page="& CurrentPage &""">暂停</a>)")
				End If
			End If
			%>
			</td>
			<td class="td_content"><a href="Ad_Edit.asp?AdId=<%=Rs("AdId")%>&Keyword=<%=Keyword%>&AdTypeId=<%=AdTypeId%>&Page=<%=CurrentPage%>">修改</a> | <a href="#" onClick="AdDel('<%=Rs("AdId")%>' , '<%=CurrentPage%>');return false;">删除</a></td>
		</tr>
<%
	i = i + 1
	Rs.MoveNext
	If i >= Rs.PageSize Then Exit Do
	Loop
%>
		<tr>
			<td height="23" colspan="5" class="td_content">
<%
	Qsite.Page_Cn CurrentPage , Rs.PageCount , Rs.RecordCount , FileName
%>			</td>
		</tr>
<%
End If
Rs.Close
%>
</table>
</body>
</html>
