]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/autocomplete.inc
Imported Upstream version 0.2~stable
[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, 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;  // same limit as in app.js
23 $contacts = array();
24
25 if ($search = get_input_value('_search', RCUBE_INPUT_POST)) {
26
27   foreach ($RCMAIL->config->get('autocomplete_addressbooks', array('sql')) as $id) {
28     $abook = $RCMAIL->get_address_book($id);
29     $abook->set_pagesize($MAXNUM);
30
31     if ($result = $abook->search(array('email','name'), $search)) {
32       while ($sql_arr = $result->iterate()) {
33         if (stripos((string)$sql_arr['email'], $search) !== false || stripos((string)$sql_arr['name'], $search) !== false) {
34           $contacts[] = format_email_recipient($sql_arr['email'], $sql_arr['name']);
35         }
36       }
37     }
38     
39     if (count($contacts) >= $MAXNUM)
40       break;
41   }
42   
43   sort($contacts);
44 }
45
46 $OUTPUT->command('ksearch_query_results', $contacts);
47 $OUTPUT->send();
48
49 ?>