4 +-----------------------------------------------------------------------+
5 | program/steps/settings/save_identity.inc |
7 | This file is part of the RoundCube Webmail client |
8 | Copyright (C) 2005, 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 430 2006-12-22 22:31:38Z thomasb $
22 $a_save_cols = array('name', 'email', 'organization', 'reply-to', 'bcc', 'standard', 'signature');
23 $a_html_cols = array('signature');
27 if (empty($_POST['_name']) || empty($_POST['_email']))
29 show_message('formincomplete', 'warning');
30 rcmail_overwrite_action('edit-identitiy');
35 // update an existing contact
38 $a_write_sql = array();
40 foreach ($a_save_cols as $col)
43 if (!isset($_POST[$fname]))
46 $a_write_sql[] = sprintf("%s=%s",
47 $DB->quoteIdentifier($col),
48 $DB->quote(get_input_value($fname, RCUBE_INPUT_POST, in_array($col, $a_html_cols))));
51 if (sizeof($a_write_sql))
53 $DB->query("UPDATE ".get_table_name('identities')."
54 SET ".join(', ', $a_write_sql)."
59 $_SESSION['user_id']);
61 $updated = $DB->affected_rows();
64 if ($updated && !empty($_POST['_standard']))
66 show_message('successfullysaved', 'confirmation');
68 // mark all other identities as 'not-default'
69 $DB->query("UPDATE ".get_table_name('identities')."
70 SET ".$DB->quoteIdentifier('standard')."='0'
77 if ($_POST['_framed'])
79 // update the changed col in list
83 else if ($DB->is_error())
86 show_message('errorsaving', 'error');
87 rcmail_overwrite_action('edit-identitiy');
91 // insert a new contact
94 $a_insert_cols = $a_insert_values = array();
96 foreach ($a_save_cols as $col)
99 if (!isset($_POST[$fname]))
102 $a_insert_cols[] = $DB->quoteIdentifier($col);
103 $a_insert_values[] = $DB->quote(get_input_value($fname, RCUBE_INPUT_POST, in_array($col, $a_html_cols)));
106 if (sizeof($a_insert_cols))
108 $DB->query("INSERT INTO ".get_table_name('identities')."
109 (user_id, ".join(', ', $a_insert_cols).")
110 VALUES (?, ".join(', ', $a_insert_values).")",
111 $_SESSION['user_id']);
113 $insert_id = $DB->insert_id(get_sequence_name('identities'));
118 $_GET['_iid'] = $insert_id;
120 if ($_POST['_framed'])
122 // add contact row or jump to the page where it should appear
128 // show error message
129 show_message('errorsaving', 'error');
130 rcmail_overwrite_action('edit-identity');
136 rcmail_overwrite_action($_POST['_framed'] ? 'edit-identity' : 'identities');