<%if session("admin")="" then
response.write"你没有登录或是非法用户!<meta http-equiv=refresh content='1;url=../index.asp'>"
response.End()
end if%>
<!--#include file=conn.asp-->
<!--#include file="../config.asp"-->

<head>
<link href=../style.css rel=stylesheet type=text/css>
<form method=post action=adminassort.asp>
</head>
<table width="80%"  border="1" align="center" cellpadding="0" cellspacing="0" bordercolorlight="#000000" bordercolordark="#FFFFFF" height="104">
  <tr>
    <td height="23" align="center" bgcolor="eeeeee"><font style="font-size:14px">删除、修改一级分类</font></td>
  </tr>
  <tr>
    <td align="center" bgcolor="#FFFFFF" height="77">
	<%if request("del")="删除" then
	if request("topic")="" then
	response.write"分类不能为空!<meta http-equiv=refresh content='1;url=adminassort.asp'>"
	response.End()
	else
	topic=request("topic")
	'删除该主题相关问题和答复
	rs2.open"select * from class where topic='"&topic&"'",conn,1,1
	clid=rs2("id")
	rs2.close
rs1.open"select * from assort where shuxing="&clid&"",conn,1,1
if not rs1.eof then
	rs2.open"select * from assort where shuxing="&clid&"",conn,1,1
	topic1=rs2("topic")
	rs2.close
	rs2.open"select * from question where topic='"&topic1&"'",conn,1,3
	while not rs2.eof
	rs3.open"select * from reply where replyid="&rs2("id"),conn,1,3
	while not rs3.eof
	'修改解决数和回复数、积分
	rs4.open"select * from person where name='"&rs3("replyer")&"'",conn,1,3
	if rs3("isdeal")=1 then
	rs4("replynum")=rs4("replynum")-1
	rs4("helpnum")=rs4("helpnum")-1
	rs4("jifen")=rs4("jifen")-dajiadf-dadf
	temp=rs4("jifen")-dajiadf-dadf
	else
	rs4("replynum")=rs4("replynum")-1
	rs4("jifen")=rs4("jifen")-dadf
	temp=rs4("jifen")-dadf
	end if
	if temp<fen2 then
		  rs4("touxian")=""&ji1&" 一级"
	      elseif temp>=fen2 and temp<fen3 then
		  rs4("touxian")=""&ji2&" 二级"
		  elseif temp>=fen3 and temp<fen4 then
		  rs4("touxian")=""&ji3&" 三级"
		  elseif temp>=fen4 and temp<fen5 then
		  rs4("touxian")=""&ji4&" 四级"
		  elseif temp>=fen5 and temp<fen6 then
		  rs4("touxian")=""&ji5&" 五级"
		  elseif temp>=fen6 and temp<fen7 then
		  rs4("touxian")=""&ji6&" 六级"
		  elseif temp>=fen7 and temp<fen8 then
		  rs4("touxian")=""&ji7&" 七级"
		  elseif temp>=fen8 and temp<fen9 then
		  rs4("touxian")=""&ji8&" 八级"
		  elseif temp>=fen9 and temp<fen10 then
		  rs4("touxian")=""&ji9&" 九级"
		  elseif temp>=fen10 then
		  rs4("touxian")=""&ji10&" 十级"
		  end if	
		  rs4.update
	rs4.close
	'
	rs3.delete
	rs3.movenext
	wend
	rs3.close
	'修改发表问题数和积分
	rs4.open"select * from person where name='"&rs2("sender")&"'",conn,1,3
	rs4("asknum")=rs4("asknum")-1
	rs4("jifen")=rs4("jifen")+twf
	temp=rs4("jifen")+twf
	if temp<fen2 then
		  rs4("touxian")=""&ji1&" 一级"
	      elseif temp>=fen2 and temp<fen3 then
		  rs4("touxian")=""&ji2&" 二级"
		  elseif temp>=fen3 and temp<fen4 then
		  rs4("touxian")=""&ji3&" 三级"
		  elseif temp>=fen4 and temp<fen5 then
		  rs4("touxian")=""&ji4&" 四级"
		  elseif temp>=fen5 and temp<fen6 then
		  rs4("touxian")=""&ji5&" 五级"
		  elseif temp>=fen6 and temp<fen7 then
		  rs4("touxian")=""&ji6&" 六级"
		  elseif temp>=fen7 and temp<fen8 then
		  rs4("touxian")=""&ji7&" 七级"
		  elseif temp>=fen8 and temp<fen9 then
		  rs4("touxian")=""&ji8&" 八级"
		  elseif temp>=fen9 and temp<fen10 then
		  rs4("touxian")=""&ji9&" 九级"
		  elseif temp>=fen10 then
		  rs4("touxian")=""&ji10&" 十级"
		  end if
	rs4.update
	rs4.close
	'
	rs2.delete
	rs2.movenext
	wend
	rs2.close
	rs2.open"select * from assort where shuxing="&clid&"",conn,1,3
  while not rs2.eof
  rs2.delete
  rs2.movenext
  wend
  rs2.close
end if
rs1.close
	rs.open"select * from class where topic='"&topic&"'",conn,1,3
	rs.delete
	rs.close
	response.write"分类删除成功!<meta http-equiv=refresh content='1;url=adminassort.asp'>"
	response.End()
	end if
	end if%>
	<%if request("up2")="修改" then
if request("paixu")="" then
	response.write"分类排序不能为空!<meta http-equiv=refresh content='1;url=adminassort.asp'>"
	response.End()
	end if
if not IsNumeric(request("paixu")) then
	response.write"分类排序只能为数字!<meta http-equiv=refresh content='1;url=adminassort.asp'>"
	response.End()
	end if
	if request("topic")="" then
	response.write"分类名称不能为空!<a href=javascript:history.back()>返回</a>"
	response.End()
	else
	rs.open"select * from class where id<>"&cint(request("id")),conn,1,1
	while not rs.eof
	if request("topic")=rs("topic") then
	response.write"分类名称已经存在!<a href=javascript:history.back()>返回</a>"
	response.End()
	end if
	rs.movenext
	wend
	rs.close
		
	rs.open"select * from class where id="&cint(request("id")),conn,1,3
	rs("topic")=request("topic")
	rs("paixu")=request("paixu")
	rs.update
	rs.close
	response.write"分类修改成功!<meta http-equiv=refresh content='1;url=adminassort.asp'>"
	response.End()
	end if
	end if%>
	<%if request("up")="修改" then
	if request("topic")="" then
	response.write"分类不能为空!<meta http-equiv=refresh content='1;url=adminassort.asp'>"
	response.End()
	else
	rs.open"select * from class where topic='"&request("topic")&"'",conn,1,1
	id=rs("id")%>
	<form method=post action=adminassort.asp>
	<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align=center>
	<input type=hidden name="id" value=<%=rs("id")%>>
	分类名称:<input type=text size=12 name="topic" value=<%=request("topic")%> >&nbsp;分类排序:<input type=text size=4 name="paixu" value=<%=rs("paixu")%> >&nbsp;<input type=submit name="up2" value="修改"></td>
  </tr>
</table></form>

      <%rs.close
	response.End()
	end if
	end if%>
	分类:                                    
      <select name="topic">
	    <%rs.open"select * from class",conn,1,1
	  while not rs.eof%>
	    <option value=<%=rs("topic")%>><%=rs("topic")%></option>
	    <%rs.movenext
	  wend
	  rs.close%>
      </select>
      <br>
      <input name="del" type="submit" id="del" value="删除">
      <input name="up" type="submit" id="up" value="修改">                                    
      </td>
      </tr>
      </table>
      </form>

<table width="80%"  border="1" align="center" cellpadding="0" cellspacing="0" bordercolordark="#FFFFFF" bordercolorlight="#000000" height="150">
  <tr>
    <td height="1" align="center" bgcolor="eeeeee"><font style="font-size:14px">删除、修改二级分类</font></td>
  </tr>
  <tr>
    <td align="center" bgcolor="#FFFFFF" height="65">
	<%if request("del_2")="删除" then
	if request("topic")="" then
	response.write"分类不能为空!<meta http-equiv=refresh content='1;url=adminassort.asp'>"
	response.End()
	else
	topic=request("topic")
	'删除该主题相关问题和答复
	rs2.open"select * from question where topic='"&topic&"'",conn,1,3
	while not rs2.eof
	rs3.open"select * from reply where replyid="&rs2("id"),conn,1,3
	while not rs3.eof
	'修改解决数和回复数、积分
	rs4.open"select * from person where name='"&rs3("replyer")&"'",conn,1,3
	if rs3("isdeal")=1 then
	rs4("replynum")=rs4("replynum")-1
	rs4("helpnum")=rs4("helpnum")-1
	rs4("jifen")=rs4("jifen")-dajiadf-dadf
	temp=rs4("jifen")-dajiadf-dadf
	else
	rs4("replynum")=rs4("replynum")-1
	rs4("jifen")=rs4("jifen")-dadf
	temp=rs4("jifen")-dadf
	end if
	if temp<fen2 then
		  rs4("touxian")=""&ji1&" 一级"
	      elseif temp>=fen2 and temp<fen3 then
		  rs4("touxian")=""&ji2&" 二级"
		  elseif temp>=fen3 and temp<fen4 then
		  rs4("touxian")=""&ji3&" 三级"
		  elseif temp>=fen4 and temp<fen5 then
		  rs4("touxian")=""&ji4&" 四级"
		  elseif temp>=fen5 and temp<fen6 then
		  rs4("touxian")=""&ji5&" 五级"
		  elseif temp>=fen6 and temp<fen7 then
		  rs4("touxian")=""&ji6&" 六级"
		  elseif temp>=fen7 and temp<fen8 then
		  rs4("touxian")=""&ji7&" 七级"
		  elseif temp>=fen8 and temp<fen9 then
		  rs4("touxian")=""&ji8&" 八级"
		  elseif temp>=fen9 and temp<fen10 then
		  rs4("touxian")=""&ji9&" 九级"
		  elseif temp>=fen10 then
		  rs4("touxian")=""&ji10&" 十级"
		  end if
	rs4.update
	rs4.close
	'
	rs3.delete
	rs3.movenext
	wend
	rs3.close
	'修改发表问题数和积分
	rs4.open"select * from person where name='"&rs2("sender")&"'",conn,1,3
	rs4("asknum")=rs4("asknum")-1
	rs4("jifen")=rs4("jifen")+twf
	temp=rs4("jifen")+twf
	if temp<fen2 then
		  rs4("touxian")=""&ji1&" 一级"
	      elseif temp>=fen2 and temp<fen3 then
		  rs4("touxian")=""&ji2&" 二级"
		  elseif temp>=fen3 and temp<fen4 then
		  rs4("touxian")=""&ji3&" 三级"
		  elseif temp>=fen4 and temp<fen5 then
		  rs4("touxian")=""&ji4&" 四级"
		  elseif temp>=fen5 and temp<fen6 then
		  rs4("touxian")=""&ji5&" 五级"
		  elseif temp>=fen6 and temp<fen7 then
		  rs4("touxian")=""&ji6&" 六级"
		  elseif temp>=fen7 and temp<fen8 then
		  rs4("touxian")=""&ji7&" 七级"
		  elseif temp>=fen8 and temp<fen9 then
		  rs4("touxian")=""&ji8&" 八级"
		  elseif temp>=fen9 and temp<fen10 then
		  rs4("touxian")=""&ji9&" 九级"
		  elseif temp>=fen10 then
		  rs4("touxian")=""&ji10&" 十级"
		  end if
	rs4.update
	rs4.close
	'
	rs2.delete
	rs2.movenext
	wend
	rs2.close
	'
	rs.open"select * from assort where topic='"&topic&"'",conn,1,3
	rs.delete
	rs.close
	response.write"分类删除成功!<meta http-equiv=refresh content='1;url=adminassort.asp'>"
	response.End()
	end if
	end if%>
	<%if request("up2_2")="修改" then
if request("paixu")="" then
	response.write"分类排序不能为空!<meta http-equiv=refresh content='1;url=adminassort.asp'>"
	response.End()
	end if
if not IsNumeric(request("paixu")) then
	response.write"分类排序只能为数字!<meta http-equiv=refresh content='1;url=adminassort.asp'>"
	response.End()
	end if
	if request("topic")="" then
	response.write"分类名称不能为空!<a href=javascript:history.back()>返回</a>"
	response.End()
	else
	rs.open"select * from assort where id<>"&cint(request("id")),conn,1,1
	while not rs.eof
	if request("topic")=rs("topic") then
	response.write"分类名称已经存在!<a href=javascript:history.back()>返回</a>"
	response.End()
	end if
	rs.movenext
	wend
	rs.close
	'更新问题中的topic字段
	rs.open"select * from assort where id="&cint(request("id")),conn,1,1
	oldtopic=rs("topic")
	rs.close
	rs.open"select * from question where topic='"&oldtopic&"'",conn,1,3
	while not rs.eof
	rs("topic")=request("topic")
	rs.update
	rs.movenext
	wend
	rs.close
	
	'response.write cint(request.("id"))
	'response.End()
	rs.open"select * from class where topic='"&request("topic1")&"'",conn,1,1
    sxid=rs("id")
	rs.close
	rs.open"select * from assort where id="&cint(request("id")),conn,1,3
	rs("topic")=request("topic")
	rs("shuxing")=sxid
	rs("paixu")=request("paixu")
	rs.update
	rs.close
	response.write"分类修改成功!<meta http-equiv=refresh content='1;url=adminassort.asp'>"
	response.End()
	end if
	end if%>
	<%if request("up_2")="修改" then
	if request("topic")="" then
	response.write"分类不能为空!<meta http-equiv=refresh content='1;url=adminassort.asp'>"
	response.End()
	else
	rs.open"select * from assort where topic='"&request("topic")&"'",conn,1,1
	id=rs("id")%><form method=post action=adminassort.asp>
	<input type=hidden name="id" value=<%=rs("id")%>>
	分类名称:<input type=text size=12 name="topic" value=<%=request("topic")%> >&nbsp;分类排序:<input type=text size=4 name="paixu" value=<%=rs("paixu")%> >&nbsp;现属分类:<font color="#FF0000">
	<%rs2.open"select * from class where id="&rs("shuxing")&"",conn,1,1%><%=rs2("topic")%></font>&nbsp;修改为:                         
	<select name="topic1">
	    <%rs1.open"select * from class",conn,1,1
	    while not rs1.eof
	    %>
	    <option <%if rs1("topic")=rs2("topic") then%>selected<%end if%> value=<%=rs1("topic")%>><%=rs1("topic")%></option>
	    <%
	    rs1.movenext
	  wend
	    rs1.close%>
      </select><%rs2.close%> 
	<%end if%>                           
    <input type=submit name="up2_2" value="修改"><br></td>                          
  </tr>
</form>

      <%rs.close
	response.End()
	end if%><form method=post action=adminassort.asp>
	分类:                             
      <select name="topic">
	    <%rs.open"select * from assort",conn,1,1
	  while not rs.eof%>
	    <option value=<%=rs("topic")%>><%=rs("topic")%></option>
	    <%rs.movenext
	  wend
	  rs.close%>
      </select>
      <br>
      <input name="del_2" type="submit" id="del_2" value="删除">
      <input name="up_2" type="submit" id="up_2" value="修改">                             
      </form>                           
	  </table>
<form method=post action=adminassort.asp>
<table width="80%"  border="1" align="center" cellpadding="0" cellspacing="0" bordercolorlight="#000000" bordercolordark="#FFFFFF" height="50">
  <tr>
    <td height="21" align="center" bgcolor="eeeeee"><font style="font-size:14px">添加一级分类</font></td>
  </tr>
  <tr>
    <td align="center" bgcolor="#FFFFFF" height="25">
	<%if request("add")="添加一级分类" then
if request("paixu")="" then
	response.write"分类排序不能为空!<meta http-equiv=refresh content='1;url=adminassort.asp'>"
	response.End()
	end if
if not IsNumeric(request("paixu")) then
	response.write"分类排序只能为数字!<meta http-equiv=refresh content='1;url=adminassort.asp'>"
	response.End()
	end if
	if request("topic")="" then
	response.write"分类名称不能为空!<meta http-equiv=refresh content='1;url=adminassort.asp'>"
	response.End()
	else
	rs.open"select * from class where topic='"&request("topic")&"'",conn,1,1
	if not rs.eof then
	rs.close
	response.write"该分类名称已经存在!<meta http-equiv=refresh content='1;url=adminassort.asp'>"
	response.End()
	else
	rs.close
	rs.open"select * from class",conn,1,3
	rs.addnew
	rs("topic")=request("topic")
	rs("paixu")=request("paixu")
	rs.update
	rs.close
	response.write"分类添加成功!<meta http-equiv=refresh content='1;url=adminassort.asp'>"
	response.End()
	end if
	end if
	end if%>
	分类名称:                     
    <input name="topic" type="text" size=12>&nbsp;分类排序:<input type=text size=4 name="paixu">&nbsp;<input name="add" type="submit" value="添加一级分类"></td>
  </tr>
</table></form>
<form method=post action=adminassort.asp>
<table width="80%"  border="1" align="center" cellpadding="0" cellspacing="0" bordercolorlight="#000000" bordercolordark="#FFFFFF" height="50">
  <tr>
    <td height="21" align="center" bgcolor="eeeeee"><font style="font-size:14px">添加二级分类</font></td>
  </tr>
  <tr>
    <td align="center" bgcolor="#FFFFFF" height="25">
	<%if request("add2")="添加二级分类" then
if request("paixu2")="" then
	response.write"分类排序不能为空!<meta http-equiv=refresh content='1;url=adminassort.asp'>"
	response.End()
	end if
if not IsNumeric(request("paixu2")) then
	response.write"分类排序只能为数字!<meta http-equiv=refresh content='1;url=adminassort.asp'>"
	response.End()
	end if
	if request("topic2")="" then
	response.write"分类名称不能为空!<meta http-equiv=refresh content='1;url=adminassort.asp'>"
	response.End()
	else
	rs.open"select * from assort where topic='"&request("topic2")&"'",conn,1,1
	if not rs.eof then
	rs.close
	response.write"该分类名称已经存在!<meta http-equiv=refresh content='1;url=adminassort.asp'>"
	response.End()
	else
	rs.close
	rs.open"select * from assort",conn,1,3
	rs.addnew
	rs("topic")=request("topic2")
	rs("shuxing")=request("yjfl")
	rs("paixu")=request("paixu2")
	rs.update
	rs.close
	response.write"分类添加成功!<meta http-equiv=refresh content='1;url=adminassort.asp'>"
	response.End()
	end if
	end if
	end if%>
	分类名称:                     
    <input name="topic2" type="text" size=12>&nbsp;分类排序:<input type=text size=4 name="paixu2">&nbsp;所属分类:<select name="yjfl">
	    <%rs3.open"select * from class",conn,1,1
	  while not rs3.eof%>
	    <option value=<%=rs3("id")%>><%=rs3("topic")%></option>
	    <%rs3.movenext
	  wend
	  rs3.close%>
      </select>
    <input name="add2" type="submit" value="添加二级分类"></td>         
  </tr>
</table></form>
