<!-- #include virtual="/NR/System/WBC/Internals/Main/WBCApp.inc"-->
<!-- #include virtual="/NR/System/WBC/Customizable/WBCFuncPagesConfig/UIStringConstants/PageOperationUIStrings.inc"-->
<!-- #include virtual="/NR/System/WBC/Internals/WBCFuncPages/Cross-Browser/PageOperation/AuthoringMode/EntryProgrammingConstants.inc"-->
<!-- #include virtual="/NR/System/WBC/Internals/WBCFuncPages/Cross-Browser/PageOperation/AuthoringMode/InternalProgrammingConstants.inc"-->
<!-- #include virtual="/NR/System/WBC/Internals/PageTemplate/PlaceholdersSupport/SetPosting.inc"-->
<!-- #include virtual="/NR/System/WBC/Internals/WBCFuncPages/Cross-Browser/PageOperation/AuthoringMode/PageSave/PageSave.inc"-->

<!-- #include virtual="/NR/System/WBC/Internals/Integration/InternalHooks/PostingOpHooks.inc" -->
<!-- #include virtual="/NR/System/WBC/Customizable/Hooks/PostingOpHooks.inc"-->

<!-- #include virtual="/NR/System/WBC/Internals/Integration/InternalHooks/PlaceholderHooks.inc" -->
<!-- #include virtual="/NR/System/WBC/Customizable/Hooks/PlaceholderHooks.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/AuthoringMode/
'			PageSave/ExistingPageSave/CNCASPPageManager_ExistingPageSave.inc
' Version: 	Microsoft Content Management Server
' Author:	Microsoft Corporation.
' Purpose:	Encapsulate the ASP logic associated with ExistingPageSave.asp
'
' Implements the INCASPPageManager interface:
'	- Sub InitManager()
'	- Property URLRetrySaveLink()
'	- Property URLAuthoringAgainLink()
'	- Property URLCancelEditLink()
'	- Property ContinueToAuthoring()
'	- Property CharSet()
'	- Property CodePage()
'	- Property URLGoToAuthoringMode()
'	- Property URLGoToEditMode()
'	- Property URLPreview()
'	- Property ShowWarningReport()
'	- Property ErrorString()
'	- Property HookFailed()
' ********************************************************************

Class CNCASPPageManager_ExistingPageSave


	'Try to do the save again
	Private m_strURLRetrySaveLink

	'Try to do the edit
	Private m_strURLAuthoringAgainLink

	'Try to cancel
	Private m_strURLCancelEditLink

	'Did user pressed continue and quit / continue and save
	Private m_bContinueToAuthoring

	'm_strCharSet for the ErrorString page
	Private m_strCharSet

	'm_strCodePage
	Private m_lCodePage

	'URL used to go back to Authoring mode if everything successful
	Private m_strURLGoToAuthoringMode

	'URL used to go back to Edit mode if everything successful
	Private m_strURLGoToEditMode

	'Preview
	Private m_strURLPreview

	'Show Report indicator in case there is filtering problem with the placeholder
	Private m_bShowWarningReport

	'Last Modified Date
	Private m_strLastModifiedDate

	'Error String that carry the enum of the error
	Private m_strError

	'Hook Has failed
	Private m_bHookFailed


	Public Property Get URLRetrySaveLink()
		URLRetrySaveLink = m_strURLRetrySaveLink
	End Property

	Public Property Get URLAuthoringAgainLink()
		URLAuthoringAgainLink = m_strURLAuthoringAgainLink
	End Property

	Public Property Get URLCancelEditLink()
		URLCancelEditLink = m_strURLCancelEditLink
	End Property

	Public Property Get ContinueToAuthoring()
		ContinueToAuthoring = m_bContinueToAuthoring
	End Property

	Public Property Get CharSet()
		Charset = m_strCharSet
	End Property

	Public Property Get CodePage()
		CodePage = m_lCodePage
	End Property

	Public Property Get URLGoToAuthoringMode()
		URLGoToAuthoringMode = m_strURLGoToAuthoringMode
	End Property

	Public Property Get URLGoToEditMode()
		URLGoToEditMode = m_strURLGoToEditMode
	End Property

	Public Property Get URLPreview()
		URLPreview = m_strURLPreview
	End Property

	Public Property Get ShowWarningReport()
		ShowWarningReport = m_bShowWarningReport
	End Property

	Public Property Get ErrorString()
		ErrorString = m_strError
	End Property

	Public Property Get HookFailed()
		HookFailed = m_bHookFailed
	End Property





	' ---- [Private] Class standard initialization routine
	Private Sub Class_Initialize()
		m_strURLRetrySaveLink = "#"
		m_strURLAuthoringAgainLink = "#"
		m_strURLCancelEditLink = "#"
		m_bContinueToAuthoring = True
		m_strCharSet = ""
		m_lCodePage = 0
		m_strURLGoToAuthoringMode = "#"
		m_strURLGoToEditMode = "#"
		m_strURLPreview = "#"
		m_bShowWarningReport = False
		m_strLastModifiedDate = ""
		m_strError = IDS_E_NO_ERROR
		m_bHookFailed = False
	End Sub

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

		Dim pPostingAfterUpdate


		If AutoSession.ThisPosting is Nothing Then
			m_strError  = IDS_E_PAGE_DOES_NOT_EXIST
		Else
			Call SetupMLSInfo()
			Call ReadQueryString()

			If m_strError <> IDS_E_NO_ERROR Then
				Exit Sub
			End If

			' -- Set up URL needed for links in the ASP page
			Call SetupSaveAgainLinkURL()
			Call SetupCancelEditLinkURL()
			m_strURLAuthoringAgainLink = SetupAuthoringModeURL(AutoSession.ThisPosting)& "&" & _
							 IDS_QPARAM_WBCACCEPT & "=" & IDS_ACCEPTCONTENT_PHS
			Call SetupPreviewURL()

			If LastModifiedDateChanged(AutoSession.ThisPosting, m_strLastModifiedDate) Then
				m_strError = IDS_E_PAGE_MODIFIED_ALREADY
				Exit Sub
			End If

			Set pPostingAfterUpdate = UpdateExistingPosting( AutoSession.ThisPosting, m_bHookFailed)

			'Hook is returning false, so we get out of this function
			'And we make sure all return link used the new created node
			If m_bHookFailed = True Then
				m_strURLGoToEditMode = GetGoBackToEditModeAndRefreshURL(pPostingAfterUpdate)
				m_strURLGoToAuthoringMode = GetGoBackToAuthoringModeAndRefreshURL(pPostingAfterUpdate)
				Exit Sub
			ElseIf AutoSession.LastError.ID <> 0 Then
				m_strError = IDS_E_ERR_IN_PAGE_UPDATE
				Exit Sub
			End If

			' -- Do we have any special warning like we will be omitting some
			'    placeholder info b/c the placeholder was set to use attachment only?
			Call CheckForWarning

			m_strURLGoToEditMode = GetGoBackToEditModeAndRefreshURL(pPostingAfterUpdate)
			m_strURLGoToAuthoringMode = GetGoBackToAuthoringModeAndRefreshURL(pPostingAfterUpdate)

		End If

	End Sub

	' ---- [Public] Generate HTML hidden form elements to retain user authored content
	'				in case there is any ErrorString druing the processing.  If we don't
	'               use this function to retain the user entered contents, the resubmit will
	'               loss the user entered info
	Public Sub GenerateRoundTripFormElementsForReSubmit()
		Call GenerateRoundTripFormElements()
	End Sub


	' ---- [Private] Determines if Posting has been changed on server since client last loaded the Posting
	'				 From CommonServer.inc
	Function LastModifiedDateChanged( pPosting, strLastModDateAsDbl )
		If strLastModDateAsDbl <> "" Then
			' Instead of comparing with Zero, we compare with -1 to allow for round-off errors
			If (DateDiff("s", CDate(pPosting.LastModifiedDate), CDate(strLastModDateAsDbl)) < -1) Then
				LastModifiedDateChanged = True
			Else
				LastModifiedDateChanged = False
			End If
		Else
			LastModifiedDateChanged = False
		End If
	End Function



	' ---- [Private] Setup the m_strCharSet
	Private Sub  SetupMLSInfo()
		m_strCharSet = AutoSession.ThisPosting.CharSet
		m_lCodePage = AutoSession.ThisPosting.CodePage
	End Sub


	' ---- [Private] Get the query string
	Private Sub ReadQueryString()
		Dim strContinueAuthoring

		strContinueAuthoring = (Request.QueryString(IDS_QSTR_PAGEOPERATIONAUTHORING_CONTINUEAUTHORING))

		If strContinueAuthoring = IDS_PAGEOPERATIONAUTHORING_CONTINUEAUTHORING_FALSE Then
			m_bContinueToAuthoring = False
		Else
			m_bContinueToAuthoring = True
		End If

		m_strLastModifiedDate = Request.QueryString(IDS_QSTR_PAGEOPERATIONAUTHORING_LASTMODIFIEDDATE)

	End Sub


	' ---- [Private] Save again URL in case there is a saving ErrorString like page lock
	Private Sub SetupSaveAgainLinkURL()

		Dim strContinue

		If m_bContinueToAuthoring = True Then
			strContinue = IDS_QSTR_PAGEOPERATIONAUTHORING_CONTINUEAUTHORING & "=" & IDS_PAGEOPERATIONAUTHORING_CONTINUEAUTHORING_TRUE
		Else
			strContinue = IDS_QSTR_PAGEOPERATIONAUTHORING_CONTINUEAUTHORING & "=" & IDS_PAGEOPERATIONAUTHORING_CONTINUEAUTHORING_FALSE
		End If

		m_strURLRetrySaveLink = IDS_FRAMEWORK_VIRTUAL_PATH & IDS_PAGEOPERATIONAUTHORING_PAGESAVE_PATH & _
							 "/ExistingPageSave/ExistingPageSave.asp?" & AutoSession.ThisPosting.QueryStringModeUpdate & "&" & _
							 IDS_QPARAM_LASTMOD & "=" & CDbl(CDate(AutoSession.ThisPosting.LastModifiedDate)) & "&" & _
							 strContinue
	End Sub


	' ---- [Private] Cancel saving means go back to edit mode
	Private Sub SetupCancelEditLinkURL()
		m_strURLCancelEditLink =  GetWBCBasicEditURL(AutoSession.ThisPosting)
	End Sub


	' ---- [Private]
	Private Function SetupAuthoringModeURL(pObject)

		If (pObject.IsFramed) Then
			' Framed case: since we are just targeting the Posting Frame, we
			'				will just grab the PostingFrame URL. If we just use
			'				GetWBCAuthoringURL as below. we will end up missing
			'               all the frame info
			SetupAuthoringModeURL = AppendQueryString(pObject.URLPostingFrame(False), _
							IDS_QPARAM_NREMIT & "=" & IDS_EMIT_THINEDIT & "&" & _
							IDS_QPARAM_WBCPURPOSE & "=" & IDS_WBCPURPOSE_AUTHORING)
		Else
			SetupAuthoringModeURL = GetWBCAuthoringUrl(pObject)
		End If

		'Note:To go back, we should never add the timestamp
		'SetupAuthoringModeURL = SetupAuthoringModeURL & "&" & IDS_QPARAM_LASTMOD & "=" & CDbl(CDate(AutoSession.ThisPosting.LastModifiedDate))

	End Function


	' ---- [Private]
	Private Sub SetupPreviewURL()
		m_strURLPreview = GetPreviewURL(AutoSession.ThisPosting)
	End Sub



	' ---- [Private] B/c we may need to filter out placeholder info out based on
	'                placeholder's properties, we need to let the user know if this
	'                is the case.  g_bFiltered is defined in the setposting.inc.
	Private Sub CheckForWarning()
		' TODO: g_bFiltered from SetPosting.inc should be some kind of
		'		property exposed from some SetPosting Class
		If g_bFiltered And IDB_SHOW_FILTERED_WARNING Then
			m_bShowWarningReport = True
		Else
			m_bShowWarningReport = False
		End If
	End Sub


End Class
%>


