4 +-----------------------------------------------------------------------+
5 | program/steps/mail/addcontact.inc |
7 | This file is part of the RoundCube Webmail client |
8 | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland |
9 | Licensed under the GNU GPL |
12 | Add the submitted contact to the users address book |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
18 $Id: addcontact.inc 543 2007-04-28 18:07:12Z thomasb $
22 require_once('include/rcube_contacts.inc');
26 if (!empty($_POST['_address']))
28 $CONTACTS = new rcube_contacts($DB, $_SESSION['user_id']);
29 $contact_arr = $IMAP->decode_address_list(get_input_value('_address', RCUBE_INPUT_POST, true), 1, false);
31 if (!empty($contact_arr[1]['mailto']))
34 'email' => $contact_arr[1]['mailto'],
35 'name' => $contact_arr[1]['name']
38 // use email address part for name
39 if (empty($contact['name']) || $contact['name'] == $contact['email'])
40 $contact['name'] = ucfirst(preg_replace('/[\.\-]/', ' ', substr($contact['email'], 0, strpos($contact['email'], '@'))));
42 // check for existing contacts
43 $existing = $CONTACTS->search('email', $contact['email'], false);
44 if ($done = $existing->count)
45 $OUTPUT->show_message('contactexists', 'warning');
46 else if ($done = $CONTACTS->insert($contact))
47 $OUTPUT->show_message('addedsuccessfully', 'confirmation');
52 $OUTPUT->show_message('errorsavingcontact', 'warning');