<%

'	NOTE: Caller that uses this function must include the hook in the caller body
'
'
' ********************************************************************
' 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."
' ********************************************************************


' ---- [Public] Update an existing posting
Function UpdateExistingPosting( pPosting, bHookFailed )
	'In case, there is problem like the node is locked, we do not want this module to
	'blow up
	On Error Resume Next
	Call AutoSession.ClearLastError()

	' set up default return object
	Set UpdateExistingPosting = pPosting

	' Call hook function to invoke customzied script before the operation
	If ( OnInternalBeforeUpdatePosting( pPosting ) = False Or _
		OnBeforeUpdatePosting( pPosting ) = False ) Then

		' hook function returns False to cancel the operation
		bHookFailed = True
		Exit Function
	End If


	Call SetContentForAllEmittedPhs(pPosting)

	' if there is error, bail out!
	If (AutoSession.LastError.ID <> 0) Then
		Call AutoSession.RollbackAll()
		Exit Function
	End If

	' if all calls to update the Posting succeeded, Commit!
	Call AutoSession.CommitAll()

	If (AutoSession.LastError.ID <> 0) Then
		Exit Function
	End If

	' Call Internal Hook
	Call OnInternalAfterUpdatePosting( pPosting )

	' Call Customizable Hook
	Call OnAfterUpdatePosting( pPosting )

	Set UpdateExistingPosting = pPosting

End Function



' ---- [Public] Create the URL so that caller can use this go back to edit mode
Public Function GetGoBackToEditModeAndRefreshURL(pObjToShow)
	Dim strURL

	If (pObjToShow.IsFramed) Then

		' Framed case: redirect to the ASP page that will refresh the frameset
		' 	It is done this way because we want the whole frameset to be refreshed!
		GetGoBackToEditModeAndRefreshURL = AppendQueryString( IDS_FRAMEWORK_VIRTUAL_PATH & _
							"/Internals/WBCFuncPages/Cross-Browser/PageOperation/FramesetRefresh.asp" , _
							pObjToShow.QueryString & "&" & IDS_QPARAM_GOTOMODE & "=" & IDS_GOTOMODE_EDIT )
	Else
		' Frameless case: simply redirect to the pObjToShow URL
		GetGoBackToEditModeAndRefreshURL = GetWBCBasicEditURL( pObjToShow )
	End If


End Function



' ---- [Public] Create the URL so that caller can use this go back to authoring mode
Public Function GetGoBackToAuthoringModeAndRefreshURL(pObject)

	If (pObject.IsFramed) Then
		' Framed case: since we are just targeting the Posting Frame, we
		'				will just grab the PostingFrame URL
		GetGoBackToAuthoringModeAndRefreshURL = AppendQueryString( IDS_FRAMEWORK_VIRTUAL_PATH & _
							"/Internals/WBCFuncPages/Cross-Browser/PageOperation/FramesetRefresh.asp" , _
							pObject.QueryString & "&" & IDS_QPARAM_GOTOMODE & "=" & IDS_GOTOMODE_AUTHORING )
	Else
		GetGoBackToAuthoringModeAndRefreshURL = GetWBCAuthoringUrl(pObject)
	End If


End Function




%>