<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
Dim NCheck:NCheck=true
%>
<!--#include file="cgi/Config.asp"-->
<%
Dim rs
Dim act:act=request("act")
Dim eStr:eStr=""
select case act
	case "save"
		q_id=trim(request("q_id"))
		q_name		=mobj.CheckBadstr(trim(request("q_name")))
		
		q_note		=trim(request("q_note"))
		q_check		=trim(request("q_check"))
		q_max		=trim(request("q_max"))	
		q_yangshi=trim(request("q_yangshi"))
		
		
		if mobj.testreg(q_id,"^(\w|-){36}$") then
		if q_name="" or len(q_name)>50 then eStr=eStr&"<br />名称不能为空,且长度必须小于50"
		
			if len(q_note)>250 then eStr=eStr&"<br />描述长度大于250"
			if not mobj.testreg(q_check,"^[0,1]$") then q_check=0
			if not mobj.testreg(q_yangshi,"^[0,1]$") then q_yangshi=0
			if not mobj.testreg(q_max,"^\d{1,5}$") then q_max=0
			
			if eStr<>"" then 
				act="error"
			else
				mobj.crs rs 
				rs.open "select * from b2c_qudao where q_sn='"&q_id&"'",dstr,1,3
				if rs.eof and rs.eof then
					act="error"
					eStr=eStr&"<br />渠道不存在"
				else
					rs("q_name")=q_name
					
					rs("q_note")=q_note
					rs("q_check")=q_check
					rs("q_max")=q_max
					rs("q_yangshi")=q_yangshi
					
					rs.update
					act="ok"
					eStr="恭喜！渠道修改成功"
				end if
			end if
		else
			if q_name="" or len(q_name)>50 then eStr=eStr&"<br />名称不能为空,且长度必须小于50"
			
			if len(q_note)>250 then eStr=eStr&"<br />描述长度大于250"
			if not mobj.testreg(q_check,"^[0,1]$") then q_check=0
			if not mobj.testreg(q_max,"^\d{1,5}$") then q_max=0
			
			if eStr<>"" then 
				act="error"
			else
				mobj.crs rs
				rs.open "select * from b2c_qudao where q_name='"&q_name&"'",dstr,1,3
				if rs.eof and rs.bof then
					q_id=mobj.GenerateGuid()
					rs.addnew
					rs("q_sn")=q_id
					rs("q_name")=q_name
					
					rs("q_note")=q_note
					rs("q_check")=q_check
					rs("q_max")=q_max
					rs("q_yangshi")=q_yangshi
					rs.update
					act="ok"
					eStr="恭喜！渠道添加成功"
				else
					act="error"
					eStr=eStr&"<br />该渠道已经存在"
				end if
				mobj.drs rs
			end if
		end if
		
	case "edit"
			q_id		=trim(request("editid"))
			if not mobj.testreg(q_id,"^(\w|-){36}$") then
				act="error"
				eStr=eStr&"<br />渠道ID参数错误"
			else
				mobj.crs rs 
				rs.open "select * from b2c_qudao where q_sn='"&q_id&"'",dstr,1,1
				if rs.eof and rs.bof then
					act="error"
					eStr=eStr&"<br />渠道不存在"
				else
					
					q_name			=rs("q_name")
					
					q_note			=rs("q_note")
					q_check			=rs("q_check")
					q_max			=rs("q_max")
					q_yangshi=rs("q_yangshi")
				end if	
				mobj.drs rs			 	
			end if
	case "del"
		q_id		=trim(request("q_id"))
		if not mobj.testreg(q_id,"^(\w|-){36}$") then
				act="error"
				eStr=eStr&"<br />渠道ID参数错误"
		else
				
				
					mobj.crs rs 
					rs.open "select count(0) as rsc from b2c_goods where g_qudao='"&q_id&"' and g_delete=0",dstr,1,1
					if rs("rsc")>0 then
						mobj.drs rs
						act="error"
						eStr=eStr&"<br />该渠道或者该渠道的子渠道下有产品"
					else
						act="ok"
						mobj.drs rs
						mobj.cexe "update b2c_qudao set q_del=1 where q_sn='"&q_id&"' "
						eStr="恭喜！成功删除渠道"
						c_id="0"
					end if 
					
					
				
		end if
end select

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
<title>管理页面</title>
<meta http-equiv="Expires" Content="0"/>
<meta http-equiv="Cache-Control" Content="no-cache"/>
<meta http-equiv="Pragma" Content="no-cache"/>
<link href="/images/skin_1/style.css" type="text/css" rel="stylesheet"/>
<script language=javascript type="text/javascript" src="/calendar/calendar.js"></script>
<script language=javascript type="text/javascript" src="/js/jquery-1.7.1.min.js"></script>
<base target="_self"/>
</head>
<body class="htmlbody">


<table class="table1" cellspacing="1" cellpadding="3" align="center" border="0">
	<tr>
		<td class="tableline linetitle" width="200" align="left">渠道管理</td>
		<td class="tableline" width="*" align="right"><a href="admin_goods.asp">频道首页</a>
			 - <a href="admin_goods_add.asp?act=add">添加商品</a>
			 - <a href="admin_goods_list.asp?ChannelID=1&order=0">商品列表</a>
			 - <a href="admin_goods_cat.asp?act=add">添加渠道</a>
			 - <a href="admin_goods_cat.asp?act=list">渠道管理</a>
             <select onchange="if(this.options[this.selectedIndex].value!=''){location=this.options[this.selectedIndex].value;}">
<option value="admin_goods_list.asp">≡选择详细分类≡</option>
<%
mobj.crs rs
rs.open "select q_id,q_name,q_sn from b2c_qudao  where q_del=0 ",dstr,1,1
do while not rs.eof
%>
<option value="admin_goods_list.asp?qudao=<%=rs("q_sn")%>" <%if qudao=rs("q_sn") then response.Write("selected='selected'")%>><%=rs("q_name")%></option>

<%


rs.movenext
loop
mobj.drs rs
%>

<option value='admin_goods_list.asp'>≡返回全部列表≡</option>
</select>
			
		</td>
	</tr>
</table>
<%
If act="edit" then
%>
<table id="tablehovered1" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
	<tr>
		<th colspan="2">修改渠道</th>
	</tr>
	<form name="myform" method="POST" action="admin_goods_cat.asp">	
	<input type="hidden" name="act" value="save">
   <input name="q_id" type="hidden" value="<%=q_id%>" />
	<tr>
		<td width="19%" align="right" class="tablerow1"><strong>渠道名称：</strong></td>
		<td width="81%" class="tablerow1">
		<input name="q_name" type="text" id="q_name" value="<%=q_name%>" size="35">		</td>
	</tr>
	
	<tr>
		<td align="right" class="tablerow1"><strong>是否启动验证码：</strong></td>
		<td class="tablerow1"><label>
		  <input type="radio" name="q_check" value="1" <%if q_check=1 then response.Write(" checked='checked'")%> />开启验证码</label>
		 <label> <input name="q_check" type="radio" value="0" <%if q_check=0 then response.Write(" checked='checked'")%>  />
		 不开启验证码</label>
		</td>
	</tr>
	<tr>
		<td align="right" class="tablerow1"><strong>产品列表样式：</strong></td>
		<td class="tablerow1"><label>
		  <input name="q_yangshi" type="radio" value="1"  <%if q_yangshi=1 then response.Write(" checked='checked'")%>  />
		  单选样式</label>
		 <label> <input name="q_yangshi" type="radio" value="0" <%if q_yangshi=0 then response.Write(" checked='checked'")%>  />
		 下拉列表样式</label>
		</td>
	</tr>
	<tr>
		<td align="right" class="tablerow1"><strong>相同IP每天最多订单数：</strong></td>
	  <td class="tablerow1"><label>
	    <input name="q_max" type="text" id="q_max" value="<%=q_max%>" size="10" />
	    “0”表示无限制，请慎用此功能，遇到恶意下单可以开启。
	  </label></td>
	</tr><tr>
		<td align="right" class="tablerow1"><strong>渠道描述：</strong></td>
		<td class="tablerow1"><textarea name="q_note" cols="80" rows="4" id="q_note"><%=q_note%></textarea></td>
	</tr>
	<tr>
		<td class="tablerow1">&nbsp;</td>
		<td align="left" class="tablerow1">
		<p align="left"><input type="button" onclick="javascript:history.go(-1)" value="返回上一页" name="B1" class=button>&nbsp;&nbsp;
		<input type="submit" value="保存设置" name="B2" class="button"></td>
	</tr>
	</form>
</table>
<%
end if
%>

<%
If act="add" then

%>
<table id="tablehovered1" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
	<tr>
		<th colspan="2">添加渠道</th>
	</tr>
	<form name="myform" method="POST" action="admin_goods_cat.asp">	
	<input type="hidden" name="act" value="save">
   
	<tr>
		<td width="19%" align="right" class="tablerow1"><strong>渠道名称：</strong></td>
		<td width="81%" class="tablerow1">
		<input type="text" name="q_name" id="q_name" size="35">		</td>
	</tr>
	
	<tr>
		<td align="right" class="tablerow1"><strong>是否启动验证码：</strong></td>
		<td class="tablerow1"><label>
		  <input type="radio" name="q_check" value="1" />开启验证码</label>
		 <label> <input name="q_check" type="radio" value="0" checked="checked" />
		 不开启验证码</label>
		</td>
	</tr>
	<tr>
		<td align="right" class="tablerow1"><strong>产品列表样式：</strong></td>
		<td class="tablerow1"><label>
		  <input name="q_yangshi" type="radio" value="1" checked="checked" />
		  单选样式</label>
		 <label> <input name="q_yangshi" type="radio" value="0" />
		 下拉列表样式</label>
		</td>
	</tr>
	<tr>
		<td align="right" class="tablerow1"><strong>相同IP每天最多订单数：</strong></td>
	  <td class="tablerow1"><label>
	    <input name="q_max" type="text" id="q_max" value="0" size="10" />
	    “0”表示无限制，请慎用此功能，遇到恶意下单可以开启。
	  </label></td>
	</tr><tr>
		<td align="right" class="tablerow1"><strong>渠道描述：</strong></td>
		<td class="tablerow1"><textarea name="q_note" cols="80" rows="4" id="q_note"></textarea></td>
	</tr>
	<tr>
		<td class="tablerow1">&nbsp;</td>
		<td align="left" class="tablerow1">
		<p align="left"><input type="button" onclick="javascript:history.go(-1)" value="返回上一页" name="B1" class=button>&nbsp;&nbsp;
		<input type="submit" value="保存设置" name="B2" class="button"></td>
	</tr>
	</form>
</table>
<%
end if
%>

<%If act="list" then%>
<table id="tablehovered" align="center" class="tableborder" cellspacing="1" cellpadding="2"> <tr> <th noWrap width="8%">序号ID</th> <th width="22%">渠道名称</th> 
<th width="32%" align="center">识别KEY</th> 
<th noWrap width="38%">管理选项</th>
</tr>
<%
Dim kkk:kkk=1
dim rs2
Dim thisIndex:thisIndex=1
mobj.crs rs
rs.open "select q_id,q_sn,q_name,q_check,q_max from b2c_qudao where q_del=0",dstr,1,1
do while not rs.eof
%>
 <tr> <td class="tablerow<%=kkk%> hovered"><%=thisIndex%></td> <td class="tablerow<%=kkk%> hovered"> <b><%=rs("q_name")%></b> </td>
 <td class="tablerow<%=kkk%> hovered" align="center"><%=rs("q_sn")%></td>
 <td align="center" class="tablerow<%=kkk%> hovered"><a href="?act=edit&editid=<%=rs("q_sn")%>">编辑渠道</a> | <a href="?act=del&q_id=<%=rs("q_sn")%>" onclick="return confirm('确定删除吗?')"> 删除渠道</a> | <a href="admin_goods_add.asp?act=add&q_sn=<%=rs("q_sn")%>">添加产品</a> | <a href="admin_goods_list.asp?qudao=<%=rs("q_sn")%>">查看渠道产品</a></td>
</tr>

<%
if kkk=2 then kkk=0	
kkk=kkk+1
thisIndex=thisIndex+1
rs.movenext
loop
mobj.drs rs
%>
 <tr><td colspan="4" class="tablerow1">&nbsp;</td></tr></form></table>
<%end if%>
<%if act="error" then%>
<table align="center" border="0" cellpadding="3" cellspacing="1" class="table2">
    <tr> 
      <th colspan="2" align="left"> 错误提示信息!</th>
    </tr>
  <tr><td align="center" width="20%" class="tableline1"><img src="/images/err.gif" width="95" height="97" border="0"></td><td width="80%" class="tableline1"> <b style="color:blue">产生错误的可能原因：</b><br><%=eStr%></td></tr>
  <tr><td colspan="2" align="center" height="25" class="tableline2"><a href="javascript:history.go(-1)">返回上一页...</a></td></tr>
</table><p>&nbsp;</p>
<%end if%>
<%if act="ok" then%>
<table align="center" border="0" cellpadding="3" cellspacing="1" class="table2">
    <tr> 
      <th colspan="2" align="left"> 成功提示信息!</th>
    </tr>
  <tr><td align="center" width="20%" class="tableline1"><img src="/images/suc.gif" width="95" height="97" border="0"></td><td width="80%" class="tableline1"> <b style="color:blue"><%=eStr%>。</b></td></tr>
  <tr><td colspan="2" align="center" height="25" class="tableline2">
  
  <a href="admin_goods_cat.asp?act=edit&editid=<%=q_id%>">返回修改</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
  
  <a href="admin_goods_add.asp?act=add&q_sn=<%=q_id%>">添加产品</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  
  
   
  <a href="admin_goods_cat.asp?act=add">继续新增渠道</a>
  
  
  </td></tr>
</table><p>&nbsp;</p>

<%end if%>
<!--#include file="end.asp"--></body></html>