<!--#include file="Qvodcms_Conn.asp"-->
<!--#include file="QvodCms_Check.asp"-->
<%
Dim action,class_id,del_id,class_bigid,class_orderid,class_name,class_dir
action=Trim(Request.QueryString("action"))
del_id=QvodCms_CLng(Request.QueryString("del_id"))
class_id=QvodCms_CLng(Request("class_id"))
class_bigid=QvodCms_CLng(Request.Form("class_bigid"))
class_orderid=QvodCms_CLng(Request.Form("class_orderid"))
class_name=Trim(ReplaceBadChar(Request.Form("class_name")))
class_dir=Trim(ReplaceBadChar(Request.Form("class_dir")))
class_skin=Trim(Request.Form("class_skin"))
detail_skin=Trim(Request.Form("detail_skin"))
Call OpenConn()
%><html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<TITLE>管理页面</TITLE>
<link href="skins/css/jaja_main.css" rel="stylesheet" type="text/css" />
<script language = "javaScript" src = "Qvodcms_All.js" type="text/javascript"></script>
<style type="text/css">
.td2 input{color: #555;height:21px;}
.td2 .small{color:#999;border:#DFDFDF 1px solid;}
</style>
</head>
<body>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr><th colspan=2 background="Skins/images/tdbg.gif" class="title">&nbsp;<a href="?action=add">添加新分类</a></th>
</tr>
<tr><td class="td2">
<%If action="add" Then%>
    <table width="100%" border=0 align=center cellpadding="4" cellspacing=1 class=tbtitle style="background: #cad9ea;">
    <form method="post" action="?action=saveadd">
	<tr align="center" bgcolor="#f5fafe">
	<td width="152">选择分类</td>
	<td width="152">栏目名称</td>
	<td width="101">英文目录</td>  
	<td width="130">栏目模板</td>
	<td width="130">内容页模板</td>
	<td width="61" style="text-align:left; padding-left:10px;">栏目排序</td>
	<td width="439" style="text-align:left; padding-left:10px;">管理操作</td>
	</tr>	
	<tr align="center" bgcolor="#f5fafe">
	<td><select name="class_bigid"><option value="0">作为一级分类</option><%If class_id>0 Then Call SelectClass(class_id) Else Call SelectClass(-1) End If%></select></td>
	<td><input size=15 type="text" name="class_name" onFocus="if(this.value=='电影名称')this.value='';" value="电影名称" style="color: #999;height:21px;"></td>
	<td><input size=8 type="text" name="class_dir"  onfocus="if(this.value=='电影目录')this.value='';" value="电影目录" style="color: #999;height:21px;"></td>
	<td><input size=15 type="text" name="class_skin" value="type.html"></td>
	<td><input name="detail_skin" type="text" id="detail_skin" value="details.html" size=15></td>
	<td style="text-align:left; padding-left:10px;"><input name="class_orderid" type="text" id="class_orderid" value="<%=QvodCms_MaxId("class")%>" size=5></td>
	<td style="text-align:left; padding-left:10px;"><input type="submit" value="添 加" name="Submit2"></td>
	</tr></form>
	</table>
<%ElseIf action="edit" Then
    Set ers = Conn.Execute(" Select * from qvodcms_class where class_id="&class_id&" ")
	If Not(ers.bof and ers.eof) Then%>
    <table width="100%" border=0 align=center cellpadding="4" cellspacing=1 class=tbtitle style="background: #f9fcfd;">
    <form method="post" action="?action=saveedit2">
	<tr align="center" bgcolor="#f5fafe">
	<td width="152">选择分类</td>
	<td width="152">栏目名称</td>
	<td width="101">英文目录</td>  
	<td width="130">栏目模板</td>
	<td width="130">内容页模板</td>
	<td width="137">栏目排序</td>
	<td width="442" style="text-align:left; padding-left:10px;">管理操作</td>
	</tr>	
	<tr align="center" bgcolor="#f5fafe">
	<td><select name="class_bigid"><option value=0>无(一级分类)</option><%Call SelectClass(ers("class_bigid"))%></select></td>
	<td><input size=15 type="text" name="class_name" value="<%=ers("class_name")%>"></td>
	<td><input size=8 type="text" name="class_dir"  value="<%=ers("class_dir")%>"></td>
	<td><input size=15 type="text" name="class_skin" value="<%=ers("class_skin")%>"></td>
	<td><input name="detail_skin" type="text" id="detail_skin" value="<%=ers("detail_skin")%>" size=15></td>
	<td><input size=5 type="text" name="class_orderid" value="<%=ers("class_orderid")%>"></td>
	<input name="class_id" type="hidden" value="<%=class_id%>">
	<td style="text-align:left; padding-left:10px;"><input type="submit" value="修 改" name="Submit"></td>
	</tr></form>
	</table>
<%  Else
    Call QvodCms_Err("没有查询到栏目ID="&class_id&"的相关数据,请返回！")
    End If
	Set ers=nothing
ElseIf action="saveadd" Then
	If class_name="" Or class_dir="" or class_skin="" Then  Call QvodCms_Err("必要参数不能为空！")
	Conn.Execute(" Insert Into [qvodcms_class] (class_id,class_bigid,class_orderid,class_name,class_dir,class_skin,detail_skin) values ("&QvodCms_MaxId("class")&","&class_bigid&","&class_orderid&",'"&class_name&"','"&class_dir&"','"&class_skin&"','"&detail_skin&"') ")
	Call class_create()
	Response.Redirect "qvodcms_class.asp"
ElseIf action="saveedit" Then
	id_a = Split(Request.Form("id"), ", ")
	For Each id In id_a
	Conn.Execute "update [qvodcms_class] Set class_name='"&Trim(ReplaceBadChar(Request.Form("class_name_"&id)))&"',class_dir='"&Trim(ReplaceBadChar(Request.Form("class_dir_"&id)))&"',class_skin='"&Trim(Request.Form("class_skin_"&id))&"',detail_skin='"&Trim(Request.Form("detail_skin_"&id))&"',class_orderid="&QvodCms_CLng(Request.Form("class_orderid_"&id))&" where class_id="&id
	Next
	Call class_create()
	Response.Redirect "qvodcms_Class.asp"
ElseIf action="saveedit2" Then
    If class_bigid=class_id then Call QvodCms_Err("大类ID不能与小类ID相同")
    Conn.Execute "update [qvodcms_class] Set class_name='"&class_name&"',class_dir='"&class_dir&"',class_skin='"&class_skin&"',detail_skin='"&detail_skin&"',class_orderid="&class_orderid&",class_bigid="&class_bigid&" where class_id="&class_id
	Call class_create()	
	Response.Redirect "qvodcms_Class.asp"
ElseIf action="del" Then
	Conn.Execute(" Update [qvodcms_name] Set class_id=0 Where class_id="&del_id&" ")    '更新栏目ID
	Conn.Execute(" Delete from [qvodcms_class] where class_id="&del_id&" or class_id in (select class_id from qvodcms_class where class_bigid="&del_id&") ")'删除分类数据表
	Call Class_Create
	Response.Redirect "qvodcms_class.asp"
Else%>
<table width="100%" border=0 align=center cellpadding="4" cellspacing=1 class=tbtitle style="background: #cad9ea;">
<tr bgcolor="#e4edf9" style="text-align:center;">
  <td width="30">选中</td>
  <td width="30">ID</td>
  <td width="150">栏目名称</td>
  <td width="100">英文目录</td>  
  <td width="150">栏目模板</td>
  <td width="150">内容页模板</td>
  <td width="60">栏目排序</td>
  <td style="text-align:left; padding-left:10px;">相关管理操作</td>
</tr>
<%  Response.Write "<form action='?action=saveedit' method='post' name='form'>"&chr(10)
	Set rs = Server.CreateObject("adodb.recordset")
	sql = "select * from qvodcms_class where class_bigid=0 order by class_orderid asc"
	rs.Open sql, Conn, 1, 1
	If rs.bof And rs.eof Then
		Response.Write("<tr><td>没有分类请先添加!</td></tr>")
	Else  
		Do while not rs.eof	  
			Call HtmlTable(rs("class_id"),rs("class_name")&"",rs("class_dir"),rs("class_orderid"),rs("class_skin"),rs("detail_skin"),0)
			Call SmallClassHtml(rs("class_id"))'调用二级	
		rs.movenext  
		Loop
    End If
	rs.Close
	Set rs=nothing
	Response.Write "<tr bgcolor='#ffffff'><td colspan='8' align='left'>&nbsp;<INPUT type='submit' value='批量修改选中栏目' name='Submit'></td></tr>"&chr(10)&"</form>"
End If
%>
</table>
<%Call CloseConn()%>
</td></tr> 
</table>
</body>
</html>
<%
Sub SmallClassHtml(sid)
    '作用:递归查询二级分类
	Set rs1 = Server.CreateObject("adodb.recordset")
	sql = "select * from qvodcms_class where class_bigid="&sid&" order by class_orderid asc"
	rs1.Open sql, Conn, 1, 1
	If Not(rs1.bof And rs1.eof) Then
		Do while not rs1.eof
			Call HtmlTable(rs1("class_id"),rs1("class_name"),rs1("class_dir"),rs1("class_orderid"),rs1("class_skin"),rs1("detail_skin"),-1)
			'Call SmallClass(rs1("class_id"))
			'调用无级子级(我们这里只需要2级)
		rs1.movenext  
		loop 
    End If
	rs1.Close
	Set rs1=nothing
End Sub

Sub HtmlTable(classid,classname,classdir,classorderid,classkin,detailskin,bigid)
	If bigid=0 Then zimulu="<a href=?action=add&class_id="&classid&">增加子目录</a>"
	If bigid=-1 Then cn="class='small'"
	Response.Write "<tr align=""center"" bgcolor=#f5fafe>"&chr(10)
	Response.Write "<td ><input name='id' type='checkbox' value='"&classid&"' style='border:none' checked></td>"&chr(10)
	Response.Write "<td >"&classid&"</td>"&chr(10)
	Response.Write "<td ><input size=15 type='text' name='class_name_"&classid&"' value='"&classname&"' "&cn&"></td>"&chr(10)
	Response.Write "<td ><input size=8 type='text' name='class_dir_"&classid&"'  value='"&classdir&"' "&cn&"></td>"&chr(10)
	Response.Write "<td ><input size=15 type='text' name='class_skin_"&classid&"' value='"&classkin&"' "&cn&"></td>"&chr(10)
	Response.Write "<td ><input size=15 type='text' name='detail_skin_"&classid&"' value='"&detailskin&"' "&cn&"></td>"&chr(10)
	Response.Write "<td ><input size=5 type='text' name='class_orderid_"&classid&"' value='"&classorderid&"' "&cn&"></td>"&chr(10)
	Response.Write "<td style='text-align:left; padding-left:10px;'><a href=?action=edit&class_id="&classid&">修改</a> <a href=# onClick=qvodcmsdel('?action=del&del_id="&classid&"','如果该分类有子目录将一同删除子目录!','删除分类并不会删除该分类下的电影,该操作不可恢复，确认吗？');>删除</a> "&zimulu&"</td>"&chr(10)
	Response.Write "</tr>"&chr(10)
End Sub

Sub SelectClass(BigId)
    '作用:处理分类下拉框
    'If BigId=0 Then Exit Sub'一级分类则退出
	Set Srs = Server.CreateObject("adodb.recordset")
	sql = "select * from qvodcms_class where class_bigid=0 order by class_orderid asc"
	Srs.Open sql, Conn, 1, 1
	If Not(Srs.bof And Srs.eof) Then
		Do while not Srs.eof
		If BigId=Srs("class_id") Then
		Response.Write "<option value="&Srs("class_id")&" selected='selected'>"&Srs("class_name")&"</option>"
		Else		
		Response.Write "<option value="&Srs("class_id")&">"&Srs("class_name")&"</option>"
		End If	
		Srs.movenext 
		Loop	
    End If
	Srs.Close
	Set Srs=nothing	
End Sub

Sub Class_Create'动态生成栏目名称以提供前台缓存
    Dim Class_Name,Class_En,Class_Cname,Class_Cid,Class_Temp,Class_Count,C
	Class_Name="":Class_En=""
	Set crs = Server.CreateObject("adodb.recordset")
	sql = " Select class_id,class_name,class_dir from qvodcms_class order by class_id asc " 
	crs.Open sql, Conn, 1, 1
	If Not crs.eof Then
	    Set ctrs=Conn.Execute("Select class_id as class_count from qvodcms_class order by class_id desc")
	    C=C+1
		Class_Temp="Dim Class_Cname("&ctrs("class_count")&"),Class_Cid("&ctrs("class_count")&"),Class_Count:Class_Count="&crs.recordcount&chr(13)&""
	    Class_Name = "Class_N_0=""未知"""&chr(13)
		Class_En = "Class_E_0=""noclass"""&chr(13)
		Do while not crs.eof
		Class_Name=Class_Name&"Class_N_"&crs("class_id")&"="""&crs("class_name")&""""&chr(13)
		Class_En=Class_En&"Class_E_"&crs("class_id")&"="""&crs("class_dir")&""""&chr(13)
		Class_Cname=Class_Cname&"Class_Cname("&crs("class_id")&")="""&crs("class_name")&""""&chr(13)
		Class_Cid=Class_Cid&"Class_Cid("&crs("class_id")&")="""&crs("class_id")&""""&chr(13)
		crs.movenext
		Loop
		Call MakeHtml("../Cache/QvodCms.Class.asp","<%"&chr(13)&Class_Name&Class_En&"%"&">")'生成栏目缓存文件
		Call MakeHtml("../Cache/QvodCms.Class_Cai.asp","<%"&chr(13)&Class_Temp&Class_Cname&Class_Cid&"%"&">")'生成栏目缓存文件
	End if
	crs.Close
	Set crs=nothing:Set ctrs=nothing
End Sub
%>