diff options
author | thomascube <thomas@roundcube.net> | 2012-02-11 11:38:46 +0000 |
---|---|---|
committer | thomascube <thomas@roundcube.net> | 2012-02-11 11:38:46 +0000 |
commit | ba36dd03f6f7005a6e35ec02e4ff9a58f95be1c3 (patch) | |
tree | 002d0183144bb7adcf757144c035f0f8d0eba649 | |
parent | 5ea6e16036aa18c57c709dc88e4255120b63e965 (diff) |
Backported r5850 to 0.7 branch
-rw-r--r-- | config/main.inc.php.dist | 3 | ||||
-rw-r--r-- | program/include/rcmail.php | 4 | ||||
-rw-r--r-- | program/include/rcube_addressbook.php | 17 | ||||
-rw-r--r-- | program/include/rcube_contacts.php | 13 | ||||
-rw-r--r-- | program/include/rcube_ldap.php | 24 | ||||
-rw-r--r-- | program/include/rcube_mdb2.php | 2 | ||||
-rw-r--r-- | program/steps/addressbook/list.inc | 3 | ||||
-rw-r--r-- | program/steps/settings/func.inc | 14 | ||||
-rw-r--r-- | program/steps/settings/save_prefs.inc | 1 |
9 files changed, 61 insertions, 20 deletions
diff --git a/config/main.inc.php.dist b/config/main.inc.php.dist index 6957577b1..d2902e9b4 100644 --- a/config/main.inc.php.dist +++ b/config/main.inc.php.dist @@ -653,6 +653,9 @@ $rcmail_config['skin'] = 'default'; // show up to X items in list view $rcmail_config['pagesize'] = 40; +// sort contacts by this col (preferably either one of name, firstname, surname) +$rcmail_config['addressbook_sort_col'] = 'surname'; + // use this timezone to display date/time $rcmail_config['timezone'] = 'auto'; diff --git a/program/include/rcmail.php b/program/include/rcmail.php index 6f0ba2ce9..f6e2b4b59 100644 --- a/program/include/rcmail.php +++ b/program/include/rcmail.php @@ -452,6 +452,10 @@ class rcmail true, true); } + // set configured sort order + if ($sort_col = $this->config->get('addressbook_sort_col')) + $contacts->set_sort_order($sort_col); + // add to the 'books' array for shutdown function $this->address_books[$id] = $contacts; diff --git a/program/include/rcube_addressbook.php b/program/include/rcube_addressbook.php index 5f17f4a8a..33f8f8a5b 100644 --- a/program/include/rcube_addressbook.php +++ b/program/include/rcube_addressbook.php @@ -44,6 +44,8 @@ abstract class rcube_addressbook public $group_id = null; public $list_page = 1; public $page_size = 10; + public $sort_col = 'name'; + public $sort_order = 'ASC'; public $coltypes = array('name' => array('limit'=>1), 'firstname' => array('limit'=>1), 'surname' => array('limit'=>1), 'email' => array('limit'=>1)); protected $error; @@ -180,6 +182,21 @@ abstract class rcube_addressbook $this->page_size = (int)$size; } + /** + * Set internal sort settings + * + * @param string $sort_col Sort column + * @param string $sort_order Sort order + */ + function set_sort_order($sort_col, $sort_order = null) + { + if ($sort_col != null && ($this->coltypes[$sort_col] || in_array($sort_col, $this->coltypes))) { + $this->sort_col = $sort_col; + } + if ($sort_order != null) { + $this->sort_order = strtoupper($sort_order) == 'DESC' ? 'DESC' : 'ASC'; + } + } /** * Check the given data before saving. diff --git a/program/include/rcube_contacts.php b/program/include/rcube_contacts.php index ab3b181a5..7cd317981 100644 --- a/program/include/rcube_contacts.php +++ b/program/include/rcube_contacts.php @@ -213,6 +213,16 @@ class rcube_contacts extends rcube_addressbook $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 @@ class rcube_contacts extends rcube_addressbook " 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, diff --git a/program/include/rcube_ldap.php b/program/include/rcube_ldap.php index 978c4e7e4..b82e17502 100644 --- a/program/include/rcube_ldap.php +++ b/program/include/rcube_ldap.php @@ -35,8 +35,6 @@ class rcube_ldap extends rcube_addressbook public $readonly = true; public $ready = false; public $group_id = 0; - public $list_page = 1; - public $page_size = 10; public $coltypes = array(); /** private properties */ @@ -47,7 +45,6 @@ class rcube_ldap extends rcube_addressbook protected $filter = ''; protected $result = null; protected $ldap_result = null; - protected $sort_col = ''; protected $mail_domain = ''; protected $debug = false; @@ -413,24 +410,15 @@ class rcube_ldap extends rcube_addressbook /** - * Set internal list page + * Set internal sort settings * - * @param number $page Page number to list + * @param string $sort_col Sort column + * @param string $sort_order Sort order */ - function set_page($page) + function set_sort_order($sort_col, $sort_order = null) { - $this->list_page = (int)$page; - } - - - /** - * Set internal page size - * - * @param number $size Number of messages to display on one page - */ - function set_pagesize($size) - { - $this->page_size = (int)$size; + if ($this->fieldmap[$sort_col]) + $this->sort_col = $this->fieldmap[$sort_col]; } diff --git a/program/include/rcube_mdb2.php b/program/include/rcube_mdb2.php index f1669677c..26e5e974a 100644 --- a/program/include/rcube_mdb2.php +++ b/program/include/rcube_mdb2.php @@ -633,6 +633,8 @@ class rcube_mdb2 { $func = ''; $args = func_get_args(); + if (is_array($args[0])) + $args = $args[0]; switch($this->db_provider) { case 'mysql': diff --git a/program/steps/addressbook/list.inc b/program/steps/addressbook/list.inc index b4b7306a6..71196b4bb 100644 --- a/program/steps/addressbook/list.inc +++ b/program/steps/addressbook/list.inc @@ -31,6 +31,7 @@ if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search $page = isset($_SESSION['page']) ? $_SESSION['page'] : 1; $_SESSION['page'] = $page; + $sort_col = $this->config->get('addressbook_sort_col', 'name'); // Get records from all sources foreach ($search as $s => $set) { @@ -46,7 +47,7 @@ if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search while ($row = $result->next()) { $row['sourceid'] = $s; - $key = $row['name'] . ':' . $row['sourceid']; + $key = $row[$sort_col] . ':' . $row['sourceid']; $records[$key] = $row; } unset($result); diff --git a/program/steps/settings/func.inc b/program/steps/settings/func.inc index fdb65ade9..a529b3b12 100644 --- a/program/steps/settings/func.inc +++ b/program/steps/settings/func.inc @@ -660,6 +660,20 @@ function rcmail_user_prefs($current=null) ); } + // show addressbook sort column + if (!isset($no_override['addressbook_sort_col'])) { + $field_id = 'rcmfd_addressbook_sort_col'; + $select_sort = new html_select(array('name' => '_addressbook_sort_col', 'id' => $field_id)); + $select_sort->add(rcube_label('name'), 'name'); + $select_sort->add(rcube_label('firstname'), 'firstname'); + $select_sort->add(rcube_label('surname'), 'surname'); + + $blocks['main']['options']['sort_col'] = array( + 'title' => html::label($field_id, Q(rcube_label('listsorting'))), + 'content' => $select_sort->show($config['addressbook_sort_col']), + ); + } + if (!isset($no_override['autocomplete_single'])) { $field_id = 'rcmfd_autocomplete_single'; $checkbox = new html_checkbox(array('name' => '_autocomplete_single', 'id' => $field_id, 'value' => 1)); diff --git a/program/steps/settings/save_prefs.inc b/program/steps/settings/save_prefs.inc index f5f3e36d3..0808c72bb 100644 --- a/program/steps/settings/save_prefs.inc +++ b/program/steps/settings/save_prefs.inc @@ -93,6 +93,7 @@ switch ($CURR_SECTION) case 'addressbook': $a_user_prefs = array( 'default_addressbook' => get_input_value('_default_addressbook', RCUBE_INPUT_POST, true), + 'addressbook_sort_col' => get_input_value('_addressbook_sort_col', RCUBE_INPUT_POST), 'autocomplete_single' => isset($_POST['_autocomplete_single']) ? TRUE : FALSE, ); |