summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/tablesort.inc28
1 files changed, 16 insertions, 12 deletions
diff --git a/includes/tablesort.inc b/includes/tablesort.inc
index 44a0db948..0ba06f196 100644
--- a/includes/tablesort.inc
+++ b/includes/tablesort.inc
@@ -55,20 +55,24 @@ function tablesort_get_querystring() {
}
function tablesort_get_order($headers) {
- if ($_GET['order'] != NULL) {
- return $_GET['order'];
+ $order = $_GET['order'];
+ foreach ($headers as $header) {
+ if ($order == $header['data']) {
+ return $header['data'];
+ }
+
+ if ($header['sort'] == 'asc' || $header['sort'] == 'desc') {
+ $default = $header['data'];
+ }
+ }
+
+ if ($default) {
+ return $default;
}
else {
- foreach ($headers as $header) {
- if ($header["sort"] == 'asc' || $header["sort"] == 'desc') {
- return $header["data"];
- }
- elseif (!$first) {
- // the first column specified is initial 'order by' field unless otherwise specified
- $first = $header["data"];
- }
- }
- return $first;
+ // The first column specified is initial 'order by' field unless otherwise specified
+ $first = reset($header);
+ return $first['data'];
}
}