Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
3892 dpurdie 1
<%@LANGUAGE="VBSCRIPT"%>
2
<%
3
'=====================================================
4
'                  NEW VERSION
5
'       Package Inquiry utilities
6
'       Designed to be called via AJAX and to return
7
'       JSON formatted data to dynamic page
8
'=====================================================
9
%>
10
<%
11
Option explicit
12
' Good idea to set when using redirect
13
Response.Expires = 0   ' always load the page, dont store
14
%>
15
 
16
<!--#include file="common/conf.asp"-->
17
<!--#include file="common/globals.asp"-->
18
<!--#include file="common/formating.asp"-->
19
<!--#include file="common/qstr.asp"-->
20
<!--#include file="common/common_subs.asp"-->
21
<!--#include file="common/common_dbedit.asp"-->
22
<!--#include file="class/classaspJSON.asp" -->
3896 dpurdie 23
<!--#include file="class/classSortHelper.asp"-->
3892 dpurdie 24
<%
25
'------------ ACCESS CONTROL ------------------
26
%>
27
<!--#include file="_access_control_login.asp"-->
28
<!--#include file="_access_control_general.asp"-->
29
<!--#include file="_access_control_project.asp"-->
30
<%
31
'------------ Variable Definition -------------
32
Dim parOpr
33
Dim parPkgName
34
Dim result
35
Dim SqlQry
36
Dim rsQry
37
 
38
parOpr = QStrPar("Opr")
39
parPkgName = Trim(QStrPar("packageName"))
40
result = -1
41
 
3896 dpurdie 42
' Init the output JSON class
43
'   Operations can add data
44
'   Default data will be added at the end
45
Dim oJSON
46
Set oJSON = New aspJSON
47
Dim newitem
48
 
3892 dpurdie 49
If (parOpr = "checkName") Then
50
 
51
    ' Test existance of a package name
52
    ' Returns the PKG_ID of the package or 0
53
    '
54
    result = 0
55
    SqlQry = "SELECT pkg.*" &_
56
         "  FROM packages pkg"&_
57
         " WHERE pkg.pkg_id != 0"&_
58
         "   AND UPPER(pkg.pkg_name) = UPPER('"& parPkgName & "')"
59
 
60
    On Error Resume Next
61
    objEH.ErrorRedirect = FALSE
62
    objEH.TryORA ( OraSession )
63
    Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )
64
    objEH.CatchORA ( OraSession )
65
 
66
    If objEH.Finally Then
67
        If ((NOT rsQry.BOF) AND (NOT rsQry.EOF)) Then
68
            result = rsQry("pkg_id")
69
        End If
70
    End If
71
 
72
    rsQry.Close
73
    Set rsQry = Nothing
74
 
75
ElseIf (parOpr = "checkVer") Then
76
    '
77
    ' Test the existance of a Package-Version
78
    ' Returns the PV_ID of the package-Version or 0
79
    '
80
    result = 0
81
    SqlQry = "select pv.pkg_id, pv.PV_ID" &_
82
         "  FROM packages pkg,"&_
83
         "       package_versions pv"&_
84
         " WHERE pkg.pkg_id = pv.pkg_id"&_
85
         "   AND UPPER(pkg.pkg_name) = UPPER('"& parPkgName & "')" &_
86
         "   AND UPPER(pv.pkg_version) = UPPER('" & QStrPar("Version") & "')"
87
 
88
    On Error Resume Next
89
    objEH.ErrorRedirect = FALSE
90
    objEH.TryORA ( OraSession )
91
    Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )
92
    objEH.CatchORA ( OraSession )
93
 
94
    If objEH.Finally Then
95
        If ((NOT rsQry.BOF) AND (NOT rsQry.EOF)) Then
96
            result = rsQry("PV_ID")
97
        End If
98
    End IF
99
 
100
    rsQry.Close
101
    Set rsQry = Nothing
3896 dpurdie 102
 
103
ElseIf (parOpr = "getVerList") Then
104
    Dim parPkgId
105
    parPkgId = QStrPar("pkg_id")
106
 
107
    result = 0
108
    SqlQry = "select pv_id, pkg_version, dlocked" &_
109
         "  FROM package_versions pv" &_
110
         " WHERE pv.pkg_id = "& parPkgId
111
 
112
    On Error Resume Next
113
    objEH.ErrorRedirect = FALSE
114
    objEH.TryORA ( OraSession )
115
    Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )
116
    objEH.CatchORA ( OraSession )
117
 
118
    If objEH.Finally Then
119
 
120
        oJSON.data("VersionRef") = QStrPar("Ref")
121
        Set oJSON.data("Versions") = oJSON.Collection()
122
 
123
        Dim aVersions
124
        Dim objSortHelper
125
        Dim lastRow, i
126
 
127
	    If rsQry.RecordCount > 0 Then
128
 
129
		    aVersions = rsQry.GetRows()
130
		    lastRow = UBound( aVersions, 2 )
131
 
132
		    Set objSortHelper = New SortHelper
133
 
134
		    ' Sort versions
135
		    Call objSortHelper.VersionSort( aVersions, 0, lastRow, rsQry.FieldIndex("pkg_version") )
136
 
137
		    ' Descending order
138
		    For i = lastRow To 0 Step -1
139
 
140
                Dim vname : vname = aVersions( rsQry.FieldIndex("pkg_version"), i )
141
                Dim pvid : pvid = aVersions( rsQry.FieldIndex("pv_id"), i )
142
                Dim lck : lck = aVersions( rsQry.FieldIndex("dlocked"), i )
143
 
144
                result = result + 1
145
 
146
                Set newitem = oJSON.AddToCollection(oJSON.data("Versions"))
147
                newitem.add "vname", vname
148
                newitem.add "pv_id", pvid
149
                newitem.add "dlocked", lck
150
		    Next
151
		    Set objSortHelper = nothing
152
	    End If
153
    End IF
154
 
155
    rsQry.Close
156
    Set rsQry = Nothing
157
 
3892 dpurdie 158
End If
159
 
160
 
161
'
162
'   Create JSON data for the user
163
'   Important fields
164
'       result
165
'
166
'   Debug fields
167
'       QueryString
168
'       SqlQry
169
'       Request (Array)
170
'
171
'Write single value
172
oJSON.data("result") = result
173
 
174
' SQL error detection and reporting
175
If objEH.LastOraFailed Then
176
    oJSON.data("error") = 1
177
 
178
    oJSON.data("emsgSummary") = objEH.MessageSummary
179
    oJSON.data("emsgDetails") = objEH.MessageDetails
180
    oJSON.data("SqlQry") = SqlQry
181
End If
182
 
183
' DEBUG: An array of the user provided requests
184
oJSON.data("QueryString") = Request.QueryString
185
 
186
Set oJSON.data("Request") = oJSON.Collection()
187
Set newitem = oJSON.AddToCollection(oJSON.data("Request"))
188
Dim variableName
189
for each variableName in Request.QueryString
190
    newitem.add variableName, Request.QueryString(variableName)
191
next
192
 
193
'Return the object
194
Response.Write oJSON.JSONoutput()
195
%>
196
 
197
 
198
 
199