commit | author | age
|
4e17e6
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
+-----------------------------------------------------------------------+ |
|
5 |
| program/steps/settings/save_identity.inc | |
|
6 |
| | |
e019f2
|
7 |
| This file is part of the Roundcube Webmail client | |
f5e7b3
|
8 |
| Copyright (C) 2005-2009, The Roundcube Dev Team | |
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 |
|
ec0171
|
22 |
define('IDENTITIES_LEVEL', intval($RCMAIL->config->get('identities_level', 0))); |
A |
23 |
|
a0109c
|
24 |
$a_save_cols = array('name', 'email', 'organization', 'reply-to', 'bcc', 'standard', 'signature', 'html_signature'); |
516467
|
25 |
$a_html_cols = array('signature', 'name', 'organization'); |
a0109c
|
26 |
$a_boolean_cols = array('standard', 'html_signature'); |
6ec91f
|
27 |
$updated = $default_id = false; |
4e17e6
|
28 |
|
10a699
|
29 |
// check input |
ec0171
|
30 |
if (empty($_POST['_name']) || (empty($_POST['_email']) && IDENTITIES_LEVEL != 1 && IDENTITIES_LEVEL != 3)) |
516467
|
31 |
{ |
f11541
|
32 |
$OUTPUT->show_message('formincomplete', 'warning'); |
407dcf
|
33 |
rcmail_overwrite_action('edit-identity'); |
10a699
|
34 |
return; |
516467
|
35 |
} |
10a699
|
36 |
|
T |
37 |
|
fba1f5
|
38 |
$save_data = array(); |
T |
39 |
foreach ($a_save_cols as $col) |
|
40 |
{ |
|
41 |
$fname = '_'.$col; |
|
42 |
if (isset($_POST[$fname])) |
|
43 |
$save_data[$col] = get_input_value($fname, RCUBE_INPUT_POST, in_array($col, $a_html_cols)); |
|
44 |
} |
|
45 |
|
|
46 |
// set "off" values for checkboxes that were not checked, and therefore |
|
47 |
// not included in the POST body. |
|
48 |
foreach ($a_boolean_cols as $col) |
|
49 |
{ |
|
50 |
$fname = '_' . $col; |
|
51 |
if (!isset($_POST[$fname])) |
|
52 |
$save_data[$col] = 0; |
|
53 |
} |
ec0171
|
54 |
|
A |
55 |
// unset email address if user has no rights to change it |
|
56 |
if (IDENTITIES_LEVEL == 1 || IDENTITIES_LEVEL == 3) |
|
57 |
unset($save_data['email']); |
fba1f5
|
58 |
|
e99991
|
59 |
// Validate e-mail addresses |
A |
60 |
foreach (array('email', 'reply-to', 'bcc') as $item) { |
|
61 |
if ($email = $save_data[$item]) { |
e8d5bd
|
62 |
$ascii_email = rcube_idn_to_ascii($email); |
d80bd1
|
63 |
if (!check_email($ascii_email)) { |
e99991
|
64 |
// show error message |
A |
65 |
$OUTPUT->show_message('emailformaterror', 'error', array('email' => $email), false); |
|
66 |
rcmail_overwrite_action('edit-identity'); |
|
67 |
return; |
|
68 |
} |
|
69 |
} |
|
70 |
} |
fba1f5
|
71 |
|
4e17e6
|
72 |
// update an existing contact |
T |
73 |
if ($_POST['_iid']) |
fba1f5
|
74 |
{ |
69f18a
|
75 |
$iid = get_input_value('_iid', RCUBE_INPUT_POST); |
119ad1
|
76 |
$plugin = $RCMAIL->plugins->exec_hook('identity_update', array('id' => $iid, 'record' => $save_data)); |
69f18a
|
77 |
$save_data = $plugin['record']; |
e99991
|
78 |
|
A |
79 |
if ($save_data['email']) |
e8d5bd
|
80 |
$save_data['email'] = rcube_idn_to_ascii($save_data['email']); |
e99991
|
81 |
if ($save_data['bcc']) |
e8d5bd
|
82 |
$save_data['bcc'] = rcube_idn_to_ascii($save_data['bcc']); |
e99991
|
83 |
if ($save_data['reply-to']) |
e8d5bd
|
84 |
$save_data['reply-to'] = rcube_idn_to_ascii($save_data['reply-to']); |
69f18a
|
85 |
|
ce92ba
|
86 |
if (!$plugin['abort']) |
A |
87 |
$updated = $USER->update_identity($iid, $save_data); |
|
88 |
else |
|
89 |
$updated = $plugin['result']; |
|
90 |
|
|
91 |
if ($updated) { |
461253
|
92 |
$OUTPUT->show_message('successfullysaved', 'confirmation'); |
ce92ba
|
93 |
|
461253
|
94 |
if (!empty($_POST['_standard'])) |
A |
95 |
$default_id = get_input_value('_iid', RCUBE_INPUT_POST); |
ce92ba
|
96 |
|
A |
97 |
if ($_POST['_framed']) { |
461253
|
98 |
// update the changed col in list |
e99991
|
99 |
// ... |
4e17e6
|
100 |
} |
461253
|
101 |
} |
ce92ba
|
102 |
else { |
461253
|
103 |
// show error message |
ce92ba
|
104 |
$OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error', null, false); |
461253
|
105 |
rcmail_overwrite_action('edit-identity'); |
A |
106 |
return; |
4e17e6
|
107 |
} |
fba1f5
|
108 |
} |
4e17e6
|
109 |
|
c1b3c4
|
110 |
// insert a new identity record |
ec0171
|
111 |
else if (IDENTITIES_LEVEL < 2) |
fba1f5
|
112 |
{ |
ec0171
|
113 |
if (IDENTITIES_LEVEL == 1) |
82c45a
|
114 |
$save_data['email'] = $RCMAIL->user->get_username(); |
ec0171
|
115 |
|
e6ce00
|
116 |
$plugin = $RCMAIL->plugins->exec_hook('identity_create', array('record' => $save_data)); |
69f18a
|
117 |
$save_data = $plugin['record']; |
T |
118 |
|
2d5bee
|
119 |
if ($save_data['email']) |
A |
120 |
$save_data['email'] = rcube_idn_to_ascii($save_data['email']); |
|
121 |
if ($save_data['bcc']) |
|
122 |
$save_data['bcc'] = rcube_idn_to_ascii($save_data['bcc']); |
|
123 |
if ($save_data['reply-to']) |
|
124 |
$save_data['reply-to'] = rcube_idn_to_ascii($save_data['reply-to']); |
e99991
|
125 |
|
ce92ba
|
126 |
if (!$plugin['abort']) |
A |
127 |
$insert_id = $save_data['email'] ? $USER->insert_identity($save_data) : null; |
|
128 |
else |
|
129 |
$insert_id = $plugin['result']; |
|
130 |
|
|
131 |
if ($insert_id) { |
461253
|
132 |
$OUTPUT->show_message('successfullysaved', 'confirmation', null, false); |
2d5bee
|
133 |
|
461253
|
134 |
$_GET['_iid'] = $insert_id; |
4e17e6
|
135 |
|
461253
|
136 |
if (!empty($_POST['_standard'])) |
A |
137 |
$default_id = $insert_id; |
|
138 |
} |
ce92ba
|
139 |
else { |
461253
|
140 |
// show error message |
ce92ba
|
141 |
$OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error', null, false); |
461253
|
142 |
rcmail_overwrite_action('edit-identity'); |
A |
143 |
return; |
4e17e6
|
144 |
} |
fba1f5
|
145 |
} |
f645ce
|
146 |
else |
T |
147 |
$OUTPUT->show_message('opnotpermitted', 'error'); |
4e17e6
|
148 |
|
T |
149 |
|
6ec91f
|
150 |
// mark all other identities as 'not-default' |
T |
151 |
if ($default_id) |
fba1f5
|
152 |
$USER->set_default($default_id); |
6ec91f
|
153 |
|
4e17e6
|
154 |
// go to next step |
c1b3c4
|
155 |
rcmail_overwrite_action('identities'); |