<%

'*****************************************************************************
' Microsoft Content Management Server
'
' File: SDReportBrokenLinks.INC
'
' Purpose:
'   ASP server-side include file that generates information about those 
'	objects that have/will have broken links after the export or import 
'	operation has completed.
'
' GLOBAL DEPENDENCIES:
'	pReportXMLTag [in] - the root XML tag of the report XML.
'
'*****************************************************************************


	'*************************************************************************
	' Description:
	'	This function takes a link source XML tag pointer as an argument
	'	and dumps out the object to the output stream.
	'
	' Returns:
	'	None
	'	
	'*************************************************************************
	sub dumpLinkSource( pLinkSource )
	
		if pLinkSource is nothing then
			exit sub
		end if  'if pLinkSource = nothing
	
		if MapStringToSDType(pLinkSource.ObjectType) = NR_OP_OBJECT_TYPE_PAGE or _
			MapStringToSDType(pLinkSource.ObjectType) = NR_OP_OBJECT_TYPE_FOLDER then
			exit sub
		end if
					
		' dump out the link source and its properties
		' NOTE: pLinkSource tag has ObjectType value as string unlike other export objects
		Response.Write( "<TR> " & _
						"<TD WIDTH=""20%""> " & _
						getFolderStateImageTag( strFOLDER_OPEN, true ) & _
						getObjectTypeImageTag( MapStringToSDType(pLinkSource.ObjectType), 0 ) & " " & _
						pLinkSource.ObjectType & _
						"</TD> " & _
						"<TD> <b>" )
			Response.Write Server.HTMLEncode(pLinkSource.Location)
			Response.Write Server.HTMLEncode(pLinkSource.ObjectName)
			Response.Write("</b>" & _
						"</TD> </TR>" & vbcrlf )

		' The following is a bandaid to just get 
		' the broken links report to work (namely for Ford.com)
		' For some reason we are not getting any targetlinks?
		Dim pLinkTargets
		On Error resume next
		Set pLinkTargets = pLinkSource.LinkTargets
		If Err.Number <> 0 Then				
			Response.Write( "<TR> <TD colspan=""2""> <BLOCKQUOTE> Missing links: <br>" & _
						"<CENTER> <TABLE border=""0"" cellPadding=""1"" cellSpacing=""5"" width=""85%"">" )
			Response.Write( "<TR valign=""TOP""> " & _
						"<TD width=""30%""> " & "</TD> " & _
						"<TD> " & "</TD> " & _
						"<TD nowrap> " & "Empty Target Link Collection" & _
						"</TD> " & _
						"</TR>" )
			' end the table the indentation tags. 
			Response.Write( "</TABLE> </CENTER> </BLOCKQUOTE> </TD> </TR>" & vbcrlf )
			Exit Sub
		End If
		
		if Not (pLinkTargets is Nothing) Then
			if (pLinkTargets.Count > 0) then
			
				' start a table tag that will contain the link targets for this link
				' source object. Indent it one tab space for looks
				Response.Write( "<TR> <TD colspan=""2""> <BLOCKQUOTE> Missing links: <br>" & _
								"<CENTER> <TABLE border=""0"" cellPadding=""1"" cellSpacing=""5"" width=""85%"">" )
			
				' grab the collection of link targets from the XML (if 
				' there are any
			
				' double-check that we got back an array. If it is not an array
				' there is only one link target in the XML
				if IsArray( pLinkSource.LinkTargets.LinkTarget ) then
			
					' loop over all the link targets in the collection, dumping
					' them out as we go
					dim pLinkTarget
					for each pLinkTarget in pLinkSource.LinkTargets.LinkTarget
						call dumpLinkTarget( pLinkTarget )
							
					next
						
				else
					call dumpLinkTarget( pLinkSource.LinkTargets.LinkTarget )
						
				end if  'if broken links tag is an array
				
				' end the table the indentation tags. 
				Response.Write( "</TABLE> </CENTER> </BLOCKQUOTE> </TD> </TR>" & vbcrlf )

			end if  'if at least one link target
		end if 'pLinkTargets is not nothing
		
	end sub  'dumpLinkSource
	
	
	'*************************************************************************
	' Description:
	'	This function takes a link target XML tag pointer as an argument
	'	and dumps out the object to the output stream.
	'
	' Returns:
	'	None
	'	
	'*************************************************************************
	sub dumpLinkTarget( pLinkTarget )
	
		if pLinkTarget is nothing then
			exit sub
			
		end if  'if pLinkTarget = Nothing

		' Override object name and type for true broken links		
		dim strObjName 
		dim strObjType
		
		' default values
		strObjName = pLinkTarget.ObjectName			
		strObjType = pLinkTarget.ObjectType
		
		' true broken links are of type Unknown, customize their display values
		if NR_OP_OBJECT_TYPE_UNKNOWN = MapStringToSDType(pLinkTarget.ObjectType) then
			strObjType = "<i>" & strUNKNOWN & "</i>"
			strObjName = "<i> &#60;Unknown&#62; </i>"
		end if ' override type name if Unknown
		
		const strOBJECT_NOT_INCLUDED = "- object not included in export"
		const strOBJECT_NOT_EXISTS   = "- object does not exist in current system"

		' State the reason why it's broken
		dim strReason
		' if the type is unknown then this is a true broken link
		if MapStringToSDType(pLinkTarget.ObjectType) = NR_OP_OBJECT_TYPE_UNKNOWN then
			strReason = strOBJECT_NOT_EXISTS
		else
			strReason = strOBJECT_NOT_INCLUDED
		end if
		
		' NOTE: pLinkTarget tag has ObjectType value as string unlike other export objects		
		Response.Write( "<TR valign=""TOP""> " & _
						"<TD width=""30%""> " & _
						getObjectTypeImageTag( MapStringToSDType(pLinkTarget.ObjectType), 0 ) & " " & _
						strObjType & _
						"</TD> " & _
						"<TD> " )
			Response.Write Server.HTMLEncode(strObjName) 
			Response.Write( _
						"</TD> " & _
						"<TD nowrap> " & strReason & _
						"</TD> " & _
						"</TR>" )
							
	end sub  'dumpLinkTarget
	
	
	'*************************************************************************
	' Description:
	'	This function iterates over the XML-based broken link collection,
	'	dumping out a row in a table for each object that it comes across
	'	in the XML. The result is a nicely formatted list of objects that
	'	have/will have broken links of an import operation.
	'
	' Returns:
	'	None
	'	
	'*************************************************************************
	sub dumpBrokenLinksCollection
	
		if pReportXMLTag.BrokenLinks.Count > 0 then

			' grab the collection of broken link objects from the XML (if 
			' there are any
		
			' double-check that we got back an array. If it is not an array
			' there is only one broken link in the XML
			if IsArray( pReportXMLTag.BrokenLinks.LinkSource ) then
		
				dim pBrokenLink
				
				' loop over all the broken links in the collection, dumping
				' them out as we go
				for each pBrokenLink in pReportXMLTag.BrokenLinks.LinkSource
					call dumpLinkSource( pBrokenLink )
					
				next
				
			else
				call dumpLinkSource( pReportXMLTag.BrokenLinks.LinkSource )
				
			end if  'if broken links tag is an array
		
		else
			call Response.Write( "<TR> <TD> None </TD> </TR>" )
			
		end if  'if at least one broken link
	
	end sub  'dumpBrokenLinksCollection

%>


<BLOCKQUOTE style="MARGIN-RIGHT: 0px">

	<P>

	<TABLE border="0" cellPadding="1" cellSpacing="1" width="75%">

	<% call dumpBrokenLinksCollection %>

	</TABLE>

	</P>

</BLOCKQUOTE>