UPDATE TBDD_MODULES SET DB_VERSION = '2.5.4.2' where NAME = 'fileFLOW' 
GO
DECLARE @SQL nvarchar(max);
IF EXISTS (SELECT 1 FROM sys.databases WHERE [name] = N'IDB')
BEGIN
    SET @SQL = N'--26.09	MS	Shortname angepasst
CREATE OR ALTER   VIEW [dbo].[VWGI_DOCTYPE_IDB] AS 
SELECT 
	T4.GUID as DOCTYPE_ID,
	T4.BEZEICHNUNG AS DOCTYPE,
	T4.BEZEICHNUNG AS DOCTYPE_ONLY,
	T4.KURZNAME,
	T4.FOLDER_FOR_INDEX DYNAMIC_FOLDER,
	T4.AKTIV,
	T4.NAMENKONVENTION,
	T4.OBJEKTTYP,
	T6.OBJECT_TITLE AS OBJECT_STORE,
	T4.IDB_OBJECT_STORE_ID OBJECT_ST_ID,
	T7.CAT_TITLE AS OBJECT_ST_PATH,
	T4.ERSTELLTWANN,
	T4.GEAENDERTWANN,
	T4.SEQUENCE,
	T4.IDB_DOCTYPE_ID
FROM
	DD_ECM.dbo.TBDD_DOKUMENTART T4 LEFT JOIN IDB.dbo.TBIDB_OBJECT_STORE T6 ON T4.IDB_OBJECT_STORE_ID = T6.GUID
	LEFT JOIN IDB.dbo.TBIDB_CATALOG T7 On T6.CAT_ID = T7.GUID
WHERE
	T4.GUID in (SELECT DOKART_ID FROM DD_ECM.dbo.TBDD_DOKUMENTART_MODULE WHERE MODULE_ID = (SELECT GUID FROM DD_ECM.dbo.TBDD_MODULES WHERE SHORT_NAME = ''fileFLOW''));';
    EXEC (@SQL);
END;
GO

DECLARE @SQL nvarchar(max);
IF EXISTS (SELECT 1 FROM sys.databases WHERE [name] = N'IDB')
BEGIN
    SET @SQL = N'
--26.09	MS	Shortname angepasst
ALTER VIEW [dbo].[VWGI_DOCTYPE_USER] AS 
SELECT DISTINCT
	T.GUID AS [USER_ID],
	T.USERNAME,
	--T2.NAME AS GROUP_NAME,
	T3.DOCTYPE_ID,
	T4.BEZEICHNUNG AS DOCTYPE,
	T4.BEZEICHNUNG AS DOCTYPE_ONLY,
	T4.KURZNAME,
	T4.ZIEL_PFAD,
	T4.AKTIV,
	T4.NAMENKONVENTION,
	T4.OBJEKTTYP,
	T4.IDB_OBJECT_STORE_ID OBJECT_ST_ID,
	T5.OBJECT_TITLE as OBJECT_ST_NAME,
	T4.SEQUENCE
FROM
	DD_ECM.dbo.TBDD_USER T,
	DD_ECM.dbo.TBDD_GROUPS_USER T1,
	DD_ECM.dbo.TBDD_GROUPS T2,
	DD_ECM.dbo.TBDD_USRGRP_DOKTYPE T3,
	DD_ECM.dbo.TBDD_DOKUMENTART T4,
	IDB.dbo.TBIDB_OBJECT_STORE T5
WHERE
	T4.AKTIV = 1 AND
	T.GUID = T1.[USER_ID] AND
	T1.GROUP_ID = T2.GUID AND
	T2.GUID = T3.GROUP_ID AND
	T3.DOCTYPE_ID = T4.GUID AND
	T4.IDB_OBJECT_STORE_ID = T5.GUID AND

	T4.GUID in (SELECT DOKART_ID FROM DD_ECM.dbo.TBDD_DOKUMENTART_MODULE WHERE MODULE_ID = (SELECT GUID FROM DD_ECM.dbo.TBDD_MODULES WHERE SHORT_NAME = ''fileFLOW''))
UNION
SELECT DISTINCT
	T.GUID AS [USER_ID],
	T.USERNAME,
	--'' AS GROUP_NAME,
	T4.GUID as DOCTYPE_ID,
	T4.BEZEICHNUNG AS DOCTYPE,
	T4.BEZEICHNUNG AS DOCTYPE_ONLY,
	T4.KURZNAME,
	T4.ZIEL_PFAD,
	T4.AKTIV,
	T4.NAMENKONVENTION,
	T4.OBJEKTTYP,
	T4.IDB_OBJECT_STORE_ID OBJECT_ST_ID,
	T5.OBJECT_TITLE as OBJECT_ST_NAME,
	T4.SEQUENCE
FROM
	DD_ECM.dbo.TBDD_USER T,
	DD_ECM.dbo.TBDD_USER_DOKTYPE T3,
	DD_ECM.dbo.TBDD_DOKUMENTART T4,
	IDB.dbo.TBIDB_OBJECT_STORE T5
WHERE
	T4.AKTIV = 1 AND
	T.GUID = T3.[USER_ID] AND
	T3.DOCTYPE_ID = T4.GUID AND
	T4.IDB_OBJECT_STORE_ID = T5.GUID AND
	T4.GUID in (SELECT DOKART_ID FROM DD_ECM.dbo.TBDD_DOKUMENTART_MODULE WHERE MODULE_ID = (SELECT GUID FROM DD_ECM.dbo.TBDD_MODULES WHERE SHORT_NAME = ''fileFLOW''))'
PRINT @SQL
END
ELSE
 SET @SQL = N'
--26.09	MS	Shortname angepasst
ALTER VIEW [dbo].[VWGI_DOCTYPE_USER] AS 
SELECT DISTINCT
	T.GUID AS [USER_ID],
	T.USERNAME,
	--T2.NAME AS GROUP_NAME,
	T3.DOCTYPE_ID,
	T4.BEZEICHNUNG AS DOCTYPE,
	T4.BEZEICHNUNG AS DOCTYPE_ONLY,
	T4.KURZNAME,
	T4.ZIEL_PFAD,
	T4.AKTIV,
	T4.NAMENKONVENTION,
	T4.OBJEKTTYP,
	0 OBJECT_ST_ID,
	T5.OBJECT_TITLE as OBJECT_ST_NAME,
	T4.SEQUENCE
FROM
	DD_ECM.dbo.TBDD_USER T,
	DD_ECM.dbo.TBDD_GROUPS_USER T1,
	DD_ECM.dbo.TBDD_GROUPS T2,
	DD_ECM.dbo.TBDD_USRGRP_DOKTYPE T3,
	DD_ECM.dbo.TBDD_DOKUMENTART T4
WHERE
	T4.AKTIV = 1 AND
	T.GUID = T1.[USER_ID] AND
	T1.GROUP_ID = T2.GUID AND
	T2.GUID = T3.GROUP_ID AND
	T3.DOCTYPE_ID = T4.GUID AND
	T4.GUID in (SELECT DOKART_ID FROM DD_ECM.dbo.TBDD_DOKUMENTART_MODULE WHERE MODULE_ID = (SELECT GUID FROM DD_ECM.dbo.TBDD_MODULES WHERE SHORT_NAME = ''fileFLOW''))
UNION
SELECT DISTINCT
	T.GUID AS [USER_ID],
	T.USERNAME,
	--'' AS GROUP_NAME,
	T4.GUID as DOCTYPE_ID,
	T4.BEZEICHNUNG AS DOCTYPE,
	T4.BEZEICHNUNG AS DOCTYPE_ONLY,
	T4.KURZNAME,
	T4.ZIEL_PFAD,
	T4.AKTIV,
	T4.NAMENKONVENTION,
	T4.OBJEKTTYP,
	0 OBJECT_ST_ID,
	T5.OBJECT_TITLE as OBJECT_ST_NAME,
	T4.SEQUENCE
FROM
	DD_ECM.dbo.TBDD_USER T,
	DD_ECM.dbo.TBDD_USER_DOKTYPE T3,
	DD_ECM.dbo.TBDD_DOKUMENTART T4
WHERE
	T4.AKTIV = 1 AND
	T.GUID = T3.[USER_ID] AND
	T3.DOCTYPE_ID = T4.GUID AND
	T4.GUID in (SELECT DOKART_ID FROM DD_ECM.dbo.TBDD_DOKUMENTART_MODULE WHERE MODULE_ID = (SELECT GUID FROM DD_ECM.dbo.TBDD_MODULES WHERE SHORT_NAME = ''fileFLOW''))'
   EXEC (@SQL);
   GO

--26.09	MS	Shortname angepasst
ALTER VIEW [dbo].[VWGI_USER_GROUPS_RELATION] AS 
SELECT DISTINCT
	T.GUID AS [USER_ID],
	T.USERNAME,
	--T2.NAME AS GROUP_NAME,
	T3.DOCTYPE_ID,
	T4.BEZEICHNUNG AS DOCTYPE,
	T4.BEZEICHNUNG AS DOCTYPE_ONLY,
	T4.KURZNAME,
	T4.ZIEL_PFAD,
	T4.AKTIV,
	T4.NAMENKONVENTION,
	T4.OBJEKTTYP,
	T4.IDB_OBJECT_STORE_ID OBJECT_ST_ID,
	T4.SEQUENCE
FROM
	DD_ECM.dbo.TBDD_USER T,
	DD_ECM.dbo.TBDD_GROUPS_USER T1,
	DD_ECM.dbo.TBDD_GROUPS T2,
	DD_ECM.dbo.TBDD_USRGRP_DOKTYPE T3,
	DD_ECM.dbo.TBDD_DOKUMENTART T4
WHERE
	T4.AKTIV = 1 AND
	T.GUID = T1.[USER_ID] AND
	T1.GROUP_ID = T2.GUID AND
	T2.GUID = T3.GROUP_ID AND
	T3.DOCTYPE_ID = T4.GUID AND

	T4.GUID in (SELECT DOKART_ID FROM DD_ECM.dbo.TBDD_DOKUMENTART_MODULE WHERE MODULE_ID = (SELECT GUID FROM DD_ECM.dbo.TBDD_MODULES WHERE SHORT_NAME = 'fileFLOW'))
UNION
SELECT DISTINCT
	T.GUID AS [USER_ID],
	T.USERNAME,
	--'' AS GROUP_NAME,
	T4.GUID as DOCTYPE_ID,
	T4.BEZEICHNUNG AS DOCTYPE,
	T4.BEZEICHNUNG AS DOCTYPE_ONLY,
	T4.KURZNAME,
	T4.ZIEL_PFAD,
	T4.AKTIV,
	T4.NAMENKONVENTION,
	T4.OBJEKTTYP,
	T4.IDB_OBJECT_STORE_ID OBJECT_ST_ID,
	T4.SEQUENCE
FROM
	DD_ECM.dbo.TBDD_USER T,
	DD_ECM.dbo.TBDD_USER_DOKTYPE T3,
	DD_ECM.dbo.TBDD_DOKUMENTART T4
WHERE
	T4.AKTIV = 1 AND
	T.GUID = T3.[USER_ID] AND
	T3.DOCTYPE_ID = T4.GUID AND
	T4.GUID in (SELECT DOKART_ID FROM DD_ECM.dbo.TBDD_DOKUMENTART_MODULE WHERE MODULE_ID = (SELECT GUID FROM DD_ECM.dbo.TBDD_MODULES WHERE SHORT_NAME = 'fileFLOW'))
GO



-- =============================================
-- Author:		DD MS
-- Changed: 09.06.2022	MS ADDED ZOOFLOW
-- Changed: 11.05.2022	MS ADDED PM
-- Changed: 13.08.2020	MS ADDED Zooflow
-- =============================================
ALTER FUNCTION [dbo].[FNZF_GET_MODULE_INFO] (@pUSERNAME VARCHAR(100))
RETURNS @Table TABLE 
    (SequentialOrder INT IDENTITY(1, 1),
	[TYPE]				VARCHAR(50),
	[NAME]				VARCHAR(50),
	[VALUE]				VARCHAR(512))
AS
BEGIN
/*
This function checks all user-relevant relations an
*/
	DECLARE
		@RESULT					VARCHAR(500),
		@USER_ID				INTEGER,
		@USER_PRENAME			VARCHAR(50),
		@USER_SURNAME			VARCHAR(50),
		@USER_SHORTNAME			VARCHAR(50),
		@USER_EMAIL				VARCHAR(50),
		@USER_LANGUAGE			VARCHAR(10),
		@USER_DATE_FORMAT		VARCHAR(10),
		@USER_ECM_ID			INTEGER,
		@IS_IN_MODULE			VARCHAR(5),
		@IS_ADMIN				VARCHAR(5),
		@USER_RIGHT_FILE_DEL	BIT,
		@USERCOUNT_LOGGED_IN	INTEGER,
		@MODULE_NAME			VARCHAR(100),
		@MODULE_GUID			INTEGER,
		@USER_GROUPNAME_CW			VARCHAR(100),
		@ADMIN_GROUPNAME_fileFLOW		VARCHAR(100),
		@USER_GROUPNAME_fileFLOW		VARCHAR(100),
		@ADMIN_GROUPNAME_PM		VARCHAR(100),
		@USER_GROUPNAME_PM		VARCHAR(100),
		@ADMIN_GROUPNAME_CW		VARCHAR(100),
		@USER_GROUPNAME_ZF		VARCHAR(100),
		@ADMIN_GROUPNAME_ZF		VARCHAR(100)

	SET @USER_ID = 0
	SET @IS_ADMIN = 'False'
	SET @IS_IN_MODULE = 'False'
	SET @USERCOUNT_LOGGED_IN = 0
	SET @RESULT = ''

			SET @USER_GROUPNAME_CW = 'CW_USER'
			SET @ADMIN_GROUPNAME_CW = 'CW_ADMINS'
			SET @USER_GROUPNAME_fileFLOW = 'fileFLOW_USER'
			SET @ADMIN_GROUPNAME_fileFLOW = 'fileFLOW_ADMINS'
			SET @USER_GROUPNAME_PM = 'PM_USER'
			SET @ADMIN_GROUPNAME_PM = 'PM_ADMINS'
			SET @USER_GROUPNAME_ZF = 'ZOOFLOW_USER'
			SET @ADMIN_GROUPNAME_ZF = 'ZOOFLOW_ADMINS'


	IF NOT EXISTS(SELECT GUID FROM TBDD_USER WHERE UPPER(USERNAME) = UPPER(@pUSERNAME))
		INSERT INTO @Table (TYPE,NAME,VALUE) VALUES ('USER', 'ERROR','USER NOT CONFIGURED OR LISTED')
	ELSE
		BEGIN
			SELECT @USER_ID = GUID, @USER_ECM_ID = USERID_FK_INT_ECM, @USER_PRENAME = PRENAME,
				@USER_SURNAME = NAME, @USER_SHORTNAME = SHORTNAME,@USER_EMAIL = EMAIL,@USER_LANGUAGE = LANGUAGE,@USER_DATE_FORMAT = DATE_FORMAT FROM TBDD_USER WHERE UPPER(USERNAME) = UPPER(@pUSERNAME)
			INSERT INTO @Table (TYPE,NAME,VALUE) VALUES ('USER', 'USER_ID',@USER_ID);
			INSERT INTO @Table (TYPE,NAME,VALUE) VALUES ('USER', 'USER_PRENAME',@USER_PRENAME);
			INSERT INTO @Table (TYPE,NAME,VALUE) VALUES ('USER', 'USER_SURNAME',@USER_SURNAME);
			INSERT INTO @Table (TYPE,NAME,VALUE) VALUES ('USER', 'USER_SHORTNAME',@USER_SHORTNAME);
			INSERT INTO @Table (TYPE,NAME,VALUE) VALUES ('USER', 'USER_EMAIL',@USER_EMAIL);
			INSERT INTO @Table (TYPE,NAME,VALUE) VALUES ('USER', 'USER_DATE_FORMAT',@USER_DATE_FORMAT);
			INSERT INTO @Table (TYPE,NAME,VALUE) VALUES ('USER', 'USER_LANGUAGE',@USER_LANGUAGE);
			INSERT INTO @Table (TYPE,NAME,VALUE) VALUES ('USER', 'USER_ECM_ID',@USER_ECM_ID);
			
			/*#### ClipboardWatcher ####*/
			SELECT @MODULE_GUID = GUID, @MODULE_NAME = NAME FROM TBDD_MODULES WHERE SHORT_NAME = 'CW'
			SELECT @USERCOUNT_LOGGED_IN = COUNT(*) FROM TBDD_USER_MODULE_LOG_IN WHERE UPPER(MODULE) = UPPER(@MODULE_NAME) AND CLIENT_ID = 1
			--CHECK USER IS IN MODULE_USER_GROUP
			IF EXISTS(select T1.* from TBDD_GROUPS T, TBDD_GROUPS_USER T1 WHERE T.GUID = T1.GROUP_ID AND T1.USER_ID = @USER_ID AND UPPER(T.NAME) = @USER_GROUPNAME_CW)
				BEGIN
					SET @IS_IN_MODULE = 'True'
					SET @RESULT = 'User is part of Group (' + @USER_GROUPNAME_CW + ')'
					IF EXISTS(select T.* from TBDD_USER_MODULES T WHERE T.USER_ID = @USER_ID AND T.MODULE_ID = @MODULE_GUID)
						BEGIN
							SET @RESULT = @RESULT + '| User is also configured in User-Modules'
							select @IS_ADMIN = CONVERT(VARCHAR(5),T.IS_ADMIN),@USER_RIGHT_FILE_DEL = T.RIGHT1 from TBDD_USER_MODULES T WHERE T.USER_ID = @USER_ID AND T.MODULE_ID = @MODULE_GUID
						END
				END
			ELSE
				BEGIN
					SET @RESULT = 'User not part of group (' + @USER_GROUPNAME_CW + ')'
					IF EXISTS(select T.* from TBDD_USER_MODULES T WHERE T.USER_ID = @USER_ID AND T.MODULE_ID = @MODULE_GUID)
						BEGIN
							SET @RESULT = @RESULT + '| BUT User configured in User-Modules'
							SET @IS_IN_MODULE = 'True'
							select @IS_ADMIN = CONVERT(VARCHAR(5),T.IS_ADMIN),@USER_RIGHT_FILE_DEL = T.RIGHT1 from TBDD_USER_MODULES T WHERE T.USER_ID = @USER_ID AND T.MODULE_ID = @MODULE_GUID
						END
				END

			IF EXISTS(select T1.* from TBDD_GROUPS T, TBDD_GROUPS_USER T1 WHERE T.GUID = T1.GROUP_ID AND T1.USER_ID = @USER_ID AND UPPER(T.NAME) = @ADMIN_GROUPNAME_CW)
				BEGIN
					SET @RESULT = @RESULT + '| User is part of group (' + @ADMIN_GROUPNAME_CW + ')'
					SET @IS_ADMIN = 'True'
					SET @IS_IN_MODULE = 'True'
				END
		
			INSERT INTO @Table (TYPE,NAME,VALUE) VALUES ('CW', 'MODULE_ACCESS',@IS_IN_MODULE);
			INSERT INTO @Table (TYPE,NAME,VALUE) VALUES ('CW', 'IS_ADMIN',@IS_ADMIN);
			INSERT INTO @Table (TYPE,NAME,VALUE) VALUES ('CW', 'USER_COUNT_LOGGED_IN',@USERCOUNT_LOGGED_IN);
			INSERT INTO @Table (TYPE,NAME,VALUE) VALUES ('CW', 'RESULT',@RESULT);

			/*#### fileFLOW ####*/
			SET @RESULT = ''
			SELECT @MODULE_GUID = GUID, @MODULE_NAME = NAME FROM TBDD_MODULES WHERE SHORT_NAME = 'fileFLOW'
			SELECT @USERCOUNT_LOGGED_IN = COUNT(*) FROM TBDD_USER_MODULE_LOG_IN WHERE UPPER(MODULE) = UPPER(@MODULE_NAME) AND CLIENT_ID = 1
			--CHECK USER IS IN MODULE_USER_GROUP
			IF EXISTS(select T1.* from TBDD_GROUPS T, TBDD_GROUPS_USER T1 WHERE T.GUID = T1.GROUP_ID AND T1.USER_ID = @USER_ID AND UPPER(T.NAME) = @USER_GROUPNAME_fileFLOW)
				BEGIN
					SET @IS_IN_MODULE = 'True'
					SET @RESULT = 'User is part of Group (' + @USER_GROUPNAME_fileFLOW + ')'
					IF EXISTS(select T.* from TBDD_USER_MODULES T WHERE T.USER_ID = @USER_ID AND T.MODULE_ID = @MODULE_GUID)
						BEGIN
							SET @RESULT = @RESULT + '| User is also configured in User-Modules'
							SET @IS_IN_MODULE = 'True'
							select @IS_ADMIN = CONVERT(VARCHAR(5),T.IS_ADMIN),@USER_RIGHT_FILE_DEL = T.RIGHT1 from TBDD_USER_MODULES T WHERE T.USER_ID = @USER_ID AND T.MODULE_ID = @MODULE_GUID
						END
				END
			ELSE
				BEGIN
					SET @RESULT = 'User not part of group (' + @USER_GROUPNAME_fileFLOW + ')'
					IF EXISTS(select T.* from TBDD_USER_MODULES T WHERE T.USER_ID = @USER_ID AND T.MODULE_ID = @MODULE_GUID)
						BEGIN
							SET @RESULT = @RESULT + '| BUT User configured in User-Modules'
							SET @IS_IN_MODULE = 'True'
							select @IS_ADMIN = CONVERT(VARCHAR(5),T.IS_ADMIN),@USER_RIGHT_FILE_DEL = T.RIGHT1 from TBDD_USER_MODULES T WHERE T.USER_ID = @USER_ID AND T.MODULE_ID = @MODULE_GUID
						END
				END

			IF EXISTS(select T1.* from TBDD_GROUPS T, TBDD_GROUPS_USER T1 WHERE T.GUID = T1.GROUP_ID AND T1.USER_ID = @USER_ID AND UPPER(T.NAME) = @ADMIN_GROUPNAME_fileFLOW)
				BEGIN
					SET @RESULT = @RESULT + '| User is part of group (' + @ADMIN_GROUPNAME_fileFLOW + ')'
					SET @IS_ADMIN = 'True'
					SET @IS_IN_MODULE = 'True'
				END
			
			INSERT INTO @Table (TYPE,NAME,VALUE) VALUES ('fileFLOW', 'MODULE_ACCESS',@IS_IN_MODULE);
			INSERT INTO @Table (TYPE,NAME,VALUE) VALUES ('fileFLOW', 'IS_ADMIN',@IS_ADMIN);
			INSERT INTO @Table (TYPE,NAME,VALUE) VALUES ('fileFLOW', 'USER_COUNT_LOGGED_IN',@USERCOUNT_LOGGED_IN);
			INSERT INTO @Table (TYPE,NAME,VALUE) VALUES ('fileFLOW', 'RESULT',@RESULT);

			
			/*#### PM ####*/
			SET @RESULT = ''
			SELECT @MODULE_GUID = GUID, @MODULE_NAME = NAME FROM TBDD_MODULES WHERE SHORT_NAME = 'PM'
			SELECT @USERCOUNT_LOGGED_IN = COUNT(*) FROM TBDD_USER_MODULE_LOG_IN WHERE UPPER(MODULE) = UPPER(@MODULE_NAME) AND CLIENT_ID = 1
			--CHECK USER IS IN MODULE_USER_GROUP
			IF EXISTS(select T1.* from TBDD_GROUPS T, TBDD_GROUPS_USER T1 WHERE T.GUID = T1.GROUP_ID AND T1.USER_ID = @USER_ID AND UPPER(T.NAME) = @USER_GROUPNAME_PM)
				BEGIN
					SET @IS_IN_MODULE = 'True'
					SET @RESULT = 'User is part of Group (' + @USER_GROUPNAME_PM + ')'
					IF EXISTS(select T.* from TBDD_USER_MODULES T WHERE T.USER_ID = @USER_ID AND T.MODULE_ID = @MODULE_GUID)
						BEGIN
							SET @RESULT = @RESULT + '| User is also configured in User-Modules'
							SET @IS_IN_MODULE = 'True'
							select @IS_ADMIN = CONVERT(VARCHAR(5),T.IS_ADMIN),@USER_RIGHT_FILE_DEL = T.RIGHT1 from TBDD_USER_MODULES T WHERE T.USER_ID = @USER_ID AND T.MODULE_ID = @MODULE_GUID
						END
				END
			ELSE
				BEGIN
					SET @RESULT = 'User not part of group (' + @USER_GROUPNAME_PM + ')'
					IF EXISTS(select T.* from TBDD_USER_MODULES T WHERE T.USER_ID = @USER_ID AND T.MODULE_ID = @MODULE_GUID)
						BEGIN
							SET @RESULT = @RESULT + '| BUT User configured in User-Modules'
							SET @IS_IN_MODULE = 'True'
							select @IS_ADMIN = CONVERT(VARCHAR(5),T.IS_ADMIN),@USER_RIGHT_FILE_DEL = T.RIGHT1 from TBDD_USER_MODULES T WHERE T.USER_ID = @USER_ID AND T.MODULE_ID = @MODULE_GUID
						END
				END

			IF EXISTS(select T1.* from TBDD_GROUPS T, TBDD_GROUPS_USER T1 WHERE T.GUID = T1.GROUP_ID AND T1.USER_ID = @USER_ID AND UPPER(T.NAME) = @ADMIN_GROUPNAME_PM)
				BEGIN
					SET @RESULT = @RESULT + '| User is part of group (' + @ADMIN_GROUPNAME_PM + ')'
					SET @IS_ADMIN = 'True'
					SET @IS_IN_MODULE = 'True'
				END
			
			INSERT INTO @Table (TYPE,NAME,VALUE) VALUES ('PM', 'MODULE_ACCESS',@IS_IN_MODULE);
			INSERT INTO @Table (TYPE,NAME,VALUE) VALUES ('PM', 'IS_ADMIN',@IS_ADMIN);
			INSERT INTO @Table (TYPE,NAME,VALUE) VALUES ('PM', 'USER_COUNT_LOGGED_IN',@USERCOUNT_LOGGED_IN);
			INSERT INTO @Table (TYPE,NAME,VALUE) VALUES ('PM', 'RESULT',@RESULT);
			/*#### ZOOFLOW ####*/
			SET @RESULT = ''
			SELECT @MODULE_GUID = GUID, @MODULE_NAME = NAME FROM TBDD_MODULES WHERE NAME = 'ZooFlow'
			SELECT @USERCOUNT_LOGGED_IN = COUNT(*) FROM TBDD_USER_MODULE_LOG_IN WHERE MODULE = @MODULE_NAME AND CLIENT_ID = 1
			--CHECK USER IS IN MODULE_USER_GROUP
			IF EXISTS(select T1.* from TBDD_GROUPS T, TBDD_GROUPS_USER T1 WHERE T.GUID = T1.GROUP_ID AND T1.USER_ID = @USER_ID AND UPPER(T.NAME) = @USER_GROUPNAME_ZF)
				BEGIN
					SET @IS_IN_MODULE = 'True'
					SET @RESULT = 'User is part of Group (' + @USER_GROUPNAME_PM + ')'
					IF EXISTS(select T.* from TBDD_USER_MODULES T WHERE T.USER_ID = @USER_ID AND T.MODULE_ID = @MODULE_GUID)
						BEGIN
							SET @RESULT = @RESULT + '| User is also configured in User-Modules'
							SET @IS_IN_MODULE = 'True'
							select @IS_ADMIN = CONVERT(VARCHAR(5),T.IS_ADMIN),@USER_RIGHT_FILE_DEL = T.RIGHT1 from TBDD_USER_MODULES T WHERE T.USER_ID = @USER_ID AND T.MODULE_ID = @MODULE_GUID
						END
				END
			ELSE
				BEGIN
					SET @RESULT = 'User NOT part of group (' + @USER_GROUPNAME_ZF + ')'
				END

			IF EXISTS(select T1.* from TBDD_GROUPS T, TBDD_GROUPS_USER T1 WHERE T.GUID = T1.GROUP_ID AND T1.USER_ID = @USER_ID AND UPPER(T.NAME) = @ADMIN_GROUPNAME_ZF)
				BEGIN
					SET @RESULT = @RESULT + '| User is part of group (' + @ADMIN_GROUPNAME_ZF + ')'
					SET @IS_ADMIN = 'True'
					SET @IS_IN_MODULE = 'True'
				END
			
			INSERT INTO @Table (TYPE,NAME,VALUE) VALUES ('ZOOFLOW', 'MODULE_ACCESS',@IS_IN_MODULE);
			INSERT INTO @Table (TYPE,NAME,VALUE) VALUES ('ZOOFLOW', 'IS_ADMIN',@IS_ADMIN);
			INSERT INTO @Table (TYPE,NAME,VALUE) VALUES ('ZOOFLOW', 'USER_COUNT_LOGGED_IN',@USERCOUNT_LOGGED_IN);
			INSERT INTO @Table (TYPE,NAME,VALUE) VALUES ('ZOOFLOW', 'RESULT',@RESULT);
		END
RETURN
END
