%@LANGUAGE="VBSCRIPT"%>
<%
'=====================================================
' wAddDaemonInstruction.asp
'
' This page is designed to be loaded into an iframe
'
'=====================================================
%>
<%
Option explicit
Response.Expires = 0
%>
<%
'------------ ACCESS CONTROL ------------------
%>
<%
'------------ VARIABLE DEFINITION -------------
Dim sMessage, sMessageType
Dim parProj_id
Dim parPv_id
Dim parOp_code
Dim parRepeat
Dim parInst_id
Dim parSchDateTime
Dim parRfile
Dim bHideRepeat
Dim bHidePackages
Dim bPreventSubmit
Dim parSortOrder
Dim ReleaseMode
'------------ VARIABLE INIT -------------------
sMessage = NULL
sMessageType = 3
bPreventSubmit = False
' collect all parameters from query string
parOp_code = Request("op_code")
parProj_id = Request("proj_id")
parPv_id = Request("pv_id")
parRepeat = Request("repeat")
parInst_id = Request("inst_id")
parSchDateTime = Request("sdt")
parRfile = Request("rfile")
parSortOrder = RequestDefault("sort",0)
If parSchDateTime = "" Then
parSchDateTime = DisplayShortDateTimeSecs(Now())
End If
ReleaseMode = GetReleaseMode(parRtag_id)
parSortOrder = Request("sort")
If IsNull(parSortOrder) OR parSortOrder = "" Then
parSortOrder = "0"
End If
Set objFormCollector = CreateObject("Scripting.Dictionary")
'------------------------------------------------------------------------------------------------------------------------------------------
'
' Add a line of text to the System Message
'
Sub sMessageAdd(eLevel, text)
If NOT isNull(sMessage) Then
sMessage = sMessage & " "
End If
sMessage = sMessage & text
If eLevel < sMessageType Then
sMessageType = eLevel
End If
End Sub
'------------------------------------------------------------------------------------------------------------------------------------------
' For the specified project ID, get a list of all that project's releases that are not closed/archived.
' Return True if at least one release was found, else False
'------------------------------------------------------------------------------------------------------------------------------------------
Function ReleasesAvailable(NNproj_id)
Dim rsTemp, Query_String
ReleasesAvailable = True
Query_String = "SELECT rtag_id, rtag_name "&_
" FROM release_tags rt"&_
" WHERE rt.proj_id = "& NNproj_id &_
" AND ((rt.official = 'N') OR (rt.official = 'C') OR (rt.official = 'R'))"
Set rsTemp = OraDatabase.DbCreateDynaset( Query_String, cint(0))
If rsTemp.RecordCount = 0 Then
ReleasesAvailable = False
End If
rsTemp.Close
Set rsTemp = nothing
End Function
'------------------------------------------------------------------------------------------------------------------------------------------
' For the specified Release, get a list of all that release's daemon configurations.
' Return True if at least one daemon configuration was found, else False
'------------------------------------------------------------------------------------------------------------------------------------------
Function DaemonsAvailable(NNrtag_id)
Dim rsTemp, Query_String
DaemonsAvailable = True
Query_String = "SELECT * "&_
" FROM release_config rc"&_
" WHERE rc.rtag_id = "& NNrtag_id
Set rsTemp = OraDatabase.DbCreateDynaset( Query_String, cint(0))
If rsTemp.RecordCount = 0 Then
DaemonsAvailable = False
End If
rsTemp.Close
Set rsTemp = nothing
End Function
'------------------------------------------------------------------------------------------------------------------------------------------
' Formulate the HTML for a combo box listing all the daemon instruction operations, and select the one that matches
' the op-code passed in as a parameter. If the parameter value could not be found, correct it to the first valid op-code
' in the list.
'------------------------------------------------------------------------------------------------------------------------------------------
Function Get_OpCodes ( NNop_code )
Dim op_code_str_array
Dim op_code_str
Dim op_code_val
Dim selectedFound
Dim s
selectedFound = False
' Get the op-codes in terms of human readable string names - these will be used in the drop down select list
Call GetDaemonInstructionOperationNameArray(op_code_str_array)
s = "
Operation
"
s = s + "
"
Get_OpCodes = s
End Function
'------------------------------------------------------------------------------------------------------------------------------------------
' Formulate the HTML for a combo box listing all the Projects, and select the one that matches
' the proj-id passed in as a parameter. If the parameter value could not be found, correct it to the first valid proj-id
' in the list.
'------------------------------------------------------------------------------------------------------------------------------------------
Function Get_Projects ( NNproj_id )
Dim rsTemp, Query_String, projName, selectedFound, s
selectedFound = False
Query_String = "SELECT * FROM projects ORDER BY UPPER( proj_name )"
Set rsTemp = OraDatabase.DbCreateDynaset( Query_String, cint(0))
s = "
Project
"
s = s + "
"
rsTemp.Close
Set rsTemp = nothing
s = s + "
"
Get_Projects = s
End Function
'------------------------------------------------------------------------------------------------------------------------------------------
' Formulate the HTML for a combo box listing all the Release for a specified project, and select the one that matches
' the release-tag passed in as a parameter. If the parameter value could not be found, correct it to the first valid release-tag
' in the list.
'------------------------------------------------------------------------------------------------------------------------------------------
Function Get_Releases ( NNproj_id, NNrtag_id )
Dim rsTemp, Query_String, releaseName, val, selectedFound, s, numReleases
selectedFound = False
numReleases = 0
Query_String = "SELECT rtag_id, rtag_name "&_
" FROM release_tags rt"&_
" WHERE rt.proj_id = "& NNproj_id &_
" AND ((rt.official = 'N') OR (rt.official = 'C') OR (rt.official = 'R'))"&_
" ORDER BY UPPER(rtag_name)"
Set rsTemp = OraDatabase.DbCreateDynaset( Query_String, cint(0))
s = "
Release
"
s = s + "
"
' If no releases were found then replace drop down list with some warning text and disable form submission
If numReleases = 0 Then
bPreventSubmit = True
s = "
"
End If
Else
' If the selected release does not have a daemon configuration, append some warning text to the right of the drop down list.
If NNrtag_id > 0 AND DaemonsAvailable(NNrtag_id) = False Then
s = s + " WARNING: Release has no build daemon(s)"
End If
End If
rsTemp.Close
Set rsTemp = nothing
s = s + ""
Get_Releases = s
End Function
'------------------------------------------------------------------------------------------------------------------------------------------
' Formulate the HTML for a combo box listing all the Package Versions in a specified release, and select the one that matches
' the pv_id passed in as a parameter. If the parameter value could not be found, correct it to the first valid pv_id
' in the list.
' This function must deal with op-codes that want to read package versions from the work_in_progress table, and op-codes
' that need to read package versions from the release_content table.
' The function should only be called if a package versions drop down list is required for the form.
'------------------------------------------------------------------------------------------------------------------------------------------
Function Get_Packages ( NNrtag_id, NNpv_id, NNop_code )
Dim rsTemp, Query_String, pkgName, val, selectedFound, s, numPackages
selectedFound = False
numPackages = 0
If (NNop_code = OP_CODE_1_TEST_BUILD_PACKAGE ) Then
' Get list of packages from from work_in_progress table
Query_String = "SELECT pk.pkg_id, pk.pkg_name, pv.pkg_version, wip.pv_id "&_
" FROM work_in_progress wip, release_tags rt, packages pk, package_versions pv "&_
" WHERE wip.rtag_id = "& Cstr(NNrtag_id) &_
" AND wip.rtag_id = rt.rtag_id"&_
" AND ((rt.official = 'N') OR (rt.official = 'C') OR (rt.official = 'R'))"&_
" AND wip.pv_id = pv.pv_id"&_
" AND pk.pkg_id = pv.pkg_id"&_
" ORDER BY UPPER(pkg_name)"
ElseIf ( NNop_code = OP_CODE_2_FUTURE_BUILD) Then
' Get list of packages from from Pending Approval table
Query_String = "SELECT pk.pkg_id, pk.pkg_name, pv.pkg_version, wip.pv_id "&_
" FROM planned wip, release_tags rt, packages pk, package_versions pv "&_
" WHERE wip.rtag_id = "& Cstr(NNrtag_id) &_
" AND wip.rtag_id = rt.rtag_id"&_
" AND ((rt.official = 'N') OR (rt.official = 'C') OR (rt.official = 'R'))"&_
" AND wip.pv_id = pv.pv_id"&_
" AND pk.pkg_id = pv.pkg_id"&_
" ORDER BY UPPER(pkg_name)"
Else
' Get list of packages from from release_content table
Query_String = "SELECT pk.pkg_id, pk.pkg_name, pv.pkg_version, rc.pv_id "&_
" FROM release_content rc, release_tags rt, packages pk, package_versions pv "&_
" WHERE rc.rtag_id = "& Cstr(NNrtag_id) &_
" AND rc.rtag_id = rt.rtag_id"&_
" AND ((rt.official = 'N') OR (rt.official = 'C') OR (rt.official = 'R'))"&_
" AND rc.pv_id = pv.pv_id"&_
" AND pk.pkg_id = pv.pkg_id"&_
" ORDER BY UPPER(pkg_name)"
End If
Set rsTemp = OraDatabase.DbCreateDynaset( Query_String, cint(0))
' modify the control heading to indicate the source of the package version list
If (NNop_code = OP_CODE_1_TEST_BUILD_PACKAGE) Then
s = "
WIP Package
"
ElseIf (NNop_code = OP_CODE_2_FUTURE_BUILD) Then
s = "
Pending Package
"
Else
s = "
Released Package
"
End If
s = s + "
"
If NNrtag_id > 0 Then
' replace drop down list with a warning if no package versions were found, and ensure that the user cannot submit the form
If numPackages = 0 Then
bPreventSubmit = True
If (NNop_code = OP_CODE_1_TEST_BUILD_PACKAGE) Then
s = "
"
End If
rsTemp.Close
Set rsTemp = nothing
Get_Packages = s
End Function
'------------------------------------------------------------------------------------------------------------------------------------------
' This function will be called if and only if the form is first opened in circumstances where the user is editing an existing record
' and all of the form's parameters must be set to the values found in that record. The database record must be obtained using a query
' and the relevant parameters assigned from the record fields
'------------------------------------------------------------------------------------------------------------------------------------------
Sub Get_All_Params_From_Inst_Id(NNInstId)
Dim rsTemp, Query_String
Query_String = "SELECT op_code, rtag_id, pv_id, repeat_secs, "&_
" TO_CHAR(scheduled_datetime, 'DD-MM-YYYY HH24:MI:SS') AS schedDate "&_
" FROM DAEMON_INSTRUCTIONS "&_
" WHERE DAEMON_INSTRUCTIONS_ID = " & NNInstId
Set rsTemp = OraDatabase.DbCreateDynaset( Query_String, cint(0))
If rstemp.RecordCount = 0 Then
Call sMessageAdd(1, "Attempt to Edit a non-existent record")
Exit Sub
End If
' assign record fields to global parameters
parOp_code = rsTemp("op_code")
parRtag_id = rsTemp("rtag_id")
parPv_id = rsTemp("pv_id")
parRepeat = rsTemp("repeat_secs")
parSchDateTime = rsTemp("schedDate")
' derive project id since that is not stored in the table
If NOT IsNull(parRtag_id) AND parRtag_id <> "" Then
parProj_id = Get_Proj_ID(parRtag_id)
Else
parProj_id = "0"
End If
rsTemp.Close
Set rsTemp = nothing
End Sub
'------------------------------------------------------------------------------------------------------------------------------------------
' Perform any form callback actions
' This is implemented in a subroutine to simplify error handling
'
Sub performActions
' Check if form submit is happening
If CBool(Request("action")) Then
Dim RepeatSeconds
Dim ScheduledDateTime
Dim sErrorMsg
' determine if insert/update is enabled by permissions
If NOT UserCanAddOrEditThisDaemonInst(parProj_id, ReleaseMode, parOp_code) Then
' redirect to an error message
Call sMessageAdd (1, "You have been denied permission to add/update daemon instructions for the specified release.")
Exit Sub
End If
' do daemon instruction validation, continuing only if it passes
If ValidateDaemonInstruction(parOp_code, parRtag_id, parPv_id, sErrorMsg) = True Then
' Setup the repeat seconds count according to the radio button value
If IsNull(Request("repeat_inst")) OR Request("repeat_inst") = "" OR Request("repeat_inst") = "No" Then
RepeatSeconds = 0
Else
RepeatSeconds = 86400
End If
' If user has not entered a scheduled time, set the scheduled date/time to now
ScheduledDateTime = Request("scheduled_time")
If IsNull(ScheduledDateTime) OR ScheduledDateTime = "" Then
ScheduledDateTime = ORA_SYSDATETIME
Else
ScheduledDateTime = "TO_DATE( '"& ScheduledDateTime &"','DY DD-MON-YYYY HH24:MI' )"
End If
' nullify parPv_id for the SQL, if the instruction op-code does not require one
If bHidePackages Then
parPv_id = "NULL"
End If
objEH.ErrorRedirect = FALSE
objEH.TryORA ( OraSession )
On Error Resume Next
' if the page has been provided an inst_id, we must be editing an existing record so we do an update
If (NOT IsNull(parInst_id)) AND (parInst_id <> "") Then
' We are updating an existing record
OraDatabase.ExecuteSQL "BEGIN PK_BUILDAPI.update_daemon_inst( "& parInst_id & ", " &_
parOp_code & ", " &_
parRtag_id & ", " &_
parPv_id & ", " &_
ScheduledDateTime & ", " &_
CStr(RepeatSeconds) & ", " &_
ORA_SYSDATETIME & ", " &_
objAccessControl.UserId & "); END;"
Else ' We are adding a new record
OraDatabase.ExecuteSQL "BEGIN PK_BUILDAPI.insert_daemon_inst( "& parOp_code & ", " &_
parRtag_id & ", " &_
parPv_id & ", " &_
ScheduledDateTime & ", " &_
CStr(RepeatSeconds) & ", " &_
ORA_SYSDATETIME & ", " &_
objAccessControl.UserId & "); END;"
End If
objEH.CatchORA ( OraSession )
' If the operation was succesful, then redirect the parent
' This will also close the iframe
'
' If an error has occured, then an error message will be displayed within the iframe
' via the _msg_inline.asp processing when the page is re-displayed
'
If objEH.Finally Then
If parRfile = "admin_daemon_instructions.asp" Then
Call OpenInParentWindow (parRfile & "?sort=" & parSortOrder)
Else
Call OpenInParentWindow (parRfile & "?rtag_id=" & parRtag_id & "&pv_id=" & parPv_id)
End If
Call CloseWindow
End If
Else
sMessage = sErrorMsg
sMessageType = 1
End If
End If
End Sub
%>
<%
'------------ RUN BEFORE PAGE RENDER ----------
'
' Access Control
If NOT objAccessControl.UserLogedIn Then
Call sMessageAdd ( 1, "User is no longer logged in")
ElseIf NOT UserCanAddOrEditThisDaemonInst(DB_PROJ_ID, ReleaseMode, parOp_code) Then
Call sMessageAdd ( 1, "You have been denied permission to add/update daemon instructions for the specified release." )
End If
' Are we in edit mode? If so, populate all parameters from the record being edited
If (NOT IsNull(parInst_id)) AND (parInst_id <> "") AND (Request("edit") = "true") Then
If NOT DaemonInstructionInProgress(Request("inst_id")) Then
Call Get_All_Params_From_Inst_Id(parInst_id)
Else
Call sMessageAdd(1,"Cannot edit an instruction that is currently being processed by a Daemon")
End If
End If
' Make sure we dont have any null strings or empty strings for our parameters
If IsNull(parOp_code) OR parOp_code = "" Then
parOp_code = "0"
End If
If IsNull(parProj_id) OR parProj_id = "" Then
parProj_id = "0"
End If
If IsNull(parRtag_id) OR parRtag_id = "" Then
parRtag_id = "0"
End If
If IsNull(parPv_id) OR parPv_id = "" Then
parPv_id = "0"
End If
If IsNull(parRepeat) OR parRepeat = "" Then
parRepeat = "0"
End If
If IsNull(parRfile) OR parRfile = "" Then
parRfile = "admin_daemon_instructions.asp"
End If
If IsNull(parSchDateTime) OR parSchDateTime = "" Then
parSchDateTime = DisplayShortDateTimeSecs(Now())
End If
' If this form is opened with an OP_CODE, RTAG_ID and PV_ID only, then we need to derive the PROJ_ID before
' calling Get_Projects() to generate the project drop down list.
If parProj_id = "0" AND NOT IsNull(parRtag_id) AND parRtag_id <> "" AND parRtag_id <> "0" Then
parProj_id = DB_PROJ_ID
End If
' Hide the Package drop-down list if the Daemon Instruction does not require it
If DaemonInstructionNeedsPV_ID(parOp_code) Then
bHidePackages = False
Else
bHidePackages = True
parPv_id = "0"
End If
' NOTE: from this moment on, any real use of parPv_id has to be guarded by examination of bHidePackages
' Hide the Repeat buttons if the Daemon Instruction does not require them
If DaemonInstructionNeedsRepeat(parOp_code) Then
bHideRepeat = False
Else
bHideRepeat = True
End If
' Perform any required actions
Call performActions
'----------------------------------------------
%>
Release Manager
<%bJqueryTimePicker = TRUE%>
<%
'-- FROM START --------------------------------------------------------------------------------------------------------------
objFormComponent.FormName = "DaemonInstruction"
objFormComponent.FormClass = "form_tight"
objFormComponent.Action = ScriptName &_
"?inst_id="& parInst_id &_
"&op_code="& parOp_code &_
"&proj_id="& parProj_id &_
"&rtag_id="& parRtag_id &_
"&pv_id="& parPv_id &_
"&sort="& parSortOrder &_
"&rfile="& parRfile
objFormComponent.OnSubmit = "ShowProgress();"
Call objFormComponent.FormStart()
%>
<%
Dim disableText : disableText = ""
If NOT ( (NOT bHidePackages AND parPv_id > 0 ) AND ReleasesAvailable(parProj_id) AND DaemonsAvailable(parRtag_id) AND NOT bPreventSubmit AND IsNull(sMessage)) Then
disableText = "disabled=""disabled"""
End If
%>
<%
objPMod.ComposeHiddenTags()
Call objFormComponent.FormEnd()
'-- FROM END ----------------------------------------------------------------------------------------------------------------
%>
<%
'------------ RUN AFTER PAGE RENDER -----------
Set objFormCollector = Nothing
'----------------------------------------------
Call Destroy_All_Objects
%>