From a46266049550491849a309357270cf9aa113ee54 Mon Sep 17 00:00:00 2001 From: Carson Fleming Date: Sun, 24 Nov 2024 22:53:32 -0800 Subject: rendering works, updating not implemented --- config.inc.php.dist | 4 +- inbox_settings.php | 123 ++++++++++++++++++++++++---------------------------- 2 files changed, 59 insertions(+), 68 deletions(-) diff --git a/config.inc.php.dist b/config.inc.php.dist index 7e5f055..b65d30d 100644 --- a/config.inc.php.dist +++ b/config.inc.php.dist @@ -35,7 +35,7 @@ $config['inbox_settings_encryption_enabled_query'] = 'SELECT encrypt FROM users // %d - the domain part of the username // (in case the username is an email address) // %e - whether the inbox should be encrypted (boolean) -$config['inbox_settings_encryption_enabled_query'] = 'UPDATE users SET encrypt = ? WHERE username = %u'; +$config['inbox_settings_update_encryption_query'] = 'UPDATE users SET encrypt = ? WHERE username = %u'; // The SQL query used to select a user's forwarding addresses. // Supported replacement variables: @@ -61,5 +61,5 @@ $config['inbox_settings_forwarding_addresses_query'] = 'SELECT addr, fwd_addr, a // %fd - the domain part of the forwarding address // %sf - whether forwarding is set for this address (boolean) // %sa - the new forwarding address (string) -$config['inbox_settings_forwarding_update_query'] = 'UPDATE forwarders SET fwd_addr = %sf, active = %sa WHERE addr = %fa'; +$config['inbox_settings_update_forwarder_query'] = 'UPDATE forwarders SET fwd_addr = %sf, active = %sa WHERE addr = %fa'; ?> diff --git a/inbox_settings.php b/inbox_settings.php index 2da26d8..a9797a1 100644 --- a/inbox_settings.php +++ b/inbox_settings.php @@ -36,61 +36,90 @@ class inbox_settings extends rcube_plugin { function render_settings_ui() { $this->rcmail->output->set_pagetitle($this->gettext('inbox_settings')); $this->register_handler('plugin.body', array($this, 'render_settings_form')); - // notices and messages $this->rcmail->output->send('plugin'); } function render_settings_form() { - $page_title = html::tag('h1', 'voice', $this->gettext('inbox_settings')); + $page_title = html::tag('h1', 'voice', rcube::Q($this->gettext('inbox_settings'))); $encryption_result = $this->run_query('encryption_enabled'); $encrypt_inbox = 0; if (!empty($encryption_result) && !empty($encryption_result[0])) $encrypt_inbox = $encryption_result[0][0] ? 1 : 0; - $encryption_form = new html_table(['cols' => 2]); + $encryption_form = new html_table(['cols' => 2, 'class' => 'propform']); $encryption_form->add_row(['class' => 'form-group row']); - $encryption_form->add('title col-sm-6', html::label([ + $encryption_form->add('title col-sm-8', html::label([ 'class' => 'col-form-label', 'for' => 'rcmfd_encrypt_inbox' - ], $this->gettext('encrypt_inbox'))); - $encryption_form->add(null, - html::div(['class' => 'custom-control custom-switch'], - (new html_checkbox( - ['id' => 'rcmfd_encrypt_inbox', - 'name' => 'encrypt_inbox', - 'class' => 'form-check-input custom-control-input', - 'value' => 1] - ))->show($encrypt_inbox) - . html::label([ - 'class' => 'custom-control-label', - 'for' => 'rcmfd_encrypt_inbox' - ], ''))); - - $forwarding_form = 'forwarding here'; + ], rcube::Q($this->gettext('encrypt_inbox')))); + $encryption_form->add('col-sm-2 offset-1', self::get_checkbox( + 'rcmfd_encrypt_inbox', 'encrypt_inbox', $encrypt_inbox)); + + $forwarders = $this->run_query('forwarding_addresses'); + $forwarding_form = new html_table(['cols' => 3, 'class' => 'propform']); + foreach ($forwarders as $idx => $row) { + $forwarding_form->add_row(['class' => 'form-group row']); + $forwarding_form->add('title col-sm-4', + html::label(['class' => 'col-form-label'], rcube::Q($row[0])) + . self::get_hiddenfield('addr[]', $row[0]) + ); + $forwarding_form->add('col-sm-4', + self::get_textfield( + 'fwd_addr[]', $row[1], ['placeholder' => 'anyone@gmail.com'])); + $forwarding_form->add('col-sm-2 offset-1', + self::get_checkbox( + 'do_forward_' . $idx, + 'do_forward[]', + $row[2], + ['title' => $this->gettext('fwd_addr')])); + } + $form = html::div(['class' => 'formcontent'], + html::tag('fieldset', null, + html::tag('legend', null, rcube::Q($this->gettext('encryption'))) + . $encryption_form->show(null) + ) + . html::tag('fieldset', null, + html::tag('legend', null, rcube::Q($this->gettext('forwarding'))) + . $forwarding_form->show(null))); $save_button = new html_button([ 'class' => 'btn btn-primary submit', 'onclick' => 'return rcmail.command(\'plugin.inbox_settings_save\', \'\', this, event)' ]); $form_buttons = html::div(['class' => 'formbuttons'], $save_button->show($this->rcmail->gettext('save'))); - $form = html::div(null, - html::tag('fieldset', null, - html::tag('legend', null, $this->gettext('encryption')) - . $encryption_form->show(null) - ) - . html::tag('fieldset', null, - html::tag('legend', null, $this->gettext('forwarding')) - . $forwarding_form)); $page_content = html::div(['class' => 'formcontainer'], $page_title . $this->rcmail->output->form_tag([ 'action' => $this->rcmail->url( ['action' => $this->rcmail->action, 'a' => 'save']), 'method' => 'post' - ], html::div(['class' => 'formcontent'], $form) . $form_buttons)); + ], $form . $form_buttons)); return $page_content; } + private static function get_checkbox($id, $name, $checked, $attrs = []) { + return html::div(['class' => 'custom-control custom-switch'], + (new html_checkbox([ + 'id' => $id, + 'name' => $name, + 'class' => 'form-check-input custom-control-input', + 'value' => '1' + ] + $attrs))->show($checked ? '1' : '0') + . html::label(['class' => 'custom-control-label', 'for' => $id] + $attrs, '')); + } + + private static function get_textfield($name, $value, $attrs = []) { + return (new html_inputfield([ + 'type' => 'text', + 'name' => $name, + 'size' => 40, + ] + $attrs))->show($value); + } + + private static function get_hiddenfield($name, $value) { + return (new html_inputfield(['type' => 'hidden', 'name' => $name]))->show($value); + } + private function run_query($qid, $substitutions = []) { if (!($sql = $this->rcmail->config->get('inbox_settings_' . $qid . '_query'))) { return []; @@ -132,44 +161,6 @@ class inbox_settings extends rcube_plugin { return $ndresult; } - private function get_permitted_addresses() { - if (!($sql = $this->rcmail->config->get('identity_addresses_query'))) { - return []; - } - - if ($dsn = $this->rcmail->config->get('identity_addresses_db_dsn')) { - $db = rcube_db::factory(self::parse_dsn($dsn), '', false); - $db->set_debug((bool) $this->rcmail->config->get('sql_debug')); - } else { - $db = $this->rcmail->get_dbh(); - } - - if ($db->is_error()) { - return []; - } - - - $local_part = $this->rcmail->user->get_username('local'); - $domain_part = rcube_utils::idn_to_utf8($this->rcmail->user->get_username('domain')); - $username = rcube_utils::idn_to_utf8($_SESSION['username']); - $host = rcube_utils::idn_to_utf8($_SESSION['imap_host']); - - $sql = str_replace('%l', $db->quote($local_part, 'text'), $sql); - $sql = str_replace('%d', $db->quote($domain_part, 'text'), $sql); - $sql = str_replace('%u', $db->quote($username, 'text'), $sql); - $sql = str_replace('%h', $db->quote($host, 'text'), $sql); - - $result = $db->query($sql); - if ($db->is_error($result)) - return []; - - $permitted_addresses = []; - while ($row = $db->fetch_array($result)) - $permitted_addresses[] = $row[0]; - - return $permitted_addresses; - } - private static function parse_dsn($dsn) { if (strpos($dsn, '%')) { // parse DSN and replace variables in hostname -- cgit v1.2.3