ad_audit_trail_for_table

one of the documented procedures in this installation of the ACS
Usage:
ad_audit_trail_for_table   db   main_table_name   audit_table_name   id_column   { start_date "" }   { end_date "" }   { audit_url "" }   { restore_url "" }
What it does:
Returns the audit trail for each id from the id_column for updates and deletes from main_table_name and audit_table_name that occured between start_date and end_date. If start_date is blank, then it is assumed to be when the table was created, if end_date is blank then it is assumed to be the current time. The audit_url, if it exists, will be given the calling arguments for ad_audit_trail.
Defined in: /web/philip/tcl/ad-audit-trail.tcl

Source code:



    # Text being returned by the proc
    set return_html ""

    # Build a sql string to only return records which where last modified
    # between the start date and end date
    set date_clause_list [list]
    if { ![empty_string_p $end_date] } {
	lappend date_clause_list "last_modified < to_date('$end_date','YYYY-MM-DD HH24:MI:SS')"
    } 
    if { ![empty_string_p $start_date] } {
	lappend date_clause_list "last_modified > to_date('$start_date','YYYY-MM-DD HH24:MI:SS')"
    }

    # Generate a list of ids for records that where modified in the time
    # between start_date and end_date.
    set id_list [database_to_tcl_list $db "select distinct $id_column from $main_table_name where [join $date_clause_list "\nand "]"]

    # Display the grouped modifications to each id in id_list
    foreach id $id_list {

	# Set the HTML link tags to a page which displays the full 
	# audit history.
	if { ![empty_string_p $audit_url] } {
	    set id_href "<a href=\"$audit_url?[export_url_vars id id_column main_table_name audit_table_name]\">"
	    set id_href_close "</a>"
	} else {
	    set id_href ""
	    set id_href_close ""
	}

	append return_html "
<h4>$id_column is $id_href$id$id_href_close</h4>
<blockquote>
[ad_audit_trail $db $id $audit_table_name $main_table_name $id_column "" $start_date $end_date]
</blockquote>
"
}

    # We will now repeate the process to display the modifications 
    # that took place between start_date and end_date but occured on
    # records that have been deleted.


    # Add a constraint to view only deleted ids and
    # look into the audit table instead of the main table
    lappend date_clause_list "delete_p = 't'"
    set id_list [database_to_tcl_list $db "select distinct $id_column from $audit_table_name where [join $date_clause_list "\nand "] "]

    # Display the grouped modifications to each id in id_list
    foreach id $id_list {

	# Set the HTML link tags to a page which displays the full 
	# audit history.
	if { ![empty_string_p $audit_url] } {
	    set id_href "<a href=\"$audit_url?[export_url_vars id id_column main_table_name audit_table_name]\">"
	    set id_href_close "</a>"
	} else {
	    set id_href ""
	    set id_href_close ""
	}

	append return_html "
<h4>Deleted $id_column is $id_href$id$id_href_close</h4>
<blockquote>
[ad_audit_trail $db $id $audit_table_name $main_table_name $id_column "" $start_date $end_date $restore_url]
</blockquote>
"
    }

    return $return_html


philg@mit.edu