source: github/program/steps/addressbook/list.inc @ 0203f16

HEADcourier-fixdev-browser-capabilitiespdorelease-0.8
Last change on this file since 0203f16 was 0203f16, checked in by alecpl <alec@…>, 15 months ago
  • Fix duplicate names handling in addressbook searches (#1488375)
  • Property mode set to 100644
File size: 3.2 KB
Line 
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-2012, The Roundcube Dev Team                       |
9 |                                                                       |
10 | Licensed under the GNU General Public License version 3 or            |
11 | any later version with exceptions for skins & plugins.                |
12 | See the README file for a full license statement.                     |
13 |                                                                       |
14 | PURPOSE:                                                              |
15 |   Send contacts list to client (as remote response)                   |
16 |                                                                       |
17 +-----------------------------------------------------------------------+
18 | Author: Thomas Bruederli <roundcube@gmail.com>                        |
19 +-----------------------------------------------------------------------+
20
21 $Id$
22
23*/
24
25// Use search result
26if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']]))
27{
28    $search  = (array)$_SESSION['search'][$_REQUEST['_search']];
29    $records = array();
30
31    if (!empty($_GET['_page']))
32        $page = intval($_GET['_page']);
33    else
34        $page = isset($_SESSION['page']) ? $_SESSION['page'] : 1;
35
36    $_SESSION['page'] = $page;
37    $sort_col = $this->config->get('addressbook_sort_col', 'name');
38
39    // Get records from all sources
40    foreach ($search as $s => $set) {
41        $source = $RCMAIL->get_address_book($s);
42
43        // reset page
44        $source->set_page(1);
45        $source->set_pagesize(9999);
46        $source->set_search_set($set);
47
48        // get records
49        $result = $source->list_records(array('name', 'email'));
50
51        while ($row = $result->next()) {
52            $row['sourceid'] = $s;
53            $key = rcmail_contact_key($row, $sort_col);
54            $records[$key] = $row;
55        }
56        unset($result);
57    }
58
59    // sort the records
60    ksort($records, SORT_LOCALE_STRING);
61
62    // create resultset object
63    $count    = count($records);
64    $first  = ($page-1) * $PAGE_SIZE;
65    $result = new rcube_result_set($count, $first);
66
67    // we need only records for current page
68    if ($PAGE_SIZE < $count) {
69        $records = array_slice($records, $first, $PAGE_SIZE);
70    }
71
72    $result->records = array_values($records);
73}
74// List selected directory
75else {
76    $CONTACTS = rcmail_contact_source(null, true);
77
78    // get contacts for this user
79    $result = $CONTACTS->list_records(array('name'));
80
81    if (!$result->count && $result->searchonly) {
82        $OUTPUT->show_message('contactsearchonly', 'notice');
83        $OUTPUT->command('command', 'advanced-search');
84    }
85}
86
87// update message count display
88$OUTPUT->set_env('pagecount', ceil($result->count / $PAGE_SIZE));
89$OUTPUT->command('set_rowcount', rcmail_get_rowcount_text($result));
90
91// create javascript list
92rcmail_js_contacts_list($result);
93
94// send response
95$OUTPUT->send();
Note: See TracBrowser for help on using the repository browser.