 DELIMITER $$

/* ************************************************************************************************************************************************************************
	BI
************************************************************************************************************************************************************************ */	
DROP TRIGGER IF EXISTS `_user_accounts_bi`$$
CREATE DEFINER=`root`@`localhost` TRIGGER `_user_accounts_bi` BEFORE INSERT ON `_user_accounts` FOR EACH ROW 
A: BEGIN

	IF _TriggerDisabled() THEN LEAVE A; END IF;

	IF NEW.Datas <=> MD5('') THEN
		IF @session.LOGON.Accept_empty_pswd IS NULL THEN 
			CALL _Globals_Get('LOGON.Accept_empty_pswd', @session.LOGON.Accept_empty_pswd, 1);
		END IF;
		
		SET NEW.Datas = IF(@session.LOGON.Accept_empty_pswd, NEW.Datas, '');
	END IF;
END;
$$

/* ************************************************************************************************************************************************************************
	AI
************************************************************************************************************************************************************************ */	
DROP TRIGGER IF EXISTS `_user_accounts_ai`$$
CREATE DEFINER=`root`@`localhost` TRIGGER `_user_accounts_ai` AFTER INSERT ON `_user_accounts` FOR EACH ROW 
A: BEGIN
	IF _TriggerDisabled() THEN LEAVE A; END IF;
	/*
	IF IFNULL(@session.trigger._user_accounts, FALSE) THEN 
		LEAVE A; 
	END IF;
	SET @session.trigger._user_accounts = TRUE;
	*/

	IF IFNULL(@SYSTEM.Client.Session.GUID, '') <> '' THEN 
	--	Nowe oparte na sesji	
			SET 
				-- @.ua.Log.Opis = CONCAT_WS('', 'Zmiana uprawnień użytkownika: ', NEW.opis, '(', NEW.Miejsce, ') / ', NEW.core_id, ', upr.typ: ', NEW.upr_type),
				@.ua.Log.Opis = 
				CONCAT_WS('', 
					'Utworzenie konta ',
					(
					SELECT 
						CONCAT_WS('', 
							IF(o.Rodzaj = 0, _VarStr('grupie: "'), _VarStr('osobie: "')), 
							CONCAT_WS(' ', NULLIF(o.Imie1, ''), NULLIF(o.Nazwisko, '')), 
							IF(o.Rodzaj = 0, '"', NULL)
						) AS ContextName 
					FROM `osoby` o 
					WHERE 
						o.GUID = NEW.osobaGUID
					),
					'".',
					NULL
				),
				@.ua.Log.Miejsce.USER = 302 /* IntNetCenter - użytkownicy lub 100 */, 
				@.ua.Log.Czynnosc = 2 /* 2 INS 3 Edit */,
				@.ua.Log.GUIDLink.USER = NEW.osobaguid
			;
			-- SET @.ua.Log.IDN = NULL;
			
			CALL log_Ins('Trigger.logpo.Prepare.Clear', @.ua.Log.IDN, @.ua.Log.Miejsce.USER, @.ua.Log.Czynnosc, @.ua.Log.GUIDLink.USER, '_user_accounts', @.ua.Log.Opis, '', '', '', '', '', '');
			CALL log_Ins('Trigger.logpo.INSERT', @.ua.Log.IDN, '', '', '', '', '', 'Typ konta', '', NULL, NEW.user_type, '', '');
			CALL log_Ins('Trigger.logpo.INSERT', @.ua.Log.IDN, '', '', '', '', '', 'Administr.', '', NULL, NEW.Admin, '', '');
			CALL log_Ins('Trigger.logpo.INSERT', @.ua.Log.IDN, '', '', '', '', '', 'Hasło', '', NULL, NEW.Datas, '', '');
			CALL log_Ins('Trigger.logpo.INSERT', @.ua.Log.IDN, '', '', '', '', '', 'Login', '', NULL, NEW.Login, '', '');
			CALL log_Ins('Trigger.logpo.INSERT', @.ua.Log.IDN, '', '', '', '', '', 'Stan konta', '', NULL, NEW.Status, '', '');
			CALL log_Ins('Trigger.logpo.INSERT', @.ua.Log.IDN, '', '', '', '', '', 'Ważność od', '', NULL, NEW.date_from, '', '');
			CALL log_Ins('Trigger.logpo.INSERT', @.ua.Log.IDN, '', '', '', '', '', 'Ważność do', '', NULL, NEW.date_to, '', '');
		/*
			CALL log_Ins('INS.logpo.Diff', @.ua.Log.IDN, @.ua.Log.Miejsce.USER, @.ua.Log.Czynnosc, @.ua.Log.GUIDLink.USER, 'osoby', @.ua.Log.Opis, 'Typ konta', '', NULL, NEW.user_type, '', '');
			CALL log_Ins('INS.logpo.Diff', @.ua.Log.IDN, @.ua.Log.Miejsce.USER, @.ua.Log.Czynnosc, @.ua.Log.GUIDLink.USER, 'osoby', @.ua.Log.Opis, 'Administr.', '', NULL, NEW.Admin, '', '');
			CALL log_Ins('INS.logpo.Diff', @.ua.Log.IDN, @.ua.Log.Miejsce.USER, @.ua.Log.Czynnosc, @.ua.Log.GUIDLink.USER, 'osoby', @.ua.Log.Opis, 'Hasło', '', NULL, NEW.Datas, '', '');
			CALL log_Ins('INS.logpo.Diff', @.ua.Log.IDN, @.ua.Log.Miejsce.USER, @.ua.Log.Czynnosc, @.ua.Log.GUIDLink.USER, 'osoby', @.ua.Log.Opis, 'Login', '', NULL, NEW.Login, '', '');
			CALL log_Ins('INS.logpo.Diff', @.ua.Log.IDN, @.ua.Log.Miejsce.USER, @.ua.Log.Czynnosc, @.ua.Log.GUIDLink.USER, 'osoby', @.ua.Log.Opis, 'Stan konta', '', NULL, NEW.Status, '', '');
			CALL log_Ins('INS.logpo.Diff', @.ua.Log.IDN, @.ua.Log.Miejsce.USER, @.ua.Log.Czynnosc, @.ua.Log.GUIDLink.USER, 'osoby', @.ua.Log.Opis, 'Ważność od', '', NULL, NEW.date_from, '', '');
			CALL log_Ins('INS.logpo.Diff', @.ua.Log.IDN, @.ua.Log.Miejsce.USER, @.ua.Log.Czynnosc, @.ua.Log.GUIDLink.USER, 'osoby', @.ua.Log.Opis, 'Ważność do', '', NULL, NEW.date_to, '', '');
			CALL log_Ins('INS.logpo.Diff', @.ua.Log.IDN, @.ua.Log.Miejsce.USER, @.ua.Log.Czynnosc, @.ua.Log.GUIDLink.USER, 'osoby', @.ua.Log.Opis, 'GUID osoby', '', NULL, NEW.OsobaGUID, '', '');
		*/	
	
	END IF;
		
	
	
	/*
	SET @session.trigger._user_accounts = FALSE;
	*/
END;
$$

/* ************************************************************************************************************************************************************************
	BU
************************************************************************************************************************************************************************ */	
DROP TRIGGER IF EXISTS `_user_accounts_bu`$$
CREATE DEFINER=`root`@`localhost` TRIGGER `_user_accounts_bu` BEFORE UPDATE ON `_user_accounts` FOR EACH ROW 
A: BEGIN
	IF _TriggerDisabled() THEN LEAVE A; END IF;
	/*
	IF IFNULL(@session.trigger._user_accounts, FALSE) THEN 
		LEAVE A; 
	END IF;
	SET @session.trigger._user_accounts = TRUE;
	*/
	IF NEW.Datas <=> MD5('') THEN
		IF @session.LOGON.Accept_empty_pswd IS NULL THEN 
			CALL _Globals_Get('LOGON.Accept_empty_pswd', @session.LOGON.Accept_empty_pswd, 1);
		END IF;
		
		SET NEW.Datas = IF(@session.LOGON.Accept_empty_pswd, NEW.Datas, '');
	END IF;
	
	SET	@.NEW.datas.Changed = NOT (NEW.datas <=> OLD.datas);
	IF @.NEW.datas.Changed THEN
		SET NEW.Last_Change_Pswd = NOW();
		IF NEW.ExtFlags <=> OLD.ExtFlags THEN
		--	Zmień user type jeśli to aktywacja
            IF NEW.ExtFlags LIKE '%<%aktywacja%>%' THEN
                SET NEW.user_type = LEAST(1, ABS(NEW.user_type));
            END IF;
		--	Gdy zmieniamy hasło ale nie ruszamy ExtFlags to kasuj wymóg zmiany hasła
			SET
				NEW.ExtFlags =
				NULLIF(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(NEW.ExtFlags, 
					'<Sent.aktywacja.Auto.Pswd>', ''), 
					'<Sent.aktywacja.Auto.TmpPswd>', ''), 
					'<Sent.zapomnialem.Auto.Pswd>', ''), 
					'<Sent.zapomnialem.Auto.TmpPswd>', ''), 
					NEW.ExtFlags, ''),
				'')
				;
		END IF;
	END IF;
	
	/*
	UWAGA gdy NEW.err_logon_count = 0 to kasuj w NEW.ExtFlags zawart. '<err_logon_count.temp>'
	Jeśli chcemy pozostawić flagę a tylko wyzerować err_logon_count to dajemy -1 !!!!
	*/
	IF NEW.err_logon_count = 0 THEN
		SET NEW.ExtFlags = NULLIF(REPLACE(REPLACE(NEW.ExtFlags, '<err_logon_count.temp>', ''), '<err_logon_count>', ''), '');
	END IF;

	IF NEW.err_logon_count = -1 THEN
		SET NEW.err_logon_count = 0;
	END IF;
	
	/*
	SET @session.trigger._user_accounts = FALSE;
	*/
END;
$$

/* ************************************************************************************************************************************************************************
	AU
************************************************************************************************************************************************************************ */	
DROP TRIGGER IF EXISTS `_user_accounts_au`$$
CREATE DEFINER=`root`@`localhost` TRIGGER `_user_accounts_au` AFTER UPDATE ON `_user_accounts` FOR EACH ROW 
A: BEGIN
	IF _TriggerDisabled() THEN LEAVE A; END IF;
	IF IFNULL(@session.trigger._user_accounts, FALSE) THEN 
		LEAVE A; 
	END IF;
	SET @session.trigger._user_accounts = TRUE;
	
	SET	
		@.NEW.datas.Changed := NOT (NEW.datas <=> OLD.datas),
		@.NEW.admin.Changed := NOT (NEW.admin <=> OLD.admin),
		@.NEW.user_type.Changed := NOT (NEW.user_type <=> OLD.user_type),
		@.NEW.ExtFlags.Changed := NOT (NEW.ExtFlags <=> OLD.ExtFlags)
	;
--	Zmienilismy hasło zatem stare zapisz w archiwum o ile nie bylo puste
	IF @.NEW.datas.Changed AND OLD.datas <> 'd41d8cd98f00b204e9800998ecf8427e' THEN
		INSERT IGNORE INTO `_user_accounts_pswd_arch`
		SET
			osobaGUID = NEW.osobaGUID,
			typ = NEW.typ, 
			datas = OLD.datas, 
			LastUsed = NOW()
		;
	END IF;
	
--	Haslo traktujemy wyjatkowo - czyli zawsze przezucamy do _user_accounts
	IF 
    (@.NEW.datas.Changed 
    OR @.NEW.admin.Changed 
    OR @.NEW.user_type.Changed
    OR @.NEW.ExtFlags.Changed
    ) 
	AND NOT IFNULL(@session.trigger.osoby, FALSE) THEN
		UPDATE `osoby` o
		SET
		--	Uwaga!!! nie ruszamy kolumn w `_user_accounts` ktore w `osoby` nie ulegly zmianie
			o.datas = IF(@.NEW.datas.Changed, NEW.datas, o.datas),
			o.administrator = IF(@.NEW.admin.Changed, NEW.admin, o.administrator),
			o.user_type = IF(@.NEW.user_type.Changed OR @.NEW.ExtFlags.Changed, NEW.user_type, o.user_type)
		WHERE
			o.GUID = NEW.OsobaGUID
		
		;
	END IF;
	
	
	IF NOT(NEW.user_type <=> OLD.user_type) OR NOT(NEW.admin <=> OLD.admin) OR NOT(NEW.Datas <=> OLD.Datas) OR NOT(NEW.Login <=> OLD.Login) OR NOT(NEW.Status <=> OLD.Status)  
		OR NOT(NEW.date_from <=> OLD.date_from) OR NOT(NEW.date_to <=> OLD.date_to) 
	THEN
		IF IFNULL(@SYSTEM.Client.Session.GUID, '') <> '' THEN
	--	Nowe oparte na sesji	
			SET 
				-- @.ua.Log.Opis = CONCAT_WS('', 'Zmiana uprawnień użytkownika: ', NEW.opis, '(', NEW.Miejsce, ') / ', NEW.core_id, ', upr.typ: ', NEW.upr_type),
				@.ua.Log.Opis = 
				CONCAT_WS('', 
					'Zmiana ustawień konta ',
					(
					SELECT 
						CONCAT_WS('', 
							IF(o.Rodzaj = 0, _VarStr('grupy: "'), _VarStr('użytkownika: "')), 
							CONCAT_WS(' ', NULLIF(o.Imie1, ''), NULLIF(o.Nazwisko, '')), 
							IF(o.Rodzaj = 0, '"', NULL)
						) AS ContextName 
					FROM `osoby` o 
					WHERE 
						o.GUID = NEW.osobaGUID
					),
					'".',
					NULL
				),
				@.ua.Log.Miejsce.USER = 302 /* IntNetCenter - użytkownicy lub 100 */, 
				@.ua.Log.Czynnosc = 3 /* 2 INS 3 Edit */,
				@.ua.Log.GUIDLink.USER = NEW.osobaguid
			;
			
			
			CALL log_Ins('Trigger.logpo.Prepare.Clear', @.ua.Log.IDN, @.ua.Log.Miejsce.USER, @.ua.Log.Czynnosc, @.ua.Log.GUIDLink.USER, '_user_accounts', @.ua.Log.Opis, '', '', '', '', '', '');
			CALL log_Ins('Trigger.logpo.UPDATE', @.ua.Log.IDN, '', '', '', '', '', 'Typ konta', '', OLD.user_type, NEW.user_type, '', '');
			CALL log_Ins('Trigger.logpo.UPDATE', @.ua.Log.IDN, '', '', '', '', '', 'Administr.', '', OLD.Admin, NEW.Admin, '', '');
			CALL log_Ins('Trigger.logpo.UPDATE', @.ua.Log.IDN, '', '', '', '', '', 'Hasło', '', OLD.Datas, NEW.Datas, '', '');
			CALL log_Ins('Trigger.logpo.UPDATE', @.ua.Log.IDN, '', '', '', '', '', 'Login', '', OLD.Login, NEW.Login, '', '');
			CALL log_Ins('Trigger.logpo.UPDATE', @.ua.Log.IDN, '', '', '', '', '', 'Stan konta', '', OLD.Status, NEW.Status, '', '');
			CALL log_Ins('Trigger.logpo.UPDATE', @.ua.Log.IDN, '', '', '', '', '', 'Ważność od', '', OLD.date_from, NEW.date_from, '', '');
			CALL log_Ins('Trigger.logpo.UPDATE', @.ua.Log.IDN, '', '', '', '', '', 'Ważność do', '', OLD.date_to, NEW.date_to, '', '');
	
        /*  1 IV 2025
		ELSE
			SET @_IDN_Log = NULL;
			IF NOT(NEW.user_type <=> OLD.user_type) THEN
				CALL osoby_AddToLog('INSERT', @_IDN_Log, NEW.OsobaGUID, 3, 'user_type', OLD.user_type, NEW.user_type, 'zmiana ust. konta uzytkownika');	
			END IF;
			IF NOT(NEW.admin <=> OLD.admin) THEN
				CALL osoby_AddToLog('INSERT', @_IDN_Log, NEW.OsobaGUID, 3, 'admin', OLD.admin, NEW.admin, 'zmiana ust. konta uzytkownika');	
			END IF;
			IF NOT(NEW.Datas <=> OLD.Datas) THEN
				CALL osoby_AddToLog('INSERT', @_IDN_Log, NEW.OsobaGUID, 3, 'Datas', OLD.Datas, NEW.Datas, 'zmiana ust. konta uzytkownika');	
			END IF;
			IF NOT(NEW.Login <=> OLD.Login) THEN
				CALL osoby_AddToLog('INSERT', @_IDN_Log, NEW.OsobaGUID, 3, 'Login', OLD.Login, NEW.Login, 'zmiana ust. konta uzytkownika');	
			END IF;
			IF NOT(NEW.Status <=> OLD.Status) THEN
				CALL osoby_AddToLog('INSERT', @_IDN_Log, NEW.OsobaGUID, 3, 'Status', OLD.Status, NEW.Status, 'zmiana ust. konta uzytkownika');	
			END IF;
			IF NOT(NEW.date_from <=> OLD.date_from) THEN
				CALL osoby_AddToLog('INSERT', @_IDN_Log, NEW.OsobaGUID, 3, 'date_from', OLD.date_from, NEW.date_from, 'zmiana ust. konta uzytkownika');	
			END IF;
			IF NOT(NEW.date_to <=> OLD.date_to) THEN
				CALL osoby_AddToLog('INSERT', @_IDN_Log, NEW.OsobaGUID, 3, 'date_to', OLD.date_to, NEW.date_to, 'zmiana ust. konta uzytkownika');	
			END IF;
				
			IF NOT(NEW.Status <=> OLD.Status) AND IFNULL(@session.globals.Owner, '') != 'CRIST' AND NOT @session.trigger.osoby THEN
			--	Osoby
				UPDATE `osoby` o
				SET 
					o.user_inactive = NEW.status > 0 
				WHERE 
					o.guid = NEW.osobaguid
				;
			--	katcole		
				UPDATE `katcols` v, `v_katcol_names` vn 
				SET 
					v.nieaktywna = NEW.status > 0 
				WHERE 
					v.guidlink = NEW.osobaguid AND v.guidlink <> '' AND vn.colnr + 1 = v.colnr AND vn.typ = v.typ AND vn.katcol_link_table = 'osoby'
				;			
			END IF;		
        */    
		END IF;

	END IF;		
	
	SET @session.trigger._user_accounts = FALSE;
END;
$$

/* ************************************************************************************************************************************************************************
	BD
************************************************************************************************************************************************************************ */	


/* ************************************************************************************************************************************************************************
	AD
************************************************************************************************************************************************************************ */	
DROP TRIGGER IF EXISTS `_user_accounts_ad`$$
CREATE DEFINER = `root`@`localhost` TRIGGER `_user_accounts_ad` AFTER DELETE ON `_user_accounts` FOR EACH ROW 
A: BEGIN
	IF _TriggerDisabled() THEN LEAVE A; END IF;

	IF IFNULL(@SYSTEM.Client.Session.GUID, '') <> '' THEN 
set @X = '1.1.BEG.1';		
			SET 
				-- @.ua.Log.Opis = CONCAT_WS('', 'Zmiana uprawnień użytkownika: ', NEW.opis, '(', NEW.Miejsce, ') / ', NEW.core_id, ', upr.typ: ', NEW.upr_type),
				@.ua.Log.Opis = 
				CONCAT_WS('', 
					'Usunięcie konta ',
					(
					SELECT 
						CONCAT_WS('', IF(o.Rodzaj = 0, _VarStr('grupy: "'), _VarStr('osoby: "')), CONCAT_WS(' ', NULLIF(o.Imie1, ''), NULLIF(o.Nazwisko, '')), IF(o.Rodzaj = 0, '"', NULL)) AS ContextName 
					FROM `osoby` o WHERE o.GUID = OLD.osobaGUID
					),
					'".',
					NULL
				),
				@.ua.Log.Miejsce.USER = 302 /* IntNetCenter - użytkownicy lub 100 */, 
				@.ua.Log.Czynnosc = 4 /* 2 INS 3 Edit 4 Delete */,
				@.ua.Log.GUIDLink.USER = OLD.osobaguid
			;
			SET @.ua.Log.IDN = NULL;
			CALL log_Ins('Trigger.logpo.Prepare.Clear', @.ua.Log.IDN, @.ua.Log.Miejsce.USER, @.ua.Log.Czynnosc, @.ua.Log.GUIDLink.USER, '_user_accounts', @.ua.Log.Opis, '', '', '', '', '', '');
			CALL log_Ins('Trigger.logpo.DELETE', @.ua.Log.IDN, '', '', '', '', '', 'Typ konta', '', OLD.user_type, NULL, '', '');
			CALL log_Ins('Trigger.logpo.DELETE', @.ua.Log.IDN, '', '', '', '', '', 'Administr.', '', OLD.Admin, NULL, '', '');
			CALL log_Ins('Trigger.logpo.DELETE', @.ua.Log.IDN, '', '', '', '', '', 'Hasło', '', OLD.Datas, NULL, '', '');
			CALL log_Ins('Trigger.logpo.DELETE', @.ua.Log.IDN, '', '', '', '', '', 'Login', '', OLD.Login, NULL, '', '');
			CALL log_Ins('Trigger.logpo.DELETE', @.ua.Log.IDN, '', '', '', '', '', 'Stan konta', '', OLD.Status, NULL, '', '');
			CALL log_Ins('Trigger.logpo.DELETE', @.ua.Log.IDN, '', '', '', '', '', 'Ważność od', '', OLD.date_from, NULL, '', '');
			CALL log_Ins('Trigger.logpo.DELETE', @.ua.Log.IDN, '', '', '', '', '', 'Ważność do', '', OLD.date_to, NULL, '', '');
			/*
			CALL log_Ins('INS.logpo.Diff', @.ua.Log.IDN, @.ua.Log.Miejsce.USER, @.ua.Log.Czynnosc, @.ua.Log.GUIDLink.USER, 'osoby', @.ua.Log.Opis, 'GUID osoby', '', OLD.OsobaGUID, NULL, '', '');
			CALL log_Ins('INS.logpo.Diff', @.ua.Log.IDN, @.ua.Log.Miejsce.USER, @.ua.Log.Czynnosc, @.ua.Log.GUIDLink.USER, 'osoby', @.ua.Log.Opis, 'Typ konta', '', OLD.user_type, NULL, '', '');
			CALL log_Ins('INS.logpo.Diff', @.ua.Log.IDN, @.ua.Log.Miejsce.USER, @.ua.Log.Czynnosc, @.ua.Log.GUIDLink.USER, 'osoby', @.ua.Log.Opis, 'Administr.', '', OLD.Admin, NULL, '', '');
			CALL log_Ins('INS.logpo.Diff', @.ua.Log.IDN, @.ua.Log.Miejsce.USER, @.ua.Log.Czynnosc, @.ua.Log.GUIDLink.USER, 'osoby', @.ua.Log.Opis, 'Hasło', '', OLD.Datas, NULL, '', '');
			CALL log_Ins('INS.logpo.Diff', @.ua.Log.IDN, @.ua.Log.Miejsce.USER, @.ua.Log.Czynnosc, @.ua.Log.GUIDLink.USER, 'osoby', @.ua.Log.Opis, 'Login', '', OLD.Login, NULL, '', '');
			CALL log_Ins('INS.logpo.Diff', @.ua.Log.IDN, @.ua.Log.Miejsce.USER, @.ua.Log.Czynnosc, @.ua.Log.GUIDLink.USER, 'osoby', @.ua.Log.Opis, 'Stan konta', '', OLD.Status, NULL, '', '');
			CALL log_Ins('INS.logpo.Diff', @.ua.Log.IDN, @.ua.Log.Miejsce.USER, @.ua.Log.Czynnosc, @.ua.Log.GUIDLink.USER, 'osoby', @.ua.Log.Opis, 'Ważność od', '', OLD.date_from, NULL, '', '');
			CALL log_Ins('INS.logpo.Diff', @.ua.Log.IDN, @.ua.Log.Miejsce.USER, @.ua.Log.Czynnosc, @.ua.Log.GUIDLink.USER, 'osoby', @.ua.Log.Opis, 'Ważność do', '', OLD.date_to, NULL, '', '');
			*/
	END IF;
set @X = '1.1.BEG.9';		
	IF @session.globals.Owner != 'CRIST' AND NOT @session.trigger.osoby THEN
	--	Osoby
set @X = '1.1.BEG.11';		
		UPDATE `osoby` o
		SET 
			o.user_inactive = TRUE
		WHERE 
			o.guid = OLD.osobaguid
		;
set @X = '1.1.BEG.12';		
	--	katcole
	/* było - ale był błąd 
		UPDATE `katcols` v, `v_katcol_names` vn 
		SET 
			v.nieaktywna = TRUE
		WHERE 
			v.guidlink = OLD.osobaguid 
			AND v.guidlink <> '' 
			AND vn.colnr + 1 = v.colnr 
			AND vn.typ = v.typ 
			AND vn.katcol_link_table = 'osoby'
		;
	jest ... */
		UPDATE `katcols` v, `slowniki_pierwotne_def` vn 
		SET 
			v.nieaktywna = TRUE
		WHERE 
			v.guidlink = OLD.osobaguid 
			AND v.guidlink <> '' 
			AND vn.guid LIKE 'Cat%'
			AND vn.colnr + 1 = v.colnr 
			AND vn.typ = v.typ 
			AND vn.katcol_link_table = 'osoby'
		;
set @X = '1.1.BEG.13';		
	END IF;
END;
$$


DELIMITER ;

/*
$Log$
*/

/*
====================================================================================================================================================================================
	NOTATNIK
====================================================================================================================================================================================

*/

