'**********************************************************
' loadResponsibleList (added for CC-000798)
' @description: loads all roles for the training responsible selection and filter with the ResponsibleBlacklist Parameter from globalConfig
' @param: none
' @return: nothing
'**********************************************************
Function loadResponsibleList()
	myBlacklist = getValueFromGlobalConfig("ResponsibleBlacklist")

	Set oAllRoles = wforganisation.GetRoles()
	Dim RoleIdList
	RoleIdList = ""
	For y = 0 To oAllRoles.Count -1 
		if isRoleInBlacklist(oAllRoles.Item(y).Name, myBlacklist) = false Then 
			RoleIdList = RoleIdList & ";" & oAllRoles.Item(y).ID
		End If
	Next
	
	fillOrgUserMaskField wfvariables.TrainingResponsible.name, split(RoleIdList,";")
End Function

'**********************************************************
' getValueFromGlobalConfig (added for CC-000798)
' @description: gets a parameter value from the global config
' @param: sParameterName - the name of the parameter
' @return: the value of the parameter or an empty string if the parameter can not be found
'**********************************************************
Function getValueFromGlobalConfig(sParameterName)
	getValueFromGlobalConfig = ""
	For x = 0 To wfvariables.globalConfig.Count - 1
		If wfvariables.globalConfig.Item(x).Item("Name").value = sParameterName Then
			getValueFromGlobalConfig = wfvariables.globalConfig.Item(x).Item("Value").value
			Exit Function
		End If
	Next
End Function

'**********************************************************
' isRoleInBlacklist (added for CC-000798)
' @description: checks if the given role is in the blacklist (the blacklist is defined in the global config file)
' @param: sRolename - string, the name of the role which should be checked
' @return: true if the role is in the blacklist, otherwise false
'**********************************************************
Function isRoleInBlacklist (sRolename, Blacklist)	
	Dim aBlacklist : aBlacklist = split(Blacklist,";")
	For Each BlacklistItem In aBlacklist
		If BlackListItem <> "" Then
			Set re = New RegExp
			With re
				.Pattern = BlackListItem
				.IgnoreCase = True
				.Global = False
			End With

			If re.Test(sRolename) Then
				isRoleInBlacklist = True
				Exit Function
			End If
		End If
	Next ' aBlacklist
	isRoleInBlacklist = False
End Function