<!--#include virtual="/NR/System/WBC/Internals/Main/WBCApp.inc"-->
<!-- #include virtual="/NR/System/WBC/Customizable/WBCFuncPagesConfig/MLSDisplayConfig/ResourceBrowserConfig.inc" -->
<!--#include virtual="/NR/System/WBC/Internals/WBCFuncPages/Cross-Browser/ResourceBrowser/Common/ResourceBrowserCommon.inc" -->
<!--#include virtual="/NR/System/WBC/Customizable/WBCFuncPagesConfig/UIStringConstants/AuthResourceUIStrings.inc" -->
<!--#include virtual="/NR/System/WBC/Internals/WBCFuncPages/Cross-Browser/ResourceBrowser/Authoring/AuthResourceConstants.inc" -->

<!--#include virtual="/NR/System/WBC/Internals/ServerControls/StateControl/CNCStateControl.inc"-->
<!--#include virtual="/NR/System/WBC/Internals/WBCFuncPages/Cross-Browser/ResourceBrowser/Authoring/CNCStateRenderer_ViewAsTreeOrList.inc" -->

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

<!--#include virtual="/NR/System/WBC/Internals/ServerControls/TreeControl/CNCTreeControl.inc"-->
<!--#include virtual="/NR/System/WBC/Internals/ServerControls/TreeControl/CNCTreeDom_NRResGalleries.inc"-->
<!--#include virtual="/NR/System/WBC/Internals/WBCFuncPages/Cross-Browser/ResourceBrowser/Authoring/CNCTreeRenderer_GalleriesBrowse.inc" -->

<!--#include virtual="/NR/System/WBC/Internals/ServerControls/GridControl/CNCGridControl.inc"-->
<!--#include virtual="/NR/System/WBC/Internals/WBCFuncPages/Cross-Browser/ResourceBrowser/Authoring/CNCGridDecorator_GalleriesBrowse.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/ResourceBrowser/
'			Authoring/AttachmentBrowser/CNCASPPageManager_AttachmentGalleries.inc
' Version: 	Microsoft Content Management Server
' Author:	Microsoft Corporation.
' Purpose:	Encapsulate the ASP logic associated with ImageGalleriesBrowse.asp
'
' Implements the INCASPPageManager interface:
'	- Sub InitManager()
'
' Exposes the following properties:
' 	- Property ASPUtils
'	- Property CodePage
'	- Property Charset
'	- Property CurrentPosting
'	- Property URLResources
'	- Property URLSelectImage
'	- Property PlaceholderParameters
'	- Property MimeType
'	- Property ViewStateControl
'	- Property TreeControl
'	- Property ResourceGalleries
'	- Property GridStartItem
'	- Property GridEndItem
'	- Property GridPagingConfigControl
'	- Property GridControl
'	- Property GridPagingControl
' ********************************************************************


Class CNCASPPageManager_AttachmentGalleries
	
	' -- Object of the current Posting
	Public CurrentPosting

	' -- UI Links URL
	Public URLSelectImage
	Public URLResources

	' -- Object that exposes the View state (Tree or List)
	Public ViewStateControl

	' -- Object needed when "View As Tree"
	Public TreeControl

	' -- Objects needed when "View As List"
	Public ResourceGalleries
	Public GridStartItem
	Public GridEndItem
	Public GridPagingConfigControl
	Public GridControl
	Public GridPagingControl

	' -- Property that exposes the ASP utility object for the page
	Private m_pASPUtils
	
	' -- Property that exposes the CodePage for the page
	Private m_strCodePage
		
	' -- Property that exposes the Charset for the page
	Private m_strCharset
	
	' -- Placeholder information
	Private m_strPlaceholderName
	Private m_strPlaceholderType
	Private m_bAllowDeskTopRes
	Private m_bAttachIcon
	Private m_bVideo
	Private m_strPlaceholderParameters
	Private m_strMimeType

	' ---- [Private] Class standard initialization routine
	Private Sub Class_Initialize()
		Set m_pASPUtils = Nothing
		Set CurrentPosting = Nothing
		Set ViewStateControl= Nothing
		Set TreeControl= Nothing
		Set ResourceGalleries = Nothing
		Set GridStartItem = Nothing
		Set GridEndItem = Nothing
		Set GridPagingConfigControl = Nothing
		Set GridControl = Nothing
		Set GridPagingControl = Nothing
		URLSelectImage = IDS_PATH_INSERT_ATTACHMENT_URL & IDS_PATH_ATTACHMENT_SELECT_URL
		URLResources = IDS_PATH_INSERT_ATTACHMENT_URL & IDS_PATH_ATTACHMENT_RESOURCES_URL

		m_strCodePage = ""
		m_strCharset = ""
		m_strPlaceholderName = ""
		m_strPlaceholderType = ""
		m_bAllowDeskTopRes = False
		m_bAttachIcon = False
		m_bVideo = False
		m_strMimeType = ""
		m_strPlaceholderParameters = ""
	End Sub

	' ---- [Public] InitManaer will take care of all programming logic in the ASP page
	Public Sub InitManager()
		' -- Set up ASP utility object
		Call SetupASPUtils()
		
		' -- Set up CodePage
		Call SetupCodePage()
		
		' -- Set up Charset
		Call SetupCharset()
		
		' -- Set up information of the current placeholder
		Call SetupPlaceholderInfo()

		' -- Set up current Posting object
		Call SetupCurrentPosting()

		' -- Set up the UI link URL
		Call SetupLinksURL()

		' -- Set up ViewStateControl for the "View As Tree" and "View As List" state
		Call SetupViewStateControl()

		' -- Given ViewStateControl has been set up, we know whether it is "View As Tree" or "View As List"
		If (ViewStateControl.CurrentState = IDS_STATE_VIEWAS_TREE) Then
			Call SetupTreeControl()
		Else
			Call SetupGalleriesCollection()
			Call SetupPagingConfigControl()
			Call SetupPagingControl()
			Call SetupDisplayIndices()
			Call SetupGridControl()
		End If
	End Sub

	' --- Property that exposes the ASP Utility object for the page
	Public Property Get ASPUtils()
		Set ASPUtils = m_pASPUtils
	End Property
	
	' --- Property that exposes the codepage for the page
	Public Property Get CodePage()
		CodePage = m_strCodePage
	End Property
	
	' --- Property that exposes the charset for the page
	Public Property Get CharSet()
		CharSet = m_strCharSet
	End Property

	' ---- [Public] get the placeholder information parameter
	Public Property Get PlaceholderParameters()
		PlaceholderParameters = m_strPlaceholderParameters
	End Property

	' ---- [Public] get the type of filter the resources
	Public Property Get MimeType()
		MimeType = m_strMimeType
	End Property
	
	' ---- A helper function to retrieve the ASP utility object
	Private Sub SetupASPUtils()
		Set m_pASPUtils = GetInitializedASPUtils()			
	End Sub
	
	' ---- 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 = GetCodePageForResource( Nothing, m_pASPUTils )
	End Sub
		
	' ---- 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 = GetCharacterSetForResource( Nothing )
	End Sub

	' ---- [Private] Retrieve Placeholder name from Querystring in a XSS safe fashion
	Private Function GetPlaceholderName()
		On Error Resume Next
		Dim pPlaceholder

		Set pPlaceholder = AutoSession.ThisPosting.Placeholders( CStr(Request.QueryString(IDS_QPARAM_PHNAME)) )
		If (pPlaceholder Is Nothing) Then
			GetPlaceholderName = ""
		Else
			GetPlaceholderName = CStr(Request.QueryString(IDS_QPARAM_PHNAME))
		End If
	End Function
	
	' ---- [Private] Set up information of the current placeholder
	Private Sub SetupPlaceholderInfo()
		m_strPlaceholderName = GetPlaceholderName()
		' restrict value of m_strPlaceholderType to guard against XSS attack
		Select Case Request.QueryString( IDS_QPARAM_PHTYPE )
			Case IDS_PHTYPE_MULTIPURPOSE
				m_strPlaceholderType = IDS_PHTYPE_MULTIPURPOSE
			Case IDS_PHTYPE_SINGLEATTACHMENT
				m_strPlaceholderType = IDS_PHTYPE_SINGLEATTACHMENT
			Case IDS_PHTYPE_THINEDITIE
				m_strPlaceholderType = IDS_PHTYPE_THINEDITIE
			Case Else
				m_strPlaceholderType = ""
		End Select
		m_bAllowDeskTopRes = CBool(Request.QueryString( IDS_QPARAM_DESKRES ))
		m_bAttachIcon = CBool(Request.QueryString( IDS_QPARAM_ATTACHICON ))
		m_bVideo = CBool(Request.QueryString( IDS_QPARAM_VIDEO ))

		m_strPlaceholderParameters = IDS_QPARAM_PHNAME & "=" & Server.URLEncode( m_strPlaceholderName ) & _
									"&" & IDS_QPARAM_PHTYPE & "=" & m_strPlaceholderType & _
									"&" & IDS_QPARAM_DESKRES & "=" & m_bAllowDeskTopRes & _
									"&" & IDS_QPARAM_ATTACHICON & "=" & m_bAttachIcon & _
									"&" & IDS_QPARAM_VIDEO & "=" & m_bVideo
	End Sub

	' ---- [Private] Sets up the current Posting object
	Private Sub SetupCurrentPosting()
		Set CurrentPosting = AutoSession.ThisPosting
	End Sub

	' ---- [Private] Sets up the UI link URL
	Private Sub SetupLinksURL()
		URLSelectImage = IDS_PATH_INSERT_ATTACHMENT_URL & IDS_PATH_ATTACHMENT_SELECT_URL & "?" & CurrentPosting.QueryString & _
						"&" & m_strPlaceholderParameters
		URLResources = IDS_PATH_INSERT_ATTACHMENT_URL & IDS_PATH_ATTACHMENT_RESOURCES_URL
	End Sub

	' ---- [Private] Set up ViewStateControl for the "View As Tree" and "View As List" state
	Private Sub SetupViewStateControl()
		Set ViewStateControl = New CNCStateControl

		Dim pStateControlRendererViewAs
		Set pStateControlRendererViewAs = New CNCStateRenderer_ViewAsTreeOrList

		Call ViewStateControl.InitStateControl( IDS_STATE_ID_ATTACHMENT_GALLERIES_VIEWAS, pStateControlRendererViewAs, IDS_STATE_VIEWAS_LIST, True )
		Call ViewStateControl.AddState( IDS_STATE_VIEWAS_TREE )
		Call ViewStateControl.AddState( IDS_STATE_VIEWAS_LIST )
	End Sub

	' ---- [Private] Set up TreeControl for displaying Image Resource Galleries as a Tree
	Private Sub SetupTreeControl()
		Set TreeControl = New CNCTreeControl

		Dim pNCTreeDom, pNCTreeRenderer
		Set pNCTreeDom = New CNCTreeDom_NRResGalleries
		Set pNCTreeRenderer = New CNCTreeRenderer_GalleriesBrowse
		If Request.QueryString("FreshTree") = "True" Then
			Call TreeControl.InitTreeControl( IDS_TREE_ID_ATTACHMENT_GALLERIES, pNCTreeDom, pNCTreeRenderer, True )
			Call TreeControl.PropagateParameter( "FreshTree", "False" )
		Else
			Call TreeControl.InitTreeControl( IDS_TREE_ID_ATTACHMENT_GALLERIES, pNCTreeDom, pNCTreeRenderer, False )
		End If
		Call TreeControl.PropagateParameter( IDS_QPARAM_GALLERY, "" )

		TreeControl.DisplayLeafs = False
		TreeControl.IndentWidth = 35
		TreeControl.NodeSpacing = 5
		TreeControl.NodePadding = 2
	End Sub

	' ---- [Private] Sets up the ResourceGalleries collection
	Private Sub SetupGalleriesCollection()
		Set ResourceGalleries = AutoSession.Searches.UserResourceGalleries
	End Sub

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

		Call GridPagingConfigControl.InitPagingConfigControl( IDS_PAGINGCONFIG_ID_ATTACHMENT_GALLERIES_ITEMSPERPAGE, 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, ResourceGalleries.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()
		' -- calculate the GridStartItem
		If (ResourceGalleries.Count = 0) Then
			GridStartItem = 0
		Else
			GridStartItem = (GridPagingControl.CurrentPage - 1)*(GridPagingConfigControl.ItemsPerPage) + 1
		End If
		' -- calculate the GridEndItem
		If (GridPagingConfigControl.ItemsPerPage < 0) Then
			' -- a minus one value from PagingConfigControl means "All" case
			GridEndItem = ResourceGalleries.Count
		Else
			GridEndItem = GridPagingControl.CurrentPage * GridPagingConfigControl.ItemsPerPage
		End If
		GridEndItem = Min( ResourceGalleries.Count, GridEndItem )
	End Sub

	' ----
	Private Sub SetupGridControl()
		Set GridControl = New CNCGridControl

		Dim pNCGridDecorator
		Set pNCGridDecorator = New CNCGridDecorator_GalleriesBrowse

		Call GridControl.InitGridControl( IDS_GRIDID_ATTACHMENT_GALLERIES, pNCGridDecorator, ResourceGalleries, True )
		Call GridControl.SetDisplayRange( GridStartItem-1 , GridEndItem-1 )
		Call GridControl.AddColumn( IDS_GRIDINDEX_NAME, True )
		Call GridControl.AddColumn( IDS_GRIDINDEX_PATH, True )
		Call GridControl.AddColumn( IDS_GRIDINDEX_LASTMOD, True )
		Call GridControl.AddColumn( IDS_GRIDINDEX_DESC, False )

		GridControl.AscendingIndicatorHTML = "<img valign=bottom border=0 src='" & IDS_PATH_IMAGES_COMMON & _
												 IDS_IMG_ICON_ARROW_UP & "'>"
		GridControl.DescendingIndicatorHTML = "<img valign=bottom  border=0 src='"  & IDS_PATH_IMAGES_COMMON & _
												 IDS_IMG_ICON_ARROW_DOWN & "'>"
		GridControl.ColumnHeadAnchorCSSClass = "WBC_styclsHeavyTextColor1"
		GridControl.ItemSpacing = 1
		GridControl.ItemPadding = 5

	End Sub

End Class

%>