<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%option explicit%>
<!--#include file="../Conn.asp"-->
<!--#include file="../Task/TaskConfig.asp"-->
<!--#include file="../HSK_Cls/HSK.MemberCls.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_Flow_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 "AddFlow"
				Call AddFlow()
			Case Else
				Call Main()
		End Select
	End Sub
	
	Sub AddFlow()
		Dim RSObj
		Dim i,Point,ID,TotalNum,Num: Num = 0
		Dim ProductUrl,tmpProductUrl,ViewFlow,tmpViewFlow,FlowPoint,IsIP,Times
		tmpProductUrl = Replace(KS.LoseHtml(KS.S("ProductUrl"))," ","")
		tmpViewFlow = Replace(KS.S("ViewFlow")," ","")
		IsIP = KS.ChkClng(KS.S("IsIP"))
		Times = KS.ChkClng(KS.S("Times"))
		FlowPoint = KS.S("FlowPoint")
		
		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 FlowPoint <= 0 Or KS.IsNul(tmpViewFlow) Or KS.IsNul(tmpProductUrl) Then KS.AlertHistory "系统提示：\n\n您提交的数据有误，请返回核查！","-1"
        
		ProductUrl = Split(tmpProductUrl, ",")
		ViewFlow = Split(tmpViewFlow, ",")
		If Ubound(ProductUrl) <> Ubound(ViewFlow) Then KS.AlertHistory "系统提示：\n\n您提交的数据有误，请返回核查商品网址与浏览次数填写是否对应！","-1"
		For i = 0 To Ubound(ViewFlow)			
			If Not KS.IsNul(ViewFlow(i)) Then
				Num = Num + 1
				Point = Point + Int(ViewFlow(i))
			End If
		Next
		TotalNum = Point
		Point = Round(Point * Client_Flow_PricePoint,4)	'计流量点总价
		If IsIP = 1 And Client_Flow_IPLimitPoint > 0 Then Point = Round(Point + Num * Client_Flow_IPLimitPoint,4)	'判断IP限制扣点
		If Point > Round(KSUser.GetUserInfo("KS_FlowPoint"),4) Then KS.AlertHistory "抱歉！您账号下的流量点不足，请先购买流量点再发布！","-1"
		
		For i = 0 To Ubound(ProductUrl)
			If Not KS.IsNul(ProductUrl(i)) Then
				Set RSObj=Server.CreateObject("Adodb.Recordset")
				RSObj.Open "Select top 1 * From Flow",Conn,1,3
				RSObj.AddNew
				RSObj("TaskID")		= GetTaskID()
				RSObj("Inputer")	= KSUser.UserName
				RSObj("ProductUrl")	= ProductUrl(i)
				RSObj("Point") = Round(Int(ViewFlow(i)) * Client_Flow_PricePoint,2)
				RSObj("TotalPoint") = Round(Int(ViewFlow(i)) * Client_Flow_PricePoint,2)
				If IsIP = 1 And Client_Flow_IPLimitPoint > 0 Then RSObj("TotalPoint") = Round(RSObj("Point") + Client_Flow_IPLimitPoint,2)	'判断IP限制扣点
				If IsIP = 1 Then RSObj("Times") = Times
				RSObj("TotalCount")	= Int(ViewFlow(i))
				RSObj("IntervalMinute") = 1			'默认间隔1分钟
				RSObj("LastReadDate")	= Now
				RSObj("AddDate")	= Now		
				RSObj("UserIP")		= KS.GetIP()
				RSObj("SubTable")	= "FlowJie"		'目前固定接手任务表，以后可考虑增加设分表
				RSObj.Update
				RSObj.MoveLast
				ID = RSObj("ID")
				RSObj.Close				 
				Set RSObj=Nothing
			End If
		Next
		
		Call KS.FlowPointInOrOut(FlowChannelID,ID,KSUser.UserName,2,Point,"系统","您发布了" & Num & "条流量任务，总浏览:" & TotalNum & "次!",0)
		'发布流量任务累计数量+1
		Conn.Execute("UPDate KS_User Set KS_FaBuFlowCount = KS_FaBuFlowCount + " & Num & " Where UserName='" & KSUser.UserName & "'")
		
		'增加好友积分
		If Split(Client_Flow_ScoreSystem_AddTaskScore,"|")(0) = 1 Then
			Point = Point \ 100
			If Point < 1 Then Point = 1
			If KS.ChkClng(KSUser.GroupID) <> UserGroupVipID Then
				IF Point > Split(Client_Flow_ScoreSystem_AddTaskScore,"|")(1) Then Point = Split(Client_Flow_ScoreSystem_AddTaskScore,"|")(1)		'最高一次奖励50积分
			Else
				Point = Point * Split(Client_Flow_ScoreSystem_AddTaskScore,"|")(2)				'VIP双倍积分
				IF Point > Split(Client_Flow_ScoreSystem_AddTaskScore,"|")(3) Then Point = Split(Client_Flow_ScoreSystem_AddTaskScore,"|")(3)		'VIP最高一次奖励100积分
			End IF
			Call KS.ScoreInOrOut(KSUser.UserName,1,Cint(Point),"系统","发布流量任务赠送的积分!",FlowChannelID,ID)
		End If
		
		'增加好友动态
		Call KSUser.AddLog(KSUser.UserName,"发布了" & Num & "条流量任务！",1)
		KS.Die "<script>if (confirm('发布成功！\n\n您还要继续发布吗?')){location.href='AddFlowTask.asp';}else{location.href='FlowManage.asp';}</script>"			
	End Sub
	
	'函数名:GetTaskID
	'作  用:任务单号唯一ID
	Function GetTaskID()
		Dim TableNameStr,ID
		TableNameStr = "Select top 1 ID From Flow 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;
}
// -->
</SCRIPT>
<script type="text/javascript">
String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "")
};
function checkForm(){
	var result = true;
	var urls = document.getElementsByName("ProductUrl");
	var views = document.getElementsByName("ViewFlow");
	var urlPattern = /^http:\/\/([^%\*\/\?]+)\.((taobao)|(tmall))\.com\/((item)|(meal_detail)|(mealDetail))\.htm\?(.*?)id=\d+/i;
	for (var i=0; i<urls.length; i++) {
		if (urls[i].value.trim().length > 0 || views[i].value.trim().length > 0) {
			if (!urlPattern.test(urls[i].value)) {
				alert("商品网址请按以下格式填写：\n\nhttp://item.taobao.com/item.htm?id=xxxxxx\n\nhttp://item.beta.taobao.com/item.htm?id=xxxxxx\n\nhttp://item.taobao.com/item.htm?spm=xxxxxx&id=xxxxxx\n\nhttp://detail.tmall.com/item.htm?id=xxxxxx\n\nhttp://detail.tmall.com/item.htm?spm=xxxxxx&id=xxxxxx");
				urls[i].focus();
				result=false;
				break;
			}
			if (views[i].value < 10) {
				alert("浏览次数请填写大于10的整数");
				views[i].focus();
				result=false;
				break;
			}
		}
	}
	if (result && $("#isIP").checked && $("#times") < 5) {
		alert("IP限制最低值为5");
		$("#times").focus();
		result=false;
	}
	if ($("#FlowPoint").val() > <%=KSUser.GetUserInfo("KS_FlowPoint")%>){
		alert("抱歉！您账号下的流量点不足，请先购买流量点再发布！");
		result=false;
		}
return result;
}

var num = <%=Client_Flow_VIPAllowNum%>;
function addMore() {
	if (num > 2) {	//默认3条起
		var obj = $("#itemlist input[name='ProductUrl']");
		for(var i=1; i<4; i++) {
			var str = obj.length + i + "、<input name='ProductUrl' type='text' class='text' id='ProductUrl' style='width:284px;margin-top:4px;' maxlength='200' /> &nbsp; <input name='ViewFlow' type='text' class='text' id='ViewFlow' style='width:46px; margin-top:4px;' value='' maxlength='5' title='每次浏览需要<%=Client_Flow_PricePoint%>个流量点，最低浏览10次起' onKeyUp='this.value=this.value.replace(/[^0123456789]/g,\"\")'  onafterpaste='this.value=this.value.replace(/[^0123456789]/g,\"\")' onblur='CountFlows()' /><br>";
			$("#itemlist").html($("#itemlist").html() + str);
			num = num - 1;
			if (num <= 2) {
				$('#addimg').hide();
				break;
			}
		}
	}
}

function CountFlows() {
	var views = document.getElementsByName("ViewFlow");
	var f = 0;
	var n = 0;
	for(var i=0; i<views.length; i++) {
		if (parseInt(views[i].value) > 0)
			f = f + parseInt(views[i].value);
			n += 1;
	}
	f = f * <%=Client_Flow_PricePoint%>
	if($("#isIP").checked && <%=Client_Flow_IPLimitPoint%>>0){
		f = f + n * <%=Client_Flow_IPLimitPoint%>;
		}
	$("#FlowPoint").val(f.toFixed(2));
}
</script>
	<ul class="screening">
        <li>
        <span class="TaskType">
            <ul onMouseOver="this.className='ulover'" onMouseOut="this.className=''">
                <ol id="flow"><a onMouseOver="this.className='ol_over'" onMouseOut="this.className=''"><img src="images/flow.gif" align="absmiddle" hspace="4">流量任务</a></ol>
                <ol id="collect"><a href="CollectManage.asp" onMouseOver="this.className='ol_over'" onMouseOut="this.className=''"><img src="images/Favicon.gif" align="absmiddle" hspace="4">收藏任务</a></ol>
            </ul>
        </span>
        <span class="orderSub">
            <a href="FlowManage.asp">已发流量</a>
            <a href="FlowManage.asp?Action=Jie">已接流量</a>
            <a class="active" href="AddFlowTask.asp"><font color=red>发布流量任务</font></a>
        </span>
        </li>
	</ul>
    <div class="t_list" style="overflow:auto;">
        <form name="myForm" method="post" action="" id="myForm" onSubmit="CountFlows();return checkForm();">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td>
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td align="right" width="94%" height="30">商品网址 <span class="orange">(可批量发布,网址和浏览次数为空时忽略该行)</span> 　浏览次数</td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td align="right" id="itemlist">
                  1、<input name="ProductUrl" type="text" class="text" id="ProductUrl" style="width:284px; margin-top:4px;" maxlength="200" /> &nbsp; <input name="ViewFlow" type="text" class="text" id="ViewFlow" style="width:46px; margin-top:4px;" value="100" maxlength="5" title="每次浏览需要<%=Client_Flow_PricePoint%>个流量点，最低浏览10次起" onKeyUp="this.value=this.value.replace(/[^0123456789]/g,'')"  onafterpaste="this.value=this.value.replace(/[^0123456789]/g,'')" onBlur="CountFlows()" /><br>
                  2、<input name="ProductUrl" type="text" class="text" id="ProductUrl" style="width:284px; margin-top:4px;" maxlength="200" /> &nbsp; <input name="ViewFlow" type="text" class="text" id="ViewFlow" style="width:46px; margin-top:4px;" value="" maxlength="5" title="每次浏览需要<%=Client_Flow_PricePoint%>个流量点，最低浏览10次起" onKeyUp="this.value=this.value.replace(/[^0123456789]/g,'')"  onafterpaste="this.value=this.value.replace(/[^0123456789]/g,'')" onBlur="CountFlows()" /><br>
                  </td>
                  <td style="display:<%If KS.ChkClng(KSUser.GroupID) <> 17 And KS.ChkClng(KSUser.GroupID) <> 1 Then KS.Echo "none"%>" valign="bottom" align="center" id="addimg"><a href="javascript:addMore()" title="增加更多"><img src="/style/images/add.gif" align="absmiddle"></a></td>
                </tr>
                </table>
              </td>
            </tr>
            <tr>
              <td height="28" align="center">所需流量点：&nbsp;<input name="FlowPoint" type="text" class="text" id="FlowPoint" style="width:100px" value="" readonly /> &nbsp;<span class="orange">您的剩余流量点：<%=KSUser.GetUserInfo("KS_FlowPoint")%> 点</span></td>
            </tr>
            <tr>
              <td height="28" align="center">IP限制：<input name="isIP" type="checkbox" id="isIP" value="1" title="勾上表示启用" />
              限制同IP一天内浏览 <input name="times" type="text" class="text" id="times" style="width:40px" value="10" onKeyUp="this.value=this.value.replace(/[^0123456789]/g,'')"  onafterpaste="this.value=this.value.replace(/[^0123456789]/g,'')" title="每单个任务需额外支付<%=FormatNumber(Client_Flow_IPLimitPoint,1,-1)%>个流量点，系统默认同一IP最大浏览20次" /> 次 <%If Client_Flow_IPLimitPoint>0 Then%>&nbsp;需额外支付<span class="orange"><%=FormatNumber(Client_Flow_IPLimitPoint,1,-1)%></span>个流量点<%End If%></td>
            </tr>
            <tr>
              <td height="40" 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="AddFlow" /></td>
              </tr>			
          </table>
         </form>
     </div>
</body>
</html>
<%
	End Sub
End Class
%>