<%
errorMsg = ""
sql = ""
id = Request("id")
cid = Request("cid")
subaction = Request("subaction")
urlParam = "functions.asp?action="&action&LOGINPROPAGATEGET&"&page="&trim(Request("page"))
if trim(Request("page")) <> "" then
	iCurrentPage = clng(request("page"))
else
	iCurrentPage = 1
end if
if subaction = "add" and request("op") = "1" then
	title = HTMLSpecialChars(trim(Request("title")))
	status = Request("status")
	
	if title = "" then
		errorMsg = errorMsg &"请输入广告链接标题！<br>"
	end if
	if errorMsg = "" then
		sql = "insert into bs_ad(cid,title,writeDate,status) values('"& cid &"','"& title &"',GETDATE(),'"& status &"')"
	end if
elseif subaction = "modify" then
	idList = split(trim(replace(Request("SID")," ","")),",")
	for i=0 to ubound(idList)
		sql = "update bs_ad set cid="& Request("cid"& idList(i)) &",title='"& HTMLspecialChars(Request("title"& idList(i))) &"',url='"& HTMLspecialChars(Request("url"& idList(i))) &"',status="& Request("status"& idList(i)) &" where id="& idList(i)
		conn.Execute(sql)
	next
elseif subaction = "del" then
	idList = split(trim(Request("SID")),",")
	for i=0 to ubound(idList)
		sql = "delete from cm_news where id="& idList(i)
		conn.Execute(sql)
	next
elseif subaction = "search" then
	session("adCondition") = ""
	session("adConditionDesc") = ""
	if Request("keyword") <> "" then
		if Request("searchType") = "0" then
			session("adCondition") = session("adCondition") &" AND title like '%"& trim(Request("keyword")) &"%'"
			session("adConditionDesc") = session("adConditionDesc") &"关键字="& Request("keyword") &"(包括)"
		else
			session("adCondition") = session("adCondition") &" AND title='"& trim(Request("keyword")) &"'"
			session("adConditionDesc") = session("adConditionDesc") &"关键字="& Request("keyword") &"(等于)"
		end if
	end if
	if Request("cid") <> "0" and Request("cid") <> "" then
		session("adCondition") = session("adCondition") &" AND cid="& trim(Request("cid"))
		session("adConditionDesc") = session("adConditionDesc") &"类型="& adType(Request("cid"))
	end if
	if Request("title") <> "" then
		session("adCondition") = session("adCondition") &" AND title like '%"& trim(Request("title")) &"%'"
		session("adConditionDesc") = session("adConditionDesc") &"关键字="& Request("trueName") &"(包括)"
	end if
	if Request("status") <> "0" and Request("status") <> "" then
		session("adCondition") = session("adCondition") &" AND status="& trim(Request("status"))
		session("adConditionDesc") = session("adConditionDesc") &"状态="& newsStatus(Request("status"))
	end if
	if session("adCondition") <> "" then
		session("adCondition") = "where "& right(session("adCondition"),len(session("adCondition"))-5)
		session("adConditionDesc") = "<tr><td colspan=""5"">条件："& session("adConditionDesc") &"</td></tr>"
	end if
end if

if subaction = "preAdd" then
	subaction = "add"
end if
if sql <> "" then
	conn.Execute(sql)
	errorMsg = errorMsg &"操作成功！<br>"
	subaction = ""
end if

if errorMsg <> "" then
	DisplayMessage errorMsg,True
end if
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#E5EFE7">
<form method="post" action="functions.asp" name="searchForm">
<input type="hidden" name="action" value="<%=action%>">
<input type="hidden" name="subaction" value="search">
<input type="hidden" name="LOGINID" value="<%=LOGINID%>">
  <tr>
    <td height="4"></td>
  </tr>
  <tr>
    <td nowrap valign="middle">
      <span class="Search">
        <input type="radio" name="searchType" value="0" checked>模糊查询
        <input type="radio" name="searchType" value="1">精确查询
        <input type="text" name="keyword" size="10" maxlength="50" class="ButtonEdit" value="">
        &nbsp;发布日期从
        <input type="text" name="beginDate" class="ButtonEdit" size="10" value="">
        <img style="CURSOR: hand" onClick="getDate(beginDate);" src="tools/images/clock.gif">
        &nbsp;至
        <input type="text" name="endDate" class="ButtonEdit" size="10" value="">
        <img style="CURSOR: hand" onClick="getDate(endDate);" src="tools/images/clock.gif">
        &nbsp;&nbsp;类别
        <select name="cid" class="ButtonSelect">
          <option value="0">请选择…</option>
<%
for i=1 to ubound(adType)
	Response.Write "        <option value="""& i &""">"& adType(i) &"</option>"& vbCrLf
next
%>
        </select>
        &nbsp;状态
        <select name="status" class="ButtonSelect">
          <option value="0">请选择…</option>
<%
for i=1 to ubound(newsStatus)
	Response.Write "          <option value="""& i &""">"& newsStatus(i) &"</option>"& vbCrLf
next
%>
        </select>
        <input type="image" src="images/IconSearch.gif" border="0">
      </span>
    </td>
  </tr>
  <tr>
    <td height="5"></td>
  </tr>
  <tr>
    <td height="5"><font color="RED"></a></td>
  </tr>
</form>
</table>
<%
if subaction = "add" then
%>
<br>
<table width="300" border="1" cellspacing="0" cellpadding="0" bordercolorlight="#CCE0CF" bordercolordark="#FFFFFF" align="center">
<form action="<% =urlParam %>" method="post">
<input type="hidden" name="op" value="1">
<input type="hidden" name="subaction" value="<%=subaction%>">
  <tr class="ListTableHeader">
    <td colspan="2" background="images/TableHeaderBg.gif">操作：<% if (subaction = "add") or (subaction = "preAdd") then Response.Write "新增资料" else Response.Write "资料搜索" end if%></td>
  </tr>
  <tr class="InputTableRow">
    <td align="right">标题：</td>
    <td><input type="text" name="title" value="<% =title %>" size="16"></td>
  </tr>
  <tr class="InputTableRow">
    <td align="right">广告类型：</td>
    <td>
      <select name="cid">
	<%
	for i=0 to ubound(adType)
		Response.Write "        <option value="""& i &""">"& adType(i) &"</option>"& vbCrLf
	next
	%>
      </select>
    </td>
  </tr>
  <tr class="InputTableRow">
    <td align="right">状态：</td>
    <td>
      <select name="status">
	<%
	for i=0 to ubound(newsStatus)-1
		Response.Write "        <option value="""& i &""">"& newsStatus(i) &"</option>"& vbCrLf
	next
	%>
      </select>
    </td>
  </tr>
  <tr class="MainPageBar" height="30">
    <td colspan="2" align="center">
      <input type="submit" name="submit" value="<% if (subaction = "add") or (subaction = "preAdd") then Response.Write "　添加　" else Response.Write "　搜索　" end if%>">
      <input type="reset" name="reset" value="　取消　">
    </td>
  </tr>
</form>
</table>
<%
end if
%>
<br>
<table width="100%" border="1" cellspacing="0" cellpadding="0" bordercolorlight="#CCE0CF" bordercolordark="#FFFFFF" align="center">
<form name="listForm" action="functions.asp" method="post">
<input type="hidden" name="action" value="<%=action%>">
<input type="hidden" name="subaction" value="">
<input type="hidden" name="LOGINID" value="<%=LOGINID%>">
<input type="hidden" name="page" value="<%=iCurrentPage%>">
<%=session("adConditionDesc")%>
  <tr class="ListTableHeader">
    <td background="images/TableHeaderBg.gif" width="21"><input type="checkBox" name="checkAll" value="on" OnClick="OnCheckAll(this.form)"></td>
    <td background="images/TableHeaderBg.gif" align="center">标题</td>
    <td background="images/TableHeaderBg.gif" width="100" align="center">地址</td>
    <td background="images/TableHeaderBg.gif" width="100" align="center">类型</td>
    <td background="images/TableHeaderBg.gif" width="32" align="center">点击</td>
    <td background="images/TableHeaderBg.gif" width="32" align="center">显示</td>
    <td background="images/TableHeaderBg.gif" width="86" align="center">发布时间</td>
    <td background="images/TableHeaderBg.gif" width="60" align="center">状态</td>
    <td background="images/TableHeaderBg.gif" width="21"></td>
  </tr>
<%
i = 0
sql = "select id,cid,title,url,clickNum,showNum,writeDate,status from bs_ad "& session("adCondition") &" order by id Desc"
rs.Open sql,conn,1,1
rs.PageSize = iRowsPerPage
iMaxRowCount = rs.RecordCount
if iCurrentPage > Rs.PageCount then
	iCurrentPage = Rs.PageCount
end if

if not (rs.Eof and rs.Bof) then
	if iCurrentPage <> 1 then
		if (iCurrentPage - 1) * iRowsPerPage < Rs.RecordCount then
			Rs.Move (iCurrentPage - 1) * iRowsPerPage
		end if
	end if
	if rs.recordcount mod iRowsPerPage = 0 then
		iMaxPage = rs.RecordCount \ iRowsPerPage
	else
		iMaxPage = rs.RecordCount \ iRowsPerPage+1
	end if
	do while not rs.Eof and i < iRowsPerPage
%>
  <tr class="InputTableRow" id="Row<%=rs("id")%>" onclick="javascript:setRowFocus(this,false,<%=rs("id")%>)">
    <td><input type="checkBox" name="SID" value="<% =rs("id") %>"></td>
    <td><input type="text" name="title<% =rs("id") %>" value="<% =rs("title") %>" size="32" class="ButtonEdit"></td>
    <td><input type="text" name="url<% =rs("id") %>" value="<% =rs("url") %>" size="32" class="ButtonEdit"></td>
    <td>
      <select name="cid<% =rs("id") %>" class="ButtonSelect">
<%
		for j=1 to ubound(adType)
			Response.Write "        <option value="""& j &""""
			if rs("cid") = j then
				Response.Write " selected"
			end if
			Response.Write ">"& adType(j) &"</option>"& vbCrLf
		next
%>
      </select>
    </td>
    <td align="right"><% =rs("clickNum") %>&nbsp;</td>
    <td align="right"><% =rs("showNum") %>&nbsp;</td>
    <td nowrap align="center">&nbsp;<%=FormatDateTime(rs("writeDate"),2)%></td>
	<td>
      <select name="status<% =rs("id") %>" class="ButtonSelect">
<%
		for j=1 to ubound(newsStatus)-1
			Response.Write "      <option value="""& j &""""
			if rs("status") = j then
				Response.Write " selected"
			end if
			Response.Write ">"& newsStatus(j) &"</option>"& vbCrLf
		next
%>
      </select>
    </td>
    <td nowrap align="center"><span class="OperateIcon" onclick="javascript:setRowFocus(Row<%=rs("id")%>,false,<%=rs("id")%>);doEditImg('ad',<%=rs("id")%>)" title="图片修改"><img src="images/photo.gif" border="0" width="16" height="16" alt="修改"></span></td>
  </tr>
<%
		if bFirst = false then
%>
  <script LANGUAGE="javascript">
  <!--
	setRowFocus(Row<%=rs("id")%>,true,<%=rs("id")%>);
  //-->
  </script>
<%
			bFirst = true
		end if
		rs.MoveNext
		i = i + 1
	loop
end if
%>
</form>
</table>
<script language="javascript">
<!--//
function doEditImg(op,id)
{
	returnValue = window.showModalDialog("webGen/fileUpload.asp?currentType="+ op +"&id="+id,window,"dialogWidth:350pt;dialogHeight:215pt;help:No;scrolling:No;resizable:No;status:No");
	if(returnValue==1)
		location.reload();
}
//-->
</script>
<!-- #include file="pageRobot.inc.asp" //-->