<!--#include file="conn.asp"-->
<!--#include file="check.asp"-->

<% 
 '===========================================================================================
	'软件名称：126 cms 视频影视管理系统
	'程序版权：126电影               '咨询QQ：479025
	'开发作者：magicblack(479025)    '官方网站：http://www.126oo.com/
	'Copyright (C) 2009 - ... 126oo.com  All Rights Reserved.
	'郑重声明:
	'    1、免费版本请在程序首页保留版权信息，并做上本站LOGO友情连接,商业版本无此要求;
	'    2、任何个人或组织不得以盈利为目的发布,修改,本软件及其他副本上一切关于版权的信息；
	'    3、126电影保留此软件的法律追究权利；
'==========================================================================================
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE>栏目分类管理 - 后台管理中心 - 126电影程序CMS</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<LINK href="images/css_body.css" type=text/css rel=stylesheet>
<script language="javascript" src="images/admin.js"></script>
<script language="javascript" src="images/ajaxrequest.js"></script>
<script language="javascript">
function ShowPDIV(i,p){
    if($("type_P_CID_"+i).length==0){
	    var v = $("type_H_V").innerHTML.split('@|@');
		$("type_P_CID_"+i).options[0] = new Option("作为顶级","0");
		for(j=1;j<v.length;j++){
		    $("type_P_CID_"+i).options[j] = new Option(v[j].split('|=|')[1],v[j].split('|=|')[0]);
			if(p==v[j].split('|=|')[0]) $("type_P_CID_"+i).options[j].selected = true;//设置默认选择
		}
	}	
	$("type_P_DIV_"+i).style.display = ($("type_P_DIV_"+i).style.display == "none") ? "block" : "none";
}
function SelectPid(p,i){

	window.location.href = '?action=editid&typeid='+i+'&parentid='+p;
}

</script>
<style type="text/css">
.tb2{clear:both;width:100%}
	.tb2 th, .tb2 td{padding:0px;background:#fff;border-top:0px solid #DEEFFA; border-bottom:1px solid #DEEFFA;}
	.tb2 tr:hover{color:#333}

table.tdk{border:none}
table.tdk th,table.tdk td{border:none}

.tb2 .noborder,.tb .noborder{border:none}

</style>
</HEAD>
<BODY>
<DIV class=bodytitle>
<DIV class=bodytitleleft></DIV>
<DIV class=bodytitletxt>栏目分类管理</DIV>
<DIV class=bodytitletxt2></DIV>
</DIV>

<%
response.Charset="GBK"
dim action
dim arrtype

action = SafeData("RQ","action",0)

Select case action
	case "addsave" : addsave
	case "edit" : edit
	case "editsave" : editsave
	case "editall" : editall
	case "editid" : editid
	case "del" : del
	case "delall" : delAll
	case "last" : moveTolast
	case "next" : moveTonext
	case "hide" : Hide
	case "nohide" : Nohide
	case "into" : into
	case else : main :add
End Select

sub addsave
Dim T_Name : T_Name = SafeData("RF","T_Name",0)
Dim T_EnName : T_EnName = SafeData("RF","T_EnName",0)
Dim T_Sort : T_Sort = SafeData("RF","T_Sort",0)
Dim T_PatentID : T_PatentID = SafeData("RF","T_PatentID",0)

if isN(T_Sort) then  T_Sort= Database.GetRecordBySQL("select max(t_sort) from Tbl_type")(0)+1
if not isNum(T_Sort) then ErrMsg "栏目分类","信息填写不完整，请检查!"
		

Dim result : result = DataBase.AddRecord("Tbl_type",Array("T_Name:"&T_Name, "T_EnName:"&T_EnName, "T_Sort:"&T_Sort, "T_PatentID:"&T_PatentID, "T_Hide:0"))   
If result<>0 Then  
    ShowMsg "添加栏目分类成功！"  ,"admin_type.asp" 
End If  
end sub

sub Hide
	Dim T_ID : T_ID = SafeData("RQ","T_ID",0)
	DataBase.UpdateRecord "Tbl_Type","T_ID = "& T_ID ,Array( "T_Hide:1")
	ShowMsg "隐藏成功!" ,"admin_type.asp"  
end sub

sub Nohide
	Dim T_ID : T_ID = SafeData("RQ","T_ID",0)
	DataBase.UpdateRecord "Tbl_Type","T_ID = "& T_ID ,Array( "T_Hide:0")
	ShowMsg "显示成功!" ,"admin_type.asp"  
end sub 

sub del
	Dim T_ID : T_ID = SafeData("RQ","T_ID",0)
	Dim result : result = Database.DeleteRecord("Tbl_Type", "T_ID:" & T_ID)   
	If result<>0 Then  
    	ShowMsg "删除记录成功!" ,"admin_type.asp"  
	End If 
end sub

sub delall
	Dim T_ID : T_ID = SafeData("RQ","T_ID",0)
	if isN(T_ID) then ShowMsg "没有选择任何数据!" ,"admin_type.asp"  
	Dim result : result = Database.DeleteRecord("Tbl_Type", "T_ID in (" & T_ID & ")")   
	If result<>0 Then  
    	ShowMsg "批量删除记录成功!" ,"admin_type.asp"  
	End If 
end sub


sub into
dim type1,type2
	type1 = SafeData("RF","T_type1",0)
	type2 = SafeData("RF","T_type2",0)
DataBase.UpdateRecord "Tbl_Datas","d_type = "& type1 ,Array("d_type:"&type2)
ShowMsg "分类数据转移成功!" ,"admin_type.asp"  
	
end sub

sub editid

dim typeid,parentid
	typeid = SafeData("RQ","typeid",0)
	parentid = SafeData("RQ","parentid",0)

DataBase.UpdateRecord "Tbl_type","T_ID = "& typeid ,Array("T_PatentID:"&parentid)
response.Redirect "admin_type.asp"
end sub

sub editall
	dim ids,id,T_Name,T_Sort,T_EnName
	ids = split(replace(SafeData("RF","T_ID",0)," ",""),",")

	For Each id In ids
		T_Name = SafeData("RF","T_Name" &id,0)
		T_EnName = SafeData("RF","T_EnName" &id,0) 
		T_Sort = SafeData("RF","T_Sort" &id,0)
		
		if isN(T_Name)  then   ErrMsg "栏目分类","信息填写不完整，请检查!"
		if isN(T_EnName) then ErrMsg "栏目分类","信息填写不完整，请检查!"
		if isN(T_Sort) then ErrMsg "栏目分类","信息填写不完整，请检查!"
		if not isNum(T_Sort) then ErrMsg "栏目分类","信息填写不完整，请检查!"
		
			DataBase.UpdateRecord "Tbl_type","T_ID = "& id ,Array("T_Name:"&T_Name,"T_EnName:"&T_EnName, "T_Sort:"&T_Sort)
		
	Next
	
	ShowMsg "批量修改完毕!","admin_type.asp" 
end sub

function getTypeCount(TypeID)
Dim Typecount 
Typecount = DataBase.GetRecordBySQL("select count(*) from Tbl_datas where D_Type = " & TypeID)(0)
getTypeCount = Typecount
end function

sub getTypeList(ParentID)
Dim rs : Set rs = DataBase.GetPageRecord(0,Array("Tbl_Type:T_ID,T_Name,T_EnName,T_Sort,T_PatentID,T_Hide","T_PatentID=" & ParentID,"T_Sort,T_ID Asc","T_ID")) 


do while not rs.eof 
%>
	<TR bgcolor="#FFFFFF">
    	<td align="left"><%if ParentID =0 then %>╄<% else %> ├ <%end if%><input type="checkbox" name="T_ID" value="<%=rs("T_ID")%>" checked class="checkbox" /><a href="admin_movie.asp?type=<%=rs("T_ID")%>"><%=rs("T_Name")%></a>(<font color="red"><%=getTypeCount(rs("T_ID"))%></font>)</td>
		<td><input size="13" type="text" name="t_name<%=rs("T_ID")%>" value="<%=rs("T_Name")%>"></td>
		<td><input size="10" type="text" name="t_enname<%=rs("T_ID")%>" value="<%=rs("T_EnName")%>"></td>
		<td><input size="3" type="text" name="t_sort<%=rs("T_ID")%>" value="<%=rs("T_Sort")%>"></td>
		<td><input type="button" value="删除" onClick="javascript:location.href='?action=del&t_id=<%=rs("T_ID")%>';" name="Input" class="btn" /><%if rs("T_Hide")=1 then %><input type="button" value="取消隐藏" onClick="javascript:location.href='?action=nohide&t_id=<%=rs("T_ID")%>';" name="Input2"  class="btn" /><%elseif rs("T_Hide")=0 then%><input type="button" value="隐藏" onClick="location.href='?action=hide&t_id=<%=rs("T_ID")%>';" name="Input2" class="btn" /> <%end if%>
		<input type="button" value="设置上级" onClick="ShowPDIV(<%=Rs("T_ID")%>,<%=Rs("T_ID")%>);" name="Input" class="btn" />
		
		<div id="type_P_DIV_<%=Rs("T_ID")%>" style="position:absolute;display:none;">
	  <select id="type_P_CID_<%=Rs("T_ID")%>" name="type_P_CID_<%=Rs("T_ID")%>" onChange="SelectPid(this.value,<%=Rs("T_ID")%>);">
	  </select>
	</div>
	
		</td>
  	</tr>
<%	
arrtype = arrtype & "@|@"&Rs("T_ID")&"|=|" &Rs("T_Name")
	getTypeList(rs("t_id"))
		rs.movenext
	loop
	Database.C(rs)
	
end sub

Sub makeTypeOption(ParentID,separateStr)
dim span
Dim rs : Set rs = DataBase.GetPageRecord(0,Array("Tbl_Type:T_ID,T_Name,T_EnName,T_Sort,T_PatentID,T_Hide","T_PatentID=" & ParentID,"T_Sort Asc","T_ID")) 

	do while not rs.eof 
		if ParentID <> 0 then span=span&separateStr
		response.Write  "<option value='"&rs("T_id")&"'>"&span&"&nbsp;|—"&rs("T_name")&"</option>"
		makeTypeOption rs("T_id"),separateStr
		rs.movenext
	loop
	if not isN(span) then span = left(span,len(span)-len(separateStr))
	DataBase.C(rs)
End Sub

sub main

%>

<TABLE width="96%" border=0 align=center cellpadding="5" cellSpacing=1 class=tbtitle style="BACKGROUND: #cad9ea;">
<form action="" method="post" name="form1"> 
  <TBODY>
    <TR bgColor="#f5fafe">
	  <TD width="15%" align="center" >&nbsp;</TD>
      <TD width="10%" align="center">名称</TD>
	  <TD width="10%" align="center">别名</TD>
	  <TD width="5%" align="center">排序</TD>
	  <TD width="25%" align="center">操作</TD>
    </TR>
	<%
		getTypeList(0)
	%>
	<TR bgColor="#f5fafe">
	<td  colspan="6"><label>全选<input type="checkbox" name="chkall" id="chkall" class="checkbox" onClick="checkAll(this.checked,'input','T_ID')" /></label><label>反选<input type="checkbox" name="chkothers" id="chkothers" class="checkbox" onClick="checkOthers('input','T_ID')" /></label><input type="submit" value="批量删除" onClick="if(confirm('确定要删除吗')){form1.action='?action=delall';}else{return false}" class="btn"  />
	&nbsp;&nbsp;<input type="submit" value="批量修改选中" name="Submit"  class="btn"  onclick="form1.action='?action=editall';"/>
	</td></tr>
	
  </TBODY>
  </form>
</TABLE>
<div id="type_H_V" style="display:none"><%=arrtype%></div>
<%

end sub

sub add
%>
<TABLE width="96%" border=0 align=center cellpadding="5" cellSpacing=1 class=tbtitle style="BACKGROUND: #cad9ea;">
<form action="?action=addsave" method="post" name="addform"> 
  <TBODY>
    <TR bgColor="#f5fafe">
	  <TD width="10%" align="center" >
	  选择分类</TD>
      <TD align="center">名称</TD>
	  <TD width="20%" align="center">别名</TD>
	  <TD width="15%" align="center">排序</TD>
	  <TD width="25%" align="center">操作</TD>
    </TR>
	  <TR bgColor="#f5fafe">
	  <TD width="4%" align="center" > <select name="T_PatentID"><option value="0">顶级分类</option>
    <%makeTypeOption(0),"&nbsp;|&nbsp;&nbsp;"%>
	</select></TD>
      <TD align="center"><input type="text" name="T_name"></TD>
	  <TD width="20%" align="center"><input type="text" name="T_enname"></TD>
	  <TD width="15%" align="center"><input type="text" name="T_sort"></TD>
	  <TD width="25%" align="center"><input type="submit" value="添加" name="Submit" class="btn" /></TD>
    </TR>
  </TBODY>
  </form>
</TABLE>
<br>
<TABLE width="96%" border=0 align=center cellpadding="5" cellSpacing=1 class=tbtitle style="BACKGROUND: #cad9ea;">
<form action="?action=into" method="post" name="intoform"> 
  <TBODY>
    <TR bgColor="#f5fafe">
	  <TD width="10%" align="center" >
	  源分类</TD>
      <TD align="center">目标分类</TD>
	  <TD width="25%" align="center">操作</TD>
    </TR>
	  <TR bgColor="#f5fafe">
	  <TD width="4%" align="center" > <select name="T_type1">
    <%makeTypeOption(0),"&nbsp;|&nbsp;&nbsp;"%>
	</select></TD>
      <TD align="center"><select name="T_type2">
    <%makeTypeOption(0),"&nbsp;|&nbsp;&nbsp;"%>
	</select></TD>
	  <TD width="25%" align="center"><input type="submit" value="确认转移" name="Submit" class="btn" /></TD>
    </TR>
  </TBODY>
  </form>
</TABLE>

<br>
<%
end sub
%>