comparison program/steps/mail/list_contacts.inc @ 0:4681f974d28b

vanilla 1.3.3 distro, I hope
author Charlie Root
date Thu, 04 Jan 2018 15:52:31 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4681f974d28b
1 <?php
2
3 /**
4 +-----------------------------------------------------------------------+
5 | program/steps/mail/list_contacts.inc |
6 | |
7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2012-2014, 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
22 $afields = $RCMAIL->config->get('contactlist_fields');
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']));
26 $jsresult = array();
27
28 // Use search result
29 if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']])) {
30 $search = (array)$_SESSION['search'][$_REQUEST['_search']];
31 $sparam = $_SESSION['search_params']['id'] == $_REQUEST['_search'] ? $_SESSION['search_params']['data'] : array();
32
33 // get records from all sources
34 foreach ($search as $s => $set) {
35 $CONTACTS = $RCMAIL->get_address_book($s);
36
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 }
41
42 // reset page
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;
52 $key = rcube_addressbook::compose_contact_key($row, $addr_sort_col);
53 $records[$key] = $row;
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);
63 $first = ($list_page-1) * $page_size;
64 $result = new rcube_result_set($count, $first);
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 {
75 $source = rcube_utils::get_input_value('_source', rcube_utils::INPUT_GPC);
76 $CONTACTS = $RCMAIL->get_address_book($source);
77
78 if ($CONTACTS && $CONTACTS->ready) {
79 // set list properties
80 $CONTACTS->set_pagesize($page_size);
81 $CONTACTS->set_page($list_page);
82
83 if ($group_id = rcube_utils::get_input_value('_gid', rcube_utils::INPUT_GET)) {
84 $CONTACTS->set_group($group_id);
85 }
86 // list groups of this source (on page one)
87 else if ($CONTACTS->groups && $CONTACTS->list_page == 1) {
88 $jsresult = rcmail_compose_contact_groups($CONTACTS, $source);
89 }
90
91 // get contacts for this user
92 $result = $CONTACTS->list_records($afields);
93 }
94 }
95
96 if (!empty($result) && !$result->count && $result->searchonly) {
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);
103
104 // add record for every email address of the contact
105 $emails = $CONTACTS->get_col_values('email', $row, true);
106 foreach ($emails as $i => $email) {
107 $row_id = $row['ID'].'-'.$i;
108 $jsresult[$row_id] = format_email_recipient($email, $name);
109 $classname = $row['_type'] == 'group' ? 'group' : 'person';
110 $keyname = $row['_type'] == 'group' ? 'contactgroup' : 'contact';
111
112 $OUTPUT->command('add_contact_row', $row_id, array(
113 $keyname => html::a(array('title' => $email), rcube::Q($name ?: $email) .
114 ($name && count($emails) > 1 ? '&nbsp;' . html::span('email', rcube::Q($email)) : '')
115 )), $classname);
116 }
117 }
118 }
119
120 // update env
121 $OUTPUT->set_env('contactdata', $jsresult);
122 $OUTPUT->set_env('pagecount', ceil($result->count / $page_size));
123 $OUTPUT->command('set_page_buttons');
124
125 // send response
126 $OUTPUT->send();