summaryrefslogtreecommitdiff
path: root/program/steps/mail/autocomplete.inc
diff options
context:
space:
mode:
authorthomascube <thomas@roundcube.net>2010-03-31 15:23:22 +0000
committerthomascube <thomas@roundcube.net>2010-03-31 15:23:22 +0000
commitc0297f4172da47a20350d597176ecafee47c97bb (patch)
treefc7ce0fc563577c996654d1e123ead119a5a2245 /program/steps/mail/autocomplete.inc
parent3baa72a62fc69dda8306674da6d150efbf2cd55b (diff)
Asynchronously expand contact groups + skip count queries in autocompletion mode + check for the existance of contactgroups table
Diffstat (limited to 'program/steps/mail/autocomplete.inc')
-rw-r--r--program/steps/mail/autocomplete.inc27
1 files changed, 18 insertions, 9 deletions
diff --git a/program/steps/mail/autocomplete.inc b/program/steps/mail/autocomplete.inc
index 1e56fb222..724f14af5 100644
--- a/program/steps/mail/autocomplete.inc
+++ b/program/steps/mail/autocomplete.inc
@@ -20,16 +20,28 @@
*/
$MAXNUM = 15;
-$contacts = array();
$book_types = (array) $RCMAIL->config->get('autocomplete_addressbooks', 'sql');
-if ($book_types && $search = get_input_value('_search', RCUBE_INPUT_GPC, true)) {
+if ($RCMAIL->action == 'group-expand') {
+ $abook = $RCMAIL->get_address_book(get_input_value('_source', RCUBE_INPUT_GPC));
+ if ($gid = get_input_value('_gid', RCUBE_INPUT_GPC)) {
+ $members = array();
+ $abook->set_pagesize(1000); // TODO: limit number of group members by config
+ $result = $abook->list_records(array('email','name'));
+ while ($result && ($sql_arr = $result->iterate()))
+ $members[] = format_email_recipient($sql_arr['email'], $sql_arr['name']);
+
+ $OUTPUT->command('replace_group_recipients', $gid, join(', ', $members));
+ }
+}
+else if ($book_types && $search = get_input_value('_search', RCUBE_INPUT_GPC, true)) {
+ $contacts = array();
foreach ($book_types as $id) {
$abook = $RCMAIL->get_address_book($id);
$abook->set_pagesize($MAXNUM);
- if ($result = $abook->search(array('email','name'), $search)) {
+ if ($result = $abook->search(array('email','name'), $search, false, true, true)) {
while ($sql_arr = $result->iterate()) {
$contacts[] = format_email_recipient($sql_arr['email'], $sql_arr['name']);
if (count($contacts) >= $MAXNUM)
@@ -40,15 +52,12 @@ if ($book_types && $search = get_input_value('_search', RCUBE_INPUT_GPC, true))
// also list matching contact groups
if ($abook->groups) {
foreach ($abook->list_groups($search) as $group) {
- $members = array();
$abook->reset();
$abook->set_group($group['ID']);
- $result = $abook->list_records(array('email','name'));
- while ($result && ($sql_arr = $result->iterate()))
- $members[] = format_email_recipient($sql_arr['email'], $sql_arr['name']);
+ $result = $abook->count();
- if (count($members)) {
- $contacts[] = array('name' => $group['name'] . ' (' . rcube_label('group') . ')', 'members' => $members);
+ if ($result->count) {
+ $contacts[] = array('name' => $group['name'] . ' (' . intval($result->count) . ')', 'id' => $group['ID'], 'source' => $id);
if (count($contacts) >= $MAXNUM)
break;
}