CREATE OR REPLACE TRIGGER LOG_ITMENUCONFTE
BEFORE UPDATE OR INSERT OR DELETE ON ITMENUCONFTE
FOR EACH ROW
DECLARE
   V_CDPESQITEM VARCHAR2(50);
   V_USUARIO VARCHAR2(40);
   V_TIPO VARCHAR2(1);
   V_DESC VARCHAR2(4000);
   V_DSREMOTEADDR VARCHAR2(15);
   V_DSREMOTEHOST VARCHAR2(15);
   V_DSSERVERRDM  VARCHAR2(20);
   V_DSSERVMETHOD VARCHAR2(30);
   V_DSREMOTEOPER VARCHAR2(12);
BEGIN
   V_DESC := '';
   IF INSERTING THEN
	  V_CDPESQITEM := :NEW.NRCONFTELA||'-'||:NEW.IDTPBUTTON||'-'||:NEW.NRBUTTON||'-'||:NEW.NRPGCONFTELA||'-'||:NEW.IDTPBUTONAUX||'-'||:NEW.NRBUTTONAUX;
      V_TIPO := '1';
      V_DESC := 'NRCONFTELA: '||:NEW.NRCONFTELA||' IDTPBUTTON: '||:NEW.IDTPBUTTON||' NRBUTTON: '||:NEW.NRBUTTON||' NRPGCONFTELA: '||:NEW.NRPGCONFTELA||' IDTPBUTONAUX: '||:NEW.IDTPBUTONAUX||' ';
      V_DESC := V_DESC||'NRBUTTONAUX: '|| :NEW.NRBUTTONAUX||' CDIDENTBUTON: '||:NEW.CDIDENTBUTON||' DSBUTTON: '||:NEW.DSBUTTON||' NRCOLORTEXT: '||:NEW.NRCOLORTEXT||' NRCOLORBACK: '||:NEW.NRCOLORBACK || ' ';
      V_DESC := V_DESC || 'NRPGCONFTAUX: ' || :NEW.NRPGCONFTAUX || ' DSMESSAGEBUT: ' || :NEW.DSMESSAGEBUT || ' DTULTATUITCT: ' || :NEW.DTULTATUITCT || ' NRFONTETEXT: ' || :NEW.NRFONTETEXT || ' ';
      V_DESC := V_DESC || 'CDATAPRODITM: ' || :NEW.CDATAPRODITM || ' CDNATPRODUTO: ' || :NEW.CDNATPRODUTO || ' NRLIMPRODCOM: ' || :NEW.NRLIMPRODCOM || ' DSENDEIMG: ' || :NEW.DSENDEIMG || ' ';
      
      V_DESC := V_DESC || 'IDTPBUTONAUX2: ' || :NEW.IDTPBUTONAUX2 || ' NRBUTTONAUX2: ' || :NEW.NRBUTTONAUX2 || ' NRPGCONFTAUX2: ' || :NEW.NRPGCONFTAUX2 || ' IDMODOMENU: ' || :NEW.IDMODOMENU || ' ';
      V_DESC := V_DESC || 'DSENDEIMGAUX: ' || :NEW.DSENDEIMGAUX || ' DSITMENUVENDA: ' || :NEW.DSITMENUVENDA || ' IDEXIBEAPPCONS: ' || :NEW.IDEXIBEAPPCONS || ' ';
      V_DESC := V_DESC || 'DSBUTTONINGLES: ' || :NEW.DSBUTTONINGLES || ' DSBUTTONESPANH: ' || :NEW.DSBUTTONESPANH || ' IDSHOWTAA: ' || :NEW.IDSHOWTAA || ' DTINIVIGENCIA: ' || :NEW.DTINIVIGENCIA;
   ELSIF UPDATING THEN
      V_CDPESQITEM := :NEW.NRCONFTELA||'-'||:NEW.IDTPBUTTON||'-'||:NEW.NRBUTTON||'-'||:NEW.NRPGCONFTELA||'-'||:NEW.IDTPBUTONAUX||'-'||:NEW.NRBUTTONAUX;
      V_TIPO := '2';
      V_DESC := 'NRCONFTELA: '||:NEW.NRCONFTELA||' IDTPBUTTON: '||:NEW.IDTPBUTTON||' NRBUTTON: '||:NEW.NRBUTTON||' NRPGCONFTELA: '||:NEW.NRPGCONFTELA||' IDTPBUTONAUX: '||:NEW.IDTPBUTONAUX||' ';
      V_DESC := V_DESC||' NRBUTTONAUX: '||:NEW.NRBUTTONAUX||' CDIDENTBUTON: '||:NEW.CDIDENTBUTON||' DSBUTTON: '||:NEW.DSBUTTON||' NRCOLORTEXT: '||:NEW.NRCOLORTEXT||' NRCOLORBACK: '||:NEW.NRCOLORBACK || ' ';
      V_DESC := V_DESC || 'NRPGCONFTAUX: ' || :NEW.NRPGCONFTAUX || ' DSMESSAGEBUT: ' || :NEW.DSMESSAGEBUT || ' DTULTATUITCT: ' || :NEW.DTULTATUITCT || ' NRFONTETEXT: ' || :NEW.NRFONTETEXT || ' ';
      V_DESC := V_DESC || 'CDATAPRODITM: ' || :NEW.CDATAPRODITM || ' CDNATPRODUTO: ' || :NEW.CDNATPRODUTO || ' NRLIMPRODCOM: ' || :NEW.NRLIMPRODCOM || ' DSENDEIMG: ' || :NEW.DSENDEIMG || ' ';      
      V_DESC := V_DESC || 'IDTPBUTONAUX2: ' || :NEW.IDTPBUTONAUX2 || ' NRBUTTONAUX2: ' || :NEW.NRBUTTONAUX2 || ' NRPGCONFTAUX2: ' || :NEW.NRPGCONFTAUX2 || ' IDMODOMENU: ' || :NEW.IDMODOMENU || ' ';
      V_DESC := V_DESC || 'DSENDEIMGAUX: ' || :NEW.DSENDEIMGAUX || ' DSITMENUVENDA: ' || :NEW.DSITMENUVENDA || ' IDEXIBEAPPCONS: ' || :NEW.IDEXIBEAPPCONS || ' ';
      V_DESC := V_DESC || 'DSBUTTONINGLES: ' || :NEW.DSBUTTONINGLES || ' DSBUTTONESPANH: ' || :NEW.DSBUTTONESPANH || ' IDSHOWTAA: ' || :NEW.IDSHOWTAA || ' DTINIVIGENCIA: ' || :NEW.DTINIVIGENCIA;      
   ELSE
      V_TIPO := '3';
      V_CDPESQITEM := :OLD.NRCONFTELA||'-'||:OLD.IDTPBUTTON||'-'||:OLD.NRBUTTON||'-'||:OLD.NRPGCONFTELA||'-'||:OLD.IDTPBUTONAUX||'-'||:OLD.NRBUTTONAUX;
      V_DESC := 'NRCONFTELA: '||:OLD.NRCONFTELA||' IDTPBUTTON: '||:OLD.IDTPBUTTON||' NRBUTTON: '||:OLD.NRBUTTON||' NRPGCONFTELA: '||:OLD.NRPGCONFTELA||' IDTPBUTONAUX: '||:OLD.IDTPBUTONAUX||' ';
      V_DESC := V_DESC||' NRBUTTONAUX: '||:OLD.NRBUTTONAUX||' CDIDENTBUTON: '||:OLD.CDIDENTBUTON||' DSBUTTON: '||:OLD.DSBUTTON||' NRCOLORTEXT: '||:OLD.NRCOLORTEXT||' NRCOLORBACK: '||:OLD.NRCOLORBACK || ' ';
      V_DESC := V_DESC || 'NRPGCONFTAUX: ' || :OLD.NRPGCONFTAUX || ' DSMESSAGEBUT: ' || :OLD.DSMESSAGEBUT || ' DTULTATUITCT: ' || :OLD.DTULTATUITCT || ' NRFONTETEXT: ' || :OLD.NRFONTETEXT || ' ';
      V_DESC := V_DESC || 'CDATAPRODITM: ' || :OLD.CDATAPRODITM || ' CDNATPRODUTO: ' || :OLD.CDNATPRODUTO || ' NRLIMPRODCOM: ' || :OLD.NRLIMPRODCOM || ' DSENDEIMG: ' || :OLD.DSENDEIMG || ' ';      
      V_DESC := V_DESC || 'IDTPBUTONAUX2: ' || :OLD.IDTPBUTONAUX2 || ' NRBUTTONAUX2: ' || :OLD.NRBUTTONAUX2 || ' NRPGCONFTAUX2: ' || :OLD.NRPGCONFTAUX2 || ' IDMODOMENU: ' || :NEW.IDMODOMENU || ' ';
      V_DESC := V_DESC || 'DSENDEIMGAUX: ' || :OLD.DSENDEIMGAUX || ' DSITMENUVENDA: ' || :OLD.DSITMENUVENDA || ' IDEXIBEAPPCONS: ' || :OLD.IDEXIBEAPPCONS || ' ';
      V_DESC := V_DESC || 'DSBUTTONINGLES: ' || :OLD.DSBUTTONINGLES || ' DSBUTTONESPANH: ' || :OLD.DSBUTTONESPANH || ' IDSHOWTAA: ' || :OLD.IDSHOWTAA || ' DTINIVIGENCIA: ' || :NEW.DTINIVIGENCIA;      
   END IF;
   NMUSUARIO(V_USUARIO);
   IF :NEW.IDORIGENDPOINT = 'S' THEN
      V_USUARIO := 'ORIGEM ENDPOINT';
   END IF;   
   WEBTUNNING(V_DSREMOTEADDR,
              V_DSREMOTEHOST,
              V_DSSERVERRDM,
              V_DSSERVMETHOD,
              V_DSREMOTEOPER);

   V_DESC := SUBSTR(V_DESC, 1, 4000);
   INSERT INTO LOGOPERAVND
      (NMTABELAVND, DTOPERACAOVND, NMRESPOPERVND, IDTIPOOPERVND, DSOPERACAOVND, CDPESQITEMVND,
       DSRDMUSUOPERVND, DSENDUSUOPERVND, DSNMUSUOPERVND, DSMETUSUOPERVND, CDORESPOPERVND,
       CDFILLOGOPERVND)
   VALUES
      ('ITMENUCONFTE', SYSDATE, NVL(V_USUARIO,' '), V_TIPO, NVL(V_DESC,' '), V_CDPESQITEM,
       V_DSSERVERRDM, V_DSREMOTEADDR, V_DSREMOTEHOST, V_DSSERVMETHOD, V_DSREMOTEOPER, 
	   NVL(:NEW.CDFILIAL,:OLD.CDFILIAL));
END;
/