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

Class FlowManage
	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	'只显示前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 DoPause()	'暂停任务
		Dim Rs
		Dim Num
		Num = KS.ChkClng(KS.S("V"))
		Set Rs = Conn.Execute("Select Top 1 ID From Flow Where Inputer='" & KSUser.UserName & "' And ID=" & ID)
		If Not Rs.Eof Then
			Conn.Execute("UPDate Flow Set PauseTF=" & Num & " Where ID=" & ID)
			If Num = 1 Then
				KS.AlertHintScript "任务暂停成功！"
			Else
				KS.AlertHintScript "任务开启成功！"
			End If
		Else
			KS.AlertHintScript "抱歉！找不到该任务，请检查任务是否已删除！"
		End If
		Set Rs = Nothing
	End Sub
	
	Sub DoDel()		'删除任务
		Dim Rs,Total_Point
		Set Rs = Conn.Execute("Select Top 1 * From Flow Where Inputer='" & KSUser.UserName & "' And ID=" & ID)
		If Not Rs.Eof Then
			Total_Point = Round((Rs("TotalCount") - Rs("CompleteCount")) * Client_Flow_PricePoint, 2)
			Call KS.FlowPointInOrOut(FlowChannelID,Rs("ID"),KSUser.UserName,1,Round(Total_Point * Client_Flow_DelTaskReturnPoint, 2),"系统","删除流量任务退还流量点，编号：" & Rs("TaskID"),1)

			Call KS.Profit(FlowChannelID,Rs("ID"),KSUser.UserName,2,0,0,Round(Total_Point * (1 - Client_Flow_DelTaskReturnPoint), 2),Total_Point,"删除流量任务获得手续费,任务编号：" & Rs("TaskID"))	'写入利润记录
			Total_Point = Total_Point \ 100
			'减去发布时的积分+1
		 	If Split(Client_Flow_ScoreSystem_AddTaskScore,"|")(0) = 1 Then
				If KS.ChkClng(KSUser.GroupID) <> UserGroupVipID Then
					IF Total_Point > Split(Client_Flow_ScoreSystem_AddTaskScore,"|")(1) Then Total_Point = Split(Client_Flow_ScoreSystem_AddTaskScore,"|")(1)		'最高一次扣20积分
				Else
					Total_Point = Total_Point * Split(Client_Flow_ScoreSystem_AddTaskScore,"|")(2)				'VIP双倍积分
					IF Total_Point > Split(Client_Flow_ScoreSystem_AddTaskScore,"|")(3) Then	Total_Point = Split(Client_Flow_ScoreSystem_AddTaskScore,"|")(3)		'VIP最高一次扣50积分
				End IF
				Total_Point = Total_Point + Split(Client_Flow_ScoreSystem_AddTaskScore,"|")(4)		'额外加扣积分
				Call KS.ScoreInOrOut(KSUser.UserName,2,Cint(Total_Point),"系统","删除任务扣除的积分",CollectChannelID,Rs("ID"))
			End If
			Conn.Execute("Delete From Flow Where Inputer='" & KSUser.UserName & "' And ID=" & ID)
			Conn.Execute("UPDate KS_User Set KS_FaBuFlowCount = KS_FaBuFlowCount - 1 Where UserName='" & KSUser.UserName & "'")
			KS.AlertHintScript "流量任务删除成功！流量点已退回您账号下，请查收！"
		Else
			KS.AlertHintScript "抱歉！找不到此任务，请联系管理员！"
		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_Flow_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 "Del"
								Call DoDel()
					Case "Pause"
								Call DoPause()
					Case Else
								Call FaMain()
			End Select
		ElseIf Action = "Jie" Then
			Call JieMain()
		Else
			Call FaMain()
		End IF
		
	End Sub


Sub JieMain()
%>
<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>
<script type="text/javascript" src="/HSK_JS/HSK.box.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;
document.oncontextmenu = new Function("return false;");
document.onselectstart= new Function("return false;");
// -->
</SCRIPT>
<div class="wrap">
	<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 class="active" href="FlowManage.asp?Action=Jie">已接流量</a>
            <a href="AddFlowTask.asp"><font color=red>发布流量任务</font></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="28%" class="rough">商品网址</th>
    <th width="20%" class="rough">发布人</th>
    <th width="" class="rough">浏览时间</th>
    <th width="18" class="rough"></th>
    </tr>
    </table>
<%
	If KS.S("page") <> "" Then
		  CurrPage = CInt(KS.S("page"))
	Else
		  CurrPage = 1
	End If
	
	Set RS=Server.CreateObject("ADODB.RECORDSET")
	RS.Open "Select * From FlowJie Where UserName ='" & KSUser.UserName & "' 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("TaskID")%></td>
          <td width="28%" align="center"><span title="<%=GetNodeText("ProductUrl")%>">**<%=right(GetNodeText("ProductUrl"),10)%></span></td>
          <td width="20%" align="center"><span title="发布人：<%=GetNodeText("Inputer")%>"><%=GetNodeText("Inputer")%></span></td>
          <td width="" align="center"><%=KS.GetTimeFormat(GetNodeText("AddDate"))%></td>
          <td width="18" align="center"><%
		  If GetNodeText("Status") = 1 Then
		  		KS.Echo "<img src=""images/right.gif"" border=0 title=""浏览成功"">"
		  ElseIf GetNodeText("Status") > 1 Then
		  		KS.Echo "<img src=""images/error.gif"" border=0 title=""浏览失败（可能原因：对方网站服务器或网络故障）"">"
		  Else
		  		KS.Echo "&nbsp;"
		  End If
		  %></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>

</body>
</html>
<%
	End Sub
	
Sub FaMain()
%>
<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>
<script type="text/javascript" src="/HSK_JS/HSK.box.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;
document.oncontextmenu = new Function("return false;");
document.onselectstart= new Function("return false;");
// -->
</SCRIPT>
<div class="wrap">
	<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 class="active" href="FlowManage.asp">已发流量</a>
            <a href="FlowManage.asp?Action=Jie">已接流量</a>
            <a href="AddFlowTask.asp"><font color=red>发布流量任务</font></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="16%" class="rough">商品网址</th>
    <th width="16%" class="rough">浏览数量</th>
    <th width="18%" class="rough">发布时间</th>
    <th width="15%" 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
	
	Set RS=Server.CreateObject("ADODB.RECORDSET")
	RS.Open "Select * From Flow Where Inputer ='" & KSUser.UserName & "' 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("TaskID")%></td>
          <td width="16%" align="center"><span title="<%=GetNodeText("ProductUrl")%>">**<%=right(GetNodeText("ProductUrl"),6)%></span></td>
          <td width="16%" align="center"><span class="orange" title="已完成浏览数量"><%=GetNodeText("CompleteCount")%></span> / <span title="总浏览数量"><%=GetNodeText("TotalCount")%></span></td>
          <td width="18%" align="center"><%=KS.GetTimeFormat(GetNodeText("AddDate"))%></td>
          <td width="15%" align="center"><%
		  If KS.ChkClng(GetNodeText("LockTF")) = 1 Then
		  		KS.Echo "<span class=""red"" title=""请联系客服人员解锁"">已被锁定</span>"
		  Else
		  	  If KS.ChkClng(GetNodeText("PauseTF")) = 1 Then
				 KS.Echo "<span class=""red"">已暂停</span>"
			  Else
				  Select Case KS.ChkClng(GetNodeText("Status"))
						Case 0
							KS.Echo "<span class=""blue"">待浏览</span>"
						Case 1
							KS.Echo "<span class=""orange"">进行中</span>"
						Case 2
							KS.Echo "已完成"
				  End Select
			  End If
		  End If
		  %></td>
          <td width="" align="center">
          <%
			If KS.ChkClng(GetNodeText("PauseTF")) = 1 Then
				KS.Echo "<a class=""button_cur"" href=""?Action=Pause&V=0&ID=" & GetNodeText("ID") & """ title=""开始任务"">开</a>"
			Else
				KS.Echo "<a class=""button"" href=""?Action=Pause&V=1&ID=" & GetNodeText("ID") & """ title=""暂停任务"">暂</a>"
			End If
		  %> <a class="button" href="?Action=Del&ID=<%=GetNodeText("ID")%>" onClick="return confirm('您确定要删除吗？\n\n删除该任务将返还您<%=Client_Flow_DelTaskReturnPoint * 100%>%流量点！')" 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>

</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
%>