annotate program/steps/addressbook/search.inc @ 0:4681f974d28b

vanilla 1.3.3 distro, I hope
author Charlie Root
date Thu, 04 Jan 2018 15:52:31 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1 <?php
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4 +-----------------------------------------------------------------------+
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5 | program/steps/addressbook/search.inc |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6 | |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7 | This file is part of the Roundcube Webmail client |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8 | Copyright (C) 2005-2011, The Roundcube Dev Team |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9 | Copyright (C) 2011, Kolab Systems AG |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
10 | |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
11 | Licensed under the GNU General Public License version 3 or |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
12 | any later version with exceptions for skins & plugins. |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
13 | See the README file for a full license statement. |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
14 | |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
15 | PURPOSE: |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
16 | Search action (and form) for address book contacts |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
17 | |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
18 +-----------------------------------------------------------------------+
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
19 | Author: Thomas Bruederli <roundcube@gmail.com> |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
20 | Author: Aleksander Machniak <machniak@kolabsys.com> |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
21 +-----------------------------------------------------------------------+
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
22 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
23
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
24 if ($RCMAIL->action == 'search-create') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
25 $id = rcube_utils::get_input_value('_search', rcube_utils::INPUT_POST);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
26 $name = rcube_utils::get_input_value('_name', rcube_utils::INPUT_POST, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
27
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
28 if (($params = $_SESSION['search_params']) && $params['id'] == $id) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
29
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
30 $data = array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
31 'type' => rcube_user::SEARCH_ADDRESSBOOK,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
32 'name' => $name,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
33 'data' => array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
34 'fields' => $params['data'][0],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
35 'search' => $params['data'][1],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
36 ),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
37 );
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
38
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
39 $plugin = $RCMAIL->plugins->exec_hook('saved_search_create', array('data' => $data));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
40
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
41 if (!$plugin['abort'])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
42 $result = $RCMAIL->user->insert_search($plugin['data']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
43 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
44 $result = $plugin['result'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
45 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
46
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
47 if ($result) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
48 $OUTPUT->show_message('savedsearchcreated', 'confirmation');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
49 $OUTPUT->command('insert_saved_search', rcube::Q($name), rcube::Q($result));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
50 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
51 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
52 $OUTPUT->show_message($plugin['message'] ?: 'savedsearchcreateerror', 'error');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
53
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
54 $OUTPUT->send();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
55 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
56
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
57 if ($RCMAIL->action == 'search-delete') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
58 $id = rcube_utils::get_input_value('_sid', rcube_utils::INPUT_POST);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
59
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
60 $plugin = $RCMAIL->plugins->exec_hook('saved_search_delete', array('id' => $id));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
61
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
62 if (!$plugin['abort'])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
63 $result = $RCMAIL->user->delete_search($id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
64 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
65 $result = $plugin['result'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
66
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
67 if ($result) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
68 $OUTPUT->show_message('savedsearchdeleted', 'confirmation');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
69 $OUTPUT->command('remove_search_item', rcube::Q($id));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
70 // contact list will be cleared, clear also page counter
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
71 $OUTPUT->command('set_rowcount', $RCMAIL->gettext('nocontactsfound'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
72 $OUTPUT->set_env('pagecount', 0);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
73 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
74 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
75 $OUTPUT->show_message($plugin['message'] ?: 'savedsearchdeleteerror', 'error');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
76
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
77 $OUTPUT->send();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
78 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
79
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
80
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
81 if (!isset($_GET['_form'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
82 rcmail_contact_search();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
83 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
84
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
85 $OUTPUT->add_handler('searchform', 'rcmail_contact_search_form');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
86 $OUTPUT->send('contactsearch');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
87
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
88
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
89 function rcmail_contact_search()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
90 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
91 global $RCMAIL, $OUTPUT, $SEARCH_MODS_DEFAULT, $PAGE_SIZE;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
92
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
93 $adv = isset($_POST['_adv']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
94 $sid = rcube_utils::get_input_value('_sid', rcube_utils::INPUT_GET);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
95
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
96 // get search criteria from saved search
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
97 if ($sid && ($search = $RCMAIL->user->get_search($sid))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
98 $fields = $search['data']['fields'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
99 $search = $search['data']['search'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
100 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
101 // get fields/values from advanced search form
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
102 else if ($adv) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
103 foreach (array_keys($_POST) as $key) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
104 $s = trim(rcube_utils::get_input_value($key, rcube_utils::INPUT_POST, true));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
105 if (strlen($s) && preg_match('/^_search_([a-zA-Z0-9_-]+)$/', $key, $m)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
106 $search[] = $s;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
107 $fields[] = $m[1];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
108 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
109 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
110
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
111 if (empty($fields)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
112 // do nothing, show the form again
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
113 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
114 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
115 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
116 // quick-search
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
117 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
118 $search = trim(rcube_utils::get_input_value('_q', rcube_utils::INPUT_GET, true));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
119 $fields = explode(',', rcube_utils::get_input_value('_headers', rcube_utils::INPUT_GET));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
120
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
121 if (empty($fields)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
122 $fields = array_keys($SEARCH_MODS_DEFAULT);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
123 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
124 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
125 $fields = array_filter($fields);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
126 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
127
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
128 // update search_mods setting
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
129 $old_mods = $RCMAIL->config->get('addressbook_search_mods');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
130 $search_mods = array_fill_keys($fields, 1);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
131 if ($old_mods != $search_mods) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
132 $RCMAIL->user->save_prefs(array('addressbook_search_mods' => $search_mods));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
133 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
134
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
135 if (in_array('*', $fields)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
136 $fields = '*';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
137 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
138 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
139
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
140 // Values matching mode
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
141 $mode = (int) $RCMAIL->config->get('addressbook_search_mode');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
142 $mode |= rcube_addressbook::SEARCH_GROUPS;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
143
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
144 // get sources list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
145 $sources = $RCMAIL->get_address_sources();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
146 $search_set = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
147 $records = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
148 $sort_col = $RCMAIL->config->get('addressbook_sort_col', 'name');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
149 $afields = $RCMAIL->config->get('contactlist_fields');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
150
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
151 foreach ($sources as $s) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
152 $source = $RCMAIL->get_address_book($s['id']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
153
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
154 // check if search fields are supported....
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
155 if (is_array($fields)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
156 $cols = $source->coltypes[0] ? array_flip($source->coltypes) : $source->coltypes;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
157 $supported = 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
158
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
159 foreach ($fields as $f) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
160 if (array_key_exists($f, $cols)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
161 $supported ++;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
162 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
163 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
164
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
165 // in advanced search we require all fields (AND operator)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
166 // in quick search we require at least one field (OR operator)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
167 if (($adv && $supported < count($fields)) || (!$adv && !$supported)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
168 continue;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
169 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
170 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
171
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
172 // reset page
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
173 $source->set_page(1);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
174 $source->set_pagesize(9999);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
175
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
176 // get contacts count
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
177 $result = $source->search($fields, $search, $mode, false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
178
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
179 if (!$result->count) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
180 continue;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
181 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
182
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
183 // get records
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
184 $result = $source->list_records($afields);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
185
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
186 while ($row = $result->next()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
187 $row['sourceid'] = $s['id'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
188 $key = rcube_addressbook::compose_contact_key($row, $sort_col);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
189 $records[$key] = $row;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
190 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
191
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
192 unset($result);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
193 $search_set[$s['id']] = $source->get_search_set();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
194 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
195
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
196 // sort the records
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
197 ksort($records, SORT_LOCALE_STRING);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
198
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
199 // create resultset object
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
200 $count = count($records);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
201 $result = new rcube_result_set($count);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
202
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
203 // cut first-page records
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
204 if ($PAGE_SIZE < $count) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
205 $records = array_slice($records, 0, $PAGE_SIZE);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
206 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
207
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
208 $result->records = array_values($records);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
209
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
210 // search request ID
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
211 $search_request = md5('addr'
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
212 .(is_array($fields) ? implode($fields, ',') : $fields)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
213 .(is_array($search) ? implode($search, ',') : $search));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
214
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
215 // save search settings in session
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
216 $_SESSION['search'][$search_request] = $search_set;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
217 $_SESSION['search_params'] = array('id' => $search_request, 'data' => array($fields, $search));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
218 $_SESSION['page'] = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
219
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
220 if ($adv)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
221 $OUTPUT->command('list_contacts_clear');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
222
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
223 if ($result->count > 0) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
224 // create javascript list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
225 rcmail_js_contacts_list($result);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
226 $OUTPUT->show_message('contactsearchsuccessful', 'confirmation', array('nr' => $result->count));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
227 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
228 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
229 $OUTPUT->show_message('nocontactsfound', 'notice');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
230 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
231
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
232 // update message count display
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
233 $OUTPUT->set_env('search_request', $search_request);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
234 $OUTPUT->set_env('pagecount', ceil($result->count / $PAGE_SIZE));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
235 $OUTPUT->command('set_rowcount', rcmail_get_rowcount_text($result));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
236 // Re-set current source
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
237 $OUTPUT->set_env('search_id', $sid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
238 $OUTPUT->set_env('source', '');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
239 $OUTPUT->set_env('group', '');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
240 // Re-set list header
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
241 $OUTPUT->command('set_group_prop', null);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
242
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
243 if ($adv) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
244 $OUTPUT->command('parent.set_env', array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
245 'search_request' => $search_request,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
246 'pagecount' => ceil($result->count / $PAGE_SIZE),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
247 'search_id' => $sid,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
248 'source' => '',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
249 'group' => '',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
250 ));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
251 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
252
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
253 if (!$sid) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
254 // unselect currently selected directory/group
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
255 $OUTPUT->command('unselect_directory');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
256 // enable "Save search" command
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
257 $OUTPUT->command('enable_command', 'search-create', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
258 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
259 $OUTPUT->command('update_group_commands');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
260
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
261 // send response
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
262 $OUTPUT->send($adv ? 'iframe' : null);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
263 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
264
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
265 function rcmail_contact_search_form($attrib)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
266 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
267 global $RCMAIL, $CONTACT_COLTYPES;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
268
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
269 $i_size = $attrib['size'] ?: 30;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
270
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
271 $form = array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
272 'main' => array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
273 'name' => $RCMAIL->gettext('properties'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
274 'content' => array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
275 ),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
276 ),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
277 'personal' => array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
278 'name' => $RCMAIL->gettext('personalinfo'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
279 'content' => array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
280 ),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
281 ),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
282 'other' => array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
283 'name' => $RCMAIL->gettext('other'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
284 'content' => array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
285 ),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
286 ),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
287 );
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
288
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
289 // get supported coltypes from all address sources
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
290 $sources = $RCMAIL->get_address_sources();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
291 $coltypes = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
292
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
293 foreach ($sources as $s) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
294 $CONTACTS = $RCMAIL->get_address_book($s['id']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
295
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
296 if (is_array($CONTACTS->coltypes)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
297 $contact_cols = $CONTACTS->coltypes[0] ? array_flip($CONTACTS->coltypes) : $CONTACTS->coltypes;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
298 $coltypes = array_merge($coltypes, $contact_cols);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
299 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
300 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
301
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
302 // merge supported coltypes with $CONTACT_COLTYPES
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
303 foreach ($coltypes as $col => $colprop) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
304 $coltypes[$col] = $CONTACT_COLTYPES[$col] ? array_merge($CONTACT_COLTYPES[$col], (array)$colprop) : (array)$colprop;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
305 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
306
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
307 // build form fields list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
308 foreach ($coltypes as $col => $colprop)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
309 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
310 if ($colprop['type'] != 'image' && !$colprop['nosearch'])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
311 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
312 $ftype = $colprop['type'] == 'select' ? 'select' : 'text';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
313 $label = isset($colprop['label']) ? $colprop['label'] : $RCMAIL->gettext($col);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
314 $category = $colprop['category'] ?: 'other';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
315
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
316 // load jquery UI datepicker for date fields
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
317 if ($colprop['type'] == 'date')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
318 $colprop['class'] .= ($colprop['class'] ? ' ' : '') . 'datepicker';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
319 else if ($ftype == 'text')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
320 $colprop['size'] = $i_size;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
321
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
322
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
323 $content = html::div('row', html::div('contactfieldlabel label', rcube::Q($label))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
324 . html::div('contactfieldcontent', rcube_output::get_edit_field('search_'.$col, '', $colprop, $ftype)));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
325
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
326 $form[$category]['content'][] = $content;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
327 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
328 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
329
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
330 $hiddenfields = new html_hiddenfield();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
331 $hiddenfields->add(array('name' => '_adv', 'value' => 1));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
332
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
333 $out = $RCMAIL->output->request_form(array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
334 'name' => 'form', 'method' => 'post',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
335 'task' => $RCMAIL->task, 'action' => 'search',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
336 'noclose' => true) + $attrib, $hiddenfields->show());
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
337
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
338 $RCMAIL->output->add_gui_object('editform', $attrib['id']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
339
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
340 unset($attrib['name']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
341 unset($attrib['id']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
342
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
343 foreach ($form as $f) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
344 if (!empty($f['content'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
345 $content = html::div('contactfieldgroup', join("\n", $f['content']));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
346
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
347 $out .= html::tag('fieldset', $attrib,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
348 html::tag('legend', null, rcube::Q($f['name']))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
349 . $content) . "\n";
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
350 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
351 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
352
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
353 return $out . '</form>';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
354 }