<%
'程序作用：通用分页及删除程序
'调用格式：Call fenye()
'程序说明：使用前需定义类似以下的内容

	if Cook_userid="" then response.redirect "default.asp"


	const MaxPerPage=15
	dim totalPut
	dim CurrentPage
	dim TotalPages
	dim idlist
	dim rsfenye



Sub fenye()

	set rsfenye=server.createobject("adodb.recordset")


	if not isempty(request("page")) then
		currentPage=cint(request("page"))
	else
		currentPage=1
	end if

	dim idarr,id,DelUserName
	if not isempty(request("isDel")) and Request("submit")="删除" then
		idlist=request("isDel")
		if CurrFileName="admin_users.asp" then
			idlist=replace(idlist," ","")
			if instr(idlist,",")>0 then '删除多个
				idArr=split(idlist,",")
				for i = 0 to ubound(idarr)
					DelUserName=cstr(  Lcase( trim(idArr(i)) )  )  '
					Call deleteid(DelUserName)
				next
			else
				DelUserName=cstr(  Lcase( trim(idlist) )  )
				Call deleteid(DelUserName) '只删除一个
			end if
		else
			if instr(idlist,",")>0 then '删除多个
				idArr=split(idlist)
				for i = 0 to ubound(idarr)
					id=clng(idarr(i))
					Call deleteid(id)
				next
			else
				Call deleteid(clng(idlist)) '只删除一个
			end if
		end if
	end if

	if not isempty(request("isUse")) and Request("submit")="有效" then
		idlist=request.form("isUse")
		if instr(idlist,",")>0 then
			idArr=split(idlist)
			for i = 0 to ubound(idarr)
				id=clng(idarr(i))
				Call isUseid(id)
			next
		else
			Call isUseid(clng(idlist))
		end if
	end if

	if not isempty(request("notisUse")) and Request("submit")="无效" then
		idlist=request.form("notisUse")
		if instr(idlist,",")>0 then
			idArr=split(idlist)
			for i = 0 to ubound(idarr)
				id=clng(idarr(i))
				Call notisUseid(id)
			next
		else
			Call notisUseid(clng(idlist))
		end if
	end if
%>
<SCRIPT language=JavaScript>
function CheckAll(form){
	for (var i=0;i<form.elements.length;i++){
		var e = form.elements[i];
		e.checked = true;
		}
}
function FanAll(form){
	for (var i=0;i<form.elements.length;i++){
		var e = form.elements[i];
		if (e.checked == true){
			e.checked = false;
			}
		else {
			e.checked = true;
		}
	}
}
</SCRIPT>

<div align="center"><center>
<table border="0" width="95%" cellspacing="0" cellpadding="0">
  <tr>
    <td width="100%"><p align="center">
<form  method="post" action="<%=thisprog%>?action=fenye">
查找:  <input type="text" name="searchtxt" size="30" value="<%=request("searchtxt")%>"> <input type="submit" value="查 询">
</form>
<form name=easyForm method=Post action="<%=thisprog%>?action=fenye">
    <div align="center">
<%
rsfenye.open sqlfenye,conn,1,1
if rsfenye.eof and rsfenye.bof then
	Select Case CurrFileName
	Case "admin_setcount.asp"
		response.write "    系统没有发现任何计数页面！"
	Case "admin_article.asp"
		response.write "    系统没有发现任何您曾经发表的文章！，要加油哦 :-) "
	Case "admin_download.asp"
		response.write "    系统没有发现任何您曾经添加的下载！，要加油哦 :-) "
	Case Else
		response.write "    系统没有发现任何相关信息！"
	End Select
else
	totalPut=rsfenye.recordcount
	if currentpage<1 then
		currentpage=1
	end if
	if (currentpage-1)*MaxPerPage>totalput then
		if (totalPut mod MaxPerPage)=0 then
			currentpage= totalPut \ MaxPerPage
		else
			currentpage= totalPut \ MaxPerPage + 1
		end if
	end if
	if currentPage=1 then
		showpage totalput,MaxPerPage,thisprog  '打印当前是第几页和页索引
		showContent
		easySelect
		showpage totalput,MaxPerPage,thisprog
	else
		if (currentPage-1)*MaxPerPage<totalPut then
			rsfenye.move  (currentPage-1)*MaxPerPage
			dim bookmark
			bookmark=rsfenye.bookmark
			showpage totalput,MaxPerPage,thisprog
			showContent()
			easySelect()
			showpage totalput,MaxPerPage,thisprog
		else
			currentPage=1
			showpage totalput,MaxPerPage,thisprog
			showContent()
			easySelect()
			showpage totalput,MaxPerPage,thisprog
		end if
	end if
end if

	set rsfenye=nothing

End Sub





Sub easySelect()
Response.Write "<center><INPUT onclick=CheckAll(easyForm) type=button value=全选 name=chkall><INPUT onclick=FanAll(easyForm) type=button value=反选 name=clear2>"
End Sub




Sub showContent()
dim i
i=0
%>
      <center>
      <table cellspacing="1" width="98%" class=GrayTable cellpadding="1">
        <tr bgcolor=#EEEEEE>
          <td width="46" align="center" height="20"><strong>ID</strong></td>
          <td width="322" align="center"><strong>名称</strong></td>
<%if Cook_adminFlag<3 then%>
          <td width="30" align="center"><input type='submit' name="Submit" value='有效'></td>
          <td width="30" align="center"><input type='submit' name="Submit" value='无效'></td>
<%end if%>
          <td width="30" align="center"><input type='submit' name="Submit" value='删除'></td>
        </tr>


<%do while not rsfenye.eof%>
        <tr bgcolor=#FFFFFF>
          <td height="23" width="46"><p align="center"><%=rsfenye("id")%></td>
          <td width="322"><p align="center"><a href="<%=thisprog%>?action=mod&id=<%=rsfenye("id")%>"><%=HTMLEncode(rsfenye("name"))%></a></td>
<%if Cook_adminFlag<3 then%>
          <td width="30"><p align="center"><input type="checkbox" name="isUse" value="<%=rsfenye("id")%>" <%if rsfenye("isUse") then response.write "checked"%>></td>
          <td width="30"><p align="center"><input type="checkbox" name="notisUse" value="<%=rsfenye("id")%>" <%if not rsfenye("isUse") then response.write "checked"%>></td>
<%
end if

	if CurrFileName="admin_users.asp" then
%>
          <td width="30"><p align="center"><input type='checkbox' name='isDel' value='<%=cstr(rsfenye("name"))%>'></td>
<% else %>
          <td width="30"><p align="center"><input type='checkbox' name='isDel' value='<%=cstr(rsfenye("ID"))%>'></td>
<%
	end if
%>
        </tr>
<%
i=i+1
if i>=MaxPerPage then exit do
rsfenye.movenext
loop
rsfenye.close
%>
      </table>
      </center>
    </div></td>
  </tr>
</table></form>
</center></div>

<%
End Sub 






function showpage(totalnumber,maxperpage,filename)
  dim n
  if totalnumber mod maxperpage=0 then
     n= totalnumber \ maxperpage
  else
     n= totalnumber \ maxperpage+1
  end if
  response.write "<p align='right'>&nbsp;"
  if CurrentPage<2 then
    response.write "<span class=gray>首页 上一页</span>&nbsp;"
  else
    response.write "<a href="&filename&"?action=fenye&page=1&searchtxt="&txtitle&">首页</a>&nbsp;"
    response.write "<a href="&filename&"?action=fenye&page="&CurrentPage-1&"&searchtxt="&txtitle&">上一页</a>&nbsp;"
  end if
  if n-currentpage<1 then
    response.write "<span class=gray>下一页 尾页</span>"
  else
    response.write "<a href="&filename&"?action=fenye&page="&(CurrentPage+1)&"&searchtxt="&txtitle&">"
    response.write "下一页</a> <a href="&filename&"?action=fenye&page="&n&"&searchtxt="&txtitle&">尾页</a>"
  end if
    response.write "<span class=gray>&nbsp;页次：<span class=Gface><b><font color=red>"&CurrentPage&"</font><font color='#000080'>/"&n&"</b></span>页</span> "
    response.write "<span class=gray>&nbsp;共<span class=Gface><b>"&totalnumber&"</b></span>项  每页显示<span class=Gface><b>"&maxperpage&"</b></span>项</span>&nbsp;"
end function






Sub fenlei() '分类JAVASCRIPT 函数

dim rsel,count,isAdd_r
set rsel=server.createobject("adodb.recordset")
%>
<script language = "JavaScript">
	var onecount1;
	onecount1=0;
	rootcat = new Array();
        <%
        count = 0
	isAdd_r=0
	rsel.open "select distinct r,m,mtype from type order by r,m asc",conn,1,1
        do while not rsel.eof
		if rsel("r")>isAdd_r then
		%>
		rootcat[<%=count%>] = new Array("<%= trim(rsel("r"))%>","＋请选择二级栏目","");
		<%
			count = count + 1
		end if
        %>
rootcat[<%=count%>] = new Array("<%=trim(rsel("r"))%>","<%=trim(rsel("mtype"))%>","<%=trim(rsel("m"))%>");
        <%
		isAdd_r=rsel("r")
        	count = count + 1
        rsel.movenext
        loop
        rsel.close
        %>
onecount1=<%=count%>;

var onecount2;
onecount2=0;
subcat = new Array();
        <%
        count = 0
	isAdd_m=0
        rsel.open "select distinct m,stype,s from type order by m,s asc",conn,1,1
        do while not rsel.eof
		if rsel("m")>isAdd_m then
		%>
		subcat[<%=count%>] = new Array("<%=trim(rsel("m"))%>","＋请选择三级栏目","");
		<%
			count = count + 1
		end if
        %>
subcat[<%=count%>] = new Array("<%=trim(rsel("m"))%>","<%=trim(rsel("stype"))%>","<%=trim(rsel("s"))%>");
        <%
		isAdd_m=rsel("m")
        	count = count + 1
        rsel.movenext
        loop
        rsel.close
        %>
onecount2=<%=count%>;


function changem(locationid)
    {
    document.MyForm.m.length = 0; 

    var locationid=locationid;
    var i;
    for (i=0;i < onecount1; i++)
        {
            if (rootcat[i][0] == locationid)
            { 
                document.MyForm.m.options[document.MyForm.m.length] = new Option(rootcat[i][1], rootcat[i][2]);
            }        
        }
        
    }

function changes(locationid)
    {
    document.MyForm.s.length = 0; 

    var locationid=locationid;
    var i;
    for (i=0;i < onecount2; i++)
        {
            if (subcat[i][0] == locationid)
            { 
                document.MyForm.s.options[document.MyForm.s.length] = new Option(subcat[i][1], subcat[i][2]);
            }        
        }
        
    }    
    
</script>
<%
	dim selo
	rsel.open "select distinct r,rtype from type order by r asc",conn,1,1
	if rsel.eof and rsel.bof then
		PrintMsg("    请先添加栏目。")
	else
%>
<select name="r" onChange="changem(document.MyForm.r.options[document.MyForm.r.selectedIndex].value)">
	<option selected value="">请选择一级根栏目</option>
<%
	do while not rsel.eof
		if rsel("r")=r then
			selo="selected"
		else
			selo=""
		end if
%>
		<option <%=selo%> value="<%=trim(rsel("r"))%>"><%=trim(rsel("rtype"))%></option>
<%
	rsel.movenext
	loop
end if
rsel.close
%>
</select> 
<select name="m" onChange="changes(document.MyForm.m.options[document.MyForm.m.selectedIndex].value)">                  
<%if mtype<>"" then
  response.write "<option selected value="&m&">"&mtype&"</option>"
else
  response.write "<option selected value=>＋请选择二级栏目</option>"
end if%>
</select>
<select name="s">                  
<%if stype<>"" then
  response.write "<option selected value="&s&">"&stype&"</option>"
else
  response.write "<option selected value=>＋请选择三级栏目</option>"
end if%>
</select>
<%
End Sub







Sub showkeywords()
%>
<script language="JavaScript">
<!--

function keywords(keywords) {
document.MyForm.keywords.value=keywords;
}
 
// -->

</script>

<%
rSub.open "select distinct keywords from main order by keywords asc",conn,1,1
do while not rSub.eof
 if left(rSub("keywords"),1)<>"!" then Response.Write "<a href=javascript:keywords('"&replace(rSub("keywords")," ","&nbsp;")&"')>"&rSub("keywords")&"</a><span class=Vblue><b>/</b></span>"
rSub.movenext
loop
rSub.close
End Sub
%>