source: subversion/trunk/roundcubemail/program/steps/settings/edit_identity.inc @ 3989

Last change on this file since 3989 was 3989, checked in by alec, 3 years ago
  • s/RoundCube/Roundcube/
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.5 KB
Line 
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
22define('IDENTITIES_LEVEL', intval($RCMAIL->config->get('identities_level', 0)));
23
24// edit-identity
25if (($_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
38else {
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
50function 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['adressing']['content']['email']['disabled'] = true;
94    $form['adressing']['content']['email']['class'] = 'disabled';
95  }
96
97  // Allow plugins to modify identity form content
98  $plugin = $RCMAIL->plugins->exec_hook('identity_form', array(
99    'form' => $form, 'record' => $IDENTITY_RECORD));
100
101  $form = $plugin['form'];
102  $IDENTITY_RECORD = $plugin['record'];
103
104  // Set form tags and hidden fields
105  list($form_start, $form_end) = get_form_tags($attrib, 'save-identity',
106    intval($IDENTITY_RECORD['identity_id']),
107    array('name' => '_iid', 'value' => $IDENTITY_RECORD['identity_id']));
108
109  unset($plugin);
110  unset($attrib['form']);
111
112  // return the complete edit form as table
113  $out = "$form_start\n";
114
115  foreach ($form as $fieldset) {
116    if (empty($fieldset['content']))
117      continue;
118
119    $content = '';
120    if (is_array($fieldset['content'])) {
121      $table = new html_table(array('cols' => 2));
122      foreach ($fieldset['content'] as $col => $colprop) {
123        $colprop['id'] = 'rcmfd_'.$col;
124
125        $label = !empty($colprop['label']) ? $colprop['label'] : rcube_label($col);
126        $value = !empty($colprop['value']) ? $colprop['value'] :
127            rcmail_get_edit_field($col, $IDENTITY_RECORD[$col], $colprop, $colprop['type']);
128
129        $table->add('title', sprintf('<label for="%s">%s</label>', $colprop['id'], Q($label)));
130        $table->add(null, $value);
131      }
132      $content = $table->show();
133    }
134    else {
135      $content = $fieldset['content'];
136    }
137
138    $out .= html::tag('fieldset', null, html::tag('legend', null, Q($fieldset['name'])) . $content) ."\n";
139  }
140
141  $out .= $form_end;
142
143  return $out;
144}
145
146$OUTPUT->include_script('list.js');
147$OUTPUT->add_handler('identityform', 'rcube_identity_form');
148$OUTPUT->set_env('identities_level', IDENTITIES_LEVEL);
149
150$OUTPUT->set_pagetitle(rcube_label(($RCMAIL->action=='add-identity' ? 'newidentity' : 'edititem')));
151
152if ($RCMAIL->action=='add-identity' && $OUTPUT->template_exists('addidentity'))
153  $OUTPUT->send('addidentity');
154
155$OUTPUT->send('editidentity');
156
157
Note: See TracBrowser for help on using the repository browser.