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.

responses.inc 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------+
  4. | program/steps/settings/responses.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. | Manage and save canned response texts |
  15. | |
  16. +-----------------------------------------------------------------------+
  17. | Author: Thomas Bruederli <roundcube@gmail.com> |
  18. +-----------------------------------------------------------------------+
  19. */
  20. if (!empty($_POST['_insert'])) {
  21. $name = trim(rcube_utils::get_input_value('_name', rcube_utils::INPUT_POST));
  22. $text = trim(rcube_utils::get_input_value('_text', rcube_utils::INPUT_POST, true));
  23. if (!empty($name) && !empty($text)) {
  24. $dupes = 0;
  25. $responses = $RCMAIL->get_compose_responses(false, true);
  26. foreach ($responses as $resp) {
  27. if (strcasecmp($name, preg_replace('/\s\(\d+\)$/', '', $resp['name'])) == 0)
  28. $dupes++;
  29. }
  30. if ($dupes) { // require a unique name
  31. $name .= ' (' . ++$dupes . ')';
  32. }
  33. $response = array('name' => $name, 'text' => $text, 'format' => 'text', 'key' => substr(md5($name), 0, 16));
  34. $responses[] = $response;
  35. if ($RCMAIL->user->save_prefs(array('compose_responses' => $responses))) {
  36. $RCMAIL->output->command('add_response_item', $response);
  37. $RCMAIL->output->command('display_message', $RCMAIL->gettext('successfullysaved'), 'confirmation');
  38. }
  39. else {
  40. $RCMAIL->output->command('display_message', $RCMAIL->gettext('errorsaving'), 'error');
  41. }
  42. }
  43. // send response
  44. $RCMAIL->output->send();
  45. }
  46. if ($RCMAIL->action == 'delete-response' && $RCMAIL->output->ajax_call) {
  47. if ($key = rcube_utils::get_input_value('_key', rcube_utils::INPUT_POST)) {
  48. $responses = $RCMAIL->get_compose_responses(false, true);
  49. foreach ($responses as $i => $response) {
  50. if (empty($response['key']))
  51. $response['key'] = substr(md5($response['name']), 0, 16);
  52. if ($response['key'] == $key) {
  53. unset($responses[$i]);
  54. $deleted = $RCMAIL->user->save_prefs(array('compose_responses' => $responses));
  55. break;
  56. }
  57. }
  58. }
  59. if ($deleted) {
  60. $RCMAIL->output->command('display_message', $RCMAIL->gettext('deletedsuccessfully'), 'confirmation');
  61. $RCMAIL->output->command('remove_response', $key);
  62. }
  63. $RCMAIL->output->send();
  64. }
  65. $OUTPUT->set_pagetitle($RCMAIL->gettext('responses'));
  66. $OUTPUT->include_script('list.js');
  67. $OUTPUT->add_handlers(array(
  68. 'responseframe' => 'rcmail_response_frame',
  69. 'responseslist' => 'rcmail_responses_list',
  70. ));
  71. $OUTPUT->add_label('deleteresponseconfirm');
  72. $OUTPUT->send('responses');
  73. /**
  74. *
  75. */
  76. function rcmail_responses_list($attrib)
  77. {
  78. global $RCMAIL, $OUTPUT;
  79. $attrib += array('id' => 'rcmresponseslist', 'tagname' => 'table');
  80. $plugin = $RCMAIL->plugins->exec_hook('responses_list', array(
  81. 'list' => $RCMAIL->get_compose_responses(true),
  82. 'cols' => array('name')
  83. ));
  84. $out = $RCMAIL->table_output($attrib, $plugin['list'], $plugin['cols'], 'key');
  85. $readonly_responses = array();
  86. foreach ($plugin['list'] as $item) {
  87. if (!empty($item['static'])) {
  88. $readonly_responses[] = $item['key'];
  89. }
  90. }
  91. // set client env
  92. $OUTPUT->add_gui_object('responseslist', $attrib['id']);
  93. $OUTPUT->set_env('readonly_responses', $readonly_responses);
  94. return $out;
  95. }
  96. // similar function as /steps/addressbook/func.inc::rcmail_contact_frame()
  97. function rcmail_response_frame($attrib)
  98. {
  99. global $OUTPUT;
  100. if (!$attrib['id']) {
  101. $attrib['id'] = 'rcmResponseFrame';
  102. }
  103. $OUTPUT->set_env('contentframe', $attrib['id']);
  104. return $OUTPUT->frame($attrib, true);
  105. }