<!--#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" -->

<!--#include virtual="/NR/System/WBC/Internals/ServerControls/GridControl/CNCGridControl.inc"-->
<!--#include file="CNCGridDecorator_ApprovalAssistant.inc" -->

<!--#include virtual="/NR/System/WBC/Internals/ServerControls/PagingConfigControl/CNCPagingConfigControl.inc"-->
<!--#include virtual="/NR/System/WBC/Internals/ServerControls/PagingControl/CNCPagingControl.inc"-->
<!--#include virtual="/NR/System/WBC/Internals/ServerControls/PagingControl/CNCPagingRenderer_Common.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/
'				CNCASPPageManager_ApprovalAssistant.inc
'
' Version: 	Microsoft Content Management Server
' Author:	Microsoft Corporation.
'
' Purpose:	Encapsulate the ASP logic associated with
'			ApprovalAssistant.asp. This class takes care of maintaining
'			information about the various controls on the page and
'			taking care of initialization activities, such as setting
'			up URLs and creating new instances of server-side controls.
'
' Implements the INCASPPageManager interface:
'
'	- Sub InitManager()
'
' Exposes the following properties:
'
'	- Property ASPUtils [R]
'	- Property CodePage [R]
'	- Property Charset [R]
'	- Property UserShortName [R]
'	- Property StartItem [R]
'	- Property EndItem [R]
'	- Property PagingConfigControl [R]
'	- Property GridControl [R]
'	- Property PagingControl [R]
'	- Property URLApproveButton [R]
'	- Property URLDeclineButton [R]
'	- Property FilteredQueryString [R]
'	- Property ApproveButtonEnabled [R/W]
'	- Property DeclineButtonEnabled [R/W]
'	- Property Error [R]
'
' ********************************************************************

Class CNCASPPageManager_ApprovalAssistant

	' see documentation below for property descriptions for an
	' explanation of what these member variables are used for
	Private m_pASPUtils
	Private m_strCodePage
	Private m_strCharset
	Private m_nStartItem
	Private m_nEndItem
	Private m_pPagingConfigControl
	Private m_pGridControl
	Private m_pPagingControl
	Private m_strURLAction
	Private m_strURLRefreshPage
	Private m_strFilteredQueryString
	Private m_bApproveButtonEnabled
	Private m_bDeclineButtonEnabled
	Private m_strError

	Private m_pPagesToApprove

	' -------------------------------------------------------------------------
	'	[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 ASP utility object for the page
	' -------------------------------------------------------------------------
	Public Property Get ASPUtils
		Set ASPUtils = m_pASPUtils
	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 exposes the start item for rendering the
	'  	page. The start item is an integer index that indicates the index into
	' 	the collection where rendering is to begin (based on the number of
	'	items per page).
	' -------------------------------------------------------------------------
	Public Property Get StartItem
		StartItem = m_nStartItem
	End Property


	' -------------------------------------------------------------------------
	'	[PUBLIC;READ] Property that exposes the end item for rendering the
	'  	page. The end item is an integer index that indicates the index into
	' 	the collection where rendering is to end (based on the number of
	'	items per page).
	' -------------------------------------------------------------------------
	Public Property Get EndItem
		EndItem = m_nEndItem
	End Property


	' -------------------------------------------------------------------------
	'	[PUBLIC;READ] The paging config control provides access to the server-
	'	side control that handles displaying the dropdown list that displays
	'	the number of items per page
	' -------------------------------------------------------------------------
	Public Property Get PagingConfigControl
		Set PagingConfigControl = m_pPagingConfigControl
	End Property


	' -------------------------------------------------------------------------
	'	[PUBLIC;READ] This property exposes the paging control which is
	'	responsible for rendering different items depending on how many are
	'	to be shown per page.
	' -------------------------------------------------------------------------
	Public Property Get PagingControl
		Set PagingControl = m_pPagingControl
	End Property


	' -------------------------------------------------------------------------
	'	[PUBLIC;READ] The Grid control provides the main functionality for
	'	rendering the sortable list of objects.
	' -------------------------------------------------------------------------
	Public Property Get GridControl
		Set GridControl = m_pGridControl
	End Property


	' -------------------------------------------------------------------------
	'	[PUBLIC;READ] This property exposes the URL associated with the action
	'	of clicking the Approve button in the Approval Assistant dialog.
	' -------------------------------------------------------------------------
	Public Property Get URLApproveButton
		' note that both the approve and decline buttons trigger the same
		' action to the same ASP page with the details dictated by the
		' action form element
		URLApproveButton = m_strURLAction
	End Property


	' -------------------------------------------------------------------------
	'	[PUBLIC;READ] This property exposes the URL associated with the action
	'	of clicking the Decline button in the Approval Assistant dialog.
	' -------------------------------------------------------------------------
	Public Property Get URLDeclineButton
		' note that both the approve and decline buttons trigger the same
		' action to the same ASP page with the details dictated by the
		' action form element
		URLDeclineButton = m_strURLAction
	End Property


	' -------------------------------------------------------------------------
	'	[PUBLIC;READ] This property exposes the URL that is used to refresh
	'	the task assistants page.
	' -------------------------------------------------------------------------
	Public Property Get URLRefreshPage
		URLRefreshPage = m_strURLRefreshPage
	End Property


	' -------------------------------------------------------------------------
	'	[PUBLIC;READ] This property represents the original query string used
	'	to access this page minus the uneeded parameters. Examples of unneeded
	'	paramters includes the timestamp (which should not be propagated) and
	'	the page status.
	' -------------------------------------------------------------------------
	Public Property Get FilteredQueryString
		FilteredQueryString = m_strFilteredQueryString
	End Property


	' -------------------------------------------------------------------------
	'	[PUBLIC;READ] This property provides a flag that indicates whether the
	'	Approve button on the Approval Assistant dialog is enabled or disabled.
	' -------------------------------------------------------------------------
	Public Property Get ApproveButtonEnabled
		ApproveButtonEnabled = m_bApproveButtonEnabled
	End Property


	' -------------------------------------------------------------------------
	'	[PUBLIC;WRITE] This property provides a flag that indicates whether the
	'	Approve button on the Approval Assistant dialog is enabled or disabled.
	' -------------------------------------------------------------------------
	Public Property Let ApproveButtonEnabled( bButtonEnabled )
		m_bApproveButtonEnabled = bButtonEnabled
	End Property


	' -------------------------------------------------------------------------
	'	[PUBLIC;READ] This property provides a flag that indicates whether the
	'	Decline button on the Approval Assistant dialog is enabled or disabled.
	' -------------------------------------------------------------------------
	Public Property Get DeclineButtonEnabled
		DeclineButtonEnabled = m_bDeclineButtonEnabled
	End Property


	' -------------------------------------------------------------------------
	'	[PUBLIC;WRITE] This property provides a flag that indicates whether the
	'	Decline button on the Approval Assistant dialog is enabled or disabled.
	' -------------------------------------------------------------------------
	Public Property Let DeclineButtonEnabled( bButtonEnabled )
		m_bDeclineButtonEnabled = bButtonEnabled
	End Property


	' -------------------------------------------------------------------------
	'	[PUBLIC;READ] The pages to approve property exposes a collection
	'	that contains all of the pages the current logged-in user has in
	'	ready to approve (i.e. in a non-published, waiting state).
	' -------------------------------------------------------------------------
	Public Property Get PagesToApprove
		Set PagesToApprove = m_pPagesToApprove
	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_nStartItem = -1
		m_nEndItem = -1
		m_strURLAction = ""
		m_strURLRefreshPage = ""
		m_strFilteredQueryString = ""
		Set m_pASPUtils = Nothing
		Set m_pPagingConfigControl = Nothing
		Set m_pPagingControl = Nothing
		Set m_pGridControl = Nothing
		m_strError = ""

		Set m_pPagesToApprove = Nothing

	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 SetupBrowseContext()
		Call SetupLinksURL()
		Call SetupASPUtils()
		Call SetupCodePage()
		Call SetupCharset()

		' Set up objects to control the view parameters
		Call SetupPagingConfigControl()
		Call SetupPagingControl()
		Call SetupDisplayIndices()
		Call SetupGridControl()

	End Sub  'InitManager


	' -------------------------------------------------------------------------
	'	[PRIVATE] A helper function to retrieve the ASP utility object
	' -------------------------------------------------------------------------
	Private Sub SetupASPUtils()
	
		Set m_pASPUtils = GetInitializedASPUtils()
		
	End Sub  'SetupASPUtils
	
	
	' -------------------------------------------------------------------------
	'	[PRIVATE] A helper function to retrieve the information to be displayed
	'	(pages to approve) from the ROM.
	' -------------------------------------------------------------------------
	Private Sub SetupBrowseContext

		Dim pPagesToApprove
		Set pPagesToApprove = AutoSession.Searches.UserApprovalsPending

		If Not pPagesToApprove Is Nothing Then
			Set m_pPagesToApprove = pPagesToApprove
		End If  'if collection returned

	End Sub  'SetupBrowseContext


	' -------------------------------------------------------------------------
	'	[PRIVATE] Configure the URLs required to perform the approve and
	'	decline operations on the page
	' -------------------------------------------------------------------------
	Private Sub SetupLinksURL

		m_strURLAction = "PagesApproveDecline.asp?NRMODE=Update" & "&" & URLEncodedQueryString()
		m_strURLRefreshPage = GetBaseURL()

	End Sub  'SetupLinksURL


	' -------------------------------------------------------------------------
	' 	[PRIVATE] This function will remove unwanted query string parameters.
	'	The reason for this is the PagesApprove.asp and PagesDecline.asp are
	'	passing special query string for this page to do refresh and page
	'	control handing on boundary case (e.g. delete the last item in page 3
	'	of 3 should put this page to page 2 of 2 after approve or decline)
	' -------------------------------------------------------------------------
	Private Function GetBaseURL()

		' the first part of the URL is the original URL plus a "?" for
		' the query string parameters
		GetBaseURL = Request.ServerVariables( "URL" ) & "?" & FilterQueryString()

		' add an updated timestamp parameter so that the old cached page is
		' not used
		GetBaseURL = GetBaseURL & "&" & IDS_QPARAM_TIMESTAMP_NAME & "=" & CDbl( CDate( now ) )

	End Function  'GetBaseURL



	' -------------------------------------------------------------------------
	' 	[PRIVATE] A helper function to take in the original query string,
	'	filter parameters that should not be propagated or used on this page,
	'	and return the new query string.
	'
	'	@param <implicit> Request.QueryString - original query string to filter
	' -------------------------------------------------------------------------
	Private Function FilterQueryString()

		Dim bFirstParam
		bFirstParam = true

		m_strFilteredQueryString = ""

		Dim pQParam
		Dim strParamName

		For Each pQParam In Request.QueryString

			' mask out some Querystring Params that should not be propagated
			' to the next page, namely timestamp and page status
			strParamName = CStr( pQParam )

			If Not ( ( strParamName = IDS_QPARAM_TIMESTAMP_NAME ) OR _
			   		 ( strParamName = IDS_QPARAM_PAGESTATUS_NAME ) ) Then

				' the "if" below is special case for the first query string
				' parameter because an "&" is not required if only one param
				If bFirstParam Then
					bFirstParam = false
					m_strFilteredQueryString = m_strFilteredQueryString & Server.URLEncode(pQParam) & "=" & Server.URLEncode(Request.QueryString(pQParam))

				Else
					m_strFilteredQueryString = m_strFilteredQueryString & "&" & Server.URLEncode(pQParam) & "=" & Server.URLEncode(Request.QueryString(pQParam))

				End If  'else not first param

			End If  'if first param not page status or timestamp

		Next  'loop over all query string params

		FilterQueryString = m_strFilteredQueryString

	End Function  'FilterQueryString


	' -------------------------------------------------------------------------
	'	[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 to create a new instance of the page
	'	config control and set up its parameters, such as the default number
	'	of items per page.
	' -------------------------------------------------------------------------
	Private Sub SetupPagingConfigControl()

		' create an initialize the new paging config control. Note that the
		' last parameter on the call to InitPagingConfigControl indicates
		' whether the paging value should be persisted across sessions. In
		' this case, yes (True) -- it doesn't do any harm
		Set m_pPagingConfigControl = New CNCPagingConfigControl
		Call m_pPagingConfigControl.InitPagingConfigControl( IDS_PAGINGCONFIG_ID_APPROVALASSISTANT_ITEMSPERPAGE, _
														     IDS_PAGINGCONFIG_APPROVALASSISTANT_DEFAULTITEMSPERPAGE, _
														     True )
	End Sub  'SetupPagingConfigControl


	' -------------------------------------------------------------------------
	'	[PRIVATE] A helper function that configures the paging control with
	'	input from the paging config control. This is the spot where the
	'	paging renderer is attached to the paging control.
	' -------------------------------------------------------------------------
	Private Sub SetupPagingControl()

		Set m_pPagingControl = New CNCPagingControl

		' create a new instance of the paging render callback class. There is
		' nothing special that needs to be done here for rendering pages,
		' so use the common version.
		Dim pNCPagingRenderer
		Set pNCPagingRenderer = New CNCPagingRenderer_Common

		' init the paging control with the renderer, the total number of
		' items present in the collection to be paged, and the number
		' of items per page to display
		Call m_pPagingControl.InitPagingControl( pNCPagingRenderer, m_pPagesToApprove.Count, m_pPagingConfigControl.ItemsPerPage )

		' if a new value was set for items per page or the page was changed
		' (should be the case here since we initialized), then set the
		' current page to the beginning.
		If ( m_pPagingConfigControl.IsSetNewValue = True) Then

			' PagingConfigControl has just been set a new value, set PagingControl back to Page 1
			m_pPagingControl.CurrentPage = 1

		End If  'if paging control set to new value

		' stop propagation of certain querystring parameters on controls that
		' do round-tripping. The page status is used originally for
		' informational purposes when this page is reloaded from the
		' approve/decline handler page. Once we have made use of it, it is
		' no longer required.
		If Request.QueryString( IDS_QPARAM_PAGESTATUS_NAME ) = IDS_QPARAM_PAGESTATUS_VALUE_AFTERPOSTINGACTION Then

			m_pPagingControl.CurrentPage = 1

			Call m_pPagingControl.StopPropagateParameter( IDS_QPARAM_PAGESTATUS_NAME )
			Call m_pPagingConfigControl.StopPropagateParameter( IDS_QPARAM_PAGESTATUS_NAME )

			Call m_pPagingControl.StopPropagateParameter( IDS_QPARAM_TIMESTAMP_NAME )
			Call m_pPagingConfigControl.StopPropagateParameter( IDS_QPARAM_TIMESTAMP_NAME )

		End If  'if after posting action query string param found

	End Sub  'SetupPagingControl


	' -------------------------------------------------------------------------
	'	[PRIVATE] A helper function that configures the start and end item
	'	indexes into the collection of pages in production to determine exactly
	'	what items should be displayed on the screen given the current paging
	'	context.
	' -------------------------------------------------------------------------
	Private Sub SetupDisplayIndices()

		If ( m_pPagesToApprove Is Nothing ) Then
			m_nStartItem = 0
			m_nEndItem = 0

		Else

			' calculate the StartItem
			If ( m_pPagesToApprove.Count = 0 ) Then
				m_nStartItem = 0

			Else
				m_nStartItem = ( m_pPagingControl.CurrentPage - 1 ) * ( m_pPagingConfigControl.ItemsPerPage ) + 1

			End If  'calculate start/end indicies

			' calculate the EndItem
			If ( m_pPagingConfigControl.ItemsPerPage < 0 ) Then

				' -- a minus one value from PagingConfigControl means "All" case
				m_nEndItem = m_pPagesToApprove.Count

			Else

				m_nEndItem = m_pPagingControl.CurrentPage * m_pPagingConfigControl.ItemsPerPage

			End If  'if show all pages

			m_nEndItem = Min( m_pPagesToApprove.Count, EndItem )

		End If  'if no pages in production collection

	End Sub  'SetupDisplayIndicies


	' -------------------------------------------------------------------------
	'	[PRIVATE] This helper function takes care of creating the grid control
	'	and configuring it with the appopriate columns. All of the properties
	'	necessary for displaying postings in production are specified here,
	'	including what columns are sortable.
	' -------------------------------------------------------------------------
	Private Sub SetupGridControl()

		Set m_pGridControl = New CNCGridControl

		' create a new decorator control that is specific to the production
		' manager pages. This control will provide the base rendering
		' service and callback mechanism for displaying the list.
		Dim pGridDecorator
		Set pGridDecorator = New CNCGridDecorator_ApprovalAssistant
		Call m_pGridControl.InitGridControl( IDS_GRIDID_APPROVALASSISTANT, pGridDecorator, m_pPagesToApprove, True )

		' set the display range for the control. Note that the indices are
		' zero-based, thus, the -1 on each of the ranges
		Call m_pGridControl.SetDisplayRange( m_nStartItem - 1, m_nEndItem - 1 )

		' add each of the columns to the grid. The boolean parameter
		' indicates whether the column is sortable or not
		Call m_pGridControl.AddColumn( IDS_GRIDINDEX_SELECT, False)
		Call m_pGridControl.AddColumn( IDS_GRIDINDEX_DISPLAYNAME, True )
		Call m_pGridControl.AddColumn( IDS_GRIDINDEX_GOTO, False)
		Call m_pGridControl.AddColumn( IDS_GRIDINDEX_PATH, True )
		Call m_pGridControl.AddColumn( IDS_GRIDINDEX_STATUS, False )
		Call m_pGridControl.AddColumn( IDS_GRIDINDEX_OWNER, True )
		Call m_pGridControl.AddColumn( IDS_GRIDINDEX_LASTMODIFIED, True )

		m_pGridControl.AscendingIndicatorHTML = "<img valign=bottom border=0 src='" & IDS_PATH_IMAGES_COMMON_ICONS & "iconArrowUp.gif'>"
		m_pGridControl.DescendingIndicatorHTML = "<img valign=bottom border=0 src='" & IDS_PATH_IMAGES_COMMON_ICONS & "iconArrowDown.gif'>"
		m_pGridControl.ColumnHeadAnchorCSSClass = IDS_CSS_APPROVALASSISTANT_HEAVYTEXT1
		m_pGridControl.ItemSpacing = 1
		m_pGridControl.ItemPadding = 5

	End Sub  'SetupGridControl

End Class  'CNCASPPageManager_ApprovalAssistant

%>