<!--#include file="admin_head.asp"-->
<br><br>

<%
if Request("updateorder") <> "" then

	set rs=server.createobject("adodb.recordset")
	sql = "Select Unid,orderflag from article_class where flag = 0 order by Unid asc"
	rs.open sql,conn,2,3
	Do While NOT rs.EOF
		rs.Fields("orderflag") = CInt(Request.Form("OrderFlag" & rs(0)))
		rs.update
		rs.movenext
	loop	

	rs.close
	Response.Redirect "admin_class.asp"
end if
Select case Request("method")
	Case 1
		Call AddClass()
	Case 2
		Call DelClass()
	Case 3
		Call EditClass()
End Select

sub AddClass()
	if Trim(Request.form("Classname")) = "" then
		Errmsg = "<li>请输入大栏目名称。"
		call Qcdn.Err_List(errmsg,1)
		Response.end
	end if
	Classname = Qcdn.checkStr(Request.form("Classname"))
	Conn.execute("insert into article_class(classname,flag)values('"& Classname &"',0)")
	Response.write "<script>alert(""添加成功"");location.href=""admin_Class.asp"";</script>"
	Response.end
end sub
Sub DelClass()
	if Trim(Request.form("classid")) = "" then
		Errmsg = "<li>发现异常错误。<li>错误编号为: error 102。<li>请和青创网络联系解决问题。"
		call Qcdn.Err_List(errmsg,1)
		Response.end
	end if
	classid = Request.form("classid")
	Conn.execute("Delete from article_class where Unid in ("& classid &")")
	Conn.execute("Delete from article_class where flag in ("& classid &")")
	Conn.execute("Delete from article_info where classid in ("& classid &")")
	Response.write "<script>alert(""删除成功"");location.href=""admin_Class.asp"";</script>"
	Response.end
End Sub
Sub EditClass()
	if Trim(Request.form("Classname")) = "" then
		Errmsg = "<li>请选择要修改的大栏目名称。"
		FoundErr = true
	end if 
	if Request.form("classunid") = "" then
		Errmsg = Errmsg + "<li>发现异常错误。<li>错误编号为: error 103。<li>请和青创网络联系解决问题。"
		FoundErr = true
	end if
	if FoundErr = true then
		call Qcdn.Err_List(errmsg,1)
		Response.end
	end if
	Classname = Qcdn.checkStr(Request.form("Classname"))
	classunid = Request.form("classunid")
	Conn.execute("Update article_Class set Classname='"& Classname &"' where Unid = " & classunid)
	Response.write "<script>alert(""修改成功"");location.href=""admin_Class.asp"";</script>"
	Response.end
End Sub
Unid = Request("unid")
%>
<table width="95%" border="1" cellspacing="0" cellpadding="3" align="center" bordercolorlight="#ECEEE4" bordercolordark="#CCCABC">
  <form action="" name="form1" method="post">
    <tr> 
      <td colspan="2" align="center" height="30" background="image/tablebg.gif"><b>
	  <%if Unid<>"" then response.write "修 改 " else response.write "添 加 " end if%>文 章 大 栏 目 </b> </td>
    </tr>
	<form name="form1" method="post" action="">
    <tr> 
      <td width="15%" height="25" colspan="2" valign="middle" align="center">大栏目名称：<input type="text" name="Classname" size="30" value="<%=Qcdn.HTMLcode(Qcdn.Classlist(Unid))%>">&nbsp;<input type="submit" name="submit" value="提交" class="tbutton"></td>
	  <input type="hidden" name="classunid" value="<%=Unid%>">
    </tr>
	<%
	if Unid = "" then
		Response.write "<input type=hidden name=method value=1>"
	else
		Response.write "<input type=hidden name=method value=3>"
	end if
	%>
	</form>
	
  <tr> 
    <td width="15%" height="25" align="center" valign="middle">ID</td>
      
    <td width="85%" height="25" align="center" valign="middle">栏目名称</td>
    </tr>
	<form name="form2" method="post" action="">
	<%
	Sql = "Select Count(Unid) from article_class where flag = 0"
	Set Rs = conn.execute(sql)
		CountClass = rs(0)
	rs.close

	Sql = "Select Unid,ClassName,OrderFlag from article_class where flag = 0 order by Orderflag asc"
	set rs = conn.execute(sql)
	if not rs.eof then
		do while not rs.eof
	%>
	<tr> 
      <td width="15%" height="25" align="center" valign="middle"><%=rs(0)%></td>
      <td width="85%" height="25" valign="middle">
<input name="classid" type="checkbox" id="classid" value='<%=rs(0)%>'>&nbsp;<a href="admin_Class.asp?unid=<%=rs(0)%>"><%=rs(1)%></a>
	  <select name="OrderFlag<%=rs(0)%>">
		<%
		 for i = 1 to CountClass
			Response.write("<option ")
			if rs(2) = i then Response.write("selected")
			Response.write(" value="& i &">"& i &"</option>")
		 next
		%>
	  </select>
	  </td>
    </tr>
	<%
		rs.movenext
		loop
	else
		Response.write "<tr><td align=center colspan=2 height=25>还没有添加大栏目</td></tr>"
	end if
		rs.close
	%>
	<tr>
	  <td height=25 align=center>删除操作</td>
	  <td height=25> 全部选择 

        <input type="checkbox" name="chkall" value="checkbox" onClick="javascript:CheckAll(this.form)">

		<input onClick="{if(confirm('此操作同时将删除该分类下的全部子分类及文章！\n\n确定要执行此项操作吗？')){this.document.form2.submit();return true;}return false;}" type=submit value=删除 name=action2 class="tbutton"> 

		<input type="submit" name="updateorder" value="刷新排序" class="tbutton">
        <input type="Hidden" name="method" value="2"> 
		<input type="hidden" name="Counts" value="<%=CountClass%>">
		<font color="#FF0000">删除操作同时将删除该分类下的全部子分类及文章</font>
	  </td>
	</tr>
	</form>
</table>
<!--#include file="admin_copy.asp"-->