ad_table (public, deprecated)

 ad_table [ -Torder_target_url Torder_target_url ] \
    [ -Torderby Torderby ] [ -Tasc_order_img Tasc_order_img ] \
    [ -Tdesc_order_img Tdesc_order_img ] \
    [ -Tmissing_text Tmissing_text ] [ -Tsuffix Tsuffix ] \
    [ -Tcolumns Tcolumns ] [ -Taudit Taudit ] \
    [ -Trows_per_band Trows_per_band ] [ -Tband_colors Tband_colors ] \
    [ -Tband_classes Tband_classes ] \
    [ -Trows_per_page Trows_per_page ] [ -Tmax_rows Tmax_rows ] \
    [ -Ttable_extra_html Ttable_extra_html ] \
    [ -Theader_row_extra Theader_row_extra ] \
    [ -Ttable_break_html Ttable_break_html ] \
    [ -Tpre_row_code Tpre_row_code ] [ -Trow_code Trow_code ] \
    [ -Tpost_data_ns_sets Tpost_data_ns_sets ] \
    [ -Textra_vars Textra_vars ] [ -Textra_rows Textra_rows ] \
    [ -bind bind ] [ -dbn dbn ] statement_name sql_qry Tdatadef

Defined in packages/acs-tcl/tcl/deprecated-procs.tcl

Deprecated. Invoking this procedure generates a warning.

DRB: New code should use the listbuilder. Note: all the variables in this function are named Tblah since we could potentially have namespace collisions

build and return an HTML fragment given an active query and a data definition.

  • sql_qry -- The query that should be executed to generate the table.
    You can specify an optional -bind argument to specify an ns_set of bind variables.
  • Tdatadef -- the table declaration.
Datadef structure :
    {
        {column_id "Column_Heading" order_clause display_info}
        ...
    }
    
  • column_id -- what to set as orderby for sorting and also is the default variable for the table cell.
  • the text for the heading to be wrapped in <th> and </th> tags. I am not entirely happy that things are wrapped automatically since you might not want plain old th tags but I also don;t want to add another field in the structure.
  • order_clause -- the order clause for the field. If null it defaults to "column_id $order". It is also interpolated, with orderby and order defined as variables so that:
                 {upper(last_name) $order, upper(first_names) $order}
             
    would do the right thing.

    the value "no_sort" should be used for columns which should not allow sorting.

    the value "sort_by_pos" should be used if the columns passed in are column positions rather than column names.

  • display_info. If this is a null string you just default to generating <td>column_id</td>. If it is a string in the lookup list then special formatting is applied; this is l r c tf 01 for align=left right center, Yes/No (from tf), Yes/No from 0/1.

    if the display stuff is not any of the above then it is interpolated and the results returned (w/o any <td> tags put in). An example:

        set table_def {
            {ffn "Full Name"
                {upper(last_name) $order, upper(first_names) $order}
                {<td><a href="/admin/users/one?user_id=$user_id">$first_names $last_name</a></td>}}
            {email "e-Mail" {} {<td><a href="mailto:$email">$email</a>}}
            {email_bouncing_p "e-Bouncing?" {} tf}
            {user_state "State" {} {}}
            {last_visit "Last Visit" {} r}
            {actions "Actions" no_sort {<td>
                    <a href="/admin/users/basic-info-update?user_id=$user_id">Edit Info</a> |
                    <a href="/admin/users/password-update?user_id=$user_id">New Password</a> |
                [ad_registration_finite_state_machine_admin_links $user_state $user_id]}}
        }
        

Switches:
-Torder_target_url (optional)
-Torderby (optional)
-Tasc_order_img (optional, defaults to "^")
-Tdesc_order_img (optional, defaults to "v")
-Tmissing_text (optional, defaults to "<em>No data found.</em>")
-Tsuffix (optional)
-Tcolumns (optional)
-Taudit (optional)
-Trows_per_band (optional, defaults to "1")
-Tband_colors (optional, defaults to "{} "#ececec"")
-Tband_classes (optional, defaults to "{even} {odd}")
-Trows_per_page (optional, defaults to "0")
-Tmax_rows (optional, defaults to "0")
-Ttable_extra_html (optional, defaults to "cellpadding=3 cellspacing=0 class="table-display"")
-Theader_row_extra (optional, defaults to "style="background-color:#f8f8f8" class="table-header"")
-Ttable_break_html (optional, defaults to "<br><br>")
-Tpre_row_code (optional)
-Trow_code (optional, defaults to "[subst $Trow_default]")
-Tpost_data_ns_sets (optional)
-Textra_vars (optional)
-Textra_rows (optional)
-bind (optional)
-dbn (optional)
The database name to use. If empty_string, uses the default database.
Parameters:
statement_name (required)
sql_qry (required)
Tdatadef (required)
See Also:

Testcases:
No testcase defined.
Source code:
ad_log_deprecated proc ad_table

    set full_statement_name [db_qd_get_fullname $statement_name]

    # This procedure needs a full rewrite!
    db_with_handle -dbn $dbn Tdb {
        # Execute the query
        set selection [db_exec select $Tdb $full_statement_name $sql_qry]
        set Tcount 0
        set Tband_count 0
        set Tpage_count 0
        set Tband_color 0
        set Tband_class 0
        set Tn_bands [llength $Tband_colors]
        set Tn_band_classes [llength $Tband_classes]
        set Tform [ad_conn form]

        # export variables from calling environment
        if {$Textra_vars ne ""} {
            foreach Tvar $Textra_vars {
                upvar $Tvar $Tvar
            }
        }

        # get the current ordering information
        set Torderbykey {::not_sorted::}
        set Treverse {}
        regexp {^([^*,]+)([*])?} $Torderby match Torderbykey Treverse
        if {$Treverse eq "*"} {
            set Torder desc
        } else {
            set Torder asc
        }

        # set up the target url for new sorts
        if {$Torder_target_url eq ""} {
            set Torder_target_url [ad_conn url]
        }
        set Texport "[uplevel [list export_ns_set_vars url [list orderby$Tsuffix]]]&"
        if {$Texport == "&"} {
            set Texport {}
        }
        set Tsort_url "$Torder_target_url?${Texport}orderby$Tsuffix="

        set Thtml {}
        set Theader {}

        # build the list of columns to display...
        set Tcolumn_list [ad_table_column_list $Tdatadef $Tcolumns]

        # generate the header code
        #
        append Theader "<table $Ttable_extra_html>\n"
        if {$Theader_row_extra eq ""} {
            append Theader "<tr>\n"
        } else {
            append Theader "<tr $Theader_row_extra>\n"
        }
        foreach Ti $Tcolumn_list {
            set Tcol [lindex $Tdatadef $Ti]
            if { ( [ns_set find $selection [lindex $Tcol 0]] < 0
                   && ([lindex $Tcol 2] eq "" || [lindex $Tcol 2] ne "sort_by_pos")
                   )
                 || [lindex $Tcol 2] eq "no_sort"
             } {

                # not either a column in the select or has sort code
                # then just a plain text header so do not do sorty things
                append Theader " <th>[lindex $Tcol 1]</th>\n"
            } else {
                if {[lindex $Tcol 0] eq $Torderbykey } {
                    if {$Torder eq "desc"} {
                        set Tasord $Tasc_order_img
                    } else {
                        set Tasord $Tdesc_order_img
                    }
                } else {
                    set Tasord {}
                }
                set href $Tsort_url[ns_urlencode [ad_new_sort_by [lindex $Tcol 0] $Torderby]]
                append Theader  [subst { <th><a href="[ns_urlencode $href]">}]  "\n[lindex $Tcol 1]</a>&nbsp;$Tasord</th>\n"
            }
        }
        append Theader "</tr>\n"

        #
        # This has gotten kind of ugly.  Here we are looping over the
        # rows returned and then potentially a list of ns_sets which can
        # be passed in (grrr.  Richard Li needs for general protections stuff
        # for "fake" public record which does not exist in DB).
        #

        set Tpost_data 0

        while { 1 } {
            if {!$Tpost_data && [ns_db getrow $Tdb $selection]} {
                # in all its evil majesty
                set_variables_after_query
            } else {
                # move on to fake rows...
                incr Tpost_data
            }

            if { $Tpost_data && $Tpost_data <= [llength $Tpost_data_ns_sets] } {
                # bind the Tpost_data_ns_sets row of the passed in data
                set_variables_after_query_not_selection [lindex $Tpost_data_ns_sets $Tpost_data-1]
            } elseif$Tpost_data } {
                # past the end of the fake data drop out.
                break
            }

            if { $Tmax_rows && $Tcount >= $Tmax_rows } {
                if { ! $Tpost_data } {
                    # we hit max count and had rows left to read...
                    ns_db flush $Tdb
                }
                break
            }

            # deal with putting in the header if need
            if { $Tcount == 0 } {
                append Thtml "$Theader"
            } elseif$Tpage_count == 0 }  {
                append Thtml "</table>\n$Ttable_break_html\n$Theader"
            }

            # first check if we are in audit mode and if the audit columns have changed
            set Tdisplay_changes_only 0
            if {$Taudit ne "" && $Tcount > 0} {
                # check if the audit key columns changed
                foreach Taudit_key $Taudit {
                    if {[set $Taudit_key] eq [set P$Taudit_key] } {
                        set Tdisplay_changes_only 1
                    }
                }
            }

            # this is for breaking on sorted field etc.
            append Thtml [subst $Tpre_row_code]

            if { ! $Tdisplay_changes_only } {
                # in audit mode a record spans multiple rows.
                incr Tcount
                incr Tband_count
            }
            incr Tpage_count

            if { $Trows_per_page && $Tpage_count >= $Trows_per_page } {
                set Tband_color 0
                set Tband_class 0
                set Tband_count 0
                set Tpage_count 0

            }

            set Trow_default {}
            # generate the row band color
            if { $Tband_count >= $Trows_per_band } {
                set Tband_count 0
                set Tband_color [expr {($Tband_color + 1) % $Tn_bands} ]
                set Tband_class [expr {($Tband_class + 1) % $Tn_band_classes} ]
            }
            # do this check since we would like the ability to band with
            # page background as well
            if {$Tn_bands && [lindex $Tband_colors $Tband_color] ne ""} {
                append Trow_default " style=\"background-color:[lindex $Tband_colors $Tband_color]\""
            }
            if {$Tn_band_classes && [lindex $Tband_classes $Tband_class] ne ""} {
                append Trow_default " class=\"[lindex $Tband_classes $Tband_class]\""
            }


            set Trow_default "<tr$Trow_default>"

            append Thtml [subst $Trow_code]

            foreach Ti $Tcolumn_list {
                set Tcol [lindex $Tdatadef $Ti]
                # If we got some special formatting code we handle it
                # single characters r l c are special for alignment
                set Tformat [lindex $Tcol 3]
                set Tcolumn [lindex $Tcol 0]
                switch -- $Tformat {
                    "" {set Tdisplay_field " <td>[set $Tcolumn]</td>\n"}
                    r {set Tdisplay_field " <td align=\"right\">[set $Tcolumn]</td>\n"}
                    l {set Tdisplay_field " <td align=\"left\">[set $Tcolumn]</td>\n"}
                    c {set Tdisplay_field " <td align=\"center\">[set $Tcolumn]</td>\n"}
                    tf {set Tdisplay_field " <td align=\"center\">[util_PrettyBoolean [set $Tcolumn]]</td>\n"}
                    01 {set Tdisplay_field " <td align=\"center\">[util_PrettyTclBoolean [set $Tcolumn]]</td>\n"}
                    bz {set Tdisplay_field " <td align=\"right\">&nbsp;[blank_zero [set $Tcolumn]]</td>\n"}
                    default {set Tdisplay_field " [subst $Tformat]\n"}
                }

                if { $Tdisplay_changes_only
                     && $Tdisplay_field eq $Tlast_display($Ti) } {
                    set Tdisplay_field {<td>&nbsp;</td>}
                } else {
                    set Tlast_display($Ti$Tdisplay_field
                }
                append Thtml $Tdisplay_field
            }

            append Thtml "</tr>\n"

            # keep the last row around so we can do fancy things.
            # so on next row we can say things like if $Pvar != $var not blank
            if { $Tpost_data && $Tpost_data <= [llength $Tpost_data_ns_sets] } {
                # bind the Tpost_data_ns_sets row of the passed in data
                set_variables_after_query_not_selection [lindex $Tpost_data_ns_sets $Tpost_data-1] P
            } else {
                set_variables_after_query_not_selection $selection P
            }
        }

        if { $Tcount > 0} {
            append Thtml "$Textra_rows
</table>\n"
        } else {
            append Thtml $Tmissing_text
        }
    }
    return $Thtml
XQL Not present:
PostgreSQL, Oracle
Generic XQL file:
packages/acs-tcl/tcl/deprecated-procs.xql

[ hide source ] | [ make this the default ]
Show another procedure: