UPDATE TBDD_MODULES SET PRODUCT_VERSION = '2.4.6.2' where NAME = 'Record-Organizer' 
GO
ALTER TABLE TBPMO_CHART_ENTITY
ADD GROUP_ID VARCHAR(50) NOT NULL DEFAULT ''
GO
ALTER TABLE TBPMO_RIGHTS_WORK_SERVICE_ADD_RIGHT ADD
	[SERVICE] bit NOT NULL DEFAULT 0
GO
ALTER TRIGGER [dbo].[TBDD_USER_AFT_DEL] ON [dbo].[TBDD_USER]
FOR DELETE
AS
DECLARE @USER_ID INTEGER
BEGIN
	SELECT @USER_ID = GUID FROM DELETED
	IF @USER_ID IN (0,1)
		BEGIN
			ROLLBACK TRANSACTION
			RAISERROR('THIS USER CAN NOT BE DELETED!',16,10)
		END
	ELSE
		BEGIN
			INSERT INTO TBPMO_USER_RIGHTS_JOBS (USER_ID,COMMENT,ADDED_WHO) VALUES
			(@USER_ID,'USER DELETED','TBDD_GROUPS_USER_AFT_DEL')
			INSERT INTO TBPMO_LOG_ESSENTIALS (REFERENCE_KEY,REFERENCE_STRING,COMMENT,ADDED_WHO) VALUES 
				(@USER_ID,'USER-ID','USER DELETED','TBDD_GROUPS_USER_AFT_DEL')
		END
END
GO
ALTER TABLE TBPMO_KONFIGURATION ADD
SQL_FULLTEXT VARCHAR(5000) NOT NULL DEFAULT ''
GO
ALTER TABLE TBPMO_FORM ADD
LOAD_ENT_SEARCH_AT_SU BIT NOT NULL DEFAULT 0
GO
ALTER PROCEDURE [dbo].[PRPMO_DELETE_RESULTFILE](@pDOCID INT, @pRECORDID INT, @DELETE_FILE INT)
AS
BEGIN TRY
	DECLARE @COUNT INT
	SELECT @COUNT = COUNT(GUID) FROM TBPMO_DOC_RECORD_LINK WHERE DOC_ID = @pDOCID
	IF @COUNT = 1 OR (@DELETE_FILE = 1 AND @COUNT > 1)
		BEGIN
			DELETE FROM TBPMO_DOC_INDICES WHERE DocID = @pDOCID
			DELETE FROM TBPMO_DOC_RECORD_LINK WHERE Doc_ID = @pDOCID
			DELETE FROM TBPMO_DOCRESULT_LIST WHERE DocID = @pDOCID
		END
	ELSE IF @COUNT > 1 and @DELETE_FILE = 0
		BEGIN
			DELETE FROM TBPMO_DOC_RECORD_LINK WHERE Doc_ID = @pDOCID AND RECORD_ID = @pRECORDID
		END
	ELSE IF @DELETE_FILE = 1
		BEGIN
			DELETE FROM TBPMO_DOC_INDICES WHERE DocID = @pDOCID
			DELETE FROM TBPMO_DOC_RECORD_LINK WHERE Doc_ID = @pDOCID
			DELETE FROM TBPMO_DOCRESULT_LIST WHERE DocID = @pDOCID
		END
END TRY
BEGIN CATCH   
	PRINT 'ERROR IN PROCEDURE: ' + CONVERT(VARCHAR(30),ERROR_PROCEDURE()) + ' - ROW: ' + CONVERT(VARCHAR(10),ERROR_LINE())
	+ ' - ERROR-MESSAGE: ' 
    + CONVERT(VARCHAR(500),ERROR_MESSAGE())
END CATCH
GO
CREATE FUNCTION [dbo].[FNPMO_GET_CONTROL_VALUES_DOC_ENTITY] (@pCONTROL_ID INTEGER,@pDOC_ID INTEGER, @pENTITY_ID INTEGER)
RETURNS VARCHAR(1000)
AS 
BEGIN
	DECLARE	
		@RESULT		VARCHAR(MAX),
		@TEMP_VALUE	VARCHAR(MAX)

		
	DECLARE	c_RESULT CURSOR FOR SELECT VALUE FROM TBPMO_CONTROL_VALUE WHERE CONTROL_ID = @pCONTROL_ID AND RECORD_ID in (SELECT RECORD_ID FROM TBPMO_DOC_RECORD_LINK WHERE DOC_ID = @pDOC_ID
	 AND RECORD_ID IN (SELECT GUID FROM TBPMO_RECORD WHERE FORM_ID = @pENTITY_ID))


	BEGIN
		OPEN c_RESULT 
		FETCH NEXT FROM c_RESULT INTO @TEMP_VALUE
    
		WHILE @@FETCH_STATUS = 0
			BEGIN
				IF LEN(@RESULT) > 0
					SET @RESULT = @RESULT + ';' + @TEMP_VALUE
				ELSE
					SET @RESULT = @TEMP_VALUE
				FETCH NEXT FROM c_RESULT INTO @TEMP_VALUE
			END

		CLOSE c_RESULT
		DEALLOCATE c_RESULT

		RETURN(@RESULT)
	END
END

GO
CREATE TABLE [dbo].[TBPMO_CHART_ENTITY](
	[GUID]			INT IDENTITY(1,1) NOT NULL,
	[ENTITY_ID]		INT					NOT NULL,
	[SQL_COMMAND]	VARCHAR(max)		NOT NULL,
	[TYPE_CHART]	VARCHAR(30)			NOT NULL,
	[ARGUMENT]		VARCHAR(30)			NOT NULL,
	[VALUE]			VARCHAR(30)			NOT NULL,
	[TITLE]			VARCHAR(30)			NOT NULL DEFAULT (''),
	[ADDED_WHO]		VARCHAR(50)			NOT NULL DEFAULT ('DEFAULT'),
	[ADDED_WHEN]	DATETIME			DEFAULT (getdate()),
	[CHANGED_WHO]	VARCHAR(50),
	[CHANGED_WHEN]	DATETIME,
	[GROUP_ID]		VARCHAR(50)			NOT NULL DEFAULT (''),
CONSTRAINT 	   	[PK_TBPMO_CHART_ENTITY] 	PRIMARY KEY(GUID),
CONSTRAINT		FK_TBPMO_CHART_ENTITY_ENT_ID	FOREIGN KEY (ENTITY_ID) REFERENCES  TBPMO_FORM (GUID))
GO

CREATE TRIGGER [dbo].[TBPMO_CHART_ENTITY_AFT_UPD] ON [dbo].[TBPMO_CHART_ENTITY]
FOR UPDATE
AS
	UPDATE TBPMO_CHART_ENTITY SET CHANGED_WHEN = GETDATE() FROM INSERTED WHERE TBPMO_CHART_ENTITY.GUID = INSERTED.GUID







