<!--- RR-2382 --->
<cfquery datasource="#application.config.DSN#">

IF NOT EXISTS(SELECT * FROM AppSetting WHERE Name = 'SSOAuthenticate')
BEGIN
	INSERT INTO [dbo].[AppSetting]
          ([Name]
          ,[Value])
    VALUES
          ('SSOAuthenticate'
          ,'0')
END

IF NOT EXISTS(SELECT * FROM AppSetting WHERE Name = 'SSOExistingUserMapping')
BEGIN
	INSERT INTO [dbo].[AppSetting]
          ([Name]
          ,[Value])
    VALUES
          ('SSOExistingUserMapping'
          ,'')
END

IF NOT EXISTS(SELECT * FROM AppSetting WHERE Name = 'SSOImportUserMapping')
BEGIN
	INSERT INTO [dbo].[AppSetting]
          ([Name]
          ,[Value])
    VALUES
          ('SSOImportUserMapping'
          ,'')
END

IF NOT EXISTS(SELECT * FROM AppSetting WHERE Name = 'SSOIssuerUrlAuthenticate')
BEGIN
	INSERT INTO [dbo].[AppSetting]
          ([Name]
          ,[Value])
    VALUES
          ('SSOIssuerUrlAuthenticate'
          ,'')
END

IF NOT EXISTS(SELECT * FROM AppSetting WHERE Name = 'SSOProviderName')
BEGIN
	INSERT INTO [dbo].[AppSetting]
          ([Name]
          ,[Value])
    VALUES
          ('SSOProviderName'
          ,'')
END

IF NOT EXISTS(SELECT * FROM AppSetting WHERE Name = 'SSOCertificate')
BEGIN
	INSERT INTO [dbo].[AppSetting]
          ([Name]
          ,[Value])
    VALUES
          ('SSOCertificate'
          ,'')
END

IF NOT EXISTS(SELECT * FROM AppSetting WHERE Name = 'FormAuthenticate')
BEGIN
	INSERT INTO [dbo].[AppSetting]
          ([Name]
          ,[Value])
    VALUES
          ('FormAuthenticate'
          , (SELECT CASE WHEN (SELECT Value FROM AppSetting WHERE(Name = N'NTAuthentUser')) = 'no' OR (SELECT Value FROM AppSetting WHERE(Name = N'ADMixedMode')) = '1' THEN '1' ELSE '0' END))
END

IF NOT EXISTS (
  SELECT
    *
  FROM
    INFORMATION_SCHEMA.COLUMNS
  WHERE
    TABLE_NAME = 'UserProfile' AND COLUMN_NAME = 'SSONameID')
BEGIN
	ALTER TABLE UserProfile ADD
		SSONameID varchar(250) NULL
END

</cfquery>


<cfquery datasource="#application.config.DSN#">
      ALTER VIEW [dbo].[UserProfiles]
	AS
	SELECT     a.PersonID, a.FirstName, a.LastName, a.Email, a.Picture, b.UserID, b.UserName, b.Password, b.PasswordChanged, b.LoginRedirect, b.LoginRedirectAbsolute, 
	                      b.EULAAccepted, b.LastLogin, b.SuperAdmin, b.Administrator, b.SiteDesigner, b.UPManager, b.ApprovalManager, b.SupervisorID, b.GlobalRestrict, 
	                      b.DisableUserAlerts, b.DisableUserWidgets, b.ProfileDomain, b.ADSID, b.ADCanonical, b.USNChanged, b.ADDisabled, b.ChatAutoLogin, b.ChatStatus, b.ChatSound, 
	                      b.ChatAlert, b.DisableChat, b.DefaultUserProfile, b.HideDeptMenu, b.LinksDisplay, b.UserDisabled, b.UserDisabledTime, b.DisabledCodeRun, b.SSONameID,
	                      CASE WHEN b.ADSID IS NULL OR
	                      b.ADSID = '' THEN 0 ELSE 1 END AS ADUser
	FROM         Person AS a INNER JOIN
	                      UserProfile AS b ON a.PersonID = b.PersonID
                            
</cfquery>
