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 | |
6ec91f
|
8 |
| Copyright (C) 2005-2007, 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 |
|
a0109c
|
22 |
$a_save_cols = array('name', 'email', 'organization', 'reply-to', 'bcc', 'standard', 'signature', 'html_signature'); |
ea7c46
|
23 |
$a_html_cols = array('signature'); |
a0109c
|
24 |
$a_boolean_cols = array('standard', 'html_signature'); |
6ec91f
|
25 |
$updated = $default_id = false; |
4e17e6
|
26 |
|
10a699
|
27 |
// check input |
T |
28 |
if (empty($_POST['_name']) || empty($_POST['_email'])) |
|
29 |
{ |
f11541
|
30 |
$OUTPUT->show_message('formincomplete', 'warning'); |
10a699
|
31 |
rcmail_overwrite_action('edit-identitiy'); |
T |
32 |
return; |
|
33 |
} |
|
34 |
|
|
35 |
|
4e17e6
|
36 |
// update an existing contact |
T |
37 |
if ($_POST['_iid']) |
|
38 |
{ |
|
39 |
$a_write_sql = array(); |
|
40 |
|
|
41 |
foreach ($a_save_cols as $col) |
|
42 |
{ |
|
43 |
$fname = '_'.$col; |
6ec91f
|
44 |
if (isset($_POST[$fname])) |
T |
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)))); |
4e17e6
|
48 |
} |
T |
49 |
|
a0109c
|
50 |
// set "off" values for checkboxes that were not checked, and therefore |
S |
51 |
// not included in the POST body. |
|
52 |
foreach ($a_boolean_cols as $col) |
|
53 |
{ |
|
54 |
$fname = '_' . $col; |
|
55 |
if (!isset($_POST[$fname])) |
|
56 |
$a_write_sql[] = sprintf("%s=0", $DB->quoteIdentifier($col)); |
|
57 |
} |
|
58 |
|
4e17e6
|
59 |
if (sizeof($a_write_sql)) |
T |
60 |
{ |
6ec91f
|
61 |
$DB->query( |
T |
62 |
"UPDATE ".get_table_name('identities')." |
|
63 |
SET ".join(', ', $a_write_sql)." |
|
64 |
WHERE identity_id=? |
|
65 |
AND user_id=? |
|
66 |
AND del<>1", |
|
67 |
get_input_value('_iid', RCUBE_INPUT_POST), |
|
68 |
$_SESSION['user_id']); |
4e17e6
|
69 |
|
T |
70 |
$updated = $DB->affected_rows(); |
|
71 |
} |
|
72 |
|
ea206d
|
73 |
if ($updated) |
4e17e6
|
74 |
{ |
f11541
|
75 |
$OUTPUT->show_message('successfullysaved', 'confirmation'); |
6ec91f
|
76 |
|
ea206d
|
77 |
if (!empty($_POST['_standard'])) |
6ec91f
|
78 |
$default_id = get_input_value('_iid', RCUBE_INPUT_POST); |
4e17e6
|
79 |
|
T |
80 |
if ($_POST['_framed']) |
|
81 |
{ |
|
82 |
// update the changed col in list |
|
83 |
// ... |
|
84 |
} |
|
85 |
} |
ad57b3
|
86 |
else if ($DB->is_error()) |
4e17e6
|
87 |
{ |
T |
88 |
// show error message |
f11541
|
89 |
$OUTPUT->show_message('errorsaving', 'error'); |
10a699
|
90 |
rcmail_overwrite_action('edit-identitiy'); |
6ec91f
|
91 |
return; |
4e17e6
|
92 |
} |
T |
93 |
} |
|
94 |
|
|
95 |
// insert a new contact |
|
96 |
else |
|
97 |
{ |
|
98 |
$a_insert_cols = $a_insert_values = array(); |
|
99 |
|
|
100 |
foreach ($a_save_cols as $col) |
|
101 |
{ |
|
102 |
$fname = '_'.$col; |
|
103 |
if (!isset($_POST[$fname])) |
|
104 |
continue; |
|
105 |
|
d7cb77
|
106 |
$a_insert_cols[] = $DB->quoteIdentifier($col); |
ea7c46
|
107 |
$a_insert_values[] = $DB->quote(get_input_value($fname, RCUBE_INPUT_POST, in_array($col, $a_html_cols))); |
4e17e6
|
108 |
} |
T |
109 |
|
|
110 |
if (sizeof($a_insert_cols)) |
|
111 |
{ |
d7cb77
|
112 |
$DB->query("INSERT INTO ".get_table_name('identities')." |
S |
113 |
(user_id, ".join(', ', $a_insert_cols).") |
|
114 |
VALUES (?, ".join(', ', $a_insert_values).")", |
|
115 |
$_SESSION['user_id']); |
1cded8
|
116 |
|
T |
117 |
$insert_id = $DB->insert_id(get_sequence_name('identities')); |
4e17e6
|
118 |
} |
T |
119 |
|
|
120 |
if ($insert_id) |
|
121 |
{ |
|
122 |
$_GET['_iid'] = $insert_id; |
|
123 |
|
6ec91f
|
124 |
if (!empty($_POST['_standard'])) |
T |
125 |
$default_id = $insert_id; |
|
126 |
|
4e17e6
|
127 |
if ($_POST['_framed']) |
T |
128 |
{ |
|
129 |
// add contact row or jump to the page where it should appear |
|
130 |
// .... |
|
131 |
} |
|
132 |
} |
|
133 |
else |
|
134 |
{ |
|
135 |
// show error message |
f11541
|
136 |
$OUTPUT->show_message('errorsaving', 'error'); |
853b2e
|
137 |
rcmail_overwrite_action('edit-identity'); |
6ec91f
|
138 |
return; |
4e17e6
|
139 |
} |
T |
140 |
} |
|
141 |
|
|
142 |
|
6ec91f
|
143 |
// mark all other identities as 'not-default' |
T |
144 |
if ($default_id) |
|
145 |
$DB->query( |
|
146 |
"UPDATE ".get_table_name('identities')." |
|
147 |
SET ".$DB->quoteIdentifier('standard')."='0' |
|
148 |
WHERE user_id=? |
|
149 |
AND identity_id<>? |
|
150 |
AND del<>1", |
|
151 |
$_SESSION['user_id'], |
|
152 |
$default_id); |
|
153 |
|
4e17e6
|
154 |
// go to next step |
f11541
|
155 |
rcmail_overwrite_action($_framed ? 'edit-identity' : 'identities'); |
4e17e6
|
156 |
|
T |
157 |
?> |