]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/addcontact.inc
Imported Upstream version 0.1~rc2
[roundcube.git] / program / steps / mail / addcontact.inc
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-2007, 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: addcontact.inc 638 2007-07-03 17:25:05Z thomasb $
19
20 */
21
22 require_once('include/rcube_contacts.inc');
23
24 $done = false;
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']))
32   {
33     $contact = array(
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'], '@'))));
41
42     // check for existing contacts
43     $existing = $CONTACTS->search('email', $contact['email'], true, 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');
48   }
49 }
50
51 if (!$done)
52   $OUTPUT->show_message('errorsavingcontact', 'warning');
53
54 $OUTPUT->send();
55 ?>