<!--#include virtual="/NR/System/WBC/Internals/Main/WBCApp.inc"-->
<!-- #include virtual="/NR/System/WBC/Customizable/WBCFuncPagesConfig/MLSDisplayConfig/TasksAssistantConfig.inc" -->

<!--#include virtual="/NR/System/WBC/Customizable/WBCFuncPagesConfig/UIStringConstants/TasksAssistantUIStrings.inc" -->
<!--#include virtual="/NR/System/WBC/Internals/WBCFuncPages/Cross-Browser/TasksAssistant/ApprovalAssistant/ApprovalAssistantConstants.inc" -->

<%

' ********************************************************************
' Copyright (C) 2001 Microsoft Corporation. All rights reserved.
'
'	IMPORTANT.  Please read the legal.txt file, located in the
'	"<CMS Install Directory>\Server\httpexec\WBC\Internals"
'	directory, governing the use of this internal file."
' ********************************************************************

' ********************************************************************
' File:		/NR/System/WBC/Internals/WBCFuncPages/Cross-Browser/
'				TasksAssistant/ApprovalAssistant/PagesApproveDecline/
'				CNCASPPageManager_PagesApproveDecline.inc
'
' Version: 	Microsoft Content Management Server
' Author:	Microsoft Corporation.
'
' Purpose:	Encapsulate the ASP logic associated with
'			PagesApproveDecline.asp. This class takes care of
'			handling the grunt work of approving pages and doing any
'			necessary configuration for things like multiple languages.
'
' Implements the INCASPPageManager interface:
'
'	- Sub InitManager()
'
' Exposes the following public methods:
'
'	- Function HasRightsToApprove( pPosting )
'	- Sub PerformPostingActionSafe( pPosting )
'
' Exposes the following properties:
'
'	- Property CodePage
'	- Property Charset
'	- Property URLRefreshPagesAfterAction
'	- Property ActionPresentTense
'	- Property ActionPastTense
'	- Property FormReader
'	- Property ASPUtils
'	- Property Error
'
' ********************************************************************

Class CNCASPPageManager_PagesApproveDecline

	' see documentation below for property descriptions for an
	' explanation of what these member variables are used for
	Private m_strCodePage
	Private m_strCharset
	Private m_strURLRefreshPagesAfterAction
	Private m_strActionPresentTense
	Private m_strActionPastTense
	Private m_pFormReader
	Private m_pASPUtils
	Private m_strError
	Private m_dictPostingConnectedGuids

	' the action passed to this page. Note that the
	' ActionPresentTense and ActionPastTense members are used for
	' UI purposes. This member is used to track the original action
	' string passed in by the form
	Private m_strPostingAction


	' -------------------------------------------------------------------------
	'	[PUBLIC;READ] Property that exposes the username
	' -------------------------------------------------------------------------
	Public Property Get UserShortName
		If Autosession.User Is Nothing Then
			UserShortName = ""
		Else
			UserShortName = Autosession.User.ShortName
		End If
	End Property


	' -------------------------------------------------------------------------
	'	[PUBLIC;READ] Property that exposes the codepage for the page
	' -------------------------------------------------------------------------
	Public Property Get CodePage
		CodePage = m_strCodePage
	End Property
	
	
	' -------------------------------------------------------------------------
	'	[PUBLIC;READ] Property that exposes the charset for the page
	' -------------------------------------------------------------------------
	Public Property Get CharSet
		CharSet = m_strCharSet
	End Property


	' -------------------------------------------------------------------------
	'	[PUBLIC;READ] Property that stores the URL for the page to return
	' 	to after a successful operation.
	' -------------------------------------------------------------------------
	Public Property Get URLRefreshPagesAfterAction
		URLRefreshPagesAfterAction = m_strURLRefreshPagesAfterAction
	End Property


	' -------------------------------------------------------------------------
	'	[PUBLIC;READ] Property that indicates what action was performed to
	'	invoke this ASP page - approving a set of pages, or declining a set
	' 	of pages. Note that the verb returned should be the present tense
	' 	form of the action (e.g. Approve).
	' -------------------------------------------------------------------------
	Public Property Get ActionPresentTense
		ActionPresentTense = m_strActionPresentTense
	End Property


	' -------------------------------------------------------------------------
	'	[PUBLIC;READ] Property that indicates what action was performed to
	'	invoke this ASP page - approving a set of pages, or declining a set
	' 	of pages. Note that the verb returned should be the past tense
	' 	form of the action (e.g. Approved).
	' -------------------------------------------------------------------------
	Public Property Get ActionPastTense
		ActionPastTense = m_strActionPastTense
	End Property


	' -------------------------------------------------------------------------
	'	[PUBLIC;READ] Provides access to the form reader component for this
	'	page to get access to all of the submitted form elements.
	' -------------------------------------------------------------------------
	Public Property Get FormReader
		Set FormReader = m_pFormReader
	End Property


	' -------------------------------------------------------------------------
	'	[PUBLIC;READ] Provides access to the generic ASP utilities object.
	' -------------------------------------------------------------------------
	Public Property Get ASPUtils
		Set ASPUtils = m_pASPUtils
	End Property


	' -------------------------------------------------------------------------
	'	[PUBLIC;READ] The error string is filled in when an error occurs in
	'	initialization of the page manager
	' -------------------------------------------------------------------------
	Public Property Get Error
		Error = m_strError
	End Property


	' -------------------------------------------------------------------------
	'	[PRIVATE] The Class_Initialize method acts as a constructor for the
	'	class and is called automatically by the scripting engine when the
	'	class is instantiated.
	' -------------------------------------------------------------------------
	Private Sub Class_Initialize()

		m_strCodePage = ""
		m_strCharSet = ""
		m_strURLRefreshPagesAfterAction = "../ApprovalAssistant.asp"
		Set m_pFormReader = Nothing
		Set m_pASPUtils = Nothing
		m_strError = ""
		
		' create a dictionary for keeping track of 
		' approved Postings' connected postings Guids
		Set m_dictPostingConnectedGuids = CreateObject("Scripting.Dictionary")

	End Sub  'Class_Initialize


	' -------------------------------------------------------------------------
	'	[PUBLIC] This function should be the first one called by anyone
	'	creating a new instance of this page manager class. It is responsible
	'	for creating objects associated with all the member variables and
	'	thus, encapsulating initialization logic from the main ASP page.
	'
	'	@see CNCASPPageManager
	' -------------------------------------------------------------------------
	Public Sub InitManager()

		Call SetupASPUtils()
		Call SetupCodePage()
		Call SetupCharSet()
		Call SetupBrowseContext()
		Call SetupLinksURL()

	End Sub  'InitManager


	Public Sub RegisterApprovedPosting( pPosting )
		Dim pConnectedPosting
		For Each pConnectedPosting in pPosting.ConnectedPostings
			m_dictPostingConnectedGuids.Item( pConnectedPosting.Guid ) = True
		Next
	End Sub

	Public Function HasNoRightsToApprove( pPosting )
		' check against CanApprove, but filter out cases where
		' pPosting is a connected posting of a posting processed 
		' here already.
		HasNoRightsToApprove = (pPosting.CanApprove = False) And _
						Not m_dictPostingConnectedGuids.Exists( pPosting.Guid )
	End Function

	' -------------------------------------------------------------------------
	'	[PUBLIC] This function will safely (i.e. without returning or
	' 	propagating errors) approve or decline the posting that is passed as a
	'	parameter. The action to be performed is based on the form value
	'	that was read during initialization that indicates whether to approve
	'	or decline.
	'
	'	@param pPosting [in] - the posting to perform the approve or decline
	'		operation on.
	'
	'	@exception Err Unknown form action
	' -------------------------------------------------------------------------
	Public Sub PerformPostingActionSafe( pPosting )

		On Error Resume Next

		If (pPosting.CanApprove) Then
			If (m_strPostingAction = IDS_FORM_ELEMENT_APPROVEORDECLINE_VALUE_APPROVE) Then
				Call pPosting.Approve()

			ElseIf (m_strPostingAction = IDS_FORM_ELEMENT_APPROVEORDECLINE_VALUE_DECLINE) Then
				Call pPosting.Decline()

			Else
				' unrecognized form action, so throw a general error
				' and exit
				Response.Write( IDS_UI_ERROR_INVALIDFORMPARAMS )
				Call Err.Raise( ID_ERROR_UNKNOWN_FORM_ACTION )

			End If  'case on form action
		End If

	End Sub  'PerformPostingActionSafe


	' -------------------------------------------------------------------------
	'	[PRIVATE] A helper function to setup the code page that the ASP page
	'	will be running under (for multi-language support).
	' -------------------------------------------------------------------------
	Private Sub SetupCodePage()

		m_strCodePage = GetCodePageForTasksAssistant( m_pASPUtils )

	End Sub  'SetupCodePage
	

	' -------------------------------------------------------------------------
	'	[PRIVATE] A helper function to setup the char page that the ASP page
	'	will be running under (for multi-language support).
	' -------------------------------------------------------------------------
	Private Sub SetupCharset()

		m_strCharSet = GetCharacterSetForTasksAssistant()

	End Sub  'SetupCharset


	' -------------------------------------------------------------------------
	'	[PRIVATE] A helper function that takes care of creating an instance
	' 	of the form reader object, which encapsulates form handling into a
	'	nicer-to-use ASP object. Note the "Safe" in the function name - this
	'	method will not throw any errors to the caller
	'
	'	@param lCodePage [in] - code page the ASP page is running in
	' -------------------------------------------------------------------------
	Function SetupFormReaderSafe( lCodePage )

		Err.Clear()
		On Error Resume Next

		' if the form reader has already been initialized, then return the
		' existing reader.
		If Not m_pFormReader Is Nothing Then

			Set SetupFormReaderSafe = m_pFormReader
			Exit Function

		End If  'if form reader already created

		' create the ASPFormReader object
		Set m_pFormReader = Server.CreateObject( "NCASPExtensions.ASPFormReader" )
		m_pFormReader.CodePage = lCodePage
		m_pFormReader.UploadValidation = false

		Set SetupFormReaderSafe = m_pFormReader

	End Function  'SetupFormReaderSafe


	' -------------------------------------------------------------------------
	'	[PRIVATE] Set up ASPUtil objects with MLS info
	' -------------------------------------------------------------------------
	Private Sub SetupASPUtils()

		Set m_pASPUtils = GetInitializedASPUtils()

		' setup the form reader object that will help us with form-related
		' details, such as grabbing form parameters
		SetupFormReaderSafe( GetCodePageForTasksAssistant( m_pASPUtils ) )

	End Sub  'SetupASPUtils


	' -------------------------------------------------------------------------
	'	[PRIVATE] A helper function to retrieve the form parameters that were
	' 	passed to the page and disseminate them into useful information. In
	'	this case, one useful piece of information is the form action -
	'	approve or decline.
	'
	'	@exception Err Unknown form action
	' -------------------------------------------------------------------------
	Private Sub SetupBrowseContext()

		m_strPostingAction = m_pFormReader.Form( IDS_FORM_ELEMENT_APPROVEORDECLINE )

		' define strings to be used for display in UI later on
		If m_strPostingAction = IDS_FORM_ELEMENT_APPROVEORDECLINE_VALUE_APPROVE Then

			m_strActionPresentTense = IDS_UI_LABEL_APPROVE_PRESENT
			m_strActionPastTense = IDS_UI_LABEL_APPROVE_PAST

		ElseIf m_strPostingAction = IDS_FORM_ELEMENT_APPROVEORDECLINE_VALUE_DECLINE Then

			m_strActionPresentTense = IDS_UI_LABEL_DECLINE_PRESENT
			m_strActionPastTense = IDS_UI_LABEL_DECLINE_PAST

		Else
			' some weird action that we weren't expecting so dump out a fatal
			' error
			Response.Write( IDS_UI_ERROR_INVALIDFORMPARAMS )
			Call Err.Raise( ID_ERROR_UNKNOWN_FORM_ACTION )

		End If  'if recognized action

	End Sub  'SetupBrowseContext


	' -------------------------------------------------------------------------
	'	[PRIVATE] Set up the required URLs for refreshing the page and going
	'	back to previous pages.
	' -------------------------------------------------------------------------
	Private Sub SetupLinksURL()

		' setup the URL that will take us back to the original page that
		' spawned this one. Note that the original query string parameters
		' must be preserved in order for the list of pages waiting for
		' approval to be updated. In addition, an additional parameter
		' is sent back to the calling page to indicate that the redirect
		' happened from here and that the page control should be reset.
		m_strURLRefreshPagesAfterAction = "../ApprovalAssistant.asp?" & URLEncodedQueryString() & "&" & _
										  IDS_QPARAM_PAGESTATUS_NAME & "=" & IDS_QPARAM_PAGESTATUS_VALUE_AFTERPOSTINGACTION

	End Sub  'SetupLinksURL


End Class  'CNCASPPageManager_PagesApproveDecline

%>