| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /* |
|---|
| 4 | +-----------------------------------------------------------------------+ |
|---|
| 5 | | program/steps/settings/edit_identity.inc | |
|---|
| 6 | | | |
|---|
| 7 | | This file is part of the Roundcube Webmail client | |
|---|
| 8 | | Copyright (C) 2005-2011, The Roundcube Dev Team | |
|---|
| 9 | | | |
|---|
| 10 | | Licensed under the GNU General Public License version 3 or | |
|---|
| 11 | | any later version with exceptions for skins & plugins. | |
|---|
| 12 | | See the README file for a full license statement. | |
|---|
| 13 | | | |
|---|
| 14 | | PURPOSE: | |
|---|
| 15 | | Show edit form for a identity record or to add a new one | |
|---|
| 16 | | | |
|---|
| 17 | +-----------------------------------------------------------------------+ |
|---|
| 18 | | Author: Thomas Bruederli <roundcube@gmail.com> | |
|---|
| 19 | +-----------------------------------------------------------------------+ |
|---|
| 20 | |
|---|
| 21 | $Id$ |
|---|
| 22 | |
|---|
| 23 | */ |
|---|
| 24 | |
|---|
| 25 | define('IDENTITIES_LEVEL', intval($RCMAIL->config->get('identities_level', 0))); |
|---|
| 26 | |
|---|
| 27 | // edit-identity |
|---|
| 28 | if (($_GET['_iid'] || $_POST['_iid']) && $RCMAIL->action=='edit-identity') { |
|---|
| 29 | $IDENTITY_RECORD = $RCMAIL->user->get_identity(get_input_value('_iid', RCUBE_INPUT_GPC)); |
|---|
| 30 | |
|---|
| 31 | if (is_array($IDENTITY_RECORD)) |
|---|
| 32 | $OUTPUT->set_env('iid', $IDENTITY_RECORD['identity_id']); |
|---|
| 33 | else { |
|---|
| 34 | $OUTPUT->show_message('dberror', 'error'); |
|---|
| 35 | // go to identities page |
|---|
| 36 | rcmail_overwrite_action('identities'); |
|---|
| 37 | return; |
|---|
| 38 | } |
|---|
| 39 | } |
|---|
| 40 | // add-identity |
|---|
| 41 | else { |
|---|
| 42 | if (IDENTITIES_LEVEL > 1) { |
|---|
| 43 | $OUTPUT->show_message('opnotpermitted', 'error'); |
|---|
| 44 | // go to identities page |
|---|
| 45 | rcmail_overwrite_action('identities'); |
|---|
| 46 | return; |
|---|
| 47 | } |
|---|
| 48 | else if (IDENTITIES_LEVEL == 1) |
|---|
| 49 | $IDENTITY_RECORD['email'] = $RCMAIL->user->get_username(); |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | function rcube_identity_form($attrib) |
|---|
| 54 | { |
|---|
| 55 | global $IDENTITY_RECORD, $RCMAIL, $OUTPUT; |
|---|
| 56 | |
|---|
| 57 | // Add HTML editor script(s) |
|---|
| 58 | rcube_html_editor('identity'); |
|---|
| 59 | |
|---|
| 60 | // add some labels to client |
|---|
| 61 | $OUTPUT->add_label('noemailwarning', 'nonamewarning', 'converting', 'editorwarning'); |
|---|
| 62 | |
|---|
| 63 | $i_size = !empty($attrib['size']) ? $attrib['size'] : 40; |
|---|
| 64 | $t_rows = !empty($attrib['textarearows']) ? $attrib['textarearows'] : 6; |
|---|
| 65 | $t_cols = !empty($attrib['textareacols']) ? $attrib['textareacols'] : 40; |
|---|
| 66 | |
|---|
| 67 | // list of available cols |
|---|
| 68 | $form = array( |
|---|
| 69 | 'addressing' => array( |
|---|
| 70 | 'name' => rcube_label('settings'), |
|---|
| 71 | 'content' => array( |
|---|
| 72 | 'name' => array('type' => 'text', 'size' => $i_size), |
|---|
| 73 | 'email' => array('type' => 'text', 'size' => $i_size), |
|---|
| 74 | 'organization' => array('type' => 'text', 'size' => $i_size), |
|---|
| 75 | 'reply-to' => array('type' => 'text', 'size' => $i_size), |
|---|
| 76 | 'bcc' => array('type' => 'text', 'size' => $i_size), |
|---|
| 77 | 'standard' => array('type' => 'checkbox', 'label' => rcube_label('setdefault')), |
|---|
| 78 | )), |
|---|
| 79 | 'signature' => array( |
|---|
| 80 | 'name' => rcube_label('signature'), |
|---|
| 81 | 'content' => array( |
|---|
| 82 | 'signature' => array('type' => 'textarea', 'size' => $t_cols, 'rows' => $t_rows, |
|---|
| 83 | 'spellcheck' => true), |
|---|
| 84 | 'html_signature' => array('type' => 'checkbox', 'label' => rcube_label('htmlsignature'), |
|---|
| 85 | 'onclick' => 'return rcmail_toggle_editor(this, \'rcmfd_signature\');'), |
|---|
| 86 | )) |
|---|
| 87 | ); |
|---|
| 88 | |
|---|
| 89 | // Enable TinyMCE editor |
|---|
| 90 | if ($IDENTITY_RECORD['html_signature']) { |
|---|
| 91 | $form['signature']['content']['signature']['class'] = 'mce_editor'; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | $IDENTITY_RECORD['signature'] = htmlentities($IDENTITY_RECORD['signature'], ENT_NOQUOTES, RCMAIL_CHARSET); |
|---|
| 95 | |
|---|
| 96 | // disable some field according to access level |
|---|
| 97 | if (IDENTITIES_LEVEL == 1 || IDENTITIES_LEVEL == 3) { |
|---|
| 98 | $form['addressing']['content']['email']['disabled'] = true; |
|---|
| 99 | $form['addressing']['content']['email']['class'] = 'disabled'; |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | $IDENTITY_RECORD['email'] = rcube_idn_to_utf8($IDENTITY_RECORD['email']); |
|---|
| 103 | $IDENTITY_RECORD['reply-to'] = rcube_idn_to_utf8($IDENTITY_RECORD['reply-to']); |
|---|
| 104 | $IDENTITY_RECORD['bcc'] = rcube_idn_to_utf8($IDENTITY_RECORD['bcc']); |
|---|
| 105 | |
|---|
| 106 | // Allow plugins to modify identity form content |
|---|
| 107 | $plugin = $RCMAIL->plugins->exec_hook('identity_form', array( |
|---|
| 108 | 'form' => $form, 'record' => $IDENTITY_RECORD)); |
|---|
| 109 | |
|---|
| 110 | $form = $plugin['form']; |
|---|
| 111 | $IDENTITY_RECORD = $plugin['record']; |
|---|
| 112 | |
|---|
| 113 | // Set form tags and hidden fields |
|---|
| 114 | list($form_start, $form_end) = get_form_tags($attrib, 'save-identity', |
|---|
| 115 | intval($IDENTITY_RECORD['identity_id']), |
|---|
| 116 | array('name' => '_iid', 'value' => $IDENTITY_RECORD['identity_id'])); |
|---|
| 117 | |
|---|
| 118 | unset($plugin); |
|---|
| 119 | unset($attrib['form'], $attrib['id']); |
|---|
| 120 | |
|---|
| 121 | // return the complete edit form as table |
|---|
| 122 | $out = "$form_start\n"; |
|---|
| 123 | |
|---|
| 124 | foreach ($form as $fieldset) { |
|---|
| 125 | if (empty($fieldset['content'])) |
|---|
| 126 | continue; |
|---|
| 127 | |
|---|
| 128 | $content = ''; |
|---|
| 129 | if (is_array($fieldset['content'])) { |
|---|
| 130 | $table = new html_table(array('cols' => 2)); |
|---|
| 131 | foreach ($fieldset['content'] as $col => $colprop) { |
|---|
| 132 | $colprop['id'] = 'rcmfd_'.$col; |
|---|
| 133 | |
|---|
| 134 | $label = !empty($colprop['label']) ? $colprop['label'] : |
|---|
| 135 | rcube_label(str_replace('-', '', $col)); |
|---|
| 136 | $value = !empty($colprop['value']) ? $colprop['value'] : |
|---|
| 137 | rcmail_get_edit_field($col, $IDENTITY_RECORD[$col], $colprop, $colprop['type']); |
|---|
| 138 | |
|---|
| 139 | $table->add('title', html::label($colprop['id'], Q($label))); |
|---|
| 140 | $table->add(null, $value); |
|---|
| 141 | } |
|---|
| 142 | $content = $table->show($attrib); |
|---|
| 143 | } |
|---|
| 144 | else { |
|---|
| 145 | $content = $fieldset['content']; |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | $out .= html::tag('fieldset', null, html::tag('legend', null, Q($fieldset['name'])) . $content) ."\n"; |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | $out .= $form_end; |
|---|
| 152 | |
|---|
| 153 | return $out; |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | $OUTPUT->include_script('list.js'); |
|---|
| 157 | $OUTPUT->add_handler('identityform', 'rcube_identity_form'); |
|---|
| 158 | $OUTPUT->set_env('identities_level', IDENTITIES_LEVEL); |
|---|
| 159 | $OUTPUT->add_label('deleteidentityconfirm'); |
|---|
| 160 | |
|---|
| 161 | $OUTPUT->set_pagetitle(rcube_label(($RCMAIL->action=='add-identity' ? 'newidentity' : 'edititem'))); |
|---|
| 162 | |
|---|
| 163 | if ($RCMAIL->action=='add-identity' && $OUTPUT->template_exists('identityadd')) |
|---|
| 164 | $OUTPUT->send('identityadd'); |
|---|
| 165 | |
|---|
| 166 | $OUTPUT->send('identityedit'); |
|---|
| 167 | |
|---|
| 168 | |
|---|