<%
if request.cookies("buyok")("admin")="" then response.write "<meta http-equiv='refresh' content='0;URL=../admin.asp'>"
%>
<!--#include file="../include/config.asp"-->

<script language=javascript src=../include/mouse.js></script>
     <%
sub checkmanage(str)
Set mrs = conn.Execute("select * from manage where username='"&request.cookies("buyok")("admin")&"'")
if not (mrs.bof and mrs.eof) then
manage=mrs("manage")
if instr(manage,str)<=0 then
response.write "<script language='javascript'>"
response.write "alert('警告：您没有此项操作的权限！');"
response.write "location.href='quit.asp';"
response.write "</script>"
response.end
else
session("buyok_admin_login")=0
end if
else 
response.write "<script language='javascript'>"
response.write "alert('没有登陆，不能执行此操作！');"
response.write "location.href='quit.asp';"
response.write "</script>"
response.end
end if
set mrs=nothing
end sub
%>
<%call checkmanage("06")%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<LINK href="../images/css.css" type=text/css rel=stylesheet>
<LINK href="../list/newhead.css" type=text/css rel=stylesheet>
<script language="JavaScript" type="text/JavaScript">
function CheckAll(form)  {
  for (var i=0;i<form.elements.length;i++)    {
    var e = form.elements[i];
    if (e.name != 'chkall')       e.checked = form.chkall.checked; 
   }
  }
</script>
</head>
<BODY bgcolor="#D9EAFC">
<%
Set rs = conn.Execute("select * from bconfig") 
newstitle1=rs("newstitle1")
newstitle2=rs("newstitle2")
newstitle3=rs("newstitle3")
newstitle4=rs("newstitle4")
newstitle5=rs("newstitle5")
rs.close
set rs=nothing

nclass=trim(request("nclass"))
if nclass<>"" and nclass<>"1"  and nclass<>"2"  and nclass<>"3"  and nclass<>"4"  and nclass<>"5" then
	response.write "<script language='javascript'>"
	response.write "alert('没有相关新闻，单击“确定”返回上一页！');"
	response.write "location.href='javascript:history.go(-1)';"
	response.write "</script>"
	response.end
end if


action=request("action")
if action="" then
%>
		  <table height="5"><tr><td></td></tr></table>

<TABLE cellSpacing=0 cellPadding=0 width=95% border=0 style="BORDER-RIGHT: #b1bfee 1px solid; BORDER-TOP: #b1bfee 1px solid; BORDER-LEFT: #b1bfee 1px solid; BORDER-BOTTOM: #b1bfee 1px solid" 
>
  <TBODY>
    <TR> 
      <TD bgColor=#f4f5fd height=30>　<B><font color="#FF0000">&nbsp;新闻公告管理</font></B></TD>
    </TR>
  </TBODY>
</TABLE>		  <table height="5"><tr><td></td></tr></table>

<table width="95%"  border="0" cellpadding="0" cellspacing="1" bgcolor="#b1bfee">

<form action=news1.asp method=post name="newslist">

<tr bgcolor="#f4f5fd" align=center><td width=5% height="30">选</td> <td width=50%>标题（单击标题编辑新闻）</td><td width=15%>类别</td><td width=15%>发布时间</td><td width=15%>状态</td></tr>

<%
dim rs,msg_per_page
dim sql
msg_per_page = 20 '定义每页显示记录条数
sql = "select * from News"
if nclass<>"" then sql = sql + " where NewsClass='" & nclass &"'"
sql=sql+" order by uup desc, PubDate desc"

set rs=Server.CreateObject("ADODB.RecordSet")

rs.cursorlocation = 3 '使用客户端游标，可以使效率提高
rs.pagesize = msg_per_page '定义分页记录集每页显示记录数
rs.open sql,conn,1,1 

if rs.eof and rs.bof then
response.write "<tr bgcolor=#FFFFFF><td height=18 class=b colspan=5 align=center>暂时没有新闻文章</td></tr>"
end if

if err.number<>0 then '错误处理
response.write "数据库操作失败：" & err.description
err.clear
else
if not (rs.eof and rs.bof) then '检测记录集是否为空
totalrec = RS.RecordCount 'totalrec：总记录条数
if rs.recordcount mod msg_per_page = 0 then '计算总页数,recordcount:数据的总记录数
n = rs.recordcount\msg_per_page 'n:总页数
else 
n = rs.recordcount\msg_per_page+1 
end if 

currentpage = request("page") 'currentpage:当前页
If currentpage <> "" then
currentpage = clng(currentpage)
if currentpage < 1 then 
currentpage = 1
end if 
if err.number <> 0 then 
err.clear
currentpage = 1
end if
else
currentpage = 1
End if 
if currentpage*msg_per_page > totalrec and not((currentpage-1)*msg_per_page < totalrec)then 
currentPage=1
end if
rs.absolutepage = currentpage 'absolutepage：设置指针指向某页开头
rowcount = rs.pagesize 'pagesize：设置每一页的数据记录数

dim i
dim k
%>
<%
do while not rs.eof and rowcount>0
%>
              <tr bgcolor="#FFFFFF"><td height=20 class=b><input type='checkbox' value='<%=Cstr(rs("NewsId"))%>' name=id></td><td><a href="news1.asp?action=modify&id=<%=Cstr(rs("NewsId"))%>" title='编辑这篇新闻文章' ><%=rs("NewsTitle")%></a></td>
<td>
<%
if rs("NewsClass")="1" then
response.write newstitle1
elseif  rs("NewsClass")="2" then
response.write newstitle2
elseif  rs("NewsClass")="3" then
response.write newstitle3
elseif  rs("NewsClass")="4" then
response.write newstitle4
elseif  rs("NewsClass")="5" then
response.write newstitle5
end if
%>
</td><td><%=split(rs("PubDate")," ")(0)%>

</td><td> <% if rs("Online")=true then response.write "显示 " else response.write "<font color=red><b>隐藏</b></font>" end if%><% if rs("uup")=1 then response.write " 固顶" end if%></td></tr>
<%
rowcount=rowcount-1
rs.movenext   
loop
end if
end if     
rs.close
conn.close
set rs=nothing
set coon=nothing
%>
	<tr bgcolor="#FFFFFF"><td colspan=5 class=b>
	<input type='checkbox' name=chkall onclick='CheckAll(this.form)'>全选 
	<input type="submit" name="action" value="关闭" onClick="{if(confirm('确定隐藏这条新闻吗？')){this.document.newslist.submit();return true;}return false;}"> <input type="submit" name="action" value="打开" onClick="{if(confirm('确定要显示这条新闻吗？')){this.document.newslist.submit();return true;}return false;}">
	<input type="submit" name="action" value="删除" onClick="{if(confirm('该操作不可恢复！\n\n确定删除选定的新闻？')){this.document.newslist.submit();return true;}return false;}"> 
	<input type="button" name="action" onClick="javascript:location.href='news1.asp?action=addnews';" value="添加新闻">
	</td></tr>
</form></table>

<%call listPages()%>
<%end if

if action="关闭" then
	NewsId=replace(request("id")," ","")
	call prodclose()
end if

if action="打开" then
	NewsId=replace(request("id")," ","")
	call prodopen()
end if

if action="删除" then
delid=replace(request("id")," ","")
call proddel()
end if

if action="addnews" then
call newsadd()
end if

if action="modify" then
id=request("id")
call modify()
end if%></table></td></tr>
</table>
</body>
</html>

<%
sub listPages() 
if n <= 1 then exit sub 
%>
<p>>> 
<%if currentpage = 1 then%>
<font color=darkgray>首页</font>
<%else%> 
<font color=black face="arial"><a href="<%=request.ServerVariables("script_name")%>?page=1">
首页</font></a>
 <a href="<%=request.ServerVariables("script_name")%>?page=<%=currentpage-1%>">
<font color=black face="arial" >前页</a></font>
<%end if%>
<%if currentpage = n then%> 
<font color=darkgray face="arial" >后页</font>
<%else%> 
<font color=black face="arial" ><a href="<%=request.ServerVariables("script_name")%>?page=<%=currentpage+1%>">下页</a>
 <a href="<%=request.ServerVariables("script_name")%>?page=<%=n%>">末页</a></font>
<%end if%>
<font color=black face="arial" >
  总:<%=currentpage%>/<%=n%>页  <%=msg_per_page%>新闻/页   共:<%=totalrec%>新闻</font></p>
<%end sub

sub prodopen()
	if NewsId="" or isnull(NewsId) then
	response.write "<script language='javascript'>"
	response.write "alert('操作失败，您什么也没有选择。');"
	response.write "location.href='javascript:history.go(-1)';"							
	response.write "</script>"	
	response.end
	else
		Set rs=Server.CreateObject("ADODB.Recordset")
		sql="select * from News where NewsId in ("&NewsId&")"
		rs.open sql,conn,1,3
		if err.number<>0 then '错误处理
			response.write "数据库操作失败：" & err.description
			err.clear
		else
			if rs.eof and rs.bof then
				response.write "<script language='javascript'>"
				response.write "alert('该新闻不存在，或者被删除了！');"	
				response.write "location.href='news1.asp';"							
				response.write "</script>"			
			else
				Do while not rs.eof
				rs("online")=true
				rs.update
				rs.movenext
				loop				 
				response.write "<script language='javascript'>"
				response.write "alert('所选新闻文章已被打开！');"
				response.write "location.href='news1.asp';"			
				response.write "</script>"
			end if
			rs.close
			conn.close
			set rs=nothing
			set conn=nothing
		end if
	end if
end sub

sub prodclose()
	if NewsId="" or isnull(NewsId) then
	response.write "<script language='javascript'>"
	response.write "alert('操作失败，您什么也没有选择。');"
	response.write "location.href='javascript:history.go(-1)';"							
	response.write "</script>"	
	response.end
	else
		Set rs=Server.CreateObject("ADODB.Recordset")
		sql="select * from News where NewsId in ("&NewsId&")"
		rs.open sql,conn,1,3
		if err.number<>0 then '错误处理
			response.write "数据库操作失败：" & err.description
			err.clear
		else
			if rs.eof and rs.bof then
				response.write "<script language='javascript'>"
				response.write "alert('该新闻不存在，或者被删除了！');"	
				response.write "location.href='news1.asp';"				
				response.write "</script>"			
			else
				Do while not rs.eof
				rs("online")=false
				rs.update
				rs.movenext
				loop		 
				response.write "<script language='javascript'>"
				response.write "alert('所选新闻文章已被隐藏！');"
				response.write "location.href='news1.asp';"			
				response.write "</script>"
			end if
			rs.close
			conn.close
			set rs=nothing
			set conn=nothing
		end if
	end if
end sub

sub proddel()
	if delid="" or isnull(delid) then
	response.write "<script language='javascript'>"
	response.write "alert('操作失败，您什么也没有选择。');"
	response.write "location.href='javascript:history.go(-1)';"							
	response.write "</script>"	
	response.end
	else
		conn.execute("delete from News where NewsId in ("&delid&")")
		if err.number<>0 then '错误处理
			response.write "数据库操作失败：" & err.description
			err.clear
		else		
			conn.close
			set conn=nothing

	response.write "<script language='javascript'>"
	response.write "alert('所选新闻已被删除，单击“确定”返回新闻列表！');"
	response.write "location.href='news1.asp';"
	response.write "</script>"	
	response.end

		end if
	end if
end sub


sub newsadd()
	if request("add") ="ok" then	
		Set rs=Server.CreateObject("ADODB.Recordset")
		sql = "select * from News"
		rs.open sql,conn,1,3
		if err.number<>0 then '错误处理
			response.write "数据库操作失败：" & err.description
			err.clear
		else		
		rs.Addnew
		rs("NewsTitle")=request.form("NewsTitle")
		rs("NewsContain")=request.form("NewsContain")
		rs("PubDate")=request.form("PubDate")
		rs("NewsClass")=request.form("NewsClass")
		rs("Online")=request.form("Online")
		rs("OffDate")=request.form("OffDate")
		rs("Source")=request.form("Source")
		rs("uup")=request.form("uup")
		rs.update	

		rs.close
		conn.close
		set rs=nothing
		set conn=nothing

		response.write "<script language='javascript'>"
		response.write "alert('您已经成功添加一条新闻，单击“确定”返回新闻列表！');"
		response.write "location.href='news1.asp';"
		response.write "</script>"	
		response.end

		end if	
	else
%>		  <table height="5"><tr><td></td></tr></table>

<TABLE cellSpacing=0 cellPadding=0 width=95% border=0 style="BORDER-RIGHT: #b1bfee 1px solid; BORDER-TOP: #b1bfee 1px solid; BORDER-LEFT: #b1bfee 1px solid; BORDER-BOTTOM: #b1bfee 1px solid" 
>
  <TBODY>
    <TR>
      <TD width="90%" bgColor=#f4f5fd><font color="#000000">　<B><font color="#FF0000">添加新闻公告</font></B></font></TD>
      <TD bgColor=#f4f5fd height=30><font color="#000000"></font></TD>
    </TR>
  </TBODY>
</TABLE>		  <table height="5"><tr><td></td></tr></table>

<table width="95%"  border="0" cellpadding="5" cellspacing="1" bgcolor="#b1bfee">
	<form name="addnews" method="post" action='news1.asp?action=addnews'>
	 <TR bgcolor="#FFFFFF"><TD>新闻标题：<input name="NewsTitle" type="text" value="" size="50" maxlength="50"></TD></TR>
<TR bgcolor="#FFFFFF"><TD>新闻类别：<select name="NewsClass">
	<option value="1" selected><%=newstitle1%></option>
	<%if newstitle2<>"" then%><option value="2"><%=newstitle2%></option><%end if%>
	<%if newstitle3<>"" then%><option value="3"><%=newstitle3%></option><%end if%>
	<%if newstitle4<>"" then%><option value="4"><%=newstitle4%></option><%end if%>
	<%if newstitle5<>"" then%><option value="5"><%=newstitle5%></option><%end if%>
</select>
</TD></TR>
<TR bgcolor="#FFFFFF"><TD>
<textarea name="NewsContain"  style="display:none"></textarea>
<iframe ID="edit1" src="../edit/ewebeditor.asp?id=NewsContain&style=putong" frameborder="0" scrolling="no" width="98%" HEIGHT="350"></iframe> 
</TD></TR>
	 <TR bgcolor="#FFFFFF"><TD>新闻来源：<input name="Source" type="text" value="<%=sitename%>" size="40" maxlength="20"></TD></TR>
	 <TR bgcolor="#FFFFFF"><TD>生效日期：<input name="PubDate" type="text" value="<%=now()%>" size="40" maxlength="20"></TD></TR>
	 <TR bgcolor="#FFFFFF"><TD>失效日期：<input name="OffDate" type="text" value="<%=now()+731%>" size="40" maxlength="20"></TD></TR>
	 <TR bgcolor="#FFFFFF"><TD>是否在线：<input type="radio" name="Online" value="0" checked>否 <input type="radio" name="Online" value="1">是</TD></TR>
	 <TR bgcolor="#FFFFFF"><TD>是否固顶：<input type="radio" name="uup" value="0" checked>否 <input type="radio" name="uup" value="1">是</TD></TR>
	 <TR bgcolor="#FFFFFF"><TD><INPUT TYPE="hidden" name=add value=ok><input type="submit" name="submit" value="添加完成"> <input type="reset" name="Submit2" value="重新填写"></TD></TR>
	</form>
</TABLE>

<%		
end if
end sub


sub modify()
if id="" then
	response.write "<script language='javascript'>"
	response.write "alert('提交了不正确的参数，单击“确定”返回！');"
	response.write "location.href='news1.asp';"
	response.write "</script>"	
	response.end
end if
	'修改新闻资料
	if request("modify")="ok" then
	Set rs=Server.CreateObject("ADODB.Recordset")
	sql = "select * from News where NewsId="&id
	rs.open sql,conn,1,3
		if not (rs.eof and rs.bof) then
		rs("NewsContain")=request.form("NewsContain")
		rs("NewsTitle")=request.form("NewsTitle")
		rs("PubDate")=request.form("PubDate")
		rs("NewsClass")=request.form("NewsClass")
		rs("Online")=request.form("Online")
		rs("uup")=request.form("uup")
		rs("OffDate")=request.form("OffDate")
		rs("Source")=request.form("Source")
		rs.update
		end if

	rs.close
	set rs=nothing

	response.write "<script language='javascript'>"
	response.write "alert('新闻修改完成，单击“确定”返回新闻列表！');"
	response.write "location.href='news1.asp';"
	response.write "</script>"	
	response.end
	end if

	'显示详细资料
	set rs = server.createobject("adodb.recordset")
	sql = "select * from News where NewsId="&id
	rs.open sql,conn,1,1
	if not (rs.eof and rs.bof) then 
	%>
	
		  <table height="5"><tr><td></td></tr></table>
<TABLE cellSpacing=0 cellPadding=0 width=95% border=0 style="BORDER-RIGHT: #b1bfee 1px solid; BORDER-TOP: #b1bfee 1px solid; BORDER-LEFT: #b1bfee 1px solid; BORDER-BOTTOM: #b1bfee 1px solid" 
>
  <TBODY>
    <TR>
      <TD width="90%" bgColor=#f4f5fd><font color="#000000">　<B><font color="#FF0000">编辑新闻公告</font></B></font></TD>
      <TD bgColor=#f4f5fd height=30><font color="#000000"></font></TD>
    </TR>
  </TBODY>
</TABLE>
		  <table height="5"><tr><td></td></tr></table>

<table width="95%"  border="0" cellpadding="5" cellspacing="1" bgcolor="#b1bfee">
	<form name="editnews" method="post" action='news1.asp?action=modify&id=<%=id%>'>
	<TR bgcolor="#FFFFFF"><TD>新闻标题：<input name="NewsTitle" type="text" value="<%=rs("NewsTitle")%>" size="50" maxlength="50"></TD></TR>

<TR bgcolor="#FFFFFF"><TD>新闻类别：<select name="NewsClass">
	<option value="1" <%if rs("NewsClass")="1" then%>selected<%end if%>><%=newstitle1%></option>
	<%if newstitle2<>"" then%><option value="2" <%if rs("NewsClass")="2" then%>selected<%end if%>><%=newstitle2%></option><%end if%>
	<%if newstitle3<>"" then%><option value="3" <%if rs("NewsClass")="3" then%>selected<%end if%>><%=newstitle3%></option><%end if%>
	<%if newstitle4<>"" then%><option value="4" <%if rs("NewsClass")="4" then%>selected<%end if%>><%=newstitle4%></option><%end if%>
	<%if newstitle5<>"" then%><option value="5" <%if rs("NewsClass")="5" then%>selected<%end if%>><%=newstitle5%></option><%end if%>
</select>
</TD></TR>
	 <TR bgcolor="#FFFFFF"><TD>
<textarea name="NewsContain"  style="display:none"><%=Server.HTMLEncode(rs("NewsContain"))%></textarea>

<iframe ID="edit2" src="../edit/ewebeditor.asp?id=NewsContain&style=putong" frameborder="0" scrolling="no" width="98%" HEIGHT="350"></iframe> 

</TD></TR>
	 <TR bgcolor="#FFFFFF"><TD>新闻来源：<input name="Source" type="text" value="<%=rs("Source")%>" size="20" maxlength="20"></TD></TR>
	 <TR bgcolor="#FFFFFF"><TD>生效日期：<input name="PubDate" type="text" value="<%=rs("pubdate")%>" size="20" maxlength="20"></TD></TR>
	 <TR bgcolor="#FFFFFF"><TD>失效日期：<input name="OffDate" type="text" value="<%=rs("offdate")%>" size="20" maxlength="20"></TD></TR>
	<TR bgcolor="#FFFFFF"><TD>是否在线：<input type="radio" name="Online" value="0" <%if rs("Online")=false then%>checked<%end if%>>否<input type="radio" name="Online" value="1" <%if rs("Online")=true then%>checked<%end if%>> 是 </TD></TR>
	<TR bgcolor="#FFFFFF"><TD>是否固顶：<input type="radio" name="uup" value="0" <%if rs("uup")=0 then%>checked<%end if%>>否<input type="radio" name="uup" value="1" <%if rs("uup")=1 then%>checked<%end if%>>  是</TD></TR>
	<TR bgcolor="#FFFFFF"><TD><INPUT TYPE="hidden" name=modify value=ok><input type="submit" name="submit" value="提交修改"> <input type="reset" name="Submit2" value="重新修改"></TD></TR>
	</form></TABLE>

	<%
	end if
	rs.close
	set rs=nothing
end sub
%>
