<!--#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/ResMgntUIStrings.inc" -->
<!--#include virtual="/NR/System/WBC/Internals/WBCFuncPages/Cross-Browser/ResourceBrowser/Management/InternalProgrammingConstants.inc" -->

<!--#include virtual="/NR/System/WBC/Internals/WBCFuncPages/Cross-Browser/ResourceBrowser/Management/ResourceFileIO.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/Management/ResourceProperties/
'			CNCASPPageManager_ResourcePropertiesSave.inc
'
' Version: 	Microsoft Content Management Server
' Author:	Microsoft Corporation.
' Purpose:	Encapsulate the ASP logic associated with ResourceProperties.asp
'
' Implements the INCASPPageManager interface:
'	- Sub InitManager()
'	- Property Error
'
' Exposes the following methods/properties:
'	- Property ASPUtilsObject
'	- Property CodePage
'	- Property Charset
'	- Property Resource
'	- Property URLBack2ResourcePropertiesLink
'	- Property PropertiesSaveSuccess
' ********************************************************************

Class CNCASPPageManager_ResourcePropertiesSave

	' -- The Charset ASP page will be running under
	Public ASPUtilsObject
	Public CodePage
	Public Charset

	' -- objects needed in the ASP page
	Public Resource
	Public URLBack2ResourcePropertiesLink
	Public PropertiesSaveSuccess
	Public Error

	Private m_strResourceGUID

	' ---- [Private] Standard Class_Initialize
	Private Sub Class_Initialize()
		Set ASPUtilsObject = Nothing
		Set Resource = Nothing
		URLBack2ResourcePropertiesLink = "ResourcePropertiesShow.asp"
		Error = ""
	End Sub

	' ---- [Public] InitManager will take care of all programming logic in the ASP page
	Public Sub InitManager()
		' -- set up Gallery context and its associated MLS info
		Call SetupBrowseContext()
		If (Resource Is Nothing) Then
			Error = IDS_ERR_RESOURCE_NOT_FOUND
			Exit Sub
		End If
		Call SetupMLSInfo()

		' -- Set up URL needed for links in the ASP page
		Call SetupLinksURL()

		Call ReadAndSetResourceContent()
	End Sub

	' ---- [Private] Sets up the browsing context (Resource)
	Private Sub SetupBrowseContext()
		m_strResourceGUID = GetGuidFromQueryString(IDS_QPARAM_RESOURCE)
		Set Resource = AutoSession.Searches.GetByGUID( m_strResourceGUID )
	End Sub

	' ---- [Private] Set up the MLS info this ASP page will be running under
	Private Sub SetupMLSInfo()
		Set ASPUtilsObject = GetInitializedASPUtils()
		CodePage = GetCodePageForResource( Resource.Parent, ASPUtilsObject )
		Charset = GetCharacterSetForResource( Resource.Parent )
	End Sub

	' ---- [Private] Set up URL needed for links in the ASP page
	Private Sub SetupLinksURL()
		URLBack2ResourcePropertiesLink = "ResourcePropertiesShow.asp?" & IDS_QPARAM_RESOURCE & "=" & m_strResourceGUID
	End Sub

	' ---- [Private] Read data from the form and set properties on Resource object
	Private Sub ReadAndSetResourceContent()
		PropertiesSaveSuccess = False

		' -- there could be lots of places that can generate errors here
		On Error Resume Next
		Call Autosession.ClearLastError()

		Dim pASPUtils, pFormReader
		Dim lCodePage

		' -- set up the FormReader
		Set pASPUtils = GetInitializedASPUtils()
		lCodePage = GetCodePageForResource( Resource.Parent, pASPUtils )
		Set pFormReader = GetResMgntFormReaderSafe( False, lCodePage )
		If (Err.Number <> 0) Then
			Error = IDS_ERR_INIT_FORMREADER
			Call CleanupRequestStream()
			Exit Sub
		End If

		' -- read Name, DisplayName, and Description from FormReader and set
		'	 their values into the Resource
		' 	 Refer to TRACK #5053 as to why we need to do the empty string
		'	 check before setting DisplayName and Description
		Resource.Name = pFormReader.Form(IDS_FORM_RESOURCE_NAME)
		If pFormReader.Form(IDS_FORM_RESOURCE_DISPLAY_NAME) = "" Then
			Resource.DisplayName = ""
		Else
			Resource.DisplayName = pFormReader.Form(IDS_FORM_RESOURCE_DISPLAY_NAME)
		End if
		If pFormReader.Form(IDS_FORM_RESOURCE_DESCRIPTION) = "" Then
			Resource.Description = ""
		Else
			Resource.Description = pFormReader.Form(IDS_FORM_RESOURCE_DESCRIPTION)
		End if

		' -- check if any properties setting result in errors
		If (AutoSession.LastError.ID <> 0) Then
			Error = IDS_ERR_RESOURCE_SETPROPS
			Call AutoSession.RollbackAll()
			Call CleanupRequestStream()
			Exit Sub
		End If
		
		' -- everything seems ok, attempt to commit
		Call AutoSession.CommitAll()
		If (AutoSession.LastError.ID <> 0) Then
			Error = IDS_ERR_RESOURCE_SETPROPS
			Call CleanupRequestStream()
		End if

		' -- set success flag if it passes all the calls without error
		PropertiesSaveSuccess = True
	End Sub


End Class

%>