<!--#include file = "Startup.asp"-->
<!-- #include file="Function.asp" -->
<%

' ======================
' 功能：新闻列表
' ======================
call adminer()
Call Header()
Call ComeUrl()

%>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<SCRIPT language=javascript>
function unselectall()
{
    if(document.myform.chkAll.checked){
	document.myform.chkAll.checked = document.myform.chkAll.checked&0;
    } 	
}

function CheckAll(form)
  {
  for (var i=0;i<form.elements.length;i++)
    {
    var e = form.elements[i];
    if (e.Name != "chkAll"&&e.disabled==false)
       e.checked = form.chkAll.checked;
    }
  }
  
function ConfirmDel()
{
	if(document.myform.Action.value=="Del")
	{
		if(confirm("确定要彻底删除选中的资讯吗？一旦删除将不能恢复！"))
		    return true;
		else
			return false;
	}
}

function doSubmit()
{
	if (document.SearchForm.keyword.value==""){
		alert("搜索关键字不能为空，请您输入搜索关键字！！");
		return false;
	}
}
</SCRIPT>

<%
Dim z_sql,z_rs
dim w
dim strFileName,FileName,strParentPath,strParentPathw()
dim keyword,strField
dim ClassID
dim ManageType

dim PurviewChecked
dim strAdmin,arrAdmin
dim tClass,ClassName,RootID,ParentID,Depth,ParentPath,Child,ChildID,tID,tChild,ClassMaster
dim SkinID,LayoutID,BrowsePurview,AddPurview

ManageType=trim(request("ManageType"))
FileName="News_Manage.asp"
ClassID=Trim(request("ClassID"))
strField=Trim(request("Field"))
keyword=trim(request("keyword"))
If ClassID="" Then
	ClassID=0
End If
if keyword<>"" then 
	keyword=ReplaceBadChar(keyword)'过滤非法的SQL字符
end if
If ClassID <>0 Then
	sSql="Select ClassID,ClassName,ParentPath,Child From NewsClass Where ClassID="&ClassID
	oRs.Open sSql,oConn,1,1
	If Not oRs.Eof Then
		if oRs("ClassID")>0 then
			if oRs("Child")>0 then
				ChildID=""
				set tClass=oConn.execute("select ClassID from NewsClass where ParentID=" & oRs("ClassID") & " or ParentPath like '" & oRs("ParentPath") & "," & oRs("ClassID") & ",%'")
				do while not tClass.eof
					if ChildID="" then
						ChildID=tClass(0)
					else
						ChildID=ChildID & "," & tClass(0)
					end if
					tClass.movenext
				loop
			else
				ChildID=ClassID
			end if
		end if
	End If
	oRs.Close
End If
If ManageType="ClassForm" Then
	sSql="Select d_id,d_title,d_classid,d_time,d_editor,d_count From NewsData Where d_classid in ("&ChildID&") and d_recycle=false ORDER BY d_id DESC"
	FileName=FileName&"?ManageType=ClassForm&ClassID="&ClassID&"&"
	Session("FileName")=FileName
ElseIf ManageType="SearchForm" Then
	If ClassID<>0 Then
		sSql="Select d_id,d_title,d_classid,d_time,d_editor,d_count From NewsData Where d_classid in ("&ChildID&") And "&strField&" like '%"&keyword&"%' And d_recycle=false ORDER BY d_id DESC"
		FileName=FileName&"?ManageType=SearchForm&Field="&strField&"&keyword="&keyword&"&ClassID="&ClassID&"&"
	Session("FileName")=FileName
	Else
		sSql="Select d_id,d_title,d_classid,d_time,d_editor,d_count From NewsData Where "&strField&" like '%"&keyword&"%' And d_recycle=false ORDER BY d_id DESC"
		FileName=FileName&"?ManageType=SearchForm&Field="&strField&"&keyword="&keyword&"&"
	Session("FileName")=FileName
	End If
Else
	sSql="Select d_id,d_title,d_classid,d_time,d_editor,d_count From NewsData Where d_recycle=false ORDER BY d_id DESC"
	FileName="News_Manage.asp?"
	Session("FileName")=FileName
End If
oRs.Open sSql,oConn,1,1

%>
<%
const MaxPerPage=15   '单独页最大记录数 const 用来申明常量
dim totalPut   '总记录
dim CurrentPage  '当前页次
dim TotalPages   '总页数
dim i



'!-- 分页功能代码块,可独立使用
if not ors.eof then
  ors.MoveFirst  '注意放到前面来,否则到任何页总是在第一个记录上
  end if
  ors.pagesize=MaxPerPage  '设置每页最多显示多少条记录
  If trim(Request("Page"))<>"" then  '如果请求的页次不为空
	CurrentPage= CLng(request("Page"))   'clng是转换成长整型数据类型,并赋值到当前页次上
	If CurrentPage> ors.PageCount then  '如果当前页次大于总页数,则将最大页次赋值到当前页次上
		CurrentPage = ors.PageCount 
	End If 
Else 
	CurrentPage= 1 '一切条件不成立,将当前页设为第一页
End If 

 totalPut=ors.recordcount '将总记录赋值于TOTALPUT
	if CurrentPage<>1 then '如果当前页数不等于第一页
		if (currentPage-1)*MaxPerPage<totalPut then  '如果当前页减一乘以每页最大的记录数小于总记录的话
			ors.move(currentPage-1)*MaxPerPage  '相对当前记录数向后移动
			dim bookmark  '定义书签变量
			bookmark=ors.bookmark '将当前记录的标签赋于变量BOOKMARK上
		end if 
	end if

	dim n,k
	if (totalPut mod MaxPerPage)=0 then  '总记录数与每页最大记录数求余的结果为零时,则N返回整数页次,否则再加一.
		n= totalPut \ MaxPerPage
	else  
		n= totalPut \ MaxPerPage + 1  
	end if
%>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>您现在的位置： <a href="News_Manage.asp">资讯管理</a> >>
	<%
	If ClassID=0 Then
		If keyword="" Then
			Response.Write " 所有资讯"
		Else
			Response.Write " 搜索结果"
		End If
	Else
	Dim zClassID,zClassName,zParentPath,ParentPath1
	Set z_rs=Server.CreateObject("ADODB.Recordset")
	z_sql="Select ClassID,ClassName,ParentPath From NewsClass Where ClassID="&ClassID
	z_rs.Open z_sql,oConn,1,1
	If Not z_rs.Eof Then
		zClassID=z_rs("ClassID")
		zParentPath=z_rs("ParentPath")
		zClassName=z_rs("ClassName")
	End If
	z_rs.Close
	If zParentPath<>0 Then
		zParentPath=Replace(zParentPath,"0,","")
		Set z_rs=Server.CreateObject("ADODB.Recordset")
		z_sql="Select ClassID,ClassName,ParentPath From NewsClass Where ClassID in ("&zParentPath&")"
		z_rs.Open z_sql,oConn,1,1
		Do While Not z_rs.Eof
			Response.Write "<a href='News_Manage.asp?ManageType=ClassForm&ClassID="&z_rs("ClassID")&"'>"&z_rs("ClassName")&"</a>&nbsp;&gt;&gt;&nbsp;"
			z_rs.MoveNext
		Loop
		z_rs.Close
	End If
	Response.Write "<a href='News_Manage.asp?ManageType=ClassForm&ClassID="&zClassID&"'>"&zClassName&"</a>"
	End If
	%>
    </td>
    <td><div align="right">
      <select name='JumpClass' id="JumpClass" onchange="if(this.options[this.selectedIndex].value!=''){location='News_Manage.asp?ManageType=ClassForm&ClassID='+this.options[this.selectedIndex].value;}">
          <option value='' selected>跳转栏目至…</option>
	      <%call NewsClass_Option(2,0)%>
	    </select>
    </div></td>
  </tr>
  <tr>
    <td colspan="2"><img src="images/zw000.gif" width="1" height="8"></td>
  </tr>
</table>
<table width="100%"  border="0" cellpadding="3" cellspacing="1" bgcolor="#DEDFDE">
<form name="myform" method="Post" action="News_Del.asp" onsubmit="return ConfirmDel();">
<input name="FileName" type="hidden" value="<%=FileName%>">
  <tr bgcolor="#F7F7F7">
    <td width="40"><div align="center"><STRONG>选中</STRONG></div></td>
    <td bgcolor="#F7F7F7"><div align="center"><STRONG>资讯标题</STRONG></div></td>
    <td><div align="center"><strong>栏目分类</strong></div></td>
    <td><div align="center"><STRONG>录入</STRONG></div></td>
    <td width="130" bgcolor="#F7F7F7"><div align="center"><strong>添加时间</strong></div></td>
    <td width="40" bgcolor="#F7F7F7"><div align="center"><strong>修改</strong></div></td>
    <td width="40" bgcolor="#F7F7F7"><div align="center"><strong>删除</strong></div></td>
    </tr>

<%
If oRs.Eof Then
Response.Write "<tr><td bgcolor='#ffffff' colspan='7'><div align='center'>暂无新闻信息！！</div></td></tr></table><br><br>"

Else
Do While Not oRs.Eof and i<maxperpage
%> 
  
  <tr bgcolor="#FFFFFF" onmouseout="this.style.backgroundColor=''" onmouseover="this.style.backgroundColor='#F7F8F8'">
    <td width="40"><div align="center">
        <input name='NewsID' type='checkbox' onClick="unselectall()" id="NewsID" value="<%=oRs("d_id")%>">
    </div></td>
    <td><a href="News_Show.asp?newsid=<%=oRs("d_id")%>" title="新闻 ID：<%=oRs("d_id")&vbcrlf%>标　　题：<%=oRs("d_title")&vbcrlf%>添加时间：<%=oRs("d_time")&vbcrlf%>资讯添加：<%=oRs("d_editor")&vbcrlf%>点 击 数：<%=oRs("d_count")%>"><%=gotTopic(oRs("d_title"),50)%></a></td>
    <td><div align="center">
	<%
	Set z_rs=Server.CreateObject("ADODB.Recordset")
	z_sql="Select ClassName From NewsClass Where ClassID="&oRs("d_classid")
	z_rs.Open z_sql,oConn,1,1
	If Not z_rs.Eof Then
	Response.Write "<a href='News_Manage.asp?ManageType=ClassForm&ClassID="&oRs("d_classid")&"'>"&z_rs("ClassName")&"</a>"
	Else
	Response.Write "无此栏目分类"
	End If
	z_rs.Close
	%>
	</div></td>
    <td><div align="center"><%=oRs("d_editor")%></div></td>
    <td width="130"><div align="center"><%=oRs("d_time")%></div></td>
    <td width="40"><div align="center">[<a href="News_Modify.asp?id=<%=oRs("d_id")%>">修改</a>]</div></td>
    <td width="40"><div align="center">[<a href="News_Del.asp?NewsID=<%=oRs("d_id")%>&Action=Del" onclick="return ConfirmDel();">删除</a>]</div></td>
    </tr>
  
<%
oRs.MoveNext
i=i+1
Loop

%>  
  <tr bgcolor="#FFFFFF">
    <td colspan="7"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="40"><div align="center">
      <input name="chkAll" type="checkbox" id="chkAll" onclick=CheckAll(this.form) value="checkbox">
    </div></td>
    <td>选中本页显示的所有资讯</td>
    <td><div align="right"><input name="Action" type="hidden" id="Action2" value="Del"><input type="Submit" id="submit" value="　删除选中资讯　" title='删除选中资讯' onClick="document.myform.Action.value='Del'" class='input_submit'>
                &nbsp; </div></td>
  </tr>
</table>
</td>
    </tr>
</form>
</table>
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="30"><div align="center">
        <%
	Response.Write "共 <font color='#FF0000'>"&totalPut&"</font> 篇资讯　" 
          k=currentPage
		if k<>1 then
			response.write "[<b>"+"<a href='"&FileName&"page=1'>首页</a></b>] "
			response.write "[<b>"+"<a href='"&FileName&"page="&cstr(k-1)&"'>上一页</a></b>] "
		else
			Response.Write "[首页] [上一页]"
		end if
		if k<>n then
			response.write "[<b>"+"<a href='"&FileName&"page="&cstr(k+1)&"'>下一页</a></b>] "
			response.write "[<b>"+"<a href='"&FileName&"page="&cstr(n)&"'>尾页</a></b>] "
		else
			Response.Write "[下一页] [尾页]"
		end if	
		Response.Write "　页次：<font color='#ff0000'>"&currentpage&"</font>/"&n&"页　15篇资讯/页"
		%>
　转到：
<select name="select" onchange="javascript:window.location='<%=FileName%>page='+this.options[this.selectedIndex].value;">
<option>跳转页</option>
<%
Dim z
For z=1 To n%>
  <option value="<%=z%>">第<%=z%>页</option>
<%
Next
%> 
</select>
        </div></td>
  </tr></table>
<%
End If
oRs.Close
%>  

<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#DEDFDE">
  <tr>
    <td bgcolor="#FFFFFF"><table width="100%" border="0" cellpadding="3" cellspacing="0">
      <form name="SearchForm" method="post" action="News_Manage.asp">
        <tr>
          <td width="70"><strong>资讯搜索：</strong></td>
          <td width="80"><select name="Field" id="Field">
              <option value="D_Title" selected>资讯标题</option>
              <option value="D_Content">资讯内容</option>
            </select>
          </td>
          <td width="100"><select name="ClassID" id="ClassID">
            <option value="0" selected>所有栏目</option>
            <%call NewsClass_Option(1,0)%>
          </select></td>
          <td width="40"><input name="keyword" type="text" class="input_text" size="40"></td>
          <td><input type="submit" name="Submit" value="　搜　索　" class="input_submit" onClick="return doSubmit()">
            <input type="hidden" name="ManageType" value="SearchForm"></td>
        </tr>
      </form>
    </table></td>
  </tr>
</table>
