commit | author | age
|
4e17e6
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
+-----------------------------------------------------------------------+ |
|
5 |
| program/steps/addressbook/func.inc | |
|
6 |
| | |
e019f2
|
7 |
| This file is part of the Roundcube Webmail client | |
f5e7b3
|
8 |
| Copyright (C) 2005-2007, The Roundcube Dev Team | |
30233b
|
9 |
| Licensed under the GNU GPL | |
4e17e6
|
10 |
| | |
T |
11 |
| PURPOSE: | |
|
12 |
| Provide addressbook functionality and GUI objects | |
|
13 |
| | |
|
14 |
+-----------------------------------------------------------------------+ |
|
15 |
| Author: Thomas Bruederli <roundcube@gmail.com> | |
|
16 |
+-----------------------------------------------------------------------+ |
|
17 |
|
|
18 |
$Id$ |
|
19 |
|
|
20 |
*/ |
|
21 |
|
3cacf9
|
22 |
$SEARCH_MODS_DEFAULT = array('name'=>1, 'firstname'=>1, 'surname'=>1, 'email'=>1, '*'=>1); |
A |
23 |
|
0501b6
|
24 |
// general definition of contact coltypes |
T |
25 |
$CONTACT_COLTYPES = array( |
57ce50
|
26 |
'name' => array('type' => 'text', 'size' => 40, 'maxlength' => 50, 'limit' => 1, 'label' => rcube_label('name'), 'category' => 'main'), |
T |
27 |
'firstname' => array('type' => 'text', 'size' => 19, 'maxlength' => 50, 'limit' => 1, 'label' => rcube_label('firstname'), 'category' => 'main'), |
|
28 |
'surname' => array('type' => 'text', 'size' => 19, 'maxlength' => 50, 'limit' => 1, 'label' => rcube_label('surname'), 'category' => 'main'), |
|
29 |
'email' => array('type' => 'text', 'size' => 40, 'maxlength' => 50, 'label' => rcube_label('email'), 'subtypes' => array('home','work','other'), 'category' => 'main'), |
|
30 |
'middlename' => array('type' => 'text', 'size' => 19, 'maxlength' => 50, 'limit' => 1, 'label' => rcube_label('middlename'), 'category' => 'main'), |
|
31 |
'prefix' => array('type' => 'text', 'size' => 8, 'maxlength' => 20, 'limit' => 1, 'label' => rcube_label('nameprefix'), 'category' => 'main'), |
|
32 |
'suffix' => array('type' => 'text', 'size' => 8, 'maxlength' => 20, 'limit' => 1, 'label' => rcube_label('namesuffix'), 'category' => 'main'), |
|
33 |
'nickname' => array('type' => 'text', 'size' => 40, 'maxlength' => 50, 'limit' => 1, 'label' => rcube_label('nickname'), 'category' => 'main'), |
|
34 |
'jobtitle' => array('type' => 'text', 'size' => 40, 'maxlength' => 50, 'limit' => 1, 'label' => rcube_label('jobtitle'), 'category' => 'main'), |
|
35 |
'organization' => array('type' => 'text', 'size' => 40, 'maxlength' => 50, 'limit' => 1, 'label' => rcube_label('organization'), 'category' => 'main'), |
|
36 |
'department' => array('type' => 'text', 'size' => 40, 'maxlength' => 50, 'limit' => 1, 'label' => rcube_label('department'), 'category' => 'main'), |
e9a9f2
|
37 |
'gender' => array('type' => 'select', 'limit' => 1, 'label' => rcube_label('gender'), 'options' => array('male' => rcube_label('male'), 'female' => rcube_label('female')), 'category' => 'personal'), |
57ce50
|
38 |
'maidenname' => array('type' => 'text', 'size' => 40, 'maxlength' => 50, 'limit' => 1, 'label' => rcube_label('maidenname'), 'category' => 'personal'), |
T |
39 |
'phone' => array('type' => 'text', 'size' => 40, 'maxlength' => 20, 'label' => rcube_label('phone'), 'subtypes' => array('home','home2','work','work2','mobile','main','homefax','workfax','car','pager','video','assistant','other'), 'category' => 'main'), |
0501b6
|
40 |
'address' => array('type' => 'composite', 'label' => rcube_label('address'), 'subtypes' => array('home','work','other'), 'childs' => array( |
57ce50
|
41 |
'street' => array('type' => 'text', 'size' => 40, 'maxlength' => 50, 'label' => rcube_label('street'), 'category' => 'main'), |
T |
42 |
'locality' => array('type' => 'text', 'size' => 28, 'maxlength' => 50, 'label' => rcube_label('locality'), 'category' => 'main'), |
|
43 |
'zipcode' => array('type' => 'text', 'size' => 8, 'maxlength' => 15, 'label' => rcube_label('zipcode'), 'category' => 'main'), |
|
44 |
'region' => array('type' => 'text', 'size' => 12, 'maxlength' => 50, 'label' => rcube_label('region'), 'category' => 'main'), |
|
45 |
'country' => array('type' => 'text', 'size' => 40, 'maxlength' => 50, 'label' => rcube_label('country'), 'category' => 'main'), |
e9a9f2
|
46 |
), 'category' => 'main'), |
57ce50
|
47 |
'birthday' => array('type' => 'date', 'size' => 12, 'maxlength' => 16, 'label' => rcube_label('birthday'), 'limit' => 1, 'render_func' => 'rcmail_format_date_col', 'category' => 'personal'), |
T |
48 |
'anniversary' => array('type' => 'date', 'size' => 12, 'maxlength' => 16, 'label' => rcube_label('anniversary'), 'limit' => 1, 'render_func' => 'rcmail_format_date_col', 'category' => 'personal'), |
dbb0c2
|
49 |
'website' => array('type' => 'text', 'size' => 40, 'maxlength' => 50, 'label' => rcube_label('website'), 'subtypes' => array('homepage','work','blog','profile','other'), 'category' => 'main'), |
57ce50
|
50 |
'im' => array('type' => 'text', 'size' => 40, 'maxlength' => 50, 'label' => rcube_label('instantmessenger'), 'subtypes' => array('aim','icq','msn','yahoo','jabber','skype','other'), 'category' => 'main'), |
T |
51 |
'notes' => array('type' => 'textarea', 'size' => 40, 'rows' => 15, 'maxlength' => 500, 'label' => rcube_label('notes'), 'limit' => 1), |
e9a9f2
|
52 |
'photo' => array('type' => 'image', 'limit' => 1, 'category' => 'main'), |
57ce50
|
53 |
'assistant' => array('type' => 'text', 'size' => 40, 'maxlength' => 50, 'limit' => 1, 'label' => rcube_label('assistant'), 'category' => 'personal'), |
T |
54 |
'manager' => array('type' => 'text', 'size' => 40, 'maxlength' => 50, 'limit' => 1, 'label' => rcube_label('manager'), 'category' => 'personal'), |
|
55 |
'spouse' => array('type' => 'text', 'size' => 40, 'maxlength' => 50, 'limit' => 1, 'label' => rcube_label('spouse'), 'category' => 'personal'), |
0501b6
|
56 |
// TODO: define fields for vcards like GEO, KEY |
T |
57 |
); |
|
58 |
|
ecf295
|
59 |
|
A |
60 |
// Addressbook UI |
|
61 |
if (!$RCMAIL->action && !$OUTPUT->ajax_call) { |
|
62 |
// add list of address sources to client env |
|
63 |
$js_list = $RCMAIL->get_address_sources(); |
|
64 |
|
ca7dda
|
65 |
$source = get_input_value('_source', RCUBE_INPUT_GPC); |
A |
66 |
|
ecf295
|
67 |
// use first directory by default |
ca7dda
|
68 |
if (!strlen($source) || !isset($js_list[$source])) |
A |
69 |
$source = $js_list[key($js_list)]['id']; |
ecf295
|
70 |
|
5c9d1f
|
71 |
// count all/writeable sources |
5b3ac3
|
72 |
$writeable = 0; |
5c9d1f
|
73 |
$count = 0; |
A |
74 |
foreach ($js_list as $sid => $s) { |
|
75 |
$count++; |
ecf295
|
76 |
if (!$s['readonly']) { |
5b3ac3
|
77 |
$writeable++; |
5c9d1f
|
78 |
} |
A |
79 |
// unset hidden sources |
|
80 |
if ($s['hidden']) { |
|
81 |
unset($js_list[$sid]); |
ecf295
|
82 |
} |
0501b6
|
83 |
} |
ecf295
|
84 |
|
A |
85 |
$search_mods = $RCMAIL->config->get('addressbook_search_mods', $SEARCH_MODS_DEFAULT); |
|
86 |
$OUTPUT->set_env('search_mods', $search_mods); |
|
87 |
$OUTPUT->set_env('address_sources', $js_list); |
5b3ac3
|
88 |
$OUTPUT->set_env('writable_source', $writeable); |
ecf295
|
89 |
|
A |
90 |
$OUTPUT->set_pagetitle(rcube_label('addressbook')); |
5c9d1f
|
91 |
$_SESSION['addressbooks_count'] = $count; |
5b3ac3
|
92 |
$_SESSION['addressbooks_count_writeable'] = $writeable; |
5c9d1f
|
93 |
|
fa5996
|
94 |
if (!strlen($source)) |
T |
95 |
$source = strval(key($js_list)); |
ecf295
|
96 |
|
A |
97 |
$CONTACTS = rcmail_contact_source($source, true); |
0501b6
|
98 |
} |
T |
99 |
|
7f5a84
|
100 |
// remove undo information... |
A |
101 |
if ($undo = $_SESSION['contact_undo']) { |
63fda8
|
102 |
// ...after timeout |
A |
103 |
$undo_time = $RCMAIL->config->get('undo_timeout', 0); |
|
104 |
if ($undo['ts'] < time() - $undo_time) |
7f5a84
|
105 |
$RCMAIL->session->remove('contact_undo'); |
A |
106 |
} |
ecf295
|
107 |
|
A |
108 |
// instantiate a contacts object according to the given source |
70c311
|
109 |
function rcmail_contact_source($source=null, $init_env=false, $writable=false) |
ecf295
|
110 |
{ |
A |
111 |
global $RCMAIL, $OUTPUT, $CONFIG, $CONTACT_COLTYPES; |
|
112 |
|
|
113 |
if (!strlen($source)) { |
|
114 |
$source = get_input_value('_source', RCUBE_INPUT_GPC); |
|
115 |
} |
|
116 |
|
|
117 |
// Get object |
70c311
|
118 |
$CONTACTS = $RCMAIL->get_address_book($source, $writable); |
ecf295
|
119 |
$CONTACTS->set_pagesize($CONFIG['pagesize']); |
A |
120 |
|
|
121 |
// set list properties and session vars |
|
122 |
if (!empty($_GET['_page'])) |
|
123 |
$CONTACTS->set_page(($_SESSION['page'] = intval($_GET['_page']))); |
|
124 |
else |
|
125 |
$CONTACTS->set_page(isset($_SESSION['page']) ? $_SESSION['page'] : 1); |
|
126 |
|
|
127 |
if (!empty($_REQUEST['_gid'])) |
|
128 |
$CONTACTS->set_group(get_input_value('_gid', RCUBE_INPUT_GPC)); |
|
129 |
|
|
130 |
if (!$init_env) |
|
131 |
return $CONTACTS; |
|
132 |
|
|
133 |
$OUTPUT->set_env('readonly', $CONTACTS->readonly); |
|
134 |
$OUTPUT->set_env('source', $source); |
|
135 |
|
|
136 |
// reduce/extend $CONTACT_COLTYPES with specification from the current $CONTACT object |
|
137 |
if (is_array($CONTACTS->coltypes)) { |
|
138 |
// remove cols not listed by the backend class |
|
139 |
$contact_cols = $CONTACTS->coltypes[0] ? array_flip($CONTACTS->coltypes) : $CONTACTS->coltypes; |
|
140 |
$CONTACT_COLTYPES = array_intersect_key($CONTACT_COLTYPES, $contact_cols); |
|
141 |
// add associative coltypes definition |
|
142 |
if (!$CONTACTS->coltypes[0]) { |
|
143 |
foreach ($CONTACTS->coltypes as $col => $colprop) |
|
144 |
$CONTACT_COLTYPES[$col] = $CONTACT_COLTYPES[$col] ? array_merge($CONTACT_COLTYPES[$col], $colprop) : $colprop; |
|
145 |
} |
|
146 |
} |
|
147 |
|
|
148 |
$OUTPUT->set_env('photocol', is_array($CONTACT_COLTYPES['photo'])); |
|
149 |
|
|
150 |
return $CONTACTS; |
|
151 |
} |
|
152 |
|
|
153 |
|
|
154 |
function rcmail_default_source($writable=false) |
|
155 |
{ |
|
156 |
global $RCMAIL; |
|
157 |
|
|
158 |
// get list of address sources |
34854b
|
159 |
$first = reset($RCMAIL->get_address_sources($writable)); |
ecf295
|
160 |
|
A |
161 |
// use first directory by default |
34854b
|
162 |
return $first['id']; |
ecf295
|
163 |
} |
0501b6
|
164 |
|
da89cf
|
165 |
function rcmail_set_sourcename($abook) |
T |
166 |
{ |
|
167 |
global $OUTPUT; |
70c311
|
168 |
|
da89cf
|
169 |
// get address book name (for display) |
T |
170 |
if ($abook && $_SESSION['addressbooks_count'] > 1) { |
|
171 |
$name = $abook->get_name(); |
|
172 |
if (!$name && $source == 0) { |
|
173 |
$name = rcube_label('personaladrbook'); |
|
174 |
} |
|
175 |
$OUTPUT->set_env('sourcename', $name); |
|
176 |
} |
|
177 |
} |
|
178 |
|
0501b6
|
179 |
|
f11541
|
180 |
function rcmail_directory_list($attrib) |
T |
181 |
{ |
a79417
|
182 |
global $RCMAIL, $OUTPUT; |
f11541
|
183 |
|
a79417
|
184 |
if (!$attrib['id']) |
A |
185 |
$attrib['id'] = 'rcmdirectorylist'; |
cc97ea
|
186 |
|
a79417
|
187 |
$out = ''; |
A |
188 |
$local_id = '0'; |
|
189 |
$jsdata = array(); |
ca7dda
|
190 |
|
a79417
|
191 |
$line_templ = html::tag('li', array( |
b0689b
|
192 |
'id' => 'rcmli%s', 'class' => '%s'), |
a79417
|
193 |
html::a(array('href' => '%s', |
ce988a
|
194 |
'rel' => '%s', |
a79417
|
195 |
'onclick' => "return ".JS_OBJECT_NAME.".command('list','%s',this)"), '%s')); |
cc97ea
|
196 |
|
ca7dda
|
197 |
$sources = (array) $OUTPUT->env['address_sources']; |
A |
198 |
reset($sources); |
cc97ea
|
199 |
|
ca7dda
|
200 |
// currently selected source |
A |
201 |
$current = get_input_value('_source', RCUBE_INPUT_GPC); |
|
202 |
|
|
203 |
foreach ($sources as $j => $source) { |
64ebc9
|
204 |
$id = strval(strlen($source['id']) ? $source['id'] : $j); |
a79417
|
205 |
$js_id = JQ($id); |
b0689b
|
206 |
|
A |
207 |
// set class name(s) |
|
208 |
$class_name = 'addressbook'; |
|
209 |
if ($current === $id) |
|
210 |
$class_name .= ' selected'; |
|
211 |
if ($source['readonly']) |
|
212 |
$class_name .= ' readonly'; |
44143c
|
213 |
if ($source['class_name']) |
A |
214 |
$class_name .= ' ' . $source['class_name']; |
b0689b
|
215 |
|
ce988a
|
216 |
$out .= sprintf($line_templ, |
T |
217 |
html_identifier($id), |
b0689b
|
218 |
$class_name, |
a79417
|
219 |
Q(rcmail_url(null, array('_source' => $id))), |
ce988a
|
220 |
$source['id'], |
a79417
|
221 |
$js_id, (!empty($source['name']) ? Q($source['name']) : Q($id))); |
0501b6
|
222 |
|
T |
223 |
$groupdata = array('out' => $out, 'jsdata' => $jsdata, 'source' => $id); |
|
224 |
if ($source['groups']) |
|
225 |
$groupdata = rcmail_contact_groups($groupdata); |
a79417
|
226 |
$jsdata = $groupdata['jsdata']; |
A |
227 |
$out = $groupdata['out']; |
|
228 |
} |
|
229 |
|
f8e48d
|
230 |
$line_templ = html::tag('li', array( |
A |
231 |
'id' => 'rcmliS%s', 'class' => '%s'), |
|
232 |
html::a(array('href' => '#', 'rel' => 'S%s', |
|
233 |
'onclick' => "return ".JS_OBJECT_NAME.".command('listsearch', '%s', this)"), '%s')); |
|
234 |
|
|
235 |
// Saved searches |
|
236 |
$sources = $RCMAIL->user->list_searches(rcube_user::SEARCH_ADDRESSBOOK); |
|
237 |
foreach ($sources as $j => $source) { |
|
238 |
$id = $source['id']; |
|
239 |
$js_id = JQ($id); |
|
240 |
|
|
241 |
// set class name(s) |
|
242 |
$class_name = 'contactsearch'; |
|
243 |
if ($current === $id) |
|
244 |
$class_name .= ' selected'; |
|
245 |
if ($source['class_name']) |
|
246 |
$class_name .= ' ' . $source['class_name']; |
|
247 |
|
|
248 |
$out .= sprintf($line_templ, |
|
249 |
html_identifier($id), |
|
250 |
$class_name, |
|
251 |
$id, |
|
252 |
$js_id, (!empty($source['name']) ? Q($source['name']) : Q($id))); |
|
253 |
} |
|
254 |
|
|
255 |
$OUTPUT->set_env('contactgroups', $jsdata); |
a79417
|
256 |
$OUTPUT->add_gui_object('folderlist', $attrib['id']); |
5731d6
|
257 |
// add some labels to client |
2c77f5
|
258 |
$OUTPUT->add_label('deletegroupconfirm', 'groupdeleting', 'addingmember', 'removingmember'); |
a79417
|
259 |
|
A |
260 |
return html::tag('ul', $attrib, $out, html::$common_attrib); |
a61bbb
|
261 |
} |
T |
262 |
|
|
263 |
|
bb8012
|
264 |
function rcmail_contact_groups($args) |
a61bbb
|
265 |
{ |
a79417
|
266 |
global $RCMAIL; |
a61bbb
|
267 |
|
a79417
|
268 |
$groups = $RCMAIL->get_address_book($args['source'])->list_groups(); |
bb8012
|
269 |
|
a79417
|
270 |
if (!empty($groups)) { |
A |
271 |
$line_templ = html::tag('li', array( |
f6c7af
|
272 |
'id' => 'rcmliG%s', 'class' => 'contactgroup'), |
a79417
|
273 |
html::a(array('href' => '#', |
ce988a
|
274 |
'rel' => '%s:%s', |
a79417
|
275 |
'onclick' => "return ".JS_OBJECT_NAME.".command('listgroup',{'source':'%s','id':'%s'},this)"), '%s')); |
bb8012
|
276 |
|
a79417
|
277 |
$jsdata = array(); |
A |
278 |
foreach ($groups as $group) { |
ce988a
|
279 |
$args['out'] .= sprintf($line_templ, |
T |
280 |
html_identifier($args['source'] . $group['ID']), |
|
281 |
$args['source'], $group['ID'], |
|
282 |
$args['source'], $group['ID'], Q($group['name']) |
|
283 |
); |
a79417
|
284 |
$args['jsdata']['G'.$args['source'].$group['ID']] = array( |
A |
285 |
'source' => $args['source'], 'id' => $group['ID'], |
|
286 |
'name' => $group['name'], 'type' => 'group'); |
|
287 |
} |
bb8012
|
288 |
} |
A |
289 |
|
a79417
|
290 |
return $args; |
f11541
|
291 |
} |
T |
292 |
|
4e17e6
|
293 |
|
fa5996
|
294 |
// return the contacts list as HTML table |
4e17e6
|
295 |
function rcmail_contacts_list($attrib) |
a79417
|
296 |
{ |
A |
297 |
global $CONTACTS, $OUTPUT; |
4e17e6
|
298 |
|
0501b6
|
299 |
// define list of cols to be displayed |
T |
300 |
$a_show_cols = array('name'); |
|
301 |
|
a79417
|
302 |
// add id to message list table if not specified |
A |
303 |
if (!strlen($attrib['id'])) |
|
304 |
$attrib['id'] = 'rcmAddressList'; |
|
305 |
|
|
306 |
// create XHTML table |
fa5996
|
307 |
$out = rcube_table_output($attrib, array(), $a_show_cols, $CONTACTS->primary_key); |
a79417
|
308 |
|
A |
309 |
// set client env |
|
310 |
$OUTPUT->add_gui_object('contactslist', $attrib['id']); |
|
311 |
$OUTPUT->set_env('current_page', (int)$CONTACTS->list_page); |
|
312 |
$OUTPUT->include_script('list.js'); |
|
313 |
|
|
314 |
// add some labels to client |
2c77f5
|
315 |
$OUTPUT->add_label('deletecontactconfirm', 'copyingcontact'); |
a79417
|
316 |
|
A |
317 |
return $out; |
|
318 |
} |
4e17e6
|
319 |
|
T |
320 |
|
f11541
|
321 |
function rcmail_js_contacts_list($result, $prefix='') |
a79417
|
322 |
{ |
A |
323 |
global $OUTPUT; |
4e17e6
|
324 |
|
a79417
|
325 |
if (empty($result) || $result->count == 0) |
A |
326 |
return; |
4e17e6
|
327 |
|
a79417
|
328 |
// define list of cols to be displayed |
A |
329 |
$a_show_cols = array('name'); |
e9a9f2
|
330 |
|
a79417
|
331 |
while ($row = $result->next()) { |
A |
332 |
$a_row_cols = array(); |
e9a9f2
|
333 |
|
ecf295
|
334 |
// build contact ID with source ID |
A |
335 |
if (isset($row['sourceid'])) { |
|
336 |
$row['ID'] = $row['ID'].'-'.$row['sourceid']; |
|
337 |
} |
|
338 |
|
a79417
|
339 |
// format each col |
71e8cc
|
340 |
foreach ($a_show_cols as $col) { |
A |
341 |
$val = $row[$col]; |
|
342 |
if ($val == '' && $col == 'name') { |
|
343 |
$val = rcube_addressbook::compose_display_name($row, true); |
|
344 |
} |
b95149
|
345 |
|
71e8cc
|
346 |
$a_row_cols[$col] = Q($val); |
b95149
|
347 |
} |
a79417
|
348 |
|
A |
349 |
$OUTPUT->command($prefix.'add_contact_row', $row['ID'], $a_row_cols); |
f11541
|
350 |
} |
a79417
|
351 |
} |
4e17e6
|
352 |
|
T |
353 |
|
|
354 |
// similar function as /steps/settings/identities.inc::rcmail_identity_frame() |
|
355 |
function rcmail_contact_frame($attrib) |
a79417
|
356 |
{ |
A |
357 |
global $OUTPUT; |
4e17e6
|
358 |
|
a79417
|
359 |
if (!$attrib['id']) |
A |
360 |
$attrib['id'] = 'rcmcontactframe'; |
ecf295
|
361 |
|
a79417
|
362 |
$attrib['name'] = $attrib['id']; |
f11541
|
363 |
|
a79417
|
364 |
$OUTPUT->set_env('contentframe', $attrib['name']); |
A |
365 |
$OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/blank.gif'); |
e2c610
|
366 |
|
a79417
|
367 |
return html::iframe($attrib); |
A |
368 |
} |
4e17e6
|
369 |
|
T |
370 |
|
|
371 |
function rcmail_rowcount_display($attrib) |
a79417
|
372 |
{ |
A |
373 |
global $OUTPUT; |
4e17e6
|
374 |
|
a79417
|
375 |
if (!$attrib['id']) |
A |
376 |
$attrib['id'] = 'rcmcountdisplay'; |
4e17e6
|
377 |
|
a79417
|
378 |
$OUTPUT->add_gui_object('countdisplay', $attrib['id']); |
4e17e6
|
379 |
|
fa5996
|
380 |
return html::span($attrib, rcube_label('loading')); |
a79417
|
381 |
} |
4e17e6
|
382 |
|
T |
383 |
|
ecf295
|
384 |
function rcmail_get_rowcount_text($result=null) |
a79417
|
385 |
{ |
ecf295
|
386 |
global $CONTACTS, $CONFIG; |
A |
387 |
|
a79417
|
388 |
// read nr of contacts |
ecf295
|
389 |
if (!$result) { |
A |
390 |
$result = $CONTACTS->get_result(); |
a79417
|
391 |
} |
4e17e6
|
392 |
|
a79417
|
393 |
if ($result->count == 0) |
A |
394 |
$out = rcube_label('nocontactsfound'); |
|
395 |
else |
|
396 |
$out = rcube_label(array( |
|
397 |
'name' => 'contactsfromto', |
|
398 |
'vars' => array( |
|
399 |
'from' => $result->first + 1, |
ecf295
|
400 |
'to' => min($result->count, $result->first + $CONFIG['pagesize']), |
a79417
|
401 |
'count' => $result->count) |
A |
402 |
)); |
|
403 |
|
|
404 |
return $out; |
|
405 |
} |
|
406 |
|
|
407 |
|
29aab5
|
408 |
function rcmail_get_type_label($type) |
T |
409 |
{ |
|
410 |
$label = 'type'.$type; |
8703b0
|
411 |
if (rcube_label_exists($label, '*', $domain)) |
A |
412 |
return rcube_label($label, $domain); |
29aab5
|
413 |
else if (preg_match('/\w+(\d+)$/', $label, $m) |
T |
414 |
&& ($label = preg_replace('/(\d+)$/', '', $label)) |
8703b0
|
415 |
&& rcube_label_exists($label, '*', $domain)) |
A |
416 |
return rcube_label($label, $domain) . ' ' . $m[1]; |
ecf295
|
417 |
|
29aab5
|
418 |
return ucfirst($type); |
T |
419 |
} |
|
420 |
|
|
421 |
|
0501b6
|
422 |
function rcmail_contact_form($form, $record, $attrib = null) |
a79417
|
423 |
{ |
0501b6
|
424 |
global $RCMAIL, $CONFIG; |
a79417
|
425 |
|
A |
426 |
// Allow plugins to modify contact form content |
|
427 |
$plugin = $RCMAIL->plugins->exec_hook('contact_form', array( |
|
428 |
'form' => $form, 'record' => $record)); |
|
429 |
|
|
430 |
$form = $plugin['form']; |
|
431 |
$record = $plugin['record']; |
0501b6
|
432 |
$edit_mode = $RCMAIL->action != 'show'; |
T |
433 |
$del_button = $attrib['deleteicon'] ? html::img(array('src' => $CONFIG['skin_path'] . $attrib['deleteicon'], 'alt' => rcube_label('delete'))) : rcube_label('delete'); |
|
434 |
unset($attrib['deleteicon']); |
a79417
|
435 |
$out = ''; |
ecf295
|
436 |
|
0501b6
|
437 |
// get default coltypes |
T |
438 |
$coltypes = $GLOBALS['CONTACT_COLTYPES']; |
e9a9f2
|
439 |
$coltype_labels = array(); |
ecf295
|
440 |
|
0501b6
|
441 |
foreach ($coltypes as $col => $prop) { |
T |
442 |
if ($prop['subtypes']) { |
c4e555
|
443 |
$subtype_names = array_map('rcmail_get_type_label', $prop['subtypes']); |
0501b6
|
444 |
$select_subtype = new html_select(array('name' => '_subtype_'.$col.'[]', 'class' => 'contactselectsubtype')); |
c4e555
|
445 |
$select_subtype->add($subtype_names, $prop['subtypes']); |
0501b6
|
446 |
$coltypes[$col]['subtypes_select'] = $select_subtype->show(); |
T |
447 |
} |
|
448 |
if ($prop['childs']) { |
|
449 |
foreach ($prop['childs'] as $childcol => $cp) |
e9a9f2
|
450 |
$coltype_labels[$childcol] = array('label' => $cp['label']); |
0501b6
|
451 |
} |
T |
452 |
} |
a79417
|
453 |
|
0501b6
|
454 |
foreach ($form as $section => $fieldset) { |
T |
455 |
// skip empty sections |
a79417
|
456 |
if (empty($fieldset['content'])) |
A |
457 |
continue; |
|
458 |
|
0501b6
|
459 |
$select_add = new html_select(array('class' => 'addfieldmenu', 'rel' => $section)); |
T |
460 |
$select_add->add(rcube_label('addfield'), ''); |
|
461 |
|
|
462 |
// render head section with name fields (not a regular list of rows) |
|
463 |
if ($section == 'head') { |
|
464 |
$content = ''; |
e84818
|
465 |
|
ec4b59
|
466 |
// unset display name if it is composed from name parts |
445a4c
|
467 |
if ($record['name'] == rcube_addressbook::compose_display_name(array('name' => '') + (array)$record)) |
0501b6
|
468 |
unset($record['name']); |
T |
469 |
|
|
470 |
// group fields |
|
471 |
$field_blocks = array( |
|
472 |
'names' => array('prefix','firstname','middlename','surname','suffix'), |
|
473 |
'displayname' => array('name'), |
|
474 |
'nickname' => array('nickname'), |
317372
|
475 |
'organization' => array('organization'), |
T |
476 |
'department' => array('department'), |
|
477 |
'jobtitle' => array('jobtitle'), |
0501b6
|
478 |
); |
T |
479 |
foreach ($field_blocks as $blockname => $colnames) { |
|
480 |
$fields = ''; |
|
481 |
foreach ($colnames as $col) { |
|
482 |
// skip cols unknown to the backend |
|
483 |
if (!$coltypes[$col]) |
|
484 |
continue; |
ecf295
|
485 |
|
0fbade
|
486 |
// only string values are expected here |
T |
487 |
if (is_array($record[$col])) |
|
488 |
$record[$col] = join(' ', $record[$col]); |
0501b6
|
489 |
|
T |
490 |
if ($RCMAIL->action == 'show') { |
|
491 |
if (!empty($record[$col])) |
|
492 |
$fields .= html::span('namefield ' . $col, Q($record[$col])) . " "; |
|
493 |
} |
|
494 |
else { |
|
495 |
$colprop = (array)$fieldset['content'][$col] + (array)$coltypes[$col]; |
|
496 |
$colprop['id'] = 'ff_'.$col; |
|
497 |
if (empty($record[$col]) && !$colprop['visible']) { |
|
498 |
$colprop['style'] = 'display:none'; |
|
499 |
$select_add->add($colprop['label'], $col); |
|
500 |
} |
|
501 |
$fields .= rcmail_get_edit_field($col, $record[$col], $colprop, $colprop['type']); |
|
502 |
} |
|
503 |
} |
|
504 |
$content .= html::div($blockname, $fields); |
|
505 |
} |
ecf295
|
506 |
|
0501b6
|
507 |
if ($edit_mode) |
T |
508 |
$content .= html::p('addfield', $select_add->show(null)); |
|
509 |
|
|
510 |
$out .= html::tag('fieldset', $attrib, (!empty($fieldset['name']) ? html::tag('legend', null, Q($fieldset['name'])) : '') . $content) ."\n"; |
|
511 |
continue; |
|
512 |
} |
|
513 |
|
a79417
|
514 |
$content = ''; |
A |
515 |
if (is_array($fieldset['content'])) { |
|
516 |
foreach ($fieldset['content'] as $col => $colprop) { |
0501b6
|
517 |
// remove subtype part of col name |
T |
518 |
list($field, $subtype) = explode(':', $col); |
|
519 |
if (!$subtype) $subtype = 'home'; |
|
520 |
$fullkey = $col.':'.$subtype; |
a79417
|
521 |
|
0501b6
|
522 |
// skip cols unknown to the backend |
T |
523 |
if (!$coltypes[$field]) |
|
524 |
continue; |
|
525 |
|
|
526 |
// merge colprop with global coltype configuration |
|
527 |
$colprop += $coltypes[$field]; |
|
528 |
$label = isset($colprop['label']) ? $colprop['label'] : rcube_label($col); |
|
529 |
|
|
530 |
// prepare subtype selector in edit mode |
|
531 |
if ($edit_mode && is_array($colprop['subtypes'])) { |
29aab5
|
532 |
$subtype_names = array_map('rcmail_get_type_label', $colprop['subtypes']); |
0501b6
|
533 |
$select_subtype = new html_select(array('name' => '_subtype_'.$col.'[]', 'class' => 'contactselectsubtype')); |
29aab5
|
534 |
$select_subtype->add($subtype_names, $colprop['subtypes']); |
0501b6
|
535 |
} |
T |
536 |
else |
|
537 |
$select_subtype = null; |
a79417
|
538 |
|
A |
539 |
if (!empty($colprop['value'])) { |
0501b6
|
540 |
$values = (array)$colprop['value']; |
a79417
|
541 |
} |
A |
542 |
else { |
0501b6
|
543 |
// iterate over possible subtypes and collect values with their subtype |
T |
544 |
if (is_array($colprop['subtypes'])) { |
|
545 |
$values = $subtypes = array(); |
|
546 |
foreach ($colprop['subtypes'] as $i => $st) { |
|
547 |
$newval = false; |
|
548 |
if ($record[$field.':'.$st]) { |
|
549 |
$subtypes[count($values)] = $st; |
|
550 |
$newval = $record[$field.':'.$st]; |
|
551 |
} |
|
552 |
else if ($i == 0 && $record[$field]) { |
|
553 |
$subtypes[count($values)] = $st; |
|
554 |
$newval = $record[$field]; |
|
555 |
} |
|
556 |
if ($newval !== false) { |
|
557 |
if (is_array($newval) && isset($newval[0])) |
|
558 |
$values = array_merge($values, $newval); |
|
559 |
else |
|
560 |
$values[] = $newval; |
|
561 |
} |
|
562 |
} |
|
563 |
} |
|
564 |
else { |
|
565 |
$values = $record[$fullkey] ? $record[$fullkey] : $record[$field]; |
|
566 |
$subtypes = null; |
|
567 |
} |
a79417
|
568 |
} |
A |
569 |
|
0501b6
|
570 |
// hack: create empty values array to force this field to be displayed |
T |
571 |
if (empty($values) && $colprop['visible']) |
|
572 |
$values[] = ''; |
|
573 |
|
|
574 |
$rows = ''; |
|
575 |
foreach ((array)$values as $i => $val) { |
|
576 |
if ($subtypes[$i]) |
|
577 |
$subtype = $subtypes[$i]; |
|
578 |
|
|
579 |
// render composite field |
|
580 |
if ($colprop['type'] == 'composite') { |
|
581 |
$composite = array(); $j = 0; |
|
582 |
$template = $RCMAIL->config->get($col . '_template', '{'.join('} {', array_keys($colprop['childs'])).'}'); |
|
583 |
foreach ($colprop['childs'] as $childcol => $cp) { |
|
584 |
$childvalue = $val[$childcol] ? $val[$childcol] : $val[$j]; |
|
585 |
|
|
586 |
if ($edit_mode) { |
|
587 |
if ($colprop['subtypes'] || $colprop['limit'] != 1) $cp['array'] = true; |
|
588 |
$composite['{'.$childcol.'}'] = rcmail_get_edit_field($childcol, $childvalue, $cp, $cp['type']) . " "; |
|
589 |
} |
|
590 |
else { |
|
591 |
$childval = $cp['render_func'] ? call_user_func($cp['render_func'], $childvalue, $childcol) : Q($childvalue); |
|
592 |
$composite['{'.$childcol.'}'] = html::span('data ' . $childcol, $childval) . " "; |
|
593 |
} |
|
594 |
$j++; |
|
595 |
} |
|
596 |
|
|
597 |
$coltypes[$field] += (array)$colprop; |
|
598 |
$coltypes[$field]['count']++; |
|
599 |
$val = strtr($template, $composite); |
|
600 |
} |
|
601 |
else if ($edit_mode) { |
|
602 |
// call callback to render/format value |
|
603 |
if ($colprop['render_func']) |
|
604 |
$val = call_user_func($colprop['render_func'], $val, $col); |
|
605 |
|
|
606 |
$coltypes[$field] = (array)$colprop + $coltypes[$field]; |
|
607 |
|
|
608 |
if ($colprop['subtypes'] || $colprop['limit'] != 1) |
|
609 |
$colprop['array'] = true; |
|
610 |
|
|
611 |
$val = rcmail_get_edit_field($col, $val, $colprop, $colprop['type']); |
|
612 |
$coltypes[$field]['count']++; |
|
613 |
} |
|
614 |
else if ($colprop['render_func']) |
|
615 |
$val = call_user_func($colprop['render_func'], $val, $col); |
|
616 |
else if (is_array($colprop['options']) && isset($colprop['options'][$val])) |
|
617 |
$val = $colprop['options'][$val]; |
|
618 |
else |
|
619 |
$val = Q($val); |
|
620 |
|
|
621 |
// use subtype as label |
|
622 |
if ($colprop['subtypes']) |
29aab5
|
623 |
$label = rcmail_get_type_label($subtype); |
0501b6
|
624 |
|
T |
625 |
// add delete button/link |
|
626 |
if ($edit_mode && !($colprop['visible'] && $colprop['limit'] == 1)) |
|
627 |
$val .= html::a(array('href' => '#del', 'class' => 'contactfieldbutton deletebutton', 'title' => rcube_label('delete'), 'rel' => $col), $del_button); |
|
628 |
|
|
629 |
// display row with label |
|
630 |
if ($label) { |
|
631 |
$rows .= html::div('row', |
|
632 |
html::div('contactfieldlabel label', $select_subtype ? $select_subtype->show($subtype) : Q($label)) . |
|
633 |
html::div('contactfieldcontent '.$colprop['type'], $val)); |
|
634 |
} |
|
635 |
else // row without label |
|
636 |
$rows .= html::div('row', html::div('contactfield', $val)); |
|
637 |
} |
ecf295
|
638 |
|
0501b6
|
639 |
// add option to the add-field menu |
T |
640 |
if (!$colprop['limit'] || $coltypes[$field]['count'] < $colprop['limit']) { |
|
641 |
$select_add->add($colprop['label'], $col); |
|
642 |
$select_add->_count++; |
|
643 |
} |
ecf295
|
644 |
|
0501b6
|
645 |
// wrap rows in fieldgroup container |
fbeb46
|
646 |
$content .= html::tag('fieldset', array('class' => 'contactfieldgroup ' . ($colprop['subtypes'] ? 'contactfieldgroupmulti ' : '') . 'contactcontroller' . $col, 'style' => ($rows ? null : 'display:none')), |
0501b6
|
647 |
($colprop['subtypes'] ? html::tag('legend', null, Q($colprop['label'])) : ' ') . |
T |
648 |
$rows); |
a79417
|
649 |
} |
0501b6
|
650 |
|
T |
651 |
// also render add-field selector |
|
652 |
if ($edit_mode) |
|
653 |
$content .= html::p('addfield', $select_add->show(null, array('style' => $select_add->_count ? null : 'display:none'))); |
|
654 |
|
|
655 |
$content = html::div(array('id' => 'contactsection' . $section), $content); |
a79417
|
656 |
} |
A |
657 |
else { |
|
658 |
$content = $fieldset['content']; |
|
659 |
} |
|
660 |
|
|
661 |
$out .= html::tag('fieldset', null, html::tag('legend', null, Q($fieldset['name'])) . $content) ."\n"; |
|
662 |
} |
0501b6
|
663 |
|
T |
664 |
if ($edit_mode) { |
e9a9f2
|
665 |
$RCMAIL->output->set_env('coltypes', $coltypes + $coltype_labels); |
0501b6
|
666 |
$RCMAIL->output->set_env('delbutton', $del_button); |
T |
667 |
$RCMAIL->output->add_label('delete'); |
|
668 |
} |
|
669 |
|
a79417
|
670 |
return $out; |
0501b6
|
671 |
} |
T |
672 |
|
|
673 |
|
|
674 |
function rcmail_contact_photo($attrib) |
|
675 |
{ |
c3dabf
|
676 |
global $SOURCE_ID, $CONTACTS, $CONTACT_COLTYPES, $RCMAIL, $CONFIG; |
e50551
|
677 |
|
A |
678 |
if (!$CONTACT_COLTYPES['photo']) |
|
679 |
return ''; |
|
680 |
|
0501b6
|
681 |
if ($result = $CONTACTS->get_result()) |
T |
682 |
$record = $result->first(); |
e50551
|
683 |
|
0501b6
|
684 |
$photo_img = $attrib['placeholder'] ? $CONFIG['skin_path'] . $attrib['placeholder'] : 'program/blank.gif'; |
e50551
|
685 |
$RCMAIL->output->set_env('photo_placeholder', $photo_img); |
0501b6
|
686 |
unset($attrib['placeholder']); |
e50551
|
687 |
|
A |
688 |
if (strpos($record['photo'], 'http:') === 0) |
|
689 |
$photo_img = $record['photo']; |
|
690 |
else if ($record['photo']) |
c3dabf
|
691 |
$photo_img = $RCMAIL->url(array('_action' => 'photo', '_cid' => $record['ID'], '_source' => $SOURCE_ID)); |
e50551
|
692 |
else |
A |
693 |
$ff_value = '-del-'; // will disable delete-photo action |
|
694 |
|
|
695 |
$img = html::img(array('src' => $photo_img, 'border' => 1, 'alt' => '')); |
|
696 |
$content = html::div($attrib, $img); |
|
697 |
|
|
698 |
if ($RCMAIL->action == 'edit' || $RCMAIL->action == 'add') { |
|
699 |
$RCMAIL->output->add_gui_object('contactphoto', $attrib['id']); |
|
700 |
$hidden = new html_hiddenfield(array('name' => '_photo', 'id' => 'ff_photo', 'value' => $ff_value)); |
|
701 |
$content .= $hidden->show(); |
|
702 |
} |
|
703 |
|
|
704 |
return $content; |
0501b6
|
705 |
} |
T |
706 |
|
|
707 |
|
|
708 |
function rcmail_format_date_col($val) |
|
709 |
{ |
|
710 |
global $RCMAIL; |
|
711 |
return format_date($val, $RCMAIL->config->get('date_format', 'Y-m-d')); |
a79417
|
712 |
} |
A |
713 |
|
|
714 |
|
ecf295
|
715 |
/** |
A |
716 |
* Returns contact ID(s) and source(s) from GET/POST data |
|
717 |
* |
|
718 |
* @return array List of contact IDs per-source |
|
719 |
*/ |
|
720 |
function rcmail_get_cids() |
|
721 |
{ |
|
722 |
// contact ID (or comma-separated list of IDs) is provided in two |
|
723 |
// forms. If _source is an empty string then the ID is a string |
|
724 |
// containing contact ID and source name in form: <ID>-<SOURCE> |
|
725 |
|
|
726 |
$cid = get_input_value('_cid', RCUBE_INPUT_GPC); |
87a2f6
|
727 |
$source = (string) get_input_value('_source', RCUBE_INPUT_GPC); |
ecf295
|
728 |
|
A |
729 |
if (!preg_match('/^[a-zA-Z0-9\+\/=_-]+(,[a-zA-Z0-9\+\/=_-]+)*$/', $cid)) { |
|
730 |
return array(); |
|
731 |
} |
|
732 |
|
|
733 |
$cid = explode(',', $cid); |
|
734 |
$got_source = strlen($source); |
|
735 |
$result = array(); |
|
736 |
|
|
737 |
// create per-source contact IDs array |
|
738 |
foreach ($cid as $id) { |
|
739 |
// if _source is not specified we'll find it from decoded ID |
|
740 |
if (!$got_source) { |
|
741 |
list ($c, $s) = explode('-', $id, 2); |
|
742 |
if (strlen($s)) { |
87a2f6
|
743 |
$result[(string)$s][] = $c; |
ecf295
|
744 |
} |
A |
745 |
} |
|
746 |
else { |
|
747 |
$result[$source][] = $id; |
|
748 |
} |
|
749 |
} |
|
750 |
|
|
751 |
return $result; |
|
752 |
} |
|
753 |
|
f11541
|
754 |
// register UI objects |
T |
755 |
$OUTPUT->add_handlers(array( |
a79417
|
756 |
'directorylist' => 'rcmail_directory_list', |
a61bbb
|
757 |
// 'groupslist' => 'rcmail_contact_groups', |
a79417
|
758 |
'addresslist' => 'rcmail_contacts_list', |
A |
759 |
'addressframe' => 'rcmail_contact_frame', |
|
760 |
'recordscountdisplay' => 'rcmail_rowcount_display', |
|
761 |
'searchform' => array($OUTPUT, 'search_form') |
f11541
|
762 |
)); |
68d2d5
|
763 |
|
A |
764 |
// register action aliases |
|
765 |
$RCMAIL->register_action_map(array( |
|
766 |
'add' => 'edit.inc', |
0501b6
|
767 |
'photo' => 'show.inc', |
68d2d5
|
768 |
'group-create' => 'groups.inc', |
A |
769 |
'group-rename' => 'groups.inc', |
|
770 |
'group-delete' => 'groups.inc', |
|
771 |
'group-addmembers' => 'groups.inc', |
|
772 |
'group-delmembers' => 'groups.inc', |
f8e48d
|
773 |
'search-create' => 'search.inc', |
A |
774 |
'search-delete' => 'search.inc', |
68d2d5
|
775 |
)); |