source: github/program/steps/mail/addcontact.inc @ f115416

HEADcourier-fixdev-browser-capabilitiespdorelease-0.6release-0.7release-0.8
Last change on this file since f115416 was f115416, checked in by thomascube <thomas@…>, 6 years ago

Merged branch devel-addressbook from r443 back to trunk

  • Property mode set to 100644
File size: 2.0 KB
Line 
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$
19
20*/
21
22require_once('include/rcube_contacts.inc');
23
24$done = false;
25
26if (!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'], 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
51if (!$done)
52  $OUTPUT->show_message('errorsavingcontact', 'warning');
53
54$OUTPUT->send();
55?>
Note: See TracBrowser for help on using the repository browser.