4 +-----------------------------------------------------------------------+
5 | program/steps/settings/edit_identity.inc |
7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2005-2007, Roundcube Dev. - Switzerland |
9 | Licensed under the GNU GPL |
12 | Show edit form for a identity record or to add a new one |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
18 $Id: edit_identity.inc 4509 2011-02-09 10:51:50Z thomasb $
22 define('IDENTITIES_LEVEL', intval($RCMAIL->config->get('identities_level', 0)));
25 if (($_GET['_iid'] || $_POST['_iid']) && $RCMAIL->action=='edit-identity') {
26 $IDENTITY_RECORD = $USER->get_identity(get_input_value('_iid', RCUBE_INPUT_GPC));
28 if (is_array($IDENTITY_RECORD))
29 $OUTPUT->set_env('iid', $IDENTITY_RECORD['identity_id']);
31 $OUTPUT->show_message('opnotpermitted', 'error');
32 // go to identities page
33 rcmail_overwrite_action('identities');
39 if (IDENTITIES_LEVEL > 1) {
40 $OUTPUT->show_message('opnotpermitted', 'error');
41 // go to identities page
42 rcmail_overwrite_action('identities');
45 else if (IDENTITIES_LEVEL == 1)
46 $IDENTITY_RECORD['email'] = $RCMAIL->user->get_username();
50 function rcube_identity_form($attrib)
52 global $IDENTITY_RECORD, $RCMAIL, $OUTPUT;
54 // Add HTML editor script(s)
55 rcube_html_editor('identity');
57 // add some labels to client
58 $OUTPUT->add_label('noemailwarning', 'nonamewarning', 'converting', 'editorwarning');
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;
64 // list of available cols
66 'addressing' => array(
67 'name' => rcube_label('settings'),
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')),
77 'name' => rcube_label('signature'),
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\');'),
86 // Enable TinyMCE editor
87 if ($IDENTITY_RECORD['html_signature']) {
88 $form['signature']['content']['signature']['class'] = 'mce_editor';
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';
97 $IDENTITY_RECORD['email'] = rcube_idn_to_utf8($IDENTITY_RECORD['email']);
98 $IDENTITY_RECORD['reply-to'] = rcube_idn_to_utf8($IDENTITY_RECORD['reply-to']);
99 $IDENTITY_RECORD['bcc'] = rcube_idn_to_utf8($IDENTITY_RECORD['bcc']);
101 // Allow plugins to modify identity form content
102 $plugin = $RCMAIL->plugins->exec_hook('identity_form', array(
103 'form' => $form, 'record' => $IDENTITY_RECORD));
105 $form = $plugin['form'];
106 $IDENTITY_RECORD = $plugin['record'];
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']));
114 unset($attrib['form']);
116 // return the complete edit form as table
117 $out = "$form_start\n";
119 foreach ($form as $fieldset) {
120 if (empty($fieldset['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;
129 $label = !empty($colprop['label']) ? $colprop['label'] :
130 rcube_label(str_replace('-', '', $col));
131 $value = !empty($colprop['value']) ? $colprop['value'] :
132 rcmail_get_edit_field($col, $IDENTITY_RECORD[$col], $colprop, $colprop['type']);
134 $table->add('title', sprintf('<label for="%s">%s</label>', $colprop['id'], Q($label)));
135 $table->add(null, $value);
137 $content = $table->show();
140 $content = $fieldset['content'];
143 $out .= html::tag('fieldset', null, html::tag('legend', null, Q($fieldset['name'])) . $content) ."\n";
151 $OUTPUT->include_script('list.js');
152 $OUTPUT->add_handler('identityform', 'rcube_identity_form');
153 $OUTPUT->set_env('identities_level', IDENTITIES_LEVEL);
155 $OUTPUT->set_pagetitle(rcube_label(($RCMAIL->action=='add-identity' ? 'newidentity' : 'edititem')));
157 if ($RCMAIL->action=='add-identity' && $OUTPUT->template_exists('identityadd'))
158 $OUTPUT->send('identityadd');
160 $OUTPUT->send('identityedit');