<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%option explicit%>
<!--#include file="../Conn.asp"-->
<!--#include file="../Task/TaskConfig.asp"-->
<!--#include file="../HSK_Cls/HSK.MemberCls.asp"-->
<!--#include file="../HSK_Cls/ConvertToSimple.asp"-->
<!--#include file="../Plus/md5.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 AddCollect
HSKCls.Run()
Set HSKCls = Nothing

Class AddCollect
	Private KS
	Private KSUser,Action
	Private Sub Class_Initialize()
		Set KS=New PublicCls
		Set KSUser = New UserCls
		Session(KS.SiteSN&"UserInfo") = Empty
	End Sub
	
	Private Sub Class_Terminate()
		Call CloseConn()
		Set KS=Nothing
		Set KSUser=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 "抱歉！收藏任务模块已暂停使用！具体开放时间请留意官网公告！"
		
		IF KS.ChkClng(KSUser.GetUserInfo("KS_IDAuthentication")) <> 1 And SMS_IDAuthentication_Enabled = 1 Then
			KS.AlertHistory  "抱歉！\n\n由于您的账号尚未通过手机认证，暂时不能发布收藏任务，请登录官网认证后再来发布。","-1"
		End IF
		If KS.ChkClng(KSUser.GetUserInfo("KS_JinzhiFaBu")) = 1 Then
			KS.AlertHistory "抱歉！\n\n您当前被禁止发布任务，如需解除禁止请联系客服！","-1"
		End IF
		IF TaskAddEnabled = 0 Then Call KS.AlertHistory(TaskAddCloseMsg,"-1")
		
		Action=KS.S("Action")
		Select Case Action
			Case "AddCollect"
				Call AddCollect()
			Case Else
				Call Main()
		End Select
	End Sub
	
	Sub AddCollect()
		Dim i,Point,ID
		Dim ClassID,ShopName,CollectType,ProductUrl,CollectNum,CollectInterval
		ClassID = KS.S("ClassID")
		ShopName= KS.S("ShopName")
		CollectType= KS.ChkClng(KS.S("CollectType"))
		ProductUrl= KS.LoseHtml(KS.S("ProductUrl"))
		CollectNum= KS.ChkClng(KS.S("CollectNum"))
		CollectInterval= KS.ChkClng(KS.S("CollectInterval"))
		
		IF KS.IsNul(Trim(KS.C("SecurityCode"))) Then
			IF Md5(Trim(KS.S("SecurityCode")),16) <> KSUser.GetUserInfo("KS_SecurityCode") Then
				KS.AlertHistory "系统提示：\n\n您输入的安全密码不对!","-1"
			Else
				Response.Cookies(KS.SiteSn)("SecurityCode") = Md5(Trim(KS.S("SecurityCode")),16)
			End IF
		End IF

		If ClassID="" Then
			ClassID="20100598989251"
		End IF
		
		If ShopName="" Then
			KS.Die "<script>alert('请选择掌柜号!');history.back();</script>"
		End IF
		
		If CollectType = 0 Then KS.AlertHistory "系统提示：\n\n请选择收藏类型!","-1"
		
		If CollectNum <= 0 Or CollectInterval <= 0 then
			KS.Die "<script>alert('收藏次数或收藏间隔时间填写有误!');history.back();</script>"
		End If
		
		Select Case ClassID
			Case "20100598989251"
				If CollectType = 2 Then		'商品地址判断
					IF KS.reTest(ProductUrl,"^http:\/\/([^%\*\/\?]+)\.((taobao)|(tmall))\.com\/((item)|(meal_detail)|(mealDetail))\.htm\?(.*?)id=\d+") = False Then
						KS.Die "<script>alert('系统检测到你的商品网址不正确，淘宝商品网址格式应为：\n\nhttp://item.taobao.com/item.htm?id=*********\nhttp://item.beta.taobao.com/item.htm?id=*********\nhttp://item.lp.taobao.com/item.htm?item_id=*********\nhttp://detail.tmall.com/item.htm?id=*********\n\n请在您的淘宝店铺打开商品然后再复制商品网址！');history.back();</script>"
					End IF
				ElseIf CollectType =1 Then
					IF (KS.reTest(ProductUrl,"^http:\/\/([^%\*\/\?]+)\.((taobao)|(tmall))\.com\/?") And Instr(ProductUrl,"id=") > 0) Or (KS.reTest(ProductUrl,"^http:\/\/([^.*]+)\.((taobao)|(tmall))\.com\/?") = False And KS.reTest(ProductUrl,"^http:\/\/store\.taobao\.com\/shop\/view_shop.*?") = False) Then
						KS.Die "<script>alert('系统检测到你的淘宝店铺网址不正确，店铺网址格式应为：\n\nhttp://*******.taobao.com\nhttp://*******.tmall.com\nhttp://store.taobao.com/shop/view_shop*********');history.back();</script>"
					End If
				End If
			Case "20104912544927"
				If CollectType = 2 Then		'商品地址判断
					IF KS.reTest(ProductUrl,"^http:\/\/([^%\*\/\?]+)\.paipai.com\/.*?\w{32}") = False Then
						KS.Die "<script>alert('系统检测到你的商品网址不正确，拍拍商品网址格式应为：\n\nhttp://auction1.paipai.com/xxxxx\n\n请在您的拍拍店铺首页打开商品然后再复制商品网址！');history.back();</script>"
					End IF
				ElseIf CollectType =1 Then
					IF KS.reTest(ProductUrl,"^http:\/\/([^%\*\/\?]+)\.paipai\.com") = False Then
						KS.Die "<script>alert('系统检测到你的拍拍店铺网址不正确，店铺 网址格式应为：\n\nhttp://shop.paipai.com/xxxxx\nhttp://xxxxxxxxx.paipai.com/');history.back();</script>"
					End IF
				End If
			Case "20107602754390"		'有啊，关了
				IF KS.reTest(ProductUrl,"^http:\/\/([^.*]+)\.baidu\.com\/item\/") = False Then
					KS.Die "<script>alert('系统检测到你的商品网址不正确，商品网址格式应为：\n\nhttp://youa.baidu.com/item/xxxxx\n\n请在您的有啊店铺首页打开商品然后再复制商品网址！');history.back();</script>"
				End IF		
		End Select

		Point = Round(CollectNum * Client_Collect_PricePoint, 3)
		If Round(KSUser.GetUserInfo("KS_CollectPoint"),3) < Point Then
			 Call KS.AlertHistory("您账号上的收藏点不够，请到官网购买收藏点再回来发布!","-1")
		End If
		
		Dim Content,tmpShopNameArr,k,Flag: Flag = False
		Content = GetHttpPage(ProductUrl, "gb2312")
		If InStr(Content, "taobao.com") = 0 Then Content = GetHttpPage(ProductUrl, "gb2312")
		Dim isHongkong: isHongkong = InStr(Content, "淘寶")
		Content = KS.reReplace(Content, "<span class=""J_WangWang.*?data-nick=""(.*?)""", 1, "")
		If Not KS.IsNul(Content) Then
			tmpShopNameArr = Split(ConvertToSimple(KS.URLDecode(Content), isHongkong), vbCrLf)
			For k = 0 To UBound(tmpShopNameArr)
				If ShopName = tmpShopNameArr(k) Then
					Flag = True
					Exit For
				End If
			Next
			If Not Flag Then Call KS.AlertHistory("您发布的收藏地址不是掌柜“" & ShopName & "”的店铺地址！请核对后再发布！","-1")
		Else
			Call KS.AlertHistory("抱歉！该商品已下架或商品地址有误无法通过检验，请核实后再提交！","-1")
		End If
		
		Dim RSObj: Set RSObj=Server.CreateObject("Adodb.Recordset")
		RSObj.Open "Select top 1 * From Collect",Conn,1,3
		RSObj.AddNew
		RSObj("TID") 		= ClassID
		RSObj("TaskID")		= GetTaskID()
		RSObj("Inputer")	= KSUser.UserName
		RSObj("ShopName")	= ShopName
		RSObj("CollectType")= CollectType
		RSObj("ProductUrl")	= ProductUrl
		RSObj("Point")		= Point
		RSObj("TotalCount")	= CollectNum
		RSObj("LastReadDate")	= Now
		RSObj("IntervalMinute") = CollectInterval
		RSObj("AddDate")	= Now		
		RSObj("UserIP")		= KS.GetIP()
		RSObj("SubTable")	= "CollectJie"	'目前固定接手任务表，以后可考虑增加设分表
		RSObj.Update
		RSObj.MoveLast
		ID = RSObj("ID")
		RSObj.Close
		Set RSObj=Nothing
		
		Call KS.CollectPointInOrOut(CollectChannelID,ID,KSUser.UserName,ShopName,2,Point,"系统","您发布了1条淘宝收藏任务，收藏:" & CollectNum & "次!",0)
		'发布收藏任务累计数量+1
		Conn.Execute("UPDate KS_User Set KS_FaBuCollectCount = KS_FaBuCollectCount + 1 Where UserName='" & KSUser.UserName & "'")
		
		'增加好友积分
		If Split(Client_Collect_ScoreSystem_AddTaskScore,"|")(0) = 1 Then
			Point = Point \ 10
			If Point < 1 Then Point = 1
			If KS.ChkClng(KSUser.GroupID) <> UserGroupVipID Then
				IF Point > Split(Client_Collect_ScoreSystem_AddTaskScore,"|")(1) Then Point = Split(Client_Collect_ScoreSystem_AddTaskScore,"|")(1)		'最高一次奖励20积分
			Else
				Point = Point * Split(Client_Collect_ScoreSystem_AddTaskScore,"|")(2)				'VIP双倍积分
				IF Point > Split(Client_Collect_ScoreSystem_AddTaskScore,"|")(3) Then Point = Split(Client_Collect_ScoreSystem_AddTaskScore,"|")(3)		'VIP最高一次奖励50积分
			End IF
			Call KS.ScoreInOrOut(KSUser.UserName,1,Cint(Point),"系统","发布淘宝收藏任务赠送的积分!",CollectChannelID,ID)
		End If
		
		'增加好友动态
		Call KSUser.AddLog(KSUser.UserName,"发布了一条淘宝收藏任务！",1)
		KS.Die "<script>if (confirm('发布成功！\n\n您还要继续发布吗?')){location.href='AddCollectTask.asp';}else{location.href='CollectManage.asp';}</script>"		

	End Sub
	
	'函数名:GetTaskID
	'作  用:任务单号唯一ID
	Function GetTaskID()
		Dim TableNameStr,ID
		TableNameStr = "Select top 1 ID From Collect Where TaskID='"
		Do While True
		   ID = right("0" & Month(Now),2) & right("0" & Day(Now),2) & KS.MakeRandom(6)
		   If Conn.Execute(TableNameStr & ID & "'").Eof Then Exit Do
		Loop
		GetTaskID=ID
	End Function

	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 = {'ProductUrl': 1};
document.oncontextmenu = function(){//屏蔽右键菜单
    allowSelected = 1 == allowedControls[event.srcElement.id] ? true : false;
    event.returnValue = allowSelected;
}
document.onselectstart = function() {
	allowSelected = 1 == allowedControls[event.srcElement.id] ? true : false;
	event.returnValue = allowSelected;
}

function checkForm(){
	if ($('#ProductUrl').val()==''){
		alert('请输入收藏地址！');
		$('#ProductUrl').focus();
		return false;
		}
	if ($('#CollectNum').val()=='' || $('#CollectNum').val() < 10){
		alert('请输入大于10的整数！（最低收藏10次起）');
		$('#CollectNum').focus();
		return false;
		}
	if ($('#CollectInterval').val() < 1){
		alert('随机收藏间隔时间不能小于1分钟！');
		$('#CollectInterval').focus();
		return false;
		}
	return true;
}
// -->
</SCRIPT>
	<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 class="active" href="AddCollectTask.asp"><font color=red>发布收藏</font></a>
            <a href="BindingManage.asp">设置收藏小号</a>
        </span>
        </li>
	</ul>
    <div class="t_list">
        <form name="myForm" method="post" action="" id="myForm" onSubmit="return checkForm();">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td align="right"></td>
              <td height="10" align="left"></td>
            </tr>
            <!--
            <tr>
              <td width="38%" align="right">请选择收藏任务区：</td>
              <td width="62%" height="24" align="left">&nbsp;<select name='ClassID' id='ClassID' style='width:100px'>
              <option pubtf='1' Name='淘宝' value='20100598989251'>淘宝任务</option>
              <option pubtf='1' Name='拍拍' value='20104912544927'>京东任务</option></select>
              </td>
            </tr>
            -->
            <tr>
              <td width="29%" align="right">请选择淘宝掌柜：</td>
              <td width="71%" height="24" align="left">&nbsp;
                <%
                Dim RSSN, Tid
                Tid = "20100598989251"	'目前只显示淘宝任务
                Set RSSN=Server.CreateObject("ADODB.RECORDSET")
                RSSN.Open "Select ShopName From MaiMaiUser Where UserName='" & KSUser.UserName & "' And Tid='" & Tid & "' And AccountType=2 And Status<2 And IsDel=0 And IsActivate=1 Order By ID Desc", Conn, 1, 1
                If Not RSSN.Eof Then
                    KS.Echo "<select name='ShopName' class='text' id='ShopName'>"
                  Do While Not(RSSN.Eof)
                    KS.Echo "<option value='" & RSSN("ShopName") & "'>" & RSSN("ShopName") & "</option>" & vbCrlf
                    RSSN.MoveNext
                  loop
                    KS.Echo "</select>"
                Else
                    KS.Echo "<a href='#' class='red'>请先到官网绑定掌柜号再来发布>></a>"
                End If
                RSSN.Close
                Set RSSN=Nothing
                %>
              </td>
            </tr>
            <tr>
              <td align="right">收藏类型：</td>
              <td height="24" align="left">
              <label><input name="CollectType" type="radio" id="CollectType" onClick="$('#MaiNum').html('店铺首页地址');" value='1' checked />店铺收藏</label>&nbsp; 
              <label><input type="radio" name="CollectType" id="CollectType" onClick="$('#MaiNum').html('商品地址');" value='2' />商品收藏</label></td>
            </tr>
            <tr>
              <td align="right"><span id="MaiNum">店铺首页地址</span>：</td>
              <td height="24" align="left">&nbsp;<input name="ProductUrl" type="text" class="text" id="ProductUrl" style="width:250px" maxlength="200" /></td>
            </tr>
            <tr>
              <td align="right">收藏次数：</td>
              <td height="24" align="left">&nbsp;<input name="CollectNum" type="text" class="text" id="CollectNum" style="width:100px" value="100" maxlength="4" title="每个收藏需要<%=Client_Collect_PricePoint%>个收藏点，最低收藏10次起" onKeyUp="this.value=this.value.replace(/[^0123456789]/g,'')"  onafterpaste="this.value=this.value.replace(/[^0123456789]/g,'')" /> <span class="orange">您的剩余收藏点：<%=KSUser.GetUserInfo("KS_CollectPoint")%> 点</span></td>
            </tr>
            <tr>
              <td align="right">收藏间隔时间：</td>
              <td height="24" align="left">&nbsp;<input name="CollectInterval" type="text" class="text" id="CollectInterval" style="width:100px" value="5" maxlength="2" onKeyUp="this.value=this.value.replace(/[^0123456789]/g,'')"  onafterpaste="this.value=this.value.replace(/[^0123456789]/g,'')" title="注：如果您的收藏量大，可缩短间隔时间！" /> 
              分钟之内随机收藏一次</td>
            </tr>
            <tr>
              <td height="40" colspan="2" align="center"><% IF KS.IsNul(KS.R(Trim(KS.C("SecurityCode")))) Then %><strong>安全密码：</strong>&nbsp;<input class="text" style="width:100px;" type="password" id="SecurityCode" maxlength="16" name="SecurityCode" value="" title="安全密码主要用于资金流转、账户安全二层保护作用。&#13;&#10;注：安全密码不是登录密码，只需第一次输入。" />&nbsp; &nbsp; &nbsp;<% End IF %><input type="image" name="Save" src="/style/images/ConfirmButton_2.gif" align="absmiddle" hidefocus="true" /><input type="hidden" name="Action" value="AddCollect" /></td>
              </tr>			
          </table>
         </form>
     </div>
</body>
</html>
<%
	End Sub
End Class
%>