USE DD_ECM
GO
INSERT INTO [dbo].[TBAPPSERV_CRON_JOB]
           ([TITLE]
           ,[CRON_DEFINITION]
           ,[ACTIVE])
     VALUES
           ('Every Minute'
           ,'30 * * ? * * *'
           ,1)
GO
INSERT INTO [dbo].[TBAPPSERV_CRON_JOB]
           ([TITLE]
           ,[CRON_DEFINITION]
           ,[ACTIVE])
     VALUES
           ('Every 2 Minutes'
           ,'15,30 0/2 * ? * * *'
           ,1)
GO
INSERT INTO [dbo].[TBAPPSERV_CRON_JOB]
           ([TITLE]
           ,[CRON_DEFINITION]
           ,[ACTIVE])
     VALUES
           ('Every 5 Minutes'
           ,'30,30 0/5 * ? * * *'
           ,1)
GO

CREATE TABLE TBDD_USER_MODULE
(
	USER_ID INTEGER, 
	MODULE_SHORT	VARCHAR(30),
	USERNAME		VARCHAR(100),
	USER_PRENAME	VARCHAR(50), 
	USER_SURNAME	VARCHAR(50), 
	USER_SHORTNAME	VARCHAR(50),
	USER_EMAIL		VARCHAR(100), 
	USER_LANGUAGE	VARCHAR(10),
	USER_DATE_FORMAT VARCHAR(10),
	USER_RIGHT_FILE_DEL		BIT,
	MODULE_ACCESS			BIT,
	IS_ADMIN				BIT, 
	USERCOUNT_LOGGED_IN		INTEGER,
	COMMENT					VARCHAR(500),
	USER_RIGHT2				BIT NOT NULL DEFAULT 1,
	USER_RIGHT3				BIT NOT NULL DEFAULT 0,
	USER_RIGHT4				BIT NOT NULL DEFAULT 0,
	USER_RIGHT5				BIT NOT NULL DEFAULT 0,
	WORKING_MODE			VARCHAR(5000) NOT NULL DEFAULT ''
	,ADDITIONAL_TITLE		VARCHAR(200));

--DECLARE
--	@GUID			INTEGER,
--	@USERNAME		VARCHAR(500)		
								
--DECLARE cursorUser1 CURSOR FOR 
--	select GUID,lower(USERNAME) FROM TBDD_USER 
--  OPEN cursorUser1 
--    FETCH NEXT FROM cursorUser1 INTO @GUID,@USERNAME
--    WHILE @@FETCH_STATUS = 0
--	BEGIN
--		DELETE FROM TBDD_USER_MODULE WHERE USER_ID = @GUID AND MODULE_SHORT = 'CW';
--		INSERT INTO [dbo].[TBDD_USER_MODULE]
--           ([USER_ID]
--           ,[MODULE_SHORT]
--		   ,USERNAME
--           ,[USER_PRENAME]
--           ,[USER_SURNAME]
--           ,[USER_SHORTNAME]
--           ,[USER_EMAIL]
--           ,[USER_LANGUAGE]
--           ,[USER_DATE_FORMAT]
--           ,[USER_RIGHT_FILE_DEL]
--           ,[MODULE_ACCESS]
--           ,[IS_ADMIN]
--           ,[USERCOUNT_LOGGED_IN]
--           ,[COMMENT]
--           ,[WORKING_MODE]
--           ,[ADDITIONAL_TITLE])
--		SELECT [USER_ID]
--           ,'CW'
--		   ,@USERNAME
--           ,[USER_PRENAME]
--           ,[USER_SURNAME]
--           ,[USER_SHORTNAME]
--           ,[USER_EMAIL]
--           ,[USER_LANGUAGE]
--           ,[USER_DATE_FORMAT]
--           ,[USER_RIGHT_FILE_DEL]
--           ,[MODULE_ACCESS]
--           ,[IS_ADMIN]
--           ,[USERCOUNT_LOGGED_IN]
--           ,[COMMENT]
--           ,[WORKING_MODE]
--           ,[ADDITIONAL_TITLE]  FROM [dbo].[FNDD_CHECK_USER_MODULE] (@USERNAME,'CW',1);
--		DELETE FROM TBDD_USER_MODULE WHERE USER_ID = @GUID AND MODULE_SHORT = 'PM';
--		INSERT INTO [dbo].[TBDD_USER_MODULE]
--           ([USER_ID]
--		   ,USERNAME
--           ,[MODULE_SHORT]
--           ,[USER_PRENAME]
--           ,[USER_SURNAME]
--           ,[USER_SHORTNAME]
--           ,[USER_EMAIL]
--           ,[USER_LANGUAGE]
--           ,[USER_DATE_FORMAT]
--           ,[USER_RIGHT_FILE_DEL]
--           ,[MODULE_ACCESS]
--           ,[IS_ADMIN]
--           ,[USERCOUNT_LOGGED_IN]
--           ,[COMMENT]
--		   ,[USER_RIGHT2]
--			,[USER_RIGHT3]
--			,[USER_RIGHT4]
--			,[USER_RIGHT5]
--           ,[WORKING_MODE]
--           ,[ADDITIONAL_TITLE])
--		SELECT [USER_ID]
--			,@USERNAME
--			,'PM'
--			,[USER_PRENAME]
--			,[USER_SURNAME]
--			,[USER_SHORTNAME]
--			,[USER_EMAIL]
--			,[USER_LANGUAGE]
--			,[USER_DATE_FORMAT]
--			,[USER_RIGHT_FILE_DEL]
--			,[MODULE_ACCESS]
--			,[IS_ADMIN]
--			,[USERCOUNT_LOGGED_IN]
--			,[COMMENT]
--			,[USER_RIGHT2]
--			,[USER_RIGHT3]
--			,[USER_RIGHT4]
--			,[USER_RIGHT5]
--			,[WORKING_MODE]
--			,[ADDITIONAL_TITLE]  FROM [dbo].[FNDD_CHECK_USER_MODULE] (@USERNAME,'PM',1);

--		FETCH NEXT FROM cursorUser1 INTO @GUID,@USERNAME
--	END
--CLOSE cursorUser1
--DEALLOCATE cursorUser1
--GO


--select * from TBAPPSERV_CRON_JOB
--select * from TBAPPSERV_CRON_DETAIL
--select * from TBAPPSERV_CRON_DETAIL_HISTORY where DETAIL_ID = 4 order by guid desc
--select * from TBCW_PROF_DATA_SEARCH where PROFILE_ID = 56 order by TAB_INDEX
--delete from TBAPPSERV_CRON_DETAIL where TITLE like '%PM%' or TITLE LIKE '%CW%' or TITLE in ('TBIDB_DOC_INFO','TBDD_SQL_COMMANDS','DTGRID_COLUMNS_WITH_SQL','DTGRID_SQL_DEFINITION','DTCONTROLS_WITH_SQL')
Insert Into TBAPPSERV_CRON_DETAIL (
CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
2,			1,		'VWPM_PROFILE_USER',	'VWPM_PROFILE_USER',	1,					'SELECT * FROM VWPM_PROFILE_USER');
Insert Into TBAPPSERV_CRON_DETAIL (
CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
2,			1,		'VWDD_USER_CLIENT',	'VWDD_USER_CLIENT',	1,					'SELECT * FROM VWDD_USER_CLIENT');
Insert Into TBAPPSERV_CRON_DETAIL (
CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
2,			1,		'TBDD_CONNECTION',	'TBDD_CONNECTION',	1,					'SELECT * FROM TBDD_CONNECTION WHERE AKTIV = 1');
Insert Into TBAPPSERV_CRON_DETAIL (
CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
3,			1,		'TBCW_PROF_DOC_SEARCH',	'TBCW_PROF_DOC_SEARCH',	1,					'SELECT * FROM TBCW_PROF_DOC_SEARCH WHERE ACTIVE = 1');
Insert Into TBAPPSERV_CRON_DETAIL (
CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
3,			1,		'TBCW_PROF_DATA_SEARCH',	'TBCW_PROF_DATA_SEARCH',	1,					'SELECT * FROM TBCW_PROF_DATA_SEARCH WHERE ACTIVE = 1');
Insert Into TBAPPSERV_CRON_DETAIL (
CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
3,			1,		'TBDD_USER_MODULE',	'TBDD_USER_MODULE',	1,					'SELECT * FROM TBDD_USER_MODULE');

Insert Into TBAPPSERV_CRON_DETAIL (
CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
3,			1,		'TBPM_KONFIGURATION',	'TBPM_KONFIGURATION',	1,					'SELECT * FROM TBPM_KONFIGURATION');
Insert Into TBAPPSERV_CRON_DETAIL (
CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
3,			1,		'TBDD_GUI_LANGUAGE_PHRASE',	'TBDD_GUI_LANGUAGE_PHRASE',	1,					'SELECT * FROM TBDD_GUI_LANGUAGE_PHRASE WHERE MODULE IN (''PM'',''All Modules'')');
Insert Into TBAPPSERV_CRON_DETAIL (
CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
3,			1,		'TBDD_3RD_PARTY_MODULES',	'TBDD_3RD_PARTY_MODULES',	1,					'SELECT * FROM TBDD_3RD_PARTY_MODULES WHERE ACTIVE = 1');
Insert Into TBAPPSERV_CRON_DETAIL (
CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
3,			1,		'TBPM_PROFILE_SEARCH',	'TBPM_PROFILE_SEARCH',	1,					'SELECT * FROM TBPM_PROFILE_SEARCH WHERE ACTIVE = 1');
Insert Into TBAPPSERV_CRON_DETAIL (
CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
3,			1,		'TBPM_MAIN_VIEW_GROUPS',	'TBPM_MAIN_VIEW_GROUPS',	1,					'SELECT * FROM TBPM_MAIN_VIEW_GROUPS WHERE ACTIVE = 1');
Insert Into TBAPPSERV_CRON_DETAIL (
CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
3,			1,		'TBPM_CHART',	'TBPM_CHART',	1,					'SELECT * FROM TBPM_CHART');
Insert Into TBAPPSERV_CRON_DETAIL (
CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
3,			1,		'TBDD_MODULES',	'TBDD_MODULES',	1,					'SELECT * FROM TBDD_MODULES');
Insert Into TBAPPSERV_CRON_DETAIL (
CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
3,			1,		'DTCONTROLS_WITH_SQL',	'DTCONTROLS_WITH_SQL',	1,					'SELECT * FROM TBPM_PROFILE_CONTROLS WHERE LEN(SQL_UEBERPRUEFUNG) > 0 AND CTRL_TYPE <> ''BUTTON''');
Insert Into TBAPPSERV_CRON_DETAIL (
CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
3,			1,		'TBPM_PROFILE',	'TBPM_PROFILE',	1,					'select * from TBPM_PROFILE where ACTIVE = 1');
Insert Into TBAPPSERV_CRON_DETAIL (
CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
2,			1,		'VWPM_CONTROL_INDEX',	'VWPM_CONTROL_INDEX',	1,					'SELECT * FROM VWPM_CONTROL_INDEX ORDER BY PROFIL_ID,Y_LOC, X_LOC');
--Insert Into TBAPPSERV_CRON_DETAIL (
--CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
--2,			1,		'TBDD_SQL_COMMANDS',	'TBDD_SQL_COMMANDS',	1,					'SELECT * FROM TBDD_SQL_COMMANDS');
Insert Into TBAPPSERV_CRON_DETAIL (
CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
2,			1,		'TBPM_PROFILE_FINAL_INDEXING',	'TBPM_PROFILE_FINAL_INDEXING',	1,					'select * from TBPM_PROFILE_FINAL_INDEXING where ACTIVE = 1');
Insert Into TBAPPSERV_CRON_DETAIL (
CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
2,			1,		'TBPM_PROFILE_CONTROLS_LANGUAGE',	'TBPM_PROFILE_CONTROLS_LANGUAGE',	1,					
'SELECT ''de-DE'' as LANGUAGE, [dbo].[FNPM_LANGUAGE_CONTROL_TEXT] (NAME,''de-DE'',CTRL_TYPE,CTRL_TEXT) CTRL_CAPTION_LANG, * FROM TBPM_PROFILE_CONTROLS WHERE CONTROL_ACTIVE = 1 ORDER BY Y_LOC, X_LOC');

Insert Into TBAPPSERV_CRON_DETAIL (
CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
2,			1,		'DTGRID_COLUMNS_WITH_SQL',	'DTGRID_COLUMNS_WITH_SQL',	1,					
'SELECT T1.GUID As CONTROL_ID, T1.PROFIL_ID,T.SEQUENCE, T.CONNECTION_ID, T.SQL_COMMAND, T.SPALTENNAME,T.FORMATTYPE,T.FORMATSTRING from TBPM_CONTROL_TABLE T, TBPM_PROFILE_CONTROLS T1 WHERE CONTROL_ACTIVE = 1  AND T.CONTROL_ID = T1.GUID AND LEN(T.SQL_COMMAND) > 0 AND T.LOAD_AFT_LOAD_CONTROL = 0');
--delete from TBAPPSERV_CRON_DETAIL where TITLE = 'TBPM_CONTROL_TABLE'
Insert Into TBAPPSERV_CRON_DETAIL (
CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
2,			1,		'TBPM_CONTROL_TABLE',	'TBPM_CONTROL_TABLE',	1,					
'SELECT T1.PROFIL_ID, T.* from TBPM_CONTROL_TABLE T, TBPM_PROFILE_CONTROLS T1 WHERE T1.CONTROL_ACTIVE = 1  AND  T.CONTROL_ID = T1.GUID');
--delete from TBAPPSERV_CRON_DETAIL where TITLE = 'DTGRID_SQL_DEFINITION'
Insert Into TBAPPSERV_CRON_DETAIL (
CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
2,			1,		'DTGRID_SQL_DEFINITION',	'DTGRID_SQL_DEFINITION',	1,					
'SELECT T1.GUID As CONTROL_ID, T1.PROFIL_ID, T.CONNECTION_ID, T.SQL_COMMAND, T.SPALTENNAME,T.FORMATTYPE,T.FORMATSTRING, T.SEQUENCE from TBPM_CONTROL_TABLE T, TBPM_PROFILE_CONTROLS T1 WHERE T1.CONTROL_ACTIVE = 1  AND  T.CONTROL_ID = T1.GUID AND LEN(T.SQL_COMMAND) > 0 AND T.LOAD_AFT_LOAD_CONTROL = 1 ');
Insert Into TBAPPSERV_CRON_DETAIL (
CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
2,			1,		'TBPM_PROFILE_CONTROLS_SQL_UEP',	'TBPM_PROFILE_CONTROLS_SQL_UEP',	1,					
'select PROFIL_ID,NAME,CONNECTION_ID,SQL_UEBERPRUEFUNG FROM TBPM_PROFILE_CONTROLS WHERE CONTROL_ACTIVE = 1 AND LEN(SQL_UEBERPRUEFUNG) > 0 ');
Insert Into TBAPPSERV_CRON_DETAIL (
CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
3,			1,		'TBIDB_ACCESSRIGHT',	'TBIDB_ACCESSRIGHT',	1,					
'select * from IDB.dbo.TBIDB_ACCESSRIGHT');
Insert Into TBAPPSERV_CRON_DETAIL (
CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
3,			1,		'TBIDB_ATTRIBUTE',	'TBIDB_ATTRIBUTE',	1,					
'select * from IDB.dbo.TBIDB_ATTRIBUTE');
Insert Into TBAPPSERV_CRON_DETAIL (
CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
3,			1,		'VWDDINDEX_MAN',	'VWDDINDEX_MAN',	1,					
'select * from VWDDINDEX_MAN');
Insert Into TBAPPSERV_CRON_DETAIL (
CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
3,			1,		'VWDDINDEX_AUTOM',	'VWDDINDEX_AUTOM',	1,					
'select * from VWDDINDEX_AUTOM');
Insert Into TBAPPSERV_CRON_DETAIL (
CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
3,			1,		'VWGI_DOCTYPE_IDB',	'VWGI_DOCTYPE_IDB',	1,					
'select * from VWGI_DOCTYPE_IDB');
Insert Into TBAPPSERV_CRON_DETAIL (
CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
3,			1,		'TBDD_INDEX_MAN_POSTPROCESSING',	'TBDD_INDEX_MAN_POSTPROCESSING',	1,					
'select * from TBDD_INDEX_MAN_POSTPROCESSING');
INSERT INTO [dbo].[TBAPPSERV_CRON_DETAIL](
CRON_ID,	CON_ID,	TITLE	           ,DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
3,          2,		'VWIDB_DOCTYPE_HANDLING',           'VWIDB_DOCTYPE_HANDLING',			1,'SELECT * FROM VWIDB_DOCTYPE_HANDLING');
GO
--Insert Into TBAPPSERV_CRON_DETAIL (
--CRON_ID,	CON_ID,	TITLE,				DT_NAME,			RUN_ON_STARTUP,		COMMAND) VALUES (
--2,			2,		'TBIDB_DOC_INFO',	'TBIDB_DOC_INFO',	1,					
--'declare @praefix varchar(100)  select @praefix = CAT_STRING from tbidb_catalog where CAT_TITLE = ''FILESTORE_PRAEFIX''  select    IDB_OBJ_ID,OBJ_ST_ID,FILENAME_ONLY,FILENAME_EXT,EXTENSION,@praefix + ''\'' + RELATIVE_PATH as FULL_PATH   ,ADDED_WHO,ADDED_WHEN  from TBIDB_DOC_INFO');









