thomascube
2006-09-01 3ea0e3202a73eb7efcbf0b825582a6d3504658aa
commit | author | age
4e17e6 1 <?php
T 2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/steps/settings/save_identity.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  |   Save an identity record or to add a new one                         |
13  |                                                                       |
14  +-----------------------------------------------------------------------+
15  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16  +-----------------------------------------------------------------------+
17
18  $Id$
19
20 */
21
1cded8 22 $a_save_cols = array('name', 'email', 'organization', 'reply-to', 'bcc', 'standard', 'signature');
ea7c46 23 $a_html_cols = array('signature');
4e17e6 24
T 25
10a699 26 // check input
T 27 if (empty($_POST['_name']) || empty($_POST['_email']))
28   {
29   show_message('formincomplete', 'warning');
30   rcmail_overwrite_action('edit-identitiy');
31   return;
32   }
33
34
4e17e6 35 // update an existing contact
T 36 if ($_POST['_iid'])
37   {
38   $a_write_sql = array();
39
40   foreach ($a_save_cols as $col)
41     {
42     $fname = '_'.$col;
43     if (!isset($_POST[$fname]))
44       continue;
45
13c1af 46     $a_write_sql[] = sprintf("%s=%s",
T 47                              $DB->quoteIdentifier($col),
ea7c46 48                              $DB->quote(get_input_value($fname, RCUBE_INPUT_POST, in_array($col, $a_html_cols))));
4e17e6 49     }
T 50
51   if (sizeof($a_write_sql))
52     {
d7cb77 53     $DB->query("UPDATE ".get_table_name('identities')."
S 54                 SET ".join(', ', $a_write_sql)."
55                 WHERE  identity_id=?
56                 AND    user_id=?
1cded8 57                 AND    del<>1",
89406f 58                 get_input_value('_iid', RCUBE_INPUT_POST),
d7cb77 59                 $_SESSION['user_id']);
4e17e6 60                        
T 61     $updated = $DB->affected_rows();
62     }
63        
ea206d 64   if ($updated)
4e17e6 65     {
T 66     show_message('successfullysaved', 'confirmation');
67
68     // mark all other identities as 'not-default'
ea206d 69     if (!empty($_POST['_standard']))
T 70       $DB->query("UPDATE ".get_table_name('identities')."
71                   SET ".$DB->quoteIdentifier('standard')."='0'
72                   WHERE  user_id=?
73                   AND    identity_id<>?
74                   AND    del<>1",
75                   $_SESSION['user_id'],
76                   get_input_value('_iid', RCUBE_INPUT_POST));
4e17e6 77     
T 78     if ($_POST['_framed'])
79       {
80       // update the changed col in list
81       // ...      
82       }
83     }
ad57b3 84   else if ($DB->is_error())
4e17e6 85     {
T 86     // show error message
10a699 87     show_message('errorsaving', 'error');
T 88     rcmail_overwrite_action('edit-identitiy');
4e17e6 89     }
T 90   }
91
92 // insert a new contact
93 else
94   {
95   $a_insert_cols = $a_insert_values = array();
96
97   foreach ($a_save_cols as $col)
98     {
99     $fname = '_'.$col;
100     if (!isset($_POST[$fname]))
101       continue;
102     
d7cb77 103     $a_insert_cols[] = $DB->quoteIdentifier($col);
ea7c46 104     $a_insert_values[] = $DB->quote(get_input_value($fname, RCUBE_INPUT_POST, in_array($col, $a_html_cols)));
4e17e6 105     }
T 106     
107   if (sizeof($a_insert_cols))
108     {
d7cb77 109     $DB->query("INSERT INTO ".get_table_name('identities')."
S 110                 (user_id, ".join(', ', $a_insert_cols).")
111                 VALUES (?, ".join(', ', $a_insert_values).")",
112                 $_SESSION['user_id']);
1cded8 113
T 114     $insert_id = $DB->insert_id(get_sequence_name('identities'));
4e17e6 115     }
T 116     
117   if ($insert_id)
118     {
119     $_GET['_iid'] = $insert_id;
120
121     if ($_POST['_framed'])
122       {
123       // add contact row or jump to the page where it should appear
124       // ....
125       }
126     }
127   else
128     {
129     // show error message
10a699 130     show_message('errorsaving', 'error');
T 131     rcmail_overwrite_action('edit-identitiy');
4e17e6 132     }
T 133   }
134
135
136 // go to next step
10a699 137 rcmail_overwrite_action($_POST['_framed'] ? 'edit-identitiy' : 'identities');
4e17e6 138
T 139 ?>