Subversion Repositories DevTools

Rev

Rev 3892 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<%@LANGUAGE="VBSCRIPT"%>
<%
'=====================================================
'                  NEW VERSION
'       Package Inquiry utilities
'       Designed to be called via AJAX and to return
'       JSON formatted data to dynamic page
'=====================================================
%>
<%
Option explicit
' Good idea to set when using redirect
Response.Expires = 0   ' always load the page, dont store
%>

<!--#include file="common/conf.asp"-->
<!--#include file="common/globals.asp"-->
<!--#include file="common/formating.asp"-->
<!--#include file="common/qstr.asp"-->
<!--#include file="common/common_subs.asp"-->
<!--#include file="common/common_dbedit.asp"-->
<!--#include file="class/classaspJSON.asp" -->
<!--#include file="class/classSortHelper.asp"-->
<%
'------------ ACCESS CONTROL ------------------
%>
<!--#include file="_access_control_login.asp"-->
<!--#include file="_access_control_general.asp"-->
<!--#include file="_access_control_project.asp"-->
<%
'------------ Variable Definition -------------
Dim parOpr
Dim parPkgName
Dim result
Dim SqlQry
Dim rsQry

parOpr = QStrPar("Opr")
parPkgName = Trim(QStrPar("packageName"))
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

If (parOpr = "checkName") Then

    ' Test existance of a package name
    ' Returns the PKG_ID of the package or 0
    '
    result = 0
    SqlQry = "SELECT pkg.*" &_
         "  FROM packages pkg"&_
         " WHERE pkg.pkg_id != 0"&_
         "   AND UPPER(pkg.pkg_name) = UPPER('"& parPkgName & "')"

    On Error Resume Next
    objEH.ErrorRedirect = FALSE
    objEH.TryORA ( OraSession )
    Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )
    objEH.CatchORA ( OraSession )

    If objEH.Finally Then
        If ((NOT rsQry.BOF) AND (NOT rsQry.EOF)) Then
            result = rsQry("pkg_id")
        End If
    End If

    rsQry.Close
    Set rsQry = Nothing

ElseIf (parOpr = "checkVer") Then
    '
    ' Test the existance of a Package-Version
    ' Returns the PV_ID of the package-Version or 0
    '
    result = 0
    SqlQry = "select pv.pkg_id, pv.PV_ID" &_
         "  FROM packages pkg,"&_
         "       package_versions pv"&_
         " WHERE pkg.pkg_id = pv.pkg_id"&_
         "   AND UPPER(pkg.pkg_name) = UPPER('"& parPkgName & "')" &_
         "   AND UPPER(pv.pkg_version) = UPPER('" & QStrPar("Version") & "')"

    On Error Resume Next
    objEH.ErrorRedirect = FALSE
    objEH.TryORA ( OraSession )
    Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )
    objEH.CatchORA ( OraSession )

    If objEH.Finally Then
        If ((NOT rsQry.BOF) AND (NOT rsQry.EOF)) Then
            result = rsQry("PV_ID")
        End If
    End IF

    rsQry.Close
    Set rsQry = Nothing

ElseIf (parOpr = "getVerList") Then
    Dim parPkgId
    parPkgId = QStrPar("pkg_id")

    result = 0
    SqlQry = "select pv_id, pkg_version, dlocked" &_
         "  FROM package_versions pv" &_
         " WHERE pv.pkg_id = "& parPkgId

    On Error Resume Next
    objEH.ErrorRedirect = FALSE
    objEH.TryORA ( OraSession )
    Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )
    objEH.CatchORA ( OraSession )

    If objEH.Finally Then

        oJSON.data("VersionRef") = QStrPar("Ref")
        Set oJSON.data("Versions") = oJSON.Collection()

        Dim aVersions
        Dim objSortHelper
        Dim lastRow, i

            If rsQry.RecordCount > 0 Then

                    aVersions = rsQry.GetRows()
                    lastRow = UBound( aVersions, 2 )

                    Set objSortHelper = New SortHelper

                    ' Sort versions
                    Call objSortHelper.VersionSort( aVersions, 0, lastRow, rsQry.FieldIndex("pkg_version") )

                    ' Descending order
                    For i = lastRow To 0 Step -1

                Dim vname : vname = aVersions( rsQry.FieldIndex("pkg_version"), i )
                Dim pvid : pvid = aVersions( rsQry.FieldIndex("pv_id"), i )
                Dim lck : lck = aVersions( rsQry.FieldIndex("dlocked"), i )

                result = result + 1

                Set newitem = oJSON.AddToCollection(oJSON.data("Versions"))
                newitem.add "vname", vname
                newitem.add "pv_id", pvid
                newitem.add "dlocked", lck
                    Next
                    Set objSortHelper = nothing
            End If
    End IF

    rsQry.Close
    Set rsQry = Nothing

End If


'
'   Create JSON data for the user
'   Important fields
'       result
'
'   Debug fields
'       QueryString
'       SqlQry
'       Request (Array)
'
'Write single value
oJSON.data("result") = result

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

    oJSON.data("emsgSummary") = objEH.MessageSummary
    oJSON.data("emsgDetails") = objEH.MessageDetails
    oJSON.data("SqlQry") = SqlQry
End If

' DEBUG: An array of the user provided requests
oJSON.data("QueryString") = Request.QueryString

Set oJSON.data("Request") = oJSON.Collection()
Set newitem = oJSON.AddToCollection(oJSON.data("Request"))
Dim variableName
for each variableName in Request.QueryString
    newitem.add variableName, Request.QueryString(variableName)
next

'Return the object
Response.Write oJSON.JSONoutput()
%>