 set names utf8;

DELIMITER $$
DROP FUNCTION IF EXISTS `_varSTR`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_varSTR`(_Value VARCHAR(65532)) RETURNS VARCHAR(256)
    NO SQL
    DETERMINISTIC
BEGIN
	RETURN LEFT(_Value, 255);
END $$

DROP FUNCTION IF EXISTS `_varSTR_NOTNULL`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_varSTR_NOTNULL`(_Value VARCHAR(65532)) RETURNS VARCHAR(256)
    NO SQL
    DETERMINISTIC
BEGIN
	RETURN LEFT(IFNULL(_Value, ''),255); 
END $$

DROP FUNCTION IF EXISTS `_varTEXT`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_varTEXT`(_Value TEXT) RETURNS TEXT
    NO SQL
    DETERMINISTIC
BEGIN
	RETURN _Value;
END $$

DROP FUNCTION IF EXISTS `_varTEXT_NOTNULL`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_varTEXT_NOTNULL`(_Value TEXT) RETURNS TEXT
    NO SQL
    DETERMINISTIC
BEGIN
	RETURN IFNULL(_Value, '');
END $$

DROP FUNCTION IF EXISTS `_varMEDIUMTEXT`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_varMEDIUMTEXT`(_Value VARCHAR(65532)) RETURNS VARCHAR(65532)
    NO SQL
    DETERMINISTIC
BEGIN
	RETURN _Value;
END $$

/* ************************************************************************************************************************************************************************
	StrUtils
************************************************************************************************************************************************************************ */	
DROP FUNCTION IF EXISTS `_BezPolskich`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_BezPolskich`(_Value TEXT) RETURNS TEXT
    NO SQL
    DETERMINISTIC
BEGIN
	RETURN REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( _Value, 'Ń', 'N' ), 'Ć', 'C' ), 'Ź', 'Z' ), 'Ż', 'Z' ), 'Ł', 'L' ), 'Ś', 'S' ), 'Ą', 'A' ), 'Ó', 'O' ), 'Ę', 'E' ), 'ń', 'n' ), 'ć', 'c' ), 'ź', 'z' ), 'ż', 'z' ), 'ł', 'l' ), 'ś', 's' ), 'ą', 'a' ), 'ó', 'o' ), 'ę', 'e' ) 
;
END $$

DROP FUNCTION IF EXISTS `_Html_2_Windows`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_Html_2_Windows`(_Value MEDIUMTEXT) RETURNS MEDIUMTEXT
    NO SQL
    DETERMINISTIC
BEGIN
	RETURN 
		REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(_Value,
			-- '''', ''), 
			-- '"', ''), 
			'<b>', ''), 
			'</b>', ''), 
			'<br>', '\n'), 
			'\n', '\n'), 
			'<ul>', ''), 
			'</ul>', ''), 
			'<li>', '* ') 
	;
END $$

DROP FUNCTION IF EXISTS `_Windows_2_Html`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_Windows_2_Html`(_Value MEDIUMTEXT) RETURNS MEDIUMTEXT
    NO SQL
    DETERMINISTIC
BEGIN
	RETURN 
		REPLACE(_Value,
			'\n', '<br>') 
	;
END $$


DROP FUNCTION IF EXISTS `_Low_U_UpF`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_Low_U_UpF`(_Value VARCHAR(250), _Param INTEGER) RETURNS TEXT
    NO SQL
    DETERMINISTIC
BEGIN
	RETURN 
		IF(_Param = 0, 
			_Value,
			IF(_Param < 0, 
				LOWER(_Value),
				IF(_Param = 1, 
					UPPER(_Value),
					_UpperFirst(_Value)
				)
			)	
		);	
END $$


DROP FUNCTION IF EXISTS `_UpperFirst`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_UpperFirst`(_Value TEXT) RETURNS TEXT
    NO SQL
    DETERMINISTIC
BEGIN
	RETURN CONCAT(UCASE(SUBSTRING(_Value,1,1)),LCASE(SUBSTRING(_Value,2)));
END $$

DROP FUNCTION IF EXISTS `_CutSTR`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_CutSTR`(
	_Value VARCHAR(65532),
	_Len INTEGER,
	_PostFix VARCHAR(256)
	) 
RETURNS VARCHAR(256)
    NO SQL
    DETERMINISTIC
BEGIN
	IF LENGTH(_Value) > _Len THEN
		RETURN CONCAT(LEFT(_Value, _Len - 1), _PostFix);
	ELSE	
		RETURN _Value;
	END IF;	
END $$

DROP FUNCTION IF EXISTS `_QUOTE`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_QUOTE`(
	_Value VARCHAR(65532),
	_QSeparator VARCHAR(20)
) RETURNS VARCHAR(256)
    NO SQL
    DETERMINISTIC
BEGIN
	RETURN CONCAT(_QSeparator, NULLIF(_Value, ''), _QSeparator);
END $$

DROP FUNCTION IF EXISTS `_QUOTE_NotNULL`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_QUOTE_NotNULL`(
	_Value VARCHAR(65532),
	_QSeparator VARCHAR(20)
) RETURNS VARCHAR(256)
    NO SQL
    DETERMINISTIC
BEGIN
	RETURN CONCAT(_QSeparator, IFNULL(_Value, ''), _QSeparator);
END $$

DROP FUNCTION IF EXISTS `_Brackets`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_Brackets`(
	_Bra_1 VARCHAR(20),
	_Value VARCHAR(65532),
	_Bra_2 VARCHAR(20)
) RETURNS VARCHAR(1024)
    NO SQL
    DETERMINISTIC
BEGIN
	RETURN CONCAT(_Bra_1, NULLIF(_Value, ''), _Bra_2);
END $$

DROP FUNCTION IF EXISTS `_Brackets_NotNULL`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_Brackets_NotNULL`(
	_Bra_1 VARCHAR(20),
	_Value VARCHAR(65532),
	_Bra_2 VARCHAR(20)
) RETURNS VARCHAR(256)
    NO SQL
    DETERMINISTIC
BEGIN
	RETURN CONCAT(_Bra_1, IFNULL(_Value, ''), _Bra_2);
END $$

DROP FUNCTION IF EXISTS `_ConcatPre`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_ConcatPre`(
	_Pre VARCHAR(20),
	_Value VARCHAR(65532)
) RETURNS VARCHAR(256)
    NO SQL
    DETERMINISTIC
BEGIN
	RETURN CONCAT(_Pre, NULLIF(_Value, ''));
END $$

DROP FUNCTION IF EXISTS `_Concat_OLD_NEW`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_Concat_OLD_NEW`(
	_Pre VARCHAR(20),
	_OLD_Value VARCHAR(65532),
	_Separator VARCHAR(20),
	_NEW_Value VARCHAR(65532)
) RETURNS VARCHAR(256)
    NO SQL
    DETERMINISTIC
BEGIN
	-- RETURN _ConcatPre(_Pre, IF(NOT(_OLD_Value <=> _NEW_Value), CONCAT_WS(IFNULL(NULLIF(_Separator, ''), ' -> '), _VarStr(IFNULL(QUOTE(_OLD_Value), '(NULL)')), _VarStr(IFNULL(QUOTE(_NEW_Value), '(NULL)'))), NULL));
	RETURN _ConcatPre(_Pre, 
		IF(NOT(_OLD_Value <=> _NEW_Value), 
			CONCAT_WS(
				IFNULL(NULLIF(_Separator, ''), ' -> '), 
				_OLD_Value, 
				-- IF(_OLD_Value IS NULL, NULL, QUOTE(NULLIF(_OLD_Value, '(NULL)'))), 
				_NEW_Value
				-- IF(_NEW_Value IS NULL, NULL, QUOTE(NULLIF(_NEW_Value, '(NULL)')))
			), 
			NULL
		)
	);
END $$

DROP FUNCTION IF EXISTS `_Concat_OLD_NEW_Memo_LOG`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_Concat_OLD_NEW_Memo_LOG`(
	_MODE VARCHAR(20),	-- "INSERT"|"UPDATE"|"DELETE"
	_What VARCHAR(20),
	_OLD_Value VARCHAR(65532),
	_NEW_Value VARCHAR(65532),
	_Separator VARCHAR(20)
	-- _Quote BOOLEAN
) RETURNS VARCHAR(256)
    NO SQL
    DETERMINISTIC
BEGIN
	RETURN 
		IF(_MODE LIKE 'UPD%' AND _OLD_Value <=> _NEW_Value, 	
			NULL,
			CONCAT(
				IFNULL(CONCAT(_What, ': '), ''),	-- Co: ..
				NULLIF(
					CONCAT_WS('',
						IF(_MODE LIKE 'DEL%' OR _MODE LIKE 'UPD%',
							IF(_MODE LIKE 'DEL%' AND _OLD_Value IS NULL, 
								NULL,
								QUOTE(_OLD_Value)
							), 
							NULL	-- dla Inserrta
						),
						' -> ',
						IF(_MODE LIKE 'INS%' OR _MODE LIKE 'UPD%',
							IF(_MODE LIKE 'INS%' AND _NEW_Value IS NULL, 
								NULL,
								QUOTE(_NEW_Value)
							), 
							NULL	-- dla Delete
						),
						NULL
					),
					' -> '
				)
			)
		)
	;
END $$

DROP FUNCTION IF EXISTS `_ConcatSTR`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_ConcatSTR`(
	_Value1 VARCHAR(65532),
	_Value2 VARCHAR(65532),
	_Separator VARCHAR(256)
) RETURNS VARCHAR(256)
    NO SQL
    DETERMINISTIC
BEGIN
	DECLARE _OUTStr VARCHAR(256);
	SET _Value1 = IFNULL(_Value1, '');
	SET _Value2 = IFNULL(_Value2, '');
	IF (_Value1 != '') AND (_Value2 != '') THEN
		SET _OUTStr = CONCAT(_Value1, _Separator, _Value2);
	ELSE 
		SET _OUTStr = IF(_Value1 != '', _Value1, IF(_Value2 != '', _Value2, ''));
	END IF;
	RETURN _OUTStr;
END $$
 
DROP FUNCTION IF EXISTS `_ConcatSTR2`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_ConcatSTR2`(
	_Value1 VARCHAR(65532),
	_Value2 VARCHAR(65532),
	_Separator VARCHAR(256)
) RETURNS VARCHAR(65532)
    NO SQL
    DETERMINISTIC
/*
jmam X 2016 - lepsza i ciut szybsza
*/	
BEGIN
	/*
	DECLARE _OUTStr VARCHAR(65532);
	IF NULLIF(_Value1, '') IS NULL OR NULLIF(_Value2, '') IS NULL THEN
		SET _OUTStr = CONCAT(IFNULL(_Value1, ''), IFNULL(_Value2, ''));
	ELSE
		SET _OUTStr = CONCAT(_Value1, _Separator, _Value2);
	END IF;
	RETURN _OUTStr;
	*/
	RETURN 
		IF(NULLIF(_Value1, '') IS NULL OR NULLIF(_Value2, '') IS NULL,
			CONCAT(IFNULL(_Value1, ''), IFNULL(_Value2, '')),
			CONCAT(_Value1, _Separator, _Value2)
		)
	;
END $$
 
DROP FUNCTION IF EXISTS `_ConcatTxt`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_ConcatTxt`(
	_Value1 TEXT,
	_Value2 TEXT,
	_Separator VARCHAR(256)
) RETURNS TEXT
    NO SQL
    DETERMINISTIC
BEGIN
	DECLARE _OUTStr TEXT;
	SET _Value1 = IFNULL(_Value1, '');
	SET _Value2 = IFNULL(_Value2, '');
	IF (_Value1 != '') AND (_Value2 != '') THEN
		SET _OUTStr = CONCAT(_Value1, _Separator, _Value2);
	ELSE 
		SET _OUTStr = IF(_Value1 != '', _Value1, IF(_Value2 != '', _Value2, ''));
	END IF;
	RETURN _OUTStr;
END $$
 
DROP FUNCTION IF EXISTS `_ConcatSepSTR`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_ConcatSepSTR`(
	_Value1 VARCHAR(65532),
	_Separator VARCHAR(256)
) RETURNS VARCHAR(256)
    NO SQL
    DETERMINISTIC
BEGIN
	SET _Value1 = IFNULL(_Value1, '');
	IF (_Value1 != '') THEN
		RETURN CONCAT(_Value1, _Separator);
	ELSE
		RETURN _Value1;
	END IF;
END $$
 
DROP FUNCTION IF EXISTS `_ConcatSTR_NotEqu`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_ConcatSTR_NotEqu`(
	_Value1 VARCHAR(65532),
	_Value2 VARCHAR(65532),
	_Separator VARCHAR(256)
) RETURNS VARCHAR(256)
    NO SQL
    DETERMINISTIC
BEGIN
	DECLARE _OUTStr VARCHAR(256);
	SET _Value1 = IFNULL(_Value1, '');
	SET _Value2 = IFNULL(_Value2, '');
	IF _Value1 = _Value2 THEN
		SET _Value2 = '';
	END IF;
	SET _OUTStr = _ConcatSTR(_Value1, _Value2, _Separator);
	RETURN _OUTStr;
END $$

DROP FUNCTION IF EXISTS `_varSTR_Flush_Spaces`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_varSTR_Flush_Spaces`(
	_Value VARCHAR(65532)
) RETURNS VARCHAR(256)
    NO SQL
    DETERMINISTIC
BEGIN
	RETURN REPLACE(_Value, ' ', '');
END $$

DROP FUNCTION IF EXISTS `_varSTR_UpperFirst`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_varSTR_UpperFirst`(
	_Value VARCHAR(65532)
) RETURNS VARCHAR(255)
    NO SQL
    DETERMINISTIC
BEGIN
	RETURN CONCAT(UPPER(LEFT(_Value, 1)), LOWER(SUBSTRING(_Value, 2)));
END $$

DROP FUNCTION IF EXISTS `_varSTR_UpperFirstAll`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_varSTR_UpperFirstAll`(
	_Value VARCHAR(65532)
) RETURNS VARCHAR(255)
    NO SQL
    DETERMINISTIC
BEGIN
	DECLARE _Len INT;
	DECLARE i INT;
 
	SET _Len   = CHAR_LENGTH(_Value);
	SET _Value = LOWER(_Value);
	SET i = 0;
 
	WHILE (i < _Len) DO
		IF (MID(_Value, i, 1) in(' ','-','.') OR i = 0) THEN
			IF (i < _Len) THEN
				SET _Value = CONCAT(
					LEFT(_Value,i),
					UPPER(MID(_Value,i + 1,1)),
					RIGHT(_Value,_Len - i - 1)
				);
			END IF;
		END IF;
		SET i = i + 1;
	END WHILE;
 
	RETURN _Value;
END $$
DELIMITER ;

DELIMITER $$ 
DROP FUNCTION IF EXISTS `_varSTR_1_N_Fleks_Liczebn`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_varSTR_1_N_Fleks_Liczebn`(
	_Value INTEGER, 
	Str_1 VARCHAR(50), 
	Str_2 VARCHAR(50),
	Str_3 VARCHAR(50)
) RETURNS VARCHAR(256)
    NO SQL
    DETERMINISTIC
BEGIN
/*
    1       - minuta
    2..4    - minuty
    5..21   - minut
    x(2..4) - minuty
    x(5..9, 0) - minut
*/
    SET @.Lf.Value := _Value;
    IF @.Lf.Value = 0 THEN  
        SET @.Lf := 3;
    ELSEIF @.Lf.Value = 1 THEN  
        SET @.Lf := 1;
    ELSE
        SET @.Lf.Value := @.Lf.Value MOD 100;
        IF @.Lf.Value BETWEEN 5 AND 21 THEN
            SET @.Lf := 3;
        ELSE
            SET @.Lf.Value := @.Lf.Value MOD 10;
            IF @.Lf.Value BETWEEN 2 AND 4 THEN
                SET @.Lf := 2;
            ELSE
                SET @.Lf := 3;
            END IF;
        END IF;
    END IF;
    SET @.Lf.Return := 
        CONCAT_WS(' ' ,
            _Value, 
            IF(@.Lf = 1, Str_1, IF(@.Lf = 2, Str_2, Str_3))
        );
	RETURN @.Lf.Return;
END $$
DELIMITER ;

DELIMITER $$ 
DROP FUNCTION IF EXISTS `_varSTR_1_N_Liczebnikowo`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_varSTR_1_N_Liczebnikowo`(
	_Value VARCHAR(256), 
	Str_1 VARCHAR(256), 
	Str_N VARCHAR(256)
) RETURNS VARCHAR(256)
    NO SQL
    DETERMINISTIC
BEGIN
	RETURN CONCAT(_Value, ' ', IF(_Value = 1, Str_1, Str_N));
END $$

DELIMITER ;

DELIMITER $$
/* ************************************************************************************************************************************************************************
	MASK
************************************************************************************************************************************************************************ */	
DROP FUNCTION IF EXISTS `_MaskTool`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_MaskTool`(
	_MODE VARCHAR(255),
	_InputStr VARCHAR(255),
	_Mask_Prefix VARCHAR(5),
	_Mask_Char VARCHAR(5),
	_Value VARCHAR(50),
	_Mask_Prefix_Value VARCHAR(5),
	_MaxChars INTEGER
) 
RETURNS VARCHAR(256)
    NO SQL
    DETERMINISTIC
SPROC: BEGIN
/*
	_MODE 
	_InputStr 			Wejsciowy string np '%NNNN/%YYYY-%A'
	_Mask_Prefix 		domyslnie '%'
	_Mask_Char 			np 'N' lub 'M' etc.
	_Value 				co bedziemy wstawiac w maske np. 
							dla _Value = 2345 za %NNNNNNN mamy 002345
							dla _Value = 2010 za %YY mamy 10
	_Mask_Prefix_Value	Poprzedzajaca wartosc (domyslnie 0 wstawiamy przed numer gdy za krotki 
						przykladowo dla _Value = 2345 za %NNNNNNN mamy 002345
	_MaxChars INTEGER	domyslnie 6 znakowe wartosci

*/

	SET @OutStr = IFNULL(_InputStr, '');
	IF @OutStr = '' THEN
		RETURN @OutStr;
		LEAVE SPROC;
	END IF;
	SET _Mask_Prefix_Value = IFNULL(_Mask_Prefix_Value, '');
	IF _Mask_Prefix_Value = ' ' THEN
		SET _Mask_Prefix_Value = '. .';
	END IF;	
	IF _Mask_Prefix_Value = '' THEN
		SET _Mask_Prefix_Value = '0';
	END IF;	
	SET _Mask_Prefix_Value = REPLACE(_Mask_Prefix_Value, '. .', ' ');
	SET @I = 6;
	WHILE @I >= 1 DO
		-- SET @SubMask = RPAD(_Mask_Prefix, @I + 1, _Mask_Char);
		SET @SubMask = CONCAT(_Mask_Prefix, REPEAT(_Mask_Char, @I));
		IF LOCATE(@SubMask, @OutStr) > 0 THEN
			IF _Mask_Prefix_Value = 'CHAR' THEN
				SET @_Value = _Value;
			ELSE	
				SET @LENGTH._Value = GREATEST(LENGTH(_Value), @I);
				SET @_Value = LPAD(RIGHT(_Value, @LENGTH._Value), @LENGTH._Value, _Mask_Prefix_Value);
			END IF;	
			SET @OutStr = REPLACE(@OutStr, @SubMask, @_Value);
			-- SET @I := 1;
		END IF;
		SET @I := @I - 1;
	END WHILE;
	
	RETURN @OutStr;
END $$
DELIMITER ;

DELIMITER $$ 
DROP FUNCTION IF EXISTS `_ConcatSQLFields`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_ConcatSQLFields`(
	_InputSQL TEXT,
	_NextPart TEXT,
	_Separator VARCHAR(256)
) RETURNS TEXT
    NO SQL
    DETERMINISTIC
BEGIN
	DECLARE _SQLText TEXT DEFAULT '';
	
	IF _Separator = '' THEN
		SET _Separator = ',\n';
	END IF;
	IF _InputSQL != '' THEN
		SET _SQLText = CONCAT(
			_InputSQL, _Separator, _NextPart
		)
		;
	ELSE	
		SET _SQLText = _NextPart;
	END IF;
	RETURN _SQLText;
END $$
DELIMITER ;

DELIMITER $$ 
/* ************************************************************************************************************************************************************************
	Polskie znaki/ Tłumaczenia
************************************************************************************************************************************************************************ */	
DROP FUNCTION IF EXISTS `_bez_pl_znakow`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_bez_pl_znakow`(
	t TEXT
) RETURNS TEXT
    NO SQL
    DETERMINISTIC
BEGIN
    SET t = REPLACE(t, 'ą', 'a');
    SET t = REPLACE(t, 'Ą', 'A');
    SET t = REPLACE(t, 'ć', 'c');
    SET t = REPLACE(t, 'Ć', 'C');
    SET t = REPLACE(t, 'ę', 'e');
    SET t = REPLACE(t, 'Ę', 'E');
    SET t = REPLACE(t, 'ł', 'l');
    SET t = REPLACE(t, 'Ł', 'L');
    SET t = REPLACE(t, 'ń', 'n');
    SET t = REPLACE(t, 'Ń', 'N');
    SET t = REPLACE(t, 'ó', 'o');
    SET t = REPLACE(t, 'Ó', 'O');
    SET t = REPLACE(t, 'ś', 's');
    SET t = REPLACE(t, 'Ś', 'S');
    SET t = REPLACE(t, 'ż', 'z');
    SET t = REPLACE(t, 'Ż', 'Z');
    SET t = REPLACE(t, 'ź', 'z');
    SET t = REPLACE(t, 'Ź', 'Z');
    RETURN t;
END $$

DROP FUNCTION IF EXISTS `_to_utf_rtf`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_to_utf_rtf`(
	t TEXT
) RETURNS TEXT
    NO SQL
    DETERMINISTIC
BEGIN
    SET t = REPLACE(t, 'Ą', "\\u260\\'3f");
    SET t = REPLACE(t, 'ą', "\\u261\\'3f");
    SET t = REPLACE(t, 'Ć', "\\u262\\'3f");
    SET t = REPLACE(t, 'ć', "\\u263\\'3f");
    SET t = REPLACE(t, 'Ę', "\\u280\\'3f");
    SET t = REPLACE(t, 'ę', "\\u281\\'3f");
    SET t = REPLACE(t, 'Ł', "\\u321\\'3f");
    SET t = REPLACE(t, 'ł', "\\u322\\'3f");
    SET t = REPLACE(t, 'Ń', "\\u323\\'3f");
    SET t = REPLACE(t, 'ń', "\\u324\\'3f");
    SET t = REPLACE(t, 'Ó', "\\u211\\'3f");
    SET t = REPLACE(t, 'ó', "\\u243\\'3f");
    SET t = REPLACE(t, 'Ś', "\\u346\\'3f");
    SET t = REPLACE(t, 'ś', "\\u347\\'3f");
    SET t = REPLACE(t, 'Ż', "\\u379\\'3f");
    SET t = REPLACE(t, 'ż', "\\u380\\'3f");
    SET t = REPLACE(t, 'Ź', "\\u377\\'3f");
    SET t = REPLACE(t, 'ź', "\\u378\\'3f");
    RETURN t;
END $$

DROP FUNCTION IF EXISTS `_to_utf_xml`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_to_utf_xml`(
	t TEXT
) RETURNS TEXT
    NO SQL
    DETERMINISTIC
BEGIN
    SET t = REPLACE(t, 'Ą', "&#260;");
    SET t = REPLACE(t, 'ą', "&#261;");
    SET t = REPLACE(t, 'Ć', "&#262;");
    SET t = REPLACE(t, 'ć', "&#263;");
    SET t = REPLACE(t, 'Ę', "&#280;");
    SET t = REPLACE(t, 'ę', "&#281;");
    SET t = REPLACE(t, 'Ł', "&#321;");
    SET t = REPLACE(t, 'ł', "&#322;");
    SET t = REPLACE(t, 'Ń', "&#323;");
    SET t = REPLACE(t, 'ń', "&#324;");
    SET t = REPLACE(t, 'Ó', "&#211;");
    SET t = REPLACE(t, 'ó', "&#243;");
    SET t = REPLACE(t, 'Ś', "&#346;");
    SET t = REPLACE(t, 'ś', "&#347;");
    SET t = REPLACE(t, 'Ż', "&#379;");
    SET t = REPLACE(t, 'ż', "&#380;");
    SET t = REPLACE(t, 'Ź', "&#377;");
    SET t = REPLACE(t, 'ź', "&#378;");
    SET t = REPLACE(t, 'Ü', "&#220;");
    SET t = REPLACE(t, 'ü', "&#252;");
    SET t = REPLACE(t, 'Ö', "&#246;");
    SET t = REPLACE(t, 'ö', "&#214;");
    SET t = REPLACE(t, 'ä', "&#228;");
    SET t = REPLACE(t, 'Ä', "&#196;");
    SET t = REPLACE(t, 'ß', "&#223;");
		SET t = REPLACE(t, '”', " ");
    SET t = REPLACE(t, '„', " ");
		SET t = REPLACE(t, '–', "-");
    SET t = REPLACE(t, '“', " ");
		SET t = REPLACE(t, 'á', "a");
    SET t = REPLACE(t, 'č', "c");
    SET t = REPLACE(t, 'Š', "S");
    SET t = REPLACE(t, 'Č', "C");
    SET t = REPLACE(t, 'ř', "r");
    SET t = REPLACE(t, 'í', "i");
    SET t = REPLACE(t, 'Í', "I");
		SET t = REPLACE(t, 'ľ', "l");
    SET t = REPLACE(t, 'ž', "I");
		SET t = REPLACE(t, 'Ç', "C");
		SET t = REPLACE(t, 'Ş', "S");
		SET t = REPLACE(t, 'é', "&#233;");
		SET t = REPLACE(t, 'ë', "e");
		SET t = REPLACE(t, 'š', "s");
		SET t = REPLACE(t, 'É', "E");
		SET t = REPLACE(t, 'ş', "s");

		-- SET t = REPLACE(t, '&', "&#38;");
		-- SET t = REPLACE(t, '&#38;', "#####;");
		-- SET t = REPLACE(t, '&', "and");
    -- SET t = REPLACE(t, '#####', "&#38;");
    RETURN t;
END $$


DROP FUNCTION IF EXISTS `ht_Translate_Word`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `ht_Translate_Word`(
	_Slowo VARCHAR(38),
	_Lang_id VARCHAR(50)
) RETURNS VARCHAR(250)
    READS SQL DATA
    DETERMINISTIC
BEGIN
	DECLARE _Result VARCHAR(250) DEFAULT NULL;
	SELECT tostr INTO _Result FROM lang_translations WHERE from_lang='pl' AND to_lang=_Lang_id AND fromstr=_Slowo
	;

	RETURN _Result;
END $$


/* ************************************************************************************************************************************************************************
	SEARCH
************************************************************************************************************************************************************************ */	
DROP FUNCTION IF EXISTS `_SearchKeysToWhere`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_SearchKeysToWhere`(
	_MODE VARCHAR(150),
	_InputKeys TEXT,
	_MaskKeys TEXT,
	_KeySeparator VARCHAR(256)
) RETURNS TEXT
    NO SQL
    DETERMINISTIC
BEGIN
	DECLARE _NextKey VARCHAR(250);
	DECLARE _NextPos INTEGER;
-- 	DECLARE _MaskKeys TEXT;
	DECLARE _KeyWHERE TEXT;
	DECLARE _WHERE TEXT;
	DECLARE _SQL TEXT;
	
	SET _NextKey = '';
	SET _WHERE = '';
	
/*		
	Gdy _MODE = 'FIELDS' to oznacza że mamy w _MaskKeys cos na wzor 'C.Temat;C.nrwewn;C.Opis;C.Log_memo' ) oddzielone srednikiem)
	Gdy _MODE = '' to oznacza że mamy w _MaskKeys całe wyrazenie zawierajace juz %s np.
		SET _MaskKeys = 
		'	(
			(k.Symbol LIKE %s) OR
			(k.Nazwa LIKE %s) OR
			(k.NIP LIKE %s) OR
			(k.NazwaMiasta LIKE %s) OR
			(k.Ulica LIKE %s) OR
			(kk.Adres LIKE %s AND kk.typ_medium IN (0,1,2)) OR
			(kk.Adres LIKE %s AND kk.typ_medium = 3)
			)'
*/		
	
	IF _MODE = 'FIELDS' THEN
		SET _MaskKeys = CONCAT(_MaskKeys, '#LIKE#');
		SET _MaskKeys = REPLACE(_MaskKeys, ';' , '#LIKE# OR ');
		SET _MaskKeys = REPLACE(_MaskKeys, '#LIKE#' , ' LIKE %s ');
		SET _MaskKeys = CONCAT('(', _MaskKeys, ')');
	END IF;
	
	SET _InputKeys = REPLACE(UPPER(_InputKeys), ' AND ' , ';');
	SET _InputKeys = REPLACE(_InputKeys, _KeySeparator , ';');
	SET _InputKeys = CONCAT(_InputKeys, ';');
	SET _NextPos = LOCATE(';', _InputKeys);
	-- SET @_InputKeys = _InputKeys;
	WHILE _NextPos > 0 DO
		IF _NextPos > 1 THEN 
			SET _NextKey = SUBStr(_InputKeys, 1, _NextPos - 1);
			SET _KeyWHERE = REPLACE(_MaskKeys, '%s', CONCAT('''%', _NextKey, '%'''));
			IF _WHERE = '' THEN
				SET _WHERE = _KeyWHERE;
			ELSE
				SET _WHERE = CONCAT(_WHERE, ' AND \n', _KeyWHERE);
			END IF;
			-- SET @_NextKey = _NextKey;
		END IF;
		SET _InputKeys = SUBStr(_InputKeys, _NextPos + 1, 255);
		SET _NextPos = LOCATE(';', _InputKeys);
		-- SET @_WHERE = _WHERE;
		-- SET @_NextPos = _NextPos;
	END WHILE;
		
	
	RETURN _WHERE;
END $$

DROP FUNCTION IF EXISTS `_Buff_Stack`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_Buff_Stack`(
	_MODE VARCHAR(250),
	_BUFF TEXT,
	_INPUT VARCHAR(250)
) RETURNS TEXT
    NO SQL
    DETERMINISTIC
BEGIN
	SET @.Buff := _BUFF;
	IF _MODE = 'Clear' THEN
		SET @.Buff := NULL;
	END IF;
	
	IF _MODE = 'Add' THEN
	-- 	dodawanie
		SET @.Buff = CONCAT_WS(';', @.Buff, _INPUT);
	END IF;
	
	IF _MODE IN ('Del', 'Del.and.Get.Last') THEN
	-- 	usuwanie konkretnego
		SET @.Buff = NULLIF(TRIM(BOTH ';' FROM REPLACE(REPLACE(@.Buff, _INPUT , ''), ';;', ';')), '');
	END IF;
	
	IF _MODE IN ('Del.Last', 'Del.Last.and.Get.Last') THEN
	--	usuwanie ostatniego
		SET @.Buff = NULLIF(TRIM(TRAILING ';' FROM REPLACE(@.Buff, SUBSTRING_INDEX(@.Buff, ';', -1), '')), '');
	END IF;
	
	IF _MODE LIKE '%Get.Last%' THEN
	--	zwróć ostatni
		SET @.Buff = SUBSTRING_INDEX(@.Buff, ';', -1);
	END IF;
	
	IF _MODE LIKE '@.%' THEN
	--	zwróć ostatni
		SET 
			@.Buff.WE = @.Buff
		;
		IF _MODE LIKE '@.TakeOff.First%' OR _MODE LIKE '@.%First%Delete' THEN
			SET @.Buff.Elem = SUBSTRING_INDEX(@.Buff, ';', 1);
			IF _MODE LIKE '@.%First%Delete' THEN
				SET @.Buff.OUT = NULLIF(TRIM(BOTH ';' FROM REPLACE(REPLACE(@.Buff, @.Buff.Elem , ''), ';;', ';')), '');
				SET @xxx = @.Buff.OUT ;
			END IF;
			IF _MODE LIKE '@.TakeOff.First%' THEN
				SET @.Buff = @.Buff.Elem;
			END IF;
		END IF;
	END IF;
	
	RETURN @.Buff;
	
END $$
-- select benchmark(1000000,_mid_sep('xxx|aaa|333|444','|',5)) -> 9sek u konkola;


DROP FUNCTION IF EXISTS `_Mid_Sep`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_Mid_Sep`(
	_Input TEXT,
	_Separator VARCHAR(20),
	_Position INTEGER
) RETURNS TEXT
    NO SQL
    DETERMINISTIC
BEGIN
	RETURN SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(_Input,REPEAT(_Separator,_Position)), _Separator, _Position), _Separator, -1);
END $$
-- select benchmark(1000000,_mid_sep('xxx|aaa|333|444','|',5)) -> 9sek u konkola;

DROP FUNCTION IF EXISTS `_sfmtr`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_sfmtr`(
	_Input VARCHAR(255)
) RETURNS VARCHAR(255)
    NO SQL
    DETERMINISTIC
BEGIN
	RETURN CONCAT('#',_Input);
END $$

DROP FUNCTION IF EXISTS `_dfmt0`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_dfmt0`(
	_Input DOUBLE(16,4)
) RETURNS VARCHAR(20)
    NO SQL
    DETERMINISTIC
BEGIN
	RETURN CONCAT('#',REPLACE(REPLACE(REPLACE(FORMAT(_Input,0),',','*'),'.',','),'*','.'));
END $$

DROP FUNCTION IF EXISTS `_dfmt`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_dfmt`(
	_Input DOUBLE(16,4)
) RETURNS VARCHAR(20)
    NO SQL
    DETERMINISTIC
BEGIN
	RETURN CONCAT('#',REPLACE(REPLACE(REPLACE(FORMAT(_Input,2),',','*'),'.',','),'*','.'));
END $$

DROP FUNCTION IF EXISTS `_dfmt4`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_dfmt4`(
	_Input DOUBLE(16,4)
) RETURNS VARCHAR(20)
    NO SQL
    DETERMINISTIC
BEGIN
	RETURN CONCAT('#',REPLACE(REPLACE(REPLACE(FORMAT(_Input,4),',','*'),'.',','),'*','.'));
END $$

DROP FUNCTION IF EXISTS `_dfmtl`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_dfmtl`(
	_Input DOUBLE(16,4)
) RETURNS VARCHAR(20)
    NO SQL
    DETERMINISTIC
BEGIN
	SET @_dfmtlRETURN=REPLACE(REPLACE(REPLACE(FORMAT(_Input,2),',','*'),'.',','),'*','.');
	RETURN IF(IFNULL(@_dfmtlRIGHT,0)>0,LPAD(@_dfmtlRETURN,greatest(@_dfmtlRIGHT,length(@_dfmtlRETURN)),' '),@_dfmtlRETURN);
END $$

DROP FUNCTION IF EXISTS `_dfmts`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_dfmts`(
	_Input DOUBLE(16,4)
) RETURNS VARCHAR(20)
    NO SQL
    DETERMINISTIC
BEGIN
	RETURN CONCAT('#',REPLACE(REPLACE(FORMAT(_Input,2),',',' '),'.',','));
END $$
 
DROP FUNCTION IF EXISTS `_Mid_Two_Sep`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_Mid_Two_Sep`(
	_Input TEXT,
	_Separator1 VARCHAR(250),
	_Separator2 VARCHAR(250)
) RETURNS TEXT
    NO SQL
    DETERMINISTIC
BEGIN
	RETURN SUBSTRING_INDEX(SUBSTRING_INDEX(_Input, _Separator2, 1), _Separator1, -1);
END $$
 
DROP FUNCTION IF EXISTS `_Midle_Two_Sep`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_Midle_Two_Sep`(
	_Input TEXT,
	_Separator1 VARCHAR(250),
	_Separator2 VARCHAR(250)
) RETURNS TEXT
    NO SQL
    DETERMINISTIC
BEGIN
	IF LOCATE(_Separator1, _Input) > 0 THEN
		RETURN SUBSTRING_INDEX(SUBSTRING_INDEX(_Input, _Separator1, -1), _Separator2, 1);
	ELSE
		RETURN '';
	END IF;
END $$

DROP FUNCTION IF EXISTS `_FetchParams_Quick`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_FetchParams_Quick`(
	_MODE VARCHAR(200),
	_Params TEXT,
	_ParamName VARCHAR(250),
	_ParamA VARCHAR(250)
) RETURNS TEXT
    NO SQL
    DETERMINISTIC
/*
SELECT 
	_FetchParams_Quick('', 'Ala=123&Ola=An12&Tytul=Enea', 'Ola', ''),
;
*/	
BEGIN
	-- SET _ParamName = CONCAT(_ParamName, '=');
	SET _Params = CONCAT('&', _Params);
	RETURN IF(LOCATE(@_ParamName := CONCAT('&', _ParamName, '='), _Params) > 0, SUBSTRING_INDEX(SUBSTRING_INDEX(_Params, @_ParamName, -1), '&', 1), '');
	-- RETURN _Midle_Two_Sep(_Params, CONCAT(_ParamName, '='), '&');
END $$

DELIMITER ;

DELIMITER $$ 
/*  _FetchPar to to samo co _FetchParams_Quick ale zwraca NULL gdy brak  */
DROP FUNCTION IF EXISTS `_FetchPar`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_FetchPar`(
	_MODE VARCHAR(200),
	_Params TEXT,
	_ParamName VARCHAR(250),
	_ParamA VARCHAR(250)
) RETURNS TEXT
    NO SQL
    DETERMINISTIC
/*
SELECT 
	_FetchPar('', 'Ala=123&Ola=An12&Tytul=Enea', 'Ola', ''),
;
*/	
BEGIN
	SET _Params = CONCAT('&', _Params, '&');
    IF _ParamA <> '' THEN
        SET @.fp.R := NULL;
        SET @.fp.Start := LOCATE(@_ParamName := CONCAT('&', _ParamName, '='), _Params);
        IF @.fp.Start > 0 THEN
            SET @.fp.R := SUBSTRING_INDEX(SUBSTRING_INDEX(_Params, @_ParamName, -1), '&', 1);
            IF @.fp.R = '' THEN
            --  duze male litery zawiodly - LOCATE znalazl a SUBSTRING_INDEX nie :( 
                SET @.fp.Start := LOCATE('=', _Params, @.fp.Start + 1);
                SET @.fp.R := SUBSTR(_Params, @.fp.Start + 1);
                SET @.fp.R := SUBSTRING_INDEX(@.fp.R, '&', 1);
                -- SET @.fp.End := GREATEST(@.fp.Start + 1, LOCATE('&', _Params, @.fp.Start + 1));
                -- SET @.fp.R := SUBSTR(_Params, @.fp.Start, @.fp.End - @.fp.Start);
            END IF;
        END IF;
        RETURN @.fp.R;
    ELSE
	RETURN 
        IF(LOCATE(@_ParamName := CONCAT('&', _ParamName, '='), _Params) > 0, 
            SUBSTRING_INDEX(SUBSTRING_INDEX(_Params, @_ParamName, -1), '&', 1), 
            NULL
        );
    END IF;
END $$
DELIMITER ;

DELIMITER $$ 
DROP FUNCTION IF EXISTS `_FetchParams_QuickNull`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_FetchParams_QuickNull`(
	_MODE VARCHAR(200),
	_Params TEXT,
	_ParamName VARCHAR(250),
	_ParamA VARCHAR(250)
) RETURNS TEXT
    NO SQL
    DETERMINISTIC
BEGIN
	SET _Params = CONCAT('&', _Params);
	RETURN IF(LOCATE(@_ParamName := CONCAT('&', _ParamName, '='), _Params) > 0, SUBSTRING_INDEX(SUBSTRING_INDEX(_Params, @_ParamName, -1), '&', 1), NULL);
END $$

DROP FUNCTION IF EXISTS `_FetchParams_QuickEmptyNull`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_FetchParams_QuickEmptyNull`(
	_MODE VARCHAR(200),
	_Params TEXT,
	_ParamName VARCHAR(250),
	_ParamA VARCHAR(250)
) RETURNS TEXT
    NO SQL
    DETERMINISTIC
BEGIN
	SET _Params = CONCAT('&', _Params);
	RETURN NULLIF(IF(LOCATE(@_ParamName := CONCAT('&', _ParamName, '='), _Params) > 0, SUBSTRING_INDEX(SUBSTRING_INDEX(_Params, @_ParamName, -1), '&', 1), NULL), '');
END $$
DELIMITER ;

DELIMITER $$ 
DROP FUNCTION IF EXISTS `_FetchParams`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_FetchParams`(
	_MODE VARCHAR(200),
	_Params TEXT,
	_ParamName VARCHAR(250),
	_ParamA VARCHAR(250)
) RETURNS TEXT
    NO SQL
    DETERMINISTIC
/*
SELECT 
	_FetchParams('', 'Ala=123&Ola=An12&Tytul=Enea', 'Ola', ''),
	_FetchParams('', 'Ala=123&Ola=An12&Tytul=Enea', 'Ala', ''),
	_FetchParams('', 'Ala=123&Ola=An12&Tytul=Enea', 'Tytul', ''),
	_FetchParams('', '<Ala>123<#Ala><Ola>An12<#Ola><Tytul>Enea<#Tytul>', 'Ola', ''),
	_FetchParams('', '<Ala>123<#Ala><Ola>An12<#Ola><Tytul>Enea<#Tytul>', 'Ala', ''),
	_FetchParams('', '<Ala>123<#Ala><Ola>An12<#Ola><Tytul>Enea<#Tytul>', 'Tytul', '')

;
*/	
BEGIN
	DECLARE _Separator1, _Separator2 VARCHAR(250);
set @.x._Params = _Params, @.x._ParamName = _ParamName, @.x._ParamA = _ParamA;
	SET _MODE = IF(LOCATE('<#', _Params) > 0, '<>', _MODE);
	IF _MODE = '<>' THEN
		SET 
			_Separator1 = REPLACE('<ParamName>', 'ParamName', _ParamName),
			_Separator2 = REPLACE('<#ParamName>', 'ParamName', _ParamName)
		;
	ELSE
		SET 
			_Params = CONCAT('&', _Params),
			_Separator1 = REPLACE('&ParamName=', 'ParamName', _ParamName),
			_Separator2 = '&'
		;
	END IF;
set @.x._Separator1 = _Separator1;
	RETURN _Midle_Two_Sep(_Params, _Separator1, _Separator2);
END $$

DROP FUNCTION IF EXISTS `_Params`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_Params`(
	_MODE VARCHAR(200),
	_Separator_MODE VARCHAR(200),
	_Params TEXT,
	_ParamName VARCHAR(250),
	_ParamA VARCHAR(250)	--	dla 'Add' zawiera nowa wartosc parametru
) RETURNS TEXT
    NO SQL
    DETERMINISTIC
BEGIN
	DECLARE _Separator1, _Separator2 VARCHAR(250);
set @.x._Params = _Params, @.x._ParamName = _ParamName, @.x._ParamA = _ParamA;
	IF _MODE LIKE '_FetchParams%' OR _MODE IN ('Delete', 'Add') THEN
		SET _Separator_MODE = IF(_Separator_MODE IN ('&', '<>'), _Separator_MODE, IF(LOCATE('<#', _Params) > 0, '<>', _Separator_MODE));
		IF _Separator_MODE = '<>' THEN
			SET 
				_Separator1 = REPLACE('<ParamName>', 'ParamName', _ParamName),
				_Separator2 = REPLACE('<#ParamName>', 'ParamName', _ParamName)
			;
		ELSE
			SET 
				_Separator1 = REPLACE('&ParamName=', 'ParamName', _ParamName),
				_Separator2 = '&',
				_Params = IF(_Params = '', _Params, REPLACE(CONCAT_WS('', '&', _Params, '&'), '&&', '&'))
			;
set @._Separator1 = _Separator1, @._Separator2 = _Separator2, @._Params = _Params;
		END IF;
		IF _MODE = 'Add' THEN
			RETURN REPLACE(CONCAT_WS('', REPLACE(_Params, CONCAT(_Separator1, _Midle_Two_Sep(_Params, _Separator1, _Separator2), _Separator2), ''), _Separator1, _ParamA, _Separator2), '&&', '&');
		ELSEIF _MODE = 'Delete' THEN
			RETURN REPLACE(_Params, CONCAT(_Separator1, _Midle_Two_Sep(_Params, _Separator1, _Separator2), _Separator2), '');
		ELSEIF _MODE = '_FetchParams' THEN
			RETURN _Midle_Two_Sep(_Params, _Separator1, _Separator2);
		ELSEIF _MODE = '_FetchParams_Quick' THEN
			RETURN IF(LOCATE(@_ParamName := CONCAT(_ParamName, '='), _Params) > 0, SUBSTRING_INDEX(SUBSTRING_INDEX(_Params, @_ParamName, -1), '&', 1), '');
		ELSEIF _MODE = '_FetchParams_QuickNull' THEN
			-- RETURN IF(LOCATE(@_ParamName := CONCAT(_ParamName, '='), _Params) > 0, SUBSTRING_INDEX(SUBSTRING_INDEX(_Params, @_ParamName, -1), '&', 1), NULL);
			-- IF(LOCATE(@_ParamName := CONCAT(_ParamName, '='), _Params) > 0, SUBSTRING_INDEX(SUBSTRING_INDEX(_Params, @_ParamName, -1), '&', 1), NULL);
			RETURN IF(LOCATE(@_ParamName := CONCAT(_ParamName, '='), _Params) > 0, SUBSTRING_INDEX(SUBSTRING_INDEX(_Params, @_ParamName, -1), '&', 1), NULL);
		ELSEIF _MODE = '_FetchParams_QuickEmptyNull' THEN
			RETURN NULLIF(IF(LOCATE(@_ParamName := CONCAT(_ParamName, '='), _Params) > 0, SUBSTRING_INDEX(SUBSTRING_INDEX(_Params, @_ParamName, -1), '&', 1), NULL), '');
		END IF;
	END IF;
	-- RETURN _Midle_Two_Sep(_Params, CONCAT(_ParamName, '='), '&');
END $$


DROP FUNCTION IF EXISTS `_Params2`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_Params2`(
	_MODE VARCHAR(200),
	_Separator_MODE VARCHAR(200),
	_Params TEXT,
	_ParamName VARCHAR(250),
	_ParamA VARCHAR(250)	--	dla 'Add' zawiera nowa wartosc parametru
) RETURNS TEXT
    NO SQL
    DETERMINISTIC
BEGIN
	DECLARE _Separator1, _Separator2 VARCHAR(250);
set @.x._Params = _Params, @.x._ParamName = _ParamName, @.x._ParamA = _ParamA;
	IF _MODE LIKE '_FetchParams%' OR _MODE IN ('Delete', 'Add') THEN
		SET _Separator_MODE = IF(_Separator_MODE IN ('&', '<>'), _Separator_MODE, IF(LOCATE('<#', _Params) > 0, '<>', _Separator_MODE));
		IF _Separator_MODE = '<>' THEN
			SET 
				_Separator1 = CONCAT('<', _ParamName, '>'),
				_Separator2 = CONCAT('<#', _ParamName, '>')
				-- _Separator1 = REPLACE('<ParamName>', 'ParamName', _ParamName),
				-- _Separator2 = REPLACE('<#ParamName>', 'ParamName', _ParamName)
			;
			SET 
				@._Separator1 = SUBSTR(_Params, LOCATE(_Separator1, _Params), LENGTH(_Separator1)),
				@._Separator2 = SUBSTR(_Params, LOCATE(_Separator2, _Params), LENGTH(_Separator2))
			;
			SET 
				@.SEQ.Parameter = _Midle_Two_Sep(_Params, @._Separator1, @._Separator2)
			;
			SET 
				@.SEQ.SEP.Parameter.SEP = CONCAT(@._Separator1, @.SEQ.Parameter, @._Separator2)
			;
		ELSE
			SET 
				_Separator1 = CONCAT('&', _ParamName, '='),
				_Separator2 = '&',
				_Params = IF(_Params = '', _Params, REPLACE(CONCAT_WS('', '&', _Params, '&'), '&&', '&'))
			;
			set @.A._Separator1 = _Separator1;
			SET 
				@._Separator1 = SUBSTR(_Params, LOCATE(_Separator1, _Params), LENGTH(_Separator1)),
				@._Separator2 = _Separator2
			;
			SET 
				@.SEQ.Parameter = _Midle_Two_Sep(_Params, @._Separator1, @._Separator2)
			;
			SET 
				@.SEQ.SEP.Parameter.SEP = CONCAT(@._Separator1, @.SEQ.Parameter, @._Separator2)
			;
		END IF;
		
		IF _MODE = 'Add' THEN
			-- bylo RETURN REPLACE(CONCAT_WS('', REPLACE(_Params, CONCAT(_Separator1, _Midle_Two_Sep(_Params, _Separator1, _Separator2), _Separator2), ''), _Separator1, _ParamA, _Separator2), '&&', '&');
			SET @.Result.Parameter = 
				CONCAT_WS('', REPLACE(_Params, @.SEQ.SEP.Parameter.SEP, ''), _Separator1, _ParamA, _Separator2);
			IF NOT (_Separator_MODE = '<>') THEN
				SET @.Result.Parameter = REPLACE(@.Result.Parameter, '&&', '&');
			END IF;
		ELSEIF _MODE = 'Delete' THEN
			-- bylo RETURN REPLACE(_Params, CONCAT(_Separator1, _Midle_Two_Sep(_Params, _Separator1, _Separator2), _Separator2), '');
			SET @.Result.Parameter = 
				REPLACE(_Params, @.SEQ.SEP.Parameter.SEP, '');
			IF NOT (_Separator_MODE = '<>') THEN
				SET @.Result.Parameter = REPLACE(@.Result.Parameter, '&&', '&');
			END IF;
		ELSEIF _MODE = '_FetchParams' THEN
			SET @.Result.Parameter = @.SEQ.Parameter;
		ELSEIF _MODE = '_FetchParams.Sznurek' THEN
		--	pobieranie ze sznurka danyc do zapisu - gdy @._Separator1 jest pusty oznacza ze 
		--	parametru nie bylo a nie ze jest pusty - dajemy NULL a na zwenatrz mozemy sobie to obrobic typu ifnull
			SET @.Result.Parameter =
				IF(IFNULL(@._Separator1, '') = '',
					NULL,
					@.SEQ.Parameter
				)
			;
		ELSEIF _MODE = '_FetchParams_Quick' THEN
			SET @.Result.Parameter = @.SEQ.Parameter;
		ELSEIF _MODE = '_FetchParams_QuickNull' THEN
			SET @.Result.Parameter = NULLIF(@.SEQ.Parameter, '');
		ELSEIF _MODE = '_FetchParams_QuickEmptyNull' THEN
			SET @.Result.Parameter = NULLIF(@.SEQ.Parameter, '');
		ELSE 
			SET @.Result.Parameter = NULL;
		END IF;
		
		RETURN @.Result.Parameter;
	END IF;
	-- RETURN _Midle_Two_Sep(_Params, CONCAT(_ParamName, '='), '&');
END $$

DROP FUNCTION IF EXISTS `_REPLACE_Brackets`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_REPLACE_Brackets`(
	_MASK VARCHAR(150),
	_From VARCHAR(150),
	_To VARCHAR(150)
) RETURNS VARCHAR(250)
    NO SQL
    DETERMINISTIC
BEGIN
	IF (@._REPLACE_Brackets.Exists := (LOCATE('<', _MASK) > 0)) AND (LOCATE(_From, _MASK) > 0) THEN
		SET _MASK = REPLACE(_MASK, _From, _To);
		SET @._REPLACE_Brackets.Exists := (LOCATE('<', _MASK) > 0);
	END IF;
	RETURN _MASK;
END $$

DROP PROCEDURE IF EXISTS `_SEQ_Get_Next`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `_SEQ_Get_Next`(
	INOUT _Str TEXT,
	IN _Separator VARCHAR(20),
	-- IN _Pos INTEGER,
	INOUT _SubStr VARCHAR(255),
	IN _Param_A VARCHAR(255)
	)
/*
	SET @_Str = 'ala&ola&ela';
	CALL _SEQ_Get_Next(@_Str, '&', 1, @_SubStr, '');
	CALL _SEQ_Get_Next(@_Str, '&', 2, @_SubStr, '');
	...
*/	

BEGIN 
	-- SET _SubStr = NULLIF(SUBSTRING_INDEX(SUBSTRING_INDEX(_Str, _Separator, _Pos), _Separator, -1), _Str);
	SET _SubStr = SUBSTRING_INDEX(_Str, _Separator, 1);
	SET 
		_Str = 
			IF(_Str = _SubStr,
				'',
				REPLACE(REPLACE(_Str, CONCAT(_SubStr, _Separator), ''), CONCAT(_Separator, _SubStr), '')
			)
	;
END $$


/************************************************************************************************************************************************************************
	slownie
************************************************************************************************************************************************************************/
DROP FUNCTION IF EXISTS `_Get_Slownie`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_Get_Slownie`(
	_Kwota INTEGER
) RETURNS VARCHAR(255)
    NO SQL
    DETERMINISTIC
BEGIN
	SET
		@jednosc = _Kwota % 10,
		@para = _Kwota % 100,
		@Setki = (_Kwota % 1000) DIV 100,
		@mult = '0',
		@result = NULL
	;


	IF _Kwota = 0 THEN
		RETURN 'zero';
	ELSE
		IF (@para >= 10 AND @para < 20) THEN
			SET @result = 
				(SELECT Liczebnik FROM `_sys_Liczebniki` WHERE Rzad='N' AND Nominal = @jednosc LIMIT 1)
			;
		ELSE
			SET @result =
				CONCAT(
					(SELECT Liczebnik FROM `_sys_Liczebniki` WHERE Rzad='D' AND Nominal = (@para DIV 10) LIMIT 1),
					(SELECT Liczebnik FROM `_sys_Liczebniki` WHERE Rzad='J' AND Nominal = @jednosc LIMIT 1)
				)
			;
		END IF;
		SET @resultXX = @result;
		SET @result =
			CONCAT(
				(SELECT Liczebnik FROM `_sys_Liczebniki` WHERE Rzad='S' AND Nominal = @Setki LIMIT 1),
				@result
			)
			;

		-- X > 1000 
		SET _Kwota = _Kwota DIV 1000;
		
		WHILE _Kwota> 0 DO
			SET @jednosc = _Kwota % 10;
			SET @para = _Kwota % 100;
			SET @Setki = (_Kwota % 1000) DIV 100;
	  
			IF ((_Kwota % 1000) DIV 10 = 0) THEN
				SET @result =
					CONCAT(
						CASE 
						WHEN @jednosc > 1 THEN
							(SELECT Liczebnik FROM `_sys_Liczebniki` WHERE Rzad='J' AND Nominal = @jednosc LIMIT 1)
						ELSE ''
						END,
						CASE 
						WHEN @jednosc=1 THEN
							(SELECT Liczebnik FROM `_sys_Liczebniki` WHERE Rzad=@mult AND Nominal = 1 LIMIT 1)
						WHEN @jednosc BETWEEN 2 AND 4 THEN
							(SELECT Liczebnik FROM `_sys_Liczebniki` WHERE Rzad=@mult AND Nominal = 2 LIMIT 1)
						WHEN _Kwota % 1000 != 0 THEN
							(SELECT Liczebnik FROM `_sys_Liczebniki` WHERE Rzad=@mult AND Nominal = 5 LIMIT 1)
						ELSE ''
						END,
						@result
					)
				; 
			ELSEIF (@para >= 10 AND @para < 20) THEN
				SET @result =
					CONCAT(
						(SELECT Liczebnik FROM `_sys_Liczebniki` WHERE Rzad='N' AND Nominal = @para%10 LIMIT 1),
						(SELECT Liczebnik FROM `_sys_Liczebniki` WHERE Rzad=@mult AND Nominal = 5 LIMIT 1),
						@result
					)
				;
			ELSE
				SET @result =
					CONCAT(
						(SELECT Liczebnik FROM `_sys_Liczebniki` WHERE Rzad='D' AND Nominal = (@para DIV 10) LIMIT 1),
						(SELECT Liczebnik FROM `_sys_Liczebniki` WHERE Rzad='J' AND Nominal = @jednosc LIMIT 1),
						CASE 
						WHEN @jednosc BETWEEN 2 AND 4 THEN
							(SELECT Liczebnik FROM `_sys_Liczebniki` WHERE Rzad=@mult AND Nominal = 2)
						ELSE
							(SELECT Liczebnik FROM `_sys_Liczebniki` WHERE Rzad=@mult AND Nominal = 5 LIMIT 1)
						END,
						@result
					)
				;
			END IF;
			
			SET @result =
				CONCAT(
					(SELECT Liczebnik FROM `_sys_Liczebniki` WHERE Rzad='S' AND Nominal = @Setki LIMIT 1),
					@result
				)
			;
			
			SET _Kwota = _Kwota / 1000;
			SET @mult = @mult+1;
		END WHILE;
		
		RETURN RTRIM(LTRIM(REPLACE(@result,'  ', ' ')));
	END IF;
END $$

/*
select get_slownie(1234567.01,'',2,'PLN');
*/

DROP FUNCTION IF EXISTS `Get_Slownie`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `Get_Slownie`(

	_Kwota DOUBLE(16, 4),
	_TrimStr VARCHAR(5),
	_FracDecimal INTEGER,
	_NazwaWalutyShort VARCHAR(20)
) RETURNS VARCHAR(255)
    NO SQL
    DETERMINISTIC
BEGIN
	DECLARE _FracPower, _KwotaFrac INTEGER;
	DECLARE _Kwota_WE DOUBLE(16, 4);
	SET	
		_NazwaWalutyShort = IFNULL(_NazwaWalutyShort, 'PLN'),
		_FracDecimal = IFNULL(_FracDecimal, 2),
		_Kwota_WE = ABS(_Kwota)
	;
	SET	_FracPower = ROUND(POWER(10, _FracDecimal));
	
	SET _KwotaFrac = _Get_Frac(_Kwota_WE, _FracDecimal);
	
	set @_Kwota = _Kwota, @_FracDecimal = _FracDecimal, @_NazwaWalutyShort = _NazwaWalutyShort;

	SET @_KwotaStr.1 = CONCAT(_Get_Slownie(ABS(FLOOR(_Kwota_WE))), ' ', @_NazwaWalutyShort);
	SET @_KwotaStr.Frac = 
		IF(_FracDecimal > 0 AND _KwotaFrac <> 0,
			-- CONCAT(LPAD(_KwotaFrac, _FracDecimal, '0'), IFNULL(@.Waluta.Farc.Name, CONCAT('/', POWER(10, _FracDecimal)))),
			CONCAT(LPAD(_KwotaFrac, _FracDecimal, '0'), IFNULL(@.Waluta.Farc.Name, CONCAT('/', _FracPower))),
			''
		)
	;
	SET @_KwotaStr = _ConcatSTR(@_KwotaStr.1, @_KwotaStr.Frac, ' ');
	RETURN 
		IF((@_TrimStr := IFNULL(_TrimStr, '***')) <> '', 
			CONCAT(@_TrimStr, @_KwotaStr, @_TrimStr),
			@_KwotaStr
		)
	;
END $$
DELIMITER ;

DELIMITER $$
DROP FUNCTION IF EXISTS `SetTypeV`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `SetTypeV`(
	_MODE VARCHAR(250),
	we VARCHAR(250),	--	BI, AI, BU, AU, ...
	S1 VARCHAR(250),
	S2 VARCHAR(250),
	S3 VARCHAR(250)
	
) RETURNS VARCHAR(200)
	DETERMINISTIC
-- 	Dodawanie usuwanie z typu SET
BEGIN
    SET @.IsStatusV.Return := we;
	IF _MODE LIKE 'ADD' THEN
    /*  dodaje S1 do we i usuwa S2 z we    */
        IF S2 <> '' THEN
            SET @.IsStatusV.Return = REPLACE(@.IsStatusV.Return, S2, '');
        END IF;
        SET @.IsStatusV.Return = CONCAT_WS(',', @.IsStatusV.Return, S1);
    END IF;
	IF _MODE LIKE 'DEL' THEN
    /*  usuwa S2 lub S3 z we    */
        IF S2 <> '' THEN
            SET @.IsStatusV.Return = REPLACE(@.IsStatusV.Return, S2, '');
        END IF;
        IF S3 <> '' THEN
            SET @.IsStatusV.Return = REPLACE(@.IsStatusV.Return, S3, '');
        END IF;
    END IF;
	RETURN @.IsStatusV.Return;
END;
$$
DELIMITER ;

DELIMITER $$ 
DROP FUNCTION IF EXISTS `_Delimit`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_Delimit`(
	_MODE VARCHAR(200),
	_We VARCHAR(256),
	_Par VARCHAR(256),
	_Delimiter VARCHAR(10)
) RETURNS VARCHAR(2560)
    NO SQL
    DETERMINISTIC
L_EXIT: BEGIN
    IF IFNULL(_Par, '') <> '' THEN
        SET _Delimiter := IFNULL(NULLIF(_Delimiter, ''), ',');
        SET @_Del2 := CONCAT(_Delimiter, _Delimiter);
        
        IF _MODE IN ('Add','Del') THEN
            SET @._Delimit.Return := 
                REPLACE(REPLACE(REPLACE(_We, _Par, ''), @_Del2, _Delimiter), @_Del2, _Delimiter);
        END IF;
        IF _MODE IN ('Add') THEN
            SET @._Delimit.Return := 
                REPLACE(CONCAT_WS(_Delimiter, @._Delimit.Return, _Par), @_Del2, _Delimiter);
        END IF;
    ELSE
        SET @._Delimit.Return := _We;
    END IF;
    SET @._Delimit.Return := TRIM(BOTH _Delimiter FROM @._Delimit.Return);
    RETURN @._Delimit.Return;
END $$
DELIMITER ;

DELIMITER $$ 
DROP FUNCTION IF EXISTS `_ExtFlags`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_ExtFlags`(
	_MODE VARCHAR(200),
	_IN_ExtFlags VARCHAR(256),
	_Flag VARCHAR(256),
	_Content VARCHAR(256),
	_ParamA VARCHAR(256)
) RETURNS VARCHAR(256)
    NO SQL
    DETERMINISTIC
BEGIN
	IF _MODE IN ('Del', 'DELETE') THEN
		SET @_loc.ExtFlag := CONCAT('<', _Flag, '>');
		SET _IN_ExtFlags = REPLACE(_IN_ExtFlags, @_loc.ExtFlag, '');
		RETURN _IN_ExtFlags;
	END IF;
	
	IF _MODE IN ('ADD', 'SET') THEN
		SET @_loc.ExtFlag := CONCAT('<', _Flag, '>');
		SET _IN_ExtFlags = REPLACE(_IN_ExtFlags, @_loc.ExtFlag, '');
		SET _IN_ExtFlags = CONCAT_WS('', _IN_ExtFlags, @_loc.ExtFlag);
		RETURN _IN_ExtFlags;
	END IF;

	IF _MODE = 'GET' THEN
		SET @_loc.ExtFlag := CONCAT('<', _Flag, '>');
		SET _IN_ExtFlags = 
			IF(LOCATE(@_loc.ExtFlag, _IN_ExtFlags) > 0,
				@_loc.ExtFlag,
				''
			)
		;
		RETURN _IN_ExtFlags;
	END IF;

	
	IF _MODE LIKE 'Del.Content' THEN
		SET _IN_ExtFlags = _Params('delete', '<>', _IN_ExtFlags, _Flag, '');
		RETURN _IN_ExtFlags;
	END IF;

	IF _MODE LIKE 'ADD.Content' THEN
		SET _IN_ExtFlags = _Params('Add', '<>', _IN_ExtFlags, _Flag, _Content);
		RETURN _IN_ExtFlags;
	END IF;

	IF _MODE = 'GET.Content' THEN
		SET _IN_ExtFlags = _Params('_FetchParams', '<>', _IN_ExtFlags, _Flag, '');
		RETURN _IN_ExtFlags;
	END IF;
	
	
	IF _MODE = 'ADD.Text' THEN
		SET _Flag = IF(_ParamA = '(', CONCAT('(', _Flag, ')'), _Flag);
		SET _IN_ExtFlags = REPLACE(_IN_ExtFlags, _Flag, '');
		SET _IN_ExtFlags = CONCAT_WS('', _IN_ExtFlags, _Flag);
		RETURN _IN_ExtFlags;
	END IF;

	IF _MODE = 'DEL.Text' THEN
		SET _Flag = IF(_ParamA = '(', CONCAT('(', _Flag, ')'), _Flag);
		SET _IN_ExtFlags = REPLACE(_IN_ExtFlags, _Flag, '');
		RETURN _IN_ExtFlags;
	END IF;

	IF _MODE = 'GET.Text' THEN
		SET _IN_ExtFlags = 
			IF(LOCATE(_Flag, _IN_ExtFlags) > 0,
				_Flag,
				''
			)
		;
		RETURN _IN_ExtFlags;
	END IF;
	
	IF _MODE LIKE '%.Value' THEN
		SET @.Flag.Value = CONCAT('<', _Flag, '=');
		IF _MODE LIKE 'ADD.Value' THEN
			SET _IN_ExtFlags = 
				CONCAT_WS('', 
					REPLACE(_IN_ExtFlags, CONCAT(@.Flag.Value, _Midle_Two_Sep(_IN_ExtFlags, @.Flag.Value, '>'), '>'), ''),
					CONCAT(@.Flag.Value, _Content, '>')
				)
			;
			RETURN _IN_ExtFlags;
		END IF;

		IF _MODE = 'GET.Value' THEN
			SET _IN_ExtFlags = _Midle_Two_Sep(_IN_ExtFlags, @.Flag.Value, '>');
			RETURN _IN_ExtFlags;
		END IF;
		
		IF _MODE LIKE 'DEL.Value' THEN
			SET _IN_ExtFlags = REPLACE(_IN_ExtFlags, CONCAT(@.Flag.Value, _Midle_Two_Sep(_IN_ExtFlags, @.Flag.Value, '>'), '>'), '');
			RETURN _IN_ExtFlags;
		END IF;
	END IF;

END $$
DELIMITER ;

DELIMITER $$ 
/*  
    FlagsSet
*/
DROP FUNCTION IF EXISTS `FlagsSet`$$ --  dawne _abT
CREATE DEFINER=`root`@`localhost` FUNCTION `FlagsSet`(
    _MODE VARCHAR(150),
    _flags VARCHAR(50),   -- flagi do 50 znaków
    _flag VARCHAR(50),   -- flagi do 50 znaków
    _A VARCHAR(50)
) RETURNS VARCHAR(500)
    NO SQL
    DETERMINISTIC
BEGIN
    SET @.Flags.Return := _flags;
    IF _MODE IN ('ADD','+') THEN
        IF LOCATE(_flag, IFNULL(_flags, '')) = 0 THEN
            SET @.Flags.Return := CONCAT_WS('', @.Flags.Return, _flag);
        END IF;
    END IF;
    IF _MODE IN ('DEL','-') THEN
        IF LOCATE(_flag, _flags) > 0 THEN
            SET @.Flags.Return := REPLACE(@.Flags.Return, _flag, '');
        END IF;
    END IF;
    RETURN @.Flags.Return;
END $$
DELIMITER ;

DELIMITER $$ 
DROP FUNCTION IF EXISTS _regexp_replace$$
CREATE FUNCTION  _regexp_replace(lancuch VARCHAR(100), maska VARCHAR(100),naco VARCHAR(100))
-- funkcja ktora zamienia znaki w lancuchu, zdefiniowane maska, na znaki pozadane - maska moze byc podana jako regexp, przyklad:
-- _regexp_replace(nip,'[^0-9]','')
RETURNS VARCHAR(100)
DETERMINISTIC
BEGIN 
 DECLARE temp VARCHAR(100); 
 DECLARE ch VARCHAR(1); 
 DECLARE i INT;
 SET i = 1;
 SET temp = '';
 IF lancuch REGEXP maska THEN 
  loop_label: LOOP 
   IF i > CHAR_LENGTH(lancuch) THEN
    LEAVE loop_label;  
   END IF;
   SET ch = SUBSTRING(lancuch,i,1);
   IF NOT ch REGEXP maska THEN
    SET temp = CONCAT(temp,ch);
   ELSE
    SET temp = CONCAT(temp,naco);
   END IF;
   SET i=i+1;
  END LOOP;
 ELSE
  SET temp = lancuch;
 END IF;
 RETURN temp;
END $$
DELIMITER ;

DELIMITER $$ 
/*  od VI 20025 
    regexp_replace w zalezności od wersji serw.
*/
DROP FUNCTION IF EXISTS `regexp_replace_ver`$$
CREATE FUNCTION  `regexp_replace_ver`(
    _inStr VARCHAR(100), 
    _mask VARCHAR(100),
    _toStr VARCHAR(100)
)
RETURNS VARCHAR(100)
-- funkcja ktora zamienia znaki w lancuchu, zdefiniowane maska, na znaki pozadane - maska moze byc podana jako regexp, przyklad:
-- _regexp_replace(nip,'[^0-9]','')
    NO SQL
    DETERMINISTIC
BEGIN
	SET @.RegExp.Return := NULL, @.RegExp.F := NULL;
    IF @@version LIKE '10.%' THEN
        SET @.X := '1';
        /*M!100001 SET @.RegExp.Return := IFNULL(@.RegExp.Return, regexp_replace(_inStr, _mask, _toStr)), @.RegExp.F := IFNULL(@.RegExp.F, 'NEW.10mmrr');*/
    /*  Wersja OK - Mamy @.RegExp.Return  */
    ELSE
    /*  Wersja starsza .... @.RegExp.Return tutaj jest nadal NULL   */
        SET @.X := '2';
    END IF;
    SET 
        @.RegExp.Return := IFNULL(@.RegExp.Return, _regexp_replace(_inStr, _mask, _toStr)),
        @.RegExp.F := IFNULL(@.RegExp.F, 'LESS 8.4.0')
    ;
    RETURN @.RegExp.Return;
	-- RETURN IFNULL(@.KB, REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(TRIM(_NrR), '.', ''), '-', ''), ' ', ''), '_', ''), '/', ''));
END $$
DELIMITER ;

DELIMITER $$ 
DROP FUNCTION IF EXISTS `regexp_replace_`$$
CREATE FUNCTION  `regexp_replace_`(
    _inStr VARCHAR(100), 
    _mask VARCHAR(100),
    _toStr VARCHAR(100)
)
RETURNS VARCHAR(100)
-- funkcja ktora zamienia znaki w lancuchu, zdefiniowane maska, na znaki pozadane - maska moze byc podana jako regexp, przyklad:
-- _regexp_replace(nip,'[^0-9]','')
    NO SQL
    DETERMINISTIC
BEGIN
	SET @.RegExp.Return := NULL, @.RegExp.F := NULL;
	/*!80404 SET @.RegExp.Return := REGEXP_REPLACE(_inStr, _mask, _toStr), @.RegExp.F := 'NEW.80404';*/
	/*M!100001 SET @.RegExp.Return := IFNULL(@.RegExp.Return, _regexp_replace(_inStr, _mask, _toStr)), @.RegExp.F := IFNULL(@.RegExp.F, 'NEW.10mmrr');*/
    SET 
        @.RegExp.Return := IFNULL(@.RegExp.Return, _regexp_replace(_inStr, _mask, _toStr)),
        @.RegExp.F := IFNULL(@.RegExp.F, 'LESS 8.4.0')
    ;
    RETURN @.RegExp.Return;
	-- RETURN IFNULL(@.KB, REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(TRIM(_NrR), '.', ''), '-', ''), ' ', ''), '_', ''), '/', ''));
END $$
DELIMITER ;

DELIMITER $$ 
DROP FUNCTION IF EXISTS `_NrRB`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_NrRB`(
	_NrR VARCHAR(50)
) RETURNS VARCHAR(50)
    NO SQL
    DETERMINISTIC
L_EXIT: BEGIN
    RETURN regexp_replace_(_NrR, '[^0-9]+', '');
    LEAVE L_EXIT;
END $$
DELIMITER ;

DELIMITER $$ 
DROP FUNCTION IF EXISTS `_Get_Replace_from_Slowniki_Pierw`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_Get_Replace_from_Slowniki_Pierw`(
	_IN_Text VARCHAR(1024), -- MEDIUMTEXT,
	_Slownik_GUID VARCHAR(100),
	-- _Slownik_GUID_1 VARCHAR(100),
	-- _Slownik_GUID_2 VARCHAR(100),
	_Sep1 VARCHAR(100),
	_Sep2 VARCHAR(100)
) RETURNS VARCHAR(65532)
    NO SQL
    DETERMINISTIC
BEGIN
	/*
	SET
		_IN_Text = CONVERT(_IN_Text USING UTF8),
		_Sep1 = CONVERT(_Sep1 USING UTF8),
		_Sep2 = CONVERT(_Sep2 USING UTF8)
	;
	*/
	SET
		@.IN_Text = _IN_Text
	-- 'Elżbieta I ma Oddział warana i Plac wyładunkowy. Ten plac to Plac wyładunkowy a nie Sklep.\nBiuro jest opodal a dalej Stacja paliw i Stacja kolejowa.\nZa rogiem jes Punkt odbioru jeszcze.'
	;
	DROP TEMPORARY TABLE IF EXISTS `t_IN_repl_out_texts_end`;
	CREATE TEMPORARY TABLE `t_IN_repl_out_texts_end` (
	  `End_WORD` VARCHAR(250) NOT NULL,
	  PRIMARY KEY `End_WORD`(`End_WORD`)
	) ENGINE=MYISAM -- DEFAULT CHARSET=UTF8
	;
	INSERT IGNORE INTO `t_IN_repl_out_texts_end`
	(`End_WORD`)
	VALUES
	(' '),(','),(';'),('.'),(')'),(']'),('\r'),('\n')
	;
	
	DROP TEMPORARY TABLE IF EXISTS `t_IN_repl_out_texts`;
	CREATE TEMPORARY TABLE `t_IN_repl_out_texts` (
	  `IN_WORD` VARCHAR(250) NOT NULL,
	  `IN_WORD_UUU` VARCHAR(250) NOT NULL,
	  `IN_WORD_lll` VARCHAR(250) NOT NULL,
	  `IN_WORD_Ull` VARCHAR(250) NOT NULL,
	  `OUT_WORD` VARCHAR(250),
	  PRIMARY KEY `IN_WORD`(`IN_WORD`)
	) ENGINE=MYISAM -- DEFAULT CHARSET=UTF8
	;
	/*
	INSERT IGNORE INTO `t_IN_repl_out_texts`
	(IN_WORD, IN_WORD_UUU, IN_WORD_lll, IN_WORD_Ull, OUT_AS_UPPER)
		SELECT
			-- CONVERT(sp.DisplayValue USING UTF8),
			-- UCASE(CONVERT(sp.DisplayValue USING UTF8)),
			-- LCASE(CONVERT(sp.DisplayValue USING UTF8)),
			-- _UpperFirst(CONVERT(sp.DisplayValue USING UTF8))
			sp.DisplayValue,
			UCASE(sp.DisplayValue),
			LCASE(sp.DisplayValue),
			_UpperFirst(sp.DisplayValue),
			IF(@session.globals.Owner = 'KONKOL', TRUE, FALSE)
		FROM `slowniki_pierwotne` sp 
		WHERE
			-- sp.Slownik_GUID IN ('Area_Nodes_Lokalizacje', 'TOWR_ALERGENY')
			sp.Slownik_GUID = _Slownik_GUID
			-- AND IFNULL(sp.DisplayValue, '') <> ''
			AND LENGTH(sp.DisplayValue) > 1
		ORDER BY sp.DisplayValue DESC
	;
	*/
	INSERT IGNORE INTO `t_IN_repl_out_texts`
	(IN_WORD, IN_WORD_UUU, IN_WORD_lll, IN_WORD_Ull, OUT_WORD)
		SELECT
			sp.DisplayValue,
			UCASE(sp.DisplayValue),
			LCASE(sp.DisplayValue),
			_UpperFirst(sp.DisplayValue),
			IF(@session.globals.Owner = 'KONKOL', UPPER(sp.DisplayValue), sp.DisplayValue)
		FROM `slowniki_pierwotne` sp
		WHERE
			-- sp.Slownik_GUID IN ('Area_Nodes_Lokalizacje', 'TOWR_ALERGENY')
			sp.Slownik_GUID = _Slownik_GUID
			-- AND IFNULL(sp.DisplayValue, '') <> ''
			AND LENGTH(sp.DisplayValue) > 1
		ORDER BY sp.DisplayValue DESC
	;
	
	SET 
		-- @.OUT_Text = @.IN_Text, 
		-- @.OUT_Text = _IN_Text,
		@.OUT_Text = NULL,
		@.I = 0, 
		@._Sep1 = _Sep1, @._Sep2 = _Sep2
	;
	/*
	było
	SET
		@.OUT_Text =
		(
			SELECT 
				t.OUT_Text 
			FROM 
			(
				SELECT
					(@.I := @.I + 1) AS ID,
					(@.IN_Text) AS IN_Text,
					(@.OUT_Text := 
						REPLACE(REPLACE(@.OUT_Text, 
							CONCAT(TRIM(sp.DisplayValue), ' '), CONCAT(_Sep1, sp.DisplayValue, _Sep2)),
							CONCAT(TRIM(sp.DisplayValue), ','), CONCAT(_Sep1, sp.DisplayValue, _Sep2))
					) AS OUT_Text
				FROM `slowniki_pierwotne` sp 
				WHERE
					sp.Slownik_GUID = _Slownik_GUID
			) AS t 
			ORDER BY ID DESC 
			LIMIT 1
		)
	;
	*/
	SET
		@.OUT_Text =
		(
			SELECT 
				t.OUT_Text 
			FROM 
			(
				SELECT
					(@.I := @.I + 1) AS ID,
					(@.IN_Text) AS IN_Text,
					(@.OUT_Text := 
						REPLACE(
						REPLACE(
						REPLACE(
						REPLACE(
							IFNULL(@.OUT_Text, @.IN_Text), 
						--	IN_WORD
							CONCAT(rt.IN_WORD, tend.End_WORD), CONCAT(@._Sep1, rt.OUT_WORD, @._Sep2, tend.End_WORD)),
						--	IN_WORD_UUU
							CONCAT(rt.IN_WORD_UUU, tend.End_WORD), CONCAT(@._Sep1, rt.OUT_WORD, @._Sep2, tend.End_WORD)),
						--	IN_WORD_lll
							CONCAT(rt.IN_WORD_lll, tend.End_WORD), CONCAT(@._Sep1, rt.OUT_WORD, @._Sep2, tend.End_WORD)),
						--	IN_WORD_Ull
							CONCAT(rt.IN_WORD_Ull, tend.End_WORD), CONCAT(@._Sep1, rt.OUT_WORD, @._Sep2, tend.End_WORD))
							
						/*
						
						REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
						REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
						REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
						REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
							IFNULL(@.OUT_Text, _IN_Text), 
						--	IN_WORD
							CONCAT(TRIM(rt.IN_WORD), ' '), CONCAT(@._Sep1, rt.IN_WORD, @._Sep2, ',')),
							CONCAT(TRIM(rt.IN_WORD), ','), CONCAT(@._Sep1, rt.IN_WORD, @._Sep2, ',')),
							CONCAT(TRIM(rt.IN_WORD), ';'), CONCAT(@._Sep1, rt.IN_WORD, @._Sep2, ';')),
							CONCAT(TRIM(rt.IN_WORD), '.'), CONCAT(@._Sep1, rt.IN_WORD, @._Sep2, '.')),
							CONCAT(TRIM(rt.IN_WORD), ')'), CONCAT(@._Sep1, rt.IN_WORD, @._Sep2, ')')),
							CONCAT(TRIM(rt.IN_WORD), ']'), CONCAT(@._Sep1, rt.IN_WORD, @._Sep2, ']')),
							CONCAT(TRIM(rt.IN_WORD), '\r'), CONCAT(@._Sep1, rt.IN_WORD, @._Sep2, '\r')),
							CONCAT(TRIM(rt.IN_WORD), '\n'), CONCAT(@._Sep1, rt.IN_WORD, @._Sep2, '\n')),
						--	IN_WORD_UUU
							CONCAT(TRIM(rt.IN_WORD_UUU), ' '), CONCAT(@._Sep1, rt.IN_WORD_UUU, @._Sep2, ' ')),
							CONCAT(TRIM(rt.IN_WORD_UUU), ','), CONCAT(@._Sep1, rt.IN_WORD_UUU, @._Sep2, ',')),
							CONCAT(TRIM(rt.IN_WORD_UUU), ';'), CONCAT(@._Sep1, rt.IN_WORD_UUU, @._Sep2, ';')),
							CONCAT(TRIM(rt.IN_WORD_UUU), '.'), CONCAT(@._Sep1, rt.IN_WORD_UUU, @._Sep2, '.')),
							CONCAT(TRIM(rt.IN_WORD_UUU), ')'), CONCAT(@._Sep1, rt.IN_WORD_UUU, @._Sep2, ')')),
							CONCAT(TRIM(rt.IN_WORD_UUU), ']'), CONCAT(@._Sep1, rt.IN_WORD_UUU, @._Sep2, ']')),
							CONCAT(TRIM(rt.IN_WORD_UUU), '\r'), CONCAT(@._Sep1, rt.IN_WORD_UUU, @._Sep2, '\r')),
							CONCAT(TRIM(rt.IN_WORD_UUU), '\n'), CONCAT(@._Sep1, rt.IN_WORD_UUU, @._Sep2, '\n')),
						--	IN_WORD_lll
							CONCAT(TRIM(rt.IN_WORD_lll), ' '), CONCAT(@._Sep1, rt.IN_WORD_lll, @._Sep2, ' ')),
							CONCAT(TRIM(rt.IN_WORD_lll), ','), CONCAT(@._Sep1, rt.IN_WORD_lll, @._Sep2, ',')),
							CONCAT(TRIM(rt.IN_WORD_lll), ';'), CONCAT(@._Sep1, rt.IN_WORD_lll, @._Sep2, ';')),
							CONCAT(TRIM(rt.IN_WORD_lll), '.'), CONCAT(@._Sep1, rt.IN_WORD_lll, @._Sep2, '.')),
							CONCAT(TRIM(rt.IN_WORD_lll), ')'), CONCAT(@._Sep1, rt.IN_WORD_lll, @._Sep2, ')')),
							CONCAT(TRIM(rt.IN_WORD_lll), ']'), CONCAT(@._Sep1, rt.IN_WORD_lll, @._Sep2, ']')),
							CONCAT(TRIM(rt.IN_WORD_lll), '\r'), CONCAT(@._Sep1, rt.IN_WORD_lll, @._Sep2, '\r')),
							CONCAT(TRIM(rt.IN_WORD_lll), '\n'), CONCAT(@._Sep1, rt.IN_WORD_lll, @._Sep2, '\n')),
						--	IN_WORD_Ull
							CONCAT(TRIM(rt.IN_WORD_Ull), ' '), CONCAT(@._Sep1, rt.IN_WORD_Ull, @._Sep2, ' ')),
							CONCAT(TRIM(rt.IN_WORD_Ull), ','), CONCAT(@._Sep1, rt.IN_WORD_Ull, @._Sep2, ',')),
							CONCAT(TRIM(rt.IN_WORD_Ull), ';'), CONCAT(@._Sep1, rt.IN_WORD_Ull, @._Sep2, ';')),
							CONCAT(TRIM(rt.IN_WORD_Ull), '.'), CONCAT(@._Sep1, rt.IN_WORD_Ull, @._Sep2, '.')),
							CONCAT(TRIM(rt.IN_WORD_Ull), ')'), CONCAT(@._Sep1, rt.IN_WORD_Ull, @._Sep2, ')')),
							CONCAT(TRIM(rt.IN_WORD_Ull), ']'), CONCAT(@._Sep1, rt.IN_WORD_Ull, @._Sep2, ']')),
							CONCAT(TRIM(rt.IN_WORD_Ull), '\r'), CONCAT(@._Sep1, rt.IN_WORD_Ull, @._Sep2, '\r')),
							CONCAT(TRIM(rt.IN_WORD_Ull), '\n'), CONCAT(@._Sep1, rt.IN_WORD_Ull, @._Sep2, '\n'))
							
						*/
					) AS OUT_Text
				FROM `t_IN_repl_out_texts` rt, `t_IN_repl_out_texts_end` tend 
			) AS t 
			ORDER BY ID DESC 
			LIMIT 1
		)
	;
	DROP TEMPORARY TABLE IF EXISTS `t_IN_repl_out_texts`;
	DROP TEMPORARY TABLE IF EXISTS `t_IN_repl_out_texts_end`;
	RETURN @.OUT_Text;
END $$
DELIMITER ;

DELIMITER $$ 
DROP FUNCTION IF EXISTS `_Get_Replace_from_Slowniki_Pierw2`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_Get_Replace_from_Slowniki_Pierw2`(
	_IN_Text VARCHAR(1024), -- MEDIUMTEXT,
	_Slownik_GUID VARCHAR(100),
	-- _Slownik_GUID_1 VARCHAR(100),
	-- _Slownik_GUID_2 VARCHAR(100),
	_Sep1 VARCHAR(100),
	_Sep2 VARCHAR(100)
) RETURNS VARCHAR(65532)
    NO SQL
    DETERMINISTIC
BEGIN
	/*
	SET
		_IN_Text = CONVERT(_IN_Text USING UTF8),
		_Sep1 = CONVERT(_Sep1 USING UTF8),
		_Sep2 = CONVERT(_Sep2 USING UTF8)
	;
	*/
	SET
		@.IN_Text = _IN_Text
	-- 'Elżbieta I ma Oddział warana i Plac wyładunkowy. Ten plac to Plac wyładunkowy a nie Sklep.\nBiuro jest opodal a dalej Stacja paliw i Stacja kolejowa.\nZa rogiem jes Punkt odbioru jeszcze.'
	;
	
	DROP TEMPORARY TABLE IF EXISTS `t_IN_text`;
	CREATE TEMPORARY TABLE `t_IN_text` (
	  `IN_Text` VARCHAR(1024) NOT NULL,
	  `OUT_Text` MEDIUMTEXT,
	  `IN_Sep1` VARCHAR(50) NOT NULL,
	  `IN_Sep2` VARCHAR(50) NOT NULL
	) ENGINE=MYISAM
	;
	INSERT INTO `t_IN_text` SET IN_Text = _IN_Text, OUT_Text = IN_Text, IN_Sep1 = _Sep1, IN_Sep2 = _Sep2 
	;
	DROP TEMPORARY TABLE IF EXISTS `t_IN_repl_out_texts`;
	CREATE TEMPORARY TABLE `t_IN_repl_out_texts` (
	  `IN_WORD` VARCHAR(250) NOT NULL,
	  `IN_WORD_UUU` VARCHAR(250) NOT NULL,
	  `IN_WORD_lll` VARCHAR(250) NOT NULL,
	  `IN_WORD_Ull` VARCHAR(250) NOT NULL,
	  `_Sep1` VARCHAR(50) NOT NULL,
	  `_Sep2` VARCHAR(50) NOT NULL,
	  PRIMARY KEY `IN_WORD`(`IN_WORD`)
	) ENGINE=MYISAM -- DEFAULT CHARSET=UTF8
	;
	INSERT IGNORE INTO `t_IN_repl_out_texts`
	(IN_WORD, IN_WORD_UUU, IN_WORD_lll, IN_WORD_Ull, _Sep1, _Sep2)
		SELECT
			-- CONVERT(sp.DisplayValue USING UTF8),
			-- UCASE(CONVERT(sp.DisplayValue USING UTF8)),
			-- LCASE(CONVERT(sp.DisplayValue USING UTF8)),
			-- _UpperFirst(CONVERT(sp.DisplayValue USING UTF8))
			sp.DisplayValue,
			UCASE(sp.DisplayValue),
			LCASE(sp.DisplayValue),
			_UpperFirst(sp.DisplayValue),
			'<#B#>', 
			'<#E#>'
		FROM `slowniki_pierwotne` sp 
		WHERE
			-- sp.Slownik_GUID IN (_Slownik_GUID_1, _Slownik_GUID_2)
			sp.Slownik_GUID = _Slownik_GUID
			-- AND IFNULL(sp.DisplayValue, '') <> ''
			AND LENGTH(sp.DisplayValue) > 1
		ORDER BY sp.DisplayValue DESC
	;
	
	SET 
		-- @.OUT_Text = @.IN_Text, 
		-- @.OUT_Text = _IN_Text,
		@.OUT_Text = NULL,
		@.I = 0, 
		@._Sep1 = _Sep1, @._Sep2 = _Sep2
	;
	/*
	było
	SET
		@.OUT_Text =
		(
			SELECT 
				t.OUT_Text 
			FROM 
			(
				SELECT
					(@.I := @.I + 1) AS ID,
					(@.IN_Text) AS IN_Text,
					(@.OUT_Text := 
						REPLACE(REPLACE(@.OUT_Text, 
							CONCAT(TRIM(sp.DisplayValue), ' '), CONCAT(_Sep1, sp.DisplayValue, _Sep2)),
							CONCAT(TRIM(sp.DisplayValue), ','), CONCAT(_Sep1, sp.DisplayValue, _Sep2))
					) AS OUT_Text
				FROM `slowniki_pierwotne` sp 
				WHERE
					sp.Slownik_GUID = _Slownik_GUID
			) AS t 
			ORDER BY ID DESC 
			LIMIT 1
		)
	;
	*/
	-- SET @._Sep1 = '<#B#>', @._Sep2 = '<#E#>';
	/*
	SET
		@.OUT_Text =
		(
			SELECT 
				t.OUT_Text 
			FROM 
			(
				SELECT
					(@.I := @.I + 1) AS ID,
					(@.IN_Text) AS IN_Text,
					(@.OUT_Text := 
						REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
						REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
						REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
						REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
							IFNULL(@.OUT_Text, _IN_Text), 
						--	IN_WORD
							CONCAT(TRIM(rt.IN_WORD), ' '), CONCAT(rt._Sep1, rt.IN_WORD, rt._Sep2, ' ')),
							CONCAT(TRIM(rt.IN_WORD), ','), CONCAT(rt._Sep1, rt.IN_WORD, rt._Sep2, ',')),
							CONCAT(TRIM(rt.IN_WORD), ';'), CONCAT(rt._Sep1, rt.IN_WORD, rt._Sep2, ';')),
							CONCAT(TRIM(rt.IN_WORD), '.'), CONCAT(rt._Sep1, rt.IN_WORD, rt._Sep2, '.')),
							CONCAT(TRIM(rt.IN_WORD), ')'), CONCAT(rt._Sep1, rt.IN_WORD, rt._Sep2, ')')),
							CONCAT(TRIM(rt.IN_WORD), ']'), CONCAT(rt._Sep1, rt.IN_WORD, rt._Sep2, ']')),
							CONCAT(TRIM(rt.IN_WORD), '\r'), CONCAT(rt._Sep1, rt.IN_WORD, rt._Sep2, '\r')),
							CONCAT(TRIM(rt.IN_WORD), '\n'), CONCAT(rt._Sep1, rt.IN_WORD, rt._Sep2, '\n')),
						--	IN_WORD_UUU
							CONCAT(TRIM(rt.IN_WORD_UUU), ' '), CONCAT(rt._Sep1, rt.IN_WORD_UUU, rt._Sep2, ' ')),
							CONCAT(TRIM(rt.IN_WORD_UUU), ','), CONCAT(rt._Sep1, rt.IN_WORD_UUU, rt._Sep2, ',')),
							CONCAT(TRIM(rt.IN_WORD_UUU), ';'), CONCAT(rt._Sep1, rt.IN_WORD_UUU, rt._Sep2, ';')),
							CONCAT(TRIM(rt.IN_WORD_UUU), '.'), CONCAT(rt._Sep1, rt.IN_WORD_UUU, rt._Sep2, '.')),
							CONCAT(TRIM(rt.IN_WORD_UUU), ')'), CONCAT(rt._Sep1, rt.IN_WORD_UUU, rt._Sep2, ')')),
							CONCAT(TRIM(rt.IN_WORD_UUU), ']'), CONCAT(rt._Sep1, rt.IN_WORD_UUU, rt._Sep2, ']')),
							CONCAT(TRIM(rt.IN_WORD_UUU), '\r'), CONCAT(rt._Sep1, rt.IN_WORD_UUU, rt._Sep2, '\r')),
							CONCAT(TRIM(rt.IN_WORD_UUU), '\n'), CONCAT(rt._Sep1, rt.IN_WORD_UUU, rt._Sep2, '\n')),
						--	IN_WORD_lll
							CONCAT(TRIM(rt.IN_WORD_lll), ' '), CONCAT(rt._Sep1, rt.IN_WORD_lll, rt._Sep2, ' ')),
							CONCAT(TRIM(rt.IN_WORD_lll), ','), CONCAT(rt._Sep1, rt.IN_WORD_lll, rt._Sep2, ',')),
							CONCAT(TRIM(rt.IN_WORD_lll), ';'), CONCAT(rt._Sep1, rt.IN_WORD_lll, rt._Sep2, ';')),
							CONCAT(TRIM(rt.IN_WORD_lll), '.'), CONCAT(rt._Sep1, rt.IN_WORD_lll, rt._Sep2, '.')),
							CONCAT(TRIM(rt.IN_WORD_lll), ')'), CONCAT(rt._Sep1, rt.IN_WORD_lll, rt._Sep2, ')')),
							CONCAT(TRIM(rt.IN_WORD_lll), ']'), CONCAT(rt._Sep1, rt.IN_WORD_lll, rt._Sep2, ']')),
							CONCAT(TRIM(rt.IN_WORD_lll), '\r'), CONCAT(rt._Sep1, rt.IN_WORD_lll, rt._Sep2, '\r')),
							CONCAT(TRIM(rt.IN_WORD_lll), '\n'), CONCAT(rt._Sep1, rt.IN_WORD_lll, rt._Sep2, '\n')),
						--	IN_WORD_Ull
							CONCAT(TRIM(rt.IN_WORD_Ull), ' '), CONCAT(rt._Sep1, rt.IN_WORD_Ull, rt._Sep2, ' ')),
							CONCAT(TRIM(rt.IN_WORD_Ull), ','), CONCAT(rt._Sep1, rt.IN_WORD_Ull, rt._Sep2, ',')),
							CONCAT(TRIM(rt.IN_WORD_Ull), ';'), CONCAT(rt._Sep1, rt.IN_WORD_Ull, rt._Sep2, ';')),
							CONCAT(TRIM(rt.IN_WORD_Ull), '.'), CONCAT(rt._Sep1, rt.IN_WORD_Ull, rt._Sep2, '.')),
							CONCAT(TRIM(rt.IN_WORD_Ull), ')'), CONCAT(rt._Sep1, rt.IN_WORD_Ull, rt._Sep2, ')')),
							CONCAT(TRIM(rt.IN_WORD_Ull), ']'), CONCAT(rt._Sep1, rt.IN_WORD_Ull, rt._Sep2, ']')),
							CONCAT(TRIM(rt.IN_WORD_Ull), '\r'), CONCAT(rt._Sep1, rt.IN_WORD_Ull, rt._Sep2, '\r')),
							CONCAT(TRIM(rt.IN_WORD_Ull), '\n'), CONCAT(rt._Sep1, rt.IN_WORD_Ull, rt._Sep2, '\n'))
					) AS OUT_Text
				FROM `t_IN_repl_out_texts` rt
			) AS t 
			ORDER BY ID DESC 
			LIMIT 1
		)
	;
	*/
	SET @.OUT_Text = NULL;
	UPDATE `t_IN_text` tout, `t_IN_repl_out_texts` rt
	SET
		tout.OUT_Text := (@.OUT_Text := 
			REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
			REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
			REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
			REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
				IFNULL(@.OUT_Text, tout.OUT_Text), 
			--	IN_WORD
				CONCAT(TRIM(rt.IN_WORD), ' '), CONCAT(rt._Sep1, rt.IN_WORD, rt._Sep2, ' ')),
				CONCAT(TRIM(rt.IN_WORD), ','), CONCAT(rt._Sep1, rt.IN_WORD, rt._Sep2, ',')),
				CONCAT(TRIM(rt.IN_WORD), ';'), CONCAT(rt._Sep1, rt.IN_WORD, rt._Sep2, ';')),
				CONCAT(TRIM(rt.IN_WORD), '.'), CONCAT(rt._Sep1, rt.IN_WORD, rt._Sep2, '.')),
				CONCAT(TRIM(rt.IN_WORD), ')'), CONCAT(rt._Sep1, rt.IN_WORD, rt._Sep2, ')')),
				CONCAT(TRIM(rt.IN_WORD), ']'), CONCAT(rt._Sep1, rt.IN_WORD, rt._Sep2, ']')),
				CONCAT(TRIM(rt.IN_WORD), '\r'), CONCAT(rt._Sep1, rt.IN_WORD, rt._Sep2, '\r')),
				CONCAT(TRIM(rt.IN_WORD), '\n'), CONCAT(rt._Sep1, rt.IN_WORD, rt._Sep2, '\n')),
			--	IN_WORD_UUU
				CONCAT(TRIM(rt.IN_WORD_UUU), ' '), CONCAT(rt._Sep1, rt.IN_WORD_UUU, rt._Sep2, ' ')),
				CONCAT(TRIM(rt.IN_WORD_UUU), ','), CONCAT(rt._Sep1, rt.IN_WORD_UUU, rt._Sep2, ',')),
				CONCAT(TRIM(rt.IN_WORD_UUU), ';'), CONCAT(rt._Sep1, rt.IN_WORD_UUU, rt._Sep2, ';')),
				CONCAT(TRIM(rt.IN_WORD_UUU), '.'), CONCAT(rt._Sep1, rt.IN_WORD_UUU, rt._Sep2, '.')),
				CONCAT(TRIM(rt.IN_WORD_UUU), ')'), CONCAT(rt._Sep1, rt.IN_WORD_UUU, rt._Sep2, ')')),
				CONCAT(TRIM(rt.IN_WORD_UUU), ']'), CONCAT(rt._Sep1, rt.IN_WORD_UUU, rt._Sep2, ']')),
				CONCAT(TRIM(rt.IN_WORD_UUU), '\r'), CONCAT(rt._Sep1, rt.IN_WORD_UUU, rt._Sep2, '\r')),
				CONCAT(TRIM(rt.IN_WORD_UUU), '\n'), CONCAT(rt._Sep1, rt.IN_WORD_UUU, rt._Sep2, '\n')),
			--	IN_WORD_lll
				CONCAT(TRIM(rt.IN_WORD_lll), ' '), CONCAT(rt._Sep1, rt.IN_WORD_lll, rt._Sep2, ' ')),
				CONCAT(TRIM(rt.IN_WORD_lll), ','), CONCAT(rt._Sep1, rt.IN_WORD_lll, rt._Sep2, ',')),
				CONCAT(TRIM(rt.IN_WORD_lll), ';'), CONCAT(rt._Sep1, rt.IN_WORD_lll, rt._Sep2, ';')),
				CONCAT(TRIM(rt.IN_WORD_lll), '.'), CONCAT(rt._Sep1, rt.IN_WORD_lll, rt._Sep2, '.')),
				CONCAT(TRIM(rt.IN_WORD_lll), ')'), CONCAT(rt._Sep1, rt.IN_WORD_lll, rt._Sep2, ')')),
				CONCAT(TRIM(rt.IN_WORD_lll), ']'), CONCAT(rt._Sep1, rt.IN_WORD_lll, rt._Sep2, ']')),
				CONCAT(TRIM(rt.IN_WORD_lll), '\r'), CONCAT(rt._Sep1, rt.IN_WORD_lll, rt._Sep2, '\r')),
				CONCAT(TRIM(rt.IN_WORD_lll), '\n'), CONCAT(rt._Sep1, rt.IN_WORD_lll, rt._Sep2, '\n')),
			--	IN_WORD_Ull
				CONCAT(TRIM(rt.IN_WORD_Ull), ' '), CONCAT(rt._Sep1, rt.IN_WORD_Ull, rt._Sep2, ' ')),
				CONCAT(TRIM(rt.IN_WORD_Ull), ','), CONCAT(rt._Sep1, rt.IN_WORD_Ull, rt._Sep2, ',')),
				CONCAT(TRIM(rt.IN_WORD_Ull), ';'), CONCAT(rt._Sep1, rt.IN_WORD_Ull, rt._Sep2, ';')),
				CONCAT(TRIM(rt.IN_WORD_Ull), '.'), CONCAT(rt._Sep1, rt.IN_WORD_Ull, rt._Sep2, '.')),
				CONCAT(TRIM(rt.IN_WORD_Ull), ')'), CONCAT(rt._Sep1, rt.IN_WORD_Ull, rt._Sep2, ')')),
				CONCAT(TRIM(rt.IN_WORD_Ull), ']'), CONCAT(rt._Sep1, rt.IN_WORD_Ull, rt._Sep2, ']')),
				CONCAT(TRIM(rt.IN_WORD_Ull), '\r'), CONCAT(rt._Sep1, rt.IN_WORD_Ull, rt._Sep2, '\r')),
				CONCAT(TRIM(rt.IN_WORD_Ull), '\n'), CONCAT(rt._Sep1, rt.IN_WORD_Ull, rt._Sep2, '\n'))
		)
	;

	
	UPDATE `t_IN_text` tout
	SET
		OUT_Text = (@.OUT_Text := REPLACE(REPLACE(tout.OUT_Text, '<#B#>', tout.IN_Sep1), '<#E#>', tout.IN_Sep2))
	;
	-- SET @.OUT_Text = REPLACE(REPLACE(@.OUT_Text, @._Sep1, _Sep1), @._Sep2, _Sep2);
	-- DROP TEMPORARY TABLE IF EXISTS `t_IN_repl_out_texts`;
	RETURN @.OUT_Text;
END $$

DROP FUNCTION IF EXISTS _sys_browsers_col_to_html$$
CREATE DEFINER=`root`@`localhost` FUNCTION _sys_browsers_col_to_html(_Value VARCHAR(38)) RETURNS VARCHAR(38)
    NO SQL
    DETERMINISTIC
BEGIN
  RETURN (CASE
    WHEN _Value = 'Str' THEN 'text'
    WHEN _Value = 'Int' THEN 'number'
    WHEN _Value = 'Bool' THEN 'checkbox'
    WHEN _Value = 'Date' THEN 'date'
    WHEN _Value = 'DateTime' THEN 'datetime'
    WHEN _Value = 'none' THEN 'richText'
    WHEN _Value = 'Blob' THEN 'file'
    WHEN _Value = 'float' THEN 'number'
    ELSE  _Value
  END);
END $$

DROP FUNCTION IF EXISTS `_SQL_FMT_Stat`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_SQL_FMT_Stat`(
	_MODE VARCHAR(200),
	_Template VARCHAR(200),
	_KeyWord VARCHAR(200),
	_Pre VARCHAR(50),
	_Value TEXT,
	_ValueTab BOOLEAN,
	_Post VARCHAR(50),
	-- _ShowComment BOOLEAN,
	_ValueIfNULL VARCHAR(256)
) RETURNS TEXT -- VARCHAR(1020)
	NO SQL
	DETERMINISTIC
BEGIN
	IF _MODE = 'RESET' OR @.SQL.FS.Default1 IS NULL THEN 
		SET
			@.SQL.FS.Default1 = 		'/*** #COMMENT# ***/\n#CONTENT#',
			@.SQL.FS.Default2 = 		'/*** #COMMENT# ***/\n#PRE##CONTENT##POST#',
			@.SQL.FS.FROM =	 			'/*** FROM ***/\n#PRE##CONTENT##POST#',
			@.SQL.FS.JOIN =	 			'/*** JOIN ***/\n#PRE##CONTENT##POST#',
			@.SQL.FS.WHERE 	= 			'/*** WHERE ***/\nWHERE\n#PRE##CONTENT##POST#',
			@.SQL.FS.WHERE.S =	 		'/*** WHERE staly browsera ***/\n#PRE##CONTENT##POST#',
			@.SQL.FS.WHERE.S.ADD =		'/*** WHERE alternatywny browsera dodatkowy ***/\n#PRE##CONTENT##POST#',
			@.SQL.FS.WHERE.V =	 		'/*** WHERE alternatywny aktualnego widoku ***/\n#PRE##CONTENT##POST#',
			@.SQL.FS.WHERE.P =	 		'/*** WHERE alternatywny filtrow ***/\n#PRE##CONTENT##POST#',
			@.SQL.FS.WHERE.Key = 		'/*** WHERE dla refresh Key ***/\n#PRE##CONTENT##POST#',
			@.SQL.FS.WHERE.MaxTime =	'/*** WHERE dla refresh time ***/\n#PRE##CONTENT##POST#',
			
			@.SQL.FS.GROUP =			'\n#KeyWord# #CONTENT#',
			@.SQL.FS.HAVING = 			'\n/*** HAVING ***/\n#KeyWord# #PRE##CONTENT##POST#',
			@.SQL.FS.ORDER =			'\n#KeyWord# #CONTENT#',
			
			@.SQL.FS.Ext1 = ',\n/*** Pole REC_OK gdy tryb refresh key lub refresh time ***/\n#(##PRE##CONTENT##POST##)# AS REC_OK',
			@.SQL.FS.Ext2 = '/*** COMMENT ***/\n',
			@.SQL.FS.LIMIT =			'\n#CONTENT#',
			@.SQL.FS.Empty =		'#CONTENT#'
		;
		RETURN 'OK';
	END IF;
	IF _MODE IN ('', 'FMT') THEN
		SET 
			@._Value.IS.NULL = (@._Value := NULLIF(_Value, '')) IS NULL
		;
		IF IFNULL(@._Value, '') = '' THEN
			SET @._SQL_FMT_Stat = IFNULL(@._Value, _ValueIfNULL);
		ELSE
			SET
				@.Value.has.1.Line = LOCATE('\n', @._Value) = 0
			;	
			SET 
				@.TAB = 
					_ValueTab = 1 OR 
					_ValueTab = 2 AND NOT @.Value.has.1.Line 
				-- @._Comment = _Comment
			; 
			SET 
				@._Value = 
				IF(@.TAB,
					CONCAT('\t', REPLACE(_Value, '\n', '\n\t')),
					_Value
				)
			;
			SET @._SQL_FMT_Stat = 
				REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(_Template,
					-- '#COMMENT#', _Comment),
					'#KeyWord#\n', CONCAT(_KeyWord, '\n')),
					'#KeyWord#', CONCAT(_KeyWord, IF(@.Value.has.1.Line, '', '\n'))),
					'#(#', IF(@.Value.has.1.Line, '(', '(\n')),
					'#)#', IF(@.Value.has.1.Line, ')', '\n)')),
					'#PRE#', _Pre),
					'#CONTENT#', @._Value),
					'#POST#', _Post)
			;		
		END IF;
		RETURN @._SQL_FMT_Stat;
	END IF;
END $$		

DROP FUNCTION IF EXISTS `_VerFmtStr`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_VerFmtStr`(
	_MODE VARCHAR(200),
	_Ver VARCHAR(256),	-- wej. 1
	_vN1 VARCHAR(20), 
	_vN2 VARCHAR(20), 
	_vN3 VARCHAR(20), 
	_vN4 VARCHAR(20)
) RETURNS VARCHAR(256)
    NO SQL
    DETERMINISTIC
BEGIN
	/*
	_MODE
	GET.[vN[1|2|3|4]]|[Ver]<-[Ver|vN]
	czyli
		GET.vN1<-vN		zwraca 1 cz. z wersji utworzonej z _VN1..4
		GET.vN2<-vN		zwraca 2 cz. z wersji utworzonej z _VN1..4
		GET.Ver<-vN		zwraca cały num. wersji z wersji utworzonej z _VN1..4
		GET.vN1<-Ver	zwraca 1 cz. z wersji konwert. z _Ver
		GET.vN2<-Ver	zwraca 2 cz. z wersji konwert. z _Ver
		GET.Ver<-Ver	zwraca cały num. wersji konwert. z _Ver
	*/
	-- IF IFNULL(_VerA, '') <> '' THEN
	IF _MODE LIKE '%<-Ver%' OR _MODE LIKE 'Cmp.%' THEN
		SET
			@.Fmt.Ver := CONCAT(_Ver, '...'),
			@.Fmt.vN1 := LPAD(RIGHT(SUBSTRING_INDEX(SUBSTRING_INDEX(@.Fmt.Ver, '.', 1), '.', -1), 4), 4, '0'),
			@.Fmt.vN2 := LPAD(RIGHT(SUBSTRING_INDEX(SUBSTRING_INDEX(@.Fmt.Ver, '.', 2), '.', -1), 4), 2, '0'),
			@.Fmt.vN3 := LPAD(RIGHT(SUBSTRING_INDEX(SUBSTRING_INDEX(@.Fmt.Ver, '.', 3), '.', -1), 4), 2, '0'),
			@.Fmt.vN4 := RIGHT(SUBSTRING_INDEX(SUBSTRING_INDEX(@.Fmt.Ver, '.', 4), '.', -1), 4)
		;
	END IF;
	IF _MODE LIKE '%<-vN%' THEN
		SET
			@.Fmt.vN1 := _vN1,
			@.Fmt.vN2 := _vN2,
			@.Fmt.vN3 := _vN3,
			@.Fmt.vN4 := _vN4
		;
	END IF;
	
	IF _MODE LIKE 'GET.vN%' THEN
		RETURN 
			IF(_MODE LIKE 'GET.vN1%', 
				@.Fmt.vN1,
				IF(_MODE LIKE 'GET.vN2%', 
					@.Fmt.vN2,
					IF(_MODE LIKE 'GET.vN3%', 
						@.Fmt.vN3,
						@.Fmt.vN4
					)
				)
			)
		;
	END IF;
	
	IF _MODE LIKE 'GET.Ver%' THEN
		RETURN 
			CONCAT_WS('.', @.Fmt.vN1, @.Fmt.vN2, @.Fmt.vN3, NULLIF(@.Fmt.vN4, ''))
		;
	END IF;
	
	IF _MODE LIKE 'Cmp.%' THEN
		RETURN
			@.Fmt.vN1 > _vN1
			AND
			@.Fmt.vN2 > _vN2
			AND
			@.Fmt.vN3 > _vN3
			AND
			@.Fmt.vN4 > _vN4
		;
	END IF;
END $$

/*
SELECT _PasswdGen(10);
*/


DROP FUNCTION IF EXISTS _PasswdGen $$
CREATE DEFINER='root'@'localhost' FUNCTION _PasswdGen (_LEN INT) RETURNS VARCHAR(30)
	NO SQL
	DETERMINISTIC
BEGIN
	SET @_SpecialChars='@#$%*!';
	SET @_Char=MID(@_SpecialChars,FLOOR(1 + RAND() * CHAR_LENGTH(@_SpecialChars)),1);
	SET @_POS=FLOOR(1 + RAND() * _LEN);
	SET @pass=LPAD(LEFT(REPLACE(REPLACE(REPLACE(TO_BASE64(UNHEX(MD5(RAND()))), "/", ""), "+", ""), "=", ""), _LEN), _LEN, 0);
	SET @pass=INSERT(@pass, @_POS, 1, @_Char);
	RETURN @pass;
END $$

-- TK: funkcja konwertujaca znaki zakazane w xml na odpowiedniki jedynie sluszne
-- moze warto tam tez dodac biale znaki, o ile nie sa wywalane przez trim
DROP FUNCTION IF EXISTS _escape_to_xml $$
CREATE  DEFINER='root'@'localhost' FUNCTION _escape_to_xml(input_str TEXT)
RETURNS TEXT DETERMINISTIC
BEGIN
    DECLARE output_str TEXT;
    SET output_str = REPLACE(input_str,  '&', '&amp;');
    SET output_str = REPLACE(output_str, '<', '&lt;');
    SET output_str = REPLACE(output_str, '>', '&gt;');
    SET output_str = REPLACE(output_str, '"', '&quot;');
    SET output_str = REPLACE(output_str, "'", '&apos;');
    RETURN output_str;
END $$
DELIMITER ; 

DELIMITER $$
DROP FUNCTION IF EXISTS `ToDoF5`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `ToDoF5`(
	_MODE VARCHAR(250),
	_weFlags VARCHAR(200),
	_F1 VARCHAR(50),
	_F2 VARCHAR(50),
	_F3 VARCHAR(50),
	_F4 VARCHAR(50),
	_F5 VARCHAR(50)
	
) RETURNS VARCHAR(200)
	DETERMINISTIC
L_EXIT: BEGIN
    IF _MODE = 'ADD' THEN
    /*
        Set @.rc := ToDoF5('ADD', NEW.ToDo, '[PxD<-]', '', '', '', ''); 
    */
        IF IFNULL(_F1, '') <> '' THEN
            SET _weFlags := CONCAT_WS('', REPLACE(_weFlags, _F1, ''), _F1);
        END IF;
        IF IFNULL(_F2, '') <> '' THEN
            SET _weFlags := CONCAT_WS('', REPLACE(_weFlags, _F2, ''), _F2);
        END IF;
        IF IFNULL(_F3, '') <> '' THEN
            SET _weFlags := CONCAT_WS('', REPLACE(_weFlags, _F3, ''), _F3);
        END IF;
        IF IFNULL(_F4, '') <> '' THEN
            SET _weFlags := CONCAT_WS('', REPLACE(_weFlags, _F4, ''), _F4);
        END IF;
        IF IFNULL(_F5, '') <> '' THEN
            SET _weFlags := CONCAT_WS('', REPLACE(_weFlags, _F5, ''), _F5);
        END IF;
        SET @.ToDoF.Return := _weFlags;
    END IF;
    IF _MODE = 'DEL' THEN
    /*
        Set @.rc := ToDoF5('DEL', NEW.ToDo, '[PxD<-]', '', '', '', ''); 
    */
        IF IFNULL(_F1, '') <> '' THEN
            SET _weFlags := REPLACE(_weFlags, _F1, '');
        END IF;
        IF IFNULL(_F2, '') <> '' THEN
            SET _weFlags := REPLACE(_weFlags, _F2, '');
        END IF;
        IF IFNULL(_F3, '') <> '' THEN
            SET _weFlags := REPLACE(_weFlags, _F3, '');
        END IF;
        IF IFNULL(_F4, '') <> '' THEN
            SET _weFlags := REPLACE(_weFlags, _F4, '');
        END IF;
        IF IFNULL(_F5, '') <> '' THEN
            SET _weFlags := REPLACE(_weFlags, _F5, '');
        END IF;
        SET @.ToDoF.Return := _weFlags;
    END IF;
    IF _MODE = 'Exists1' THEN
    /*
        Set @.rc := ToDoF5('Exists1', NEW.ToDo, '[PxD<-]', '', '', '', ''); 
    */
        SET @.ToDoF.Return := (LOCATE(_F1, _weFlags) > 0);
    END IF;
    IF _MODE = 'ExistsAny' THEN
    /*
        Set @.rc := ToDoF5('ExistsAny', 'Hej[Ala][PxD<-][Ela]', '[xxx]', '', '[Ela]', '', ''); 
    */
        SET @.ToDoF.Return := FALSE; 
        IF NOT @.ToDoF.Return AND IFNULL(_F1, '') <> '' THEN
            SET @.ToDoF.Return := (LOCATE(_F1, _weFlags) > 0);
        END IF;
        IF NOT @.ToDoF.Return AND IFNULL(_F2, '') <> '' THEN
            SET @.ToDoF.Return := (LOCATE(_F2, _weFlags) > 0);
        END IF;
        IF NOT @.ToDoF.Return AND IFNULL(_F3, '') <> '' THEN
            SET @.ToDoF.Return := (LOCATE(_F3, _weFlags) > 0);
        END IF;
        IF NOT @.ToDoF.Return AND IFNULL(_F4, '') <> '' THEN
            SET @.ToDoF.Return := (LOCATE(_F4, _weFlags) > 0);
        END IF;
        IF NOT @.ToDoF.Return AND IFNULL(_F5, '') <> '' THEN
            SET @.ToDoF.Return := (LOCATE(_F5, _weFlags) > 0);
        END IF;
    END IF;
    IF _MODE IN ('Was.Del.1', 'Was.Exists1') THEN
    /*
        Uwaga tu mamy NEW i OLD i spr. czy był w OLD i nie ma w NEW
        Set @.rc := ToDoF5('Was.Del.1', NEW.ToDo, OLD.ToDo, '[PxD<-]', '', '', '', ''); 
        _weFlags    NEW
        _F1         OLD
        _F2         szukana fraza
    */
        SET @.ToDoF.Return := 
            _F1 IS NOT NULL
            AND
            _F2 IS NOT NULL
            AND
        --  Istnieje w OLD
            LOCATE(_F2, _F1) > 0
            AND
        --  i nie istnieje w NEW
            LOCATE(_F2, IFNULL(_weFlags, '')) = 0
        ;
    END IF;
    
    RETURN @.ToDoF.Return;
END;
$$
DELIMITER ;

/*
$Log: _varSTR.sql,v $
Revision 1.109  2026/06/23 14:50:41  jmam
modyf. Fetch + ToDoF5

Revision 1.108  2026/05/11 09:58:55  jmam
Poprawki syntakt. $send$

Revision 1.107  2026/05/11 09:18:01  jmam
Poprawki syntakt.

Revision 1.106  2026/01/16 09:15:05  jmam
stan na 16 I 2026 $send$

Revision 1.105  2026/01/16 09:13:01  jmam
_varSTR_1_N_Fleks_Liczebn + FlagsSet do plac 2025

Revision 1.104  2026/01/16 07:07:59  waliant
$SEND$ _escape_to_xml

Revision 1.103  2025/08/10 12:18:35  apro
popr. długosci hasla

Revision 1.102  2025/08/10 12:10:14  apro
$SEND$
_PasswdGen

Revision 1.101  2025/06/30 10:35:10  jmam
$SEND$ SetTypeV + _Delimit + regexp_replace_ver

Revision 1.100  2025/03/31 13:11:25  jmam
$send$ dodanie _FetchPar

Revision 1.99  2025/02/19 12:51:51  jmam
$send$ regexp_replace_ jako wariantowa zalezna od wersji MySQL/MariaDB

Revision 1.98  2025/02/14 11:59:06  apro
kosmetyka

Revision 1.97  2024/05/27 16:10:07  jmam
Nr rach. bank.2 $SEND$

Revision 1.96  2024/05/27 15:58:39  jmam
Nr rach. bank. $SEND$

Revision 1.95  2023/06/12 12:08:11  jmam
$SEND$  func. do wersji exe

Revision 1.94  2023/02/08 07:18:27  jmam
$SEND$ Values w Params

Revision 1.93  2023/01/23 10:47:43  jmam
$SEND$ funkc. _Concat_OLD_NEW_Memo_LOG

Revision 1.91  2022/11/08 08:34:34  jmam
$SEND$

Revision 1.90  2022/04/25 11:03:30  rafalg
kolejny znak w xml to utf

Revision 1.89  2022/04/11 08:47:43  waliant
Wylaczenie konwersji znaczka & w ...to_xml $SEND$

Revision 1.88  2022/03/28 09:37:48  waliant
Poprawka bledu w sekcji to_xml $SEND$

Revision 1.87  2022/03/15 10:40:59  waliant
Po naprawie $SEND$

Revision 1.86  2022/03/15 10:36:21  jmam
no message

Revision 1.82  2022/02/28 18:12:36  jmam
$SEND$

Revision 1.81  2022/02/10 11:59:20  jmam
$SEND$ - zmiany II 2022

Revision 1.80  2022/02/01 14:51:16  jmam
$SEND$ - funk. do SQL i znak?sg, dla Window

Revision 1.79  2022/01/04 13:44:54  waliant
Wylaczenie replace na znaku & $SEND$

Revision 1.78  2021/10/07 13:14:19  jmam
$SEND$

Revision 1.77  2021/09/30 12:53:21  apro
_sys_browsers_col_to_html
$SEND$

Revision 1.76  2021/09/22 08:27:48  waliant
utf to xml - ampersand $SEND$

Revision 1.75  2021/09/21 09:19:07  rafalg
kolejny znak w utftoxml

Revision 1.74  2021/09/02 09:29:16  rafalg
zmiana foramtowania
$SEND$

Revision 1.73  2021/09/02 09:27:42  rafalg
zmiana foramtowania
$SEND$

Revision 1.72  2021/09/01 15:25:45  rafalg
znak
$SEND$

Revision 1.71  2021/09/01 15:20:11  rafalg
poprawka kodowania

Revision 1.70  2021/08/25 13:32:31  waliant
Kolejny znak do przekodowania dla xml $SEND$

Revision 1.69  2021/08/25 10:08:33  rafalg
no message

Revision 1.68  2021/08/19 18:46:59  jmam
$SEND$

Revision 1.67  2021/08/19 12:09:30  waliant
Uzupełnienie przekodowania utf_to_xml $SEND$

Revision 1.66  2021/06/24 07:40:53  rafalg
kolejny znak w to_utf_xml

Revision 1.65  2021/06/21 13:54:25  jmam
$SEND$

Revision 1.64  2021/05/06 11:45:14  jmam
$SEND$

Revision 1.63  2021/05/05 13:04:00  rafalg
poprawka
$SEND$

Revision 1.62  2021/04/26 08:12:25  jmam
$SEND$

Revision 1.61  2021/04/26 08:10:25  jmam
$SEND$

Revision 1.60  2021/04/23 12:28:34  rafalg
to_utf_xml - kolejna porcja znakow

Revision 1.59  2021/04/23 10:25:44  rafalg
to_utf_xml - kolejna porcja znakow

Revision 1.58  2021/04/19 16:29:46  jmam
$SEND$

Revision 1.57  2021/04/16 08:52:59  jmam
$SEND$

Revision 1.56  2021/04/15 16:43:39  jmam
$SEND$

Revision 1.55  2021/04/12 13:47:23  jmam
$SEND$

Revision 1.54  2021/04/07 13:10:34  jmam
$SEND$

Revision 1.53  2021/03/22 12:00:05  jmam
$SEND$

Revision 1.52  2021/03/09 09:30:39  jmam
$SEND$

Revision 1.51  2021/01/22 08:10:23  rafalg
uzupelnienie  _to_utf_xml

Revision 1.50  2021/01/17 20:28:42  jmam
$SEND$

Revision 1.49  2020/11/26 13:43:40  jmam
$SEND$

Revision 1.48  2020/11/25 10:08:40  rafalg
dodanie nowych znakow w _to_utf_xml

Revision 1.47  2020/11/20 13:52:23  rafalg
poprawka to_utf_xml
$SEND$

Revision 1.46  2020/11/17 11:22:28  waliant
Niemieckie litery w funkcji _to_utf_xml $SEND$

Revision 1.45  2020/09/15 07:09:47  jmam
$SEND$

Revision 1.44  2020/02/19 10:06:57  apro
*** empty log message ***

Revision 1.43  2019/09/16 08:34:45  jmam
$SEND$

Revision 1.42  2019/08/08 12:29:37  jmam
$SEND$

Revision 1.41  2019/06/07 06:15:05  apro
utf_xml

Revision 1.40  2019/05/30 11:29:05  apro
$SEND$

*/
