summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2004-06-02 05:35:51 +0000
committerDries Buytaert <dries@buytaert.net>2004-06-02 05:35:51 +0000
commitcd48e69b29ebb50699813b3ba92d6fc92793e04f (patch)
tree7e42b8a5ab04c633db961f985d3425f321b2e092 /includes
parentfbbf51051159d9ace934d206f63e5b3061c0a767 (diff)
downloadbrdo-cd48e69b29ebb50699813b3ba92d6fc92793e04f.tar.gz
brdo-cd48e69b29ebb50699813b3ba92d6fc92793e04f.tar.bz2
- Patches #6863 by Kristjan and Moshe: implemented pretty tables and fixed some tablesort glitches.
Diffstat (limited to 'includes')
-rw-r--r--includes/tablesort.inc68
-rw-r--r--includes/theme.inc13
2 files changed, 41 insertions, 40 deletions
diff --git a/includes/tablesort.inc b/includes/tablesort.inc
index ce30a409a..51943e403 100644
--- a/includes/tablesort.inc
+++ b/includes/tablesort.inc
@@ -2,48 +2,57 @@
// $Id$
function tablesort_init($header) {
- static $ts;
-
- if (empty($ts)) {
- $ts = tablesort_get_order($header);
- $ts['sort'] = tablesort_get_sort($header);
- $ts['query_string'] = tablesort_get_querystring();
- }
+ $ts = tablesort_get_order($header);
+ $ts['sort'] = tablesort_get_sort($header);
+ $ts['query_string'] = tablesort_get_querystring();
return $ts;
}
function tablesort_pager() {
$cgi = $_SERVER['REQUEST_METHOD'] == 'GET' ? $_GET : $_POST;
- unset($cgi['q'], $cgi["from"]);
+ unset($cgi['q'], $cgi['from']);
return $cgi;
}
function tablesort_sql($header) {
$ts = tablesort_init($header);
- $sql = check_query($ts['sql']);
- $sort = strtoupper(check_query($ts['sort']));
- return " ORDER BY $sql $sort";
+ if ($ts['field']) {
+ $sql = check_query($ts['sql']);
+ $sort = strtoupper(check_query($ts['sort']));
+ return " ORDER BY $sql $sort";
+ }
}
-function tablesort($cell, $header) {
- $ts = tablesort_init($header);
- $title = t("sort by %s", array("%s" => $cell['data']));
-
+function tablesort_header($cell, $header, $ts) {
// special formatting for the currently sorted column header
- if ($cell['data'] == $ts['name']) {
- $ts['sort'] = (($ts['sort'] == 'asc') ? 'desc' : 'asc');
- $cell['class'] = 'active';
- $image = '&nbsp;<img src="' . theme('image', 'arrow-' . $ts['sort'] . '.gif') . '" alt="'. t('sort icon') .'" />';
- $title = ($ts['sort'] == 'asc' ? t("sort ascending") : t("sort descending"));
- }
- else {
- // If the user clicks a different header, we want to sort ascending initially.
- $ts['sort'] = "asc";
- }
+ if (is_array($cell) && $cell['field']) {
+ if ($cell['data'] == $ts['name']) {
+ $ts['sort'] = (($ts['sort'] == 'asc') ? 'desc' : 'asc');
+ $cell['class'] = 'active';
+ $image = '&nbsp;<img src="' . theme('image', 'arrow-' . $ts['sort'] . '.gif') . '" alt="'. t('sort icon') .'" />';
+ $title = ($ts['sort'] == 'asc' ? t('sort ascending') : t('sort descending'));
+ }
+ else {
+ // If the user clicks a different header, we want to sort ascending initially.
+ $ts['sort'] = 'asc';
+ }
+ $title = t('sort by %s', array('%s' => $cell['data']));
+ $cell['data'] = l($cell['data'] . $image, $_GET['q'], array('title' => $title), "sort=". $ts['sort']. "&amp;order=". urlencode($cell['data']). $ts['query_string']);
- $cell['data'] = l($cell['data'] . $image, $_GET['q'], array("title" => $title), "sort=". $ts['sort']. "&amp;order=". urlencode($cell['data']). $ts['query_string']);
+ unset($cell['field'], $cell['sort']);
+ }
+ return $cell;
+}
- unset($cell['field'], $cell['sort']);
+function tablesort_cell($cell, $header, $ts, $i) {
+ if ($header[$i]['data'] == $ts['name'] && $header[$i]['field']) {
+ if (is_array($cell)) {
+ $cell['class'] .= ' active';
+ }
+ else {
+ $cell = array('data' => $cell, 'class' => 'active');
+ }
+ }
return $cell;
}
@@ -51,7 +60,7 @@ function tablesort_get_querystring() {
$cgi = $_SERVER['REQUEST_METHOD'] == 'GET' ? $_GET : $_POST;
foreach ($cgi as $key => $val) {
if ($key != 'order' && $key != 'sort' && $key != 'q') {
- $query_string .= "&amp;". $key ."=". $val;
+ $query_string .= '&amp;'. $key .'='. $val;
}
}
return $query_string;
@@ -67,6 +76,7 @@ function tablesort_get_order($headers) {
if ($header['sort'] == 'asc' || $header['sort'] == 'desc') {
$default = array('name' => $header['data'], 'sql' => $header['field']);
}
+ $i++;
}
if ($default) {
@@ -75,7 +85,7 @@ function tablesort_get_order($headers) {
else {
// The first column specified is initial 'order by' field unless otherwise specified
if (is_array($headers[0])) {
- return array('name' => $headers[0]['name'], 'sql' => $headers[0]['field']);
+ return array('name' => $headers[0]['data'], 'sql' => $headers[0]['field']);
}
else {
return array('name' => $headers[0]);
diff --git a/includes/theme.inc b/includes/theme.inc
index b66cccb01..31c01afca 100644
--- a/includes/theme.inc
+++ b/includes/theme.inc
@@ -322,9 +322,7 @@ function theme_table($header, $rows, $attributes = NULL) {
$ts = tablesort_init($header);
$output .= " <tr>";
foreach ($header as $cell) {
- if (is_array($cell) && $cell['field']) {
- $cell = tablesort($cell, $header);
- }
+ $cell = tablesort_header($cell, $header, $ts);
$output .= _theme_table_cell($cell, 1);
}
$output .= " </tr>\n";
@@ -345,14 +343,7 @@ function theme_table($header, $rows, $attributes = NULL) {
}
foreach ($row as $cell) {
- if ($header[$i]['data'] == $ts['name'] && $header[$i]['field']) {
- if (is_array($cell)) {
- $cell['class'] .= ' active';
- }
- else {
- $cell = array('data' => $cell, 'class' => 'active');
- }
- }
+ $cell = tablesort_cell($cell, $header, $ts, $i);
$output .= _theme_table_cell($cell, 0);
$i++;
}