-- for existing EasyList users with EasyMenu, update the connection setting
update BacoSettings 
set SettingName = replace(SettingName, 'CSEasyListConnection', 'CSEasyConnection')
where 
	SettingType = 0
	and SettingGroup = 'general'
	and SettingName like 'CSEasyListConnection%'
	and isnumeric(right(SettingName, 1)) = 1
go

declare @RequestType int
set @RequestType = (select IsNull(LongValue, StringValue) from BacoSettings where SettingType = 0 and SettingGroup = 'general' and SettingName = 'CSEasyListRequestType')

if @RequestType is not null
begin
	update RequestFieldOptions
	set SelectionValues = replace(SelectionValues, '''CSEasyListConnection%''', '''CSEasyConnection%''')
	where 
		RequestType = @RequestType
		and FieldID = 44
		and SelectionValues is not null
		and SelectionValues like '%''CSEasyListConnection%''%'
end
go

delete from BacoSettings where SettingType = 0 and SettingGroup = 'general' and SettingName in ('CSEasyListslic', 'CSEasyScriptlic', 'CSEasyVerifyLic')
go



if object_id('vwCSEasyMenuConnection') is not null
	drop view vwCSEasyMenuConnection
go

create view dbo.vwCSEasyMenuConnection
as
	select ConnName as ConnectionName, DisplayOrder
	from (
		select 'Synergy' as ConnName, 1 as DisplayOrder
		union 
		select rtrim(left(StringValue, 30)) as ConnectionName, 3 as DisplayOrder
		from BacoSettings 
		where SettingType = 0 
			and SettingGroup = N'general' 
			and SettingName like N'CSEasyConnection%' 
			and StringValue is not null 
		union 
		select 'Globe' + bedrnr, 2 as DisplayOrder
		from bedryf
		where Active = 1
			and BackOfficeEnabled = 1
	) d
go
