<%
' *****************************************************************************
' File:		CNCASPPageManager_NTDomainAddAcceptor.inc
'
' Version: 	Microsoft Content Management Server
' Author:	Microsoft Corporation
' Purpose:	Contains ASP programming logic for the "Access" tab and 
'			configuration dialog for SCA.
'
' Implements the INCASPPageManager interface:
'	- Sub InitManager()
'	- Property Error
'	- Property ErrorDetails
'
' Exposes the following properties
'	- Property NewNTDomainName [readonly String]
'
' *****************************************************************************

Const IDS_E_ADDNTDOMAIN_NO_RESSERVERINDEX = "No ResServerIndex Present."
Const IDS_E_ADDNTDOMAIN_NO_BINDING_INFO = "No Windows NT Domain Name Present."
Const IDS_E_ADDNTDOMAIN_CANNOT_GET_NTDOMAIN = "Cannot retrieve this Windows NT Domain."

Class CNCASPPageManager_NTDomainAddAcceptor

	Public Error
	Public ErrorDetails
	
	' ---- Properties of the new container to be added
	Public NewNTDomainName
	
	Private m_nResServerIndex
	
	Private m_strNTDomainName
	
	' ---- [Private] Class standard initialize
    Private Sub Class_Initialize()
    	Error = ""
    	ErrorDetails = ""

    	m_nResServerIndex = 0
    	
    	m_strNTDomainName = ""
    	
		NewNTDomainName = ""
    End Sub 

	' ---- [Public] CNCASPPageManager standard init method
	Public Sub InitManager()	
		If GetResServerIndex() = False Then
			Exit Sub
		End If

		If GetBindingInfo() = False Then
			Exit Sub
		End If

		Call ValidateNTDomain()
	End Sub
	
	' ---- [Public] The MCMS Index for communicating with the server
	Property Get ResServerIndex()
		ResServerIndex = m_nResServerIndex
	End Property 
	
	' ---- [Private] Retrieve the ResServerIndex we need for communication with SCAPI; return success flag.
	Private Function GetResServerIndex()
		If ( Request.QueryString("ResServerIndex") <> "" ) Then
			m_nResServerIndex = CLng( Request.QueryString("ResServerIndex") )
			GetResServerIndex = True
		Else
			Error = IDS_E_ADDNTDOMAIN_NO_RESSERVERINDEX
			GetResServerIndex = False
		End If
	End Function

	' ---- [Private] Retrieve user entered OU name
	Private Function GetBindingInfo()
		m_strNTDomainName = Request.Form("SCA_txtNTDomainNameToAdd")
		
		If (m_strNTDomainName = "") Then
			Error = IDS_E_ADDNTDOMAIN_NO_BINDING_INFO
			GetBindingInfo = False
		Else
			GetBindingInfo = True
		End If
	End Function
	
	' ---- [Private] Validate user-entered NT Domain name
	Private Sub ValidateNTDomain()
		Dim pSCAPI
	   	Set pSCAPI = Server.CreateObject("ServerConfigurationAPI.NRSCAPI")
		Call pSCAPI.Initialize()
		Dim pDBSetting
		Set pDBSetting = pSCAPI.CurrentDatabaseSettings( m_nResServerIndex )
			
		' -- retrieve Authrntication setting object
		Dim pUserAuthenticationSettings
		Set pUserAuthenticationSettings = pSCAPI.UserAuthenticationSettings( m_nResServerIndex )
		
		' -- retrieve INRNTSettings
		Dim pNTSettings
		Set pNTSettings = pUserAuthenticationSettings.NT

		' -- attempt to get the container so that we validate its existence
		If (Not GetNTDomainSafe(pNTSettings) ) Then
			Exit Sub
		End If		
	End Sub
	
	' ---- [Private] Validate the OU
	Private Function GetNTDomainSafe( pNTSettings )
		Err.Clear
		On Error Resume Next
		
		' -- attempt to retrieve NT Domain by name
		Dim pNewNTDomain
		Set pNewNTDomain = pNTSettings.GetNTDomain( m_strNTDomainName )

		If (pNewNTDomain Is Nothing) Then
			Error = IDS_E_ADDNTDOMAIN_CANNOT_GET_NTDOMAIN
			ErrorDetails = Err.Description
			GetNTDomainSafe = False
			Exit Function
		End If
		
		' -- all successful
		NewNTDomainName = pNewNTDomain.Name

		GetNTDomainSafe = True
	End Function
	
End Class

%>