comparison program/steps/settings/edit_response.inc @ 0:4681f974d28b

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