<%
dim rsNC, bTop
dim strExpDate, strStartDate, bHome, bScroll, bPhoto

errorMsg = ""
sql = ""
pid = 1
bNewsBase = false
if trim(Request("pid")) <> "" then
	pid = clng(request("pid"))
end if
if trim(Request("page")) <> "" then
	iCurrentPage = clng(request("page"))
else
	iCurrentPage = 1
end if
if trim(session("newsBase")) = "1" then
	bNewsBase = true
end if
if session("newsMenuCondition") = "" then
	session("newsMenuCondition") = "WHERE n.id=nm.nid"
end if
subaction = Request("subaction")
set rsNC = server.createobject("adodb.recordset")

if subaction = "issue" then
	bHome=0:bScroll=0:bPhoto=0
	strStartDate = FormatDateTime(Now, 0)
	strExpDate = trim(Request("newsExpDate"))
	if Request("newsTimeSwitch") = "1" then
		strStartDate = trim(Request("newsTimeSwitchDate")) &" "& Request("newsTimeSwitchHour") &":"& Request("newsTimeSwitchMinute") & ":00"
	end if
	if Request("home") = "1" then
		bHome = 1
	end if
	if Request("roll") = "1" then
		bScroll = 1
	end if
	if Request("photo") = "1" then
		bPhoto = 1
	end if

	if not IsDate(strStartDate) then
		errorMsg = errorMsg & strStartDate &"请检查起始日期是否正确！<br>"
	end if
	if not IsDate(strExpDate) then
		errorMsg = errorMsg & strExpDate  &"请检查到期日期是否正确！<br>"
	end if

	if errorMsg = "" then
		if trim(Request("SID")) <> "" then
			idList = split(trim(Request("SID")),",")
  			for i=0 to ubound(idList)
				idList(i) = trim(idList(i))
				sql = "SELECT id from cm_newsMenu WHERE cid="& pid &" AND nid="& idList(i)
				set rs = conn.Execute(sql)
				if not rs.EOF then
					sql = "UPDATE cm_newsMenu SET startDate='"& strStartDate &"',endDate='"& strExpDate &"',isMenu="& bHome &",isRoll="& bScroll &",isPhoto="& bPhoto &" WHERE cid="& pid &" AND nid="& idList(i)
				else
					sql = "INSERT INTO cm_newsMenu(nid,cid,startDate,endDate,isMenu,isRoll,isPhoto) VALUES("& idList(i) &","& pid &",'"& strStartDate &"','"& strExpDate &"',"& bHome &","& bScroll &","& bPhoto &")"
				end if
				rs.Close
				conn.Execute(sql)
			next
			errorMsg = "操作成功！"
		else
			errorMsg = "请选择需要发布的资料！"
		end if
	end if
elseif subaction = "zero" then
	sql = "update cm_newsMenu set pos=999 where cid="& pid
	conn.Execute(sql)
	errorMsg = "重置位置成功！"
elseif subaction = "pos" 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 pos='"& request("pos"& idList(i)) &"' where cid="& pid &" and id="& idList(i)
			conn.Execute(sql)
		next
		errorMsg = "修改位置成功！"
	else
		errorMsg = "请选择需要修改位置的资料！"
	end if
elseif subaction = "del" then
	id = 0
	if trim(Request("id")) <> "" then
		id = clng(request("id"))
	end if
	if id > 0 then
		sql = "delete from cm_newsMenu where cid="& pid &" and nid="& id
		conn.Execute(sql)
		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 cid="& pid &" and id="& trim(idList(i))
			conn.Execute(sql)
		next
		errorMsg = "删除成功！"
	else
		errorMsg = "请选择需要删除的资料！"
	end if
elseif subaction = "search" then
	if Request("newsBase") = "1" then
		bNewsBase = true
		session("newsBase") = "1"
		session("newsMenuCondition") = "1=1"
	else
		bNewsBase = false
		session("newsBase") = "0"
		session("newsMenuCondition") = "n.id=nm.nid"
	end if
	session("newsMenuConditionDesc") = ""
	strBeginDate = trim(Request("beginDate"))
	strEndDate = trim(Request("endDate"))

	if Request("keyword") <> "" then
		if Request("searchType") = "0" then
			session("newsMenuCondition") = session("newsMenuCondition") &" AND n.title like '%"& trim(Request("keyword")) &"%'"
			session("newsMenuConditionDesc") = session("newsMenuConditionDesc") &"关键字="& Request("keyword") &"(包括)"
		else
			session("newsMenuCondition") = session("newsMenuCondition") &" AND n.title='"& trim(Request("keyword")) &"'"
			session("newsMenuConditionDesc") = session("newsMenuConditionDesc") &"关键字="& Request("keyword") &"(等于)"
		end if
	end if
	if ((strBeginDate <> "") and (strEndDate <> "")) then
		session("newsMenuCondition") = session("newsMenuCondition") &" AND n.postTime BETWEEN '"& strBeginDate &"' AND '"& strEndDate &"'"
		session("newsMenuConditionDesc") = session("newsMenuConditionDesc") &",发布日期从"& strBeginDate &"至"+ strEndDate
	elseif (strBeginDate <> "") then
		session("newsMenuCondition") = session("newsMenuCondition") &" AND n.postTime BETWEEN '"& strBeginDate &"' AND '"& now &"'"
		session("newsMenuConditionDesc") = session("newsMenuConditionDesc") &",发布日期从"& strBeginDate &"至今"
	elseif (strEndDate <> "") then
		session("newsMenuCondition") = session("newsMenuCondition") &" AND n.postTime BETWEEN '1900-01-01' AND '"& strEndDate &"'"
		session("newsMenuConditionDesc") = session("newsMenuConditionDesc") &",发布日期至"& strEndDate
	end if
	if Request("status") <> "0" and Request("status") <> "" then
		session("newsMenuCondition") = session("newsMenuCondition") &" AND n.status="& trim(Request("status"))
		session("newsMenuConditionDesc") = session("newsMenuConditionDesc") &"状态="& newsStatus(Request("status"))
	end if
	if session("newsMenuCondition") <> "" then
		session("newsMenuCondition") = " where "& session("newsMenuCondition")
		session("newsMenuConditionDesc") = "<tr><td colspan=""5"">条件："& session("newsMenuConditionDesc") &"</td></tr>"
	end if
	if bNewsBase then
		session("newsMenuCondition") = replace(session("newsMenuCondition"),"n.","")
	end if
end if
strStartDate = FormatDateTime(Now, 0)
strStartDate = Left(strStartDate,InStr(strStartDate," "))
strExpDate =  "9999-01-01"

if errorMsg <> "" then
	DisplayMessage errorMsg,True
end if
%>
<table border="1" cellspacing="0" cellpadding="0" bordercolorlight="#CCE0CF" bordercolordark="#FFFFFF">
<form name="InfoEdit" action="functions.asp" method="post">
<input type="hidden" name="action" value="<%=action%>">
<input type="hidden" name="LOGINID" value="<%=LOGINID%>">
  <tr class="InputTableRow">
    <td align="right">当前结点：</td>
    <td>
      <select name="pid" class="ButtonSelect">
        <option value="0">请选择…</option>
<%
bTop = true
sql = "SELECT id,className FROM cm_newsClass WHERE channel='N' and 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"
			bTop = false
		end if
		Response.Write ">　　　　"& rsNC(1) &"</option>"& vbCrLf
		rsNC.MoveNext
	loop
	rsNC.Close

	rs.MoveNext
loop
rs.Close
%>
      </select>
    </td>
    <td align="center"><input type="submit" name="Submit" value="　提交　" class="ButtonReply"></td>
  </tr>
</form>
</table>
<%
if bTop then
%>
<table width="100%" border="1" cellspacing="0" cellpadding="0" bordercolorlight="#CCE0CF" bordercolordark="#FFFFFF">
  <tr class="ListTableHeader">
    <td nowrap background="images/TableHeaderBg.gif" align="center">栏目名称</td>
    <td nowrap background="images/TableHeaderBg.gif" width="60" align="center">子栏目数</td>
    <td nowrap background="images/TableHeaderBg.gif" width="40" align="center">新闻数</td>
    <td nowrap background="images/TableHeaderBg.gif" width="24" align="center">操作</td>
  </tr>
<%
	dim iSubMenuCount, iNewsCount

	sql = "select id,className,status from cm_newsClass where channel='N' and pid="& pid &" order by pos ASC, id Desc"
	rs.Open sql,conn,1,1
	if not (rs.Eof and rs.Bof) then
		do while not rs.Eof
			sql = "select count(*) from cm_newsClass where pid="& rs("id")
			rsNC.Open sql,conn,1,1
			iSubMenuCount = rsNC(0)
			rsNC.Close

			sql = "select count(*) from cm_newsMenu where cid="& rs("id")
			rsNC.Open sql,conn,1,1
			iNewsCount = rsNC(0)
			rsNC.Close
%>
  <tr class="InputTableRow" id="Row<%=rs("id")%>" onclick="javascript:setRowFocus(this,false,<%=rs("id")%>)">
    <td nowrap>&nbsp;<a href="functions.asp?action=<%=action%>&pid=<%=rs("id")%>&LOGINID=<%=LOGINID%>"><%=rs("className")%></a></td>
    <td nowrap align="right"><%=iSubMenuCount%>&nbsp;</td>
    <td nowrap align="right"><%=iNewsCount%>&nbsp;</td>
    <td nowrap align="center"><span class="OperateIcon" onclick="javascript:setRowFocus(Row<%=rs("id")%>,false,<%=rs("id")%>);delCol('<%=action%>','<%=rs("id")%>','您正要删除【<%=rs("className")%>】。\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
	rs.Close
	if not bFirst then
%>
  <tr class="InputTableRow" id="Row0" onclick="javascript:setRowFocus(this,false,0)">
    <td nowrap colspan="4">&nbsp;没有任何子栏目！</td>
  </tr>
<%
end if
%>
  </form>
</table>
<%
else
%>
<br>
<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="pid" value="<%=pid%>">
<input type="hidden" name="LOGINID" value="<%=LOGINID%>">
  <tr>
    <td height="4"></td>
  </tr>
  <tr>
    <td nowrap valign="middle">
      <span class="Search">
        <input type="checkbox" name="newsBase" value="1"<%if bNewsBase then response.write " checked" end if%>>资料库
        &nbsp;
        <input type="radio" name="searchType" value="0" checked>模糊查询
        <input type="radio" name="searchType" value="1">精确查询
        <input type="text" name="keyword" size="25" 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="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="">
  <input type="hidden" name="pid" value="<%=pid%>">
  <input type="hidden" name="LOGINID" value="<%=LOGINID%>">
  <input type="hidden" name="page" value="<%=iCurrentPage%>">
<%
	i = 0
	if bNewsBase then
		sql = "select id,title,postTime,status from cm_news "& session("newsMenuCondition") &" order by id Desc"
	else
		sql = "select nm.id,n.id as nid,nm.pos,n.title,n.postTime,n.status from cm_news n,cm_newsMenu nm "& session("newsMenuCondition") &" and nm.cid="& pid &" order by n.id Desc"
	end if
	if bNewsBase then
%>
  <tr class="ListTableHeader">
    <td nowrap background="images/TableHeaderBg.gif" colspan="6">&nbsp;发布设置</td>
  </tr>
  <tr class="InputTableRow">
    <td colspan="6">
      <table border="0" cellspacing="0" cellpadding="0" bordercolorlight="#CCE0CF" bordercolordark="#FFFFFF">
        <tr>
          <td width="32"></td>
          <td width="24"></td>
          <td width="68">到期日期：</td>
          <td width="78"><input type="text" name="newsExpDate" class="ButtonEdit" size="10" value="<%=strExpDate%>"></td>
          <td width="20"><img style="CURSOR: hand" onClick="getDate(newsExpDate);" src="tools/images/clock.gif" width="16" height="15"></td>
          <td colspan="4"></td>
        </tr>
        <tr>
          <td width="32"></td>
          <td><input type="checkbox" name="newsTimeSwitch" value="1" onclick="javascript:OnNewsTimeSwitch();"></td>
          <td>定时发布：</td>
          <td><input type="text" name="newsTimeSwitchDate" class="ButtonEdit" size="10" value="<%=strStartDate%>"></td>
          <td><img style="CURSOR: hand" onClick="getDate(newsTimeSwitchDate);" src="tools/images/clock.gif" width="16" height="15"></td>
          <td>
            <select name="newsTimeSwitchHour" class="ButtonSelect">
<%
		for j=0 to 24
			if j < 10 then
				response.write "              <option vlaue=""0"& j &""">0"& j &"</option>"& vbCrLf
			else
				response.write "              <option vlaue="""& j &""">"& j &"</option>"& vbCrLf
			end if
		next	
%>
            </select>
          </td>
          <td>时</td>
          <td>
            <select name="newsTimeSwitchMinute" class="ButtonSelect">
<%
		for j=0 to 60
			if j < 10 then
				response.write "              <option vlaue=""0"& j &""">0"& j &"</option>"& vbCrLf
			else
				response.write "              <option vlaue="""& j &""">"& j &"</option>"& vbCrLf
			end if
		next	
%>
            </select>
          </td>
          <td>分</td>
        </tr>
        <tr>
          <td width="32"></td>
          <td colspan="8">
            <table border="0" cellspacing="0" cellpadding="0" bordercolorlight="#CCE0CF" bordercolordark="#FFFFFF">
              <tr>
                <td width="24"><input type="checkbox" name="home" value="1" onclick="javascript:OnCheckboxHome();"></td>
                <td width="68">首页显示：</td>
                <td width="24"><input type="checkbox" name="roll" value="1"></td>
                <td width="68">滚动</td>
                <td width="24"><input type="checkbox" name="photo" value="1"></td>
                <td width="68">图片</td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <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="40" align="center">状态</td>
    <td nowrap background="images/TableHeaderBg.gif" width="131" align="center">发布时间</td>
    <td nowrap background="images/TableHeaderBg.gif" width="24" align="center">操作</td>
  </tr>
<%
	else
%>
  <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" width="40" align="center">位置</td>
    <td nowrap background="images/TableHeaderBg.gif" 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>
<%
	end if
	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
			if bNewsBase then
%>
  <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;<%=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("id")%>)" title="修改"><img src="images/IconEdit.gif" border="0" width="16" height="16" alt="修改"></span></td>
  </tr>
<%
			else
%>
  <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;<input type="text" name="pos<%=rs("id")%>" value="<%=rs("pos")%>" size="3" class="ButtonEdit" onChange="OnCheckIt(this.form,<%=rs("id")%>)"></td>
    <td nowrap>&nbsp;<%=rs("title")%></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")%>);delNewsMenu('<%=pid%>','<%=rs("id")%>','您正要删除【<%=rs("title")%>】。\n本操作将删除该记录。请确认！')" title="删除"><img src="images/IconDelete.gif" border="0" width="16" height="16" alt="删除"></span></td>
  </tr>
<%
			end if
			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">
<!--//
<%
	if bNewsBase then
%>
function OnNewsTimeSwitch()
{
  with (document.listForm)
  {
    newsTimeSwitchDate.disabled = ! newsTimeSwitch.checked;
    newsTimeSwitchHour.disabled = ! newsTimeSwitch.checked;
    newsTimeSwitchMinute.disabled = ! newsTimeSwitch.checked;
  }
}

function OnCheckboxHome()
{
  with (document.listForm)
  {
    roll.disabled = ! home.checked;
    photo.disabled = ! home.checked;
  }
}

function InitCheckbox()
{
  OnNewsTimeSwitch();
  OnCheckboxHome();
}

InitCheckbox();
<%
	end if
%>
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>
<%
end if
%>