Mercurial > hg > rc2
comparison program/steps/settings/responses.inc @ 0:4681f974d28b
vanilla 1.3.3 distro, I hope
author | Charlie Root |
---|---|
date | Thu, 04 Jan 2018 15:52:31 -0500 (2018-01-04) |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4681f974d28b |
---|---|
1 <?php | |
2 | |
3 /** | |
4 +-----------------------------------------------------------------------+ | |
5 | program/steps/settings/responses.inc | | |
6 | | | |
7 | This file is part of the Roundcube Webmail client | | |
8 | Copyright (C) 2013, The Roundcube Dev Team | | |
9 | | | |
10 | Licensed under the GNU General Public License version 3 or | | |
11 | any later version with exceptions for skins & plugins. | | |
12 | See the README file for a full license statement. | | |
13 | | | |
14 | PURPOSE: | | |
15 | Manage and save canned response texts | | |
16 | | | |
17 +-----------------------------------------------------------------------+ | |
18 | Author: Thomas Bruederli <roundcube@gmail.com> | | |
19 +-----------------------------------------------------------------------+ | |
20 */ | |
21 | |
22 | |
23 if (!empty($_POST['_insert'])) { | |
24 $name = trim(rcube_utils::get_input_value('_name', rcube_utils::INPUT_POST)); | |
25 $text = trim(rcube_utils::get_input_value('_text', rcube_utils::INPUT_POST, true)); | |
26 | |
27 if (!empty($name) && !empty($text)) { | |
28 $dupes = 0; | |
29 $responses = $RCMAIL->get_compose_responses(false, true); | |
30 foreach ($responses as $resp) { | |
31 if (strcasecmp($name, preg_replace('/\s\(\d+\)$/', '', $resp['name'])) == 0) | |
32 $dupes++; | |
33 } | |
34 if ($dupes) { // require a unique name | |
35 $name .= ' (' . ++$dupes . ')'; | |
36 } | |
37 | |
38 $response = array('name' => $name, 'text' => $text, 'format' => 'text', 'key' => substr(md5($name), 0, 16)); | |
39 $responses[] = $response; | |
40 | |
41 if ($RCMAIL->user->save_prefs(array('compose_responses' => $responses))) { | |
42 $RCMAIL->output->command('add_response_item', $response); | |
43 $RCMAIL->output->command('display_message', $RCMAIL->gettext('successfullysaved'), 'confirmation'); | |
44 } | |
45 else { | |
46 $RCMAIL->output->command('display_message', $RCMAIL->gettext('errorsaving'), 'error'); | |
47 } | |
48 } | |
49 | |
50 // send response | |
51 $RCMAIL->output->send(); | |
52 } | |
53 | |
54 if ($RCMAIL->action == 'delete-response' && $RCMAIL->output->ajax_call) { | |
55 if ($key = rcube_utils::get_input_value('_key', rcube_utils::INPUT_POST)) { | |
56 $responses = $RCMAIL->get_compose_responses(false, true); | |
57 foreach ($responses as $i => $response) { | |
58 if (empty($response['key'])) | |
59 $response['key'] = substr(md5($response['name']), 0, 16); | |
60 if ($response['key'] == $key) { | |
61 unset($responses[$i]); | |
62 $deleted = $RCMAIL->user->save_prefs(array('compose_responses' => $responses)); | |
63 break; | |
64 } | |
65 } | |
66 } | |
67 | |
68 if ($deleted) { | |
69 $RCMAIL->output->command('display_message', $RCMAIL->gettext('deletedsuccessfully'), 'confirmation'); | |
70 $RCMAIL->output->command('remove_response', $key); | |
71 } | |
72 | |
73 $RCMAIL->output->send(); | |
74 } | |
75 | |
76 | |
77 $OUTPUT->set_pagetitle($RCMAIL->gettext('responses')); | |
78 $OUTPUT->include_script('list.js'); | |
79 | |
80 $OUTPUT->add_handlers(array( | |
81 'responseframe' => 'rcmail_response_frame', | |
82 'responseslist' => 'rcmail_responses_list', | |
83 )); | |
84 $OUTPUT->add_label('deleteresponseconfirm'); | |
85 | |
86 $OUTPUT->send('responses'); | |
87 | |
88 | |
89 /** | |
90 * | |
91 */ | |
92 function rcmail_responses_list($attrib) | |
93 { | |
94 global $RCMAIL, $OUTPUT; | |
95 | |
96 $attrib += array('id' => 'rcmresponseslist', 'tagname' => 'table'); | |
97 | |
98 $plugin = $RCMAIL->plugins->exec_hook('responses_list', array( | |
99 'list' => $RCMAIL->get_compose_responses(true), | |
100 'cols' => array('name') | |
101 )); | |
102 | |
103 $out = $RCMAIL->table_output($attrib, $plugin['list'], $plugin['cols'], 'key'); | |
104 | |
105 $readonly_responses = array(); | |
106 foreach ($plugin['list'] as $item) { | |
107 if (!empty($item['static'])) { | |
108 $readonly_responses[] = $item['key']; | |
109 } | |
110 } | |
111 | |
112 // set client env | |
113 $OUTPUT->add_gui_object('responseslist', $attrib['id']); | |
114 $OUTPUT->set_env('readonly_responses', $readonly_responses); | |
115 | |
116 return $out; | |
117 } | |
118 | |
119 // similar function as /steps/addressbook/func.inc::rcmail_contact_frame() | |
120 function rcmail_response_frame($attrib) | |
121 { | |
122 global $OUTPUT; | |
123 | |
124 if (!$attrib['id']) { | |
125 $attrib['id'] = 'rcmResponseFrame'; | |
126 } | |
127 | |
128 $OUTPUT->set_env('contentframe', $attrib['id']); | |
129 | |
130 return $OUTPUT->frame($attrib, true); | |
131 } |