thomascube
2006-02-22 745b1466fc76d5ded589e2469328086002430c1c
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');
4e17e6 23
T 24
10a699 25 // check input
T 26 if (empty($_POST['_name']) || empty($_POST['_email']))
27   {
28   show_message('formincomplete', 'warning');
29   rcmail_overwrite_action('edit-identitiy');
30   return;
31   }
32
33
4e17e6 34 // update an existing contact
T 35 if ($_POST['_iid'])
36   {
37   $a_write_sql = array();
38
39   foreach ($a_save_cols as $col)
40     {
41     $fname = '_'.$col;
42     if (!isset($_POST[$fname]))
43       continue;
44
13c1af 45     $a_write_sql[] = sprintf("%s=%s",
T 46                              $DB->quoteIdentifier($col),
47                              $DB->quote(rcube_charset_convert(strip_tags($_POST[$fname]), $OUTPUT->get_charset())));
4e17e6 48     }
T 49
50   if (sizeof($a_write_sql))
51     {
d7cb77 52     $DB->query("UPDATE ".get_table_name('identities')."
S 53                 SET ".join(', ', $a_write_sql)."
54                 WHERE  identity_id=?
55                 AND    user_id=?
1cded8 56                 AND    del<>1",
d7cb77 57                 $_POST['_iid'],
S 58                 $_SESSION['user_id']);
4e17e6 59                        
T 60     $updated = $DB->affected_rows();
61     }
62        
63   if ($updated)
64     {
65     show_message('successfullysaved', 'confirmation');
66
67     // mark all other identities as 'not-default'
d7cb77 68     $DB->query("UPDATE ".get_table_name('identities')."
1cded8 69                 SET ".$DB->quoteIdentifier('standard')."='0'
10a699 70                 WHERE  user_id=?
T 71                 AND    identity_id<>?
1cded8 72                 AND    del<>1",
10a699 73                 $_SESSION['user_id'],
T 74                 $_POST['_iid']);
4e17e6 75     
T 76     if ($_POST['_framed'])
77       {
78       // update the changed col in list
79       // ...      
80       }
81     }
82   else
83     {
84     // show error message
10a699 85     show_message('errorsaving', 'error');
T 86     rcmail_overwrite_action('edit-identitiy');
4e17e6 87     }
T 88   }
89
90 // insert a new contact
91 else
92   {
93   $a_insert_cols = $a_insert_values = array();
94
95   foreach ($a_save_cols as $col)
96     {
97     $fname = '_'.$col;
98     if (!isset($_POST[$fname]))
99       continue;
100     
d7cb77 101     $a_insert_cols[] = $DB->quoteIdentifier($col);
13c1af 102     $a_insert_values[] = $DB->quote(rcube_charset_convert(strip_tags($_POST[$fname]), $OUTPUT->get_charset()));
4e17e6 103     }
T 104     
105   if (sizeof($a_insert_cols))
106     {
d7cb77 107     $DB->query("INSERT INTO ".get_table_name('identities')."
S 108                 (user_id, ".join(', ', $a_insert_cols).")
109                 VALUES (?, ".join(', ', $a_insert_values).")",
110                 $_SESSION['user_id']);
1cded8 111
T 112     $insert_id = $DB->insert_id(get_sequence_name('identities'));
4e17e6 113     }
T 114     
115   if ($insert_id)
116     {
117     $_GET['_iid'] = $insert_id;
118
119     if ($_POST['_framed'])
120       {
121       // add contact row or jump to the page where it should appear
122       // ....
123       }
124     }
125   else
126     {
127     // show error message
10a699 128     show_message('errorsaving', 'error');
T 129     rcmail_overwrite_action('edit-identitiy');
4e17e6 130     }
T 131   }
132
133
134 // go to next step
10a699 135 rcmail_overwrite_action($_POST['_framed'] ? 'edit-identitiy' : 'identities');
4e17e6 136
T 137 ?>