IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[SPWEB_KVKKDURUM]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE SPWEB_KVKKDURUM
GO
CREATE PROCEDURE [dbo].[SPWEB_KVKKDURUM] @kisino NVARCHAR(30)
AS
BEGIN

  DECLARE @HKIMLIKID INT = dbo.FN_BASIT_ID_SIFRE_AC(@kisino)
  --EXEC SPWEB_LOGLA 'hesapgoruldu',@HKIMLIKID,'',''

  IF (SELECT COUNT(*) FROM HKIMLIKGIZLILIK WHERE HKIMLIKID=@HKIMLIKID)=0
  BEGIN
	INSERT INTO HKIMLIKGIZLILIK (HKIMLIKID,KVKKONAY,PAYLASIMIZNI,BILGILENDIRILSINMI,TELEFON,SMS,MAIL,FAX,POSTA,TELEFONNO1,TELEFONNO2,SMSNO,MAILADRESI,POSTAADRESI,KYTKULLANICI,KYTTARIHI,
		SGKULLANICI,SGTARIHI,PAYLASIMIZNIEVET,BILGILENDIRILSINEVET,PAYLASIMIZINDURUMU,TICARIIZINDURUMU) 
					SELECT @HKIMLIKID,0,0,0,0,0,0,0,0,ISNULL(HKIMLIK.HCEP,''),ISNULL(HKIMLIK.HCEP,''),ISNULL(HKIMLIK.HCEP,''),ISNULL(HKIMLIK.HEMAIL,''),'','WEB',GETDATE(),'WEB',GETDATE(),0,0,2,2
					FROM HKIMLIK WHERE HKIMLIKID=@HKIMLIKID
  END

  SELECT ISNULL(SMS,0) as smsonay,ISNULL(KVKKONAY,0) as kvkkonay FROM HKIMLIKGIZLILIK WHERE HKIMLIKID=@HKIMLIKID
  
END
GO

IF EXISTS (SELECT [name] FROM [sys].[database_principals] WHERE [type] = N'S' AND [name] = N'mediwebuser')
BEGIN
	BEGIN TRY
		GRANT EXECUTE ON [dbo].[SPWEB_KVKKDURUM] TO [mediwebuser]
	END TRY
	BEGIN CATCH
	END CATCH
END
GO




