File: response_edit.php

package info (click to toggle)
roundcube 1.6.13%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 44,888 kB
  • sloc: javascript: 195,591; php: 76,917; sql: 3,150; sh: 2,882; pascal: 1,079; makefile: 234; xml: 93; perl: 73; ansic: 48; python: 21
file content (124 lines) | stat: -rw-r--r-- 4,971 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php

/**
 +-----------------------------------------------------------------------+
 | This file is part of the Roundcube Webmail client                     |
 |                                                                       |
 | Copyright (C) The Roundcube Dev Team                                  |
 |                                                                       |
 | Licensed under the GNU General Public License version 3 or            |
 | any later version with exceptions for skins & plugins.                |
 | See the README file for a full license statement.                     |
 |                                                                       |
 | PURPOSE:                                                              |
 |   Show edit form for a canned response record                         |
 +-----------------------------------------------------------------------+
 | Author: Thomas Bruederli <roundcube@gmail.com>                        |
 +-----------------------------------------------------------------------+
*/

class rcmail_action_settings_response_edit extends rcmail_action_settings_responses
{
    protected static $mode = self::MODE_HTTP;
    protected static $response;

    /**
     * Request handler.
     *
     * @param array $args Arguments from the previous step(s)
     */
    public function run($args = [])
    {
        $rcmail = rcmail::get_instance();
        $title  = $rcmail->gettext($rcmail->action == 'add-response' ? 'addresponse' : 'editresponse');

        if (!empty($args['post'])) {
            self::$response = $args['post'];
        }
        else if ($id = rcube_utils::get_input_string('_id', rcube_utils::INPUT_GP)) {
            self::$response = $rcmail->get_compose_response($id);

            if (!is_array(self::$response)) {
                $rcmail->output->show_message('dberror', 'error');
                $rcmail->output->send('iframe');
            }
        }

        $rcmail->output->set_pagetitle($title);
        $rcmail->output->set_env('readonly', !empty(self::$response['static']));
        $rcmail->output->add_handler('responseform', [$this, 'response_form']);
        $rcmail->output->send('responseedit');
    }

    /**
     * Get content of a response editing/adding form
     *
     * @param array $attrib Template object attributes
     *
     * @return string HTML content
     */
    public static function response_form($attrib)
    {
        $rcmail = rcmail::get_instance();

        // add some labels to client
        $rcmail->output->add_label('converting', 'editorwarning');

        // Set form tags and hidden fields
        $readonly = !empty(self::$response['static']);
        $is_html  = self::$response['is_html'] ?? false;
        $id       = self::$response['id'] ?? '';
        $hidden   = ['name' => '_id', 'value' => $id];

        list($form_start, $form_end) = self::get_form_tags($attrib, 'save-response', $id, $hidden);
        unset($attrib['form'], $attrib['id']);

        $name_attr = [
            'id'       => 'ffname',
            'size'     => $attrib['size'] ?? null,
            'readonly' => $readonly,
            'required' => true,
        ];

        $text_attr = [
            'id'       => 'fftext',
            'size'     => $attrib['textareacols'] ?? null,
            'rows'     => $attrib['textarearows'] ?? null,
            'readonly' => $readonly,
            'spellcheck'       => true,
            'data-html-editor' => true
        ];

        $chk_attr = [
            'id'       => 'ffis_html',
            'disabled' => $readonly,
            'onclick'  => "return rcmail.command('toggle-editor', {id: 'fftext', html: this.checked}, '', event)"
        ];

        // Add HTML editor script(s)
        self::html_editor('response', 'fftext');

        // Enable TinyMCE editor
        if ($is_html) {
            $text_attr['class']      = 'mce_editor';
            $text_attr['is_escaped'] = true;

            // Correctly handle HTML entities in HTML editor (#1488483)
            self::$response['data'] = htmlspecialchars(self::$response['data'], ENT_NOQUOTES, RCUBE_CHARSET);
        }

        $table = new html_table(['cols' => 2]);

        $table->add('title', html::label('ffname', rcube::Q($rcmail->gettext('responsename'))));
        $table->add(null, rcube_output::get_edit_field('name', self::$response['name'] ?? '', $name_attr, 'text'));

        $table->add('title', html::label('fftext', rcube::Q($rcmail->gettext('responsetext'))));
        $table->add(null, rcube_output::get_edit_field('text', self::$response['data'] ?? '', $text_attr, 'textarea'));

        $table->add('title', html::label('ffis_html', rcube::Q($rcmail->gettext('htmltoggle'))));
        $table->add(null, rcube_output::get_edit_field('is_html', $is_html, $chk_attr, 'checkbox'));

        // return the complete edit form as table
        return "$form_start\n" . $table->show($attrib) . $form_end;
    }
}