<!--#include virtual="/NRConfig/GeneralConfig/CNCASPPageUI_GeneralConfig.inc"-->
<% 
'*****************************************************************************
' Copyright (C) 2001 Microsoft Corporation.  All rights reserved.
'
' File:   NRCONFIG/SCAASPInitManager_SCAConfigMain.inc
' Author: Microsoft Corporation.  
'
' Purpose:
'  	Provide functions to manage querystring and data access to API for confiuring general tab
'
'Public Methods and Properties Exposed:
'	- Sub InitManager()
'	Property IsURLFormatGUID [ReadOnly, Boolean]
'	Property IsURLFormatHierarchical [ReadOnly, Boolean]	
'	Property ResServerIndex [ReadOnly, Number]
'	Property IsHostNameToChannelMappingEnabled (ReadOnly, Boolean)
'	Property Error [ReadOnly, String]
'	Property ErrorDetails [ReadOnly, String]
'	Property IsSupportedBrowser [ReadOnly, String]
'	Property IsSSLRunning [Readonly, Boolean] 
'	Property IsLocalHost [Readonly, Boolean] 
'	Property SecurityAlertURL [Readonly, String]
'       Property IsAspEnabled [Readonly, Boolean]
'       Property IsAspWbcEnabled [ReadOnly, Boolean]
'
'*****************************************************************************


'--Define constants

'Define a class to create CInitManager class
Class CNCASPPageManager_GeneralConfig
	
	'Public property	
	Public IsURLFormatGUID
	Public IsURLFormatHierarchical	
	Public ResServerIndex
	Public IsHostNameToChannelMappingEnabled
	Public Error
	Public ErrorDetail
    	Public IsSupportedBrowser
	Public IsSSLRunning
	Public IsLocalHost
	Public SecurityAlertURL
	Public IsAspEnabled
	Public IsAspWbcEnabled
    
	'Define private variable
	Private m_pSCAPI
	
	'---- [Private] Standard Class_Initialize
	Private Sub Class_Initialize()
		' -- init all member with default values
		IsURLFormatGUID = False
		IsURLFormatHierarchical =False	

		ResServerIndex = -1

		Error = IDS_OK_NO_ERROR
		ErrorDetail = ""

	        IsHostNameToChannelMappingEnabled = False
		
		IsLocalHost = False
		IsSSLRunning = False

		Call ChkIsLocalHostConnection()
		Call SetupSSLRunningFlag()
		
		
		SecurityAlertURL = "\NRConfig\SecurityAlert\SecurityAlert.asp?" & "ResServerIndex=" & Request.QueryString("ResServerIndex")
		
		'-- Create an instance of ServerConfiguration API
	   	SET m_pSCAPI = server.createobject("ServerConfigurationAPI.NRSCAPI")
		
		'-- Inititalize this API
		m_pSCAPI.Initialize ( )
		
		
	End Sub
	
	'*************************************************
	'Purpose: Response for all init asp page process for General tab and Dlg
	'         
	'Input:	  None
	'
	'Output:  Get values from API and set up properties 
   	'************************************************* 
    
	Public Sub InitManager()
	
	
	' -- Check browser version and java script enable
	IsSupportedBrowser = VerifyIsSupportedBrowser
	
	' -- Get Resolution index
	ResServerIndex =Request.QueryString(IDS_QUERYSTRING_RESOLUTION_SERVER_INDEX)
	
	' -- Check ResServerIndex exist or not  
	ResServerIndexExist(ResServerIndex)
	
	' -- No Resolution Entry Point not run this code
	If ResServerIndex > ID_NO_RESOLUTION_ENTEY_POINT Then
		
		' --If can get form elements, then update otherwise get data from API
		If GetFormElements Then 

			' -- Update data to API after user submit form
			Call UpdateDataToAPI
			
			If Err.Number <> 0 Then
				Exit Sub
			Else
				If Err.Number = 0 Then
					' -- If no error,Close popup window and back to main ASP Page
					Call CloseWindowAndRedirectToMainASP	
				End If
			End If
		Else	
			' -- Get API data for both tab control renderer and General config UI
			Call GetAPIDataForUI
		End If
		
	
	Else
		' -- Err. Raise 
		Error = IDS_UI_WARNING_NOENTRYPOINTS_ISWRONG
	End If


	End Sub
   	
   	'-- [Private] Update Security data to API 
	Private Sub UpdateDataToAPI
	
   		On Error Resume next
   		
   		' -- Set new script time out 
   		Dim ScriptTimeOut
   		Server.ScriptTimeOut = 100000
   		
   		Dim pGlobalSetting 
		Set pGlobalSetting = m_pSCAPI.GlobalSettings(ResServerIndex)
		
		' -- Error Check
		If Err.number <>0 Then
			Error = IDS_UNEXPEXTED_ERROR & " " & IDS_UI_ERROR_GET_GLOBAL_SETTING 
			ErrorDetail = Err.Description
			Exit Sub
   		End If
		
		Dim pGeneral 
		Set pGeneral = PGlobalSetting.General
		
		' -- Error Check
		If Err.number <>0 Then
			Error = IDS_UNEXPEXTED_ERROR & " " & IDS_UI_ERROR_GET_GLOBAL_SETTING_GENERAL
			ErrorDetail = Err.Description
			Exit Sub
		End If
		
		' -- Update URL Format 
		If IsURLFormatHierarchical Then
		
   			Call pGeneral.SetURLFormatHierarchical
   					
   		Else
   			Call pGeneral.SetURLFormatGUID
   			
   		End If
   		
   		' -- Error Check
   		If Err.number <>0 Then
   			Error = IDS_UNEXPEXTED_ERROR & " " & IDS_UI_ERROR_UPDATE_URL_FORMAT_GUID
   			ErrorDetail = Err.Description
   			Exit Sub
   		End If
   		
   		
   		' -- Update Host Name To Channel Mapp
   		pGeneral.HostNameToChannelMappingEnabled = IsHostNameToChannelMappingEnabled
   		
   		' -- Error Check
		If Err.number <>0 Then
			Error = IDS_UNEXPEXTED_ERROR & " " & IDS_UI_ERROR_UPDATE_MAP_CHANNEL_NAMES
			ErrorDetail = Err.Description
   			Exit Sub
   		End If
   		
 	
   		'--Back to default for script time and bufer
		Server.ScriptTimeOut = ScriptTimeOut
   		
   		' -- clear object
   		
		Set pGeneral = Nothing
		Set pGlobalSetting = Nothing 
		Set m_pSCAPI = Nothing	

   	End Sub
   	
   	'-- [Private] Close popup window and redirect to main asp page after update data to API
	Private Sub CloseWindowAndRedirectToMainASP()
	   		
	   		
	   	' -- Render a java script to close popup window and redirect to main asp
	   	call Response.Write ("<script language='JavaScript'  type='text/javascript'>" & vbCrLf)
		Call Response.Write ("window.opener.location = '../" & IDS_MAIN_CONFIGASPPAGE & "?" & IDS_QUERYSTRING_RESOLUTION_SERVER_INDEX & "=" & Server.URLEncode(ResServerIndex) & _
						"&" &  IDS_QUERYSTRING_CURRENT_TAB_INDEX & "=" & _
						IDS_CONFIG_GENERAL_QUERYSTRING  & "&" & _
						IDS_QUERYSTRING_SKIPSSL_WARNING & "=true" & "&" & _
						IDS_TIME_STAMP & "=" & CDbl(CDate(now)) & "';"  & vbCrLf)
		Call Response.Write ("IsWindowOpenBefore = false;" & vbCrLf)
		Call Response.Write ("window.close();" & vbCrLf)
		call Response.Write ("</script>" & vbCrLf)
   	
   	End Sub
   	
   	  		
	'-- [Private] Get all Form elements for update those element to 
	Private Function GetFormElements()
	

		' -- Get form elements
		IsURLFormatHierarchical = Request.Form(DIS_FORM_ELEMENTS_GENERAL_URLFORMAT)
		IsHostNameToChannelMappingEnabled = Request.Form(DIS_FORM_ELEMENTS_GENERAL_HOSTNAMETOCHANNE)

		' -- Return value
		GetFormElements = CBool(Request.Form(DIS_FORM_ELEMENTS_GENERAL_FORMSUBMIT))
		
	End Function   	
	
	'--[Private] Get API data for UI
	Private Sub GetAPIDataForUI()
		
		On Error Resume next
		
			
		'--Get URL format 
			    	
		Dim pGlobalSetting 
		Set pGlobalSetting = m_pSCAPI.GlobalSettings(ResServerIndex)
		
		' -- Error Check
		If Err.number <>0 Then
			Error = IDS_UNEXPEXTED_ERROR & " " & IDS_UI_ERROR_GET_GLOBAL_SETTING 
			ErrorDetail = Err.Description
			Exit Sub
   		End If
   		
		Dim pGeneral 
		Set pGeneral = pGlobalSetting.General 
		
		' -- Error Check
		If Err.number <>0 Then
			Error = IDS_UNEXPEXTED_ERROR & " " & IDS_UI_ERROR_GET_GLOBAL_SETTING_GENERAL
			ErrorDetail = Err.Description
			Exit Sub
		End If
		
		Dim  bIsURLFormatGUID
		Dim  bIsURLFormatHierarchical
		
		' -- Get URL Format
		IsURLFormatGUID = pGeneral.IsURLFormatGUID 
		' -- Error Check
		If Err.number <>0 Then
			Error = IDS_UNEXPEXTED_ERROR & " " & IDS_UI_ERROR_GET_URL_FORMAT_GUID
			ErrorDetail = Err.Description
			Exit Sub
		End If
		
		IsURLFormatHierarchical = pGeneral.IsURLFormatHierarchical
		
		' -- Error Check
		If Err.number <>0 Then
			Error = IDS_UNEXPEXTED_ERROR & " " & IDS_UI_ERROR_GET_URL_FORMAT_GUID
			ErrorDetail = Err.Description
			Exit Sub
		End If
		
		' -- Get Host Name to Channel Map
		IsHostNameToChannelMappingEnabled = pGeneral.HostNameToChannelMappingEnabled
			
		' -- Error Check
		If Err.number <>0 Then
			Error = IDS_UNEXPEXTED_ERROR & " " & IDS_UI_ERROR_GET_MAP_CHANNEL_NAMES
			ErrorDetail = Err.Description
			Exit Sub
		End If
		
		' -- Get the IsAspSupported and IsAspWbcSupported
		Dim pLocalSettings
		Dim pLocalServerSettings

		Set pLocalSettings = m_pSCAPI.LocalSettings(ResServerIndex)
		
		' -- Error Check
		If Err.number <>0 Then
			Error = IDS_UNEXPEXTED_ERROR & " " & IDS_UI_ERROR_GET_LOCAL_SETTING
			ErrorDetail = Err.Description
			Exit Sub
		End If
		
		Set pLocalServerSettings = pLocalSettings.CMSLocalServerSettings
		
		' -- Error Check
		If Err.number <>0 Then
			Error = IDS_UNEXPEXTED_ERROR & " " & IDS_UI_ERROR_GET_LOCAL_SERVER_SETTING
			ErrorDetail = Err.Description
			Exit Sub
		End If
		
		IsAspEnabled = pLocalServerSettings.IsAspEnabled
		
		' -- Error Check
		If Err.number <>0 Then
			Error = IDS_UNEXPEXTED_ERROR & " " & IDS_UI_ERROR_GET_LOCAL_ASP_ENABLED
			ErrorDetail = Err.Description
			Exit Sub
		End If
		
		IsAspWbcEnabled = pLocalServerSettings.IsAspWbcEnabled
		
		' -- Error Check
		If Err.number <>0 Then
			Error = IDS_UNEXPEXTED_ERROR & " " & IDS_UI_ERROR_GET_LOCAL_ASP_WBC_ENABLED
			ErrorDetail = Err.Description
			Exit Sub
		End If
		
		' -- clear object
		Set pGeneral = Nothing
		Set pGlobalSetting = Nothing

	End Sub
	
	' ---- [Private] Chk if we are using LocalHost
	Private Sub ChkIsLocalHostConnection()

		Dim strRemoteHost
		Dim strLocalHost

		strRemoteHost = CStr(Request.ServerVariables(IDS_ACCESS_REMOTE_ADDR))
		strLocalHost = CStr(Request.ServerVariables(IDS_ACCESS_LOCAL_ADDR))

		If (strLocalHost = IDS_LOCAL_HOST_ID) OR (strRemoteHost = IDS_LOCAL_HOST_ID) OR _
		   (strLocalHost = strRemoteHost) Then
			IsLocalHost = True
		End If
	End Sub



	' ---- [Private] Chk is SSL is running
	Private Sub SetupSSLRunningFlag()

		Dim strSSLStatus 

		strSSLStatus = CStr(Request.ServerVariables(IDS_ACCESS_HTTPS))

		If strSSLStatus = "on" Then
			IsSSLRunning = True
		End If

	End Sub
	
	
End Class
%>
