Subversion Repositories DevTools

Rev

Go to most recent revision | 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" -->
<%
'------------ 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

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
End If


Dim oJSON
Set oJSON = New aspJSON
Dim newitem

'
'   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()
%>