thomascube
2006-08-30 107bde9cfd9a0392d18544b5a433552ce6f2f0a6
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        
fa4cd2 64   if ($updated && !empty($_POST['_standard']))
4e17e6 65     {
T 66     show_message('successfullysaved', 'confirmation');
67
68     // mark all other identities as 'not-default'
d7cb77 69     $DB->query("UPDATE ".get_table_name('identities')."
1cded8 70                 SET ".$DB->quoteIdentifier('standard')."='0'
10a699 71                 WHERE  user_id=?
T 72                 AND    identity_id<>?
1cded8 73                 AND    del<>1",
10a699 74                 $_SESSION['user_id'],
89406f 75                 get_input_value('_iid', RCUBE_INPUT_POST));
4e17e6 76     
T 77     if ($_POST['_framed'])
78       {
79       // update the changed col in list
80       // ...      
81       }
82     }
ad57b3 83   else if ($DB->is_error())
4e17e6 84     {
T 85     // show error message
10a699 86     show_message('errorsaving', 'error');
T 87     rcmail_overwrite_action('edit-identitiy');
4e17e6 88     }
T 89   }
90
91 // insert a new contact
92 else
93   {
94   $a_insert_cols = $a_insert_values = array();
95
96   foreach ($a_save_cols as $col)
97     {
98     $fname = '_'.$col;
99     if (!isset($_POST[$fname]))
100       continue;
101     
d7cb77 102     $a_insert_cols[] = $DB->quoteIdentifier($col);
ea7c46 103     $a_insert_values[] = $DB->quote(get_input_value($fname, RCUBE_INPUT_POST, in_array($col, $a_html_cols)));
4e17e6 104     }
T 105     
106   if (sizeof($a_insert_cols))
107     {
d7cb77 108     $DB->query("INSERT INTO ".get_table_name('identities')."
S 109                 (user_id, ".join(', ', $a_insert_cols).")
110                 VALUES (?, ".join(', ', $a_insert_values).")",
111                 $_SESSION['user_id']);
1cded8 112
T 113     $insert_id = $DB->insert_id(get_sequence_name('identities'));
4e17e6 114     }
T 115     
116   if ($insert_id)
117     {
118     $_GET['_iid'] = $insert_id;
119
120     if ($_POST['_framed'])
121       {
122       // add contact row or jump to the page where it should appear
123       // ....
124       }
125     }
126   else
127     {
128     // show error message
10a699 129     show_message('errorsaving', 'error');
T 130     rcmail_overwrite_action('edit-identitiy');
4e17e6 131     }
T 132   }
133
134
135 // go to next step
10a699 136 rcmail_overwrite_action($_POST['_framed'] ? 'edit-identitiy' : 'identities');
4e17e6 137
T 138 ?>