Index: openacs-4/packages/q-forms/tcl/form-helper-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/q-forms/tcl/form-helper-procs.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/q-forms/tcl/form-helper-procs.tcl 14 Nov 2014 18:27:52 -0000 1.1 +++ openacs-4/packages/q-forms/tcl/form-helper-procs.tcl 8 Apr 2015 08:34:36 -0000 1.2 @@ -217,34 +217,43 @@ } } # sort by smallest variance - set sorted_bg_lists [lsort -increasing -real -index 2 $bguess_lists] - ns_log Notice "qss_txt_table_stats.220: sorted_bg_lists ${sorted_bg_lists}" - set i [lindex [lindex $sorted_bg_lists 0] 0] - set bguess $table_arr(${i}-bguess) - set bguessD $table_arr(${i}-bguessD) - set rows_count $table_arr(${i}-rows) - set delimiter $table_arr(${i}-delim) - - # If there are no bguesses over 2, then use this process: - if { [llength $bguess_lists] == 0 } { - # This following techinque is not dynamic enough to handle all conditions. - set bguessD $table_arr(0-bguessD) - set bguess $table_arr(0-bguess) - set rows_count $table_arr(0-rows) - set delimiter $table_arr(0-delim) - # bguessD is absolute value of bguess from variance - for { set i 0 } { $i < $delimC } { incr i } { - if { ( $table_arr(${i}-bguessD) <= $bguessD ) && $table_arr(${i}-bguess) > 1 } { - if { ( $bguess > 1 && $table_arr(${i}-bguess) < $bguess ) || $bguess < 2 } { - set bguess $table_arr(${i}-bguess) - set bguessD $table_arr(${i}-bguessD) - set rows_count $table_arr(${i}-rows) - set delimiter $table_arr(${i}-delim) + if { [llength $bguess_lists] > 0 } { + set sorted_bg_lists [lsort -increasing -real -index 2 $bguess_lists] + ns_log Notice "qss_txt_table_stats.220: sorted_bg_lists '${sorted_bg_lists}'" + set i [lindex [lindex $sorted_bg_lists 0] 0] + set bguess $table_arr(${i}-bguess) + set bguessD $table_arr(${i}-bguessD) + set rows_count $table_arr(${i}-rows) + set delimiter $table_arr(${i}-delim) + + # If there are no bguesses over 2, then use this process: + if { [llength $bguess_lists] == 0 } { + # This following techinque is not dynamic enough to handle all conditions. + set bguessD $table_arr(0-bguessD) + set bguess $table_arr(0-bguess) + set rows_count $table_arr(0-rows) + set delimiter $table_arr(0-delim) + # bguessD is absolute value of bguess from variance + for { set i 0 } { $i < $delimC } { incr i } { + if { ( $table_arr(${i}-bguessD) <= $bguessD ) && $table_arr(${i}-bguess) > 1 } { + if { ( $bguess > 1 && $table_arr(${i}-bguess) < $bguess ) || $bguess < 2 } { + set bguess $table_arr(${i}-bguess) + set bguessD $table_arr(${i}-bguessD) + set rows_count $table_arr(${i}-rows) + set delimiter $table_arr(${i}-delim) + } } } } + ns_log Notice "qss_txt_table_stats linebreak '${linebreak_char}' delim '${delimiter}' rows '${rows_count}' columns '${bguess}'" + } else { + # There appears to be no rows or columns + # create defaults + set linebreak_char "\n" + set delimiter "\t" + set rows_count 1 + set bguess 1 } - ns_log Notice "qss_txt_table_stats linebreak '${linebreak_char}' delim '${delimiter}' rows '${rows_count}' columns '${bguess}'" set return_list [list $linebreak_char $delimiter $rows_count $bguess] # ns_log Notice "qss_txt_table_stats: return_list $return_list" return $return_list @@ -256,10 +265,13 @@ table_list_of_lists {table_attribute_list ""} {td_attribute_lists ""} + {th_rows "1"} } { Converts a tcl list_of_lists to an html table, returns table as text/html table_attribute_list can be a list of attribute pairs to pass to the TABLE tag: attribute1 value1 attribute2 value2.. - The td_attribute_lists adds attributes to TD tags at the same position as table_list_of_lists + td_attribute_lists adds attributes to TD tags at the same position as table_list_of_lists + First row(s) use html accessibility guidelines TH tag inplace of TD. + Number of th_rows sets the number of rows that use TH tag. Default is 1. the list is represented {row1 {cell1} {cell2} {cell3} .. {cell x} } {row2 {cell1}...} Note that attribute - value pairs in td_attribute_lists can be added uniquely to each TD tag. } { @@ -278,10 +290,19 @@ set repeat_last_row_p 1 set repeat_row [expr { [llength $td_attribute_lists] - 1 } ] } + set td_tag "th" + set td_tag_html "<" + append td_tag_html $td_tag foreach row_list $table_list_of_lists { append table_html "" + if { $row_i == $th_rows } { + set td_tag "td" + set td_tag_html "<" + append td_tag_html $td_tag + } + foreach column $row_list { - append table_html " $repeat_row } { set attribute_value_list [lindex [lindex $td_attribute_lists $repeat_row] $column_i] @@ -292,7 +313,7 @@ regsub -all -- {\"} $value {\"} value append table_html " $attribute=\"$value\"" } - append table_html ">${column}" + append table_html ">${column}" incr column_i } append table_html "\n"