-- ZROBIÄ† NA SAMYM POCZATKU!!!!

DELIMITER $$

DROP PROCEDURE IF EXISTS `_sys_db_logons_Tools`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `_sys_db_logons_Tools`(
	IN _MODE VARCHAR(250), 
	IN _GUID VARCHAR(38),
	IN _CONNECTION_ID INTEGER,
	IN _Param_A VARCHAR(200),
	IN _Param_B VARCHAR(200),
	IN _Param_C VARCHAR(200),
	IN _Param_D VARCHAR(200),
	IN _Param_E VARCHAR(200),
	IN _Param_F VARCHAR(200),
	IN _Param_G VARCHAR(200)
)
S__sys_db_logons_Tools: BEGIN

	DECLARE _SQLText MEDIUMTEXT; 

	DO _Birth_System();	--	aby miec m.in. @session.globals.INPUT_SALT_Hash
	
	IF _MODE = 'INSERT' THEN
			DO _counters_tools('INC', CONCAT('_sys_db_logons_Tools: ', _MODE, ':', @session.LOGON.Ver), '', '');		-- to tylko Licznik!!!!
	/*
		Czy ten mode w ogole cos wola ????????????????
		Nowa sesja
		CALL _sys_db_logons_Tools('INSERT', '', 0, 'select', 'WWW', '', '', '', '', '');
		lub
		CALL _sys_db_logons_Tools('INSERT', @_GUID, 0, 'select', 'WWW', '', '', '', '', '');
		Zwrotnie dostajemy wszystkie kolumny tabeli `_sys_db_logons` w ktÄ‚Ĺ‚rej jest `GUID` MUSIMY go ZAPAMIĂ„ÂTAĂ„â€ !
		CALL _sys_db_logons_Tools('INSERT',NULL, 0, 'select', 'Kind=EXE&log_HOST=192.168.67.33&log_HOST_NAME=HP_TEST&log_MACADDRESS=AC-16-2D-47-52-D7&log_APPNAME=HT2003&', '', '', '', '', '');
		_Param_A	'select'
		_Param_B	sznurek
	*/
		/* */
		SET @Params = CONCAT_WS('&', '<select>', _Param_B);
		CALL _sessions_APP('NEW', _GUID, '', '', '', '', @Params);
		LEAVE S__sys_db_logons_Tools;
		/* */

		SET _CONNECTION_ID = IF(IFNULL(_CONNECTION_ID, 0) = 0, CONNECTION_ID(), _CONNECTION_ID);
		SET _GUID = UUID();
		SET @_GUID = _GUID;
		CALL _sys_db_logons_rec_tools('INSERT', _GUID, 0, _Param_A, _Param_B, _Param_C, _Param_D, _Param_E);
		IF _Param_A = 'select' THEN
			SELECT * FROM `_sys_db_logons` WHERE GUID = _GUID;
		END IF;
	END IF;
	
	
	IF _MODE IN ('GLOBUSIK') THEN
	
		UPDATE `_sys_db_logons` sdl
		SET
			sdl.STATUS = 'ACTIVE'
		WHERE
			sdl.GUID = _GUID
			AND sdl.STATUS LIKE 'CLOSE%'
			AND sdl.CONNECT_AT > (NOW() - INTERVAL 2 DAY)
		;
	END IF;
	
	IF _MODE IN ('LOG ON') THEN
			DO _counters_tools('INC', CONCAT('_sys_db_logons_Tools: ', _MODE, ':', @session.LOGON.Ver), '', '');		-- to tylko Licznik!!!!
	/*
		Zalogowanie prawidlowe/bledne
		CALL _sys_db_logons_Tools('LOG ON', @_SESSION_GUID, 0, 'select', '', @_INPUT_LOGIN_Hash, @_INPUT_Datas_Hash, @_INPUT_MACADDRESS_Hash, 'M.WEB.ScanPack', '');

		Zalogowanie prawidlowe/bledne
		CALL _sys_db_logons_Tools('LOG ON', @_SESSION_GUID, 0, 'select', '', @_INPUT_LOGIN_Hash, @_INPUT_Datas_Hash, @_INPUT_MACADDRESS_Hash, 'M.WEB.ScanPack', '');
		CALL _sys_db_logons_Tools('LOG ON.TEST', '39033242-5cc4-11eb-9347-00215e4eee26', 0, 'select', '', 
			MD5(CONCAT('28825d161c6ba55a849ad21b0dfbfee6',@SYSTEM.Client.Session.GUID,
			MD5('jmam'))), MD5(CONCAT('28825d161c6ba55a849ad21b0dfbfee6',@SYSTEM.Client.Session.GUID,
			MD5('pr3z3s$'))), MD5(CONCAT('28825d161c6ba55a849ad21b0dfbfee6',@SYSTEM.Client.Session.GUID,
			MD5('AC-16-2D-47-52-D7'))), 'M.EXE.HT2003', ''
		);
		CALL _sys_db_logons_Tools('LOG ON', '3765e432-9f98-11ec-9613-00155d000205', 0, 
			'select', 
			'', 
			MD5(CONCAT('X','3765e432-9f98-11ec-9613-00155d000205',MD5('kmozoluk'))), MD5(CONCAT('X','3765e432-9f98-11ec-9613-00155d000205',MD5('@koszalkowo@'))), MD5(CONCAT('X','3765e432-9f98-11ec-9613-00155d000205',MD5('AC-16-2D-47-52-D7'))), 'M.EXE.HT2003', '')
		_Param_A	'select'	
		_Param_B				PUSTY
		_Param_C	login#		md5
		_Param_D	Pswd#		md5
		_Param_E	McAddr#		i to akurat jest bez sensu bo nie potrzebujemy jasz adresu!??
		_Param_F	AppID		jawne
		_Param_G				PUSTY
	*/
	IF 
	@session.LOGON.Ver < '2.15'  -- OR TRUE
	/********************************************************************************************************
		Starsze czyli do sty. 2021 r.
		IF _MODE IN ('CHECK', 'CHECK.Connection') THEN
	********************************************************************************************************/
	THEN	-- @session.LOGON.Ver < 2.15	
	--	WoÄąâ€šanie protezy - _TEST_sys_db_logons_Tools to to samo co _sys_db_logons_Tools ale wewn. woÄąâ€ša nowe >= 2022
		/* 
		CALL _TEST_sys_db_logons_Tools(
			_MODE, _GUID, _CONNECTION_ID, _Param_A, _Param_B, _Param_C, _Param_D, _Param_E, _Param_F, _Param_G
		);
		LEAVE S__sys_db_logons_Tools;
		*/
		CALL _auth_bypass('_sys_db_logons_Tools', 'LOG ON', 
			_GUID,	-- @_SESSION_GUID 
			'select', '', 
			_Param_C,	-- @_INPUT_LOGIN_Hash, 
			_Param_D,	-- @_INPUT_Datas_Hash, 
			_Param_E,	-- @_INPUT_MACADDRESS_Hash, 
			_Param_F, 
			_Param_G
		);
		LEAVE S__sys_db_logons_Tools;
		IF 
			_Param_F IS NOT NULL 
		AND 
			IFNULL((SELECT a.Disabled FROM `_sys_app_reg` a WHERE a.ID = _Param_F), 0) = 1
		/*
		IF 
			_Param_F = 'M.EXE.PL2003'
		AND 
			IFNULL((SELECT  `Value` FROM `_db_globals` WHERE `key` = 'blokada.PL2023'), 0) = 1
		*/
		THEN
			UPDATE `_sys_db_logons` l
			SET
				l.LAST_MSG = (@.auth.Final.Verify_Status := 'Nieaktualna wersja aplikacji, proszĂ„â„˘ uÄąÄ˝yĂ„â€ˇ nowej wersji!')	-- waÄąÄ˝na maÄąâ€špa!!!
				-- , l.Inactive = 1 
			WHERE 
				l.GUID = _GUID
			;
			SELECT 
				l.GUID, l.log_USER, l.log_USER_GUID, l.LAST_MSG, l.STATUS, u.Administrator, 
				CONCAT(u.Nazwisko, ' ', u.Imiona) AS NazwiskoImiona, u.User_account_Type, u.user_type,
				IF(l.LAST_MSG = 'OK.RODO.Need.Change.PSWD', 'Ze wzglĂ„â„˘du na przepisy RODO wymagana jest okresowa zmiana hasÄąâ€ša.\nProszĂ„â„˘ podaĂ„â€ˇ nowe - zmienione - hasÄąâ€šo!', '') AS Add_Msg
			FROM `_sys_db_logons` l
			LEFT JOIN `v_intnet_users` u ON u.GUID = l.log_USER_GUID
			WHERE 
				l.GUID = _GUID
			;
			LEAVE S__sys_db_logons_Tools;
		END IF;
		
		CALL _sys_db_logons_LOG('CHECK.NEW', _GUID, _Param_C, _Param_D, _Param_E, '', _Param_F, _Param_G, '');
		SELECT 
			l.GUID, l.log_USER, l.log_USER_GUID, l.LAST_MSG, l.STATUS, u.Administrator, 
			CONCAT(u.Nazwisko, ' ', u.Imiona) AS NazwiskoImiona, u.User_account_Type, u.user_type,
			IF(l.LAST_MSG = 'OK.RODO.Need.Change.PSWD', 'Ze wzglĂ„â„˘du na przepisy RODO wymagana jest okresowa zmiana hasÄąâ€ša.\nProszĂ„â„˘ podaĂ„â€ˇ nowe - zmienione - hasÄąâ€šo!', '') AS Add_Msg
		FROM `_sys_db_logons` l
		LEFT JOIN `v_intnet_users` u ON u.GUID = l.log_USER_GUID
		WHERE 
			l.GUID = _GUID
		;
		-- SELECT GUID,log_USER,log_USER_GUID,LAST_MSG,STATUS FROM `_sys_db_logons` WHERE GUID = _GUID;
		-- END IF;
	/*** koniec @session.LOGON.Ver < 2.15 **/
		LEAVE S__sys_db_logons_Tools;
	END IF;	-- koniec @session.LOGON.Ver < 2.15	
	IF 
	@session.LOGON.Ver >= '2.15'  -- AND FALSE 
	/********************************************************************************************************
		NOWE > sty. 2021 r.
		IF _MODE IN ('CHECK', 'CHECK.Connection') THEN
		NIEBEZPIECZNE!!!!!!!!!!!!!!!!!!!!!
		bo woÄąâ€ša _sys_authorization dla @session.LOGON.Ver >= '2.15' - po ki czort???????????
	********************************************************************************************************/
	THEN	-- @session.LOGON.Ver >= '2.15'
		CALL _auth_bypass('_sys_db_logons_Tools', 'LOG ON', 
			_GUID,	-- @_SESSION_GUID 
			'select', '', 
			_Param_C,	-- @_INPUT_LOGIN_Hash, 
			_Param_D,	-- @_INPUT_Datas_Hash, 
			_Param_E,	-- @_INPUT_MACADDRESS_Hash, 
			_Param_F, 
			_Param_G
		);
		LEAVE S__sys_db_logons_Tools;
	
		SET 
			@.APP_ID.Hash = _MD5_CHARSET('', @session.globals.INPUT_SALT_Hash, _GUID, (@._INPUT_APP_ID := _Param_F), '', '')
		;
		CALL _sys_authorization('authorization.LOG.#Login,#Pswd', _GUID, _Param_C, _Param_D, @.EMPTY_STR.Hash, @.APP_ID.Hash, 
			
			'<Session.In.Hash><FROM._sys_db_logons_Tools>'
		);
		LEAVE S__sys_db_logons_Tools;
		
	END IF;	-- @session.LOGON.Ver >= 2.15

	END IF;

	IF _MODE IN ('LOG ON.TEST') THEN
			DO _counters_tools('INC', CONCAT('_sys_db_logons_Tools: ', _MODE, ':', @session.LOGON.Ver), '', '');		-- to tylko Licznik!!!!
	
		
		SET 
			@.APP_ID.Hash = _MD5_CHARSET('', @session.globals.INPUT_SALT_Hash, _GUID, (@._INPUT_APP_ID := _Param_F), '', '')
		;
		CALL _sys_authorization('authorization.LOG.#Login,#Pswd', _GUID, _Param_C, _Param_D, @.EMPTY_STR.Hash, @.APP_ID.Hash, 'No.select<Session.In.Hash>');
		-- CALL _sys_db_logons_LOG('CHECK.NEW', _GUID, _Param_C, _Param_D, _Param_E, '', _Param_F, _Param_G, '');
		SELECT 
			l.GUID, l.log_USER, l.log_USER_GUID, l.LAST_MSG, l.STATUS, u.Administrator, 
			CONCAT(u.Nazwisko, ' ', u.Imiona) AS NazwiskoImiona, u.User_account_Type,
			IF(l.LAST_MSG = 'OK.RODO.Need.Change.PSWD', 'Ze wzglĂ„â„˘du na przepisy RODO wymagana jest okresowa zmiana hasÄąâ€ša.\nProszĂ„â„˘ podaĂ„â€ˇ nowe - zmienione - hasÄąâ€šo!', '') AS Add_Msg
		FROM `_sys_db_logons` l
		LEFT JOIN `v_intnet_users` u ON u.GUID = l.log_USER_GUID
		WHERE 
			l.GUID = _GUID
		;
		LEAVE S__sys_db_logons_Tools;
		
		
	END IF;


	IF _MODE IN ('LOG ON NEW', 'LOG ON BIO') THEN
	/*
		Zalogowanie prawidlowe/bledne
		Bypass albo ...
		CALL _sys_db_logons_Tools('LOG ON', @_SESSION_GUID, 0, 'select', '', @_INPUT_LOGIN_Hash, @_INPUT_Datas_Hash, @_INPUT_MACADDRESS_Hash, 'M.WEB.ScanPack', '');
		
	*/
			DO _counters_tools('INC', CONCAT('_sys_db_logons_Tools: ', _MODE, ':', @session.LOGON.Ver), '', '');		-- to tylko Licznik!!!!
		IF _MODE IN ('LOG ON BIO') AND @session.globals.Owner IN ('KONKOL') THEN
					CALL _auth_bypass('_sys_db_logons_Tools', 'LOG ON BIO', 
						_GUID,	--	@.we.Session, 
						'select', 
						'', 
						_Param_C,	--	@.we.U.L.5, 	
						_Param_D,	--	@.we.U.P.5, 
						_Param_E,	--	@.we.D.ID.5, 
						_Param_F,	--	@.we.A.ID,
						''
					);
			LEAVE S__sys_db_logons_Tools;
		END IF;
		CALL _sys_db_logons_LOG(IF(_MODE = 'LOG ON NEW', 'CHECK.NEW', 'CHECK.NEW.BIO'), _GUID, _Param_C, _Param_D, _Param_E, '', _Param_F, _Param_G, '');
		SELECT 
			l.GUID, l.log_USER, l.log_USER_GUID, l.LAST_MSG, l.STATUS, u.Administrator, 
			CONCAT(u.Nazwisko, ' ', u.Imiona) AS NazwiskoImiona, u.User_account_Type,
			IF(l.LAST_MSG = 'OK.RODO.Need.Change.PSWD', 'Ze wzglĂ„â„˘du na przepisy RODO wymagana jest okresowa zmiana hasÄąâ€ša.\nProszĂ„â„˘ podaĂ„â€ˇ nowe - zmienione - hasÄąâ€šo!', '') AS Add_Msg
		FROM `_sys_db_logons` l
		LEFT JOIN `v_intnet_users` u ON u.GUID = l.log_USER_GUID
		WHERE 
			l.GUID = _GUID
		;
		
		
		
	END IF;
	
	
	IF _MODE LIKE 'BIO.%' THEN
			DO _counters_tools('INC', CONCAT('_sys_db_logons_Tools: ', _MODE, ':', @session.LOGON.Ver), '', '');		-- to tylko Licznik!!!!
	
		SET
			@_SESSION_GUID = _GUID,
			@_INPUT_LOGIN_Hash = _Param_C,
			@_INPUT_MACADDRESS = _Param_E,
			@_INPUT_SALT_Hash  = (SELECT g.VALUE FROM `_db_globals` g WHERE g.key = '_SLT_#' LIMIT 1)
		;
		IF _MODE = 'BIO.Clear' THEN
			DELETE hc FROM `hr_cards` hc
			WHERE
				hc.ID = @_INPUT_MACADDRESS	--	to jest MACADDRESS
				AND hc.kind = 'MACADDRESS'
			;
			SELECT 
				NOT(ROW_COUNT() <> 0) AS Bio_Err, 
				'' AS Bio_Result
			;
		END IF;	


		
		IF _MODE = 'BIO.Set' THEN
			SET _SQLText = 
"		
			SET
				@.Search.User_GUID = (
				SELECT
					ua.OsobaGUID
				FROM `_user_accounts` ua
				WHERE
					CONVERT(@_INPUT_LOGIN_Hash USING '#CHARSET#') = CONVERT(MD5(CONCAT(CONVERT(@_INPUT_SALT_Hash USING '#CHARSET#'), CONVERT(@_SESSION_GUID USING '#CHARSET#'), CONVERT(MD5(ua.`login`) USING '#CHARSET#'))) USING '#CHARSET#')
				LIMIT 1
				)
			;
"
	;		
			SET _SQLText = REPLACE(_SQLText, '#CHARSET#', @@character_set_client);
			SET @_SQLText = _SQLText;
			CALL _ExecuteCmd(_SQLText, @Error);
			
			INSERT IGNORE INTO `hr_cards`
			(ID, kind, OsobaGUID)
			SELECT
				@_INPUT_MACADDRESS AS ID,
				'MACADDRESS' AS kind,
				ua.OsobaGUID
			FROM `_user_accounts` ua
			WHERE
				ua.OsobaGUID = @.Search.User_GUID
			;
			SELECT 
				NOT(ROW_COUNT() <> 0) AS Bio_Err, 
				'' AS Bio_Result
			;
		END IF;	
		
		IF _MODE = 'BIO.Get' THEN
			SET
				@.BIO.Login = IFNULL(
					(
					SELECT
						
						ua.Login
						
					FROM `hr_cards` hc, `_user_accounts` ua
					WHERE
						hc.ID = @_INPUT_MACADDRESS
						AND hc.kind = 'MACADDRESS'
						AND ua.OsobaGUID = hc.OsobaGUID
					)
				, '')
				
			;	
			SET _SQLText = 
"		
			SET
				@.BIO.Login_Hash = 
					CONVERT(MD5(CONCAT(CONVERT(@_INPUT_SALT_Hash USING '#CHARSET#'), CONVERT(@_SESSION_GUID USING '#CHARSET#'), CONVERT(MD5(@.BIO.Login) USING '#CHARSET#'))) USING '#CHARSET#')
			;
"
	;		
			SET _SQLText = REPLACE(_SQLText, '#CHARSET#', @@character_set_client);
			SET @_SQLText = _SQLText;
			CALL _ExecuteCmd(_SQLText, @Error);
			
			SELECT 
				
				IFNULL(@.BIO.Login, '') = '' OR IFNULL(@.BIO.Login_Hash, '') != @_INPUT_LOGIN_Hash AS Bio_Err, 
				@.BIO.Login AS Bio_Result
			;
		END IF;	

	END IF;	
	
	
	IF _MODE IN ('PING') THEN
	/*
		ZOSTAWIC!!!!
		Wolane w EXE
		Sprawdzenie sesji
		CALL _sys_db_logons_Tools('PING', _GUID, 0, '', '', '', '', '', '', '');
	*/
	IF 
	@session.LOGON.Ver < '2.15' 
	/********************************************************************************************************
		Starsze czyli do sty. 2021 r.
		IF _MODE IN ('CHECK', 'CHECK.Connection') THEN
	********************************************************************************************************/
	THEN	-- @session.LOGON.Ver < 2.15	
		CALL _sessions_APP('Ping.and.SET.Client.Session', _GUID, '', '', '', '', '');
		LEAVE S__sys_db_logons_Tools;
	/*** koniec @session.LOGON.Ver < 2.15 **/
	END IF;	
	IF 
	@session.LOGON.Ver >= '2.15' 
	/********************************************************************************************************
		NOWE > sty. 2021 r.
		IF _MODE IN ('CHECK', 'CHECK.Connection') THEN
	********************************************************************************************************/
	THEN	-- @session.LOGON.Ver >= '2.15'
	--	od 2021-01-12...NEW
		-- byÄąâ€šo CALL _sessions('SESSION.CHECK', _GUID, 'CHECK.TIME+PING', '', '', '', 'GO.FULL');
		CALL _sessions_APP('Ping.and.SET.Client.Session', _GUID, '', '', '', '', ''); 
	END IF;	-- @session.LOGON.Ver >= 2.15
	END IF;
	
	IF _MODE IN ('CHECK', 'CHECK.Connection') THEN
	/*
		ZOSTAWIC!!!!
		Wolane w EXE
		Sprawdzenie sesji
		CALL _sys_db_logons_Tools('CHECK', @_GUID, 0, 'select', '', '', '', '', '', '');
	*/
	IF 
	@session.LOGON.Ver < '2.15' 
	/********************************************************************************************************
		Starsze czyli do sty. 2021 r.
		IF _MODE IN ('CHECK', 'CHECK.Connection') THEN
	********************************************************************************************************/
	THEN	-- @session.LOGON.Ver < 2.15	
	/*
		Sprawdzenie sesji
		CALL _sys_db_logons_Tools('CHECK', @_GUID, 0, 'select', '', '', '', '', '', '');
	*/
	--	od 2022-02-01...NEW
		
		CALL _sessions_APP('Check.and.SET.Client.Session', _GUID, '', '', '', '', IF(_Param_A = 'select', '<select>', '')); 
		LEAVE S__sys_db_logons_Tools;
		
		
		
		
		CALL _sys_db_logons_rec_tools(_MODE, _GUID, 0, _Param_A, _Param_B, _Param_C, _Param_D, _Param_E);
		SET @SYSTEM.Client.Session.GUID = _GUID;
		SET @SYSTEM.Client.Session.GUID.TEST = _GUID;
		IF _Param_A = 'select' THEN
			SELECT GUID,log_USER,log_USER_GUID,LAST_MSG,STATUS FROM `_sys_db_logons` WHERE GUID = _GUID;
		END IF;
		CALL _sys_db_logons_Tools('RENAME.@session.Variables', '', 0, '', '', '', '', '', '', '');
	/*** koniec @session.LOGON.Ver < 2.15 **/
		LEAVE S__sys_db_logons_Tools;
	END IF;	-- koniec @session.LOGON.Ver < 2.15	
	IF 
	@session.LOGON.Ver >= '2.15' 
	/********************************************************************************************************
		NOWE > sty. 2021 r.
		IF _MODE IN ('CHECK', 'CHECK.Connection') THEN
	********************************************************************************************************/
	THEN	-- @session.LOGON.Ver >= '2.15'
	--	od 2022-02-01...NEW
		CALL _sessions_APP('Check.and.SET.Client.Session', _GUID, '', '', '', '', IF(_Param_A = 'select', '<select>', '')); 
		LEAVE S__sys_db_logons_Tools;

	
		CALL _sessions('SESSION.CHECK', _GUID, 'CHECK.TIME+PING', '', '', '', 'GO'); -- !!!!! patrz _Param_E = 'GO.FULL'
		IF _Param_A = 'select' THEN
			SELECT GUID,log_USER,log_USER_GUID,LAST_MSG,STATUS FROM `_sys_db_logons` WHERE GUID = _GUID;
		END IF;
	END IF;	-- @session.LOGON.Ver >= 2.15
	END IF;
	
	IF _MODE IN ('CHECK.stability') THEN
		--	IF NOT (@session.globals.Owner IN ('CDG', 'MPGK', 'KONKOL')) THEN
		--		DO _counters_tools('INC', CONCAT('_sys_db_logons_Tools: ', _MODE, ':', @session.LOGON.Ver), '', '');		-- to tylko Licznik!!!!
		--	END IF;
	/*
	ZOSTAWIC!!!!
	Wolane w EXE
		Sprawdzenie Äąâ€šĂ„â€¦cza i sesji
	*/
	IF 
	@session.LOGON.Ver < '2.15' 
	/********************************************************************************************************
		Starsze czyli do sty. 2021 r.
		IF _MODE IN ('CHECK.stability') THEN
	********************************************************************************************************/
	THEN	-- @session.LOGON.Ver < 2.15	
	/*
		Sprawdzenie Äąâ€šĂ„â€¦cza i sesji
		CALL _sys_db_logons_Tools('CHECK.stability', @_GUID, 0, '', '', '', '', '', '', '');
		CALL _sys_db_logons_Tools('CHECK.stability', @_GUID, 0, 'select', '', '', '', '', '', '');
	*/
		IF IFNULL(@SYSTEM.Client.Session.GUID, '') != _GUID THEN
			CALL _sessions_APP('Check.and.SET.Client.Session', _GUID, '', '', '', '', IF(_Param_A = 'select', '<select>', '')); 
			LEAVE S__sys_db_logons_Tools;
			
			-- CALL _sys_db_logons_Tools('CHECK', _GUID, 0, _Param_A, _Param_B, _Param_C, _Param_D, _Param_E, _Param_F, _Param_G);
		ELSE
			LEAVE S__sys_db_logons_Tools;
		END IF;
	/*** koniec @session.LOGON.Ver < 2.15 **/
		LEAVE S__sys_db_logons_Tools;
	END IF;	-- koniec @session.LOGON.Ver < 2.15	
	IF 
	@session.LOGON.Ver >= '2.15' 
	/********************************************************************************************************
		NOWE > sty. 2021 r.
		IF _MODE IN ('CHECK.stability') THEN
	********************************************************************************************************/
	THEN	-- @session.LOGON.Ver >= '2.15'
		IF IFNULL(@SYSTEM.Client.Session.GUID, '') != _GUID THEN
			CALL _sessions_APP('Check.and.SET.Client.Session', _GUID, '', '', '', '', IF(_Param_A = 'select', '<select>', '')); 
			LEAVE S__sys_db_logons_Tools;
			
			-- CALL _sys_db_logons_Tools('CHECK', _GUID, 0, _Param_A, _Param_B, _Param_C, _Param_D, _Param_E, _Param_F, _Param_G);
		ELSE
			LEAVE S__sys_db_logons_Tools;
		END IF;
	--	CALL _sessions('SESSION.CHECK', _GUID, 'CHECK.TIME+PING', '', '', '', 'GO'); -- !!!!! patrz _Param_E = 'GO.FULL'
	END IF;	-- @session.LOGON.Ver >= 2.15
	END IF;
	
	
	IF _MODE IN ('CLOSE', 'Session.Close') OR (_MODE LIKE 'LOG%OFF') OR (_MODE LIKE 'LOG%OUT') THEN
			DO _counters_tools('INC', CONCAT('_sys_db_logons_Tools: ', _MODE, ':', @session.LOGON.Ver), '', '');		-- to tylko Licznik!!!!
	/*
		Zamkniecie sesji
	*/
		CALL _sessions_APP('SESSION.Close', _GUID, '', '', '', '', IF(_Param_A = 'select', '<select>', '')); 
		LEAVE S__sys_db_logons_Tools;
		
	/*	Dalej WYWAL !!!!! ...	*/
	IF 
	@session.LOGON.Ver < '2.15' 
	/********************************************************************************************************
		Starsze czyli do sty. 2021 r.
		IF _MODE IN ('CLOSE', 'LOG OUT', 'LOG OFF') THEN
	********************************************************************************************************/
	THEN	-- @session.LOGON.Ver < 2.15	
	/*
		Zamkniecie sesji
		CALL _sys_db_logons_Tools('CLOSE', @_GUID, 0, 'select', '', '', '', '', '', '');
	*/
		
		CALL _sys_db_logons_rec_tools('CLOSE', _GUID, 0, _Param_A, _Param_B, _Param_C, _Param_D, _Param_E);
		IF _Param_A = 'select' THEN

			SELECT GUID,log_USER,log_USER_GUID,LAST_MSG,STATUS FROM `_sys_db_logons` WHERE GUID = _GUID;
		END IF;

	/*** koniec @session.LOGON.Ver < 2.15 **/
		LEAVE S__sys_db_logons_Tools;
	END IF;	-- koniec @session.LOGON.Ver < 2.15	
	IF 
	@session.LOGON.Ver >= '2.15' 
	/********************************************************************************************************
		NOWE > sty. 2021 r.
		IF _MODE IN ('CLOSE', 'LOG OUT', 'LOG OFF') THEN
	********************************************************************************************************/
	THEN	-- @session.LOGON.Ver >= '2.15'
		CALL _sessions('rec.Do_Info', _GUID, 'CLOSE', 'Zamykanie sesji', '', '', '');		
		IF _Param_A = 'select' THEN

			SELECT GUID,log_USER,log_USER_GUID,LAST_MSG,STATUS FROM `_sys_db_logons` WHERE GUID = _GUID;
		END IF;
	END IF;	-- @session.LOGON.Ver >= 2.15
	END IF;
	
	IF _MODE IN ('Set.Times') THEN
			DO _counters_tools('INC', CONCAT('_sys_db_logons_Tools: ', _MODE, ':', @session.LOGON.Ver), '', '');		-- to tylko Licznik!!!!
	/*
	...WYWALIC
	nie wolane w SQL
	w mobilnych/www ?
	w EXE?
		CALL _sys_db_logons_rec_tools('Set.Times', _GUID, 0, TIME_IDLE, TIME_OUT, '', '', '');
		CALL _sys_db_logons_Tools('Set.Times', _GUID, 0, TIME_IDLE, TIME_OUT, '', '', '', '', '');
		_Param_A	TIME_IDLE
		_Param_B	TIME_OUT
	*/
		CALL _sys_db_logons_rec_tools('Set.Times', _GUID, 0, _Param_A, _Param_B, '', '', '');
	END IF;
	
	IF _MODE IN ('INF') THEN
			DO _counters_tools('INC', CONCAT('_sys_db_logons_Tools: ', _MODE, ':', @session.LOGON.Ver), '', '');		-- to tylko Licznik!!!!
	/*
	...WYWALIC
	nie wolane w SQL
	w mobilnych/www ?
	w EXE?
		Pobierz info z rekordu _GUID
		CALL _sys_db_logons_Tools('INF', '67b3d837182014f81b0e7feb4ceb3f24', 0, '', '', '', '', '', '', '');
	*/
		SELECT * FROM `_sys_db_logons` WHERE GUID = _GUID;
	END IF;

	IF _MODE IN ('INFO') THEN
			DO _counters_tools('INC', CONCAT('_sys_db_logons_Tools: ', _MODE, ':', @session.LOGON.Ver), '', '');		-- to tylko Licznik!!!!
	/*
	...NIE WYWALIC!!! woÄąâ€šana np. w SIMEX-ie  - nie wiem skĂ„â€¦d ale jest!
	nie wolane w SQL
	w mobilnych/www ?
	w EXE?
		Select informacyjny o zalogowanym
		CALL _sys_db_logons_Tools('INFO', 'cd14821dab219ea06e2fd1a2df2e3582', 0, '', '', '', '', '', '', '');
	*/
				SELECT 
					sdl.*,
					_ConcatStr(o.Nazwisko, _ConcatStr(o.Imie1, o.Imie2, ' '), ' ') AS User_Name,
					IFNULL(
						(
							SELECT _varStr(GROUP_CONCAT(DISTINCT K.adres))
							FROM kontakty K
							WHERE
								K.typ_medium = 3 AND K.nieaktywny = 0 AND osobaGUID = o.GUID
						), ''
					) AS User_Mail,
					IFNULL(
						(
							SELECT _varStr(GROUP_CONCAT(DISTINCT K.adres))
							FROM kontakty K
							WHERE
								K.typ_medium IN (0, 2) AND K.nieaktywny = 0 AND K.osobaGUID = o.GUID
						), ''
					) AS User_Telefon,
					CONCAT(o.Nazwa_Dzialu, ' ', o.Dzial) AS Comments,
					o.UGRPGUID,
					o.IdnUser,
					o.Nazwisko, 
					o.Imie1,
					o.Imie2,
					o.Imiona,
					o.Stanowisko,
					u.user_type,
					u.Admin AS Administrator,
					o.Nazwa_Dzialu,
					o.Dzial
				FROM `_sys_db_logons` sdl 
				INNER JOIN `_user_accounts` u ON u.OsobaGUID = sdl.log_USER_GUID
				INNER JOIN `osoby` o ON o.GUID = sdl.log_USER_GUID
				WHERE 
					sdl.GUID = _GUID
				;
	END IF;
	
	IF _MODE IN ('CHECK.alive') THEN
			DO _counters_tools('INC', CONCAT('_sys_db_logons_Tools: ', _MODE, ':', @session.LOGON.Ver), '', '');		-- to tylko Licznik!!!!
	/*
	...WYWALIC ?
	w SQL				-	nie woÄąâ€šane!!!!
	w mobilnych/www ?
	w EXE?
		Wyczysc zÄąâ€šogi - czyli stare sesje
		CALL _sys_db_logons_Tools('CHECK.alive', '', 0, '', '', '', '', '', '', '');
	*/
		CALL _sys_db_logons_rec_tools(_MODE, '', 0, '', '', '', '', '');
	END IF;

	IF _MODE IN ('RENAME.@session.Variables') THEN
			DO _counters_tools('INC', CONCAT('_sys_db_logons_Tools: ', _MODE, ':', @session.LOGON.Ver), '', '');		-- to tylko Licznik!!!!
	/*
		UWAGA to jest wykonane juz wdroÄąÄ˝enie
		CALL _sessions('SESSION.SETUP.Variables<-Session.GUID', '', '', '', '', '', 'GO');
		tyle ÄąÄ˝e musi byĂ„â€ˇ @SYSTEM.Client.Session.GUID <> bo stamtad sa ustawiane maÄąâ€špy
		
		CALL _sys_db_logons_Tools('RENAME.@session.Variables', '', 0, '', '', '', '', '', '', '');
	*/
	--	Specjalnie aby sie ustawiÄąâ€šy zmienne do zapisÄ‚Ĺ‚w nagÄąâ€šÄ‚Ĺ‚wkÄ‚Ĺ‚w etc.
		SET @session.CheckLogonUser = @SYSTEM.Client.Session.log_USER_GUID;
        SET @session.CurrMyCompNameStr = IFNULL(@session.CurrMyCompNameStr, 'local'); 
        SET @session.CurrMyIPOnly = IFNULL(@session.CurrMyIPOnly, ''); 
        SET @session.CurrMACAddresses = IFNULL(@session.CurrMACAddresses, ''); 
		
		SET @session.Registration.UserLogin = IFNULL(@session.Registration.UserLogin, @SYSTEM.Client.Session.log_USER); 
		

		SET @session.CheckLogonUserLogin = IFNULL(@session.CheckLogonUserLogin, @session.Registration.UserLogin); 
		SET @session.CheckLogonUserLogin = IFNULL(@session.CheckLogonUserLogin, @SYSTEM.Client.Session.log_USER); 
		SET @session.CheckLogonUserLogin = IFNULL(@session.CheckLogonUserLogin, '<by procedure call>'); 
	END IF;

	IF _MODE IN ('SELECT.Moduly') THEN
			DO _counters_tools('INC', CONCAT('_sys_db_logons_Tools: ', _MODE, ':', @session.LOGON.Ver), '', '');		-- to tylko Licznik!!!!
	/*
	...WYWALIC ?
	nie wolane w SQL
	w mobilnych/www ?
	w EXE?
		Pobierz moduly z uprawnien do krorych ma dostep dana osoba
		CALL _sys_db_logons_Tools('SELECT.Moduly', '67b3d837182014f81b0e7feb4ceb3f24', 0, 'Like', '', '', '', '', '', '');
		w _Param_A LIKE
	*/
		DROP TEMPORARY TABLE IF EXISTS `t_upr_Access_available`;
		SET _SQLText = 
"		
		CREATE TEMPORARY TABLE `t_upr_Access_available`
		SELECT 
			DISTINCT u.miejsce, d.Opis, l.log_USER_GUID,
			FALSE AS Access_available
		FROM `_sys_db_logons` l, `uprawnienia` u, `grupy_osob` go, `uprawnienia_dict` d 
		WHERE 
			l.GUID = '#_GUID#'
			AND
			u.miejsce LIKE '#miejsce#'
			AND
			go.OsobaGUID = l.log_USER_GUID
			AND 
			u.OsobaGUID = go.GrupaGUID
			AND
			d.miejsce = u.miejsce
			AND 
			Get_Status_For_Valid_From_To('', NULL, '', go.Deleted, go.Valid_From, go.Valid_To, '', '', '') = 'OK'
		;
"		
		;
		SET 
			@.miejsce.Like = 
			IF(_varIsNullEmpty(_Param_A), 
				'M.%',
				REPLACE(CONCAT(_Param_A, '%'), '%%', '%')
			)
		;
		SET _SQLText = REPLACE(_SQLText, '#miejsce#', @.miejsce.Like);
		SET _SQLText = REPLACE(_SQLText, '#_GUID#', _GUID);
		SET @_SQLText = _SQLText;
		CALL _ExecuteCmd(_SQLText, @Error);
		
		UPDATE `t_upr_Access_available` l
		SET
			l.Access_available = 
				IFNULL(
					(SELECT MIN(u.poziom) FROM `uprawnienia` u WHERE u.miejsce = l.miejsce AND u.OsobaGUID = l.log_USER_GUID),
					IFNULL(
						(SELECT MAX(u.poziom) FROM `uprawnienia` u, `grupy_osob` go WHERE go.OsobaGUID = l.log_USER_GUID AND u.miejsce = l.miejsce AND u.OsobaGUID = go.GrupaGUID),
						TRUE
					)
				)
		;
		SELECT l.miejsce, l.Opis FROM `t_upr_Access_available` l WHERE l.Access_available;
		DROP TEMPORARY TABLE IF EXISTS `t_upr_Access_available`;
	END IF;

END$$

DELIMITER ;





-- Blokada wejÄąâ€şcia stara wersjĂ„â€¦

UPDATE _sys_app_reg SET Disabled = 0 WHERE ID = 'M.EXE.PL2024';
UPDATE _sys_app_reg SET Disabled = 1 WHERE ID = 'M.EXE.PL2003'; 


-- wyzerowanie pit-owych pól w placach
 UPDATE place O SET
    O.p26latzPodatPrzychod = 0, O.p26latzPodatKoszty = 0, O.p26latzPodatPodatek = 0, O.p26latbezPodatPrzychod = 0, O.p26latbezPodatZasMac = 0,
    O.pPEzPodatPrzychod = 0, O.pPEzPodatKoszty = 0, O.pPEzPodatPodatek = 0, O.pPEbezPodatPrzychod = 0, O.pDRzPodatPrzychod = 0, O.pDRzPodatKoszty = 0,
    O.pDRzPodatPodatek = 0, O.pDRbezPodatPrzychod = 0, O.pDRbezPodatZasMac = 0, O.pSkladkiZUSnormalne = 0, O.pSkladkaZUSod26PEzPodatkiem = 0,
    O.pSkladkaZUSodZwolnionych = 0, O.pPodstPPDprzedZaokr = 0, O.pPEbezPodatZasMac = 0, O.KwotaDoLimitu26Narast = 0, O.KwotaDoLimituDRNarast = 0,
    O.KwotaDoLimituPENarast = 0, O.KwotaDoLimitu26 = 0, O.KwotaDoLimituDR = 0, O.KwotaDoLimituPE = 0, O.pZasMacNormPrzych = 0,
    O.pZasMacNormPodatek = 0, O.pZasMac26latPrzych = 0, O.pZasMac26latPodatek = 0, O.pZasMacPEPrzych = 0, O.pZasMacPEPodatek = 0,
    O.pZasilkiPrzych = 0, O.pZasilkiPodatek = 0, O.pZaliczkaWynagrodzNormalne = 0, O.pWynagrodzNormalne = 0, O.pKosztyNormalne  = 0,
    O.pSkladkaZUSodDRzPodatkiem  = 0
    WHERE O.datawyplaty >= '2023-01-01'; 

-- wyzerowanie pit-owych pól w pracach zleconych

UPDATE prace_zlecone Z SET
   Z.z26latzPodatPrzychod = 0, Z.z26latzPodatKoszty = 0, Z.z26latzPodatPodatek = 0, Z.z26latbezPodatPrzychod = 0, Z.z26latbezPodatZasMac = 0, 
   Z.zDRzPodatPrzychod = 0, Z.zDRzPodatKoszty = 0, Z.zDRzPodatPodatek = 0, Z.zDRbezPodatPrzychod = 0, Z.zDRbezPodatZasMac = 0, 
   Z.zPEzPodatPrzychod = 0, Z.zPEzPodatKoszty = 0, Z.zPEzPodatPodatek = 0, Z.zPEbezPodatPrzychod = 0, Z.zPEbezPodatZasMac = 0, 
   Z.zSkladkiZUSnormalne = 0, Z.zSkladkaZUSod26PEzPodatkiem = 0, Z.zSkladkaZUSodZwolnionych = 0, Z.zSkladkaZUSodDRzPodatkiem = 0, 
   Z.zPodstPPDprzedZaokr = 0, Z.zZasMacNormPrzych = 0, Z.zZasMacNormPodatek = 0, Z.zZasMac26latPrzych = 0, Z.zZasMac26latPodatek = 0, 
   Z.zZasMacPePrzych = 0, Z.zZasMacPePodatek = 0, Z.zZasilkiPrzych = 0,Z.zZasilkiPodatek = 0
 WHERE Z.datawyplaty >= '2023-01-01';    


-- select * from _sys_app_reg;


-- Szukanie zapisÄ‚Ĺ‚w stornujĂ„â€¦cych w pĹ‚acach

(SELECT 's' AS Storno, P.datawyplaty, P.rok, P.miesiac, O.Nazwisko, O.imiona, Pr.NrEwidencyjny, P.GUID, P.idn
FROM place P
JOIN osoby O ON O.GUID = P.GUID_pracownika
JOIN Pracownicy Pr ON O.GUID = Pr.GUID
WHERE YEAR(P.datawyplaty) >2021 AND P.GUID_storno <> '')
UNION
(SELECT 'o' AS Storno, P.datawyplaty, P.rok, P.miesiac, O.Nazwisko, O.imiona, Pr.NrEwidencyjny, P.GUID, P.idn
FROM place P
JOIN osoby O ON O.GUID = P.GUID_pracownika
JOIN Pracownicy Pr ON O.GUID = Pr.GUID
WHERE P.GUID IN (SELECT P.GUID_storno FROM place P WHERE YEAR(P.datawyplaty) >2021 AND P.GUID_storno <> '') )
ORDER BY rok, miesiac, Nazwisko, imiona, NrEwidencyjny, Storno;

-- Szukanie zapisÄ‚Ĺ‚w stornujĂ„â€¦cych w zleceniach

(SELECT 's' AS Storno, P.datawyplaty, P.rok, P.miesiac, O.Nazwisko, O.imiona, Pr.NrEwidencyjny, P.GUID, P.idn
FROM `prace_zlecone` P
JOIN osoby O ON O.GUID = P.GUID_pracownika
JOIN Pracownicy Pr ON O.GUID = Pr.GUID
WHERE YEAR(P.datawyplaty) >2021 AND P.GUID_storno <> '')
UNION
(SELECT 'o' AS Storno, P.datawyplaty, P.rok, P.miesiac, O.Nazwisko, O.imiona, Pr.NrEwidencyjny, P.GUID, P.idn
FROM `prace_zlecone` P
JOIN osoby O ON O.GUID = P.GUID_pracownika
JOIN Pracownicy Pr ON O.GUID = Pr.GUID
WHERE P.GUID IN (SELECT P.GUID_storno FROM prace_zlecone P WHERE YEAR(P.datawyplaty) >2021 AND P.GUID_storno <> '') )
ORDER BY rok, miesiac, Nazwisko, imiona, NrEwidencyjny, Storno;


-- Sprawdzenie danych z poprzedniego zakÄąâ€šadu pracy

SELECT O.Nazwisko, O.Imiona, O.NrPesel, P.NrEwidencyjny, P.PodstUbezpWpoprzednichZakladach,P.KwotaDo3procZaktualnegoMsca,P.KwotaZpoprzZaklDoSkl3proc
FROM Pracownicy P
LEFT JOIN osoby O ON O.GUID = P.GUID
WHERE
P.PodstUbezpWpoprzednichZakladach <> 0
  AND ( (O.guid IN (SELECT pl.GUID_pracownika FROM place pl WHERE pl.deleted=0 AND YEAR(pl.datawyplaty)=2023 GROUP BY pl.GUID_pracownika)
         )
         OR
        (O.guid IN (SELECT pz.GUID_pracownika FROM prace_zlecone pz WHERE pz.deleted=0 AND YEAR(pz.datawyplaty)=2023 GROUP BY pz.GUID_pracownika )
        )
      )
ORDER BY Nazwisko, Imiona;

-- !!! UWAGA !!! 
-- PoniĹĽsze SQL-ki - 5 -  wykonujemy po przeliczeniu zapisĂłw plac i zlecen
-- jak z tych 3 ponizszych SQL-ek otrzymamy jakis wynik, to dac znac do AS: co wyszĹ‚o i na jakiej bazie, dla jakiego pracownika i w jakim miesiacu

-- sprawdzenie skladek w placach

SELECT p.miesiac, o.nazwisko, o.imiona, p.RazemSkladkiPracownika, p.pSkladkiZUSnormalne, p.pSkladkaZUSod26PEzPodatkiem, p.pSkladkaZUSodZwolnionych, p.guid
 FROM place p
 LEFT JOIN osoby o ON o.guid=p.GUID_pracownika
 WHERE p.RazemSkladkiPracownika <> (p.pSkladkiZUSnormalne + p.pSkladkaZUSod26PEzPodatkiem + p.pSkladkaZUSodZwolnionych)
       AND YEAR(p.datawyplaty)=2023 AND p.deleted=0
 ORDER BY o.nazwisko,o.imiona,p.miesiac;

-- sprawdzenie skladek w zleceniach 
      
SELECT z.miesiac, o.nazwisko, o.imiona, z.RazemSkladkiZleceniobiorcy, z.zSkladkiZUSnormalne, z.zSkladkaZUSod26PEzPodatkiem, z.zSkladkaZUSodZwolnionych, z.guid
 FROM prace_zlecone z
 LEFT JOIN osoby o ON o.guid=z.GUID_pracownika
 WHERE z.RazemSkladkiZleceniobiorcy <> (z.zSkladkiZUSnormalne + z.zSkladkaZUSod26PEzPodatkiem + z.zSkladkaZUSodZwolnionych)
       AND z.RodzajRyczaltu >=7 AND YEAR(z.datawyplaty)=2023 AND z.deleted=0
-- group by o.nazwisko,o.imiona 
 ORDER BY o.nazwisko,o.imiona;       
       
-- sprawdzenie zaliczki w placach

SELECT p.miesiac, o.nazwisko, o.imiona, p.Zaliczka, p.pZaliczkaWynagrodzNormalne, p.p26latzPodatPodatek, p.pPEzPodatPodatek, 
       p.pZasMacNormPodatek, p.pZasMac26latPodatek, p.pZasMacPePodatek, p.pZasilkiPodatek, p.guid
 FROM place p
 LEFT JOIN osoby o ON o.guid=p.GUID_pracownika
 WHERE p.Zaliczka <> (p.pZaliczkaWynagrodzNormalne + p.p26latzPodatPodatek + p.pPEzPodatPodatek 
                      + p.pZasMacNormPodatek + p.pZasMac26latPodatek + p.pZasMacPePodatek + p.pZasilkiPodatek
                     )
       AND YEAR(p.datawyplaty)=2023 AND p.deleted=0
 ORDER BY o.nazwisko,o.imiona,p.miesiac;

      
           -- pokaz nieprzeliczone place       

SELECT p.rok, p.miesiac, o.nazwisko, o.imiona, p.guid
 FROM place p -- , `log` L
 LEFT JOIN osoby o ON o.guid=p.GUID_pracownika
 WHERE YEAR(p.datawyplaty)>=2023 AND p.deleted =0
        AND  
         NOT ((SELECT LEFT(IF(L.compressed, UNCOMPRESS(L.info),L.info), 255) AS info
          FROM `log` L 
          WHERE L.GUIDlink = p.guid 
          ORDER BY L.idn DESC
          LIMIT 1)   
         LIKE 'Przeliczanie zapi%')
  ORDER BY p.rok,p.miesiac,o.nazwisko, o.imiona; -- ,p.rok, p.miesiac; 

-- pokaz nieprzeliczone zlecenia       

SELECT z.rok, z.miesiac, o.nazwisko, o.imiona, z.guid
 FROM prace_zlecone z -- , `log` L
 LEFT JOIN osoby o ON o.guid=z.GUID_pracownika
 WHERE YEAR(z.datawyplaty)>=2023 AND z.deleted =0
        AND  
         NOT ((SELECT LEFT(IF(L.compressed, UNCOMPRESS(L.info),L.info), 255) AS info
          FROM `log` L 
          WHERE L.GUIDlink = z.guid 
          ORDER BY L.idn DESC
          LIMIT 1)   
         LIKE 'Przeliczanie zapi%')
  ORDER BY z.rok,z.miesiac,o.nazwisko, o.imiona; -- , z.rok, z.miesiac;

       

-- LOG (zmieniÄ‡ ip LIKE)
-- Aga DESKTOP-EPD4IEE
-- Edyta EDYTA2

SELECT * FROM  `log`
WHERE YEAR(czas) =2024 AND MONTH(czas)=06 -- AND DAY(czas)=9
        AND czynnosc IN(2,3,5)
        AND ip LIKE 'jmam%';
-- and idn='2741147';

SELECT * FROM  `log`
WHERE YEAR(czas) =2025 AND MONTH(czas)=5
              AND ip LIKE 'EDYTA2%';
              AND idn='1630743';
              
              
  SELECT * FROM  `log`
WHERE YEAR(czas) =2025 AND MONTH(czas)=3 
              -- AND ip LIKE 'MARIOLA%';
              AND idn='1613333';            
              
              
              
              
