<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%option explicit%>
<!--#include file="../Conn.asp"-->
<!--#include file="../Task/TaskConfig.asp"-->
<!--#include file="../HSK_Cls/HSK.MemberCls.asp"-->
<!--#include file="Base64.asp"-->
<%
response.cachecontrol="no-cache"
response.addHeader "pragma","no-cache"
response.expires=-1
response.expiresAbsolute=now-1
Response.Charset = "GB2312"
Response.Addheader "Content-Type","text/html; charset=gb2312" 

Dim HSKCls
Set HSKCls = New CollectManage
HSKCls.Run()
Set HSKCls = Nothing

Class CollectManage
	Private KS,KSUser,Action,ID
	Private RS,TopNum,TotalPut,MaxPerPage,CurrPage,XML,Node
	Private Sub Class_Initialize()
		Set KS=New PublicCls
		Set KSUser = New UserCls
		TopNum = 100
		MaxPerPage = 5
		Session(KS.SiteSN&"UserInfo") = Empty
	End Sub
	Private Sub Class_Terminate()
		Call CloseConn()
		Set KS=Nothing
		Set KSUser=Nothing
	End Sub
	
'========================================================================================================================================
	Sub DoSetPassWord()	'设置收藏小号密码
		Dim Rs
		Dim PassWord
		PassWord = left(Request("PassWord"),30)
		If KS.IsNul(PassWord) Then KS.Alert "密码不能为空！", "BindingManage.asp": Exit Sub
		Set Rs = Conn.Execute("Select ShopName From MaiMaiUser Where UserName='" & KSUser.UserName & "' And ID=" & ID)
		If Not Rs.Eof Then
			Conn.Execute("UPDate MaiMaiUser Set SetPassWord='" & Base64e(PassWord) & "' Where ID=" & ID)
			KS.Alert "密码设置成功！", "BindingManage.asp"
		Else
			KS.Alert "抱歉！找不到该小号，请与管理员联系！", "BindingManage.asp"
		End If
		Set Rs = Nothing
	End Sub
	
	Sub DoSetCollect()	'设置是否开启收藏
		Dim Rs
		Dim Num,CurrCredit
		Dim HttpUrl, Content
		Num = KS.ChkClng(KS.S("V"))
		Set Rs = Conn.Execute("Select ShopName,CurrentXinYu,SetPassWord From MaiMaiUser Where UserName='" & KSUser.UserName & "' And ID=" & ID)
		If Not Rs.Eof Then
			If Num = 1 Then
				If KS.IsNul(Rs("SetPassWord")) Then KS.AlertHistory "请先设置收藏小号的密码再开启收藏！","-1": Exit Sub
				Dim tmpContent, HSK: Set HSK = CreateObject("HSK_BinDing.BinDing")
					tmpContent = HSK.GetXinYu(Rs("ShopName"))
				Set HSK=Nothing
				If InStr(tmpContent, "ok|") > 0 Then
					CurrCredit = KS.ChkClng(Split(tmpContent, "|")(1))
					If CurrCredit < 13 Then
						If CurrCredit > Rs("CurrentXinYu") Then
							Conn.Execute("UPDate MaiMaiUser Set CurrentXinYu=" & CurrCredit & " Where ID=" & ID)
						End If
						KS.AlertHintScript "你的小号：" & Rs("ShopName") & " 当前信誉值小于13，不能设为收藏小号！"
					Else
						Conn.Execute("UPDate MaiMaiUser Set CurrentXinYu=" & CurrCredit & ",IsCollect=" & Num & ",UpdateTime=" & SqlNowString & ",UserIP='" & KS.GetIP() & "' Where ID=" & ID)
						KS.AlertHintScript "设为收藏成功！"
					End If
				Else
					KS.AlertHistory "抱歉！获取该小号的信誉值失败！请稍候再试！", "-1"
				End If
			Else
				Conn.Execute("UPDate MaiMaiUser Set IsCollect=" & Num & ",UpdateTime=" & SqlNowString & ",UserIP='" & KS.GetIP() & "' Where ID=" & ID)
				KS.AlertHintScript "取消收藏成功！"
			End If
		Else
			KS.AlertHistory "抱歉！找不到该小号，请与管理员联系！", "-1"
		End If
		Set Rs = Nothing
	End Sub
'========================================================================================================================================
	Public Sub Run()
		If KSUser.UserLoginChecked = False Or KS.IsNul(KS.C("HelperName")) Then
			KS.Die "[结果]尚未登录或登录超时[/结果]"
			Exit Sub
		End If
		If Client_Collect_Enabled <> 1 Then KS.Die "抱歉！收藏任务模块已暂停使用！具体开放时间请留意官网公告！"

		Action = KS.S("Action")
		ID = KS.ChkClng(KS.S("ID"))
		
		IF Not KS.IsNul(Action) And ID > 0 Then
			Select Case Action
					Case "SetCollect"
								Call DoSetCollect()
					Case "SetPassWord"
								Call DoSetPassWord()
					
					Case Else
								Call Main()
			End Select
		Else
			Call Main()
		End IF
		
	End Sub
	
Sub Main()
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>收藏小号管理</title>
<link href="images/css.css" type="text/css" rel="stylesheet"/>
<script type="text/javascript" src="/HSK_JS/jquery.js"></script>

</head>
<body>
<SCRIPT language=JavaScript>
<!--
function click(e) {
	if (document.all) {
		if (event.button==2||event.button==3) {oncontextmenu='return false';}
		if (event.shiftKey) {alert('请不要按住Shift键！');return false;}	
	}
	if (document.layers) {
		if (e.which == 3) {oncontextmenu='return false';}
	}
}
if (document.layers) {document.captureEvents(Event.MOUSEDOWN);}
document.onmouseup=click;
var allowedControls = {'INPUT': 1};
document.oncontextmenu = function(){//屏蔽右键菜单
    allowSelected = 1 == allowedControls[event.srcElement.tagName] ? true : false;
    event.returnValue = allowSelected;
}
document.onselectstart = function() {
	allowSelected = 1 == allowedControls[event.srcElement.tagName] ? true : false;
	event.returnValue = allowSelected;
}
// -->
</SCRIPT>
<script language="javascript" type="text/javascript">
var PassInput='<input type="password" name="Password" id="Password" maxlength="30" class="text" value="" style="width:100px;" title="请填写该小号的淘宝网站登录密码，如密码不对，系统无法收藏！">';
function SeePass(){
	var v=$('#Password').val();
	$('#Pass').html($('#Pass').html().replace(/type=password/i,''));
	$('#Password').attr('value',v);
}
function SetPass(Uid,ShopName,PassWord){
	$('#mask').show();
	$('#setPassword').show();
	$('#UID').val(Uid);
	$('#ShopName').text(ShopName);
	$('#Pass').html(PassInput);
	$('#Password').val(PassWord);
	$('#Password').focus();
	}
function CloseSubWin(){
	$('#setPassword').hide();
	$('#mask').hide();
	}
</script>
<div class="wrap">
	<ul class="screening">
        <li>
        <span class="TaskType">
            <ul onMouseOver="this.className='ulover'" onMouseOut="this.className=''">
                <ol id="collect"><a onMouseOver="this.className='ol_over'" onMouseOut="this.className=''"><img src="images/Favicon.gif" align="absmiddle" hspace="4">收藏任务</a></ol>
                <ol id="flow"><a href="FlowManage.asp" onMouseOver="this.className='ol_over'" onMouseOut="this.className=''"><img src="images/flow.gif" align="absmiddle" hspace="4">流量任务</a></ol>
            </ul>
        </span>
        <span class="orderSub">
        <a href="CollectManage.asp">已发收藏</a>
        <a href="CollectManage.asp?Action=Jie">已接收藏</a>
        <a href="AddCollectTask.asp"><font color=red>发布收藏</font></a>
        <a class="active" href="BindingManage.asp">设置收藏小号</a>
        </span>
        </li>
    </ul>
    <!-- 列表内容 -->
    <div class="t_list">
    <table align="center" style="border-bottom:1px solid #ACDAFF;" border="0" cellSpacing="0" cellPadding="1" height="24" width="100%">
    <tr>
    <th width="20%" class="rough">绑定的小号</th>
    <th width="18%" class="rough">当前信誉值</th>
    <th width="18%" class="rough">今日收藏量</th>
    <th width="22%" class="rough">状态</th>
    <th width="" class="rough">操作</th>
    </tr>
    </table>
<%
	If KS.S("page") <> "" Then
		  CurrPage = CInt(KS.S("page"))
	Else
		  CurrPage = 1
	End If
	
	Dim Tid: Tid = "20100598989251"		'目前只显示淘宝任务
	Dim RS:Set RS=Server.CreateObject("ADODB.RECORDSET")
	RS.Open "Select ID,ShopName,SetPassWord,CurrentXinYu,IsCollect,UpdateTime From MaiMaiUser Where UserName='" & KSUser.UserName & "' And Tid='" & Tid & "' And AccountType=1 And IsDel=0 Order By ID Desc",Conn,1,1
	If Not RS.Eof Then
		TotalPut = RS.RecordCount
		If TotalPut>TopNum And TopNum<>0 Then TotalPut=TopNum
		If CurrPage >1 and (CurrPage - 1) * MaxPerPage < TotalPut Then
			RS.Move (CurrPage - 1) * MaxPerPage
		Else
			CurrPage = 1
		End If
		Set XML=KS.ArrayToXml(RS.GetRows(MaxPerPage),RS,"row","root")
	End If
	RS.Close
	Set RS=Nothing

	If IsObject(XML) Then
%>
    <table class="list_tbl" border="0" cellSpacing="0" cellPadding="4" width="100%">
<%		For Each Node In Xml.DocumentElement.SelectNodes("row") %>
        <tr onMouseOver="this.className='trhover'" onMouseOut="this.className=''">
          <td width="20%" align="center"><%=GetNodeText("ShopName")%></td>
          <td width="18%" align="center"><%=GetNodeText("CurrentXinYu")%></td>
          <td width="18%" align="center"><span title="店铺收藏数量"><%=Conn.Execute("SELECT Count(ID) FROM CollectJie Where UserName= '" & KSUser.UserName & "' And JieShopName = '" & GetNodeText("ShopName") & "' And CollectType = 1 And Status = 1 And DateDiff(d, AddDate, GetDate()) = 0")(0)%></span> / <span title="商品收藏数量"><%=Conn.Execute("SELECT Count(ID) FROM CollectJie Where UserName= '" & KSUser.UserName & "' And JieShopName = '" & GetNodeText("ShopName") & "' And CollectType = 2 And Status = 1 And DateDiff(d, AddDate, GetDate()) = 0")(0)%></span></td>
          <td width="22%" align="center"><%
		  If KS.ChkClng(GetNodeText("IsCollect")) = 1 Then
		  		KS.Echo "<span class=""red"">已设为收藏小号</span>"
		  Else
		  		KS.Echo "&nbsp;"
		  End If
		  %></td>
          <td width="" align="center"><%
			If KS.ChkClng(GetNodeText("IsCollect")) = 1 Then
				KS.Echo "<a class=""button_1_cur"" href=""?Action=SetCollect&V=0&ID=" & GetNodeText("ID") & """ onclick=""return confirm('您确定要取消收藏吗？');"" title=""取消收藏(恢复普通小号)"">关闭</a>"
			Else
				If Not KS.IsNul(GetNodeText("UpdateTime")) Then
					If DateDiff("n", GetNodeText("UpdateTime"), Now) >= 10 Then
						KS.Echo "<a class=""button_1"" href=""?Action=SetCollect&V=1&ID=" & GetNodeText("ID") & """ onclick=""return confirm('您确定要把此号设为收藏小号吗？\n\n确定后会同步淘宝最新信誉值，只有信誉值大于等于13的才可以设为收藏小号！\n\n注：刷收藏的小号不能接手刷信誉的任务！');"" title=""设为收藏小号"">收藏</a>"
					Else
						KS.Echo "<a class=""button_1"" href=""javascript:;"" title=""请间隔10分钟再操作"" disabled>收藏</a>"
					End If
				Else
					KS.Echo "<a class=""button_1"" href=""?Action=SetCollect&V=1&ID=" & GetNodeText("ID") & """ onclick=""return confirm('您确定要把此号设为收藏小号吗？\n\n确定后会同步淘宝最新信誉值，只有信誉值大于等于13的才可以设为收藏小号！\n\n注：刷收藏的小号不能接手刷信誉的任务！');"" title=""设为收藏小号"">收藏</a>"
				End If
			End If
		  %> <a class="button_1" href="javascript:;" onClick="SetPass(<%=GetNodeText("id")%>,'<%=GetNodeText("ShopName")%>','<%=Base64d(GetNodeText("SetPassWord"))%>')" title="设置收藏小号密码">密码</a></td>
        </tr>
	<%	Next  %>
    </table>
<%	Else
		KS.Echo "<div class='border' style='text-align:center'>目前还没有绑定任何小号，请先到官网绑定小号后再回来设置！</div>"
	End If
	Set XML = Nothing
    If Totalput > 5 Then KS.Echo "<div class=""multipage"">" & KS.ShowPage(Totalput, MaxPerPage, "", CurrPage,false,false) & "</div>"
    %>
  </div>
</div>
<!-- 弹出子窗口层 Start -->
<div id="mask" class="mask"></div>
<div id="setPassword" class="panel pop">
     <a href="javascript:;" hidefocus="true" onClick="CloseSubWin();" class="panel pop-close" title="关闭"></a>
     <div class="pop-title">设置收藏小号密码</div>
     <div class="pop-con">
     <table width="100%" border="0" cellspacing="4" cellpadding="2">
      <tr>
        <td width="39%" align="right">收藏小号：</td>
        <td width="61%"><span class="red rough" id="ShopName"></span><input type="hidden" name="UID" id="UID" value="">
        </td>
      </tr>
      <tr>
        <td align="right">淘宝登录密码：</td>
        <td><span id="Pass"></span>&nbsp;<span style="color:red; cursor:pointer;" onClick="SeePass();">看密</span></td>
      </tr>
      <tr>
        <td colspan="2" align="center" height="26" class="orange">注：此登录密码必需是淘宝网站登录密码！</td>
       </tr>
    </table>
     </div>
     <div class="pop-btn-wrap">
         <a href="javascript:window.location.href='?Action=SetPassWord&ID='+ $('#UID').val() +'&PassWord='+ escape($('#Password').val());" onClick="if($('#Password').val()==''){alert('请输入密码！');return false;}" hidefocus="true" class="panel pop-btn">确定</a>
         <a href="javascript:;" hidefocus="true" onClick="CloseSubWin();" class="panel pop-btn">取消</a>
     </div>
</div>
<!-- 弹出子窗口层 End -->
</body>
</html>
<%
	End Sub
	
	'获取XML缓存节点值
	Function GetNodeText(NodeName)
		Dim N,Str
		NodeName = Lcase(NodeName)
		If IsObject(Node) Then
			Set N = Node.SelectSingleNode("@" & NodeName)
			If Not N IS Nothing Then Str = N.text
			GetNodeText=Str
		End If
	End Function
	
End Class
%>