commit | author | age
|
eeb73c
|
1 |
<?php |
T |
2 |
|
a95874
|
3 |
/** |
eeb73c
|
4 |
+-----------------------------------------------------------------------+ |
T |
5 |
| program/steps/mail/list_contacts.inc | |
|
6 |
| | |
|
7 |
| This file is part of the Roundcube Webmail client | |
700e3c
|
8 |
| Copyright (C) 2012-2014, The Roundcube Dev Team | |
7fe381
|
9 |
| | |
T |
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. | |
eeb73c
|
13 |
| | |
T |
14 |
| PURPOSE: | |
|
15 |
| Send contacts list to client (as remote response) | |
|
16 |
| | |
|
17 |
+-----------------------------------------------------------------------+ |
|
18 |
| Author: Thomas Bruederli <roundcube@gmail.com> | |
|
19 |
+-----------------------------------------------------------------------+ |
|
20 |
*/ |
|
21 |
|
a5b79b
|
22 |
$afields = $RCMAIL->config->get('contactlist_fields'); |
AM |
23 |
$addr_sort_col = $RCMAIL->config->get('addressbook_sort_col', 'name'); |
|
24 |
$page_size = $RCMAIL->config->get('addressbook_pagesize', $RCMAIL->config->get('pagesize', 50)); |
|
25 |
$list_page = max(1, intval($_GET['_page'])); |
700e3c
|
26 |
$jsresult = array(); |
eeb73c
|
27 |
|
6c27c3
|
28 |
// Use search result |
TB |
29 |
if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']])) { |
|
30 |
$search = (array)$_SESSION['search'][$_REQUEST['_search']]; |
700e3c
|
31 |
$sparam = $_SESSION['search_params']['id'] == $_REQUEST['_search'] ? $_SESSION['search_params']['data'] : array(); |
eeb73c
|
32 |
|
6c27c3
|
33 |
// get records from all sources |
TB |
34 |
foreach ($search as $s => $set) { |
|
35 |
$CONTACTS = $RCMAIL->get_address_book($s); |
700e3c
|
36 |
|
TB |
37 |
// list matching groups of this source (on page one) |
|
38 |
if ($sparam[1] && $CONTACTS->groups && $list_page == 1) { |
|
39 |
$jsresult += rcmail_compose_contact_groups($CONTACTS, $s, $sparam[1], (int)$RCMAIL->config->get('addressbook_search_mode')); |
|
40 |
} |
eeb73c
|
41 |
|
6c27c3
|
42 |
// reset page |
TB |
43 |
$CONTACTS->set_page(1); |
|
44 |
$CONTACTS->set_pagesize(9999); |
|
45 |
$CONTACTS->set_search_set($set); |
|
46 |
|
|
47 |
// get records |
|
48 |
$result = $CONTACTS->list_records($afields); |
|
49 |
|
|
50 |
while ($row = $result->next()) { |
|
51 |
$row['sourceid'] = $s; |
a5b79b
|
52 |
$key = rcube_addressbook::compose_contact_key($row, $addr_sort_col); |
6c27c3
|
53 |
$records[$key] = $row; |
TB |
54 |
} |
|
55 |
unset($result); |
|
56 |
} |
|
57 |
|
|
58 |
// sort the records |
|
59 |
ksort($records, SORT_LOCALE_STRING); |
|
60 |
|
|
61 |
// create resultset object |
|
62 |
$count = count($records); |
a5b79b
|
63 |
$first = ($list_page-1) * $page_size; |
6c27c3
|
64 |
$result = new rcube_result_set($count, $first); |
TB |
65 |
|
|
66 |
// we need only records for current page |
|
67 |
if ($page_size < $count) { |
|
68 |
$records = array_slice($records, $first, $page_size); |
|
69 |
} |
|
70 |
|
|
71 |
$result->records = array_values($records); |
|
72 |
} |
|
73 |
// list contacts from selected source |
|
74 |
else { |
6b2b2e
|
75 |
$source = rcube_utils::get_input_value('_source', rcube_utils::INPUT_GPC); |
6c27c3
|
76 |
$CONTACTS = $RCMAIL->get_address_book($source); |
TB |
77 |
|
|
78 |
if ($CONTACTS && $CONTACTS->ready) { |
|
79 |
// set list properties |
|
80 |
$CONTACTS->set_pagesize($page_size); |
a5b79b
|
81 |
$CONTACTS->set_page($list_page); |
6c27c3
|
82 |
|
6b2b2e
|
83 |
if ($group_id = rcube_utils::get_input_value('_gid', rcube_utils::INPUT_GPC)) { |
86552f
|
84 |
$CONTACTS->set_group($group_id); |
TB |
85 |
} |
6c27c3
|
86 |
// list groups of this source (on page one) |
86552f
|
87 |
else if ($CONTACTS->groups && $CONTACTS->list_page == 1) { |
700e3c
|
88 |
$jsresult = rcmail_compose_contact_groups($CONTACTS, $source); |
eeb73c
|
89 |
} |
6c27c3
|
90 |
|
TB |
91 |
// get contacts for this user |
|
92 |
$result = $CONTACTS->list_records($afields); |
eeb73c
|
93 |
} |
6c27c3
|
94 |
} |
eeb73c
|
95 |
|
6c27c3
|
96 |
if (!empty($result) && !$result->count && $result->searchonly) { |
TB |
97 |
$OUTPUT->show_message('contactsearchonly', 'notice'); |
|
98 |
} |
|
99 |
else if (!empty($result) && $result->count > 0) { |
|
100 |
// create javascript list |
|
101 |
while ($row = $result->next()) { |
|
102 |
$name = rcube_addressbook::compose_list_name($row); |
eeb73c
|
103 |
|
6c27c3
|
104 |
// add record for every email address of the contact |
TB |
105 |
$emails = $CONTACTS->get_col_values('email', $row, true); |
|
106 |
foreach ($emails as $i => $email) { |
5224a6
|
107 |
$row_id = $row['ID'].'-'.$i; |
6c27c3
|
108 |
$jsresult[$row_id] = format_email_recipient($email, $name); |
86552f
|
109 |
$classname = $row['_type'] == 'group' ? 'group' : 'person'; |
TB |
110 |
$keyname = $row['_type'] == 'group' ? 'contactgroup' : 'contact'; |
|
111 |
|
6c27c3
|
112 |
$OUTPUT->command('add_contact_row', $row_id, array( |
827159
|
113 |
$keyname => html::a(array('title' => $email), rcube::Q($name ?: $email) . |
6b2b2e
|
114 |
($name && count($emails) > 1 ? ' ' . html::span('email', rcube::Q($email)) : '') |
86552f
|
115 |
)), $classname); |
eeb73c
|
116 |
} |
T |
117 |
} |
|
118 |
} |
|
119 |
|
6c27c3
|
120 |
|
eeb73c
|
121 |
// update env |
T |
122 |
$OUTPUT->set_env('contactdata', $jsresult); |
6c27c3
|
123 |
$OUTPUT->set_env('pagecount', ceil($result->count / $page_size)); |
eeb73c
|
124 |
$OUTPUT->command('set_page_buttons'); |
T |
125 |
|
|
126 |
// send response |
|
127 |
$OUTPUT->send(); |