]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/addcontact.inc
Imported Upstream version 0.1~beta2.2~dfsg
[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, 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 160 2006-03-03 16:36:22Z roundcube $
19
20 */
21
22 $REMOTE_REQUEST = TRUE;
23
24 if (!empty($_GET['_address']))
25   {
26   $contact_arr = $IMAP->decode_address_list(get_input_value('_address', RCUBE_INPUT_GET, TRUE));
27   if (sizeof($contact_arr))
28     {
29     $contact = $contact_arr[1];
30
31     if ($contact['mailto'])
32       $sql_result = $DB->query("SELECT 1 FROM ".get_table_name('contacts')."
33                                 WHERE  user_id=?
34                                 AND    email=?
35                                 AND    del<>1",
36                                 $_SESSION['user_id'],$contact['mailto']);
37
38     // contact entry with this mail address exists
39     if ($sql_result && $DB->num_rows($sql_result))
40       $existing_contact = TRUE;
41
42     else if ($contact['mailto'])
43       {
44       $DB->query("INSERT INTO ".get_table_name('contacts')."
45                   (user_id, changed, del, name, email)
46                   VALUES (?, now(), 0, ?, ?)",
47                   $_SESSION['user_id'],
48                   $contact['name'],
49                   $contact['mailto']);
50
51       $added = $DB->insert_id(get_sequence_name('contacts'));
52       }
53     }
54
55   if ($added)
56     $commands = show_message('addedsuccessfully', 'confirmation');
57   else if ($existing_contact)
58     $commands = show_message('contactexists', 'warning');
59   }
60
61
62 if (!$commands)
63   $commands = show_message('errorsavingcontact', 'warning');
64
65 rcube_remote_response($commands);  
66 exit;
67 ?>