| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /* |
|---|
| 4 | +-----------------------------------------------------------------------+ |
|---|
| 5 | | program/steps/mail/addcontact.inc | |
|---|
| 6 | | | |
|---|
| 7 | | This file is part of the Roundcube Webmail client | |
|---|
| 8 | | Copyright (C) 2005-2009, Roundcube Dev. - Switzerland | |
|---|
| 9 | | Licensed under the GNU GPL | |
|---|
| 10 | | | |
|---|
| 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 | |
|---|
| 22 | // only process ajax requests |
|---|
| 23 | if (!$OUTPUT->ajax_call) |
|---|
| 24 | return; |
|---|
| 25 | |
|---|
| 26 | $done = false; |
|---|
| 27 | $CONTACTS = $RCMAIL->get_address_book(null, true); |
|---|
| 28 | |
|---|
| 29 | if (!empty($_POST['_address']) && is_object($CONTACTS)) |
|---|
| 30 | { |
|---|
| 31 | $contact_arr = $IMAP->decode_address_list(get_input_value('_address', RCUBE_INPUT_POST, true), 1, false); |
|---|
| 32 | |
|---|
| 33 | if (!empty($contact_arr[1]['mailto'])) |
|---|
| 34 | { |
|---|
| 35 | $contact = array( |
|---|
| 36 | 'email' => $contact_arr[1]['mailto'], |
|---|
| 37 | 'name' => $contact_arr[1]['name'] |
|---|
| 38 | ); |
|---|
| 39 | |
|---|
| 40 | // use email address part for name |
|---|
| 41 | if (empty($contact['name']) || $contact['name'] == $contact['email']) |
|---|
| 42 | $contact['name'] = ucfirst(preg_replace('/[\.\-]/', ' ', substr($contact['email'], 0, strpos($contact['email'], '@')))); |
|---|
| 43 | |
|---|
| 44 | // check for existing contacts |
|---|
| 45 | $existing = $CONTACTS->search('email', $contact['email'], true, false); |
|---|
| 46 | if ($done = $existing->count) |
|---|
| 47 | $OUTPUT->show_message('contactexists', 'warning'); |
|---|
| 48 | else |
|---|
| 49 | { |
|---|
| 50 | $plugin = $RCMAIL->plugins->exec_hook('contact_create', array('record' => $contact, 'source' => null)); |
|---|
| 51 | $contact = $plugin['record']; |
|---|
| 52 | |
|---|
| 53 | if (!$plugin['abort'] && ($done = $CONTACTS->insert($contact))) |
|---|
| 54 | $OUTPUT->show_message('addedsuccessfully', 'confirmation'); |
|---|
| 55 | } |
|---|
| 56 | } |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | if (!$done) |
|---|
| 60 | $OUTPUT->show_message('errorsavingcontact', 'warning'); |
|---|
| 61 | |
|---|
| 62 | $OUTPUT->send(); |
|---|
| 63 | |
|---|