<!--#include file="conn.asp"-->
<title>商品分类管理</title>
<%
if session("admin")="" then
conn.close
set conn = nothing
response.Write "<script language='javascript'>alert('请先登录！');history.go(-1);</script>"
response.End
else
if request.cookies("timesshop")("admin")="" then
conn.close
set conn = nothing
response.Write "<script language='javascript'>alert('请先登录！');history.go(-1);</script>"
response.End
end if
end if
if session("rank")>1 then
conn.close
set conn = nothing
response.Write "<script language='javascript'>alert('你无权添加修改商品信息！');history.go(-1);</script>"
response.End
end if
categoryid=SafeRequest("categoryid",1)
action=SafeRequest("action",0)
Dim ii
select case action
Case "edit"
set rs=server.CreateObject("adodb.recordset")
rs.Open "select * from category where categoryid = "&categoryid,conn,1,1
%>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#227776">
  <tr> 
    <td height="20" bgcolor="#227776" align="center"><font color="#FFFFFF">添加商品大类</font></td>
  </tr>
  <tr> 
    <td bgcolor="#FFFFFF">
	<table width="90%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
        </tr>
        <form name="form1" method="post" action="addcat.asp?action=editok">
		<input name="categoryid" type="hidden" value="<%= categoryid %>">
		<tr bgcolor="#FFFFFF"> 
            <td align="center">分类名称</td>
            <td><input name="category" type="text" id="category" size="24" value="<%=trim(rs("category"))%>"></td>
          </tr>
		  <tr bgcolor="#FFFFFF"> 
            <td align="center">所属分类</td>
            <td><select name="CID">  
<option value="0">一级分类</option>
			<%
sort(0)

ii=0
sub sort(selec)
	sql="select * from category where ParentID = "&selec&" order by categoryorder"
	Set Rs1=Conn.Execute(sql)
do while not rs1.eof
if selec=0 then
%>
<option value="<%=int(rs1("categoryid"))%>" <% if int(rs1("categoryid"))=rs("ParentID") Then Response.write("Selected") %>><%=rs1("category")%></option>
<%
else
%>
<option value="<%=int(rs1("categoryid"))%>" <% if int(rs1("categoryid"))=rs("ParentID") Then Response.write("Selected") %>><%=string(ii*2,"　")%><%=rs1("category")%></option>
<%
end if
ii=ii+1
	sort rs1("categoryid")
ii=ii-1
	rs1.movenext
	loop
	rs1.close
	Set Rs1 = Nothing
end sub

%></select>
</td>
          </tr>
		  <tr bgcolor="#FFFFFF">
		  <td align="center">分类介绍</td>
		  <td><textarea name="intro" cols="80" rows="6"><%=trim(rs("intro"))%></textarea></td>
		  </tr>
		   <tr bgcolor="#FFFFFF">
		  <td align="center">分类图片</td>
		  <td><input name="icon" type="text" id="icon" size="50" value="<%=trim(rs("icon"))%>"></td>
		  </tr>
		   <tr bgcolor="#FFFFFF">
		  <td align="center">分类Meta</td>
		  <td><textarea name="meta" cols="40" rows="4"><%=trim(rs("meta"))%></textarea></td>
		  </tr>
		  <tr bgcolor="#FFFFFF">
		  <td align="center">分类排序</td>
		  <td><input name="categoryorder" type="text" id="categoryorder" size="4" value="<%=trim(rs("categoryorder"))%>"></td>
		  </tr>
		  <tr bgcolor="#FFFFFF">
		  <td align="center">推荐分类</td>
		  <td><input name="first" type="checkbox" <% if rs("first")=1 Then Response.write("checked") %> value="1"></td>
		  </tr>
		  <tr bgcolor="#FFFFFF">
		  <td align="center">显示分类</td>
		  <td><select name="hide">
		   <option value="0" <% if rs("hide")=0 Then Response.write("Selected") %>>显示</option>
           <option value="1" <% if rs("hide")=1 Then Response.write("Selected") %>>隐藏</option>
		  </select></td>
		  </tr>
		   <tr bgcolor="#FFFFFF">
		  <td></td>
		  <td><input type="submit" name="Submit3" value="提 交"></td>
		  </tr>
        </form>
      </table></td>
  </tr>
</table>
<%
case "add"

set rs=server.CreateObject("adodb.recordset")
rs.Open "select * from category where categoryid = "&categoryid,conn,1,1
%>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#6699cc">
  <tr> 
    <td height="20" bgcolor="#6699cc" align="center"><font color="#FFFFFF">添加商品分类</font></td>
  </tr>
  <tr> 
    <td bgcolor="#FFFFFF">
	<table width="90%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
        </tr>
        <form name="form1" method="post" action="addcat.asp?action=addok">
		<tr bgcolor="#FFFFFF"> 
            <td align="center">分类名称</td>
            <td><input name="category" type="text" id="category" size="24"></td>
          </tr>
		  <tr bgcolor="#FFFFFF"> 
            <td align="center" height="25">所属分类</td>
            <td><input name="CID" type="hidden" value="<%= categoryid %>">
			<%=trim(rs("category"))%></td>
          </tr>
		  <tr bgcolor="#FFFFFF">
		  <td align="center">分类介绍</td>
		  <td><textarea name="intro" cols="80" rows="6"></textarea></td>
		  </tr>
		   <tr bgcolor="#FFFFFF">
		  <td align="center">分类图片</td>
		  <td><input name="icon" type="text" id="icon" size="50"></td>
		  </tr>
		   <tr bgcolor="#FFFFFF">
		  <td align="center">分类Meta</td>
		  <td><textarea name="meta" cols="40" rows="4"></textarea></td>
		  </tr>
		  <tr bgcolor="#FFFFFF">
		  <td align="center">分类排序</td>
		  <td><input name="categoryorder" type="text" size="4" value="1"></td>
		  </tr>
		  <tr bgcolor="#FFFFFF">
		  <td align="center">推荐分类</td>
		  <td><input name="first" type="checkbox" value="1"></td>
		  </tr>
		  <tr bgcolor="#FFFFFF">
		  <td align="center">显示分类</td>
		  <td><select name="hide">
		   <option value="0">显示</option>
           <option value="1">隐藏</option>
		  </select></td>
		  </tr>
		   <tr bgcolor="#FFFFFF">
		  <td></td>
		  <td><input type="submit" name="Submit3" value="提 交"></td>
		  </tr>
        </form>
      </table></td>
  </tr>
</table>
<%
case "addcat" 
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from category",conn,1,3
rs.AddNew
rs("category")=trim(request.form("category"))
rs("categoryorder")=int(request.form("categoryorder"))
rs("ParentID")=0
rs("first")=1
rs("hide")=0
rs.Update
rs.Close
set rs=nothing
response.Redirect "bclass.asp"

case "addok" 
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from category",conn,1,3
rs.AddNew
rs("category")=trim(request.form("category"))
rs("intro")=trim(request.form("intro"))
rs("icon")=trim(request.form("icon"))
rs("meta")=trim(request.form("meta"))
rs("categoryorder")=int(request.form("categoryorder"))
rs("ParentID")=int(request.form("CID"))
rs("first")=int(request.form("first"))
rs("hide")=int(request.form("hide"))
rs.Update
rs.Close
set rs=nothing
response.Redirect "bclass.asp"

case "editok" 
set rs=server.CreateObject("adodb.recordset")
rs.Open "select * from category where categoryid = "&categoryid,conn,1,3
rs("category")=trim(request.form("category"))
rs("intro")=trim(request.form("intro"))
rs("icon")=trim(request.form("icon"))
rs("meta")=trim(request.form("meta"))
rs("categoryorder")=int(request.form("categoryorder"))
rs("ParentID")=int(request.form("CID"))
rs("first")=int(request.form("first"))
rs("hide")=int(request.form("hide"))
rs.Update
rs.Close
set rs=nothing
response.Redirect "bclass.asp"

case "delok"
set rs=server.CreateObject("adodb.recordset")
rs.open "select ParentID from category where ParentID="&categoryid,conn,1,1
If Not rs.eof then
conn.close
set conn = nothing
response.Write "<script language='javascript'>alert('该分类有子分类，请先删除该分类的所有子分类！');history.go(-1);</script>"
response.End
else
conn.execute ("delete from category where categoryid="&categoryid)
conn.execute ("delete from product where categoryid="&categoryid)
response.Redirect "bclass.asp"
end if

end select
%>
<br>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#6699cc">
  <tr> 
    <td bgcolor="#6699cc" height="20" align="center"><font color="#FFFFFF">操作注意事项及说明</font></td>
  </tr>
  <tr> 
    <td bgcolor="#FFFFFF"> 
	<table width="80%" border="0" align="center" cellpadding="5" cellspacing="0">
        <tr> 
          <td height="20"><font color="#FF6600">·请注意分类名称不要含有非法字符。<br>
            ·增加一级分类后，些分类将会被列出前台一级分类中。<br>
            ·进行删除操作的同时，会删除此大类下包含的所有小分类和商品。</font></td>
        </tr>
      </table></td>
  </tr>
</table>
<!--#include file="footer.asp"-->