CREATE OR REPLACE TRIGGER LOG_VALIDANFTPOP
AFTER DELETE OR INSERT OR UPDATE
ON VALIDANFTPOP FOR EACH ROW
DECLARE
  V_USUARIO   VARCHAR2(40);
  V_TIPO      VARCHAR2(1);
  V_ITPESQ    VARCHAR2(40);
  V_DESC      VARCHAR2(300);
  V_DSREMOTEADDR VARCHAR2(15);
  V_DSREMOTEHOST VARCHAR2(15);
  V_DSSERVERRDM  VARCHAR2(20);
  V_DSSERVMETHOD VARCHAR2(30);
  V_DSREMOTEOPER VARCHAR2(12);
BEGIN
   V_TIPO := '0';
   V_DESC := '';

   IF DELETING THEN
      IF :OLD.CDTIPOOPER IS NOT NULL THEN
         V_DESC := V_DESC || 'TpOper=' || :OLD.CDTIPOOPER;
      END IF;

      IF :OLD.IDENTRSAIDOP IS NOT NULL THEN
         V_DESC := V_DESC || ' E/S=' || :OLD.IDENTRSAIDOP;
      END IF;

      IF :OLD.IDINSCESTADIF IS NOT NULL THEN
         V_DESC := V_DESC || ' Inscr.Dif=' || :OLD.IDINSCESTADIF;
      END IF;

      IF :OLD.IDINSCESTAIGU IS NOT NULL THEN
         V_DESC := V_DESC || ' Inscr.Igual=' || :OLD.IDINSCESTAIGU;
      END IF;

      V_TIPO := '3';
      V_ITPESQ := :OLD.CDTIPOOPER;
   ELSE
      IF NVL(:OLD.CDTIPOOPER, '!') <> NVL(:NEW.CDTIPOOPER, '!') THEN
         V_DESC := V_DESC || 'TpOper=' || :NEW.CDTIPOOPER;
      END IF;

      IF NVL(:OLD.IDENTRSAIDOP, '!') <> NVL(:NEW.IDENTRSAIDOP, '!') THEN
         V_DESC := V_DESC || ' E/S=' || :NEW.IDENTRSAIDOP;
      END IF;

      IF NVL(:OLD.IDINSCESTADIF, '!') <> NVL(:NEW.IDINSCESTADIF, '!') THEN
         V_DESC := V_DESC || ' Inscr.Dif=' || :NEW.IDINSCESTADIF;
      END IF;

      IF NVL(:OLD.IDINSCESTAIGU, '!') <> NVL(:NEW.IDINSCESTAIGU, '!') THEN
         V_DESC := V_DESC || ' Inscr.Igual=' || :NEW.IDINSCESTAIGU;
      END IF;
      
      V_TIPO := '1';
      V_ITPESQ := :NEW.CDTIPOOPER;
   END IF;

   IF (V_TIPO <> '0')  THEN
      IF NOT V_DESC IS NULL THEN
         NMUSUARIO(V_USUARIO);
         WEBTUNNING(V_DSREMOTEADDR,
                    V_DSREMOTEHOST,
                    V_DSSERVERRDM,
                    V_DSSERVMETHOD,
                    V_DSREMOTEOPER);

         IF NOT V_USUARIO IS NULL THEN
            INSERT INTO LOGOPERA
               (NMTABELA,   DTOPERACAO, NMRESPOPER,
                IDTIPOOPER, CDPESQITEM, DSOPERACAO,
                DSRDMUSUOPER, DSENDUSUOPER, DSNMUSUOPER, DSMETUSUOPER, CDORESPOPER)
            VALUES
               ('VALIDANFTPOP',  SYSDATE(), V_USUARIO,
                V_TIPO,         V_ITPESQ, V_DESC,
                V_DSSERVERRDM, V_DSREMOTEADDR, V_DSREMOTEHOST, V_DSSERVMETHOD, V_DSREMOTEOPER);
         END IF;
      END IF;
   END IF;
END;
/

-- VERSAO --
BEGIN ATUVEROBJ('LOG_VALIDANFTPOP','5.42.xxx'); END;
/

