<!--#include virtual="/NR/System/WBC/Internals/Main/WBCApp.inc"-->
<!--#include virtual="/NR/System/WBC/Internals/WBCFuncPages/Cross-Browser/PageOperation/EditMode/InternalProgrammingConstants.inc" -->
<!--#include virtual="/NR/System/WBC/Internals/WBCFuncPages/Cross-Browser/PageOperation/EditMode/EntryProgrammingConstants.inc" -->
<!--#include virtual="/NR/System/WBC/Customizable/WBCFuncPagesConfig/UIStringConstants/PageOperationUIStrings.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/PageOperation/
'			/EditMode/PageCopy/PageCopyAcceptor/CNCASPPageManager_PageCopyAcceptor.inc
' Version: 	Microsoft Content Management Server
' Author:	Microsoft Corporation.
' Purpose:	Encapsulate the ASP logic associated with PageCopyAcceptor.asp
'
' Implements the INCASPPageManager interface:
'	- Sub InitManager()
'
' Exposes the following properties:
'	- Property URLGoBackEditModeLink
'	- Property DestinationChannelNode
'	- Property CurrentPostingNode
'	- Property Charset
' 	- Property Error
' ********************************************************************

Class CNCASPPageManager_PageCopyAcceptor

	'The URL that is going to go back to the edit mode when everything is successful
	Public URLGoBackEditModeLink

	'The destination channel node will be hosting a new copy of the posting
	Public DestinationChannelNode

	'The posting that is going to be copying to the new channel
	Public CurrentPostingNode

	'CharSet
	Public Charset

	' -- Error code
	Public Error


	' ---- [Private] Class standard initialization routine
	Private Sub Class_Initialize()
		URLGoBackEditModeLink = "#"
		Set DestinationChannelNode = Nothing
		Set CurrentPostingNode = Nothing
		Error = ""
	End Sub


	' ---- [Public] InitManager will take care of all programming logic in the ASP page
	Public Sub InitManager()
		Dim pPostingAfterCopy

		Call SetupCharset

		Call ReadQueryString

		If Error = "" Then
			Call ReadFormElement
		End If

		If Error = "" Then
			Call DoCopy(pPostingAfterCopy)
		End If

		If Error = "" Then
			Call SetupEditModeURL
		End If

	End Sub

	' ---- [Private] Get the charset for multi-lingual display
	Private Sub SetupCharset
		Charset = AutoSession.ThisPosting.Charset
	End Sub

	' ---- [Private] Get the query string to make sure the pass in posting guid is an existing posting
	Private Sub ReadQueryString()
		Dim strPostingGUID
		Dim pPosting

		strPostingGUID = Request.QueryString(IDS_QSTR_PAGEOPERATIONEDIT_SOURCEPAGE)

		If strPostingGUID = "" Then
			Error = IDS_UI_PAGE_DOES_NOT_EXIST
		Else
			Set CurrentPostingNode = AutoSession.Searches.GetByGUID(strPostingGuid)
			If CurrentPostingNode Is Nothing Then
				Error = IDS_UI_PAGE_DOES_NOT_EXIST
			End If
		End If
	End Sub

	' ---- [Private] Get the channel guid that the user has selected. This channel is going to be the channel that
	'                the page will copy to
	Private Sub ReadFormElement()

		Dim pFormReader
		Dim strChannelGuid

		Set pFormReader = GetInitializedFormReaderSafe(False)

		If (pFormReader.Form.Count <= 0) Then
			Error = IDS_UI_ERROR_NO_ITEMS_IN_FORM
		End If

		strChannelGuid = pFormReader.Form(IDS_FORM_CHANNEL_GUID)

		If strChannelGuid = "" Then
			Error = IDS_UI_ERROR_CHANNEL_NOT_FOUND
		Else
			Set DestinationChannelNode = AutoSession.Searches.GetByGUID(strChannelGuid)
			If DestinationChannelNode Is Nothing Then
				Error = IDS_UI_ERROR_CHANNEL_NOT_FOUND
			End If
		End If

	End Sub

	' ---- [Private]
	Private Sub DoCopy(pPostingAfterCopy)
		'In case something in here blows up
		On Error Resume Next
		Call AutoSession.ClearLastError()

		Set pPostingAfterCopy = CurrentPostingNode.CopyTo( DestinationChannelNode )

		If AutoSession.LastError.ID <> 0 Then
			' something wrong during the Copy process
			Call AutoSession.RollbackAll()
			Error = IDS_UI_ERROR_IN_COPY_PROCESS
			Exit Sub
		End If

		Call AutoSession.CommitAll()
	End Sub


	Private Sub SetupEditModeURL()
		URLGoBackEditModeLink =  GetWBCBasicEditURL(CurrentPostingNode)
	End Sub

End Class

%>
