]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/addressbook/list.inc
Imported Upstream version 0.7
[roundcube.git] / program / steps / addressbook / list.inc
1 <?php
2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/steps/addressbook/list.inc                                    |
6  |                                                                       |
7  | This file is part of the Roundcube Webmail client                     |
8  | Copyright (C) 2005-2007, The Roundcube Dev Team                       |
9  | Licensed under the GNU GPL                                            |
10  |                                                                       |
11  | PURPOSE:                                                              |
12  |   Send contacts list to client (as remote response)                   |
13  |                                                                       |
14  +-----------------------------------------------------------------------+
15  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16  +-----------------------------------------------------------------------+
17
18  $Id: list.inc 5315 2011-10-06 12:31:38Z thomasb $
19
20 */
21
22 // Use search result
23 if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']]))
24 {
25     $search  = (array)$_SESSION['search'][$_REQUEST['_search']];
26     $records = array();
27
28     if (!empty($_GET['_page']))
29         $page = intval($_GET['_page']);
30     else
31         $page = isset($_SESSION['page']) ? $_SESSION['page'] : 1;
32
33     $_SESSION['page'] = $page;
34
35     // Get records from all sources
36     foreach ($search as $s => $set) {
37         $source = $RCMAIL->get_address_book($s);
38
39         // reset page
40         $source->set_page(1);
41         $source->set_pagesize(9999);
42         $source->set_search_set($set);
43
44         // get records
45         $result = $source->list_records(array('name', 'email'));
46
47         while ($row = $result->next()) {
48             $row['sourceid'] = $s;
49             $key = $row['name'] . ':' . $row['sourceid'];
50             $records[$key] = $row;
51         }
52         unset($result);
53     }
54
55     // sort the records
56     ksort($records, SORT_LOCALE_STRING);
57
58     // create resultset object
59     $count  = count($records);
60     $first  = ($page-1) * $CONFIG['pagesize'];
61     $result = new rcube_result_set($count, $first);
62
63     // we need only records for current page
64     if ($CONFIG['pagesize'] < $count) {
65         $records = array_slice($records, $first, $CONFIG['pagesize']);
66     }
67
68     $result->records = array_values($records);
69 }
70 // List selected directory
71 else {
72     $CONTACTS = rcmail_contact_source(null, true);
73
74     // get contacts for this user
75     $result = $CONTACTS->list_records(array('name'));
76     
77     if (!$result->count && $result->searchonly) {
78         $OUTPUT->show_message('contactsearchonly', 'notice');
79         $OUTPUT->command('command', 'advanced-search');
80     }
81 }
82
83 // update message count display
84 $OUTPUT->set_env('pagecount', ceil($result->count / $CONFIG['pagesize']));
85 $OUTPUT->command('set_rowcount', rcmail_get_rowcount_text($result));
86
87 // create javascript list
88 rcmail_js_contacts_list($result);
89
90 // send response
91 $OUTPUT->send();