'**********************************************************
' InitializeRepeatTraining	(added by CC-000281)
' @description: initializes the repeat training workflow
' @param: none
' @return nothing
'**********************************************************
Function InitializeRepeatTraining	

	Dim xmlFile
	Dim oNode
	
	Dim oXmlDoc : Set oXmlDoc = CreateObject("Msxml2.DOMDocument")
	
	wfvariables.sDocumentNumber.Value = "-"	'currently in the beforeforward event is checked it the workflow got a document. in this case we don't need a document, so we set the variable to -
	
	lAcceptedType = thisprocess.WFFile.FileObjects(0).ObjectType
	For a = 0 To thisprocess.WFFile.FileObjects.Count - 1
		'the type of item (0) is already checked in the start event of the workflow,
		'now check, if each file in the WFFile got the same type
		If thisprocess.WFFile.FileObjects(a).ObjectType <> lAcceptedType Then
			wfvariables.sError.Value = "Nur Objekte vom Typ 'Person' dürfen an diesen Workflow übergeben werden. / Can only be used for objects of the type 'Person'."
			wfvariables.bCorrect.Value = 1
			Exit Function 			
		End If
	Next
	
	wfvariables.recStructure.iFolderID.Value = "1"	'this value is set for compatibility to the BPL Framework, cause currently no client protocol will be stored if the value is not set. And if no client protocol is set the merge instances function will not work
		
	For a = 0 To thisprocess.WFFile.FileObjects.Count - 1

		'CC-000900
		'sReturn = getPersonObjectInformation(thisprocess.WFFile.FileObjects(a).Id)
		Set myPerson = getPersonObjectInformation(thisprocess.WFFile.FileObjects(a).Id)

		Set o1 = wfvariables.recTrainees.CreateListItem

		'CC-0009000
		o1.Item("sName").Value = myPerson.sPersonName
		o1.Item("sLogin").Value = myPerson.sPersonLogin
		o1.Item("sTrainingStatus").Value = myPerson.sPersonTrainingStatus
		o1.Item("sStatusInformation").Value = myPerson.sPersonStatusInformation
		o1.Item("sTrainingDate").Value = myPerson.sPersonTrainingDate
		o1.Item("sTrainingType").Value = myPerson.sPersonTrainingType		
		o1.Item("sEmail").Value = myPerson.sPersonEmail
		o1.Item("sResponsible").Value = myPerson.sPersonResponsible
		o1.Item("sUserID").Value = myPerson.sPersonUserID
		o1.Item("sDocTitle").Value = myPerson.sDocTitle
		o1.Item("sDocNumber").Value = myPerson.sDocNumber
		o1.Item("sDocVersion").Value = myPerson.sDocVersion
		o1.Item("sFolderID").Value = myPerson.sFolderID
		o1.Item("ID").Value = thisprocess.WFFile.FileObjects(a).Id

		
		If o1.Item("sTrainingType").Value = "Leseschulung / Read and understood" Or o1.Item("sTrainingType").Value = "" Then
			'check if the process starter is member of the controlled documents supervisor role
			Dim bAllowRepetition : bAllowRepetition = False
			sTrainingResponsible = myPerson.sPersonResponsible 'CC-000900
			Set oCreatorRoles = wforganisation.GetOrgObjectById(thisprocess.Creator).GetPredecessorsByClassName("Rolle", true)
			For iR = 0 To oCreatorRoles.count -1
				debug2File "-----"
				debug2File "Process starter is member of the role: " & oCreatorRoles.Item(iR).Name
				debug2File "check if the role is training responsible or a supervisor role..."
				If oCreatorRoles.Item(iR).Name = "Controlled_Documents_Supervisor" Or oCreatorRoles.Item(iR).Name = sTrainingResponsible Then
					bAllowRepetition = True
					debug2File vbTab & "Role is either responsible or supervisor..."
				End If
			Next	
			If bAllowRepetition = True Then	
				wfvariables.recTrainees.AddListItem o1			
			Else
				wfvariables.sHint.value = "Sie sind nicht für alle gewählten Personen schulungsverantwortlich. / You are not responsible for training for all selected people."			
			End If
		Else
			wfvariables.sHint.value = "Nur für Schulungen vom Typ 'Leseschulung / Read and understood'. / Only available for training of type 'Leseschulung / Read and understood'."			
		End If
		
		
	Next
	
	'the objects must be moved to the info area, cause the framework tries to check in all objects in the workspace 
	For a = 0 To thisprocess.WFFile.FileObjects.Count - 1
		lID = thisprocess.WFFile.FileObjects.Item(0).Id
		lType = thisprocess.WFFile.FileObjects.Item(0).ObjectType
		thisprocess.WFFile.DeleteFileObject lID	
		thisprocess.WFFile.AddFileObject lID,lType , false, 1		
	Next
	
	Dim oFSO : Set oFSO = CreateObject("Scripting.FileSystemObject")
	If oFSO.FileExists (xmlFile) = True Then 'delete the xmlFile
		oFSO.DeleteFile xmlFile
	End If
	'clean up
	Set oFSO = Nothing	
	
End Function