thomascube
2006-12-13 7a5c48e7f70b8bc938fcae3ffd2be0fdbeaab145
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                     |
8  | Copyright (C) 2005, 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
22 $REMOTE_REQUEST = TRUE;
23
ea7c46 24 if (!empty($_GET['_address']))
4e17e6 25   {
fa1557 26   $contact_arr = $IMAP->decode_address_list(get_input_value('_address', RCUBE_INPUT_GET, TRUE));
4e17e6 27   if (sizeof($contact_arr))
T 28     {
29     $contact = $contact_arr[1];
30
31     if ($contact['mailto'])
d7cb77 32       $sql_result = $DB->query("SELECT 1 FROM ".get_table_name('contacts')."
S 33                                 WHERE  user_id=?
34                                 AND    email=?
1cded8 35                                 AND    del<>1",
d7cb77 36                                 $_SESSION['user_id'],$contact['mailto']);
4e17e6 37
T 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       {
d7cb77 44       $DB->query("INSERT INTO ".get_table_name('contacts')."
1cded8 45                   (user_id, changed, del, name, email)
107bde 46                   VALUES (?, ".$DB->now().", 0, ?, ?)",
d7cb77 47                   $_SESSION['user_id'],
S 48                   $contact['name'],
49                   $contact['mailto']);
4e17e6 50
1cded8 51       $added = $DB->insert_id(get_sequence_name('contacts'));
4e17e6 52       }
T 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 ?>