alecpl
2008-04-10 3790508c2003255c179b6f4d309d5feeaa2b6299
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 require_once('include/rcube_contacts.inc');
4e17e6 23
f11541 24 $done = false;
T 25
26 if (!empty($_POST['_address']))
27 {
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);
30   
31   if (!empty($contact_arr[1]['mailto']))
4e17e6 32   {
f11541 33     $contact = array(
T 34       'email' => $contact_arr[1]['mailto'],
35       'name' => $contact_arr[1]['name']
36     );
37     
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'], '@'))));
4e17e6 41
f11541 42     // check for existing contacts
3fc00e 43     $existing = $CONTACTS->search('email', $contact['email'], true, false);
f11541 44     if ($done = $existing->count)
T 45       $OUTPUT->show_message('contactexists', 'warning');
46     else if ($done = $CONTACTS->insert($contact))
47       $OUTPUT->show_message('addedsuccessfully', 'confirmation');
4e17e6 48   }
f11541 49 }
4e17e6 50
f11541 51 if (!$done)
T 52   $OUTPUT->show_message('errorsavingcontact', 'warning');
4e17e6 53
f11541 54 $OUTPUT->send();
4e17e6 55 ?>