
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--#include file="../inc/Conn.asp"-->
<!--#include file="Inc/Admin.Asp"-->
<%
dim rs
Action=trim(Request("Action"))
names=trim(request("names"))
zid=trim(request("zid"))
classid=trim(request("classid"))

if classid = "" then classid=0 end if
if style = "" then style=0 end if
if TemplateID = "" then TemplateID=0 end if
if TemplateID_View = "" then TemplateID_View=0 end if

Set rsBigClass=Server.CreateObject("Adodb.RecordSet")
if Action="Add" then
	
	if names = "" then
	response.write  "<script language=javascript>alert('请填写分类名称!');history.go(-1);</script>"
	response.End()
	end if
	
	Set rs=Server.CreateObject("Adodb.RecordSet")
	sql="select * from Dream_Area where Dream_Names='"&names&"' and Dream_Classid="&classid
	rs.open sql,conn,1,1
	if not (rs.bof and rs.eof) then
	response.write  "<script language=javascript>alert('同级下，不可以出现相同名称的分类!');history.go(-1);</script>"
	response.End()
	end if
	rs.Close
	set rs=Nothing
	
	
	Set rs=Server.CreateObject("Adodb.RecordSet")
	rs.open "Dream_Area",conn,1,3
    rs.addnew
    rs("Dream_Names")=names
	rs("Dream_Classid")=classid
	rs("Dream_Zid")=zid
    rs.update
    rs.Close
	set rs=Nothing
    call CloseConn()
	Response.Redirect "Menpiao_Area.asp"
end if

if action="Modify" then
	id=request("id")
	
	if names = "" then
	response.write  "<script language=javascript>alert('请填写分类名称!');history.go(-1);</script>"
	response.End()
	end if
	
	Set rs=Server.CreateObject("Adodb.RecordSet")
	sql="select * from Dream_Area where Dream_Names='"&names&"' and Dream_Classid="&classid&" and id<>"&id
	rs.open sql,conn,1,1
	if not (rs.bof and rs.eof) then
	response.write  "<script language=javascript>alert('同级下，不可以出现相同名称的分类!');history.go(-1);</script>"
	response.End()
	end if
	rs.Close
	set rs=Nothing
	
	Set rs=Server.CreateObject("Adodb.RecordSet")
	rs.open "Select * From Dream_Area Where id=" & id & "",conn,1,3
	if not (rs.bof and rs.eof) then
		rs("Dream_Classid")=classid
		rs("Dream_Names")=names
		rs("Dream_Zid")=zid			
		rs.update
		rs.close
		set rs=nothing
		Response.Redirect "Menpiao_Area.asp"  
	end if
end if

if action="Del" then
	id=int(request("id"))
	Conn.execute "Delete from Dream_Area Where ID=" & id &" or Dream_Classid=" & id
	Response.Redirect "Menpiao_Area.asp"
end if
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>分类管理</title>
<link href="css/adminstyle.css" rel="stylesheet" type="text/css">
<script language=javascript>
function ConfirmDel()
{
   if(confirm("确定要删除选中的类别吗？一旦删除，其下的内容也将被删除并将不能恢复！"))
     return true;
   else
     return false;	 
}
</script>
</head>

<body>
<div class="container">
	<div class="local"><h3>您现在的位置：<a href="admin_Index_Main.asp">管理首页</a> >> 分类管理</h3></div>
	<table width="100%" cellpadding="0" cellspacing="0" style=" margin-top:10px;">
		<tr>
			<td width="260" valign="top" >
			<%
			id=trim(request("id"))
			Set rs=Server.CreateObject("Adodb.RecordSet")
			if id<>"" then
				sql="select * from Dream_Area where id="&id
				rs.open sql,conn,1,1
				if not(rs.eof and rs.bof) then
					namess=rs("Dream_Names")
					classid=rs("Dream_Classid")					
					zid=rs("Dream_Zid")					
				end if
				rs.close
			end if
			rs.close
			set rs=nothing
			%>
			<div class="add_class">
				<h3>添加修改分类</h3>
				<form name="myform" method="post" action="Menpiao_Area.asp">			
				<table width="100%" border="0" cellpadding="3" cellspacing="0" style="margin-top:10px;">
					<tr>
					  <td width="35%" align="right" valign="middle">所属分类：</td>
					  <td width="65%" align="left" valign="middle"><select name="classid" class="select">					  
					<option value="0" <%if classid=0 then%>selected<%end if%>>一级分类</option>
					<%
					set rss=server.CreateObject("adodb.recordset")
					sql="select * from Dream_Area where Dream_Classid=0 order by Dream_Zid asc,id asc"
					rss.open sql,Conn,1,1
					if not(rss.eof and rss.bof) then
						do while not rss.eof
					%>
					<option value="<%=rss("id")%>" <%if int(classid)=rss("id") then%>selected<%end if%>><%=rss("Dream_Names")%></option>
					<%
						rss.movenext
						loop
					end if
					rss.close
					set rss=nothing
					%>				
				  </select></td>
					</tr>
					<tr>
					  <td align="right" valign="middle" width="35%">分类名称：</td>
					  <td align="left" valign="middle"><input name="names" type="text" id="names" value="<%=namess%>" class="input"></td>
					</tr>					
				  <tr>
					  <td align="right" valign="middle">排序编号：</td>
					  <td align="left" valign="middle"><input name="zid" type="text" value="<%=zid%>" class="input" /></td>
					</tr>
				 <tr>
					  <td>&nbsp;</td>
					  <td><input name="Submit" type="submit" value=" 提 交 "></td>
				  </tr>
				  </table>
				  <input name="action" type="hidden" value="<%if id<>"" then%>Modify<%else%>Add<%end if%>"><input name="id" type="hidden" value="<%=id%>"><input name="mkid" type="hidden" value="<%=mkid%>">
				</form>
			</div>			
			</td>
			<td valign="top">
			<div class="contents">
			<table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="#E6E6E6">
				<tr>
				  <td width="50" align="center" bgcolor="#FFFFFF" class="Title">ID</td>	
			      <td height="22" bgcolor="#FFFFFF" class="Title">&nbsp;&nbsp;分类名称</td>
				  <td width="130" align="center" bgcolor="#FFFFFF" class="Title">操作选项</td>
			  	</tr>
				<%
					sql="select * from Dream_Area where Dream_Classid=0 order by Dream_Zid asc"
					rsBigClass.open sql,conn,1,1
					if not(rsBigClass.eof and rsBigClass.bof) then
						do while not rsBigClass.eof
				%>				
				<tr class="tdbg">
					<td align="center" bgcolor="#F3F3F3"><%=rsBigClass("ID")%></td>
				  <td height="22" bgcolor="#F3F3F3">&nbsp;&nbsp;<b>+ <%=rsBigClass("Dream_Names")%></b></td>
					<td align="center" bgcolor="#F3F3F3" style="padding-right:10"><a href="Menpiao_Area.asp?id=<%=rsBigClass("id")%>">[修改]</a> <a href="Menpiao_Area.asp?id=<%=rsBigClass("id")%>&action=Del" onclick="return ConfirmDel();">[删除]</a></td>
				</tr>
				<%
					set rst=server.CreateObject("adodb.recordset")
					sql="select * from Dream_Area where Dream_Classid="&rsBigClass("id")&" order by id asc"
					rst.open sql,Conn,1,1
					if not(rst.eof and rst.bof) then
					do while not rst.eof
				%>
				<tr bgcolor="#fafafa">
					<td align="center" bgcolor="#FFFFFF"><%=rst("ID")%></td>
				  <td height="22" bgcolor="#FFFFFF">&nbsp;&nbsp;-- <a href="Menpiao_Area.asp?id=<%=rst("id")%>"><%=rst("Dream_Names")%></a></td>
				  <td align="center" bgcolor="#FFFFFF" style="padding-right:10"><a href="Menpiao_Area.asp?id=<%=rst("id")%>" class="blue">[修改]</a> <a href="Menpiao_Area.asp?id=<%=rst("id")%>&action=Del" onclick="return ConfirmDel();" class="blue">[删除]</a></td>
			  	</tr>				
				<%
					rst.movenext
					loop
					end if
					rst.close
					set rst=nothing
					rsBigClass.movenext
					loop
					end if
				%>
			  </table>			  
			</div>
			</td>
		</tr>
  </table>
</div>
<%
	rsBigClass.close
	set rsBigClass=nothing
%>
</body>
</html>