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_response.inc 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------+
  4. | program/steps/settings/edit_response.inc |
  5. | |
  6. | This file is part of the Roundcube Webmail client |
  7. | Copyright (C) 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 canned response record or to add a new one |
  15. | |
  16. +-----------------------------------------------------------------------+
  17. | Author: Thomas Bruederli <roundcube@gmail.com> |
  18. +-----------------------------------------------------------------------+
  19. */
  20. $responses = $RCMAIL->get_compose_responses();
  21. // edit-response
  22. if (($key = rcube_utils::get_input_value('_key', rcube_utils::INPUT_GPC))) {
  23. foreach ($responses as $i => $response) {
  24. if ($response['key'] == $key) {
  25. $RESPONSE_RECORD = $response;
  26. $RESPONSE_RECORD['index'] = $i;
  27. break;
  28. }
  29. }
  30. }
  31. // save response
  32. if ($RCMAIL->action == 'save-response' && isset($_POST['_name']) && !$RESPONSE_RECORD['static']) {
  33. $name = trim(rcube_utils::get_input_value('_name', rcube_utils::INPUT_POST));
  34. $text = trim(rcube_utils::get_input_value('_text', rcube_utils::INPUT_POST, true));
  35. if (!empty($name) && !empty($text)) {
  36. $dupes = 0;
  37. foreach ($responses as $i => $resp) {
  38. if ($RESPONSE_RECORD && $RESPONSE_RECORD['index'] === $i)
  39. continue;
  40. if (strcasecmp($name, preg_replace('/\s\(\d+\)$/', '', $resp['name'])) == 0)
  41. $dupes++;
  42. }
  43. if ($dupes) { // require a unique name
  44. $name .= ' (' . ++$dupes . ')';
  45. }
  46. $response = array('name' => $name, 'text' => $text, 'format' => 'text', 'key' => substr(md5($name), 0, 16));
  47. if ($RESPONSE_RECORD && $responses[$RESPONSE_RECORD['index']]) {
  48. $responses[$RESPONSE_RECORD['index']] = $response;
  49. }
  50. else {
  51. $responses[] = $response;
  52. }
  53. $responses = array_filter($responses, function($item){ return empty($item['static']); });
  54. if ($RCMAIL->user->save_prefs(array('compose_responses' => array_values($responses)))) {
  55. $RCMAIL->output->show_message('successfullysaved', 'confirmation');
  56. $RCMAIL->output->command('parent.update_response_row', $response, $key);
  57. $RCMAIL->overwrite_action('edit-response');
  58. $RESPONSE_RECORD = $response;
  59. }
  60. }
  61. else {
  62. $RCMAIL->output->show_message('formincomplete', 'error');
  63. }
  64. }
  65. $OUTPUT->set_env('readonly', !empty($RESPONSE_RECORD['static']));
  66. $OUTPUT->add_handler('responseform', 'rcube_response_form');
  67. $OUTPUT->set_pagetitle($RCMAIL->gettext($RCMAIL->action == 'add-response' ? 'addresponse' : 'editresponse'));
  68. $OUTPUT->send('responseedit');
  69. function rcube_response_form($attrib)
  70. {
  71. global $RCMAIL, $RESPONSE_RECORD;
  72. // Set form tags and hidden fields
  73. $disabled = !empty($RESPONSE_RECORD['static']);
  74. $key = $RESPONSE_RECORD['key'];
  75. list($form_start, $form_end) = get_form_tags($attrib, 'save-response', $key, array('name' => '_key', 'value' => $key));
  76. unset($attrib['form'], $attrib['id']);
  77. // return the complete edit form as table
  78. $out = "$form_start\n";
  79. $table = new html_table(array('cols' => 2));
  80. $table->add('title', html::label('ffname', rcube::Q($RCMAIL->gettext('responsename'))));
  81. $table->add(null, rcube_output::get_edit_field('name', $RESPONSE_RECORD['name'],
  82. array('id' => 'ffname', 'size' => $attrib['size'], 'disabled' => $disabled), 'text'));
  83. $table->add('title', html::label('fftext', rcube::Q($RCMAIL->gettext('responsetext'))));
  84. $table->add(null, rcube_output::get_edit_field('text', $RESPONSE_RECORD['text'],
  85. array('id' => 'fftext', 'size' => $attrib['textareacols'], 'rows' => $attrib['textarearows'], 'disabled' => $disabled), 'textarea'));
  86. $out .= $table->show($attrib);
  87. $out .= $form_end;
  88. return $out;
  89. }