/*****************************************************************************
*
* Filename         - $Workfile:   flight_access_triggers.sql  $
*
*                     Name              Date      Version     CR Number
* Author           - See revision history below.
* Last Update      - See revision history below.
*
* Project Name     - TAGTRAK(Oracle database)
*
* Source Code
* Identifier       - 0/3/300/8010/112
*
* Design Spec
* Section          - 
*
* Contents         - Triggers for flight_access table.
*
* Language         - Oracle SQL*Plus script
*
* Classification   - Commercial In Confidence
*
*          (c) Ultra Electronics Limited, 1998
*
*****************************************************************************/
/****************************************************************************
* @(#)$Workfile:   flight_access_triggers.sql  $  $Revision:   1.2  $
*
* Revision History
*
* Note that user tagtrak is many users. For these users the user
* name is entered as the last line in the change description.
*
* $Log:   /pvcsarch/db_ora/db/source/live/triggers/flight_access_triggers.svl  $
* 
*    Rev 1.2   21 Jun 2001 15:04:12   tagtrak
* OR:
* CR:
* Re-baseline version 4.0.0 to include patches.
* 
*    Rev 1.1   02 Apr 1998 19:46:08   tagtrak
* OR:
* CR:
* REV:
* Initial Issue
* See label for concession
* 
*    Rev 1.0   26 Feb 1998 11:43:42   tagtrak
* OR:
* CR:
* REV:
* Initial core product version
*
****************************************************************************/

/*
 * After insert trigger on flight_access
 * Maintain audit trail.
 */
create or replace trigger ti_flight_access
after insert on flight_access
for each row
begin

	/*
	 * Maintain audit trail.
	 */
	add_log_rec( 'FLIGHT_ACCESS',
		'insert: Flight ID: '||rtrim(:new.flight_id)||'. Agent: '||
		rtrim(:new.agent_code)||
		'. Flight_Priv_ID: '||rtrim(nvl(to_char(:new.flight_priv_id),'blank'))||
		'. Internal User: '||USER,
		:new.last_user );

end;
/

/*
 * After update trigger on flight_access
 * Maintain audit trail.
 */
create or replace trigger tu_flight_access
after update on flight_access
for each row
begin

	/*
	 * Maintain audit trail.
	 */
	add_log_rec( 'FLIGHT_ACCESS',
		'update: (old values): Flight ID: '||:old.flight_id||'. Agent: '||
		rtrim(:old.agent_code)||'. Flight_Priv_ID: '||
		rtrim(nvl(to_char(:old.flight_priv_id),'blank'))||
		'. Last User: '||:old.last_user||
		'.(new values): Flight ID: '||:new.flight_id||
		'. Agent: '||rtrim(:new.agent_code)||
		'. Flight_Priv_ID: '||rtrim(nvl(to_char(:new.flight_priv_id),'blank'))||
		'. Internal User: '||USER,
		:new.last_user );

end;
/

/*
 * After delete trigger on flight_access.
 * Maintain audit trail.
 */
create or replace trigger td_flight_access
after delete on flight_access
for each row
begin

	/*
	 * Maintain audit trail. User ID is unknown in this context.
	 */
	add_log_rec( 'FLIGHT_ACCESS',
		'delete: Flight ID: '||:old.flight_id||'. Agent: '||rtrim(:old.agent_code)||
		'. Flight_Priv_ID: '||rtrim(nvl(to_char(:old.flight_priv_id),'blank'))||
		'. Last User: '||:old.last_user||'. Internal User: '||USER,
		NULL );

end;
/
