%@LANGUAGE="VBSCRIPT"%>
<%
'=====================================================
'| |
'| Eidt Release Licencing Details |
'| |
'=====================================================
Option explicit
' Good idea to set when using redirect
Response.Expires = 0 ' always load the page, dont store
%>
<%
' Make sure rtag_id is always present
If Request("rtag_id") = "" Then
Call Destroy_All_Objects
Response.Redirect("index.asp")
End If
' Set rfile parameter. This is a return page after Login
Call objPMod.StoreParameter ( "rfile", "dependencies.asp" )
'------------ ACCESS CONTROL ------------------
%>
<%
'------------ Variable Definition -------------
Dim selectedLicence
Dim httpReferer
Dim licenceList
'------------ Constants Declaration -----------
Const available_licences_query_string = " SELECT * from licences ORDER BY UPPER(name) "
'------------ Variable Init -------------------
httpReferer = "dependencies.asp?rtag_id="& CStr(parRtag_Id)
' Obtain selected licence from parameter list in the URL. If none given, set the default initial
' value to -1 to initiate its selection during html page rendering
selectedLicence = Request("selected_licence")
If (IsNull(selectedLicence) OR selectedLicence = "") Then
selectedLicence = -1
End If
'--------------------------------------------------------------------------------------------------------------------------
' release_licencing_query_string
'
' DESCRIPTION
' Constructs a query string using the provided release tag, designed to elicit
' a list of PV_ID's, thier package names, versions and extensions, from the
' release
'
' INPUTS
' NNrtag_id : The release tag to be used in the query string
'
Function release_licencing_query_string(NNrtag_id)
release_licencing_query_string = "SELECT * FROM ("&_
" SELECT pv.pv_id, pkg.pkg_name, pv.pkg_version, pv.v_ext"&_
" FROM release_content rc, package_versions pv, packages pkg "&_
" WHERE rc.rtag_id = "& CStr(NNrtag_id) &_
" AND pv.pv_id = rc.pv_id "&_
" AND pkg.pkg_id = pv.pkg_id "&_
" UNION "&_
" SELECT pv.pv_id, pkg.pkg_name, pv.pkg_version, pv.v_ext"&_
" FROM work_in_progress wip, package_versions pv, packages pkg "&_
" WHERE wip.rtag_id = "& CStr(NNrtag_id) &_
" AND pv.pv_id = wip.pv_id "&_
" AND pkg.pkg_id = pv.pkg_id "&_
" UNION "&_
" SELECT pv.pv_id, pkg.pkg_name, pv.pkg_version, pv.v_ext"&_
" FROM planned pl, package_versions pv, packages pkg"&_
" WHERE pl.rtag_id = "& CStr(NNrtag_id) &_
" AND pv.pv_id = pl.pv_id "&_
" AND pkg.pkg_id = pv.pkg_id "&_
" AND (pl.operation IS NULL OR pl.operation = 'R') "&_
") ORDER BY UPPER(pkg_name), UPPER(v_ext), pv_id DESC"
End Function
'--------------------------------------------------------------------------------------------------------------------------
' IsLicenced
'
' DESCRIPTION
' Queries the database to determine if a supplied PV_ID is associated with
' the provided licence
'
' INPUTS
' NNpv_id : The PV_ID of the package version being examined
' NNlicence : The licence to be examined
'
' OUTPUTS
' TRUE if the PV_ID is associated with the licence, else FALSE
'
Function IsLicenced(NNpv_id, NNlicence)
Dim IsLicencedQuery
Dim IsLicencedQueryResults
IsLicencedQuery = "SELECT * FROM licencing WHERE pv_id=" & CStr(NNpv_id) & " AND licence=" & CStr(NNlicence)
Set IsLicencedQueryResults = OraDatabase.DbCreateDynaset( IsLicencedQuery, cint(0))
If IsLicencedQueryResults.RecordCount = 0 Then
IsLicenced = FALSE
Else
IsLicenced = TRUE
End If
IsLicencedQueryResults.Close()
Set IsLicencedQueryResults = nothing
End Function
'--------------------------------------------------------------------------------------------------------------------------
' AddLicencing
'
' DESCRIPTION
' Adds a licencing relationship to the database for the supplied PV_ID, and the
' supplied Licence
'
' INPUTS
' NNpv_id : The PV_ID of the package version to be used
' NNlicence : The licence to be used
'
Sub AddLicencing(NNpv_id, NNlicence)
OraDatabase.Parameters.Add "PV_ID", NNpv_id, ORAPARM_INPUT, ORATYPE_NUMBER
OraDatabase.Parameters.Add "LICENCE", NNlicence, ORAPARM_INPUT, ORATYPE_NUMBER
On Error Resume Next
objEH.TryORA( OraSession )
OraDatabase.ExecuteSQL ("begin INSERT INTO licencing (pv_id, licence) VALUES (:PV_ID, :LICENCE); end;")
objEH.CatchORA( OraSession )
OraDatabase.Parameters.Remove "PV_ID"
OraDatabase.Parameters.Remove "LICENCE"
On Error Goto 0
' Log Action
Call Log_Action ( NNpv_id, "software_licence", "Added: " & licenceList.Item(Cint(NNlicence)))
End Sub
'--------------------------------------------------------------------------------------------------------------------------
' RemoveLicencing
'
' DESCRIPTION
' Removes a licencing relationship from the database for the supplied PV_ID, and the
' supplied Licence
'
' INPUTS
' NNpv_id : The PV_ID of the package version to be used
' NNlicence : The licence to be used
'
Sub RemoveLicencing(NNpv_id, NNlicence)
OraDatabase.Parameters.Add "PV_ID", NNpv_id, ORAPARM_INPUT, ORATYPE_NUMBER
OraDatabase.Parameters.Add "LICENCE", NNlicence, ORAPARM_INPUT, ORATYPE_NUMBER
On Error Resume Next
objEH.TryORA( OraSession )
OraDatabase.ExecuteSQL ("begin DELETE FROM licencing WHERE pv_id=:PV_ID AND licence=:LICENCE; end;")
objEH.CatchORA( OraSession )
OraDatabase.Parameters.Remove "PV_ID"
OraDatabase.Parameters.Remove "LICENCE"
On Error Goto 0
' Log Action
Call Log_Action ( NNpv_id, "software_licence", "Removed: " & licenceList.Item(Cint(NNlicence)))
End Sub
'--------------------------------------------------------------------------------------------------------------------------
' initialLicence
'
' DESCRIPTION
' Queries the database for a list of licences, and returns the first one in the list
' which will be used as the default licence prior to a user making a specific alternative
' selection via the drop down list
'
' OUTPUTS
' The first licence from the list, else -1 if list is empty
'
Function initialLicence
Dim initialLicenceQuery
Set initialLicenceQuery = OraDatabase.DbCreateDynaset( available_licences_query_string, cint(0) )
If ((initialLicenceQuery.RecordCount > 0) AND (NOT initialLicenceQuery.BOF) AND (NOT initialLicenceQuery.EOF)) Then
initialLicence = CDbl(initialLicenceQuery("licence"))
Else
initialLicence = -1
End If
initialLicenceQuery.Close()
Set initialLicenceQuery = nothing
End Function
'--------------------------------------------------------------------------------------------------------------------------
' CheckFormEntryConditions
'
' DESCRIPTION
' Checks some conditions of entry to the form and takes action when conditions are not met
'
Sub CheckFormEntryConditions
Dim CheckFormEntryConditionsQuery
' Check that at least one licence exists that can be associated with specific package versions. If there are no
' licences, then the form cannot be used.
Set CheckFormEntryConditionsQuery = OraDatabase.DbCreateDynaset( available_licences_query_string, cint(0) )
If CheckFormEntryConditionsQuery.RecordCount = 0 Then
CheckFormEntryConditionsQuery.Close()
Set CheckFormEntryConditionsQuery = nothing
Call RaiseMsg( enum_MSG_NO_LICENCES_EXIST & "?rtag_id=" & CStr(parRtag_Id), 0 )
End If
CheckFormEntryConditionsQuery.Close()
Set CheckFormEntryConditionsQuery = nothing
End Sub
'--------------------------------------------------------------------------------------------------------------------------
' CheckFormSubmitActions
'
' DESCRIPTION
' Checks for any form submit actions and processes them accordingly
'
' The form has a number of submit buttons (OK, APPLY, CANCEL)
'
' The OK and APPLY buttons lead to the checkbox states being used to update the database.
' The database updates are not performed when the CANCEL button is pressed.
'
' Pressing OK or CANCEL takes the user out of the form and back to the original referer page.
' Pressing APPLY leaves the user in the form so that they may make further licencing changes.
'
Sub CheckFormSubmitActions
If Request("action") <> "" Then
If objForm.IsValidOnPostBack Then
If Request("btn_submit") = "Apply" OR Request("btn_submit") = "OK" Then
Dim checkedItemsFromForm
Dim checkedItemsArray
Dim item
Dim parSelectedLicence
Dim checkedItemsDict
Dim rsQry
' Get the selected licence - and cater for situation where user has not changed the selected licence in
' the drop down list since first opening the form
parSelectedLicence = Request("selected_licence")
If (IsNull(parSelectedLicence) OR parSelectedLicence = "") Then
parSelectedLicence = initialLicence()
End If
' Get the list of checked items from the form. They will be in a CSV format.
' Split the list at the commas and read each item into a dictionary so we can use it for testing against the
' full set of PV_IDs we get later.
Set checkedItemsDict = CreateObject("Scripting.Dictionary")
checkedItemsFromForm = Request("checked_pv_id_list")
checkedItemsArray = Split(checkedItemsFromForm,",")
For Each item in checkedItemsArray
checkedItemsDict.Add Trim(CStr( item )), ""
Next
' Populate the licence name diction - for logging
Call getLicenceNames
' Get the record set for the entire set of PV_IDs in the release
Set rsQry = OraDatabase.DbCreateDynaset( release_licencing_query_string(parRtag_Id), cint(0) )
Do While (NOT rsQry.BOF) AND (NOT rsQry.EOF)
' If the user has checked the item, and it does not already exist in the licencing table associated to the selected licence,
' then add a new row to the table to create that associatation
If checkedItemsDict.Exists(CStr(rsQry("pv_id"))) Then
If (NOT IsLicenced(rsQry("pv_id"), parSelectedLicence)) Then
Call AddLicencing(rsQry("pv_id"), parSelectedLicence)
End If
Else
' Item is not checked, so we need to ensure that any association to the selected licence is removed
' from the licencing table.
If (IsLicenced(rsQry("pv_id"), parSelectedLicence)) Then
Call RemoveLicencing(rsQry("pv_id"), parSelectedLicence)
End If
End If
rsQry.MoveNext
Loop
' destroy objects
rsQry.Close()
Set rsQry = nothing
checkedItemsDict.RemoveAll
Set checkedItemsDict = nothing
' figure out where to go next
If Request("btn_submit") = "OK" Then
' User has finished making licencing changes so go back to the referer page
Call OpenInWindow ( httpReferer )
Else
' else user pressed Apply, so stay in the form to let user make further licencing changes
Call OpenInWindow ( "form_edit_release_licencing.asp?rtag_id=" & Request("rtag_id") & "&selected_licence=" & parSelectedLicence )
End If
Else
' User has cancelled so go back to the referer page
Call OpenInWindow ( httpReferer )
End If
End If
End If
End Sub
'--------------------------------------------------------------------------------------------------------------------------
' LicenceDropDownHTML
'
' DESCRIPTION
' Constructs the HTML to render the drop down list and whilst doing so, updates the global selectedLicence variable
'
Function LicenceDropDownHTML
Dim rsQry
Dim html_string
' Get the full list of licences availabel from the database
Set rsQry = OraDatabase.DbCreateDynaset( available_licences_query_string, cint(0) )
' Start of select tag
' This is designed such that when the user changes the selection, the page is re-rendered with the selected licence value passed
' in as a paramter as part of the URL along with the release tage
html_string = ""
' return result
LicenceDropDownHTML = html_string
End Function
'--------------------------------------------------------------------------------------------------------------------------
' getLicenceNames
'
' DESCRIPTION
' Populates a dictionary to simplify conversion of licence data to text
' Used in logging changes
'
Sub getLicenceNames
Dim rsQry
Set licenceList=Server.CreateObject("Scripting.Dictionary")
' Get the full list of licences availabel from the database
Set rsQry = OraDatabase.DbCreateDynaset( available_licences_query_string, cint(0) )
' Add each licence to the select, using the option tag, and set the initially selected option
While (NOT rsQry.BOF) AND (NOT rsQry.EOF)
licenceList.Add Cint(rsQry.Fields("licence")), CStr(rsQry.Fields("name"))
rsQry.MoveNext
WEnd
' destroy objects
rsQry.Close()
Set rsQry = nothing
End Sub
'--------------------------------------------------------------------------------------------------------------------------
' PV_ID_ListHTML
'
' DESCRIPTION
' Constructs the HTML to render the rows of checkboxes, package names, versions and extensions
'
Function PV_ID_ListHTML
Dim rsQry
Dim html_string
Set rsQry = OraDatabase.DbCreateDynaset( release_licencing_query_string(parRtag_Id), cint(0) )
'--- Render rows ---
Do While (NOT rsQry.BOF) AND (NOT rsQry.EOF)
' BEGIN ROW
html_string = html_string & "
"
' CHECKBOX
If (IsLicenced(rsQry("pv_id"), selectedLicence)) Then
html_string = html_string & "
"
Else
html_string = html_string & "
"
End If
' PACKAGE NAME
html_string = html_string & "
" & rsQry("pkg_name") & "
"
' PACKAGE VERSION
If IsNull(rsQry("v_ext")) Then
html_string = html_string & "
"
End If
' PACKAGE EXTENSION
html_string = html_string & "
" & rsQry("v_ext") & "
"
' END ROW
html_string = html_string & "
"
rsQry.MoveNext
' ROW SEPERATOR
If (NOT rsQry.BOF) AND (NOT rsQry.EOF) Then
html_string = html_string & "
"
End If
Loop
' destroy objects
rsQry.Close()
Set rsQry = nothing
' return result
PV_ID_ListHTML = html_string
End Function
'--------------------------------------------------------------------------------------------------------------------------
'--------------------------------------------------------------------------------------------------------------------------
'------------ RUN BEFORE PAGE RENDER ----------
Call CheckFormEntryConditions()
Call CheckFormSubmitActions()
'----------------------------------------------
%>
Release Manager
<%
Call objFormComponent.FormEnd()
'-- FROM END ----------------------------------------------------------------------------------------------------------------
%>