]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/autocomplete.inc
Imported Upstream version 0.3
[roundcube.git] / program / steps / mail / autocomplete.inc
1 <?php
2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/steps/mail/autocomplete.inc                                   |
6  |                                                                       |
7  | This file is part of the RoundCube Webmail client                     |
8  | Copyright (C) 2008-2009, RoundCube Dev Team                           |
9  | Licensed under the GNU GPL                                            |
10  |                                                                       |
11  | PURPOSE:                                                              |
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  +-----------------------------------------------------------------------+
17
18  $Id: $
19
20 */
21
22 $MAXNUM = 15;
23 $contacts = array();
24 $book_types = (array) $RCMAIL->config->get('autocomplete_addressbooks', 'sql');
25
26 if ($book_types && $search = get_input_value('_search', RCUBE_INPUT_POST, true)) {
27
28   foreach ($book_types as $id) {
29     $abook = $RCMAIL->get_address_book($id);
30     $abook->set_pagesize($MAXNUM);
31
32     if ($result = $abook->search(array('email','name'), $search)) {
33       while ($sql_arr = $result->iterate()) {
34           $contacts[] = format_email_recipient($sql_arr['email'], $sql_arr['name']);
35           if (count($contacts) >= $MAXNUM)
36             break 2;
37       }
38     }
39   }
40   
41   sort($contacts);
42 }
43
44 $OUTPUT->command('ksearch_query_results', $contacts, $search);
45 $OUTPUT->send();
46
47 ?>