<!--#include file="head.asp"-->
<%Server.ScriptTimeOut = 999999%>

<style>body{background-color: #fff;}</style>

<%
On error resume next 

if trim(SafeRequest("mcode"))<>"" then
call chkmcode(trim(SafeRequest("id")),trim(SafeRequest("mcode")),trim(SafeRequest("yurl")),trim(SafeRequest("ip"))) 
end if

act=SafeRequest("act")
sid=SafeRequest("sid")

if sid<>""then
sql="select aygoodid,aygoodsuoyouid,aygooddlid from aygood where aygoodid="&sid&" and aygoodsuoyouid="&request.Cookies("aynameid")&"" 
rs.open sql,conn,1,1
if not(rs.bof and rs.eof) then
if clng(rs("aygooddlid"))<>0 then call PopErr("代理商品无法添加卡密，请联系代理商")
end if
rs.close
end if

if act="add" then

'rs.open "select kamiku,aynameid from ayname where aynameid="&request.Cookies("aynameid")&"",conn,1,1
'if not(rs.bof and rs.eof) then
'if trim(request.Cookies("kamiku"))<>trim(rs("kamiku")) then call PopErr2("系统数据已更新，请重新登录","/index/exit")
'end if
'rs.close

fangshi=SafeRequestform("fangshi")
shangid=SafeRequestform("shangid")
jiancha=SafeRequestform("jiancha")
if jiancha="" then jiancha=0 

if shangid=0 then call PopErr("请选择有效商品")

sql="select aygoodid,aygoodname from aygood where aygoodid="&clng(shangid)&"" 
rs.open sql,conn,1,1
if not(rs.bof and rs.eof) then
aygoodname=trim(rs("aygoodname"))
end if
rs.close
	
	'suiji=hour(now())&minute(now())&second(now())
	con=SafeRequestform("con")
	if con="" then call PopErr("请填写卡密")
	con=Replace(con,CHR(13), "^^")

	diankastr=split(con,"^^")
	if Ubound(diankastr)>1000 then call PopErr("添加数量最多不超过1000张")
	
	jishu=0
	For dianka=0 To Ubound(diankastr) 
		strka=""
		strmi=0
		kstr=""
		
		kstr=Replace(trim(diankastr(dianka)),CHR(10),"")
		kstr=Replace(trim(kstr),CHR(9)," ")
		kstr=trim(kstr)
		
		if trim(kstr)<>"" then
			kstr=Replace(kstr,"     ","~~")
			kstr=Replace(kstr,"    ","~~")
			kstr=Replace(kstr,"   ","~~")
			kstr=Replace(kstr,"  ","~~")
			kstr=Replace(kstr," ","~~")
		
			mimastr=split(trim(kstr),"~~")
			if Ubound(mimastr)=0 then
			strka=trim(mimastr(0))
			strmi="0"
			elseif Ubound(mimastr)>0 then
			strka=trim(mimastr(0))
			if trim(mimastr(1))<>"" then strmi=trim(mimastr(1))
			end if

	
			if trim(strka)<>"" and jiancha=0 then
			jishu=jishu+1
			conn.Execute("Insert Into "&request.Cookies("kamiku")&"(ayka,aykapass,aykasuoyou,aykagoodid) values('"&strka&"','"&strmi&"','"&clng(request.Cookies("aynameid"))&"','"&shangid&"')")	
			end if
			
			if trim(strka)<>"" and jiancha=1 then
				set rsnum=conn.execute("select count(*) as num from "&request.Cookies("kamiku")&" where ayka='"&strka&"' and aykapass='"&strmi&"' and aykagoodid="&shangid&" and aykayesno=0")
				if cint(rsnum("num"))=0 then 
				jishu=jishu+1	
				conn.Execute("Insert Into "&request.Cookies("kamiku")&"(ayka,aykapass,aykasuoyou,aykagoodid) values('"&strka&"','"&strmi&"','"&request.Cookies("aynameid")&"','"&shangid&"')")
				end if
			end if
	
		end if
	next 


	call logadd(request.Cookies("aynameid"),""&shangid&"@#-加卡"&jishu&"张",3,0)
	call PopErr2("成功添加卡密'"&jishu&"'张",url1&"kucunka?shangid="&shangid&"&cact=cha")







end if
%>

<script type="text/javascript">
function check_add()
{
   if(form1.shangid.value=="0")
   {alert("请选择商品");return false}
   document.form1.tijiao.disabled="disabled";
   document.form1.tijiao.value="提交中,请勿刷新或关闭此页…";
}
</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>

                    	<form action="?act=add" method="post" name="form1" onSubmit="return check_add()">
                        <table class="neitableanquan" width="1080">
                        
           		  		<tr>
                            <td colspan="2" align="center" width="100"  >商品名称</td>
                            <td  >
                             <select name="shangid" id="shangid" class="reginput">
                                   <option value="0">请选择商品</option>
                                  <%
                                  nogood="no"
                                  set rsf=server.CreateObject("adodb.recordset")
                                  sqlf="select * from aykafenlei where aykanamesuoyou="&request.Cookies("aynameid")&" and ayshangjiid=0 and ayfenleidlfid=0 order by aykafenleisx asc" 
                                  rsf.open sqlf,conn,1,1
                                  if rsf.bof and rsf.eof then call PopErr2("请先添加商品分类","fenlei")
                                  do while not rsf.eof
                                  
                                                      sql="select * from aygood where aygoodsuoyouid="&request.Cookies("aynameid")&" and aygoodfl="&rsf("aykafenleiid")&" and aysjgid=0 order by aygoodsx asc" 
                                                      rs.open sql,conn,1,1
                                                      if not(rs.bof and rs.eof) then 
                                                      nogood="yes"
                                                          do while not rs.eof%>
                                                          <option value="<%=rs("aygoodid")%>" 
                                                          <%
                                                          if sid<>"" then
                                                          if clng(sid)=clng(rs("aygoodid")) then response.Write("selected")
                                                          end if%>><%=trim(rsf("aykafenleiname"))%>>><%=rs("aygoodname")%></option>
                                                          <%	
                                                          rs.movenext 
                                                          loop
                                                      else%>
                                                      <option value="0"><%=trim(rsf("aykafenleiname"))%>>>暂无商品</option>
                                                      <%end if
                                                      rs.close
                                  
                                  
                                          set rsf2=server.CreateObject("adodb.recordset")
                                          sqlf2="select * from aykafenlei where aykanamesuoyou="&request.Cookies("aynameid")&" and ayshangjiid="&rsf("aykafenleiid")&" and ayfenleidlfid=0 order by aykafenleisx asc" 
                                          rsf2.open sqlf2,conn,1,1
                                          if not(rsf2.bof and rsf2.eof) then
                                          do while not rsf2.eof
                                  
                                  
                                                      sql="select * from aygood where aygoodsuoyouid="&request.Cookies("aynameid")&" and aygoodfl="&rsf2("aykafenleiid")&" and aysjgid=0 order by aygoodsx asc" 
                                                      rs.open sql,conn,1,1
                                                      if not(rs.bof and rs.eof) then 
                                                      nogood="yes"
                                                          do while not rs.eof%>
                                                          <option value="<%=rs("aygoodid")%>" 
                                                          <%
                                                          if sid<>"" then
                                                          if clng(sid)=clng(rs("aygoodid")) then response.Write("selected")
                                                          end if%>><%=trim(rsf("aykafenleiname"))%>>><%=trim(rsf2("aykafenleiname"))%>>><%=rs("aygoodname")%></option>
                                                          <%	
                                                          rs.movenext 
                                                          loop
                                                      else%>
                                                      <option value="0"><%=trim(rsf("aykafenleiname"))%>>><%=trim(rsf2("aykafenleiname"))%>>>暂无商品</option>
                                                      <%end if
                                                      rs.close
                                                  
                                          rsf2.movenext 
                                          loop	 
                                          end if
                                          rsf2.close
                                          
                                          
                                  rsf.movenext 
                                  loop 
                                  rsf.close
                                  %>
                                  </select>  
                                  <%if nogood="no" then call PopErr2("请先添加商品","goodadd")%> 
                            </td>
                          	<td><div class="regt3" > 请选择卡密所属商品</div></td>
                        </tr>
           		  		<tr>
                            <td colspan="2" align="center"  >添加方式</td>
                            <td  >
<input name="fangshi" id="fangshi" type="radio" onClick="javascript:window.location.href='kaadd?sid=<%=sid%>'" value="0" checked><label for="fangshi" style="cursor:pointer;font-weight:lighter;">使用输入框添加 </label>&nbsp;
<input name="fangshi" id="fangshi2" type="radio" value="1" onClick="javascript:window.location.href='kaaddtxt?sid=<%=sid%>'"><label for="fangshi2" style="cursor:pointer;font-weight:lighter;">使用TXT文件导入</label>
                            </td>
                          	<td><div class="regt3" > 请选择一种添加卡密的方式</div></td>
                        </tr>
           		  		<tr>
                            <td colspan="2" align="center"  >检查重复</td>
                            <td  ><input name="jiancha" type="checkbox" id="jiancha" value="1"> 添加成功后删除重复卡密</td>
                          	<td><div class="regt3"> <span style="color:#F30">卡密成功添加后，将检测并删除该商品下重复卡密，重复卡密只保留最近添加的一条卡密</span></div></td>
                        </tr>
           		  		<tr>
                            <td colspan="2" align="center"  >添加卡密</td>
                            <td colspan="2" height="350"><textarea name="con" cols="150" rows="16" id="con" style=" width:950px;line-height:20px;"></textarea></td>
                       	  </tr>
           		  		<tr>
                            <td colspan="2" align="center"  >&nbsp;</td>
                            <td colspan="2"><input class="logindlreg" type="submit" name="Submit" id="tijiao" value=" 添 加 卡 密 " /></td>
                       	  </tr>

                    </table>
                    </form>
            <!-------------------------------------- 结束 -------------------------------------->
        
        
                                                
                   
            <div class="gexian20"></div>
            <div class="mzsmbox2" style="padding-top:20px;">
			卡密格式1(有卡号也有密码的)：卡号+空格+密码  &nbsp;&nbsp;一行一张卡，如：KAsdf2d3d4dg5d8 &nbsp;MI9876543210 <br>
	  		卡密格式2(有卡号没有密码的)：卡号 一行一张卡，如：KAsdf2d3d4dg5d8 <br>
            注意事项：输入框添加卡密最多一次添加1000张(1000行)，TXT文件上传最多支持1MB。<br>
            </div>
            
           




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



</div>








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


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

</body>
</html>