Subversion Repositories DevTools

Rev

Rev 6953 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<%@LANGUAGE="VBSCRIPT"%>
<%
'=====================================================
'   rep_new_versions_json.asp
'   Ajax support for various operations
'       getData
'
'=====================================================
%>
<%
Option explicit
' Essential to get UTF through all the hoops. ie: VÄSTTRAFIK (VTK)
Response.ContentType = "text/html"
Response.AddHeader "Content-Type", "text/html;charset=UTF-8"
Response.CodePage = 65001
Response.CharSet = "UTF-8"
%>
<!--#include file="common/conf.asp"-->
<!--#include file="common/globals.asp"-->
<!--#include file="common/qstr.asp"-->
<!--#include file="common/common_subs.asp"-->
<!--#include file="_access_control_general.asp"-->
<SCRIPT LANGUAGE="VBScript" RUNAT=SERVER SRC="class/classaspJSON.vbs"></SCRIPT> 
<%
'------------ Variable Definition -------------
Dim parOpr, parRtagId
Dim result
Dim SqlQry
Dim rsQry

parOpr = QStrPar("action")
parRtagId = QStrPar("rtag_id")
result = -1

' Init the output JSON class
'   Operations can add data
'   Default data will be added at the end
Dim oJSON
Set oJSON = New aspJSON
Dim newitem

'   
'   Perform the body of the operations within a Sub and use
'   On Error Resule Next to catch errors that accur in the code
'
On Error Resume Next
If (parOpr = "getData") Then
    getData

Else
    oJSON.data("error") = 1
    oJSON.data("emsgSummary") = "Unknown JSON Operation"
    oJSON.data("emsgDetails") = "The Requested JSON operation is not supported: " & parOpr
End If


' SQL error detection and reporting
If objEH.LastOraFailed Then
    oJSON.data("error") = 1
    result = -1

    oJSON.data("emsgSummary") = objEH.MessageSummary
    oJSON.data("emsgDetails") = objEH.MessageDetails
    oJSON.data("SqlQry") = SqlQry
'
'   Detect program errors
ElseIf Err.number <> 0 Then
    result = -3
    oJSON.data("error") = 2
    oJSON.data("errnum") = Err.number
    oJSON.data("errtxt") = Err.description
    oJSON.data("errsrc") = Err.source
    oJSON.data("emsgSummary") = "Internal VBScript Error:" & Err.number &  ":" & Err.description
End If
On error goto 0
'Write single value
oJSON.data("result") = result

'function Sleep(seconds)
'    dim oshell, cmd
'    set oShell = CreateObject("Wscript.Shell")
'    cmd = "cmd.exe /c timeout " & seconds & " /nobreak"
'    oShell.Run cmd,0,1
'End function
'
'Sleep(2)


' DEBUG: A Hash of the user provided requests
<!--oJSON.data("QueryString") = Request.QueryString       -->
<!--                                                      -->
<!--Dim requestSet : Set requestSet = oJSON.Collection()  -->
<!--Set oJSON.data("Request") = requestSet                -->
<!--Dim variableName                                      -->
<!--for each variableName in Request.QueryString          -->
<!--    requestSet.add variableName, Request(variableName)-->
<!--next                                                  -->
<!--for each variableName in Request.Form                 -->
<!--    requestSet.add variableName, Request(variableName)-->
<!--next                                                  -->

'Return the object
Response.Write oJSON.JSONoutput()
Set oJSON = Nothing
Call Destroy_All_Objects
%>
<%
'-------------------------------------------------
' Function:    getData
' Description: Get the data for the page - as jason
'              Not used directly by datatables
'              The format is special. Its not a direct result of the sql query
'              Group multiple version-information as an array
'              ie: [ a,b,c,d,e,f, [[ a,b,c],[a,b,c]]
'
Sub getData

    OraDatabase.Parameters.Add "RTAG_ID", parRtagId, ORAPARM_INPUT, ORATYPE_NUMBER

    SqlQry = GetQuery("rep_new_versions.sql")
    objEH.ErrorRedirect = FALSE
    objEH.TryORA ( OraSession )
    On Error Resume Next
    Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )
    objEH.CatchORA ( OraSession )
    On Error GoTo 0

        OraDatabase.Parameters.Remove "RTAG_ID"

    ' Things for oJSON object
    '   Set someVar  = oJSON.Collection()       (Will create an empty collection)
    '   obj(field) = data                       (Will create a hash entry)
    '   newObj = oJSON.AddToCollection( obj )   (Will create an array)

    Dim lastPvid : lastPvid = 0
    Dim extraData
    Dim extraIdx
    Dim pvid
    Set oJSON.data("aaData") = oJSON.Collection()

    While (NOT rsQry.BOF) AND (NOT rsQry.EOF)
        pvid = rsQry("PV_ID") 
        If pvid <> lastPvid Then
            ' This is a new entry
            lastPvid = pvid
            Set newitem = oJSON.AddToCollection(oJSON.data("aaData"))
            newitem(0)= rsQry("PV_ID") 
            newitem(1)= rsQry("VIEW_NAME")
            newitem(2)= rsQry("PKG_ID")
            newitem(3)= rsQry("PKG_NAME")
            newitem(4)= rsQry("PKG_VERSION") 
            newitem(5)= rsQry("V_EXT")
            newitem(6)= rsQry("CREATED_STAMP") 
            newitem(7)= rsQry("NEW_PV_ID")
            newitem(8)= rsQry("NEW_PKG_VERSION")
            newitem(9)= rsQry("NEW_CREATED_STAMP")
            extraIdx = 0

        Else
            ' Additional Data to be added
            '   May need to add an array, before adding entries to the array
            If extraIdx = 0 Then
                Set extraData = oJSON.Collection()
                newitem.Add 10 ,extraData
            End If

            Dim entry: Set entry = oJSON.Collection()
            entry(0)= rsQry("NEW_PV_ID")
            entry(1)= rsQry("NEW_PKG_VERSION")
            entry(2)= rsQry("NEW_CREATED_STAMP")
            extraData.Add extraIdx, entry
            extraIdx = extraIdx + 1
        End If

       rsQry.MoveNext
    Wend

End Sub

%>