You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

edit_identity.inc 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------+
  4. | program/steps/settings/edit_identity.inc |
  5. | |
  6. | This file is part of the Roundcube Webmail client |
  7. | Copyright (C) 2005-2013, The Roundcube Dev Team |
  8. | |
  9. | Licensed under the GNU General Public License version 3 or |
  10. | any later version with exceptions for skins & plugins. |
  11. | See the README file for a full license statement. |
  12. | |
  13. | PURPOSE: |
  14. | Show edit form for a identity record or to add a new one |
  15. | |
  16. +-----------------------------------------------------------------------+
  17. | Author: Thomas Bruederli <roundcube@gmail.com> |
  18. +-----------------------------------------------------------------------+
  19. */
  20. define('IDENTITIES_LEVEL', intval($RCMAIL->config->get('identities_level', 0)));
  21. // edit-identity
  22. if (($_GET['_iid'] || $_POST['_iid']) && $RCMAIL->action=='edit-identity') {
  23. $id = rcube_utils::get_input_value('_iid', rcube_utils::INPUT_GPC);
  24. $IDENTITY_RECORD = $RCMAIL->user->get_identity($id);
  25. if (is_array($IDENTITY_RECORD)) {
  26. $OUTPUT->set_env('iid', $IDENTITY_RECORD['identity_id']);
  27. }
  28. else {
  29. $OUTPUT->show_message('dberror', 'error');
  30. // go to identities page
  31. $RCMAIL->overwrite_action('identities');
  32. return;
  33. }
  34. }
  35. // add-identity
  36. else {
  37. if (IDENTITIES_LEVEL > 1) {
  38. $OUTPUT->show_message('opnotpermitted', 'error');
  39. // go to identities page
  40. $RCMAIL->overwrite_action('identities');
  41. return;
  42. }
  43. else if (IDENTITIES_LEVEL == 1) {
  44. $IDENTITY_RECORD['email'] = $RCMAIL->get_user_email();
  45. }
  46. }
  47. $OUTPUT->include_script('list.js');
  48. $OUTPUT->add_handler('identityform', 'rcube_identity_form');
  49. $OUTPUT->set_env('identities_level', IDENTITIES_LEVEL);
  50. $OUTPUT->add_label('deleteidentityconfirm', 'uploading');
  51. $OUTPUT->set_pagetitle($RCMAIL->gettext(($RCMAIL->action == 'add-identity' ? 'addidentity' : 'editidentity')));
  52. if ($RCMAIL->action == 'add-identity' && $OUTPUT->template_exists('identityadd')) {
  53. $OUTPUT->send('identityadd');
  54. }
  55. $OUTPUT->send('identityedit');
  56. function rcube_identity_form($attrib)
  57. {
  58. global $IDENTITY_RECORD, $RCMAIL, $OUTPUT;
  59. // Add HTML editor script(s)
  60. $RCMAIL->html_editor('identity');
  61. // add some labels to client
  62. $OUTPUT->add_label('noemailwarning', 'converting', 'editorwarning');
  63. $i_size = $attrib['size'] ?: 40;
  64. $t_rows = $attrib['textarearows'] ?: 6;
  65. $t_cols = $attrib['textareacols'] ?: 40;
  66. // list of available cols
  67. $form = array(
  68. 'addressing' => array(
  69. 'name' => $RCMAIL->gettext('settings'),
  70. 'content' => array(
  71. 'name' => array('type' => 'text', 'size' => $i_size),
  72. 'email' => array('type' => 'text', 'size' => $i_size),
  73. 'organization' => array('type' => 'text', 'size' => $i_size),
  74. 'reply-to' => array('type' => 'text', 'size' => $i_size),
  75. 'bcc' => array('type' => 'text', 'size' => $i_size),
  76. 'standard' => array('type' => 'checkbox', 'label' => $RCMAIL->gettext('setdefault')),
  77. )),
  78. 'signature' => array(
  79. 'name' => $RCMAIL->gettext('signature'),
  80. 'content' => array(
  81. 'signature' => array('type' => 'textarea', 'size' => $t_cols, 'rows' => $t_rows,
  82. 'spellcheck' => true),
  83. 'html_signature' => array('type' => 'checkbox',
  84. 'label' => $RCMAIL->gettext('htmlsignature'),
  85. 'onclick' => 'return rcmail.command(\'toggle-editor\', {id: \'rcmfd_signature\', html: this.checked}, \'\', event)'),
  86. ))
  87. );
  88. // Enable TinyMCE editor
  89. if ($IDENTITY_RECORD['html_signature']) {
  90. $form['signature']['content']['signature']['class'] = 'mce_editor';
  91. $form['signature']['content']['signature']['is_escaped'] = true;
  92. // Correctly handle HTML entities in HTML editor (#1488483)
  93. $IDENTITY_RECORD['signature'] = htmlspecialchars($IDENTITY_RECORD['signature'], ENT_NOQUOTES, RCUBE_CHARSET);
  94. }
  95. // hide "default" checkbox if only one identity is allowed
  96. if (IDENTITIES_LEVEL > 1) {
  97. unset($form['addressing']['content']['standard']);
  98. }
  99. // disable some field according to access level
  100. if (IDENTITIES_LEVEL == 1 || IDENTITIES_LEVEL == 3) {
  101. $form['addressing']['content']['email']['disabled'] = true;
  102. $form['addressing']['content']['email']['class'] = 'disabled';
  103. }
  104. if (IDENTITIES_LEVEL == 4) {
  105. foreach($form['addressing']['content'] as $formfield => $value){
  106. $form['addressing']['content'][$formfield]['disabled'] = true;
  107. $form['addressing']['content'][$formfield]['class'] = 'disabled';
  108. }
  109. }
  110. $IDENTITY_RECORD['email'] = rcube_utils::idn_to_utf8($IDENTITY_RECORD['email']);
  111. // Allow plugins to modify identity form content
  112. $plugin = $RCMAIL->plugins->exec_hook('identity_form', array(
  113. 'form' => $form, 'record' => $IDENTITY_RECORD));
  114. $form = $plugin['form'];
  115. $IDENTITY_RECORD = $plugin['record'];
  116. // Set form tags and hidden fields
  117. list($form_start, $form_end) = get_form_tags($attrib, 'save-identity',
  118. intval($IDENTITY_RECORD['identity_id']),
  119. array('name' => '_iid', 'value' => $IDENTITY_RECORD['identity_id']));
  120. unset($plugin);
  121. unset($attrib['form'], $attrib['id']);
  122. // return the complete edit form as table
  123. $out = "$form_start\n";
  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. $label = $colprop['label'] ?: $RCMAIL->gettext(str_replace('-', '', $col));
  134. $value = $colprop['value'] ?: rcube_output::get_edit_field($col, $IDENTITY_RECORD[$col], $colprop, $colprop['type']);
  135. $table->add('title', html::label($colprop['id'], rcube::Q($label)));
  136. $table->add(null, $value);
  137. }
  138. $content = $table->show($attrib);
  139. }
  140. else {
  141. $content = $fieldset['content'];
  142. }
  143. $content = html::tag('legend', null, rcube::Q($fieldset['name'])) . $content;
  144. $out .= html::tag('fieldset', null, $content) . "\n";
  145. }
  146. $out .= $form_end;
  147. // add image upload form
  148. $max_filesize = $RCMAIL->upload_init($RCMAIL->config->get('identity_image_size', 64) * 1024);
  149. $upload_form_id = 'identityImageUpload';
  150. $out .= '<form id="' . $upload_form_id . '" style="display: none">'
  151. . html::div('hint', $RCMAIL->gettext(array('name' => 'maxuploadsize', 'vars' => array('size' => $max_filesize))))
  152. . '</form>';
  153. $RCMAIL->output->add_gui_object('uploadform', $upload_form_id);
  154. return $out;
  155. }