commit | author | age
|
0dbac3
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
+-----------------------------------------------------------------------+ |
|
5 |
| program/steps/addressbook/export.inc | |
|
6 |
| | |
e019f2
|
7 |
| This file is part of the Roundcube Webmail client | |
e84818
|
8 |
| Copyright (C) 2008-2011, The Roundcube Dev Team | |
ecf295
|
9 |
| Copyright (C) 2011, Kolab Systems AG | |
0dbac3
|
10 |
| Licensed under the GNU GPL | |
T |
11 |
| | |
|
12 |
| PURPOSE: | |
|
13 |
| Export the selected address book as vCard file | |
|
14 |
| | |
|
15 |
+-----------------------------------------------------------------------+ |
|
16 |
| Author: Thomas Bruederli <roundcube@gmail.com> | |
ecf295
|
17 |
| Author: Aleksander Machniak <machniak@kolabsys.com> | |
0dbac3
|
18 |
+-----------------------------------------------------------------------+ |
T |
19 |
|
ecf295
|
20 |
$Id$ |
0dbac3
|
21 |
|
T |
22 |
*/ |
|
23 |
|
ecf295
|
24 |
// Use search result |
A |
25 |
if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']])) |
|
26 |
{ |
|
27 |
$search = (array)$_SESSION['search'][$_REQUEST['_search']]; |
|
28 |
$records = array(); |
|
29 |
|
|
30 |
// Get records from all sources |
|
31 |
foreach ($search as $s => $set) { |
|
32 |
$source = $RCMAIL->get_address_book($s); |
|
33 |
|
|
34 |
// reset page |
|
35 |
$source->set_page(1); |
|
36 |
$source->set_pagesize(99999); |
|
37 |
$source->set_search_set($set); |
|
38 |
|
|
39 |
// get records |
|
40 |
$result = $source->list_records(); |
|
41 |
|
|
42 |
while ($row = $result->next()) { |
|
43 |
$row['sourceid'] = $s; |
|
44 |
$key = $row['name'] . ':' . $row['sourceid']; |
|
45 |
$records[$key] = $row; |
|
46 |
} |
|
47 |
unset($result); |
|
48 |
} |
|
49 |
|
|
50 |
// sort the records |
|
51 |
ksort($records, SORT_LOCALE_STRING); |
|
52 |
|
|
53 |
// create resultset object |
|
54 |
$count = count($records); |
|
55 |
$result = new rcube_result_set($count); |
|
56 |
$result->records = array_values($records); |
|
57 |
} |
|
58 |
// selected directory/group |
|
59 |
else { |
|
60 |
$CONTACTS = rcmail_contact_source(null, true); |
|
61 |
|
|
62 |
// get contacts for this user |
|
63 |
$CONTACTS->set_page(1); |
|
64 |
$CONTACTS->set_pagesize(99999); |
|
65 |
$result = $CONTACTS->list_records(null, 0, true); |
|
66 |
} |
0dbac3
|
67 |
|
T |
68 |
// send downlaod headers |
|
69 |
send_nocacheing_headers(); |
ecb9fb
|
70 |
header('Content-Type: text/x-vcard; charset='.RCMAIL_CHARSET); |
0dbac3
|
71 |
header('Content-Disposition: attachment; filename="rcube_contacts.vcf"'); |
T |
72 |
|
|
73 |
while ($result && ($row = $result->next())) { |
ecf295
|
74 |
// we already have a vcard record |
A |
75 |
if ($row['vcard'] && $row['name']) { |
|
76 |
echo rcube_vcard::rfc2425_fold($row['vcard']) . "\n"; |
0501b6
|
77 |
} |
ecf295
|
78 |
// copy values into vcard object |
A |
79 |
else { |
|
80 |
$vcard = new rcube_vcard($row['vcard']); |
|
81 |
$vcard->reset(); |
cbf891
|
82 |
|
ecf295
|
83 |
foreach ($row as $key => $values) { |
A |
84 |
list($field, $section) = explode(':', $key); |
|
85 |
foreach ((array)$values as $value) { |
|
86 |
if (is_array($value) || strlen($value)) |
|
87 |
$vcard->set($field, $value, strtoupper($section)); |
|
88 |
} |
|
89 |
} |
|
90 |
|
|
91 |
echo $vcard->export(true) . "\n"; |
|
92 |
} |
0dbac3
|
93 |
} |
T |
94 |
|
|
95 |
exit; |