Private objAPI
Private objCore
Private objXML
Private objUser
Private objStaple
Private objContent
Private objMapping

Private Sub Class_Initialize()
    Set objAPI = New WAPmoAPI
    Set objCore = objAPI.Core
    Set objXML = objCore.XMLParser
    Set objUser = objCore.User
End Sub

Private Sub Class_Terminate()
    Set objUser = Nothing
    Set objXML = Nothing
    Set objCore = Nothing
    Set objAPI = Nothing
End Sub

Public Sub main()
    If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
        Call doPost
    Else
        Call doGet
    End If
End Sub

Private Sub doGet()
    If objCore.CheckStaple() = False Then
        objCore.Redirect "index.asp"
    ElseIf objCore.CheckMapping() = False Then
        objCore.Redirect "index.asp"
    ElseIf objCore.CheckContent() = False Then
        objCore.Redirect "index.asp"
    Else
        Set objStaple = objCore.Staple
        Set objMapping = objCore.Mapping
        Set objContent = ObjCore.Content
        If objStaple.Item("Category") = STAPLE_LINKING Then
            objCore.Redirect objStaple.Item("Content")
        ElseIf objMapping.Item("Category") = STAPLE_LINKING Then
            objCore.Redirect objMapping.Item("Content")
        ElseIf objContent.Item("Category") = CONTENT_LINKING Then
            Call ContentRecord
            objCore.Redirect objContent.Item("Content")
        Else
            Dim strName
            Dim blnParse
            strName = objContent.Item("Templet")
            If strName = "" Then strName = objStaple.Item("ContentTemplet")
            If strName = "" Then strName = getIndexTemplet(4)
            If strName = "" Then
                blnParse = False
            Else
                blnParse = objAPI.Parse(strName)
            End If
            If blnParse = False Then
                objAPI.ParseString "left@@@ContentTitle##0||0||0###000000$$$left@@@Content$$$left@@@MarkerEntry##1$$$left@@@BackStaple##1##$(StapleName)$$$left@@@BackTheme##1##$(ThemeName)$$$left@@@BackHome##1##$(SiteName)"
            End If
            If atol(MyKernel.Config("CacheContent")) <= 0 Then
                MyKernel.Config("CacheContent") = 144000
            End If
            objCore.SetExpires "content", MyKernel.Config("CacheContent"), False, objContent.Item("SeqId"), objStaple.Item("SeqId"), objContent.Item("Intime")
        End If
        Set objContent = Nothing
        Set objMapping = Nothing
        Set objStaple = Nothing
    End If
End Sub

Private Sub doPost()
End Sub

Private Sub ContentRecord()
    Dim strSQL
    Dim lngId
    strSQL = getLimitSQL(1, "SeqId", T_CONTENT_LOG, "ContentId=$(ContentId) AND Intime>=$(Timeval)", "", "")
    strSQL = Replace(strSQL, "$(ContentId)", objContent.Item("SeqId"))
    strSQL = Replace(strSQL, "$(Timeval)", getTime(Date()))
    lngId = atol(getRecord(strSQL))
    If lngId > 0 Then
        strSQL = "UPDATE $(Table) SET Hit=Hit+1,Outime=$(Timeval) WHERE SeqId=$(SeqId)"
        strSQL = Replace(strSQL, "$(SeqId)", lngId)
    Else
        strSQL = "INSERT INTO $(Table) (StapleId,ContentId,Title,Hit,Intime,Outime) SELECT StapleId,SeqId,Title,1,$(Timeval),$(Timeval) FROM $(TableInner) WHERE SeqId=$(SeqId)"
        strSQL = Replace(strSQL, "$(TableInner)", T_CONTENT)
        strSQL = Replace(strSQL, "$(SeqId)", objContent.Item("SeqId"))
    End If
    strSQL = Replace(strSQL, "$(Table)", T_CONTENT_LOG)
    strSQL = Replace(strSQL, "$(Timeval)", getTime(Now()))
    SafeExecute strSQL
    strSQL = "UPDATE $(Table) SET Hit=Hit+1 WHERE SeqId=$(SeqId)"
    strSQL = Replace(strSQL, "$(Table)", T_CONTENT)
    strSQL = Replace(strSQL, "$(SeqId)", objContent.Item("SeqId"))
    SafeExecute strSQL
    UserRecordX "C"
End Sub

Public Sub UserRecordX(ByVal c)
    Dim strSQL
    Dim lngId
    strSQL = getLimitSQL(1, "SeqId", T_USER_LOG, "UserId=$(UserId) AND Intime>=$(Timeval)", "", "")
    strSQL = Replace(strSQL, "$(UserId)", objUser.Item("UserId"))
    strSQL = Replace(strSQL, "$(Timeval)", getTime(Date()))
    lngId = atol(getRecord(strSQL))
    If lngId > 0 Then
        strSQL = "UPDATE $(Table) SET $(Char)Hit=$(Char)Hit+1,Outime=$(Timeval) WHERE SeqId=$(SeqId)"
        strSQL = Replace(strSQL, "$(Char)", c)
        strSQL = Replace(strSQL, "$(SeqId)", lngId)
    Else
        strSQL = "INSERT INTO $(Table) (UserId,SHit,CHit,VHit,DHit,Intime,Outime) VALUES ($(UserId),$(SHit),$(CHit),$(VHit),$(DHit),$(Timeval),$(Timeval))"
        strSQL = Replace(strSQL, "$(UserId)", objUser.Item("UserId"))
        strSQL = Replace(strSQL, "$(SHit)", IIf(c = "S", 1, 0))
        strSQL = Replace(strSQL, "$(CHit)", IIf(c = "C", 1, 0))
        strSQL = Replace(strSQL, "$(VHit)", IIf(c = "V", 1, 0))
        strSQL = Replace(strSQL, "$(DHit)", IIf(c = "D", 1, 0))
    End If
    strSQL = Replace(strSQL, "$(Table)", T_USER_LOG)
    strSQL = Replace(strSQL, "$(Timeval)", getTime(Now()))
    SafeExecute strSQL
End Sub
