From ba36dd03f6f7005a6e35ec02e4ff9a58f95be1c3 Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Sat, 11 Feb 2012 06:38:46 -0500
Subject: [PATCH] Backported r5850 to 0.7 branch
---
program/include/rcube_contacts.php | 13 ++++++++++++-
1 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/program/include/rcube_contacts.php b/program/include/rcube_contacts.php
index ab3b181..7cd3179 100644
--- a/program/include/rcube_contacts.php
+++ b/program/include/rcube_contacts.php
@@ -213,6 +213,16 @@
$join = " LEFT JOIN ".get_table_name($this->db_groupmembers)." AS m".
" ON (m.contact_id = c.".$this->primary_key.")";
+ $order_col = (in_array($this->sort_col, $this->table_cols) ? $this->sort_col : 'name');
+ $order_cols = array('c.'.$order_col);
+ if ($order_col == 'firstname')
+ $order_cols[] = 'c.surname';
+ else if ($order_col == 'surname')
+ $order_cols[] = 'c.firstname';
+ if ($order_col != 'name')
+ $order_cols[] = 'c.name';
+ $order_cols[] = 'c.email';
+
$sql_result = $this->db->limitquery(
"SELECT * FROM ".get_table_name($this->db_name)." AS c" .
$join .
@@ -220,7 +230,8 @@
" AND c.user_id=?" .
($this->group_id ? " AND m.contactgroup_id=?" : "").
($this->filter ? " AND (".$this->filter.")" : "") .
- " ORDER BY ". $this->db->concat('c.name', 'c.email'),
+ " ORDER BY ". $this->db->concat($order_cols) .
+ " " . $this->sort_order,
$start_row,
$length,
$this->user_id,
--
Gitblit v1.9.1