Mercurial > hg > rc2
comparison program/steps/mail/search_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/search_contacts.inc | | |
6 | | | |
7 | This file is part of the Roundcube Webmail client | | |
8 | Copyright (C) 2013-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 | Search contacts from the address book widget | | |
16 | | | |
17 +-----------------------------------------------------------------------+ | |
18 | Author: Thomas Bruederli <roundcube@gmail.com> | | |
19 +-----------------------------------------------------------------------+ | |
20 */ | |
21 | |
22 $search = rcube_utils::get_input_value('_q', rcube_utils::INPUT_GPC, true); | |
23 $sources = $RCMAIL->get_address_sources(); | |
24 $search_mode = (int) $RCMAIL->config->get('addressbook_search_mode'); | |
25 $addr_sort_col = $RCMAIL->config->get('addressbook_sort_col', 'name'); | |
26 $afields = $RCMAIL->config->get('contactlist_fields'); | |
27 $page_size = $RCMAIL->config->get('addressbook_pagesize', $RCMAIL->config->get('pagesize', 50)); | |
28 $records = array(); | |
29 $search_set = array(); | |
30 $jsresult = array(); | |
31 $search_mode |= rcube_addressbook::SEARCH_GROUPS; | |
32 | |
33 foreach ($sources as $s) { | |
34 $source = $RCMAIL->get_address_book($s['id']); | |
35 $source->set_page(1); | |
36 $source->set_pagesize(9999); | |
37 | |
38 // list matching groups of this source | |
39 if ($source->groups) { | |
40 $jsresult += rcmail_compose_contact_groups($source, $s['id'], $search, $search_mode); | |
41 } | |
42 | |
43 // get contacts count | |
44 $result = $source->search($afields, $search, $search_mode, true, true, 'email'); | |
45 | |
46 if (!$result->count) { | |
47 continue; | |
48 } | |
49 | |
50 while ($row = $result->next()) { | |
51 $row['sourceid'] = $s['id']; | |
52 $key = rcube_addressbook::compose_contact_key($row, $addr_sort_col); | |
53 $records[$key] = $row; | |
54 } | |
55 | |
56 $search_set[$s['id']] = $source->get_search_set(); | |
57 unset($result); | |
58 } | |
59 | |
60 $group_count = count($jsresult); | |
61 | |
62 // sort the records | |
63 ksort($records, SORT_LOCALE_STRING); | |
64 | |
65 // create resultset object | |
66 $count = count($records); | |
67 $result = new rcube_result_set($count); | |
68 | |
69 // select the requested page | |
70 if ($page_size < $count) { | |
71 $records = array_slice($records, $result->first, $page_size); | |
72 } | |
73 | |
74 $result->records = array_values($records); | |
75 | |
76 if (!empty($result) && $result->count > 0) { | |
77 // create javascript list | |
78 while ($row = $result->next()) { | |
79 $name = rcube_addressbook::compose_list_name($row); | |
80 $classname = $row['_type'] == 'group' ? 'group' : 'person'; | |
81 $keyname = $row['_type'] == 'group' ? 'contactgroup' : 'contact'; | |
82 | |
83 // add record for every email address of the contact | |
84 // (same as in list_contacts.inc) | |
85 $emails = $source->get_col_values('email', $row, true); | |
86 foreach ($emails as $i => $email) { | |
87 $row_id = $row['ID'].'-'.$i; | |
88 $jsresult[$row_id] = format_email_recipient($email, $name); | |
89 $title = rcube_addressbook::compose_search_name($row, $email, $name); | |
90 | |
91 $OUTPUT->command('add_contact_row', $row_id, array( | |
92 $keyname => html::a(array('title' => $title), rcube::Q($name ?: $email) . | |
93 ($name && count($emails) > 1 ? ' ' . html::span('email', rcube::Q($email)) : '') | |
94 )), $classname); | |
95 } | |
96 } | |
97 | |
98 // search request ID | |
99 $search_request = md5('composeaddr' . $search); | |
100 | |
101 // save search settings in session | |
102 $_SESSION['search'][$search_request] = $search_set; | |
103 $_SESSION['search_params'] = array('id' => $search_request, 'data' => array($afields, $search)); | |
104 | |
105 $OUTPUT->show_message('contactsearchsuccessful', 'confirmation', array('nr' => $result->count)); | |
106 | |
107 $OUTPUT->set_env('search_request', $search_request); | |
108 $OUTPUT->set_env('source', ''); | |
109 $OUTPUT->command('unselect_directory'); | |
110 } | |
111 else if (!$group_count) { | |
112 $OUTPUT->show_message('nocontactsfound', 'notice'); | |
113 } | |
114 | |
115 // update env | |
116 $OUTPUT->set_env('contactdata', $jsresult); | |
117 $OUTPUT->set_env('pagecount', ceil($result->count / $page_size)); | |
118 $OUTPUT->command('set_page_buttons'); | |
119 | |
120 // send response | |
121 $OUTPUT->send(); |