<!--#include virtual="/NR/System/WBC/Customizable/WBCFuncPagesConfig/UIStringConstants/CommonUIStrings.inc" -->
<%
	' string of const
	const AELOCK_STATUS_HAS_CHECKED_IN_VERSION = 4
	const AELOCK_STATUS_HAS_CHECKED_OUT_VERSION = 2
	const AELOCK_STATUS_BEEN_COMMITTED = 16
	Const URLPARA_NODE_GUID = "?NRNODEGUID="
	Const URLPARA_AUTH_TOKEN = "&CMSAUTHTOKEN="
	Const URLPARA_UNPUBLISHED_MODE = "&NRMODE=UnPublished"
	Const PREVIEW_PAGE_ASP_FILE = "/NR/System/ClientUI/PreviewPage.asp"
	Const PREVIEW_TEMPLATE_ASP_FILE = "/NR/System/ClientUI/PreviewTemplate.asp"	
	
	'-- Returns the status of the node object specified
	Function StatusOfNodeObject(pAENode)
		
		Dim eStatus
		Dim eNodeStatus
		Dim strImageName

		'-- Assign the appropriate status to eStatus based on the type of node
		Select Case pAENode.Type
			Case AE_NODE_PAGE

				eNodeStatus = g_pRERightsChk.GetPageState(g_pAESession, g_pAEServer, pAENode)

				Select Case eNodeStatus
					Case STATUS_PAGE_NEW
						eStatus=RE_NEW
					Case STATUS_PAGE_SAVED
						eStatus=RE_SAVED
					Case STATUS_PAGE_WAITING
						eStatus=RE_WAITING
					Case STATUS_PAGE_APPROVED
						eStatus=RE_APPROVED
					Case STATUS_PAGE_DECLINED
						eStatus=RE_DECLINED
					Case STATUS_PAGE_EXPIRED
						eStatus=RE_EXPIRED
					Case ELSE
						eStatus=RE_UNKNOWN
				End Select

			Case AE_NODE_POSTING

				eNodeStatus = g_pRERightsChk.GetPostingState(g_pAESession, g_pAEServer, pAENode)

				Select Case eNodeStatus
					Case STATUS_POSTING_NEW
						eStatus=RE_NEW
					Case STATUS_POSTING_WAITING
						eStatus=RE_WAITING
					Case STATUS_POSTING_APPROVED
						eStatus=RE_APPROVED
					Case STATUS_POSTING_DECLINED
						eStatus=RE_DECLINED
					Case STATUS_POSTING_PUBLISHED
						eStatus=RE_PUBLISHED
					Case STATUS_POSTING_EXPIRED
						eStatus=RE_EXPIRED
					Case STATUS_POSTING_PAGE_EXPIRED
						eStatus=RE_PAGE_EXPIRED
					Case STATUS_POSTING_PAGE_DELETED
						eStatus=RE_PAGE_DELETED
					Case ELSE
						eStatus=RE_UNKNOWN
				End Select

			Case AE_NODE_TEMPLATE

				eNodeStatus = g_pRERightsChk.GetTemplateState(g_pAESession, g_pAEServer, pAENode)

				Select Case eNodeStatus
					Case STATUS_TEMPLATE_SAVED
						eStatus=RE_SAVED
					Case STATUS_TEMPLATE_APPROVED
						eStatus=RE_APPROVED
					Case ELSE
						eStatus=RE_UNKNOWN
				End Select				

			Case ELSE  'node type is not supported
				eStatus = RE_UNKNOWN
		End Select

		StatusOfNodeObject=eStatus
		
	end Function


	'-- return TRUE if checked-in version exist
	'-- Otherwise, return FALSE
	Function HasCheckedInVersion(pAENode)
		If (pAENode.Lock.LockStatus And AELOCK_STATUS_HAS_CHECKED_IN_VERSION) = AELOCK_STATUS_HAS_CHECKED_IN_VERSION Then
		        HasCheckedInVersion = True
		    Else
		        HasCheckedInVersion = False
    		End If	
	End Function
	
	'-- return TRUE if checked-out version exist
	'-- Otherwise, return FALSE
	Function HasCheckedOutVersion(pAENode)
		If (pAENode.Lock.LockStatus And AELOCK_STATUS_HAS_CHECKED_OUT_VERSION) = AELOCK_STATUS_HAS_CHECKED_OUT_VERSION Then
		        hasCheckedOutVersion = True
		    Else
		        hasCheckedOutVersion = False
    		End If
	End Function
	
	
	'-- This function returns the node = Nothing when calling GetNodeByGuid has problem.
	Function GetNode(pAEServer, strNodeGuid, bCheckedOutVersion)
		On Error Resume Next
	
		Dim pNode 
		Set pNode = Nothing
		Set pNode = pAEServer.GetNodeByGuid(strNodeGuid, bCheckedOutVersion)
	
		Set GetNode = pNode
	End Function
	
	'-- This function returns the previewURL. If strLoginCookie is empty ("") then
	'-- the cookie won't attach.
	Function GetPreviewUrl(pAEServer, strNodeGuid, strLoginCookie, strASPFile)
				
		Dim strNode
		Dim strCookie
		Dim strPreviewUrl
		
		if strNodeGuid <> "" then
			strNode = URLPARA_NODE_GUID + strNodeGuid
		end if
		
		if strLoginCookie <> "" then
			strCookie = URLPARA_AUTH_TOKEN + strLoginCookie
		end if
		
		strPreviewUrl = strASPFile + strNode + strCookie + URLPARA_UNPUBLISHED_MODE
				
		GetPreviewUrl = pAEServer.ResolveURL( strPreviewUrl )
	End Function
	
	'-- This function returns the lock is commit or not.
	Function HasBeenCommitted(pAENode)
		If (pAENode.Lock.LockStatus And AELOCK_STATUS_BEEN_COMMITTED) = AELOCK_STATUS_BEEN_COMMITTED Then
			HasBeenCommitted = True
		Else
			HasBeenCommitted = False
    		End If
	End Function
	
	
	'-- Removes the domain from the username
	Function ShortUsername(strUsername)
		Dim X
		Dim Pos
		  
		X = 0
		Pos = InStr(strUsername, "/")
		If Pos > 0 Then
			Do
				X     = Pos + 1
				Pos   = InStr(X, strUsername, "/")
			Loop Until Pos = 0
		 
			strUsername = UCase(Mid(strUsername,X,1)) + LCase(Right(strUsername, Len(strUsername) - X))
		End If
		 
		ShortUsername = strUsername
	End Function
	

	'-- Returns the status of the node specified
	Function StatusFor(strNodeGuid, bCheckedOutVersion)
		Dim pAENode
		Dim eStatus
		
		Set pAENode = GetNode(g_pAEServer, strNodeGuid, bCheckedOutVersion)

		'-- Only return the status icon if the user has rights to the node
		if (pAENode is Nothing) then
			eStatus = RE_NO_RIGHTS			
		Else
			eStatus = StatusOfNodeObject(pAENode)			
		end if

		StatusFor=eStatus
			
	End Function
	
	
	
	'-- Returns the status icon tag depending on the generic node
	'-- status passed in
	Function StatusImageTagFor(eStatus)
		Dim strTag
		Dim strImageName

		Select Case eStatus
			Case RE_NEW
				strImageName="new.gif"
			Case RE_SAVED
				strImageName="save.gif"
			Case RE_WAITING
				strImagename="waiting.gif"
			Case RE_APPROVED
				strImageName="approved.gif"
			Case RE_PUBLISHED
				strImageName="publish.gif"
			Case RE_EXPIRED
				strImageName="expired.gif"		
			Case RE_DECLINED
				strImageName="decline.gif"
			Case RE_PAGE_EXPIRED
				strImageName="expiredpage.gif"
			Case RE_PAGE_DELETED
				strImageName="deletedpage.gif"
			Case RE_NO_RIGHTS
				strImageName=""
			Case Else
				strImageName="error.gif"
		End Select

		if len(strImageName)>0 then
			strTag = "<IMG SRC= " + STATUS_ICON_PATH + "/" + strImageName + " ALIGN=TEXTTOP >"
		else
			strTag=""
		end if

		StatusImageTagFor=strTag
	end Function
	
	
	'-- Returns the status text depending on the generic node
	'-- status passed in
	Function StatusTextFor(eStatus)
		Dim strText

		'-- At some point strText will be filled in with values
		'-- but now it is filled with an empty string.
		Select Case eStatus
			Case RE_UNKNOWN
				strText="Unknown Status."
			Case RE_NO_RIGHTS
				strText="No Rights."
			Case Else
				strText=""
		End Select

		StatusTextFor=strText
	end Function
	
	
	'-- Returns the status text depending on the generic node
	'-- status passed in
	Function StatusNameTagFor(eStatus)
		Dim strText
	
		'-- At some point strText will be filled in with values
		'-- but now it is filled with an empty string.
		Select Case eStatus
			Case RE_NEW
				strText="New"
			Case RE_SAVED
				strText="Saved"
			Case RE_WAITING
				strText="Waiting"
			Case RE_APPROVED
				strText="Approved"
			Case RE_PUBLISHED
				strText="Published"
			Case RE_EXPIRED
				strText="Expired"		
			Case RE_DECLINED
				strText="Declined"
			Case RE_PAGE_EXPIRED
				strText="Page Expired"
			Case RE_PAGE_DELETED
				strText="Page Deleted"
			Case RE_UNKNOWN
				strText="Unknown Status."
			Case RE_NO_RIGHTS
				strText="No Rights."
			Case Else
				strText=""
		End Select
	
		StatusNameTagFor=strText
	end Function
	
	'-- This function will check to see if CMSAUTHTOKEN is specified
	'-- in the query string and if it is, it will set the CMSAUTHTOKEN
	'-- cookie so that pages that include authenticate.inc can automagically
	'-- authenticate the Content Management Server user.
	'-- Only sets the token into the cookies collection if one does not exist
	'-- already in this collection, as it is assumed that the cookies 
	'-- collection is the most up-to-date.
	'-- Returns True if the cookie was set, or False if it was not.
	Function SetAuthTokenCookie()
		Dim strToken
		SetAuthTokenCookie = False
		
		if  (request.Cookies("CMSAUTHTOKEN") = "") then
		
			strToken = Request.QueryString("CMSAUTHTOKEN")
		
			if (strToken <> "") then
				Response.Cookies("CMSAUTHTOKEN") = strToken
				Response.Cookies("CMSAUTHTOKEN").Path = "/"
				SetAuthTokenCookie = True
			end if
		end if
	
	end Function
	
	'-- This function get the default channel if exist in folder or
	'-- The channel isn't purged.
	Function GetDefaultChannel(strFolderGuid)
		Dim pFolder
		Dim lIndex
		Dim strDefaultChannel


		'-- get the default channel if exist
		set pFolder = GetNode(g_pAEServer, strFolderGuid, True)

		if Not (pFolder is Nothing) then
			lIndex = pFolder.GenericProperties.FindPropertyByName("_DefaultPostChannel")
			if lIndex >= 0 then
				strDefaultChannel = pFolder.GenericProperties(lIndex).Value
			else
				strDefaultChannel = ""
			End if
		else
			strDefaultChannel = ""
		end if

		Set GetDefaultChannel = GetNode(g_pAEServer, strDefaultChannel, True)
	End Function
%>
