<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%Option Explicit%>
<!--#include file="../../Conn.asp"-->
<!--#include file="../../HSK_Cls/HSK.MemberCls.asp"-->
<!--#include file="../../HSK_Cls/HSK.EscapeCls.asp"-->
<!--#include file="../../HSK_Cls/ConvertToSimple.asp"-->
<!--#include file="../../Task/TaskFunction.asp"-->
<%
'****************************************************
' 目前应用于发布任务页面AJAX
' 最后更新日期：2013-7-30
'****************************************************
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 Ajax_Check
HSKCls.Run()
Set HSKCls = Nothing

Class Ajax_Check
        Private KS, KSUser
        Private Sub Class_Initialize()
            Set KS = New PublicCls
            Set KSUser = New UserCls
        End Sub
        Private Sub Class_Terminate()
            Set KS = Nothing
            Set KSUser = Nothing
        End Sub
        Public Sub Run()
          If KS.CheckOuterUrl() Then
              KS.Die escape("err|请不要非法提交！")
          End If
          If CBool(KSUser.UserLoginChecked) = False Then
              KS.Die escape("err|请登录再操作！")
          End If
          Select Case KS.S("Action")
            Case "checkshopname"    Call CheckShopName()
            Case "checkusername"    Call CheckUserName()
            Case "getfield"         Call GetField()
            Case "gettitle"         Call GetTitle()
          End Select
        End Sub
        
        Sub GetField()  '获取会员表的某字段 暂时没用到或删除
            Dim username: username = Left(KS.DelSQL(UnEscape(Request("UserName"))),30)
            Dim fieldname: fieldname = Left(KS.S("fieldname"),20)
            If username = "" Then
                KS.Echo escape("err|请输入会员名！")
                Exit Sub
            End If
            If fieldname = "" Then
                KS.Echo escape("err|字段名不能为空！")
                Exit Sub
            End If
            Dim rs: Set rs = conn.Execute("Select top 1 " & fieldname & " From KS_User where username='" & username & "'")
            If Not rs.EOF Then
                KS.Echo escape("ok|" & rs(0))
            Else
                KS.Echo escape("err|没找到该字段值！")
            End If
            Set rs = Nothing
        End Sub
        
        Sub CheckUserName()
            Dim username: username = Left(KS.DelSQL(UnEscape(Request("UserName"))),30)
            If KS.IsNul(username) Then
                KS.Echo escape("err|请输入对方用户名！如果不指定接手人请留空即可。")
            ElseIf KSUser.UserName = Trim(username) Then
                KS.Echo escape("err|不能指定自己接手！请输入其他会员账号名。")				
            ElseIf InStr(username, "=") > 0 Or InStr(username, ".") > 0 Or InStr(username, "%") > 0 Or InStr(username, Chr(32)) > 0 Or InStr(username, "?") > 0 Or InStr(username, "&") > 0 Or InStr(username, ";") > 0 Or InStr(username, ",") > 0 Or InStr(username, "'") > 0 Or InStr(username, ",") > 0 Or InStr(username, Chr(34)) > 0 Or InStr(username, Chr(9)) > 0 Or InStr(username, "") > 0 Or InStr(username, "$") > 0 Or InStr(username, "*") Or InStr(username, "|") Or InStr(username, """") > 0 Then
                KS.Echo escape("err|用户名中含有非法字符!")
            ElseIf KS.StrLength(username) < KS.ChkClng(KS.Setting(29)) Or KS.StrLength(username) > KS.ChkClng(KS.Setting(30)) Then
                KS.Echo escape("err|输入的会员名长度应为<font color=#ff6600>" & KS.Setting(29) & "-" & KS.Setting(30) & "位</font>！")
            ElseIf KS.FoundInArr(KS.Setting(31), username, "|") = True Then
                KS.Echo escape("err|您输入的用户名为系统禁止注册的用户名</font>！")
            ElseIf Not conn.Execute("Select top 1 Userid From KS_User where username='" & username & "'").EOF Then
                KS.Echo escape("ok|该用户存在，输入正确！")
            Else
                KS.Echo escape("err|系统不存在此用户名！")
            End If
        End Sub
        
        Sub CheckShopName()
            Dim ClassID: ClassID = Request("ClassID")
            Dim ShopName: ShopName = Trim(UnEscape(Request("ShopName")))
            If KS.IsNul(ClassID) Then KS.Die escape("err|请选择任务区！")
            If KS.IsNul(ShopName) Then KS.Die escape("err|请选择掌柜号！")
            If KS.IsNul(Trim(Request("Url"))) Then KS.Die escape("err|请输入商品地址！")
            Dim Url: Url = Split(Trim(Request("Url")), "||")
            Dim Content, i, k, Flag, SiteName, Pattern, tmpShopNameArr, isHongkong
            isHongkong = 0
            If ClassID = "20100598989251" Then
                SiteName = "taobao.com"
                Pattern = "<span class=""J_WangWang.*?data-nick=""(.*?)"""
            ElseIf ClassID = "20104912544927" Then
                SiteName = "paipai.com"
                Pattern = "<img.*?src=""http:\/\/wpa\.paipai\.com\/pa\?p=1:(\w+):1[67]"""
            End If
            For i = 0 To UBound(Url)
                If Not KS.IsNul(Trim(Url(i))) Then
                    If InStr(Url(i), "#") > 0 Then
                        Url(i) = Left(Url(i), InStr(Url(i), "#") - 1)
                    End If
                    Flag = False
                    Content = GetHttpPage(Trim(Url(i)), "gb2312")
                    If InStr(Content, SiteName) = 0 Then Content = GetHttpPage(Trim(Url(i)), "gb2312")
                    If ClassID = "20100598989251" Then
                        '默认不启用过滤二手闲置宝贝，如需要过滤，请把下面三行前面的'单引号去掉即可
                        'If KS.reTest(Content, "<span>.*?：<\/span><em>二手<\/em>") = True Then
                        '    KS.Die escape("err|抱歉！不可以发布二手闲置宝贝，请核实后再提交！商品地址：" & Url(i))
                        'End If
                        If isHongkong = 0 Then isHongkong = InStr(Content, "淘寶")
                    End If
                    Content = KS.reReplace(Content, Pattern, 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 KS.Die escape("err|抱歉！不可以发布非“" & ShopName & "”店铺的商品地址：" & Url(i))
                    Else
                        KS.Die escape("err|抱歉！该商品已下架或商品地址有误无法通过检验，请核实后再提交！商品地址：" & Url(i))
                    End If
                End If
            Next
            If Flag = True Then
                KS.Die escape("ok|true")
            Else
                KS.Die escape("err|发布检验失败，请确认填写的商品地址无误再重新提交！")
            End If
        End Sub

        Sub GetTitle()
            Dim ClassID: ClassID = KS.S("ClassID")
            If KS.IsNul(Trim(KS.S("Url"))) Then KS.Die escape("err|请输入商品地址！")
            Dim Url: Url = Trim(Split(KS.S("Url"), "||")(0))    '只获取第一个地址标题
            Dim Content, SiteName, Pattern, isHongkong
            If ClassID = "20100598989251" Then
                SiteName = "taobao.com"
                Pattern = "<title>(.*?)((-tmall.com天猫)|(-淘宝网)|( - 淘宝网))<\/title>"
            ElseIf ClassID = "20104912544927" Then
                SiteName = "paipai.com"
                Pattern = "<title>(.*?)-.*?((拍拍网)|(| QQ网购-品质购物 精致有趣))<\/title>"
            End If
            If Not KS.IsNul(Url) Then
                If InStr(Url, "#") > 0 Then
                    Url = Left(Url, InStr(Url, "#") - 1)
                End If
                Content = GetHttpPage(Url, "gb2312")
                If InStr(Content, SiteName) = 0 Then Content = GetHttpPage(Url, "gb2312")
                If ClassID = "20100598989251" Then
                    isHongkong = InStr(Content, "淘寶")
                Else
                    isHongkong = 0
                End If
                Content = KS.reReplace(Content, "(<title>.*?<\/title>)", 1, "")
                If Not KS.IsNul(Content) Then
                    Content = KS.reReplace(Split(ConvertToSimple(Content, isHongkong), vbCrlf)(0), Pattern, 1, "")
                    KS.Die escape("ok|^_^|" & Split(Content, vbCrLf)(0))
                Else
                    KS.Die escape("err|^_^|获取标题失败！")
                End If
            End If
        End Sub

End Class
%>