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 |
|
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'); |
4e17e6
|
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 |
|
a0109c
|
51 |
// set "off" values for checkboxes that were not checked, and therefore |
S |
52 |
// not included in the POST body. |
|
53 |
foreach ($a_boolean_cols as $col) |
|
54 |
{ |
|
55 |
$fname = '_' . $col; |
|
56 |
if (!isset($_POST[$fname])) |
|
57 |
{ |
|
58 |
$a_write_sql[] = sprintf("%s=0", $DB->quoteIdentifier($col)); |
|
59 |
} |
|
60 |
} |
|
61 |
|
4e17e6
|
62 |
if (sizeof($a_write_sql)) |
T |
63 |
{ |
d7cb77
|
64 |
$DB->query("UPDATE ".get_table_name('identities')." |
S |
65 |
SET ".join(', ', $a_write_sql)." |
|
66 |
WHERE identity_id=? |
|
67 |
AND user_id=? |
1cded8
|
68 |
AND del<>1", |
89406f
|
69 |
get_input_value('_iid', RCUBE_INPUT_POST), |
d7cb77
|
70 |
$_SESSION['user_id']); |
4e17e6
|
71 |
|
T |
72 |
$updated = $DB->affected_rows(); |
|
73 |
} |
|
74 |
|
ea206d
|
75 |
if ($updated) |
4e17e6
|
76 |
{ |
T |
77 |
show_message('successfullysaved', 'confirmation'); |
|
78 |
|
|
79 |
// mark all other identities as 'not-default' |
ea206d
|
80 |
if (!empty($_POST['_standard'])) |
T |
81 |
$DB->query("UPDATE ".get_table_name('identities')." |
|
82 |
SET ".$DB->quoteIdentifier('standard')."='0' |
|
83 |
WHERE user_id=? |
|
84 |
AND identity_id<>? |
|
85 |
AND del<>1", |
|
86 |
$_SESSION['user_id'], |
|
87 |
get_input_value('_iid', RCUBE_INPUT_POST)); |
4e17e6
|
88 |
|
T |
89 |
if ($_POST['_framed']) |
|
90 |
{ |
|
91 |
// update the changed col in list |
|
92 |
// ... |
|
93 |
} |
|
94 |
} |
ad57b3
|
95 |
else if ($DB->is_error()) |
4e17e6
|
96 |
{ |
T |
97 |
// show error message |
10a699
|
98 |
show_message('errorsaving', 'error'); |
T |
99 |
rcmail_overwrite_action('edit-identitiy'); |
4e17e6
|
100 |
} |
T |
101 |
} |
|
102 |
|
|
103 |
// insert a new contact |
|
104 |
else |
|
105 |
{ |
|
106 |
$a_insert_cols = $a_insert_values = array(); |
|
107 |
|
|
108 |
foreach ($a_save_cols as $col) |
|
109 |
{ |
|
110 |
$fname = '_'.$col; |
|
111 |
if (!isset($_POST[$fname])) |
|
112 |
continue; |
|
113 |
|
d7cb77
|
114 |
$a_insert_cols[] = $DB->quoteIdentifier($col); |
ea7c46
|
115 |
$a_insert_values[] = $DB->quote(get_input_value($fname, RCUBE_INPUT_POST, in_array($col, $a_html_cols))); |
4e17e6
|
116 |
} |
T |
117 |
|
|
118 |
if (sizeof($a_insert_cols)) |
|
119 |
{ |
d7cb77
|
120 |
$DB->query("INSERT INTO ".get_table_name('identities')." |
S |
121 |
(user_id, ".join(', ', $a_insert_cols).") |
|
122 |
VALUES (?, ".join(', ', $a_insert_values).")", |
|
123 |
$_SESSION['user_id']); |
1cded8
|
124 |
|
T |
125 |
$insert_id = $DB->insert_id(get_sequence_name('identities')); |
4e17e6
|
126 |
} |
T |
127 |
|
|
128 |
if ($insert_id) |
|
129 |
{ |
|
130 |
$_GET['_iid'] = $insert_id; |
|
131 |
|
|
132 |
if ($_POST['_framed']) |
|
133 |
{ |
|
134 |
// add contact row or jump to the page where it should appear |
|
135 |
// .... |
|
136 |
} |
|
137 |
} |
|
138 |
else |
|
139 |
{ |
|
140 |
// show error message |
10a699
|
141 |
show_message('errorsaving', 'error'); |
T |
142 |
rcmail_overwrite_action('edit-identitiy'); |
4e17e6
|
143 |
} |
T |
144 |
} |
|
145 |
|
|
146 |
|
|
147 |
// go to next step |
10a699
|
148 |
rcmail_overwrite_action($_POST['_framed'] ? 'edit-identitiy' : 'identities'); |
4e17e6
|
149 |
|
T |
150 |
?> |