<!--#include file="users.asp" -->
<%
if session("user")="" then
	Response.redirect "index.asp"
	response.end
else
	Set admin = Server.CreateObject("ADODB.Recordset")
	asql="SELECT * FROM admin where admin='"&session("user")&"'"
	admin.OPEN asql, Conn,1,1
	if admin.eof and admin.bof then
		Response.redirect "index.asp"
		response.end
	else
		if session("pas")<>admin("pws") then
			Response.redirect "index.asp"
			response.end
		else
			if session("qx")<"2" then
				Response.redirect "index.asp"
				response.end
			end if
		end if
	end if
	admin.close
	set admin=nothing
end if
function strLength(str)
       ON ERROR RESUME NEXT
       dim WINNT_CHINESE
       WINNT_CHINESE    = (len("论坛")=2)
       if WINNT_CHINESE then
          dim l,t,c
          dim i
          l=len(str)
          t=l
          for i=1 to l
             c=asc(mid(str,i,1))
             if c<0 then c=c+65536
             if c>255 then
                t=t+1
             end if
          next
          strLength=t
       else 
          strLength=len(str)
       end if
       if err.number<>0 then err.clear
end function
if request("sort")<>"" then
	call sort()
	response.end
elseif request("small")<>"" then
	call small()
	response.end
end if
Set rs = Server.CreateObject("ADODB.Recordset")
sql="SELECT * FROM download"
rs.OPEN sql, Conn,1,1
%>
<!--#include file="code.asp" -->
<!--#include file="first.asp" -->
<table border=0 cellspacing=0 style='border-collapse:collapse' width=735 height=233 cellpadding=3>
<tr>
<td width=185 valign=top>
<!--#include file="inc.asp" -->
</td>
<td width=550 valign=top>
<center><table border=0 cellspacing=0 width=90% cellpadding=3>
<tr>
<td class=shadow2 align=center>
<b>--==分类管理==--</b></td>
</tr>
<tr>
<td class=shadow2>
<br><b>添加分类：</b></td>
</tr>
<tr>
<form method=POST action=sort.asp?sort=add>
<td>
大类：名称 <input type=text name=newsort1 size=12 class=border style='color:#000000; background-color:#efefef'>
 描述 <input type=text name=adddescription1 size=12 class=border style='color:#000000; background-color:#efefef'> 
<input type=submit value=添加 name=addsort1 class=border style='color: #000000; background-color: #efefef'>
</td>
</form></tr>
<tr>
<form method=POST action=sort.asp?small=add>
<td>
小类：名称 <input type=text name=newsort2 size=12 class=border style='color:#000000; background-color:#efefef'>
 描述 <input type=text name=adddescription2 size=12 class=border style='color:#000000; background-color:#efefef'> 
<select size=1 name=addsort1id style='color:#000000; border-style:solid; border-width:1; background-color:#efefef'>
<option value='' selected>所属大类</option>
<%
Set rssort = Server.CreateObject("ADODB.Recordset")
sqlsort="SELECT * FROM sort"
rssort.OPEN sqlsort, Conn,1,1
if not (rssort.eof and rssort.bof) then
	do while not rssort.eof
%>
<option value='<%=rssort("id")%>'><%=rssort("sort")%></option>
<%
		rssort.movenext
	loop
end if
%>
</select> 
<input type=submit value=添加 name=addsort2 class=border style='color: #000000; background-color: #efefef'>
</td>
</form></tr>
<tr>
<td class=shadow2>
<br><b>编辑分类：</b></td>
</tr>
<tr>
<form method=POST action=sort.asp?sort=edit>
<td>
大类：<select size=1 name=sortid style='color:#000000; border-style:solid; border-width:1; background-color:#efefef'>
<option value='' selected>选择大类</option>
<%
if not (rssort.eof and rssort.bof) then
	rssort.movefirst
	do while not rssort.eof
%>
<option value='<%=rssort("id")%>'><%=rssort("sort")%></option>
<%
		rssort.movenext
	loop
end if
%>
</select> 
<input type=submit value=编辑 name=editsort1 class=border style='color: #000000; background-color: #efefef'>
</td>
</form></tr>
<tr>
<form method=POST action=sort.asp?small=edit>
<td>
小类：<select size=1 name=smallid style='color:#000000; border-style:solid; border-width:1; background-color:#efefef'>
<option value='' selected>选择小类</option>
<%
Set rw = Server.CreateObject("ADODB.Recordset")
sqw="SELECT * FROM small"
rw.OPEN sqw, Conn,1,1
if not (rw.eof and rw.bof) then
	do while not rw.eof
%>
<option value='<%=rw("id")%>'><%=rw("small")%></option>
<%
		rw.movenext
	loop
end if
%>
</select> 
<input type=submit value=编辑 name=editsort2 class=border style='color: #000000; background-color: #efefef'>
</td>
</form></tr>
<tr>
<td class=shadow2>
<br><b>删除分类：</b></td>
</tr>
<tr>
<form method=POST action=sort.asp?sort=del>
<td>
大类：<select size=1 name=sortdelid style='color:#000000; border-style:solid; border-width:1; background-color:#efefef'>
<option value='' selected>选择大类</option>
<%
if not (rssort.eof and rssort.bof) then
	rssort.movefirst
	do while not rssort.eof
%>
<option value='<%=rssort("id")%>'><%=rssort("sort")%></option>
<%
		rssort.movenext
	loop
end if
%>
</select> 
<input type=submit value=删除 name=delsort1 class=border style='color: #000000; background-color: #efefef'>
</td>
</form></tr>
<tr>
<form method=POST action=sort.asp?small=del>
<td>
小类：<select size=1 name=smalldelid style='color:#000000; border-style:solid; border-width:1; background-color:#efefef'>
<option value='' selected>选择小类</option>
<%
if not (rw.eof and rw.bof) then
	rw.movefirst
	do while not rw.eof
%>
<option value='<%=rw("id")%>'><%=rw("small")%></option>
<%
		rw.movenext
	loop
end if
rw.close
set rw=nothing
%>
</select> 
<input type=submit value=删除 name=delsort2 class=border style='color: #000000; background-color: #efefef'>
</td>
</form></tr>
<tr>
<td class=shadow2><br><p style='line-height:150%'>
<img src=../images/note.gif> <b><font color=#000000>注意：</font></b>"删除分类"将删除大分类下所有小分类和小分类下的所有记录，如果该分类下的记录仍然有用，请先利用"编辑分类"功能将该分类下的记录转移到其他分类！</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
<%
sub sort()
sortl=request("sort")
Set ra = Server.CreateObject("ADODB.Recordset")
if sortl="add" then
	sqb="SELECT * FROM sort where sort='"&trim(request("newsort1"))&"'"
elseif sortl="edit" then
	if request("up")<>"" then
		sqb="SELECT * FROM sort where id="&request("ids")
	else
		sqb="SELECT * FROM sort where id="&request("sortid")
	end if
elseif sortl="del" then
	sqb="SELECT * FROM sort"
end if
ra.OPEN sqb, Conn,1,3
if sortl="add" then
	if trim(request("newsort1"))<>"" then
		if not ra.eof then
			response.write "已有该分类，请重新输入分类名"
			response.end
		end if
		if strLength(trim(request("newsort1")))>40 then
			response.write "输入的字符串太长"
			response.end
		else
			ra.addnew
			ra("sort")=trim(request("newsort1"))
		end if
	else
		response.write "请输入添加分类的名称"
		response.end
	end if
	if trim(request("adddescription1"))<>"" then
		ra("ms")=trim(request("adddescription1"))
		ra.Update
		response.write "添加完成"
		response.write "<a href=""sort.asp"">返回</a>"
	else
		ra.Update
		response.write "添加完成"
		response.write "<a href=""sort.asp"">返回</a>"
	end if
elseif sortl="edit" then
	if request("up")="" then
%>
<form method="POST" action="sort.asp?sort=edit&up=yes">
<p>编号：<input type="text" name="ids" size="3" readonly style="background-color: #C0C0C0; border: 1 solid #000000" value="<%=ra("id")%>"> 
名称：<input type="text" name="idsname" size="10" style="border: 1 solid #000000" value="<%=ra("sort")%>"> 
简介：<input type="text" name="idsjj" size="15" style="border: 1 solid #000000" value="
<%
if ra("ms")<>"" then
	response.write ra("ms")
end if
%>"> 
<input type="submit" value="提交" name="B1" style="border: 1 solid #000000"></p>
</form>
<%
	else
		if trim(request("idsname"))<>"" then
			Set rew = Server.CreateObject("ADODB.Recordset")
			sqe="SELECT * FROM sort where sort='"&trim(request("idsname"))&"'"
			rew.OPEN sqe, Conn,1,1
			if not rew.eof then
				response.write "已有该分类，请重新输入分类名"
				response.end
			end if
			rew.close
			set rew=nothing
			if strLength(trim(request("idsname")))>40 then
				response.write "输入的字符串太长"
				response.end
			else
				Set rg = Server.CreateObject("ADODB.Recordset")
				sqg="SELECT * FROM small where sortid='"&ra("sort")&"'"
				rg.OPEN sqg, Conn,3,3
			if not (rg.eof and rg.bof) then
				rg.movefirst
				do while not rg.eof
					rg("sortid")=trim(request("idsname"))
					rg.update
					alll=rg.recordcount
					il=il+1
					if il>=alll then exit do
						rg.movenext
					loop
			end if
				rg.close
				set rg=nothing
				Set rf = Server.CreateObject("ADODB.Recordset")
				sqf="SELECT * FROM download where big='"&ra("sort")&"'"
				rf.OPEN sqf, Conn,3,3
				if not (rf.eof and rf.bof) then
					rf.movefirst
					do while not rf.eof
						rf("big")=trim(request("idsname"))
						rf.update
						all=rf.recordcount
						i=i+1
					if i>=all then exit do
						rf.movenext
					loop
				end if
					rf.close
				set rf=nothing
				ra("sort")=trim(request("idsname"))
			end if
		else
			response.write "请输入修改后分类的名称"
			response.end
		end if
		if trim(request("idsjj"))<>"" then
			ra("ms")=trim(request("idsjj"))
			ra.Update
		else
			ra.Update
		end if
		response.write "修改完成"
		response.write "<a href=""sort.asp"">返回</a>"
	end if
elseif sortl="del" then
	if request("ko")="" then
%>
<form method="POST" action="sort.asp?sort=del&iddel=<%=request("sortdelid")%>&ko=yes">
<p><b><font color="#000000">注意：</font></b>&quot;<font color="#0000FF">删除分类</font>&quot;将删除大分类下所有小分类和小分类下的<font color="#0000FF">所有记录</font>，如果该分类下的记录仍然有用，请先利用&quot;编辑分类&quot;功能将该分类下的记录转移到其他分类！</p>
<p align="center">确认删除</p>
<p align="center"><input type="submit" value="提交" name="B1"> <a href="sort.asp">返回</a></p>
</form>
<%
	else
		if request("iddel")<>"" then
			Set rb = Server.CreateObject("ADODB.Recordset")
			sqz="SELECT * FROM sort where id="&request("iddel")
			rb.OPEN sqz, Conn,1,3
			if rb.eof and rb.bof then
				response.write "非法操作，没有该分类"
				response.end
			else
				idb=rb("sort")
				rb.delete
			end if
			rb.close
			set rb=nothing
			Set rc = Server.CreateObject("ADODB.Recordset")
			sqc="SELECT * FROM small where sortid='"&idb&"'"
			rc.OPEN sqc, Conn,1,3
			if not (rc.eof and rc.bof) then
			rc.movefirst
			While Not rc.EOF
				Rc.Delete
				rc.MoveNext
			Wend
			end if
			rc.close
			set rc=nothing
			Set rd = Server.CreateObject("ADODB.Recordset")
			sqd="SELECT * FROM download where big='"&idb&"'"
			rd.OPEN sqd, Conn,1,3
			if not (rd.eof and rd.bof) then
			rd.movefirst
			While Not rd.EOF
				Rd.Delete
				rd.MoveNext
			Wend
			end if
			rd.close
			set rd=nothing
			response.write "删除完成"
			response.write "<a href=""sort.asp"">返回</a>"
		else
			response.write "非法操作"
			response.end
		end if
	end if
end if
ra.close
set ra=nothing
end sub
sub small()
smalll=request("small")
Set ra = Server.CreateObject("ADODB.Recordset")
if smalll="add" then
	sqb="SELECT * FROM small where small='"&trim(request("newsort2"))&"'"
elseif smalll="edit" then
	if request("up")<>"" then
		sqb="SELECT * FROM small where id="&request("idss")
	else
		sqb="SELECT * FROM small where id="&request("smallid")
	end if
elseif smalll="del" then
	sqb="SELECT * FROM small"
end if
ra.OPEN sqb, Conn,1,3
if smalll="add" then
	if trim(request("newsort2"))<>"" then
		if not ra.eof then
			response.write "已有该分类，请重新输入分类名"
			response.end
		end if
		if strLength(trim(request("newsort2")))>40 then
			response.write "输入的字符串太长"
			response.end
		else
			Set rp = Server.CreateObject("ADODB.Recordset")
			sqp="SELECT * FROM sort where id="&request("addsort1id")
			rp.OPEN sqp, Conn,1,1
			if rp.eof and rp.bof then
				response.write "没有该大类~重新选择"
				response.end
			end if
			ra.addnew
			ra("small")=trim(request("newsort2"))
			ra("sortid")=rp("sort")
			rp.close
			set rp=nothing
		end if
	else
		response.write "请输入添加分类的名称"
		response.end
	end if
	if trim(request("adddescription2"))<>"" then
		ra("ms")=trim(request("adddescription2"))
		ra.Update
		response.write "添加完成"
		response.write "<a href=""sort.asp"">返回</a>"
	else
		ra.Update
		response.write "添加完成"
		response.write "<a href=""sort.asp"">返回</a>"
	end if
elseif smalll="edit" then
	if request("up")="" then
%>
<form method="POST" action="sort.asp?small=edit&up=yes">
<p>编号：<input type="text" name="idss" size="3" readonly style="background-color: #C0C0C0; border: 1 solid #000000" value="<%=ra("id")%>"> 
名称：<input type="text" name="idsnames" size="10" style="border: 1 solid #000000" value="<%=ra("small")%>"> 
简介：<input type="text" name="idsjjs" size="15" style="border: 1 solid #000000" value="
<%
if ra("ms")<>"" then
	response.write ra("ms")
end if
%>"> 
所属大类：<input type="text" name="idssorts" size="10" readonly style="background-color: #C0C0C0; border: 1 solid #000000" value="<%=ra("sortid")%>">
<select size=1 name=idssortsid style='color:#000000; border-style:solid; border-width:1; background-color:#efefef'>
<option value='' selected>更改所属大类</option>
<%
Set rssort = Server.CreateObject("ADODB.Recordset")
sqlsort="SELECT * FROM sort"
rssort.OPEN sqlsort, Conn,1,1
do while not rssort.eof
%>
<option value='<%=rssort("id")%>'><%=rssort("sort")%></option>
<%
rssort.movenext
loop
rssort.close
set rssort=nothing
%>
</select>
<input type="submit" value="提交" name="B1" style="border: 1 solid #000000"></p>
</form>
<%
	else
		if request("idssortsid")<>"" then
			Set rp = Server.CreateObject("ADODB.Recordset")
			sqp="SELECT * FROM sort where id="&request("idssortsid")
			rp.OPEN sqp, Conn,1,1
			Set rv = Server.CreateObject("ADODB.Recordset")
			sqv="SELECT * FROM small where id="&request("idss")
			rv.OPEN sqv, Conn,1,3
			rv("sortid")=rp("sort")
			rv.update
			rv.close
			set rv=nothing
			Set rx = Server.CreateObject("ADODB.Recordset")
			sqx="SELECT * FROM download where big='"&request("idssorts")&"'"
			rx.OPEN sqx, Conn,3,3
			if not (rx.eof and rx.bof) then
			rx.movefirst
			do while not rx.eof
				rx("big")=rp("sort")
				rx.update
				alli=rx.recordcount
				ii=ii+1
				if ii>=alli then exit do
					rx.movenext
				loop
			end if
			rx.close
			set rx=nothing
			rp.close
			set rp=nothing
		else
			if trim(request("idsnames"))<>"" then
				Set rew = Server.CreateObject("ADODB.Recordset")
				sqe="SELECT * FROM small where small='"&trim(request("idsnames"))&"'"
				rew.OPEN sqe, Conn,1,1
				if not rew.eof then
						response.write "已有该分类，请重新输入分类名"
						response.end
				end if
				rew.close
				set rew=nothing
				if strLength(trim(request("idsnames")))>40 then
					response.write "输入的字符串太长"
					response.end
				else
					Set rf = Server.CreateObject("ADODB.Recordset")
					sqf="SELECT * FROM download where sort='"&ra("small")&"'"
					rf.OPEN sqf, Conn,3,3
				if not (rf.eof and rf.bof) then
					rf.movefirst
					do while not rf.eof
						rf("sort")=trim(request("idsnames"))
						rf.update
						alle=rf.recordcount
						ie=ie+1
						if ie>=alle then exit do
							rf.movenext
						loop
				end if
					rf.close
					set rf=nothing
					ra("small")=trim(request("idsnames"))
				end if
			else
				response.write "请输入修改后分类的名称"
				response.end
			end if
		end if
		if trim(request("idsjjs"))<>"" then
			ra("ms")=trim(request("idsjjs"))
			ra.Update
		else
			ra.Update
		end if
		response.write "修改完成"
		response.write "<a href=""sort.asp"">返回</a>"
	end if
elseif smalll="del" then
	if request("ko")="" then
%>
<form method="POST" action="sort.asp?small=del&iddell=<%=request("smalldelid")%>&ko=yes">
<p><b><font color="#000000">注意：</font></b>&quot;<font color="#0000FF">删除分类</font>&quot;将删除大分类下所有小分类和小分类下的<font color="#0000FF">所有记录</font>，如果该分类下的记录仍然有用，请先利用&quot;编辑分类&quot;功能将该分类下的记录转移到其他分类！</p>
<p align="center">确认删除</p>
<p align="center"><input type="submit" value="提交" name="B1"> <a href="sort.asp">返回</a></p>
</form>
<%
	else
		if request("iddell")<>"" then
			Set rb = Server.CreateObject("ADODB.Recordset")
			sqz="SELECT * FROM small where id="&request("iddell")
			rb.OPEN sqz, Conn,1,3
			if rb.eof and rb.bof then
				response.write "非法操作，没有该分类"
				response.end
			else
				idb=rb("small")
				rb.delete
			end if
			rb.close
			set rb=nothing
			Set rd = Server.CreateObject("ADODB.Recordset")
			sqd="SELECT * FROM download where sort='"&idb&"'"
			rd.OPEN sqd, Conn,1,3
		if not (rd.eof and rd.bof) then
			While Not rd.EOF
				Rd.Delete
				rd.MoveNext
			Wend
		end if
			rd.close
			set rd=nothing
			response.write "删除完成"
			response.write "<a href=""sort.asp"">返回</a>"
		else
			response.write "非法操作"
			response.end
		end if
	end if
end if
ra.close
set ra=nothing
end sub
rssort.close
set rssort=nothing
conn.close
set conn=nothing
%>