From 09c70b1ad56cd7bbfe5b8cb244987cab484a9543 Mon Sep 17 00:00:00 2001
From: "Bradley M. Froehle" <brad.froehle@gmail.com>
Date: Mon, 21 Nov 2011 12:58:11 -0800
Subject: [PATCH] Issue #806982 by sreynen, kathyh: Added theme_table() should
 take an optional footer variable and produce <tfoot>.

---
 core/includes/common.inc |    2 +-
 core/includes/theme.inc  |   20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/core/includes/common.inc b/core/includes/common.inc
index 919bfb5..744ce5a 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -6568,7 +6568,7 @@ function drupal_common_theme() {
       'variables' => array(),
     ),
     'table' => array(
-      'variables' => array('header' => NULL, 'rows' => NULL, 'attributes' => array(), 'caption' => NULL, 'colgroups' => array(), 'sticky' => TRUE, 'empty' => ''),
+      'variables' => array('header' => NULL, 'footer' => NULL, 'rows' => NULL, 'attributes' => array(), 'caption' => NULL, 'colgroups' => array(), 'sticky' => TRUE, 'empty' => ''),
     ),
     'tablesort_indicator' => array(
       'variables' => array('style' => NULL),
diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index 68dd70b..c37720e 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -1704,6 +1704,12 @@ function theme_breadcrumb($variables) {
  *     - "sort": A default sort order for this column ("asc" or "desc").
  *     - Any HTML attributes, such as "colspan", to apply to the column header
  *       cell.
+ *   - footer: An array containing the table footers. Each element of the array
+ *     can be either a localized string or an associative array with the
+ *     following keys:
+ *     - "data": The localized title of the table column.
+ *     - Any HTML attributes, such as "colspan", to apply to the column header
+ *       cell.
  *   - rows: An array of table rows. Every row is an array of cells, or an
  *     associative array with the following keys:
  *     - "data": an array of cells
@@ -1767,6 +1773,7 @@ function theme_breadcrumb($variables) {
  */
 function theme_table($variables) {
   $header = $variables['header'];
+  $footer = $variables['footer'];
   $rows = $variables['rows'];
   $attributes = $variables['attributes'];
   $caption = $variables['caption'];
@@ -1854,6 +1861,19 @@ function theme_table($variables) {
     $ts = array();
   }
 
+  if (count($footer)) {
+    // HTML requires that the tfoot tag has tr tags in it followed by tbody
+    // tags. Using ternary operator to check and see if we have any rows.
+    $output .= (count($rows) ? ' <tfoot><tr>' : ' <tr>');
+    $i = 0;
+    foreach ($header as $cell) {
+      $cell = tablesort_cell($cell, $header, $ts, $i++);
+      $output .= _theme_table_cell($cell);
+    }
+    // Using ternary operator to close the tags based on whether or not there are rows
+    $output .= (count($rows) ? " </tr></tfoot>\n" : "</tr>\n");
+  }
+
   // Format the table rows:
   if (count($rows)) {
     $output .= "<tbody>\n";
-- 
1.7.7.2

