<%
errorMsg = ""
sql = ""
if trim(Request("page")) <> "" then
	iCurrentPage = clng(request("page"))
else
	iCurrentPage = 1
end if
if session("newsAuditingCondition") = "" then
	session("newsAuditingCondition") = "where n.id=nm.nid and nm.cid=nc.id"
end if
subaction = Request("subaction")
set rsNC = server.createobject("adodb.recordset")

if subaction = "auditing" then
	if trim(Request("SID")) <> "" then
		idList = split(trim(Request("SID")),",")
		for i=0 to ubound(idList)
			idList(i) = trim(idList(i))
			sql = "update cm_newsMenu set auditing="& request("auditing") &" where id="& idList(i)
			conn.Execute(sql)
		next
		errorMsg = "操作成功！"
	else
		errorMsg = "请选择需要审核的资料！"
	end if
elseif subaction = "delSelect" then
	if trim(Request("SID")) <> "" then
		idList = split(trim(Request("SID")),",")
		for i=0 to ubound(idList)
			sql = "DELETE FROM cm_newsMenu WHERE id="& trim(idList(i))
			conn.Execute(sql)
		next
		errorMsg = "删除成功！"
	else
		errorMsg = "请选择需要删除的资料！"
	end if
elseif subaction = "search" then
	session("newsAuditingCondition") = "n.id=nm.nid and nm.cid=nc.id"
	session("newsAuditingConditionDesc") = ""
	strBeginDate = trim(Request("beginDate"))
	strEndDate = trim(Request("endDate"))

	if Request("keyword") <> "" then
		session("newsAuditingCondition") = session("newsAuditingCondition") &" AND n.title like '%"& trim(Request("keyword")) &"%'"
		session("newsAuditingConditionDesc") = session("newsAuditingConditionDesc") &"关键字="& Request("keyword") &"(包括)"
	end if
	if Request("pid") <> "0" and Request("pid") <> "" then
		session("newsAuditingCondition") = session("newsAuditingCondition") &" AND nm.cid="& trim(Request("pid"))
		session("newsAuditingConditionDesc") = session("newsAuditingConditionDesc") &"所属栏目ID="& Request("pid") &"(等于)"
	end if
	if ((strBeginDate <> "") and (strEndDate <> "")) then
		session("newsAuditingCondition") = session("newsAuditingCondition") &" AND n.postTime BETWEEN '"& strBeginDate &"' AND '"& strEndDate &"'"
		session("newsAuditingConditionDesc") = session("newsAuditingConditionDesc") &",发布日期从"& strBeginDate &"至"+ strEndDate
	elseif (strBeginDate <> "") then
		session("newsAuditingCondition") = session("newsAuditingCondition") &" AND n.postTime BETWEEN '"& strBeginDate &"' AND '"& now &"'"
		session("newsAuditingConditionDesc") = session("newsAuditingConditionDesc") &",发布日期从"& strBeginDate &"至今"
	elseif (strEndDate <> "") then
		session("newsAuditingCondition") = session("newsAuditingCondition") &" AND n.postTime BETWEEN '1900-01-01' AND '"& strEndDate &"'"
		session("newsAuditingConditionDesc") = session("newsAuditingConditionDesc") &",发布日期至"& strEndDate
	end if
	if Request("auditing") <> "0" and Request("auditing") <> "" then
		session("newsAuditingCondition") = session("newsAuditingCondition") &" AND nm.auditing="& trim(Request("auditing"))
		session("newsAuditingConditionDesc") = session("newsAuditingConditionDesc") &"状态="& newsAuditingStatus(trim(Request("auditing")))
	end if
	if Request("status") <> "0" and Request("status") <> "" then
		session("newsAuditingCondition") = session("newsAuditingCondition") &" AND n.status="& trim(Request("status"))
		session("newsAuditingConditionDesc") = session("newsAuditingConditionDesc") &"状态="& newsStatus(trim(Request("status")))
	end if
	if session("newsAuditingCondition") <> "" then
		session("newsAuditingCondition") = " where "& session("newsAuditingCondition")
		session("newsAuditingConditionDesc") = "<tr><td colspan=""5"">条件："& session("newsAuditingConditionDesc") &"</td></tr>"
	end if
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">
        &nbsp;关键字
        <input type="text" name="keyword" size="6" 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;栏目：
        <select name="pid" class="ButtonSelect">
          <option value="0">请选择…</option>
<%
sql = "SELECT id,className FROM cm_newsClass WHERE pid=1 ORDER BY pos ASC, id ASC"
rs.Open sql,conn,1,1
do while not rs.Eof
	Response.Write "          <option value="""& rs(0) &""""
	if pid = rs(0) then
		Response.Write " selected"
	end if
	Response.Write ">　　"& rs(1) &"</option>"& vbCrLf

	sql = "SELECT id,className FROM cm_newsClass WHERE pid="& rs(0) &" ORDER BY pos ASC, id ASC"
	rsNC.Open sql,conn,1,1
	do while not rsNC.Eof
		Response.Write "          <option value="""& rsNC(0) &""""
		if pid = rsNC(0) then
			Response.Write " selected"
		end if
		Response.Write ">　　　　"& rsNC(1) &"</option>"& vbCrLf
		rsNC.MoveNext
	loop
	rsNC.Close

	rs.MoveNext
loop
rs.Close
%>
        </select>
        &nbsp;审核
        <select name="auditing" class="ButtonSelect">
          <option value="0">请选择…</option>
<%
for i=1 to ubound(newsAuditingStatus)
	Response.Write "          <option value="""& i &""">"& newsAuditingStatus(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>
<table width="100%" border="1" cellspacing="0" cellpadding="0" bordercolorlight="#CCE0CF" bordercolordark="#FFFFFF">
  <form name="listForm" action="functions.asp" method="post">
  <input type="hidden" name="action" value="<%=action%>">
  <input type="hidden" name="subaction" value="auditing">
  <input type="hidden" name="auditing" value="">
  <input type="hidden" name="pid" value="<%=pid%>">
  <input type="hidden" name="LOGINID" value="<%=LOGINID%>">
  <input type="hidden" name="page" value="<%=iCurrentPage%>">
  <tr class="ListTableHeader">
    <td nowrap background="images/TableHeaderBg.gif" width="24" align="center"><input type="checkBox" name="checkAll" value="on" OnClick="OnCheckAll(this.form)"></td>
    <td nowrap background="images/TableHeaderBg.gif" align="center">资料标题</td>
    <td nowrap background="images/TableHeaderBg.gif" width="150" align="center">所属栏目</td>
    <td nowrap background="images/TableHeaderBg.gif" width="40" align="center">审核</td>
	<td nowrap background="images/TableHeaderBg.gif" width="40" align="center">状态</td>
    <td nowrap background="images/TableHeaderBg.gif" width="131" align="center">发布时间</td>
    <td nowrap background="images/TableHeaderBg.gif" width="48" align="center">操作</td>
  </tr>
<%
i = 0
strTitle = ""
sql = "select nm.id,n.id as nid,nm.pos,n.title,nc.pid,nc.className,n.postTime,nm.auditing,n.status from cm_news n,cm_newsMenu nm,cm_newsClass nc "& session("newsAuditingCondition") &" order by n.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
		sql = "SELECT className FROM cm_newsClass WHERE id="& rs("pid")
		rsNC.Open sql,conn,1,1
		if not (rsNC.Eof and rsNC.Bof) then
			strTitle = rsNC("className")
		end if
		rsNC.Close
%>
  <tr class="InputTableRow" id="Row<%=rs("id")%>" onclick="javascript:setRowFocus(this,false,<%=rs("id")%>)">
    <td nowrap align="center"><input type="checkBox" name="SID" value="<%=rs("id")%>"></td>
    <td nowrap>&nbsp;<%=rs("title")%></td>
    <td nowrap>&nbsp;<%=strTitle &"--"& rs("className")%></td>
    <td nowrap>&nbsp;<%=newsAuditingStatus(rs("auditing"))%></td>
	<td nowrap>&nbsp;<%=newsStatus(rs("status"))%></td>
    <td nowrap align="center">&nbsp;<%=rs("postTime")%></td>
    <td nowrap align="center"><span class="OperateIcon" onclick="javascript:setRowFocus(Row<%=rs("id")%>,false,<%=rs("id")%>);doEditNews(<%=rs("nid")%>)" title="修改"><img src="images/IconEdit.gif" border="0" width="16" height="16" alt="修改"></span>&nbsp;<span class="OperateIcon" onclick="javascript:setRowFocus(Row<%=rs("id")%>,false,<%=rs("id")%>);del('newsAuditing','<%=rs("id")%>','您正要删除【<%=rs("title")%>】。\n本操作将删除该记录。请确认！')" title="删除"><img src="images/IconDelete.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>
<!-- #include file="pageRobot.inc.asp" //-->
<script language="javascript">
<!--//
function doAuditing(iType)
{
  document.listForm.auditing.value = iType;
  document.listForm.submit();
}

function doEditNews(id)
{
  window.showModalDialog("frame.asp?action=news&subaction=preEdit&LOGINID=<%=LOGINID%>&id="+ id,null,"dialogwidth=640pt;dialogheight=450pt;toolbar=no;status=no;resizable=no");
  return;
}

function BatEdit(mySubAction)
{
  document.listForm.subaction.value = mySubAction;
  document.listForm.submit();
}

function getDate(target)
{
  myDate = window.showModalDialog("tools/calendar.htm",null,"dialogwidth:155pt;dialogheight:190pt,toolbar=no,status=no,resizable=no");
  target.value = myDate;
  if (target.value == "undefined")
  {
    target.value = "";
  }
  return;
}
//-->
</script>