<%

'*****************************************************************************
'Microsoft Content Management Server
'
' File: SDReportExportObjectType.INC
'
' Purpose:
'   ASP server-side include file that generates information about the exported
'   objects. This file is included by the ASP responsible for dumping out the
'	collection of export object collections.
'
' GLOBAL DEPENDENCIES:
'	- constants defined by SDReportExportObjects.INC
'	- utility functions defined in SDReportInitialize.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 attributes column (in pixels). The attributes column 
	' displays information about each export object such as the status and
	' last modified date
	const strWIDTH_ATTRIBUTES_COLUMN = "400"
	
	' width of the column (relative to the attributes column) that indicates
	' whether an approved version of an exported object exists.
	const strWIDTH_APPROVEDVERSION_COLUMN = "20%"
	
	' width of the column (relative to the attributes column) that indicates
	' the status of an exported object.
	const strWIDTH_STATUS_COLUMN = "30%"
	
	' width of the column (relative to the attributes column) that indicates
	' the last modified date of an exported object.
	const strWIDTH_APPROVEDON_COLUMN = "50%"
	
	
	' 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"
	
	
	'*************************************************************************
	' 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

		' only dump the tree header for object types other than user rights
		' groups. The only information that we need to display about user
		' rights groups are the users within them
		
		if CLng(m_pObjectTypeInfo.ContainerType) <> NR_OP_OBJECT_TYPE_USER_RIGHTS_GROUP then
					
			Response.Write(	_
				"<TABLE border=" & DEBUG_BORDER_SIZE & " cellPadding=""0"" cellSpacing=""0"" >" & vbcrlf & _
				"	<TR> " & vbcrlf & _
				"		<TH vAlign=""top"" width=""100%"">Exported Object</TH> "  & vbcrlf & _
				"		<TH vAlign=top> "  & vbcrlf & _
				"			<TABLE border=""" & DEBUG_BORDER_SIZE & """ width=""" & strWIDTH_ATTRIBUTES_COLUMN & """> " & vbcrlf & _
				"				<TR> " & vbcrlf & _
				"					<TH vAlign=""top"" width=""" & strWIDTH_APPROVEDON_COLUMN & """>" & "Approved On/<br>Last Modified" & "</TH> " & vbcrlf & _
				"				</TR> " & vbcrlf & _
				"			</TABLE> " & vbcrlf & _
				"		</TH> " & vbcrlf & _ 
				"	</TR> "  & vbcrlf & _ 
				"</TABLE> " &  vbcrlf & _
				"<BR> "  & vbcrlf & vbcrlf )
								
		end if  'if container type NOT user rights groups

	end sub  'dumpTreeHeader
	
	
	'*************************************************************************
	' Description:
	'	This function dumps the top level of a tree for one type of export
	'	object. A table is created here that represents the root node of 
	'	the export 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></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 export object, parse it out, and dump out that
	'	object has HTML in the proper location in the export 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:
	'	pExportedObject [in] - a Grammar Parser XML tag that describes the 
	'						   object being Exported. This tag is parsed for
	'						   info to place in the report.
	'
	'*************************************************************************
	sub dumpExportedObject( pExportedObject )
	
		' tracks the images to be displayed next to the export 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(pExportedObject.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_EXPORT_OBJECT_TYPE, "dumpExportedObject", strERROR_UNDETERMINED_EXPORT_OBJECT_TYPE )
			
		end if

		' grab the name of the image to represent the object type
		strImage = getObjectTypeImageTag( pExportedObject.ObjectType, pExportedObject.IsDeleted )
				
		' compute the location + name of the export object
		dim strExportObject
		'if nObjectType = m_pObjectTypeInfo.ContainerType then
		'	strExportObject = pExportedObject.Location
		'else
			strExportObject = pExportedObject.Location & pExportedObject.ObjectName
		'end if

		' if the object is a user-related object (user rights group or user)
		' the information that is displayed is minimal. Otherwise, display
		' full info about the object, such as whether an approved version
		' exists, state, etc.

		if ( nObjectType = NR_OP_OBJECT_TYPE_USER_RIGHTS_GROUP ) or _
		   ( nObjectType = NR_OP_OBJECT_TYPE_USER ) then
		   		
			' Show path for user rights group, no path for user name
			if ( nObjectType = NR_OP_OBJECT_TYPE_USER ) then
				strExportObject = pExportedObject.ObjectName
			end if
			
			Response.Write( _
				"			<LI ID=""" & ID_LIST_OBJECTS & """> " & vbcrlf & _
				"				<TABLE ID=""" & strIDType & """ border=""" & DEBUG_BORDER_SIZE & """ cellPadding=""1"" cellSpacing=""1"" > " & vbcrlf & _
				"					<TR> " & vbcrlf & _
				"						<TD VAlign=""top"" width=""100%""> " & vbcrlf & _
				"							" & strOpenCloseImage & vbcrlf & _
				"							" & strImage & vbcrlf )
				Response.Write Server.HTMLEncode(strExportObject) 
				Response.Write( _
				"							" & "<BR> " & vbcrlf & _
				"						</TD> " & vbcrlf & _
				"						" & vbcrlf & _	
				"						<TD vAlign=""top"" width=""" & strWIDTH_ATTRIBUTES_COLUMN & """> " & vbcrlf & _
				"						</TD> " & vbcrlf & _
				"					</TR> " & vbcrlf & _
				"				</TABLE> " & vbcrlf & _
				"			</LI> " & vbcrlf & vbcrlf )
		
		else  'not a user-related object
		
			' 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 strStatusTag
				
			' if the object has a non-blank status, show the status information, 
			' including a status icon
			'if pExportedObject.Status <> "" then
			'	strStatusTag = getStatusImageTag( pExportedObject.Status ) & _
			'				   " - " & pExportedObject.Status & " <BR> "
			'end if
				
			' Make explicitly selected items bold
			dim strBeginBoldIfExplicitlySelected
			dim strEndBoldIfExplicitlySelected
			strBeginBoldIfExplicitlySelected = ""
			strEndBoldIfExplicitlySelected = ""

			if pExportedObject.ExplicitlySelected then
				strBeginBoldIfExplicitlySelected = "<B>"
				strEndBoldIfExplicitlySelected = "</B>"
			end if

			Response.Write( _
				"			<LI ID=""" & ID_LIST_OBJECTS & """> " & vbcrlf & _
				"				<TABLE ID=""" & strIDType & """ border=""" & DEBUG_BORDER_SIZE & """ cellPadding=""1"" cellSpacing=""1"" > " & vbcrlf & _
				"					<TR> " & vbcrlf & _
				"						<TD VAlign=""top"" width=""100%""> " & vbcrlf & _
				"							" & strBeginBoldIfExplicitlySelected & strOpenCloseImage & vbcrlf & _
				"							" & strImage & vbcrlf )
				Response.Write Server.HTMLEncode(strExportObject) 
				Response.Write( _ 
				"							" & strEndBoldIfExplicitlySelected & "<BR> " & vbcrlf & _
				"						</TD> " & vbcrlf & _
				"						" & vbcrlf & _	
				"						<TD vAlign=""top"" width=""" & strWIDTH_ATTRIBUTES_COLUMN & """> " & vbcrlf & _
				"							<TABLE border=""" & DEBUG_BORDER_SIZE & """ cellPadding=""1"" cellSpacing=""1"" align=""right"" width=""" & strWIDTH_ATTRIBUTES_COLUMN & """> " & vbcrlf & _
				"								<TR> " & vbcrlf & _
				"									<TD CLASS=""" & ID_COLUMN_LASTMODIFIED & """ vAlign=""top"" Align=""center"" width=""" & strWIDTH_APPROVEDON_COLUMN & """ > " & vbcrlf & _
				"										" & dateToStr( dateToClientTimeZone(pExportedObject.LastModified) ) & vbcrlf & _
				"									</TD> " & vbcrlf & _
				"								</TR> " & vbcrlf & _
				"							</TABLE> " & vbcrlf & _
				"						</TD> " & vbcrlf & _
				"					</TR> " & vbcrlf & _
				"				</TABLE> " & vbcrlf & _
				"			</LI> " & vbcrlf & vbcrlf )

		end if  'elseif NOT a user-related object
			
		' 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 _
		   ( pExportedObject.ExportObjects.Count > 0 ) then

			call dumpExportedObjectCollection( pExportedObject.ExportObjects )
			
		end if  'if container with children
		
	end sub
	
	
	'*************************************************************************
	' Description:
	'	This method takes in a tag representing a collection of export objects
	'	and iterates over each object in the collection, dumping out the HTML
	'	representation of each export object (by calling another function) at
	'	the appropriate place in the tree.
	'
	' Parameters:
	'	pExportedObjects [in] - a Grammar Parser XML tag that is parsed to 
	'							retrieve info about the export object 
	'							collection
	'
	'*************************************************************************
	sub dumpExportedObjectCollection( pExportedObjects )
	
		' define a constant that indicates whether Exported 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 = ""
		
		' dump out the header for the collection
		Response.Write( _
			"		<UL ID=""" & ID_LIST_CHILD_OBJECTS & """ style=""display:" & DEFAULT_HIDDEN_OR_VISIBLE & """ > " & vbcrlf )
			
		if IsArray( pExportedObjects.ExportObject ) then
			dim pExportedObject
			for each pExportedObject in pExportedObjects.ExportObject
		
				call dumpExportedObject( pExportedObject )
		
			next  'Export object
			
		else
		
			' not a collection of Export objects, so just pass in the
			' lone tag
			call dumpExportedObject( pExportedObjects.ExportObject )
				
		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 Export objects to write out
		if ( m_pObjectTypeInfo.XMLTag.ExportObjects.Count <= 0 ) then
			exit sub
			
		end if  'if no objects in XML
		
		call dumpExportedObjectCollection( m_pObjectTypeInfo.XMLTag.ExportObjects )
		
	
	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 export objects section of the export
	'	report calls this function to generate the tree for one particular
	'	type of Export object.
	'
	' Parameters:
	'	pObjectTypeInfo [in] - an object that contains information about the
	'						   type of export 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.ExportObjects.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 exported 
		' 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

%>