commit | author | age
|
4e17e6
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
+-----------------------------------------------------------------------+ |
|
5 |
| program/steps/mail/addcontact.inc | |
|
6 |
| | |
|
7 |
| This file is part of the RoundCube Webmail client | |
f11541
|
8 |
| Copyright (C) 2005-2007, RoundCube Dev. - Switzerland | |
30233b
|
9 |
| Licensed under the GNU GPL | |
4e17e6
|
10 |
| | |
T |
11 |
| PURPOSE: | |
|
12 |
| Add the submitted contact to the users address book | |
|
13 |
| | |
|
14 |
+-----------------------------------------------------------------------+ |
|
15 |
| Author: Thomas Bruederli <roundcube@gmail.com> | |
|
16 |
+-----------------------------------------------------------------------+ |
|
17 |
|
|
18 |
$Id$ |
|
19 |
|
|
20 |
*/ |
|
21 |
|
f11541
|
22 |
$done = false; |
T |
23 |
|
|
24 |
if (!empty($_POST['_address'])) |
|
25 |
{ |
4f9c83
|
26 |
$CONTACTS = array(); |
ed5ed9
|
27 |
if (strtolower($CONFIG['address_book_type']) == 'ldap') { |
4f9c83
|
28 |
// Use the first writable LDAP address book. |
S |
29 |
foreach ($CONFIG["ldap_public"] as $id => $prop) { |
|
30 |
if ($prop["writable"]) { |
|
31 |
$CONTACTS = new rcube_ldap($prop); |
|
32 |
break; |
|
33 |
} // end if |
|
34 |
} // end foreach |
|
35 |
} // end if |
|
36 |
else { |
|
37 |
$CONTACTS = new rcube_contacts($DB, $_SESSION['user_id']); |
|
38 |
} // end else |
f11541
|
39 |
$contact_arr = $IMAP->decode_address_list(get_input_value('_address', RCUBE_INPUT_POST, true), 1, false); |
T |
40 |
|
|
41 |
if (!empty($contact_arr[1]['mailto'])) |
4e17e6
|
42 |
{ |
f11541
|
43 |
$contact = array( |
T |
44 |
'email' => $contact_arr[1]['mailto'], |
|
45 |
'name' => $contact_arr[1]['name'] |
|
46 |
); |
|
47 |
|
|
48 |
// use email address part for name |
|
49 |
if (empty($contact['name']) || $contact['name'] == $contact['email']) |
|
50 |
$contact['name'] = ucfirst(preg_replace('/[\.\-]/', ' ', substr($contact['email'], 0, strpos($contact['email'], '@')))); |
4e17e6
|
51 |
|
f11541
|
52 |
// check for existing contacts |
3fc00e
|
53 |
$existing = $CONTACTS->search('email', $contact['email'], true, false); |
f11541
|
54 |
if ($done = $existing->count) |
T |
55 |
$OUTPUT->show_message('contactexists', 'warning'); |
|
56 |
else if ($done = $CONTACTS->insert($contact)) |
|
57 |
$OUTPUT->show_message('addedsuccessfully', 'confirmation'); |
4e17e6
|
58 |
} |
f11541
|
59 |
} |
4e17e6
|
60 |
|
f11541
|
61 |
if (!$done) |
T |
62 |
$OUTPUT->show_message('errorsavingcontact', 'warning'); |
4e17e6
|
63 |
|
f11541
|
64 |
$OUTPUT->send(); |
4f9c83
|
65 |
?> |