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

<!--#include virtual="/NR/System/WBC/Customizable/WBCFuncPagesConfig/UIStringConstants/AuthResourceUIStrings.inc" -->
<!--#include virtual="/NR/System/WBC/Internals/WBCFuncPages/Cross-Browser/ResourceBrowser/Common/ResourceBrowserCommon.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_ViewAsListOrThumbnail.inc" -->

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

<!--#include virtual="/NR/System/WBC/Internals/ServerControls/GridControl/CNCGridControl.inc"-->
<!--#include file="CNCGridDecorator_VideoResourcesBrowse.inc" -->
<!--#include virtual="/NR/System/WBC/Internals/ServerControls/ListControl/CNCListControl.inc"-->
<!--#include virtual="/NR/System/WBC/Internals/WBCFuncPages/Cross-Browser/ResourceBrowser/Authoring/CNCGridDecorator_ThumbnailSort.inc" -->
<!--#include file="CNCListRenderer_VideoResourcesBrowse.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_VideoResources.inc
' Version: 	Microsoft Content Management Server
' Author:	Microsoft Corporation.
' Purpose:	Encapsulate the ASP logic associated with VideoResourcesBrowse.asp
'
' Implements the INCASPPageManager interface:
'	- Sub InitManager()
'	- Property Error
'
' Exposes the following properties:
' 	- Property ASPUtils
'	- Property CodePage
'	- Property Charset
'	- Property CurrentPosting
'	- Property URLSelectImage
'	- Property URLResourceGallery
'	- Property PlaceholderParameters
'	- Property ViewStateControl
'	- Property ResourceGallery
'	- Property Resources
'	- Property StartItem
'	- Property EndItem
'	- Property PagingConfigControl
'	- Property GridControlForThumbnailSort
'	- Property ListControlForViewAsThumbnail
'	- Property GridControlForViewAsList
'	- Property PagingControl
' ********************************************************************

Class CNCASPPageManager_VideoResources
	' -- The Charset ASP page will be running under
	Public Charset

	' -- Object of the current Posting
	Public CurrentPosting

	' -- Some UI and links needed in the ASP page
	Public URLSelectImage
	Public URLResourceGallery

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

	' -- Objects needed in both "View As List" or "View As Thumbnail" cases
	Public ResourceGallery
	Public Resources
	Public StartItem
	Public EndItem
	Public PagingConfigControl
	Public PagingControl
	Public Error

	' -- Object needed when "View As List"
	Public GridControlForViewAsList

	' -- Objects needed when "View As Thumbnail"
	Public GridControlForThumbnailSort
	Public ListControlForViewAsThumbnail

	Private m_strGalleryGUID
	
	' -- Property that exposes the ASP utility object for the page
	Private m_pASPUtils
			
	' -- Property that exposes the CodePage for the page
	Private m_strCodePage

	' -- Placeholder information
	Private m_strPlaceholderName
	Private m_strPlaceholderType
	Private m_bAllowDeskTopRes
	Private m_bImgTag
	Private m_strPlaceholderParameters
	Private m_strMimeType

	' ---- [Private] Standard Class_Initialize
	Private Sub Class_Initialize()
		Set m_pASPUtils = Nothing
		Set CurrentPosting = Nothing
		Set ResourceGallery = Nothing
		Set Resources = Nothing
		URLSelectImage = IDS_PATH_INSERT_VIDEO_URL & IDS_PATH_VIDEO_SELECT_URL
		URLResourceGallery = IDS_PATH_INSERT_VIDEO_URL & IDS_PATH_VIDEO_GALLERIES_URL

		m_strCodePage = ""
		m_strPlaceholderName = ""
		m_strPlaceholderType = ""
		m_bAllowDeskTopRes = False
		m_bImgTag = False
		m_strPlaceholderParameters = ""
		m_strMimeType = IDS_RESTYPE_VIDEO

		Error = ""
	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()
		
		Call SetupBrowseContext()
		' -- Set up URL needed for links in the ASP page
		If (ResourceGallery Is Nothing) Then
			Error = IDS_ERR_GALLERY_NOT_FOUND
			Exit Sub
		End If

		' -- Set up information of the current placeholder
		Call SetupPlaceholderInfo()

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

		' -- Set up the Charset base on the Resource configuration function
		Call SetupCharset()

		' -- Set up all links URL
		Call SetupLinksURL()

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

		' -- Set up objects needed in both views
		Call SetupPagingConfigControl()
		Call SetupPagingControl()
		Call SetupDisplayIndices()

		' -- Given ViewStateControl has been set up, we know whether it is "View As Tree" or "View As List"
		If (ViewStateControl.CurrentState = IDS_STATE_VIEWAS_LIST) Then
			Call SetupForViewAsList()
		Else
			Call SetupForViewAsThumbnail()
		End If
	End Sub

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

	' ---- [Public] get the placeholder name
	Public Property Get PlaceholderName()
		PlaceholderName = m_strPlaceholderName
	End Property

	' ---- [Public] get the placeholder type
	Public Property Get PlaceholderType()
		PlaceholderType = m_strPlaceholderType
	End Property

	' ---- [Public] get the Attach icon value
	Public Property Get ImageTag()
		ImageTag = m_bImgTag
	End Property

	' ---- [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_THINEDITIE
				m_strPlaceholderType = IDS_PHTYPE_THINEDITIE
			Case Else
				m_strPlaceholderType = ""
		End Select
		m_bAllowDeskTopRes = CBool(Request.QueryString( IDS_QPARAM_DESKRES ))
		m_bImgTag = CBool(Request.QueryString( IDS_QPARAM_IMG ))
		m_strPlaceholderParameters = IDS_QPARAM_PHNAME & "=" & Server.URLEncode( m_strPlaceholderName ) & _
									"&" & IDS_QPARAM_PHTYPE & "=" & m_strPlaceholderType & _
									"&" & IDS_QPARAM_DESKRES & "=" & m_bAllowDeskTopRes & _
									"&" & IDS_QPARAM_IMG & "=" & m_bImgTag
	End Sub

	' ---- [Private] Sets up the browsing context (Gallery)
	Private Sub SetupBrowseContext()
		If (Request.QueryString(IDS_QPARAM_GALLERY) = "")  Then
			Set Resources = Nothing
		Else
			m_strGalleryGUID = CStr( Request.QueryString( IDS_QPARAM_GALLERY ) )

			Set ResourceGallery = AutoSession.Searches.GetByGUID( m_strGalleryGUID )
			If (ResourceGallery is Nothing) Then
				Set Resources = Nothing
			Else
				Set Resources = ResourceGallery.Resources

				' filter the resource with image only
				Call Resources.FilterByMimeType( GetMimeType( m_strMimeType ) )
			End If
		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

	' ---- 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( ResourceGallery, m_pASPUTils )
	End Sub
	
	' ---- [Private] Set up the Charset this ASP page will be running under
	Private Sub SetupCharset()
		Charset = GetCharacterSetForResource( ResourceGallery )
	End Sub

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

	' ---- [Private] Set up URL needed for links in the ASP page
	Private Sub SetupLinksURL
		URLSelectImage = IDS_PATH_INSERT_VIDEO_URL & IDS_PATH_VIDEO_SELECT_URL & "?" & CurrentPosting.QueryString & _
							"&" & m_strPlaceholderParameters
		URLResourceGallery = IDS_PATH_INSERT_VIDEO_URL & IDS_PATH_VIDEO_GALLERIES_URL & "?" & CurrentPosting.QueryString & _
							"&" & m_strPlaceholderParameters
	End Sub

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

		Dim pStateControlRendererViewAs
		Set pStateControlRendererViewAs = New CNCStateRenderer_ViewAsListOrThumbnail

		Call ViewStateControl.InitStateControl( IDS_STATE_ID_VIDEO_RESOURCES_VIEWAS, pStateControlRendererViewAs, IDS_STATE_VIEWAS_LIST, True )
		Call ViewStateControl.AddState( IDS_STATE_VIEWAS_LIST )
		Call ViewStateControl.AddState( IDS_STATE_VIEWAS_THUMBNAIL )
	End Sub

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

		Call PagingConfigControl.InitPagingConfigControl( IDS_PAGINGCONFIG_ID_VIDEO_RESOURCES_ITEMSPERPAGE, 5, True )
	End Sub


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

		Dim pNCPagingRenderer
		Set pNCPagingRenderer = New CNCPagingRenderer_Common

		Call PagingControl.InitPagingControl( pNCPagingRenderer, Resources.Count, PagingConfigControl.ItemsPerPage )
		If (PagingConfigControl.IsSetNewValue = True) Then
			' PagingConfigControl has just been set a new value, set PagingControl back to Page 1
			PagingControl.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 StartItem
		If (Resources.Count = 0) Then
			StartItem = 0
		Else
			StartItem = (PagingControl.CurrentPage - 1)*(PagingConfigControl.ItemsPerPage) + 1
		End If
		' -- calculate the EndItem
		If (PagingConfigControl.ItemsPerPage < 0) Then
			' -- a minus one value from PagingConfigControl means "All" case
			EndItem = Resources.Count
		Else
			EndItem = PagingControl.CurrentPage * PagingConfigControl.ItemsPerPage
		End If
		EndItem = Min( Resources.Count, EndItem )
	End Sub

	' ---- [Private] Set up GridControl for displaying Resources as a sortable List
	Private Sub SetupForViewAsList()
		Set GridControlForViewAsList = New CNCGridControl

		Dim pNCGridDecoratorResourcesAsList
		Set pNCGridDecoratorResourcesAsList = New CNCGridDecorator_VideoResourcesBrowse
		Call GridControlForViewAsList.InitGridControl( IDS_GRIDID_VIDEO_RESOURCES, pNCGridDecoratorResourcesAsList, Resources, True )

		Call GridControlForViewAsList.SetDisplayRange( StartItem-1 , EndItem-1 )
		Call GridControlForViewAsList.AddColumn( IDS_GRIDINDEX_DISPLAYNAME, True )
		Call GridControlForViewAsList.AddColumn( IDS_GRIDINDEX_SELECT, False )
		Call GridControlForViewAsList.AddColumn( IDS_GRIDINDEX_TYPE, True )
		Call GridControlForViewAsList.AddColumn( IDS_GRIDINDEX_SIZE, True )
		Call GridControlForViewAsList.AddColumn( IDS_GRIDINDEX_LASTMOD, True )
		Call GridControlForViewAsList.AddColumn( IDS_GRIDINDEX_DESC, False )

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

	End Sub

	' ---- [Private] Set up ListControl for displaying Resources as Thumbnails
	Private Sub SetupForViewAsThumbnail()
		' leveraging the CNCGridControl for the sorting links
		Set GridControlForThumbnailSort = New CNCGridControl

		Dim pGridDecoratorResourcesAsTnSort
		Set pGridDecoratorResourcesAsTnSort = New CNCGridDecorator_ThumbnailSort
		Call GridControlForThumbnailSort.InitGridControl( IDS_GRIDID_VIDEO_RESOURCES, pGridDecoratorResourcesAsTnSort, Resources, True )

		Call GridControlForThumbnailSort.AddColumn( "DisplayName", True )
		Call GridControlForThumbnailSort.AddColumn( "Type", True )
		Call GridControlForThumbnailSort.AddColumn( "Size", True )
		Call GridControlForThumbnailSort.AddColumn( "LastModifiedDate", True )
		GridControlForThumbnailSort.AscendingIndicatorHTML = "<img valign=bottom border=0 src='" & IDS_PATH_IMAGES_COMMON & _
												 IDS_IMG_ICON_ARROW_UP & "'>"
		GridControlForThumbnailSort.DescendingIndicatorHTML = "<img valign=bottom  border=0 src='"  & IDS_PATH_IMAGES_COMMON & _
												 IDS_IMG_ICON_ARROW_DOWN & "'>"
		GridControlForThumbnailSort.ItemSpacing = 5
		GridControlForThumbnailSort.ItemPadding = 5
		GridControlForThumbnailSort.ContentItemsVisible = False

		' the CNCListControl for displaying the list of resources as thumbnail
		Set ListControlForViewAsThumbnail = New CNCListControl

		Dim pNCListRendererResourcesAsThumbnail
		Set pNCListRendererResourcesAsThumbnail = New CNCListRenderer_VideoResourcesBrowse
		Call ListControlForViewAsThumbnail.InitListControl( pNCListRendererResourcesAsThumbnail, Resources )

		Call ListControlForViewAsThumbnail.SetDisplayRange( StartItem-1, EndItem-1 )
		ListControlForViewAsThumbnail.ObjectsPerRow = 2
		ListControlForViewAsThumbnail.ItemSpacing = 1
		ListControlForViewAsThumbnail.ItemPadding = 13

	End Sub

End Class

%>