<%
dim strTitle,strSubhead,strSummary,strNewsFrom,strAuthor,strContent,strWordsNum

errorMsg = ""
sql = ""
pid = -LOGINUSER
id = 0
if trim(Request("id")) <> "" then
	id = clng(request("id"))
end if
if trim(Request("page")) <> "" then
	iCurrentPage = clng(request("page"))
else
	iCurrentPage = 1
end if
if session("newsCondition") = "" then
	session("newsCondition") = " WHERE n.oid=u.id"
end if

set mrs = server.createobject("adodb.recordset")
subaction = Request("subaction")
if subaction = "edit" then
	if  Trim(Request("title")) = "" then
		errorMsg = errorMsg &"请输入资料标题！<br>"
	end if
	if Request("status") = "" then
		errorMsg = errorMsg &"请选择资料状态！<br>"
	end if
    
	if errorMsg = "" then
		if id = 0 then
sql = "insert into cm_news(title,subhead,summary,content,newsFrom,author,oid,postTime,status) values('"& HTMLSpecialChars(Request("title")) &"','"& HTMLSpecialChars(Request("subhead")) &"','"& HTMLSpecialChars(Request("summary")) &"','"& HTMLSpecialChars(Request("content")) &"','"& HTMLSpecialChars(Request("newsFrom")) &"','"& HTMLSpecialChars(Request("author")) &"',"& LOGINUSER &",GetDate(),"& Request("status") &")"
		else
			sql = "update cm_news set title='"& HTMLSpecialChars(Request("title")) &"',subhead='"& HTMLSpecialChars(Request("subhead")) &"',summary='"& HTMLSpecialChars(Request("summary")) &"',content='"& HTMLSpecialChars(Request("content")) &"',newsFrom='"& HTMLSpecialChars(Request("newsFrom")) &"',author='"& HTMLSpecialChars(Request("author")) &"',status="& Request("status") &" where id="& Request("id")
		end if
		conn.Execute(sql)
		if id = 0 then
			sql = "select max(id) from cm_news"
			set rs = conn.Execute(sql)
			if not rs.EOF then
				id = rs(0)
			end if
			rs.Close
			sql = "update cm_attachment set pid="& id &" where pid="& pid
			conn.Execute(sql)
		end if
		errorMsg = errorMsg &"操作成功，马上发布吗？请点击此处<a href=""javascript: javascript:doIssue("& id &")"">马上发布！</a><br>"
		id = 0
	end if
elseif subaction = "modify" then
	idList = Split(Trim(Request("SID")),",")
	for i=0 to UBound(idList)
		idList(i) = Trim(idList(i))
		sql = "UPDATE cm_news SET status="& Request("status"& idList(i)) &" WHERE id="& idList(i)
		conn.Execute(sql)
	next
	errorMsg = errorMsg &"批量修改成功！<br>"
elseif subaction = "delSelect" then
	idList = split(trim(Request("SID")),",")
	for i=0 to UBound(idList)
		idList(i) = Trim(idList(i))
		sql = "delete from cm_news where id="& idList(i)
		conn.Execute(sql)
	next
	errorMsg = errorMsg &"批量删除成功！<br>"
elseif subaction = "search" then
	dim strBeginDate,strEndDate
	session("newsCondition") = " WHERE n.oid=u.id"
	session("newsConditionDesc") = ""
	strBeginDate = trim(Request("beginDate"))
	strEndDate = trim(Request("endDate"))

	if Request("keyword") <> "" then
		if Request("searchType") = "0" then
			session("newsCondition") = session("newsCondition") &" AND n.title like '%"& trim(Request("keyword")) &"%'"
			session("newsConditionDesc") = session("newsConditionDesc") &"关键字="& Request("keyword") &"(包括)"
		else
			session("newsCondition") = session("newsCondition") &" AND n.title='"& trim(Request("keyword")) &"'"
			session("newsConditionDesc") = session("newsConditionDesc") &"关键字="& Request("keyword") &"(等于)"
		end if
	end if
	if Request("oid") <> "0" and Request("oid") <> "" then
		session("newsCondition") = session("newsCondition") &" AND n.oid="& trim(Request("oid"))
		session("newsConditionDesc") = session("newsConditionDesc") &"用户ID="& Request("oid")
	end if
	if ((strBeginDate <> "") and (strEndDate <> "")) then
		session("newsCondition") = session("newsCondition") &" AND n.postTime BETWEEN '"& strBeginDate &"' AND '"& strEndDate &"'"
		session("newsConditionDesc") = session("newsConditionDesc") &",发布日期从"& strBeginDate &"至"+ strEndDate
	elseif (strBeginDate <> "") then
		session("newsCondition") = session("newsCondition") &" AND n.postTime BETWEEN '"& strBeginDate &"' AND '"& now &"'"
		session("newsConditionDesc") = session("newsConditionDesc") &",发布日期从"& strBeginDate &"至今"
	elseif (strEndDate <> "") then
		session("newsCondition") = session("newsCondition") &" AND n.postTime BETWEEN '1900-01-01' AND '"& strEndDate &"'"
		session("newsConditionDesc") = session("newsConditionDesc") &",发布日期至"& strEndDate
	end if
	if Request("status") <> "0" and Request("status") <> "" then
		session("newsCondition") = session("newsCondition") &" AND n.status="& trim(Request("status"))
		session("newsConditionDesc") = session("newsConditionDesc") &"状态="& newsStatus(Request("status"))
	end if
	if session("newsConditionDesc") <> "" then
		session("newsConditionDesc") = "<tr><td colspan=""5"">条件："& session("newsConditionDesc") &"</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">
        <input type="radio" name="searchType" value="0" checked>模糊查询
        <input type="radio" name="searchType" value="1">精确查询
        <input type="text" name="keyword" size="18" 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="oid" class="ButtonSelect">
          <option value="0">请选择…</option>
<%
	sql = "SELECT id,name FROM bg_adminUser"
	if LOGINUSERPOPEDOM < 9 then
		sql = sql &" WHERE id="& LOGINUSER
	end if
	rs.Open sql,conn,1,1
	do while not rs.Eof
		Response.Write "        <option value="""& rs(0) &""">"& rs(1) &"</option>"& vbCrLf
		rs.MoveNext
	loop
	rs.Close
%>
        </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") or ((id > 0) and (subaction = "preEdit")) then
	if id > 0 then
		sql = "select title,subhead,summary,newsFrom,author,content,status from cm_news where id="& id
		rs.Open sql,conn,1,1
		if not rs.EOF then
			pid = id
			strTitle = rs("title")
			strSubhead = rs("subhead")
			strSummary = rs("summary")
			strNewsFrom = rs("newsFrom")
			strAuthor = rs("author")
			strContent = Replace(rs("content"),"""","&quot;")
			iStatus = rs("status")
		end if
		rs.Close
	end if
%>
<br>
<table id="Hedit" width="625" border="1" cellspacing="0" cellpadding="0" bordercolorlight="#CCE0CF" bordercolordark="#FFFFFF" align="center">
<form name="InfoEdit" action="functions.asp" method="post" onSubmit="return checkForm();">
<input type="hidden" name="action" value="<%=action%>">
<input type="hidden" name="subaction" value="edit">
<input type="hidden" name="id" value="<%=id%>">
<input type="hidden" name="LOGINID" value="<%=LOGINID%>">
<input type="hidden" name="iPage" value="<%=iCurrentPage%>">
<input type="hidden" name="content" value='<%=strContent%>'>
  <tr class="ListTableHeader">
    <td colspan="2" background="images/TableHeaderBg.gif" nowrap><b>新闻资料编辑</b></td>
  </tr>
  <tr class="InputTableRow">
    <td align="right" width="80">标题：</td>
    <td><input type="text" name="title" value="<%=strTitle%>" size="86" class="ButtonEdit"><font color="RED">*</font></td>
  </tr>
  <tr class="InputTableRow">
    <td align="right" width="80">副标题：</td>
    <td><input type="text" name="subhead" value="<%=strSubhead%>" size="86" class="ButtonEdit"><font color="RED">*</font></td>
  </tr>
  <tr class="InputTableRow">
    <td valign="top" align="right" width="80">摘要：</td>
    <td><textarea name="summary" cols="84" rows="3" class="DetailTextArea"><%=strSummary%></textarea></td>
  </tr>
  <tr class="InputTableRow">
    <td align="right">来源：</td>
    <td><input type="text" name="newsFrom" value="<%=strNewsFrom%>" size="86" class="ButtonEdit"></td>
  </tr>
  <tr class="InputTableRow">
    <td align="right">作者：</td>
    <td><input type="text" name="author" value="<%=strAuthor%>" size="86" class="ButtonEdit"><font color="RED">*</font></td>
  </tr>
  <tr class="InputTableRow">
    <td align="right" valign="Top">内容：</td>
    <td bgcolor="#FFFFFF">
      <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
        <tr>
          <td align="right" height="22">
            <img src="images/600.gif" height="16" style="cursor:hand" onClick="hss()">
            <img src="images/800.gif" height="16" style="cursor:hand" onClick="hzz()">
            <img src="images/1024.gif" height="16" style="cursor:hand" onClick="hbb()">
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr class="InputTableRow">
    <td bgcolor="#FFFFFF" colspan="2">
      <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
        <tr align="center">
          <td height="1"></td>
        </tr>
      </table>
      <table width="100%" border="0" cellspacing="1" cellpadding="0" align="center" >
        <tr valign="top">
          <td height="51">
            <table width="100%" border="0" cellspacing="1" cellpadding="6" bgcolor="#000000">
              <tr align="center" bgcolor="#FFFFFF">
                <td><a href="#" onClick="ck(0)"><img src="images/mainmod1.gif" width="80" height="80" border="0"></a></td>
                <td><a href="#" onClick="ck(1)"><img src="images/mainmod5.gif" width="80" height="80" border="0"></a></td>
                <td><a href="#" onClick="ck(2)"><img src="images/mainmod3.gif" width="80" height="80" border="0"></a></td>
                <td><a href="#" onClick="ck(3)"><img src="images/mainmod4.gif" width="80" height="80" border="0"></a></td>
                <td><a href="#" onClick="ck(4)"><img src="images/mainmod2.gif" width="80" height="80" border="0"></a></td>
                <td><a href="#" onClick="ck(5)"><img src="images/mainmod6.gif" width="80" height="80" border="0"></a></td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
      <table width="100%" border="0" cellspacing="1" cellpadding="0" align="center" >
        <tr valign="top">
          <td height="377" align="center">
            <script language="javascript" src="Common/zoom.js"></script>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr class="InputTableRow">
    <td align="right" valign="top">附件：</td>
    <td>
      <iframe name="attachList" frameborder="0" width="100%" height="250" scrolling="auto" src="attachment.asp?pid=<%=pid%>"></iframe>
    </td>
  </tr>
  <tr class="InputTableRow">
    <td align="right">状态：</td>
    <td>
      <select name="status" class="ButtonSelect">
	<%
	for i=1 to ubound(newsStatus)
		Response.Write "        <option value="""& i &""""
		if iStatus = i then
			Response.Write " selected"
		end if
		Response.Write ">"& newsStatus(i) &"</option>"& vbCrLf
	next
	%>
      </select>
    </td>
  </tr>
  <tr class="MainPageBar" height="28">
    <td colspan="2" align="center">
      <input type="submit" name="Submit" value="　提交　" class="ButtonReply">　<input type="button" name="Delete" value="　删除　" class="ButtonReply" onClick="javascript:if(confirm('真的要删除么？')) document.URL='<%=urlParam%>&subaction=del&id=<%=id%>';return false;">　<input type="button" name="Issue" value="　发布　" class="ButtonReset" onClick="javascript:doIssue(<%=id%>)"<% if id = 0 then response.write " disabled" end if%>>　<input type="button" name="Cancel" value="　取消　" class="ButtonReset" onClick="document.URL='<%=urlParam%>'">
    </td>
  </tr>
</form>
</table>
<script language="JavaScript">
<!--
  function checkForm()
  {
    if (document.InfoEdit.title.value.length == 0)
    {
      alert("请输入文章标题！");
      document.InfoEdit.title.focus();
      return false;
    }

    save();
    return true;
  }
//-->
</script>
<%
end if
%>
<br>
<table width="89%" 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="LOGINID" value="<%=LOGINID%>">
  <input type="hidden" name="iPage" 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 width="443" align="center" nowrap background="images/TableHeaderBg.gif">资料标题</td>
	<td nowrap background="images/TableHeaderBg.gif" width="74" align="center">作者</td>
    <td nowrap background="images/TableHeaderBg.gif" width="117" align="center">发布时间</td>
    <td nowrap background="images/TableHeaderBg.gif" width="94" align="center">状态</td>
    <td nowrap background="images/TableHeaderBg.gif" width="100" align="center">操作</td>
  </tr>
<%
i = 0
sql = "select n.id,n.title,n.postTime,u.name,n.status from cm_news n,bg_adminUser u "& session("newsCondition")
if LOGINUSERPOPEDOM <> 9 then
	sql = sql &" AND u.id="& LOGINUSER
end if
sql = sql &" 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
%>
  <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 align="center">&nbsp;<%=rs("name")%></td>
    <td nowrap align="center">&nbsp;<%=rs("postTime")%></td>
    <td nowrap align="center">
      <select name="status<%=rs("id")%>" class="ButtonSelect">
<%
		for j=1 to ubound(newsStatus)
			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")%>);edit('news',<%=rs("id")%>)" 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('news','<%=rs("id")%>','您正要删除【<%=Replace(rs("title"),"'","\'")%>】。\n本操作将删除该记录。请确认！')" title="删除"><img src="images/IconDelete.gif" border="0" width="16" height="16" alt="删除">&nbsp;</span><a href="functions.asp?action=words&id=<%=rs("id")%>&LOGINID=<%=LOGINID%>"><img src="images/man.gif" width="16" height="16" border="0"></a></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 doIssue(id)
{
  window.showModalDialog("frame.asp?action=newsIssue&LOGINID=<%=LOGINID%>&id="+ id,null,"dialogwidth=300pt;dialogheight=450pt;toolbar=no;status=no;resizable=no");
  return;
}

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>