| 1 | <?php |
|---|
| 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-2009, Roundcube Dev. - Switzerland | |
|---|
| 9 | | Licensed under the GNU GPL | |
|---|
| 10 | | | |
|---|
| 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 | |
|---|
| 22 | define('IDENTITIES_LEVEL', intval($RCMAIL->config->get('identities_level', 0))); |
|---|
| 23 | |
|---|
| 24 | $a_save_cols = array('name', 'email', 'organization', 'reply-to', 'bcc', 'standard', 'signature', 'html_signature'); |
|---|
| 25 | $a_html_cols = array('signature'); |
|---|
| 26 | $a_boolean_cols = array('standard', 'html_signature'); |
|---|
| 27 | $updated = $default_id = false; |
|---|
| 28 | |
|---|
| 29 | // check input |
|---|
| 30 | if (empty($_POST['_name']) || (empty($_POST['_email']) && IDENTITIES_LEVEL != 1 && IDENTITIES_LEVEL != 3)) |
|---|
| 31 | { |
|---|
| 32 | $OUTPUT->show_message('formincomplete', 'warning'); |
|---|
| 33 | rcmail_overwrite_action('edit-identity'); |
|---|
| 34 | return; |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | $save_data = array(); |
|---|
| 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 | } |
|---|
| 54 | |
|---|
| 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']); |
|---|
| 58 | |
|---|
| 59 | // Validate e-mail addresses |
|---|
| 60 | foreach (array('email', 'reply-to', 'bcc') as $item) { |
|---|
| 61 | if ($email = $save_data[$item]) { |
|---|
| 62 | $ascii_email = rcube_idn_to_ascii($email); |
|---|
| 63 | if (!check_email($ascii_email)) { |
|---|
| 64 | // show error message |
|---|
| 65 | $OUTPUT->show_message('emailformaterror', 'error', array('email' => $email), false); |
|---|
| 66 | rcmail_overwrite_action('edit-identity'); |
|---|
| 67 | return; |
|---|
| 68 | } |
|---|
| 69 | } |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | // update an existing contact |
|---|
| 73 | if ($_POST['_iid']) |
|---|
| 74 | { |
|---|
| 75 | $iid = get_input_value('_iid', RCUBE_INPUT_POST); |
|---|
| 76 | $plugin = $RCMAIL->plugins->exec_hook('identity_update', array('id' => $iid, 'record' => $save_data)); |
|---|
| 77 | $save_data = $plugin['record']; |
|---|
| 78 | |
|---|
| 79 | if ($save_data['email']) |
|---|
| 80 | $save_data['email'] = rcube_idn_to_ascii($save_data['email']); |
|---|
| 81 | if ($save_data['bcc']) |
|---|
| 82 | $save_data['bcc'] = rcube_idn_to_ascii($save_data['bcc']); |
|---|
| 83 | if ($save_data['reply-to']) |
|---|
| 84 | $save_data['reply-to'] = rcube_idn_to_ascii($save_data['reply-to']); |
|---|
| 85 | |
|---|
| 86 | if (!$plugin['abort']) |
|---|
| 87 | $updated = $USER->update_identity($iid, $save_data); |
|---|
| 88 | else |
|---|
| 89 | $updated = $plugin['result']; |
|---|
| 90 | |
|---|
| 91 | if ($updated) { |
|---|
| 92 | $OUTPUT->show_message('successfullysaved', 'confirmation'); |
|---|
| 93 | |
|---|
| 94 | if (!empty($_POST['_standard'])) |
|---|
| 95 | $default_id = get_input_value('_iid', RCUBE_INPUT_POST); |
|---|
| 96 | |
|---|
| 97 | if ($_POST['_framed']) { |
|---|
| 98 | // update the changed col in list |
|---|
| 99 | // ... |
|---|
| 100 | } |
|---|
| 101 | } |
|---|
| 102 | else { |
|---|
| 103 | // show error message |
|---|
| 104 | $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error', null, false); |
|---|
| 105 | rcmail_overwrite_action('edit-identity'); |
|---|
| 106 | return; |
|---|
| 107 | } |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | // insert a new identity record |
|---|
| 111 | else if (IDENTITIES_LEVEL < 2) |
|---|
| 112 | { |
|---|
| 113 | if (IDENTITIES_LEVEL == 1) |
|---|
| 114 | $save_data['email'] = $RCMAIL->user->get_username(); |
|---|
| 115 | |
|---|
| 116 | $plugin = $RCMAIL->plugins->exec_hook('identity_create', array('record' => $save_data)); |
|---|
| 117 | $save_data = $plugin['record']; |
|---|
| 118 | |
|---|
| 119 | if ($save_data['email']) |
|---|
| 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']); |
|---|
| 125 | |
|---|
| 126 | if (!$plugin['abort']) |
|---|
| 127 | $insert_id = $save_data['email'] ? $USER->insert_identity($save_data) : null; |
|---|
| 128 | else |
|---|
| 129 | $insert_id = $plugin['result']; |
|---|
| 130 | |
|---|
| 131 | if ($insert_id) { |
|---|
| 132 | $OUTPUT->show_message('successfullysaved', 'confirmation', null, false); |
|---|
| 133 | |
|---|
| 134 | $_GET['_iid'] = $insert_id; |
|---|
| 135 | |
|---|
| 136 | if (!empty($_POST['_standard'])) |
|---|
| 137 | $default_id = $insert_id; |
|---|
| 138 | } |
|---|
| 139 | else { |
|---|
| 140 | // show error message |
|---|
| 141 | $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error', null, false); |
|---|
| 142 | rcmail_overwrite_action('edit-identity'); |
|---|
| 143 | return; |
|---|
| 144 | } |
|---|
| 145 | } |
|---|
| 146 | else |
|---|
| 147 | $OUTPUT->show_message('opnotpermitted', 'error'); |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | // mark all other identities as 'not-default' |
|---|
| 151 | if ($default_id) |
|---|
| 152 | $USER->set_default($default_id); |
|---|
| 153 | |
|---|
| 154 | // go to next step |
|---|
| 155 | rcmail_overwrite_action('identities'); |
|---|