<%
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_links(title,status) values('"& title &"','"& status &"')"
	end if
elseif subaction = "modify" then
	idList = split(trim(replace(Request("SID")," ","")),",")
	for i=0 to ubound(idList)
		sql = "update bs_links set 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 = "delSelect" then
	idList = split(trim(replace(Request("SID")," ","")),",")
	for i=0 to ubound(idList)
		sql = "delete from bs_links where id="& idList(i)
		conn.Execute(sql)
	next
elseif subaction = "search" then
	session("linksCondition") = ""
	session("linksConditionDesc") = ""
	if Request("title") <> "" then
		session("linksCondition") = session("linksCondition") &" AND title like '%"& trim(Request("title")) &"%'"
		session("linksConditionDesc") = session("linksConditionDesc") &"关键字="& Request("trueName") &"(包括)"
	end if
	if Request("status") <> "0" and Request("status") <> "" then
		session("linksCondition") = session("linksCondition") &" AND status="& trim(Request("status"))
		session("linksConditionDesc") = session("linksConditionDesc") &"状态="& newsStatus(Request("status"))
	end if
	if session("linksCondition") <> "" then
		session("linksCondition") = "where "& right(session("linksCondition"),len(session("linksCondition"))-5)
		session("linksConditionDesc") = "<tr><td colspan=""5"">条件："& session("linksConditionDesc") &"</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
if subaction = "add" or subaction = "search" 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="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("linksConditionDesc")%>
  <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="140" align="center">地址</td>
    <td background="images/TableHeaderBg.gif" width="60" 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,title,url,clickNum,status from bs_links "& session("linksCondition") &" 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="40" class="ButtonEdit"></td>
    <td><input type="text" name="url<% =rs("id") %>" value="<% =rs("url") %>" size="36" class="ButtonEdit"></td>
    <td align="right"><% =rs("clickNum") %>&nbsp;</td>
	<td>
      <select name="status<% =rs("id") %>" class="ButtonSelect">
<%
		for j=1 to ubound(newsStatus)-1
			Response.Write "      <option value="""& j &""""
			if CLng(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('links',<%=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" //-->