alecpl
2008-10-03 cf6a833c95a341c1eada992ed09afc650493fdaa
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;
ade8e1 23 $CONTACTS = $RCMAIL->get_address_book(null, true);
f11541 24
ade8e1 25 if (!empty($_POST['_address']) && is_object($CONTACTS))
f11541 26 {
T 27   $contact_arr = $IMAP->decode_address_list(get_input_value('_address', RCUBE_INPUT_POST, true), 1, false);
28   
29   if (!empty($contact_arr[1]['mailto']))
4e17e6 30   {
f11541 31     $contact = array(
T 32       'email' => $contact_arr[1]['mailto'],
33       'name' => $contact_arr[1]['name']
34     );
35     
36     // use email address part for name
37     if (empty($contact['name']) || $contact['name'] == $contact['email'])
38       $contact['name'] = ucfirst(preg_replace('/[\.\-]/', ' ', substr($contact['email'], 0, strpos($contact['email'], '@'))));
4e17e6 39
f11541 40     // check for existing contacts
3fc00e 41     $existing = $CONTACTS->search('email', $contact['email'], true, false);
f11541 42     if ($done = $existing->count)
T 43       $OUTPUT->show_message('contactexists', 'warning');
44     else if ($done = $CONTACTS->insert($contact))
45       $OUTPUT->show_message('addedsuccessfully', 'confirmation');
4e17e6 46   }
f11541 47 }
4e17e6 48
f11541 49 if (!$done)
T 50   $OUTPUT->show_message('errorsavingcontact', 'warning');
4e17e6 51
f11541 52 $OUTPUT->send();
4f9c83 53 ?>