From bf41c84c6a5e03bbd4c85a05a17e6669fe56b0c0 Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Thu, 24 Mar 2022 14:25:29 +0100 Subject: [PATCH] migrate admin_settings::testmail Signed-off-by: Michael Kaufmann --- admin_message.php | 2 +- admin_settings.php | 38 +++++++---- .../settings/formfield.settings_mailtest.php | 64 +++++++++++++++++++ lng/english.lng.php | 3 + lng/german.lng.php | 3 + templates/Froxlor/form/formfields.html.twig | 4 +- 6 files changed, 99 insertions(+), 15 deletions(-) create mode 100644 lib/formfields/admin/settings/formfield.settings_mailtest.php diff --git a/admin_message.php b/admin_message.php index 9ac8b53d..9ecf8703 100644 --- a/admin_message.php +++ b/admin_message.php @@ -126,7 +126,7 @@ if ($page == 'message') { 'actions_links' => [[ 'href' => $linker->getLink(['section' => 'settings', 'page' => 'overview', 'part' => 'system', 'em' => 'system_mail_use_smtp']), 'label' => $lng['admin']['smtpsettings'], - 'icon' => 'fa-solid fa-wrench', + 'icon' => 'fa-solid fa-gears', 'class' => 'btn-outline-secondary' ]], // alert-box diff --git a/admin_settings.php b/admin_settings.php index 184e3a37..055c6251 100644 --- a/admin_settings.php +++ b/admin_settings.php @@ -331,7 +331,7 @@ if ($page == 'overview' && $userinfo['change_serversettings'] == '1') { 'href' => $linker->getLink(['section' => 'settings', 'page' => 'overview']), 'label' => $lng['admin']['configfiles']['overview'], 'icon' => 'fa fa-grip' - ],[ + ], [ 'class' => 'btn-outline-secondary', 'href' => $linker->getLink(['section' => 'settings', 'page' => $page, 'action' => 'export']), 'label' => 'Download/export ' . $lng['admin']['serversettings'], @@ -340,12 +340,14 @@ if ($page == 'overview' && $userinfo['change_serversettings'] == '1') { ]); } } elseif ($page == 'testmail') { + + $note_type = 'info'; + $note_msg = $lng['admin']['smtptestnote']; + if (isset($_POST['send']) && $_POST['send'] == 'send') { $test_addr = isset($_POST['test_addr']) ? $_POST['test_addr'] : null; - /** - * Initialize the mailingsystem - */ + // Initialize the mailingsystem $testmail = new \PHPMailer\PHPMailer\PHPMailer(true); $testmail->CharSet = "UTF-8"; @@ -379,10 +381,12 @@ if ($page == 'overview' && $userinfo['change_serversettings'] == '1') { $testmail->AddAddress($test_addr); $testmail->Send(); } catch (\PHPMailer\PHPMailer\Exception $e) { - $mailerr_msg = $e->errorMessage(); + $note_type = 'danger'; + $note_msg = $e->getMessage(); $_mailerror = true; } catch (Exception $e) { - $mailerr_msg = $e->getMessage(); + $note_type = 'danger'; + $note_msg = $e->getMessage(); $_mailerror = true; } @@ -396,14 +400,24 @@ if ($page == 'overview' && $userinfo['change_serversettings'] == '1') { } } else { // invalid sender e-mail - $mailerr_msg = "Invalid sender e-mail address: " . Settings::Get('panel.adminmail'); - $_mailerror = true; + $note_type = 'warning'; + $note_msg = "Invalid sender e-mail address: " . Settings::Get('panel.adminmail'); } } - $mail_smtp_user = Settings::Get('system.mail_smtp_user'); - $mail_smtp_host = Settings::Get('system.mail_smtp_host'); - $mail_smtp_port = Settings::Get('system.mail_smtp_port'); + $mailtest_add_data = include_once dirname(__FILE__) . '/lib/formfields/admin/settings/formfield.settings_mailtest.php'; - eval("echo \"" . \Froxlor\UI\Template::getTemplate("settings/testmail") . "\";"); + UI::view('user/form-note.html.twig', [ + 'formaction' => $linker->getLink(array('section' => 'settings')), + 'formdata' => $mailtest_add_data['mailtest'], + 'actions_links' => [[ + 'href' => $linker->getLink(['section' => 'settings', 'page' => 'overview', 'part' => 'system', 'em' => 'system_mail_use_smtp']), + 'label' => $lng['admin']['smtpsettings'], + 'icon' => 'fa-solid fa-gears', + 'class' => 'btn-outline-secondary' + ]], + // alert-box + 'type' => $note_type, + 'alert_msg' => $note_msg + ]); } diff --git a/lib/formfields/admin/settings/formfield.settings_mailtest.php b/lib/formfields/admin/settings/formfield.settings_mailtest.php new file mode 100644 index 00000000..2c77cb42 --- /dev/null +++ b/lib/formfields/admin/settings/formfield.settings_mailtest.php @@ -0,0 +1,64 @@ + (2010-) + * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt + * @package Formfields + * + */ +return array( + 'mailtest' => array( + 'title' => $lng['admin']['testmail'], + 'image' => 'fa-solid fa-paper-plane', + 'sections' => array( + 'section_a' => array( + 'fields' => array( + 'smtp_user' => array( + 'label' => $lng['serversettings']['mail_smtp_user'], + 'type' => 'label', + 'value' => (empty(Settings::Get('system.mail_smtp_user')) ? $lng['panel']['unspecified'] : Settings::Get('system.mail_smtp_user')) + ), + 'smtp_host' => array( + 'label' => $lng['serversettings']['mail_smtp_host'], + 'type' => 'label', + 'value' => (empty(Settings::Get('system.mail_smtp_host')) ? $lng['panel']['unspecified'] : Settings::Get('system.mail_smtp_host')) + ), + 'smtp_port' => array( + 'label' => $lng['serversettings']['mail_smtp_port'], + 'type' => 'label', + 'value' => (empty(Settings::Get('system.mail_smtp_port')) ? $lng['panel']['unspecified'] : Settings::Get('system.mail_smtp_port')) + ), + 'smtp_auth' => array( + 'label' => $lng['serversettings']['mail_smtp_auth'], + 'type' => 'checkbox', + 'value' => 1, + 'checked' => (bool) Settings::Get('system.mail_use_smtp'), + 'disabled' => true + ), + 'smtp_tls' => array( + 'label' => $lng['serversettings']['mail_smtp_usetls'], + 'type' => 'checkbox', + 'value' => 1, + 'checked' => (bool) Settings::Get('system.mail_smtp_usetls'), + 'disabled' => true + ), + 'test_addr' => array( + 'label' => $lng['admin']['smtptestaddr'], + 'type' => 'email', + 'mandatory' => true + ) + ) + ) + ) + ) +); diff --git a/lng/english.lng.php b/lng/english.lng.php index 38fb7a4d..37ccabae 100644 --- a/lng/english.lng.php +++ b/lng/english.lng.php @@ -2153,3 +2153,6 @@ $lng['admin']['configfiles']['recommendednote'] = 'Recommended/required services $lng['admin']['configfiles']['selectrecommended'] = 'Select recommended'; $lng['update']['description'] = 'Running database updates for your froxlor installation'; $lng['admin']['smtpsettings'] = 'SMTP settings'; +$lng['panel']['unspecified'] = 'unspecified'; +$lng['admin']['smtptestaddr'] = 'Send test-mail to'; +$lng['admin']['smtptestnote'] = 'Note that the values below reflect your current settings and can only be adjusted there (see link in top right corner)'; diff --git a/lng/german.lng.php b/lng/german.lng.php index 84fdc337..ba5e84ba 100644 --- a/lng/german.lng.php +++ b/lng/german.lng.php @@ -1795,3 +1795,6 @@ $lng['admin']['configfiles']['recommendednote'] = 'Empfohlene/benötigte Dienste $lng['admin']['configfiles']['selectrecommended'] = 'Empfohlene wählen'; $lng['update']['description'] = 'Aktualisierung der froxlor Datenbank'; $lng['admin']['smtpsettings'] = 'SMTP Einstellungen'; +$lng['panel']['unspecified'] = 'keine Angabe'; +$lng['admin']['smtptestaddr'] = 'Test-Email senden an'; +$lng['admin']['smtptestnote'] = 'Bitte beachten: Die untenstehenden Werte reflektieren die aktuellen Einstellungen und können auch nur dort angepasst werden (siehe Link in der oberen rechten Ecke)'; diff --git a/templates/Froxlor/form/formfields.html.twig b/templates/Froxlor/form/formfields.html.twig index f7585acb..02ec6471 100644 --- a/templates/Froxlor/form/formfields.html.twig +++ b/templates/Froxlor/form/formfields.html.twig @@ -65,7 +65,7 @@ {% if field.is_array is defined and field.is_array == 1 and field.values is not empty %} {% for subfield in field.values %}
- + @@ -74,7 +74,7 @@ {% else %}
- +
{% endif %} {% endmacro %}