| 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-2007, Roundcube Dev. - Switzerland | |
|---|
| 9 | | Licensed under the GNU GPL | |
|---|
| 10 | | | |
|---|
| 11 | | PURPOSE: | |
|---|
| 12 | | Show edit form for a 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 | // edit-identity |
|---|
| 25 | if (($_GET['_iid'] || $_POST['_iid']) && $RCMAIL->action=='edit-identity') { |
|---|
| 26 | $IDENTITY_RECORD = $USER->get_identity(get_input_value('_iid', RCUBE_INPUT_GPC)); |
|---|
| 27 | |
|---|
| 28 | if (is_array($IDENTITY_RECORD)) |
|---|
| 29 | $OUTPUT->set_env('iid', $IDENTITY_RECORD['identity_id']); |
|---|
| 30 | else { |
|---|
| 31 | $OUTPUT->show_message('opnotpermitted', 'error'); |
|---|
| 32 | // go to identities page |
|---|
| 33 | rcmail_overwrite_action('identities'); |
|---|
| 34 | return; |
|---|
| 35 | } |
|---|
| 36 | } |
|---|
| 37 | // add-identity |
|---|
| 38 | else { |
|---|
| 39 | if (IDENTITIES_LEVEL > 1) { |
|---|
| 40 | $OUTPUT->show_message('opnotpermitted', 'error'); |
|---|
| 41 | // go to identities page |
|---|
| 42 | rcmail_overwrite_action('identities'); |
|---|
| 43 | return; |
|---|
| 44 | } |
|---|
| 45 | else if (IDENTITIES_LEVEL == 1) |
|---|
| 46 | $IDENTITY_RECORD['email'] = $RCMAIL->user->get_username(); |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | function rcube_identity_form($attrib) |
|---|
| 51 | { |
|---|
| 52 | global $IDENTITY_RECORD, $RCMAIL, $OUTPUT; |
|---|
| 53 | |
|---|
| 54 | // Add HTML editor script(s) |
|---|
| 55 | rcube_html_editor('identity'); |
|---|
| 56 | |
|---|
| 57 | // add some labels to client |
|---|
| 58 | $OUTPUT->add_label('noemailwarning', 'nonamewarning', 'converting', 'editorwarning'); |
|---|
| 59 | |
|---|
| 60 | $i_size = !empty($attrib['size']) ? $attrib['size'] : 40; |
|---|
| 61 | $t_rows = !empty($attrib['textarearows']) ? $attrib['textarearows'] : 6; |
|---|
| 62 | $t_cols = !empty($attrib['textareacols']) ? $attrib['textareacols'] : 40; |
|---|
| 63 | |
|---|
| 64 | // list of available cols |
|---|
| 65 | $form = array( |
|---|
| 66 | 'addressing' => array( |
|---|
| 67 | 'name' => rcube_label('settings'), |
|---|
| 68 | 'content' => array( |
|---|
| 69 | 'name' => array('type' => 'text', 'size' => $i_size), |
|---|
| 70 | 'email' => array('type' => 'text', 'size' => $i_size), |
|---|
| 71 | 'organization' => array('type' => 'text', 'size' => $i_size), |
|---|
| 72 | 'reply-to' => array('type' => 'text', 'size' => $i_size), |
|---|
| 73 | 'bcc' => array('type' => 'text', 'size' => $i_size), |
|---|
| 74 | 'standard' => array('type' => 'checkbox', 'label' => rcube_label('setdefault')), |
|---|
| 75 | )), |
|---|
| 76 | 'signature' => array( |
|---|
| 77 | 'name' => rcube_label('signature'), |
|---|
| 78 | 'content' => array( |
|---|
| 79 | 'signature' => array('type' => 'textarea', 'size' => $t_cols, 'rows' => $t_rows, |
|---|
| 80 | 'spellcheck' => true), |
|---|
| 81 | 'html_signature' => array('type' => 'checkbox', 'label' => rcube_label('htmlsignature'), |
|---|
| 82 | 'onclick' => 'return rcmail_toggle_editor(this, \'rcmfd_signature\');'), |
|---|
| 83 | )) |
|---|
| 84 | ); |
|---|
| 85 | |
|---|
| 86 | // Enable TinyMCE editor |
|---|
| 87 | if ($IDENTITY_RECORD['html_signature']) { |
|---|
| 88 | $form['signature']['content']['signature']['class'] = 'mce_editor'; |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | // disable some field according to access level |
|---|
| 92 | if (IDENTITIES_LEVEL == 1 || IDENTITIES_LEVEL == 3) { |
|---|
| 93 | $form['addressing']['content']['email']['disabled'] = true; |
|---|
| 94 | $form['addressing']['content']['email']['class'] = 'disabled'; |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | $IDENTITY_RECORD['email'] = idn_to_utf8($IDENTITY_RECORD['email']); |
|---|
| 98 | $IDENTITY_RECORD['reply-to'] = idn_to_utf8($IDENTITY_RECORD['reply-to']); |
|---|
| 99 | $IDENTITY_RECORD['bcc'] = idn_to_utf8($IDENTITY_RECORD['bcc']); |
|---|
| 100 | |
|---|
| 101 | // Allow plugins to modify identity form content |
|---|
| 102 | $plugin = $RCMAIL->plugins->exec_hook('identity_form', array( |
|---|
| 103 | 'form' => $form, 'record' => $IDENTITY_RECORD)); |
|---|
| 104 | |
|---|
| 105 | $form = $plugin['form']; |
|---|
| 106 | $IDENTITY_RECORD = $plugin['record']; |
|---|
| 107 | |
|---|
| 108 | // Set form tags and hidden fields |
|---|
| 109 | list($form_start, $form_end) = get_form_tags($attrib, 'save-identity', |
|---|
| 110 | intval($IDENTITY_RECORD['identity_id']), |
|---|
| 111 | array('name' => '_iid', 'value' => $IDENTITY_RECORD['identity_id'])); |
|---|
| 112 | |
|---|
| 113 | unset($plugin); |
|---|
| 114 | unset($attrib['form']); |
|---|
| 115 | |
|---|
| 116 | // return the complete edit form as table |
|---|
| 117 | $out = "$form_start\n"; |
|---|
| 118 | |
|---|
| 119 | foreach ($form as $fieldset) { |
|---|
| 120 | if (empty($fieldset['content'])) |
|---|
| 121 | continue; |
|---|
| 122 | |
|---|
| 123 | $content = ''; |
|---|
| 124 | if (is_array($fieldset['content'])) { |
|---|
| 125 | $table = new html_table(array('cols' => 2)); |
|---|
| 126 | foreach ($fieldset['content'] as $col => $colprop) { |
|---|
| 127 | $colprop['id'] = 'rcmfd_'.$col; |
|---|
| 128 | |
|---|
| 129 | $label = !empty($colprop['label']) ? $colprop['label'] : rcube_label($col); |
|---|
| 130 | $value = !empty($colprop['value']) ? $colprop['value'] : |
|---|
| 131 | rcmail_get_edit_field($col, $IDENTITY_RECORD[$col], $colprop, $colprop['type']); |
|---|
| 132 | |
|---|
| 133 | $table->add('title', sprintf('<label for="%s">%s</label>', $colprop['id'], Q($label))); |
|---|
| 134 | $table->add(null, $value); |
|---|
| 135 | } |
|---|
| 136 | $content = $table->show(); |
|---|
| 137 | } |
|---|
| 138 | else { |
|---|
| 139 | $content = $fieldset['content']; |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | $out .= html::tag('fieldset', null, html::tag('legend', null, Q($fieldset['name'])) . $content) ."\n"; |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | $out .= $form_end; |
|---|
| 146 | |
|---|
| 147 | return $out; |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | $OUTPUT->include_script('list.js'); |
|---|
| 151 | $OUTPUT->add_handler('identityform', 'rcube_identity_form'); |
|---|
| 152 | $OUTPUT->set_env('identities_level', IDENTITIES_LEVEL); |
|---|
| 153 | |
|---|
| 154 | $OUTPUT->set_pagetitle(rcube_label(($RCMAIL->action=='add-identity' ? 'newidentity' : 'edititem'))); |
|---|
| 155 | |
|---|
| 156 | if ($RCMAIL->action=='add-identity' && $OUTPUT->template_exists('addidentity')) |
|---|
| 157 | $OUTPUT->send('addidentity'); |
|---|
| 158 | |
|---|
| 159 | $OUTPUT->send('editidentity'); |
|---|
| 160 | |
|---|
| 161 | |
|---|