4 +-----------------------------------------------------------------------+
5 | program/steps/settings/save_identity.inc |
7 | This file is part of the RoundCube Webmail client |
8 | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland |
9 | Licensed under the GNU GPL |
12 | Save an identity record or to add a new one |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
18 $Id: save_identity.inc 543 2007-04-28 18:07:12Z thomasb $
22 $a_save_cols = array('name', 'email', 'organization', 'reply-to', 'bcc', 'standard', 'signature', 'html_signature');
23 $a_html_cols = array('signature');
24 $a_boolean_cols = array('standard', 'html_signature');
25 $updated = $default_id = false;
28 if (empty($_POST['_name']) || empty($_POST['_email']))
30 $OUTPUT->show_message('formincomplete', 'warning');
31 rcmail_overwrite_action('edit-identitiy');
36 // update an existing contact
39 $a_write_sql = array();
41 foreach ($a_save_cols as $col)
44 if (isset($_POST[$fname]))
45 $a_write_sql[] = sprintf("%s=%s",
46 $DB->quoteIdentifier($col),
47 $DB->quote(get_input_value($fname, RCUBE_INPUT_POST, in_array($col, $a_html_cols))));
50 // set "off" values for checkboxes that were not checked, and therefore
51 // not included in the POST body.
52 foreach ($a_boolean_cols as $col)
55 if (!isset($_POST[$fname]))
56 $a_write_sql[] = sprintf("%s=0", $DB->quoteIdentifier($col));
59 if (sizeof($a_write_sql))
62 "UPDATE ".get_table_name('identities')."
63 SET ".join(', ', $a_write_sql)."
67 get_input_value('_iid', RCUBE_INPUT_POST),
68 $_SESSION['user_id']);
70 $updated = $DB->affected_rows();
75 $OUTPUT->show_message('successfullysaved', 'confirmation');
77 if (!empty($_POST['_standard']))
78 $default_id = get_input_value('_iid', RCUBE_INPUT_POST);
80 if ($_POST['_framed'])
82 // update the changed col in list
86 else if ($DB->is_error())
89 $OUTPUT->show_message('errorsaving', 'error');
90 rcmail_overwrite_action('edit-identitiy');
95 // insert a new contact
98 $a_insert_cols = $a_insert_values = array();
100 foreach ($a_save_cols as $col)
103 if (!isset($_POST[$fname]))
106 $a_insert_cols[] = $DB->quoteIdentifier($col);
107 $a_insert_values[] = $DB->quote(get_input_value($fname, RCUBE_INPUT_POST, in_array($col, $a_html_cols)));
110 if (sizeof($a_insert_cols))
112 $DB->query("INSERT INTO ".get_table_name('identities')."
113 (user_id, ".join(', ', $a_insert_cols).")
114 VALUES (?, ".join(', ', $a_insert_values).")",
115 $_SESSION['user_id']);
117 $insert_id = $DB->insert_id(get_sequence_name('identities'));
122 $_GET['_iid'] = $insert_id;
124 if (!empty($_POST['_standard']))
125 $default_id = $insert_id;
127 if ($_POST['_framed'])
129 // add contact row or jump to the page where it should appear
135 // show error message
136 $OUTPUT->show_message('errorsaving', 'error');
137 rcmail_overwrite_action('edit-identity');
143 // mark all other identities as 'not-default'
146 "UPDATE ".get_table_name('identities')."
147 SET ".$DB->quoteIdentifier('standard')."='0'
151 $_SESSION['user_id'],
155 rcmail_overwrite_action($_framed ? 'edit-identity' : 'identities');