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

<!--#include virtual="/NR/System/WBC/Customizable/WBCFuncPagesConfig/UIStringConstants/PageCreationWizardUIStrings.inc" -->
<!--#include virtual="/NR/System/WBC/Customizable/WBCFuncPagesConfig/MLSDisplayConfig/PageCreationWizardConfig.inc" -->

<!--#include virtual="/NR/System/WBC/Internals/WBCFuncPages/Cross-Browser/PageCreationWizard/EntryProgrammingConstants.inc" -->
<!--#include virtual="/NR/System/WBC/Internals/WBCFuncPages/Cross-Browser/PageCreationWizard/InternalProgrammingConstants.inc" -->

<!--#include virtual="/NR/System/WBC/Internals/ServerControls/PagingConfigControl/CNCPagingConfigControl.inc"-->

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

<!--#include virtual="/NR/System/WBC/Internals/ServerControls/PagingControl/CNCPagingControl.inc"-->
<!--#include virtual="/NR/System/WBC/Internals/ServerControls/PagingControl/CNCPagingRenderer_Common.inc"-->

<!-- #include virtual="/NR/System/WBC/Internals/Integration/InternalHooks/URLGenerationHooks/PostingCreationHooks.inc" -->
<!-- #include virtual="/NR/System/WBC/Customizable/Hooks/URLGenerationHooks/PostingCreationHooks.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/PageCreationWizard/
'			TemplateBrowse/CNCASPPageManager_TemplateBrowse.inc
' Version: 	Microsoft Content Management Server
' Author:	Microsoft Corporation.
' Purpose:	Encapsulate the ASP logic associated with TemplateBrowse.asp
'
' Implements the INCASPPageManager interface:
'	- Sub InitManager()
'
' Exposes the following properties:
'	- Property CreatingConnectedPage
'	- Property CurrentPageNode
'	- Property CurrentChannelNode
'	- Property CurrentTemplateGalleryNode
'	- Property GridControlForDisplay
'	- Property Templates
'	- Property GridStartItem
'	- Property GridEndItem
'	- Property GridPagingConfigControl
'	- Property GridControl
'	- Property GridPagingControl
'	- Property Error
'   - Property URLGoBackGalleries
'	- Property URLGoBackChannel
'	- Property ASPUtilsObject
'	- Property Charset
'	- Property CodePage
' ********************************************************************
Class CNCASPPageManager_TemplateBrowse

	' -- Flag that says whether we are creating simple / connected page
	Public CreatingConnectedPage

	' -- Page Node
	Public CurrentPageNode

	' -- Channel Node
	Public CurrentChannelNode

	' -- Template Gallery Node
	Public CurrentTemplateGalleryNode

	' -- Template Sort
	Public GridControlForDisplay

	Public Templates
	Public GridStartItem
	Public GridEndItem
	Public GridPagingConfigControl
	Public GridControl
	Public GridPagingControl

	Public StartItem
	Public EndItem

	' -- Error Handling
	Public Error

	' -- Go Back Galleries URL
	Public URLGoBackGalleries

	' -- Go Back Channel URL
	Public URLGoBackChannel

	' -- MLS info
	Public ASPUtilsObject

	' -- CharSet
	Public Charset

	' -- CodePage
	Public CodePage




	' ---- [Private] Class standard initialization routine
	Private Sub Class_Initialize()
		Set Templates = Nothing
		GridStartItem = 0
		GridEndItem = 0
		Set GridPagingConfigControl = Nothing
		Set GridControl = Nothing
		Set GridPagingControl = Nothing
		Set CurrentPageNode = Nothing
		Set CurrentChannelNode = Nothing
		Set CurrentTemplateGalleryNode = Nothing
		Set ASPUtilsObject = Nothing
		
		Dim strConnectedPageQueryString
		Dim strPageGuid
		Dim strChannelGuid
		Dim bPageGuidError
		
		strChannelGuid = GetChannelGuidFromQueryString()
		If 	strChannelGuid = "" Then
			Error = IDS_UI_ERR_CHANNEL_NOT_FOUND
			Exit Sub
		End If
		strConnectedPageQueryString = ""
		
		strPageGuid = GetConnectedPageGuidFromQueryString(bPageGuidError)
		If bPageGuidError = True Then
			Error = IDS_UI_ERR_PAGE_NOT_FOUND
			Exit Sub
		Else
			strConnectedPageQueryString = IDS_QSTR_PAGECREATIONWIZARD_CONNECTEDPAGE & "=" & strPageGuid & "&"	
		End If
		
		URLGoBackChannel = "../ChannelsBrowse/ChannelsBrowse.asp?" & _
						IDS_QPARAM_NRMODE & "=" & IDS_NRMODE_UNPUBLISHED & "&" & _
						strConnectedPageQueryString & _
						IDS_QSTR_PAGECREATIONWIZARD_DESTINATIONCHANNEL & "=" & strChannelGuid

		' -- call Internal hook
		Call OnInternalCustomizePostingCreationDlgURL( URLGoBackChannel )

		' -- call external Customizable Hook
		Call OnCustomizePostingCreationDlgURL( URLGoBackChannel )

		Dim strTemplateGalleryGuid
		strTemplateGalleryGuid = GetGuidFromQueryString(IDS_QSTR_PAGECREATIONWIZARD_TEMPLATEGALLERY)
		If (strTemplateGalleryGuid = "") Then
			Error = IDS_UI_ERR_TEMPLATE_GALLERY_NOT_FOUND
			Exit Sub
		End If
		URLGoBackGalleries = "../TemplateGalleriesBrowse/TemplateGalleriesBrowse.asp?" & _
						IDS_QPARAM_NRMODE & "=" & IDS_NRMODE_UNPUBLISHED & "&" & _
						strConnectedPageQueryString & _
						IDS_QSTR_PAGECREATIONWIZARD_DESTINATIONCHANNEL & "=" & strChannelGuid & "&" & _
						IDS_QSTR_PAGECREATIONWIZARD_TEMPLATEGALLERY & "=" & strTemplateGalleryGuid

		' -- call Internal Hook
		Call OnInternalCustomizePostingCreationDlgURL( URLGoBackGalleries )

		' -- call external Customizable Hook
		Call OnCustomizePostingCreationDlgURL( URLGoBackGalleries )

		Error = ""
	End Sub

	' ---- [Public] InitManaer will take care of all programming logic in the ASP page
	Public Sub InitManager()
		' -- Set up Boolean control to tell if we are creating a connected page or not
		'    and return URL
		Call SetupBooleanCreatingConnectedPage

		' -- Set up Required Object so we know if we are missing any query string
		Call SetupRequiredObject

		If Error = "" Then
			' -- Setup MLS Info
			Call SetupMLSInfo()

			Call SetupTemplateCollection()
			Call SetupPagingConfigControl()
			Call SetupPagingControl()
			Call SetupDisplayIndices()
			Call SetupGridControl()
		End If

	End Sub

	' ---- [Private] Setup boolean so TemplateGalleriesBrowse.asp can tell if we
	'                are creating a  Simple page / connected page
	Private Sub SetupBooleanCreatingConnectedPage
		Dim strPageGuid
		Dim strChannelGuid

		strPageGuid = Request.QueryString(IDS_QSTR_PAGECREATIONWIZARD_CONNECTEDPAGE)

		If strPageGuid <> "" Then
			CreatingConnectedPage = True
		Else
			CreatingConnectedPage = False
		End If
	End Sub

	' ---- [Private] Create all the objects that QPARAM carries
	'
	Private Sub SetUpRequiredObject
		Dim strPageGuid
		Dim strChannelGuid
		Dim strTemplateGalleryGuid

		strChannelGuid = GetGuidFromQueryString(IDS_QSTR_PAGECREATIONWIZARD_DESTINATIONCHANNEL)
		strTemplateGalleryGuid = GetGuidFromQueryString(IDS_QSTR_PAGECREATIONWIZARD_TEMPLATEGALLERY)

		If	strChannelGuid = "" Then
			Error = IDS_UI_ERR_CHANNEL_NOT_FOUND
		ElseIf strTemplateGalleryGuid = "" Then
			Error = IDS_UI_ERR_TEMPLATE_GALLERY_NOT_FOUND
		Else
			Set CurrentChannelNode = AutoSession.Searches.GetByGUID(strChannelGuid)
			Set CurrentTemplateGalleryNode = AutoSession.Searches.GetByGUID(strTemplateGalleryGuid)
			If (CurrentChannelNode is Nothing) Then
				Error = IDS_UI_ERR_CHANNEL_NOT_FOUND
			ElseIf (CurrentTemplateGalleryNode is Nothing) Then
				Error = IDS_UI_ERR_TEMPLATE_GALLERY_NOT_FOUND
			End If
		End If

		'If there is no eror then we chk for page guid
		If Error = "" Then

			'We only want to do chking if we know we have a connected page.
			'If simple page, these query string parameter will be missing
			If CreatingConnectedPage Then

				strPageGuid = GetGuidFromQueryString(IDS_QSTR_PAGECREATIONWIZARD_CONNECTEDPAGE)

				If strPageGuid = "" Then
					Error = IDS_UI_ERR_PAGE_NOT_FOUND
				Else
					Set CurrentPageNode = AutoSession.Searches.GetByGUID(strPageGuid)
					If (CurrentPageNode is Nothing) Then
						Error = IDS_UI_ERR_PAGE_NOT_FOUND
					End If
				End If
			End If
		End If

	End Sub


	' ---- [Private] Sets up the TemplateGalleries collection
	Private Sub SetupTemplateCollection()
		If Not (CurrentTemplateGalleryNode Is Nothing) Then
			Set Templates = CurrentTemplateGalleryNode.templates
		End If
	End Sub

	' ---- [Private] Sets up GridPagingConfigControl
	Private Sub SetupPagingConfigControl()
		Set GridPagingConfigControl = New CNCPagingConfigControl

		Call GridPagingConfigControl.InitPagingConfigControl( IDS_PAGINGCONFIG_ID_PAGECREATIONWIZARD_TEMPLATE, 5, True )
	End Sub


	' ---- [Private] Set up the GridPagingControl, with input from the GridPagingConfigControl
	Private Sub SetupPagingControl()
		Set GridPagingControl = New CNCPagingControl

		Dim pNCPagingRenderer
		Set pNCPagingRenderer = New CNCPagingRenderer_Common

		Call GridPagingControl.InitPagingControl( pNCPagingRenderer, Templates.Count, GridPagingConfigControl.ItemsPerPage )
		If (GridPagingConfigControl.IsSetNewValue = True) Then
			' PagingConfigControl has just been set a new value, set PagingControl back to Page 1
			GridPagingControl.CurrentPage = 1
		End If

	End Sub

	' ---- [Private] Set up indices which indicate the range of items to be displayed in the Grid
	Private Sub SetupDisplayIndices()
		If Templates.Count = 0 Then
			GridStartItem = 0
		Else
			GridStartItem = (GridPagingControl.CurrentPage - 1)*(GridPagingConfigControl.ItemsPerPage) + 1
		End If
		If (GridPagingConfigControl.ItemsPerPage < 0) Then
			' -- a minus one value from PagingConfigControl means "All" case
			GridEndItem = Templates.Count
		Else
			GridEndItem = GridPagingControl.CurrentPage * GridPagingConfigControl.ItemsPerPage
		End If
		GridEndItem = Min(Templates.Count, GridEndItem)
	End Sub

	' ---- [Private] Set up GridControl
	Private Sub SetupGridControl()

		Dim pNCGridDecoratorTemplatesAsList

		Set GridControlForDisplay = New CNCGridControl
		Set pNCGridDecoratorTemplatesAsList = New CNCGridDecorator_TemplateBrowse

		Call GridControlForDisplay.InitGridControl( IDS_GRIDID_PAGECREATIONWIZARD_TEMPLATES, pNCGridDecoratorTemplatesAsList, Templates, True )

		Call GridControlForDisplay.SetDisplayRange( GridStartItem-1 , GridEndItem-1 )
		Call GridControlForDisplay.AddColumn( IDS_GRIDINDEX_PAGECREATIONWIZARD_TEMPLATE, True )
		Call GridControlForDisplay.AddColumn( IDS_GRIDINDEX_PAGECREATIONWIZARD_SELECT, False )
		Call GridControlForDisplay.AddColumn( IDS_GRIDINDEX_PAGECREATIONWIZARD_LASTMOD, True )

		GridControlForDisplay.ColumnHeadAnchorCSSClass = "WBC_styclsHeavyTextColor1"
		GridControlForDisplay.ItemSpacing = 1
		GridControlForDisplay.ItemPadding = 5

	End Sub

	' ---- [Private] Set up the MLS info this ASP page will be running under
	Private Sub SetupMLSInfo()
		Set ASPUtilsObject = GetInitializedASPUtils()

		' -- call functions in WBC/Customizable/MLSDisplayConfig/PageCreationWizardConfig.inc
		'	 to determine CodePage and Charset setting
		CodePage = GetCodePageForPageCreationWizard( CurrentChannelNode, CurrentPageNode, ASPUtilsObject )
		Charset = GetCharacterSetForPageCreationWizard( CurrentChannelNode, CurrentPageNode )
	End Sub


End Class

%>
