'**********************************************************
' readActivityStartConfiguration
' @description
' @param
' @return
'**********************************************************
Function readActivityStartConfiguration (activityName)
	debug2File "start - readActivityStartConfiguration"
	Dim oXmlDoc : Set oXmlDoc = CreateObject("Msxml2.DOMDocument")
	If True = oXmlDoc.load(wfvariables.recCommon.sConfigurationFile.Value) Then
		Dim xpath
		Dim oNode
		Dim oNodes
		
		'Templates
		xpath = "config/WorkflowType[@type='" & recCommon.sWorkflowModel.Value & "']/Templates"
		debug2File "Reading template informations"
		Set oNode = oXmlDoc.selectSingleNode(xpath)		
		If Not oNode Is Nothing Then
			debug2File "Template Request: " 
			debug2File vbTab & vbTab & vbTab & oNode.text
			wfvariables.sTemplateRequest.value = oNode.text	'assign the request string to an internal variable (TODO: better way to do this? maybe like wffields?)
		Else
			throwError "Failed to read template informations of the activity " & activityName
		End If
		
		'AttachmentTemplates
		xpath = "config/WorkflowType[@type='" & recCommon.sWorkflowModel.Value & "']/AttachmentTemplates"
		debug2File "Reading attachment template informations"
		Set oNode = oXmlDoc.selectSingleNode(xpath)		
		If Not oNode Is Nothing Then
			debug2File "Attachment Template Request: " 
			debug2File vbTab & vbTab & vbTab & oNode.text
			wfvariables.sTemplateAttachmentRequest.value = oNode.text	'assign the request string to an internal variable (TODO: better way to do this? maybe like wffields?)
		Else
			throwError "Failed to read attachement template informations of the activity " & activityName
		End If
		
		'ConversionType
		xpath = "config/WorkflowType[@type='" & recCommon.sWorkflowModel.Value & "']/ConversionType"
		debug2File "Reading conversion type informations (0 means OS; 1 means Neevia)"
		Set oNode = oXmlDoc.selectSingleNode(xpath)		
		If Not oNode Is Nothing Then
			debug2File "Conversion Type: " 
			debug2File vbTab & vbTab & vbTab & oNode.text
			wfvariables.iConversionType.value = oNode.text	
		Else
			throwError "Failed to read the conversion type of the activity " & activityName
		End If		
		
		
		'Activity name		
		xpath = "config/WorkflowType[@type='" & recCommon.sWorkflowModel.Value & "']/Activity[@Name='" & activityName & "']"
		Set oNode = oXmlDoc.selectSingleNode(xpath)
		If Not oNode Is Nothing Then
			debug2File "Activity nameDE: " & oNode.attributes.getNamedItem("nameDE").text
			debug2File "Activity nameEN: " & oNode.attributes.getNamedItem("nameEN").text
		Else
			throwError "Failed to read the activity " & activityName
		End If
		'Activity WorkflowFields
		xpath = "config/WorkflowType[@type='" & recCommon.sWorkflowModel.Value & "']/Activity[@Name='" & activityName & "']/WorkflowFields/Field" 
		debug2File "Reading workflow fields"
		Set oNodes = oXmlDoc.selectNodes(xpath)
		If Not oNodes Is Nothing Then
			wfvariables.recConfigWFFields.ClearList
			For i = 0 To oNodes.length - 1
				debug2File vbTab & "Field Variable Name: " & oNodes(i).attributes.getNamedItem("variablename").text
				debug2File vbTab & vbTab & "Field Enabled: " & oNodes(i).attributes.getNamedItem("enabled").text
				debug2File vbTab & vbTab & "Field Visible: " & oNodes(i).attributes.getNamedItem("visible").text
				debug2File vbTab & vbTab & "Field ListType: " & oNodes(i).attributes.getNamedItem("listtype").text
				debug2File vbTab & vbTab & "Field Mandatory: " & oNodes(i).attributes.getNamedItem("mandatory").text

				Dim content : content = ""
				If oNodes(i).attributes.getNamedItem("listtype").text = "2" Then
					debug2File vbTab & vbTab & "Listtype values: " & oNodes(i).text
					content = getObjectDefListValues (oNodes(i).text)
				Else 
					If oNodes(i).attributes.getNamedItem("listtype").text = "1" Then
						debug2File vbTab & vbTab & "Listtype values: " & oNodes(i).text
						content = oNodes(i).text
					Else
						debug2File vbTab & vbTab & "Field Value: " & oNodes(i).text
						content = oNodes(i).text
					End If
				End If
				
				'add configuration wffields to internal record structure
				'this record will be read in different events to initialize wffields / controls				
				Set oEntry = wfvariables.recConfigWFFields.CreateListItem
				oEntry.Item("sVariableName").Value = oNodes(i).attributes.getNamedItem("variablename").text
				oEntry.Item("iEnabled").Value = oNodes(i).attributes.getNamedItem("enabled").text
				oEntry.Item("iVisible").Value = oNodes(i).attributes.getNamedItem("visible").text
				oEntry.Item("iListType").Value = oNodes(i).attributes.getNamedItem("listtype").text
				oEntry.Item("iMandatory").Value = oNodes(i).attributes.getNamedItem("mandatory").text
				oEntry.Item("sContent").Value = content

				'CC-000644:
				'1. Ermittlung des passenden internen Namens im Document-Zweig zu dem hier gesetzten variablen Namen
				'2. Ermittlung der Feldlänge (in der Objektdefinition) anhand des internen Namens auf dem Objekt Dokument
				'zu 1
				xpath = "config/DocumentType/Document[@internal_name='" & wfvariables.recStructure.sDocumentInternalName.Value & "']/Fields/Field[@variablename='" & oNodes(i).attributes.getNamedItem("variablename").text & "']"
				Set oFieldInfo = oXmlDoc.selectSingleNode(xpath)
				If Not oFieldInfo Is Nothing Then
					debug2file oNodes(i).attributes.getNamedItem("variablename").text & ": " & oFieldInfo.attributes.getNamedItem("internal_name").text
					'zu 2
					oEntry.Item("iMaxLength").Value = 0

					Dim sFilePath : sFilePath = getObjectDef()
					Dim oXmlObjDef : Set oXmlObjDef = CreateObject("Msxml2.DOMDocument")
					If True = oXmlObjDef.load(sFilePath) Then			
						sFieldXPath = "//asobjdef/cabinet[@internal='" & wfvariables.recStructure.sFolderInternalName.Value & "']/object[@internal='" & wfvariables.recStructure.sDocumentInternalName.Value & "']/fields/field/page/fields/field[@internal='" & oFieldInfo.attributes.getNamedItem("internal_name").text & "']/flags"
						debug2file sFieldXPath
						Dim oObjDefField : Set oObjDefField = oXmlObjDef.selectSingleNode( sFieldXPath )
						If Not oObjDefField Is Nothing Then
							debug2file "Feldlänge: " & oObjDefField.attributes.getNamedItem("input_length").text
							oEntry.Item("iMaxLength").Value = oObjDefField.attributes.getNamedItem("input_length").text
						End If
					End If
				End If
				wfvariables.recConfigWFFields.AddListItem oEntry
				
			Next			
		Else
			throwError "Failed to read fields"
		End If
		'Activity Buttons
		xpath = "config/WorkflowType[@type='" & recCommon.sWorkflowModel.Value & "']/Activity[@Name='" & activityName & "']/Buttons/Button" 
		debug2File "Reading buttons configuration"
		Set oNodes = oXmlDoc.selectNodes(xpath)
		If Not oNodes Is Nothing Then
			wfvariables.recConfigButtons.ClearList
			For i = 0 To oNodes.length - 1
				debug2File vbTab & "Button name: " & oNodes(i).text
				debug2File vbTab & vbTab & "Button Enabled: " & oNodes(i).attributes.getNamedItem("enabled").text
				debug2File vbTab & vbTab & "Button Visible: " & oNodes(i).attributes.getNamedItem("visible").text
				debug2File vbTab & vbTab & "Button Function: " & oNodes(i).attributes.getNamedItem("function").text
				
				'add configuration buttons to internal record structure
				'this record will be read in the beforeOpen event to initialize the buttons
				Set oEntry = wfvariables.recConfigButtons.CreateListItem
				oEntry.Item("iEnabled").Value = oNodes(i).attributes.getNamedItem("enabled").text
				oEntry.Item("iVisible").Value = oNodes(i).attributes.getNamedItem("visible").text
				oEntry.Item("sFunction").Value = oNodes(i).attributes.getNamedItem("function").text
				oEntry.Item("sName").Value = oNodes(i).text
				wfvariables.recConfigButtons.AddListItem oEntry
				
			Next			
		Else
			throwError "Failed to read fields"
		End If
		'RecipientRoles
		xpath = "config/WorkflowType[@type='" & recCommon.sWorkflowModel.Value & "']/Activity[@Name='" & activityName & "']/StandardRecipientRoles/Role"
		debug2File xpath
		debug2File "Reading StandardRecipientRoles"
		Set oNodes = oXmlDoc.selectNodes(xpath)
		If Not oNodes Is Nothing Then
			wfvariables.recConfigRecipients.ClearList
			For i = 0 To oNodes.length - 1
				debug2File vbTab & vbTab & "Role / user: " & oNodes(i).text
				debug2File vbTab & vbTab & "addressRoles: " & oNodes(i).attributes.getNamedItem("addressRoles").text
				debug2File vbTab & vbTab & "addressUsers: " & oNodes(i).attributes.getNamedItem("addressUsers").text
				debug2File vbTab & vbTab & "Multiinstance: " & oNodes(i).attributes.getNamedItem("multiinstance").text
				
				'add recipients to internal record structure
				Set oEntry = wfvariables.recConfigRecipients.CreateListItem
				oEntry.Item("iAddressRoles").Value = oNodes(i).attributes.getNamedItem("addressRoles").text
				oEntry.Item("iAddressUsers").Value = oNodes(i).attributes.getNamedItem("addressUsers").text
				oEntry.Item("iMultiinstance").Value = oNodes(i).attributes.getNamedItem("multiinstance").text
				oEntry.Item("sRecipient").Value = oNodes(i).text
				wfvariables.recConfigRecipients.AddListItem oEntry				
			Next			
		Else
			throwError "Failed to read StandardRecipientRoles"
		End If
		
		'ActivityFeatures
		xpath = "config/WorkflowType[@type='" & recCommon.sWorkflowModel.Value & "']/Activity[@Name='" & activityName & "']/Features/Feature"
		debug2File "Reading Features"
		Set oNodes = oXmlDoc.selectNodes(xpath)
		If Not oNodes Is Nothing Then
			wfvariables.recConfigActivityFeatures.ClearList
			For i = 0 To oNodes.length - 1
				Dim currentFeature : currentFeature = oNodes(i).attributes.getNamedItem("Name").text
				Dim FeatureEvent : FeatureEvent = oNodes(i).attributes.getNamedItem("Event").text
				Dim FeatureConditionVariable : FeatureConditionVariable = ""
				Dim FeatureConditionValue : FeatureConditionValue = ""
				
				debug2File vbTab & vbTab & "Feature name: " & currentFeature
				debug2File vbTab & vbTab & "Feature event: " & FeatureEvent
				
				
				
				'add feature to internal structure
				Set oEntry = wfvariables.recConfigActivityFeatures.CreateListItem
				oEntry.Item("sName").Value = currentFeature
				oEntry.Item("sEvent").Value = FeatureEvent
				
							
				xpath = "config/WorkflowType[@type='" & recCommon.sWorkflowModel.Value & "']/Activity[@Name='" & activityName & "']/Features/Feature[@Name='" & currentFeature & "']/Condition"
				Dim oCondition				
				Set oCondition = oXmlDoc.selectSingleNode(xpath)
				If Not oCondition Is Nothing Then
					debug2File vbTab & vbTab & "Condition: " & oCondition.text
					If Trim( oCondition.text ) <> "" Then
						oEntry.Item("sCondition").Value = oCondition.text
					End If
				End If
				
				
				wfvariables.recConfigActivityFeatures.AddListItem oEntry								
			Next			
		Else
			throwError "Failed to read Features"
		End If		
		
	Else
		throwError "Failed to read the configuration file"
	End If
	debug2File "end - readActivityStartConfiguration"
End Function