<!--#include file="head.asp"-->
<style>body{background-color: #fff;}</style>

<%
Const stringmodarr = "0123456789"
dim randarr2,strlength
strlength = Len(stringmodarr)
Randomize timer
For i = 1 To 4 
randarr2 = randarr2&Mid(stringmodarr,Int(Rnd * strlength + 1),1)  
Next 
get_timeh=timer()*100
get_timeh=right("00"&get_timeh,2)
get_timeh=replace(get_timeh,".","0")
randarr = Right((year(Now())),2)&Right(("00"&Month(Now())),2)&Right(("00"&Day(Now())),2)&Right(("00"&hour(Now())),2)&Right(("00"&minute(Now())),2)&Right(("00"&second(Now())),2)&get_timeh&randarr2



sql="select ayisguolv,ayguolvcon,rzshangjia from ayquanju" 
rs.open sql,conn,1,1
ayisguolv=rs("ayisguolv")
ayguolvcon=trim(rs("ayguolvcon"))
rzshangjia=rs("rzshangjia")
rs.close


act=SafeRequest("act")

if act<>"" then

	if act="xj" then
	id=SafeRequest("id")
	if id="" then call PopErr("出现错误")
	sql="select * from aykafenlei where aykafenleiid="&id&" and aykanamesuoyou="&clng(request.Cookies("aynameid"))&"" 
	rs.open sql,conn,1,3
	if rs.bof and rs.eof then call PopErr("未找到商品分类")
	rs("aykafenleikg")=1
	rs.update
	rs.close
	end if 
	
	if act="sj" then
	id=SafeRequest("id")
	if id="" then call PopErr("出现错误")
	sql="select * from aykafenlei where aykafenleiid="&id&" and aykanamesuoyou="&clng(request.Cookies("aynameid"))&"" 
	rs.open sql,conn,1,3
	if rs.bof and rs.eof then call PopErr("未找到商品分类")
	
	if rs("issjsuo")=1 then
	call PopErr("该商品分类被限制上架")
	response.End()
	end if
	
	
	rs("aykafenleikg")=0
	rs.update
	rs.close
	end if


	if act="addfenlei" then
	aykafenlei=SafeRequestform("aykafenlei")
	aykafenleisx=SafeRequestform("aykafenleisx")
	page=SafeRequest("page")
	if aykafenlei="" then call PopErr("卡分类不能为空")
	if aykafenleisx="" then call PopErr("卡分类顺序不能为空")
	
	if instr(1,trim(aykafenlei),"|")<>0 then call PopErr("分类名称,字符 | 不可以使用哦，请重新填写！")
	
	if ayisguolv=1 then
	if guolvRequestform("aykafenlei",ayguolvcon)=false then 
	call logadd(request.Cookies("aynameid"),"添加分类含有敏感文字"&aykafenlei,0,1)
	call PopErr(""&ayguolvcon&"，以上敏感词语禁用哦！")
	end if
	end if
	
	set rsadd=server.CreateObject("adodb.recordset")
	sql="select * from aykafenlei where aykanamesuoyou="&clng(request.Cookies("aynameid"))&" and aykafenleiname='"&aykafenlei&"'" 
	rsadd.open sql,conn,1,3
		if rsadd.bof and rsadd.eof then
		ayflsumid=trim(randarr)
		rsadd.addnew
		rsadd("aykafenleiname")=aykafenlei
		rsadd("aykafenleisx")=clng(aykafenleisx)
		rsadd("aykanamesuoyou")=request.Cookies("aynameid")
		rsadd("ayflsumid")=ayflsumid
		rsadd.update
		rsadd.close
		call logadd(request.Cookies("aynameid"),"商品分类添加成功"&left(aykafenlei,20),5,0)

		'获取id 加入MD5
		set rsid=server.CreateObject("adodb.recordset")
		sqlid="select ayflsumid,aykafenleiid,aykanamesuoyou,aykafenleimd5,ayfldlmd5url from aykafenlei where ayflsumid='"&ayflsumid&"' and aykanamesuoyou="&clng(request.Cookies("aynameid"))&"" 
		rsid.open sqlid,conn,1,3
		md51=md5d(rsid("aykafenleiid"))
		md52=md5user(rsid("aykafenleiid"))
		rsid("aykafenleimd5")=md51
		rsid("ayfldlmd5url")=md52
		rsid.update
		rsid.close
		
		response.Redirect("fenlei?page="&page&"")
		else
		rsadd.close
		call PopErr("卡分类已经存在")		
		end if
	end if
	
	if act="adderji" then
	erjifenlei=SafeRequestform("erjifenlei")
	erjifenleisx=SafeRequestform("erjifenleisx")
	page=SafeRequest("page")
	id=SafeRequest("id")
	if erjifenlei="" then call PopErr("二级分类不能为空")
	if erjifenleisx="" then call PopErr("二级分类顺序不能为空")
	if id="" then call PopErr("参数获取失败")
	
	if instr(1,trim(erjifenlei),"|")<>0 then call PopErr("分类名称,字符 | 不可以使用哦，请重新填写！")
	
	if ayisguolv=1 then
	if guolvRequestform("erjifenlei",ayguolvcon)=false then
	call logadd(request.Cookies("aynameid"),"添加二级分类含有敏感文字"&erjifenlei,0,1) 
	call PopErr(""&ayguolvcon&"，以上敏感词语禁用哦！")
	end if
	end if
	
	sql="select * from aykafenlei where aykafenleiid="&clng(id)&"" 
	rs.open sql,conn,1,3
	if rs.bof and rs.eof then
	rs.close
	call PopErr("参数获取失败")
	elseif clng(rs("aykanamesuoyou"))<>clng(request.Cookies("aynameid")) then
	rs.close
	call PopErr("参数获取失败")
	end if
	
	set rsadderji=server.CreateObject("adodb.recordset")
	sql="select * from aykafenlei where aykafenleiname='"&erjifenlei&"' and aykanamesuoyou="&clng(request.Cookies("aynameid"))&" and ayshangjiid<>0" 
	rsadderji.open sql,conn,1,3
	    if rsadderji.bof and rsadderji.eof then
		ayflsumid=trim(randarr)
		rsadderji.addnew
		rsadderji("aykafenleiname")=erjifenlei
		rsadderji("aykafenleisx")=clng(erjifenleisx)
		rsadderji("aykanamesuoyou")=request.Cookies("aynameid")
		rsadderji("ayshangjiid")=clng(id)
		rsadderji("ayflsumid")=ayflsumid
		rsadderji.update
		rsadderji.close
		call logadd(request.Cookies("aynameid"),"二级分类添加成功"&left(erjifenlei,20),5,0) 

		'获取id 加入MD5
		set rsid=server.CreateObject("adodb.recordset")
		sqlid="select ayflsumid,aykafenleiid,aykanamesuoyou,aykafenleimd5,ayfldlmd5url from aykafenlei where ayflsumid='"&ayflsumid&"' and aykanamesuoyou="&clng(request.Cookies("aynameid"))&"" 
		rsid.open sqlid,conn,1,3
		md51=md5d(rsid("aykafenleiid"))
		md52=md5user(rsid("aykafenleiid"))
		rsid("aykafenleimd5")=md51
		rsid("ayfldlmd5url")=md52
		rsid.update
		rsid.close
		
		response.Redirect("fenlei?page="&page&"")
		else
		rsadderji.close
		call PopErr("卡分类已经存在")
		end if
	end if
	
	if act="edit" then
	fenlei=SafeRequestform("fenlei")
	paixu=SafeRequestform("paixu")
	page=SafeRequest("page")
	id=SafeRequest("id")
	if fenlei="" then call PopErr("分类名称不能为空")
	if paixu="" then call PopErr("分类排序不能为空")
	if id="" then call PopErr("参数获取失败")
	
	if ayisguolv=1 then
	if guolvRequestform("fenlei",ayguolvcon)=false then 
	call logadd(request.Cookies("aynameid"),"修改分类含有敏感文字"&fenlei,0,1) 
	call PopErr(""&ayguolvcon&"，以上敏感词语禁用哦！")
	end if
	end if
	
	sql="select * from aykafenlei where aykafenleiid="&clng(id)&" and aykanamesuoyou="&clng(request.Cookies("aynameid"))&"" 
	rs.open sql,conn,1,3
		if rs.bof and rs.eof then
		rs.close
		call PopErr("未找到参数")
    	else
		rs("aykafenleiname")=fenlei
		rs("aykafenleisx")=clng(paixu)
		if isnull(trim(rs("aykafenleimd5")))=true or trim(rs("aykafenleimd5"))="" then rs("aykafenleimd5")=trim(MD5d(rs("aykafenleiid")))
		if isnull(trim(rs("ayfldlmd5url")))=true or trim(rs("ayfldlmd5url"))="" then rs("ayfldlmd5url")=trim(md5user(rs("aykafenleiid")))
		rs.update
		rs.close
		call logadd(request.Cookies("aynameid"),"分类修改成功"&left(fenlei,20),5,0) 
		%>
		<script language='javascript'>
		alert('修改成功！');
		window.document.location.href="fenlei?page="+<%=page%>;
		</script>
		<%end if
	end if
	
	if act="editerji" then
	editerji=SafeRequestform("editerji")
	paixu=SafeRequestform("paixu")
	page=SafeRequest("page")
	id=SafeRequest("id")
	if editerji="" then call PopErr("二级分类不能为空")
	if paixu="" then call PopErr("二级分类排序不能为空")
	if id="" then call PopErr("参数获取失败")
	
	if ayisguolv=1 then
	if guolvRequestform("editerji",ayguolvcon)=false then 
	call logadd(request.Cookies("aynameid"),"修改二级分类含有敏感文字"&editerji,0,1) 
	call PopErr(""&ayguolvcon&"，以上敏感词语禁用哦！")
	end if
	end if
	
	sql="select * from aykafenlei where aykafenleiid="&clng(id)&" and aykanamesuoyou="&clng(request.Cookies("aynameid"))&"" 
	rs.open sql,conn,1,3
		if rs.bof and rs.eof then
		rs.close
		call PopErr("未找到参数")
    	else
		rs("aykafenleiname")=editerji
		rs("aykafenleisx")=clng(paixu)
		if isnull(trim(rs("aykafenleimd5")))=true or trim(rs("aykafenleimd5"))="" then rs("aykafenleimd5")=trim(MD5d(rs("aykafenleiid")))
		if isnull(trim(rs("ayfldlmd5url")))=true or trim(rs("ayfldlmd5url"))="" then rs("ayfldlmd5url")=trim(md5user(rs("aykafenleiid")))
		rs.update
		rs.close
		call logadd(request.Cookies("aynameid"),"二级分类修改成功"&left(editerji,20),5,0) 
		%>
		<script language='javascript'>
		alert('修改成功！');
		window.document.location.href="fenlei?page="+<%=page%>;
		</script>
		<%end if
	end if
	
	if act="del" then
	page=SafeRequest("page")
	id=SafeRequest("id")
	if id="" then call PopErr("参数获取失败")
	
		sql="select * from aykafenlei where ayshangjiid="&clng(id)&" and aykanamesuoyou="&clng(request.Cookies("aynameid"))&"" 
		rs.open sql,conn,1,3
		if not(rs.bof and rs.eof) then
		call logadd(request.Cookies("aynameid"),"删除分类先删除二级分类",0,1) 
		call PopErr("请先将该分类下的二级分类删除")
		response.End()
    	end if
		rs.close
		
		sql="select * from aygood where aygoodfl="&clng(id)&" and aygoodsuoyouid="&clng(request.Cookies("aynameid"))&"" 
		rs.open sql,conn,1,3
		if not(rs.bof and rs.eof) then
		call logadd(request.Cookies("aynameid"),"删除分类先删除商品",0,1) 
		call PopErr("请先将该分类下的商品删除")
		response.End()
    	end if
		rs.close
		
		set delfenlei=server.CreateObject("adodb.recordset")
		sql="select * from aykafenlei where aykafenleiid="&clng(id)&" and aykanamesuoyou="&clng(request.Cookies("aynameid"))&""
		delfenlei.open sql,conn,1,3
		if delfenlei.bof and delfenlei.eof then
		delfenlei.close
		call PopErr("参数获取失败")
		else
		'if clng(delfenlei("ayfenleidlid"))<>0 then call PopErr("代理产品无法删除，您可以选择下架")
		delfenlei.delete
		delfenlei.close
		call logadd(request.Cookies("aynameid"),"分类删除成功"&id,0,0) 
		response.Redirect("fenlei?page="&page&"")
		end if
			
		
	end if
	
end if



sql="select ayismd5,aynameid,ismailrz,istelrz from ayname where aynameid="&request.Cookies("aynameid")&"" 
rs.open sql,conn,1,1
ayismd5=rs("ayismd5")
	if cint(rzshangjia)=1 then
		'if cint(rs("ismailrz"))=0 then call PopErr2("请先认证电子邮箱！","renzheng")
		if cint(rs("istelrz"))=0 then call PopErr2("请先认证手机号！","renzheng")
	end if
rs.close




%>

<script language="javascript">
function fenleierji(con){
	if(document.getElementById(con).style.display == "none"){
		document.getElementById(con).style.display = "";
	}
	else{
		document.getElementById(con).style.display = "none";
	}	
}
function err()
{
alert('代理商品无法添加二级分类');
}
</script>


<main>
<div  class="container">
<div class="ui-lrctnei">
<%call userleft()%>
<div class="r"> 
<div class="ui-content">
                        
					
                            
<div class="neiye">


            <!-------------------------------------- 开始 -------------------------------------->									
            <div class="neibiaoti"></div>
            <div class="neibiaoti2">添加商品分类</div>
           	<div class="gexian"></div>
   	  <div class="neitablewu">
                    <form name="form1" method="post" action="?act=addfenlei&page=<%=page%>">
					<table>
                  		<tr>
                          <td width="360" align="center">商品分类名称：
                          <input name="aykafenlei" type="text" class="reginput" id="aykafenlei" style="width:240px;" maxlength="25"></td>
                          <td width="150">分类排序：<input name="aykafenleisx" type="text" class="reginputddd" id="aykafenleisx" value="100" maxlength="4"></td>
                          <td><input style="cursor:pointer" class="logindlreg" type="submit" name="Submit" value=" 添 加 新 分 类 " ></td>
                        </tr>
                    </table>
              </form>
       		</div>
                    <div class="gexian20"></div>
            <!-------------------------------------- 结束 -------------------------------------->
                   
                                                     
            <!-------------------------------------- 开始 -------------------------------------->									
            <div class="neibiaoti"></div>
            <div class="neibiaoti2">商品分类列表</div>
           	<div class="gexian"></div>
                	<div class="neitable">
					<table>
                        <tr class="hd">
                            <td>分类名称</td>
                            <td>分类所属</td>
                            <td>分类排序</td>
                            <td>分类管理</td>
                        </tr>
						<%
                        sql="select * from aykafenlei where aykanamesuoyou="&request.Cookies("aynameid")&" and ayshangjiid=0 order by ayfenleidlid asc,aykafenleisx asc" 
                        rs.open sql,conn,1,3
                        if not(rs.bof and rs.eof) then
                        do while not rs.eof%>
                        <form method="post" name="edit" action="?act=edit&id=<%=rs("aykafenleiid")%>&page=<%=page%>">
                  		<tr onmouseover=this.bgColor='#FAFAFA' onmouseout=this.bgColor='#ffffff'>
                            <td><input name="fenlei" type="text" class="reginput" id="fenlei" value="<%=trim(rs("aykafenleiname"))%>" maxlength="30"></td>
                            <td><%if clng(rs("ayfenleidlid"))<>0 then response.Write "<span style='color: #009900'>"&totruename(rs("ayfenleidlid"))&"</span>":else:response.Write"本账户":end if%></td>
                          <td><input name="paixu" type="text" class="reginputddd" value="<%=rs("aykafenleisx")%>" maxlength="4"></td>
                            <td>
                            <%if clng(rs("ayfenleidlid"))<>0 then%>
							<a onClick="javascript:err();" class="logindlreg2">二级分类</a>
                            <%else%>
                            <a onClick="javascript:fenleierji('<%=88&clng(rs("aykafenleiid"))%>');" class="logindlreg2">二级分类</a>
                            <%end if%>
                            <input type="submit" name="Submit2" value="修改设置" class="logindlregedit">
							<%if cint(rs("aykafenleikg"))=0 then%>
							<a href="?act=xj&id=<%=rs("aykafenleiid")%>" title="点击下架" class="logindlreg2">上架中</a>
							<%elseif cint(rs("aykafenleikg"))=1 then%>
							<a href="?act=sj&id=<%=rs("aykafenleiid")%>" title="点击上架" style="color:#FF0000" class="logindlreg2">下架中</a>
							<%end if%>
							<a href="fenleiedit?id=<%=rs("aykafenleiid")%>" class="logindlreg2">编辑</a>
                            <!--
                            <a href="fenleijiazhi?id=<%'=rs("aykafenleiid")%>&flname=<%'=trim(rs("aykafenleiname"))%>" class="logindlreg2">卡价值</a>
                            -->
                            <a href="fenleilink?id=<%=rs("aykafenleiid")%>" style="color: #FF8000;" class="logindlreg2">分类链接</a> 
							<a href="goodlist?act=all&f=<%=rs("aykafenleiid")%>" class="logindlreg2">分类商品</a>
							<a href="?act=del&id=<%=rs("aykafenleiid")%>&page=<%=page%>"  onclick="javascript:return confirm('您确定要删除该分类吗？');" class="logindlreg2">删除</a>
                            </td>
                        </tr>
                        </form>
                        
                        
						<%  
                        set rserji=server.CreateObject("adodb.recordset")
                        sql="select * from aykafenlei where aykanamesuoyou="&request.Cookies("aynameid")&" and ayshangjiid="&rs("aykafenleiid")&" order by aykafenleisx asc" 
                        rserji.open sql,conn,1,3
                        do while not rserji.eof
                        %>
                        <form  method="post" name="editerji" action="?act=editerji&id=<%=rserji("aykafenleiid")%>&page=<%=page%>">
                  		<tr onmouseover=this.bgColor='#FAFAFA' onmouseout=this.bgColor='#ffffff'>
                            <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            ┕<input name="editerji" type="text" class="reginputer" id="editerji" value="<%=trim(rserji("aykafenleiname"))%>" maxlength="30"></td>
                            <td><%if clng(rserji("ayfenleidlid"))<>0 then response.Write "<span style='color: #009900'>"&totruename(rserji("ayfenleidlid"))&"</span>":else:response.Write"本账户":end if%></td>
                            <td><input name="paixu" type="text" class="reginputddd" value="<%=rserji("aykafenleisx")%>" maxlength="4"></td>
                            <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <input type="submit" name="Submit2" value="修改设置" class="logindlregedit">
							<%if cint(rserji("aykafenleikg"))=0 then%>
							<a href="?act=xj&id=<%=rserji("aykafenleiid")%>" title="点击下架" class="logindlreg2">上架中</a> 
							<%elseif cint(rserji("aykafenleikg"))=1 then%>
							<a href="?act=sj&id=<%=rserji("aykafenleiid")%>" title="点击上架" style="color:#FF0000" class="logindlreg2">下架中</a>
							<%end if%>
							<a href="fenleiedit?id=<%=rserji("aykafenleiid")%>" class="logindlreg2">编辑</a>
                            <!--
                            <a href="fenleijiazhi?id=<%'=rserji("aykafenleiid")%>&flname=<%'=trim(rserji("aykafenleiname"))%>" class="logindlreg2">卡价值</a>
                            -->
                            <a href="fenleilink?id=<%=rserji("aykafenleiid")%>" style="color: #FF8000;" class="logindlreg2">分类链接</a>   
		  					<a href="goodlist?fenlei=<%=rserji("aykafenleiid")%>&cact=cha" class="logindlreg2">分类商品</a>
		  					<a href="?act=del&id=<%=rserji("aykafenleiid")%>&page=<%=page%>"  onclick="javascript:return confirm('您确定要删除该分类吗？');" class="logindlreg2">删除</a>
                            </td>
                        </tr>
                        </form>
						<%
                        rserji.movenext 
                        loop
                        rserji.close%>
                        
                          <form name="adderji" method="post" action="?act=adderji&id=<%=rs("aykafenleiid")%>&page=<%=page%>"><form name="adderji" method="post" action="?act=adderji&id=<%=rs("aykafenleiid")%>&page=<%=page%>">
                          <tr id="<%=88&clng(rs("aykafenleiid"))%>" style="display:none" onmouseover=this.bgColor='#FAFAFA' onmouseout=this.bgColor='#ffffff'>
                            <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            ┕<input name="erjifenlei" type="text" class="reginputer" id="erjifenlei" maxlength="30"></td>
                            <td>&nbsp;</td>
                            <td><input name="erjifenleisx" type="text" class="reginputddd" value="100" size="10" maxlength="4"></td>
                            <td><input type="submit" name="Submit2" value="添加二级分类" class="logindlreg2tj"></td>
                          </tr>
                          </form>
                          
						<%n=n+1
                        rs.movenext  '指针向下移动
                        loop
                        end if
                        rs.close%>
                        <!--<tr><td colspan="5"></td></tr>-->
                    </table>
                    
            		</div>
            <!-------------------------------------- 结束 -------------------------------------->
                   
            <div class="gexian20"></div>
            <div class="mzsmbox2" style="padding-top:20px;">
            分类排序：排序数值越小，排位越靠前，如：排序99的会在排序100之上，在购买页面的商品分类列表会以此排序<br>
			分类下架：如果商品分类选择下架，则在购买页面，该商品分类下的所有商品统一不展示<br>
            卡价值依据顺序：商品卡价值-分类卡价值-商家卡价值。如：如果商品没有单独设置卡价值，则使用分类卡价值，分类未设置则直接使用商家设置的卡价值。
            </div>
            
           

        <div class="clearfix"></div>



</div>








</div>
</div>
</div>
</div>
</main>


<footer>
<div class="container">
</div>
</footer>

</body>
</html>