4 +-----------------------------------------------------------------------+
5 | program/steps/mail/autocomplete.inc |
7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2008-2010, Roundcube Dev Team |
9 | Licensed under the GNU GPL |
12 | Perform a search on configured address books for the address |
13 | autocompletion of the message compose screen |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
18 $Id: autocomplete.inc 3989 2010-09-25 13:03:53Z alec $
23 $book_types = (array) $RCMAIL->config->get('autocomplete_addressbooks', 'sql');
25 if ($RCMAIL->action == 'group-expand') {
26 $abook = $RCMAIL->get_address_book(get_input_value('_source', RCUBE_INPUT_GPC));
27 if ($gid = get_input_value('_gid', RCUBE_INPUT_GPC)) {
29 $abook->set_group($gid);
30 $abook->set_pagesize(1000); // TODO: limit number of group members by config
31 $result = $abook->list_records(array('email','name'));
32 while ($result && ($sql_arr = $result->iterate()))
33 $members[] = format_email_recipient($sql_arr['email'], $sql_arr['name']);
35 $OUTPUT->command('replace_group_recipients', $gid, join(', ', $members));
38 else if ($book_types && $search = get_input_value('_search', RCUBE_INPUT_GPC, true)) {
40 $books_num = count($book_types);
42 foreach ($book_types as $id) {
43 $abook = $RCMAIL->get_address_book($id);
44 $abook->set_pagesize($MAXNUM);
46 if ($result = $abook->search(array('email','name'), $search, false, true, true, 'email')) {
47 while ($sql_arr = $result->iterate()) {
48 $contact = format_email_recipient($sql_arr['email'], $sql_arr['name']);
49 // when we've got more than one book, we need to skip duplicates
50 if ($books_num == 1 || !in_array($contact, $contacts)) {
51 $contacts[] = $contact;
52 if (count($contacts) >= $MAXNUM)
58 // also list matching contact groups
60 foreach ($abook->list_groups($search) as $group) {
62 $abook->set_group($group['ID']);
63 $result = $abook->count();
66 $contacts[] = array('name' => $group['name'] . ' (' . intval($result->count) . ')', 'id' => $group['ID'], 'source' => $id);
67 if (count($contacts) >= $MAXNUM)
74 usort($contacts, 'contact_results_sort');
77 $OUTPUT->command('ksearch_query_results', $contacts, $search);
81 function contact_results_sort($a, $b)
83 $name_a = is_array($a) ? $a['name'] : $a;
84 $name_b = is_array($b) ? $b['name'] : $b;
85 return strcoll(trim($name_a, '" '), trim($name_b, '" '));