diff options
author | Thomas Bruederli <thomas@roundcube.net> | 2013-09-19 17:56:14 +0200 |
---|---|---|
committer | Thomas Bruederli <thomas@roundcube.net> | 2013-09-19 17:56:14 +0200 |
commit | 9c41ba3c9ebbb14d01abe961c420f71f9463e61a (patch) | |
tree | 43c2d4c12bbb24a05c7edea7a91f0e01c375c543 /program/steps | |
parent | cc041fe11c1997902f68f4ca8e95577e963a0053 (diff) |
Allow sysadmins to define static responses which are immutable for the user
Diffstat (limited to 'program/steps')
-rw-r--r-- | program/steps/settings/edit_response.inc | 19 | ||||
-rw-r--r-- | program/steps/settings/responses.inc | 8 |
2 files changed, 14 insertions, 13 deletions
diff --git a/program/steps/settings/edit_response.inc b/program/steps/settings/edit_response.inc index 26f7e6e48..49856775a 100644 --- a/program/steps/settings/edit_response.inc +++ b/program/steps/settings/edit_response.inc @@ -24,8 +24,6 @@ $responses = $RCMAIL->get_compose_responses(); // edit-response if (($key = get_input_value('_key', RCUBE_INPUT_GPC))) { foreach ($responses as $i => $response) { - if (empty($response['key'])) - $response['key'] = substr(md5($response['name']), 0, 16); if ($response['key'] == $key) { $RESPONSE_RECORD = $response; $RESPONSE_RECORD['index'] = $i; @@ -35,13 +33,10 @@ if (($key = get_input_value('_key', RCUBE_INPUT_GPC))) { } // save response -if ($RCMAIL->action == 'save-response' && isset($_POST['_name'])) { +if ($RCMAIL->action == 'save-response' && isset($_POST['_name']) && !$RESPONSE_RECORD['static']) { $name = trim(get_input_value('_name', RCUBE_INPUT_POST)); $text = trim(get_input_value('_text', RCUBE_INPUT_POST)); - if (!empty($_REQUEST['_framed'])) - $RCMAIL->output->framed = 1; - if (!empty($name) && !empty($text)) { $dupes = 0; foreach ($responses as $i => $resp) { @@ -62,9 +57,11 @@ if ($RCMAIL->action == 'save-response' && isset($_POST['_name'])) { $responses[] = $response; } - if ($RCMAIL->user->save_prefs(array('compose_responses' => $responses))) { + $responses = array_filter($responses, function($item){ return empty($item['static']); }); + if ($RCMAIL->user->save_prefs(array('compose_responses' => array_values($responses)))) { $RCMAIL->output->show_message('successfullysaved', 'confirmation'); - $RCMAIL->output->command('update_response_row', $response, $key); + $RCMAIL->output->command('parent.update_response_row', $response, $key); + $RCMAIL->overwrite_action('edit-response'); $RESPONSE_RECORD = $response; } } @@ -79,6 +76,7 @@ function rcube_response_form($attrib) global $RCMAIL, $OUTPUT, $RESPONSE_RECORD; // Set form tags and hidden fields + $disabled = !empty($RESPONSE_RECORD['static']); $key = $RESPONSE_RECORD['key']; list($form_start, $form_end) = get_form_tags($attrib, 'save-response', $key, array('name' => '_key', 'value' => $key)); unset($attrib['form'], $attrib['id']); @@ -90,10 +88,10 @@ function rcube_response_form($attrib) $label = rcube_label('responsename'); $table->add('title', html::label('ffname', Q(rcube_label('responsename')))); - $table->add(null, rcube_output::get_edit_field('name', $RESPONSE_RECORD['name'], array('id' => 'ffname', 'size' => $attrib['size']), 'text')); + $table->add(null, rcube_output::get_edit_field('name', $RESPONSE_RECORD['name'], array('id' => 'ffname', 'size' => $attrib['size'], 'disabled' => $disabled), 'text')); $table->add('title', html::label('fftext', Q(rcube_label('responsetext')))); - $table->add(null, rcube_output::get_edit_field('text', $RESPONSE_RECORD['text'], array('id' => 'fftext', 'size' => $attrib['textareacols'], 'rows' => $attrib['textarearows']), 'textarea')); + $table->add(null, rcube_output::get_edit_field('text', $RESPONSE_RECORD['text'], array('id' => 'fftext', 'size' => $attrib['textareacols'], 'rows' => $attrib['textarearows'], 'disabled' => $disabled), 'textarea')); $out .= $table->show($attrib); $out .= $form_end; @@ -101,6 +99,7 @@ function rcube_response_form($attrib) return $out; } +$OUTPUT->set_env('readonly', !empty($RESPONSE_RECORD['static'])); $OUTPUT->add_handler('responseform', 'rcube_response_form'); $OUTPUT->set_pagetitle(rcube_label(($RCMAIL->action=='add-response' ? 'savenewresponse' : 'editresponse'))); diff --git a/program/steps/settings/responses.inc b/program/steps/settings/responses.inc index 330b4fde4..cfc4148c3 100644 --- a/program/steps/settings/responses.inc +++ b/program/steps/settings/responses.inc @@ -26,7 +26,7 @@ if (!empty($_POST['_insert'])) { if (!empty($name) && !empty($text)) { $dupes = 0; - $responses = $RCMAIL->get_compose_responses(); + $responses = $RCMAIL->get_compose_responses(false, true); foreach ($responses as $resp) { if (strcasecmp($name, preg_replace('/\s\(\d+\)$/', '', $resp['name'])) == 0) $dupes++; @@ -54,7 +54,7 @@ if (!empty($_POST['_insert'])) { if ($RCMAIL->action == 'delete-response') { if ($key = get_input_value('_key', RCUBE_INPUT_GPC)) { - $responses = $RCMAIL->get_compose_responses(); + $responses = $RCMAIL->get_compose_responses(false, true); foreach ($responses as $i => $response) { if (empty($response['key'])) $response['key'] = substr(md5($response['name']), 0, 16); @@ -67,7 +67,7 @@ if ($RCMAIL->action == 'delete-response') { } if ($deleted) { - $RCMAIL->output->command('display_message', rcube_label('successfullydeleted'), 'confirmation'); + $RCMAIL->output->command('display_message', rcube_label('deletedsuccessfully'), 'confirmation'); $RCMAIL->output->command('remove_response', $key); } @@ -99,6 +99,8 @@ function rcmail_responses_list($attrib) // set client env $OUTPUT->add_gui_object('responseslist', $attrib['id']); + $OUTPUT->set_env('readonly_responses', array_values(array_map(function($rec){ return $rec['key']; }, + array_filter($plugin['list'], function($item){ return !empty($item['static']); })))); return $out; } |