<%

'*****************************************************************************
' Microsoft Content Management Server
'
' File: SDReportImportObjectType.INC
'
' Purpose:
'   ASP server-side include file that generates information about the imported
'   objects. This file is included by the ASP responsible for dumping out the
'	collection of import object collections.
'
' GLOBAL DEPENDENCIES:
'	constants defined by SDReportImportObjects.INC
'
'*****************************************************************************


	'*************************************************************************
	' CONSTANTS
	'*************************************************************************
	
	' variable that is used locally to this script to store information
	' about the object type being generated from XML to HTML. This prevents
	' us from having to pass around the object type info to each and every
	' function. The value of this variable is set in generateHTMLForObjectType
	dim m_pObjectTypeInfo
	set m_pObjectTypeInfo = nothing

	' width of the destination column (in pixels)
	const strWIDTH_DEST_COLUMN = "400"
	
	' width of the relocation column (in percent)
	const strWIDTH_DEST_RELOCATION = "20%"
	
	' This constant turns the border on tables on and off for debugging
	' purposes. In the release version, this constant should be "0"
	const DEBUG_BORDER_SIZE = "0"	
	
	' define a constant that indicates whether imported objects in the tree
	' start in a visible or hidden state. The respective values of this
	' constant should be "" for visible, and "none" for hidden
	const DEFAULT_HIDDEN_OR_VISIBLE = ""
	
	' This constant is the action description on a relocated object due to
	' Hierarchy Fixup.
	const strRELOCATE = "Relocate"
	
	'*************************************************************************
	' FUNCTIONS
	'*************************************************************************
	
	'*************************************************************************
	' Description:
	'	This function dumps the tree header HTML tags for one object type. 
	'	Information included in the tree header includes headings (column 
	'	names) for the tree that is to be generated beneath it.
	'
	'*************************************************************************
	sub dumpTreeHeader

		Response.Write(	_
			"<TABLE border=""" & DEBUG_BORDER_SIZE & """ cellPadding=""0"" cellSpacing=""0"" >" & vbcrlf & _
			"	<TR> " & vbcrlf & _
			"		<TH vAlign=""top"" width=""100%"">Source</TH> "  & vbcrlf & _
			"		<TH vAlign=""top""> "  & vbcrlf & _
			"			<TABLE border=""" & DEBUG_BORDER_SIZE & """ width=""" & strWIDTH_DEST_COLUMN & """> " & vbcrlf & _
			"				<TR> " & vbcrlf & _
			"					<TD width=""" & strWIDTH_DEST_RELOCATION & """ > &nbsp </TD> " & vbcrlf & _
			"					<TH vAlign=""top"">Destination</TH> " & vbcrlf & _
			"				</TR> " & vbcrlf & _
			"			</TABLE> " & vbcrlf & _
			"		</TH> " & vbcrlf & _ 
			"	</TR> "  & vbcrlf & _ 
			"</TABLE> " &  vbcrlf & _
			"<BR> "  & vbcrlf & vbcrlf )

	end sub  'dumpTreeHeader
	
	
	'*************************************************************************
	' Description:
	'	This function dumps the top level of a tree for one type of import
	'	object. A table is created here that represents the root node of 
	'	the import object tree that identifies the types of objects shown
	'	in the tree (in the form "<Container type> and <Item type>". Note that
	'	the root node in the tree is also expandable/contractable.
	'
	'*************************************************************************
	sub dumpTopLevelOfTree

		Response.Write( _
			"<UL> " & vbcrlf & _
			"	<LI ID=""" & ID_LIST_OBJECTS & """ > " & vbcrlf & _
			"		<TABLE ID=""" & ID_CONTAINER & """ border=""" & DEBUG_BORDER_SIZE & """ cellPadding=""1"" cellSpacing=""1"" width=""100%""> " & vbcrlf & _
			"			<TR> " & vbcrlf & _
			"				<TD VAlign=""top""> " & vbcrlf & _
			"				" & getFolderStateImageTag( strFOLDER_OPEN, true ) & vbcrlf & _
			"				" & getObjectPackageImageTag(m_pObjectTypeInfo.ContainerType) & vbcrlf & _
			"					" & MapSDTypeToDisplayString(m_pObjectTypeInfo.ContainerType) & " and " & MapSDTypeToDisplayString(m_pObjectTypeInfo.ItemTypeForDisplay) & vbcrlf & _
			"				<BR><BR></TD> " & vbcrlf & _
			"				<TD class=""" & ID_COLUMN_LOCATIONACTION & """ vAlign=""top""> " & vbcrlf & _
			"				</TD> " & vbcrlf & _
			"				<TD class=""" & ID_COLUMN_DESTINATION & """ vAlign=""top""> " & vbcrlf & _
			"				</TD> " & vbcrlf & _
			"			</TR> " & vbcrlf & _
			"		</TABLE> " & vbcrlf & vbcrlf )


	end sub  'dumpTopLevelOfTree
	
	
	'*************************************************************************
	' Description:
	'	This function is the guts of this module. It will take in the XML
	'	representation of an import object, parse it out, and dump out that
	'	object has HTML in the proper location in the import object tree.
	'	This is quite an involved function - to really understand what is
	'	going on, it is recommended that the main reporting ASP page be
	'	invoked from the browser and HTML that is generated compared to the
	'	Response.Write calls below.
	'
	' Parameters:
	'	pImportedObject [in] - a Grammar Parser XML tag that describes the 
	'						   object being imported. This tag is parsed for
	'						   info to place in the report.
	'
	'*************************************************************************
	sub dumpImportedObject( pImportedObject )
	
		' tracks the images to be displayed next to the import object. The
		' first one is the plus/minus image, and the next one is the object
		' type image
		dim strOpenCloseImage
		dim strImage
		
		' tracks the type of object being written - container or item
		dim strIDType
		
		dim nObjectType
		nObjectType = MapStringToSDType(pImportedObject.ObjectType)
		
		if (nObjectType = m_pObjectTypeInfo.ContainerType) then 
		
			strOpenCloseImage = getFolderStateImageTag( strFOLDER_OPEN, true )
			strIDType = ID_CONTAINER
		
		elseif (nObjectType = m_pObjectTypeInfo.ItemType) then
		
			strOpenCloseImage = getFolderStateImageTag( strFOLDER_OPEN, false )
			strIDType = ID_ITEM
			
		else			
			strIDType = ""
			' raise exception
			call Err.Raise( nERROR_UNDETERMINED_IMPORT_OBJECT_TYPE, "dumpImportedObject", strERROR_UNDETERMINED_IMPORT_OBJECT_TYPE )
			
		end if

		' grab the name of the image to represent the object type
		strImage = getObjectTypeImageTag( pImportedObject.ObjectType, 0 )
				
		dim pObjectVersion 
		set pObjectVersion = pImportedObject.Versions.Version
		
		dim pObjectSource
		set pObjectSource = pObjectVersion.Source
		
		dim pObjectDestBeforeImport
		set pObjectDestBeforeImport = pObjectVersion.DestinationBeforeImport
		
		dim pObjectDestAfterImport
		set pObjectDestAfterImport = pObjectVersion.DestinationAfterImport
		
		' compute the location + name of the import object
		dim strSourceObject
		strSourceObject = pObjectSource.Location & pObjectSource.ObjectName
						
		' compute what happened to the object: New/Same/Relcate?
		dim strObjectAction
		strObjectAction = pImportedObject.Versions.Version.LocationAction
		if ( pObjectDestBeforeImport.NodeExists ) then
			if pObjectDestAfterImport.Location <> pObjectDestBeforeImport.Location then
				strObjectAction = strRELOCATE
			end if
		end if
			
		' compute object path + name after import
		dim strObjectPath
		strObjectPath = pObjectDestAfterImport.Location & pObjectDestAfterImport.ObjectName

		Response.Write( _
			"			<LI ID=""" & ID_LIST_OBJECTS & """> " & vbcrlf & _
			"				<TABLE ID=""" & strIDType & """ border=""" & DEBUG_BORDER_SIZE & """ cellPadding=""1"" cellSpacing=""1"" > " & vbcrlf & _
			"					<TR VALIGN=""TOP""> " & vbcrlf & _
			"						<TD VAlign=""top"" width=""100%""> " & vbcrlf & _
			"							" & strOpenCloseImage & vbcrlf & _
			"							" & strImage & vbcrlf & _ 
			"							<STRONG>" )
			Response.Write Server.HTMLEncode(strSourceObject) 
			Response.Write( "</STRONG><BR> " & vbcrlf & _
			"							<BLOCKQUOTE style=""MARGIN-RIGHT: 0px; MARGIN-TOP: 0px""> " & vbcrlf & _
			"								<EM>Last modified: </EM>" & dateToStr( dateToClientTimeZone(pObjectSource.LastModified) ) & vbcrlf & _
			"							</BLOCKQUOTE> " & vbcrlf & _
			"						</TD> " & vbcrlf & _
			"						" & vbcrlf & _	
			"						<TD vAlign=""top"" width=""" & strWIDTH_DEST_COLUMN & """> " & vbcrlf & _
			"							<TABLE border=""" & DEBUG_BORDER_SIZE & """ cellPadding=""6"" cellSpacing=""6"" align=""right"" width=""" & strWIDTH_DEST_COLUMN & """> " & vbcrlf & _
			"								<TR> " & vbcrlf & _
			"									<TD CLASS=""" & ID_COLUMN_LOCATIONACTION & """ vAlign=""top"" Align=""right"" width=""" & strWIDTH_DEST_RELOCATION & """ > " & vbcrlf & _
			"										" & strObjectAction & vbcrlf & _
			"									</TD> " & vbcrlf & _
			"									" & vbcrlf & _	
			"									<TD CLASS=""" & ID_COLUMN_DESTINATION & """ vAlign=""top""> " & vbcrlf & _
			"										<STRONG>" )
			Response.Write Server.HTMLEncode(strObjectPath) 
			Response.Write("</STRONG><BR> " & vbcrlf & _
			"										<BLOCKQUOTE STYLE=""MARGIN-RIGHT: 0px; MARGIN-TOP: 0px""> " & vbcrlf )
			
		' if there is an original object sitting on the server already that the
		' one in the package will replaced, then display the information about
		' that original object
		if pObjectDestBeforeImport.NodeExists then 
		  
		   if pObjectDestBeforeImport.ObjectName <> "" then

				' variable to hold the HTML tags used to display lock information.
				' By default, we assume that there is no lock on the object by
				' having an empty string
				dim strExistingLockTag

				' if the object is currently locked by someone on the target system,
				' show information about who has it locked
				if pObjectDestBeforeImport.Lock.User <> "" then
					strExistingLockTag = "<EM>Original Object Locked By: </EM>" & _
										 pObjectDestBeforeImport.Lock.User & "<BR>"
				end if

				' variable to hold the HTML tags used to display status information.
				' By default, we assume that there is no status information about
				' the object by having an empty string
				dim strOriginalStatusTag
				strOriginalStatusTag = ""
				' if the object currently has a non-blank status on the target system,
				' show the status information, including a status icon
				'if pObjectDestBeforeImport.Status <> "" then
				'   
				'		strOriginalStatusTag = "<EM>Original Status: </EM>" & _
				'						   	   getStatusImageTag( pObjectDestBeforeImport.Status ) & _
				'						       " - " & pObjectDestBeforeImport.Status & "<BR>"
				'
				'end if	' before-import status isn't empty and different from new status

				' Display the original location if it's has been relocated
				dim strOriginalLocation			
				' do not display original location by default
				strOriginalLocation = ""
				if pObjectDestAfterImport.Location <> pObjectDestBeforeImport.Location then
					' show its original location only for relocated objects
					strOriginalLocation = vbcrlf & "<EM>Original Location: </EM>" & _
										  pObjectDestBeforeImport.Location & pObjectDestBeforeImport.ObjectName & "<BR>"
				end if	' object was relocated due to hierarchy fixup

				' write out the info about the original object
				Response.Write( _
					"										" & _
					"										" )
			Response.Write Server.HTMLEncode(strOriginalLocation) 
			Response.Write(vbcrlf & _
					"										" & strOriginalStatusTag & vbcrlf & _
					"										" & strExistingLockTag & vbcrlf )
					
		   end if  ' DestinationBeforeImport.ObjectName not empty
		   
		end if	   ' DestinationBeforeImport.NodeExists is true


		dim strUserRightsGroupsMembers
		strUserRightsGroupsMembers = ""
		
		' Add block of user names if available - if this is a User Rights Group object
		' Note: Much better if Users were reported as Import Objects, but not at the moment.
		if (nObjectType = NR_OP_OBJECT_TYPE_USER_RIGHTS_GROUP) then



			strUserRightsGroupsMembers = getUserRoleMembersList( pObjectVersion.RoleMembers )	
		
		end if		' is User Rights Group

					
		' to wrap up for this object	
		Response.Write( _		
			"										</BLOCKQUOTE> " & vbcrlf & _
			"									</TD> " & vbcrlf & _
			"								</TR> " & vbcrlf & _
			"							</TABLE> " & vbcrlf & _
			"						</TD> " & vbcrlf & _
			"					</TR> " & vbcrlf & _
			"				</TABLE> " & vbcrlf & _										
			"			   " & strUserRightsGroupsMembers & vbcrlf & _
			"			</LI> " & vbcrlf )
			
		' if the item that was just dumped out is a container, then it may have
		' children. Take care of dumping out the children if there are any
		if ( strIDType = ID_CONTAINER ) and _
		   ( pImportedObject.ImportedObjects.Count > 0 ) then
		   
			call dumpImportedObjectCollection( pImportedObject.ImportedObjects )
			
		end if  'if container with children
		
	end sub
	
	
	'*************************************************************************
	' Description:
	'	This method takes in a tag representing a collection of import objects
	'	and iterates over each object in the collection, dumping out the HTML
	'	representation of each import object (by calling another function) at
	'	the appropriate place in the tree.
	'
	' Parameters:
	'	pImportedObjects [in] - a Grammar Parser XML tag that is parsed to 
	'							retrieve info about the import object 
	'							collection
	'
	'*************************************************************************
	sub dumpImportedObjectCollection( pImportedObjects )
		
		' dump out the header for the collection
		Response.Write( _
			"		<UL ID=""" & ID_LIST_CHILD_OBJECTS & """ style=""display:" & DEFAULT_HIDDEN_OR_VISIBLE & """ > " & vbcrlf )
			
		if IsArray( pImportedObjects.ImportedObject ) then
			dim pImportedObject
			for each pImportedObject in pImportedObjects.ImportedObject
		
				call dumpImportedObject( pImportedObject )
		
			next  'import object
			
		else
		
			' not a collection of import objects, so just pass in the
			' lone tag
			call dumpImportedObject( pImportedObjects.ImportedObject )
				
		end if  'if input object is an array
	
		Response.Write( _
			"		</UL> " & vbcrlf )

	end sub
	
	
	'*************************************************************************
	' Description:
	'	Simple function that gets the whole process of tree generation going.
	'
	'*************************************************************************
	sub dumpTree
	
		' no use going on if there are no import objects to write out
		if ( m_pObjectTypeInfo.XMLTag.ImportedObjects.Count <= 0 ) then
			exit sub
			
		end if  'if no objects in XML
		
		call dumpImportedObjectCollection( m_pObjectTypeInfo.XMLTag.ImportedObjects )
		
	
	end sub  'dumpTree
	

	'*************************************************************************
	' Description:
	'	Once the entire tree has been spit out as HTML, this function is 
	'	called to close off all the header tags that were generated previously
	'
	'*************************************************************************
	sub dumpTreeFooter

		Response.Write(	_
			"	</LI> " & vbcrlf & _
			"</UL> " & vbcrlf & vbcrlf )
	
	end sub
	

	'*************************************************************************
	' Description:
	'	The main entry point to this ASP server-side include file. The ASP
	'	responsible for generating the import objects section of the import
	'	report calls this function to generate the tree for one particular
	'	type of import object.
	'
	' Parameters:
	'	pObjectTypeInfo [in] - an object that contains information about the
	'						   type of import object being described by this
	'						   ASP file.
	'
	'*************************************************************************
	sub generateHTMLForObjectType( pObjectTypeInfo )
	
		' store the object type info for use by the other
		' functions in this module
		set m_pObjectTypeInfo = pObjectTypeInfo
		
		' if there are no objects to dump out, then just dump out
		' a string indicating so and exit the routine
		if m_pObjectTypeInfo.XMLTag.ImportedObjects.Count <= 0 then
			Response.Write( "<BLOCKQUOTE>None</BLOCKQUOTE>" & vbcrlf )
			exit sub
		end if
		
		' begin by dumping out the header for the tree
		call dumpTreeHeader
		
		' dump the top level of the tree. Note that it is slightly 
		' different than the rest of the levels as it cannot be 
		' hidden
		call dumpTopLevelOfTree
		
		' start the recursive process of dumping out the imported 
		' objects as a tree in HTML
		call dumpTree

		' we're done, so close off the necessary end tags that make
		' the header tags complete
		call dumpTreeFooter
	
		' we're finished with the object type information
		set m_pObjectTypeInfo = nothing			
	end sub  'generateHTMLForObjectType


	'*************************************************************************
	' Description:
	'	Simple function that lists all user role members in a list.
	'
	'*************************************************************************
	function getUserRoleMembersList( pRoleMembers )
	
		dim strRetVal 

		if pRoleMembers.Count > 0 then
			strRetVal = "     <UL ID=""" & ID_LIST_CHILD_OBJECTS & """ style=""display:" & DEFAULT_HIDDEN_OR_VISIBLE & """ > " & vbcrlf

			if IsArray( pRoleMembers.Member ) then
			
				dim pMember
				for each pMember in pRoleMembers.Member

					strRetVal = strRetVal & getUserRoleMember( pMember )

				next  ' for each Role Member

			else

				' not a collection of members, so just pass in the lone tag
				strRetVal = strRetVal & getUserRoleMember( pRoleMembers.Member )

			end if  'if input object is an array				
			
			strRetVal = strRetVal & "				</UL> " & vbcrlf & "<br>" & vbcrlf

		end if	' there are role members

		getUserRoleMembersList = strRetVal
		
	end function	 ' getUserRoleMembersList
	

	'*************************************************************************
	' Description:
	'	Simple function that outputs HTML for a user role member.
	'
	'*************************************************************************
	function getUserRoleMember( pMember )
	
		dim strRetVal
		strRetVal = _
				"				  <LI ID=""" & ID_LIST_OBJECTS & """> " & vbcrlf & _
				"				  	<TABLE ID=""" & ID_ITEM & """ border=""" & DEBUG_BORDER_SIZE & """ cellPadding=""1"" cellSpacing=""1"" > " & vbcrlf & _
				"					  <TR> " & vbcrlf & _
				"						<TD VAlign=""top"" width=""100%""> " & vbcrlf & _
				"							" & getFolderStateImageTag( strFOLDER_OPEN, false ) & vbcrlf & _
				"							" & getObjectTypeImageTag( strOBJECT_TYPE_USER, 0 ) & vbcrlf & _ 
				"							" & pMember.UserName & "<BR> " & vbcrlf & _
				"						</TD> " & vbcrlf & _
				"					  </TR> " & vbcrlf & _
				"					</TABLE> " & vbcrlf & _
				"				  </LI> " & vbcrlf & vbcrlf
				
		getUserRoleMember = strRetVal
		
	end function	 ' getUserRoleMember
%>
