<% Option Explicit %>
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312" />
<TITLE>产品分类</TITLE>
<META NAME="Keywords" CONTENT="" />
<META NAME="Description" CONTENT="" />
<link rel="stylesheet" href="../Images/CssAdmin.css">
<script language="javascript" src="../inc/Admin.js"></script>
</HEAD>
<!--#include file="../../Include/Const.asp" -->
<!--#include file="../../Include/Conn1.asp" -->
<!--#include file="../CheckAdmin.asp"-->
<BODY>
<%
Dim rsL,sqlL,n,m
Dim Action,Sortpic,Angel_languageid
Action=request.QueryString("Action")
Select Case Action
  Case "Add"
  response.Write("<div id=""Language"">")
  response.Write("<div style=""height:37px;background:#ffffff;border:1px #628ae1 solid;padding-top:5px; width:100%; padding-left:10px;clear:both;"">")
  response.Write("<h2>简体中文</h2>")
  response.Write("</div><br/>")
  set rsL = server.createobject("adodb.recordset")
  sqlL="select * from Angel_Language order by Lorder desc"
  rsL.open sqlL,conn,1,1
  n=0
  do while not rsL.eof
  response.Write("<ul>")
  addFolder(rsL("id"))
  response.Write("</ul>")	
  rsL.movenext
  n=n+1
  loop
  rsL.close 
  %>

<%
m=request.QueryString("m")
if m="" then m=0
%>
  <script>
function $(id){return document.getElementById(id);}
function $tag(id,tagName){return $(id).getElementsByTagName(tagName)}
var onum=<%=m%>;//用于控制默认打开的标签
var Ds=$tag("Language","ul");
var Ts=$tag("Language","h2");
for(var i=0; i<Ds.length;i++){
if(i==onum){
Ds[i].style.display="block";
Ts[i].className = "title_current";
}
else{
Ds[i].style.display="none";
Ts[i].className = "title_normal";
}
Ts[i].value=i;
Ts[i].onmousedown=function(){
if(onum==this.value){return false;};
Ts[onum].className="title_normal";
Ts[this.value].className="title_current";
Ds[onum].style.display="none";
Ds[this.value].style.display="block";
onum=this.value;
}
}
</script>

<%

  Case "Del"
    Dim rs,sql,SortPath
    Set rs=server.CreateObject("adodb.recordset")
    sql="Select * From Angel_ProductSort where ID="&request.QueryString("id")
    rs.open sql,conn,1,1
	SortPath=rs("SortPath")
	conn.execute("delete from  Angel_ProductSort where Instr(SortPath,'"&SortPath&"')>0")
    conn.execute("delete from  Angel_Product where Instr(SortPath,'"&SortPath&"')>0")
    response.write ("<script language=javascript> alert('成功删除本类、子类及所有下属信息条目，点击确定查看类别树！');location.replace('ProductSort.asp?m="&request("m")&"');</script>")
  Case "Save"
	saveFolder ()
  Case "Edit"
	editFolder	
  Case "Move"
	moveFolderForm ()
  Case "MoveSave"
	saveMoveFolder ()
  Case Else

  response.Write("<div id=""Language"">")
  response.Write("<div style=""height:37px;background:#ffffff;border:1px #628ae1 solid;padding-top:5px; width:100%; padding-left:10px;clear:both;"">")
  response.Write("<h2>简体中文</h2>")
  response.Write("</div><br/>")
  set rsL = server.createobject("adodb.recordset")
  sqlL="select * from Angel_Language order by Lorder desc"
  rsL.open sqlL,conn,1,3
  n=0
  do while not rsL.eof
  response.Write("<ul>")
  Call CallFolderView(rsL("id"))
  response.Write("</ul>")	
  rsL.movenext
  n=n+1
  loop
  rsL.close 
  %>

<%
m=request.QueryString("m")
if m="" then m=0
%>
<script>
function $(id){return document.getElementById(id);}
function $tag(id,tagName){return $(id).getElementsByTagName(tagName)}
var onum=<%=m%>;//用于控制默认打开的标签
var Ds=$tag("Language","ul");
var Ts=$tag("Language","h2");
for(var i=0; i<Ds.length;i++){
if(i==onum){
Ds[i].style.display="block";
Ts[i].className = "title_current";
}
else{
Ds[i].style.display="none";
Ts[i].className = "title_normal";
}
Ts[i].value=i;
Ts[i].onmousedown=function(){
if(onum==this.value){return false;};
Ts[onum].className="title_normal";
Ts[this.value].className="title_current";
Ds[onum].style.display="none";
Ds[this.value].style.display="block";
onum=this.value;
}
}
</script>

<%
End Select
%>

</div>
</BODY>
</HTML>

<%Function CallFolderView(Angel_languageid)%>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#628AE1">
  <tr>
    <td height="24" nowrap><font color="#FFFFFF"><strong>类别树查看管理：</strong></font></td>
  </tr>
  <tr>
    <td height="24" align="center" nowrap  bgcolor="#ffffff"><a href="ProductSort.asp?Action=Add&ParentID=0&m=<%=n%>">添加一级分类</a><font color="#0000FF">&nbsp;|&nbsp;</font><a href="ProductList.asp" >查看所有产品</a></td>
  </tr>
  <tr>
    <td height="24" nowrap  bgcolor="#ffffff"><%Call Folder(0,Angel_languageid) %></td>
  </tr>
</table>
<%
End Function


'列出所有节点------------------------------
Function Folder(id,Angel_languageid)
  Dim rs,sql,i,ChildCount,FolderType,FolderName,onMouseUp,ListType
  Set rs=server.CreateObject("adodb.recordset")
  sql="Select * From Angel_ProductSort where ParentID="&id&" and Angel_languageid="&Angel_languageid&" order by id"
  rs.open sql,conn,1,1
  if id=0 and rs.recordcount=0 then
    response.write ("暂无分类!")
    response.end
  end if  
  i=1
  %>
  <table border='0' cellpadding='0' cellspacing='0'>
  <%
  while not rs.eof
ChildCount=conn.execute("select count(*) from Angel_ProductSort where Angel_languageid="&Angel_languageid&" and ParentID="&rs("id"))(0)
    if ChildCount=0 then
	  if i=rs.recordcount then
	    FolderType="SortFileEnd"
	  else
	    FolderType="SortFile"
	  end if
	  FolderName=rs("SortName")
	  onMouseUp=""
    else
	  if i=rs.recordcount then
	 	FolderType="SortEndFolderClose"
		ListType="SortEndListline"
		onMouseUp="EndSortChange('a"&rs("id")&"','b"&rs("id")&"');"
	  else
		FolderType="SortFolderClose"
		ListType="SortListline"
		onMouseUp="SortChange('a"&rs("id")&"','b"&rs("id")&"');"
	  end if
	  FolderName=rs("SortName")
    end if
%>
   <tr onMouseOver = "this.style.backgroundColor = '#D7E3F7'" onMouseOut = "this.style.backgroundColor = ''">
   <td nowrap id='b<%=rs("id")%>' class='<%=FolderType%>' onMouseUp=<%=onMouseUp%> ></td><td nowrap height="20" class="catList"><span style="width:200px"><%=FolderName%></span><p>
   <font color='#FF0000'>分类：</font><a href='ProductSort.asp?Action=Add&ParentID=<%=rs("id")%>&m=<%=n%>&Angel_languageid=<%=Angel_languageid%>'>添加</a>
    <font color='#367BDA'>&nbsp;|&nbsp;</font><a href='ProductSort.asp?Action=Edit&ID=<%=rs("id")%>&m=<%=n%>&Angel_languageid=<%=Angel_languageid%>'>修改</a>
 <font color='#367BDA'>&nbsp;|&nbsp;</font><a href='ProductSort.asp?Action=Move&ID=<%=rs("id")%>&ParentID=<%=rs("Parentid")%>&SortName=<%=rs("SortName")%>&SortPath=<%=rs("SortPath")%>&m=<%=n%>&Angel_languageid=<%=Angel_languageid%>'>移</a>
   →<a href="#" onClick="SortFromTo.rows[4].cells[0].innerHTML='→&nbsp;<%=rs("SortName")%>';MoveForm.toID.value=<%=rs("ID")%>;MoveForm.toParentID.value=<%=rs("ParentID")%>;MoveForm.toSortPath.value='<%=rs("SortPath")%>';">至</a>
	<font color='#367BDA'>&nbsp;|&nbsp;</font><a href=javascript:ConfirmDelSort('ProductSort',<%=rs("id")%>)>删除</a>
  &nbsp;&nbsp;&nbsp;&nbsp;<font color='#FF0000'>产品：</font><a href="ProductEdit.asp?Result=Add&m=<%=n%>" >添加</a>
   <font color='#367BDA'>&nbsp;|&nbsp;</font><a href="ProductList.asp?SortID=<%=rs("ID")%>&SortPath=<%=rs("SortPath")%>&m=<%=n%>" >列表</a></p></td></tr>
<%
    if ChildCount>0 then
%>
      <tr id="a<%= rs("id")%>" style="display:yes"><td class="<%= ListType%>" nowrap></td><td >
	  <%Call Folder(rs("id"),Angel_languageid) %></td></tr>
<%
    end if
    rs.movenext
    i=i+1
  wend
  %>
</table>
  <%
  rs.close
  set rs=nothing
end function
'添加节点---------------------------------
Function addFolder(Angel_languageid)
  Dim ParentID
  ParentID=request.QueryString("ParentID")
  addFolderForm ParentID,Angel_languageid
end function
'添加节点表单------------------------------
Function addFolderForm(ParentID,Angel_languageid)
  Dim ParentPath,SortTextPath,rs,sql
  if ParentID=0 then
    ParentPath="0,"
	SortTextPath=""
  else 
    Set rs=server.CreateObject("adodb.recordset")
    sql="Select * From Angel_ProductSort where Angel_languageid="&Angel_languageid&" and ID="&ParentID
    rs.open sql,conn,1,1
	if not rs.eof then
	ParentPath=rs("SortPath")
	else
	ParentPath="0,"
	SortTextPath=""
	ParentID=0
	end if

  end if
%>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#628AE1">
<form name="FolderForm" method="post" action="ProductSort.asp?Action=Save&From=Add&m=<%=n%>">
  <tr>
    <td height="24" nowrap><font color="#FFFFFF"><img src="../Images/Explain.gif" width="18" height="18" border="0" align="absmiddle">&nbsp;<strong>添加类别：</strong></font></td>
  </tr>
  <tr>
    <td height="24" nowrap bgcolor="#ffffff">|&nbsp;根类&nbsp;→&nbsp;<% if ParentID<>0 then TextPath(ParentID)%></td>
  </tr>
  <tr>
    <td height="24" bgcolor="#ffffff">
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="590" nowrap>名称：<input name="SortName" type="text" class="textfield" id="SortName" size="22">

		<input readonly name="ParentID" type="hidden" class="textfield" id="ParentID" size="6" value="<%=ParentID %>">
	
		<input readonly name="ParentPath" type="hidden" class="textfield" id="ParentPath" size="45" value="<%=ParentPath%>">

        生效：
        <input name="ViewFlag" type="radio" value="1" checked="checked" />
        是
        <input name="ViewFlag" type="radio" value="0" />
        否

		分类图：
<div style="height:26px;line-height:26px;width:230px;float:left">
<input name="Sortpic" type="text" class="textfield" id="Sortpic" style="WIDTH: 230px;" value="<%=Sortpic%>" maxlength="100" > 
</div>
<div style="height:26px;line-height:26px;width:360px;float:left">
<iframe src="../upload.asp?action=banner&fpicid=Sortpic&formname=FolderForm" width="270" height="25" frameborder="0" scrolling="no"></iframe></div>	
 	<input name="Angel_languageid" type="hidden" value="<%=Angel_languageid%>" />
		</td>
        <td nowrap><input name="submitSave" type="submit" class="button" id="保存" value="  保存  "></td>
	  </tr>
    </table>
	</td>
  </tr>
</form>
</table>
<br>
<%
end function
'生成节点文字路径--------------------------
Function TextPath(ID)
  Dim rs,sql,SortTextPath
  Set rs=server.CreateObject("adodb.recordset")
  sql="Select * From Angel_ProductSort where ID="&ID
  rs.open sql,conn,1,1
  SortTextPath=rs("SortName")&"&nbsp;→&nbsp;"
  if rs("ParentID")<>0 then TextPath rs("ParentID")
  response.write(SortTextPath)
End Function
'保存添加、修改节点-------------------------
Function saveFolder
  if len(trim(request.Form("SortName")))=0 then
      response.write ("<script language=javascript> alert('类别名称为必填项目！');history.back(-1);</script>")
      response.end
  end if
  Dim From,Action,rs,sql,SortTextPath
  From=request.QueryString("From")
  Set rs=server.CreateObject("adodb.recordset")
  if From="Add" then 
    sql="Select * From Angel_ProductSort"
    rs.open sql,conn,1,3
    rs.addnew
	Action="添加类别"
    rs("SortPath")=request.Form("ParentPath") & rs("ID") &","
  else
    sql="Select * From Angel_ProductSort where ID="&request.QueryString("ID")
    rs.open sql,conn,1,3
	Action="修改类别"
    rs("SortPath")=request.Form("SortPath")
  end If
  
  rs("Angel_languageid")=request.Form("Angel_languageid")
  rs("SortName")=request.Form("SortName")
  rs("ParentID")=request.Form("ParentID")
  rs("ViewFlag")=request.Form("ViewFlag")
  rs("Sortpic")=request.Form("Sortpic")
  rs.update 
  response.write ("<script language=javascript> alert('"&Action&"保存成功，点击确定查看类别树！');location.replace('ProductSort.asp?m="&request("m")&"');</script>")
End Function 
'修改节点---------------------------------
Function editFolder()
  Dim ID
  ID=request.QueryString("ID")
  editFolderForm ID
end function
'修改节点表单------------------------------
Function editFolderForm(ID)
  Dim SortName,ViewFlag,ParentID,SortPath,Sortpic,rs,sql,Angel_languageid
  Set rs=server.CreateObject("adodb.recordset")
  sql="Select * From Angel_ProductSort where ID="&ID
  rs.open sql,conn,1,1
  SortName=rs("SortName")
  ParentID=rs("ParentID")
  ViewFlag=rs("ViewFlag")
  SortPath=rs("SortPath")
  Sortpic=rs("Sortpic")
  Angel_languageid=rs("Angel_languageid")
%>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#628AE1">
<form name="FolderForm" method="post" action="ProductSort.asp?Action=Save&From=Edit&ID=<%=ID%>">
  <tr>
    <td height="24" nowrap><font color="#FFFFFF"><img src="../Images/Explain.gif" width="18" height="18" border="0" align="absmiddle">&nbsp;<strong>修改类别：</strong></font></td>
  </tr>
  <tr>
    <td height="24" nowrap bgcolor="#ffffff">|&nbsp;根类&nbsp;→&nbsp;<% if ParentID<>0 then TextPath(ParentID)%></td>
  </tr>
  <tr>
    <td height="24" bgcolor="#ffffff">
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="690" nowrap>名称：<input name="SortName" type="text" class="textfield" id="SortName" size="22" value="<%=SortName%>"><input readonly name="ParentID" type="hidden" class="textfield" id="ParentID" size="6" value="<%=ParentID %>"><input readonly name="SortPath" type="hidden" class="textfield" id="SortPath" size="45" value="<%=SortPath%>">
	 <input name="ViewFlag" type="radio" value="1" <%if ViewFlag then response.write ("checked=checked")%> />
        是
        <input name="ViewFlag" type="radio" value="0" <%if not ViewFlag then response.write ("checked=checked")%>/>
        否 	
		分类图：
<div style="height:26px;line-height:26px;width:230px;float:left">
<input name="Sortpic" type="text" class="textfield" id="Sortpic" style="WIDTH: 230px;" value="<%=Sortpic%>" maxlength="100" > 
</div>
<div style="height:26px;line-height:26px;width:360px;float:left">
<iframe src="../upload.asp?action=banner&fpicid=Sortpic&formname=FolderForm" width="270" height="25" frameborder="0" scrolling="no"></iframe></div>	
  	<input name="Angel_languageid" type="hidden" value="<%=Angel_languageid%>" />
		</td>
        <td nowrap><input name="submitSave" type="submit" class="button" id="保存" value="  保存  "></td>
	  </tr>
    </table>
	</td>
  </tr>
</form>
</table>
<br>
<%
end function
'转移节点表单------------------------------
Function moveFolderForm()
  Dim ID,ParentID,SortName,SortPath
  ID=request.QueryString("ID")
  ParentID=request.QueryString("ParentID")
  SortName=request.QueryString("SortName")
  SortPath=request.QueryString("SortPath")
%>
<table id="SortFromTo" width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#628AE1">
<form name="MoveForm" method="post" action="ProductSort.asp?Action=MoveSave">
  <tr>
    <td height="24" colspan="3" nowrap><font color="#FFFFFF"><img src="../Images/Explain.gif" width="18" height="18" border="0" align="absmiddle">&nbsp;<strong>类别移动：通过点击分类树中类别对应的"移"可重新选择将要作移动的类别，包括本类、子类及所有下属信息条目将一起被移动。</strong></font></td>
  </tr>
  <tr>
    <td height="24" colspan="3" nowrap bgcolor="#ffffff">→&nbsp;<% response.write (SortName) %></td>
  </tr>
  <tr>
    <td nowrap bgcolor="#ffffff">移动类ID：<input readonly name="ID" type="text" class="textfield" id="ID" size="14" value="<%=ID%>"></td>
    <td nowrap bgcolor="#ffffff">移动类父ID：<input readonly name="ParentID" type="text" class="textfield" id="ParentID" size="14" value="<%=ParentID%>"></td>
    <td nowrap bgcolor="#ffffff">移动类数字路径：<input readonly name="SortPath" type="text" class="textfield" id="SortPath" size="30" value="<%=SortPath%>"></td>
  </tr>
  <tr>
    <td height="24" colspan="3" nowrap><font color="#FFFFFF"><strong>目标位置：通过点击"至"选择将要放置到的类别。</strong></font></td>
  </tr>
  <tr>
    <td height="24" colspan="3" nowrap bgcolor="#ffffff">→&nbsp;请选择…</td>
  </tr>
  <tr>
    <td nowrap bgcolor="#ffffff">目标类ID：<input readonly name="toID" type="text" class="textfield" id="toID" size="14" value=""></td>
    <td nowrap bgcolor="#ffffff">目标类父ID：<input readonly name="toParentID" type="text" class="textfield" id="toParentID" size="14" value=""></td>
    <td nowrap bgcolor="#ffffff">目标类数字路径：<input readonly name="toSortPath" type="text" class="textfield" id="toSortPath" size="30" value=""></td>
  </tr>
  <tr>
    <td height="40" colspan="3" nowrap bgcolor="#ffffff" align="center"><input name="submitMove" type="submit" class="button" id="转移" value="  转移  "></td>
  </tr>
</form>
</table>
<br>
<%
end function
'保存转移节点------------------------------
Function saveMoveFolder()
  Dim rs,sql,fromID,fromParentID,fromSortPath,toID,toParentID,toSortPath,fromParentSortPath
  fromID=request.Form("ID")
  fromParentID=request.Form("ParentID")
  fromSortPath=request.Form("SortPath")

  toID=request.Form("toID")
  toParentID=request.Form("toParentID")
  toSortPath=request.Form("toSortPath")
  if toID="" or toParentID="" or toSortPath="" then
    response.write ("<script language=javascript> alert('没有选择移动的目标位置，请返回选择！');history.back(-1);</script>")
    response.end
  end if
  if fromParentID=0 then
    response.write ("<script language=javascript> alert('一级分类不能被移动，请返回选择！');history.back(-1);</script>")
    response.end
  end if
  if fromSortPath=toSortPath then
    response.write ("<script language=javascript> alert('选择的移动类别和目标位置相同了，请返回重新选择！');history.back(-1);</script>")
    response.end
  end if
  if Instr(toSortPath,fromSortPath)>0 or fromParentID=toID then
    response.write ("<script language=javascript> alert('不能将类别移动到本类或下属类里，请返回重新选择！');history.back(-1);</script>")
    response.end
  end if
  Set rs=server.CreateObject("adodb.recordset")
  sql="Select * From Angel_ProductSort where ID="&fromParentID
  rs.open sql,conn,0,1
  fromParentSortPath=rs("SortPath")
  conn.execute("update Angel_ProductSort set SortPath='"&toSortPath&"'+Mid(SortPath,Len('"&fromParentSortPath&"')+1) where Instr(SortPath,'"&fromSortPath&"')>0")'更新类别数字路径
  conn.execute("update Angel_ProductSort set ParentID='"&toID&"' where ID="&fromID)'更新类别父类ID
  conn.execute("update Angel_Product set SortPath='"&toSortPath&"'+Mid(SortPath,Len('"&fromParentSortPath&"')+1) where Instr(SortPath,'"&fromSortPath&"')>0")'更新信息数字路径
  response.write ("<script language=javascript> alert('移动类别成功，点击确定查看类别树！');location.replace('ProductSort.asp');</script>")
End Function
%>
