
synopsis:

	Audit of user changes

description:

	Audit of all user changes for all organizations.

columns:

	user_id:i		Internal user id
	audit_stamp		Time stamp of the audit action
	audit_action		Audit action
	audit_user_id		Internal user id of user who did the audited action
	audit_username		User name / login of user who did the audited action
	organization_id:i	Organization identifier
	username		User name / login
	password		Encrypted password

sql:

	select user_id, audit_stamp, audit_action, audit_user_id, audit_username, organization_id, username, password
	from (
	select log.id as log_id,
		web_contact_log.id as user_id,
		to_char(log.stamp, 'YYYY-MM-DD HH24:MI:SS') as audit_stamp,
		case when web_contact_log.action = 'A' then 'AUDIT START'
			when web_contact_log.action = 'I' then 'INSERT'
			when web_contact_log.action = 'U' then 'UPDATE'
			when web_contact_log.action = 'D' then 'DELETE' else 'UNKNOWN' end as audit_action,
		case when web_contact.id is not null then web_contact.id else web_contact_all.id end as audit_user_id,
		case when web_contact.id is not null then web_contact.login else web_contact_all.login end as audit_username,
		web_contact_log.org_id as organization_id,
		web_contact_log.login as username,
		web_contact_log.password as password
	from web_contact_log, log left outer join web_contact_all
		on log.user_id = web_contact_all.id
		left outer join web_contact
		on log.user_id = web_contact.id
	where web_contact_log.log_id = log.id
	) X
	-- where placeholder
	order by X.user_id, X.log_id
