From e0540ceb7cec1c63baa408c21ba114fef268c586 Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Sun, 20 Feb 2022 16:53:47 +0100 Subject: [PATCH] more work on formfields and display Signed-off-by: Michael Kaufmann --- customer_email.php | 50 ++++++------ .../domains/formfield.domains_add.php | 2 +- .../customer/email/formfield.emails_add.php | 2 +- .../email/formfield.emails_addaccount.php | 21 ++--- .../email/formfield.emails_addforwarder.php | 4 +- .../customer/email/formfield.emails_edit.php | 15 ++-- templates/Froxlor/form/formfields.html.twig | 81 ++++++++++++------- 7 files changed, 99 insertions(+), 76 deletions(-) diff --git a/customer_email.php b/customer_email.php index 20c7727f..4555ed5a 100644 --- a/customer_email.php +++ b/customer_email.php @@ -200,26 +200,23 @@ if ($page == 'overview') { Database::pexecute($result_stmt, array( "cid" => $userinfo['customerid'] )); - $domains = ''; - + $domains = []; while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { - $domains .= \Froxlor\UI\HTML::makeoption($idna_convert->decode($row['domain']), $row['domain']); + $domains[] = [ + 'label' => $idna_convert->decode($row['domain']), + 'value' => $row['domain'] + ]; } - // $iscatchall = \Froxlor\UI\HTML::makeyesno('iscatchall', '1', '0', '0'); - $email_add_data = include_once dirname(__FILE__) . '/lib/formfields/customer/email/formfield.emails_add.php'; if (Settings::Get('catchall.catchall_enabled') != '1') { unset($email_add_data['emails_add']['sections']['section_a']['fields']['iscatchall']); } - - $email_add_form = \Froxlor\UI\HtmlForm::genHTMLForm($email_add_data); - - $title = $email_add_data['emails_add']['title']; - $image = $email_add_data['emails_add']['image']; - - eval("echo \"" . \Froxlor\UI\Template::getTemplate("email/emails_add") . "\";"); + UI::TwigBuffer('user/form.html.twig', [ + 'formdata' => $email_add_data['emails_add'] + ]); + UI::TwigOutputBuffer(); } } else { \Froxlor\UI\Response::standard_error('allresourcesused'); @@ -239,17 +236,20 @@ if ($page == 'overview') { $result['email_full'] = $idna_convert->decode($result['email_full']); $result['destination'] = explode(' ', $result['destination']); uasort($result['destination'], 'strcasecmp'); - $forwarders = ''; + $forwarders = []; $forwarders_count = 0; foreach ($result['destination'] as $dest_id => $destination) { $destination = $idna_convert->decode($destination); - if ($destination != $result['email_full'] && $destination != '') { - eval("\$forwarders.=\"" . \Froxlor\UI\Template::getTemplate("email/emails_edit_forwarder") . "\";"); + $forwarders[] = [ + 'item' => $destination, + 'href' => $linker->getLink(array('section' => 'email', 'page' => 'forwarders', 'action' => 'delete', 'id' => $id, 'forwarderid' => $dest_id)), + 'label' => $lng['panel']['delete'], + 'classes' => 'btn btn-sm btn-danger' + ]; $forwarders_count ++; } - $result['destination'][$dest_id] = $destination; } @@ -329,12 +329,11 @@ if ($page == 'overview') { $quota = Settings::Get('system.mail_quota'); $account_add_data = include_once dirname(__FILE__) . '/lib/formfields/customer/email/formfield.emails_addaccount.php'; - $account_add_form = \Froxlor\UI\HtmlForm::genHTMLForm($account_add_data); - $title = $account_add_data['emails_addaccount']['title']; - $image = $account_add_data['emails_addaccount']['image']; - - eval("echo \"" . \Froxlor\UI\Template::getTemplate("email/account_add") . "\";"); + UI::TwigBuffer('user/form.html.twig', [ + 'formdata' => $account_add_data['emails_addaccount'] + ]); + UI::TwigOutputBuffer(); } } else { \Froxlor\UI\Response::standard_error(array( @@ -476,12 +475,11 @@ if ($page == 'overview') { $result = \Froxlor\PhpHelper::htmlentitiesArray($result); $forwarder_add_data = include_once dirname(__FILE__) . '/lib/formfields/customer/email/formfield.emails_addforwarder.php'; - $forwarder_add_form = \Froxlor\UI\HtmlForm::genHTMLForm($forwarder_add_data); - $title = $forwarder_add_data['emails_addforwarder']['title']; - $image = $forwarder_add_data['emails_addforwarder']['image']; - - eval("echo \"" . \Froxlor\UI\Template::getTemplate("email/forwarder_add") . "\";"); + UI::TwigBuffer('user/form.html.twig', [ + 'formdata' => $forwarder_add_data['emails_addforwarder'] + ]); + UI::TwigOutputBuffer(); } } } else { diff --git a/lib/formfields/customer/domains/formfield.domains_add.php b/lib/formfields/customer/domains/formfield.domains_add.php index ed283c13..93dd85c3 100644 --- a/lib/formfields/customer/domains/formfield.domains_add.php +++ b/lib/formfields/customer/domains/formfield.domains_add.php @@ -28,7 +28,7 @@ return array( 'type' => 'text', 'next_to' => [ 'domain' => [ - 'next_to_prefix' => ' . ', + 'next_to_prefix' => '.', 'type' => 'select', 'select_var' => $domains ] diff --git a/lib/formfields/customer/email/formfield.emails_add.php b/lib/formfields/customer/email/formfield.emails_add.php index de97ec66..0e37a44e 100644 --- a/lib/formfields/customer/email/formfield.emails_add.php +++ b/lib/formfields/customer/email/formfield.emails_add.php @@ -28,7 +28,7 @@ return array( 'type' => 'text', 'next_to' => [ 'domain' => [ - 'next_to_prefix' => ' @ ', + 'next_to_prefix' => '@', 'type' => 'select', 'select_var' => $domains ] diff --git a/lib/formfields/customer/email/formfield.emails_addaccount.php b/lib/formfields/customer/email/formfield.emails_addaccount.php index 111d0dd5..e57db43d 100644 --- a/lib/formfields/customer/email/formfield.emails_addaccount.php +++ b/lib/formfields/customer/email/formfield.emails_addaccount.php @@ -17,7 +17,7 @@ return array( 'emails_addaccount' => array( 'title' => $lng['emails']['account_add'], - 'image' => 'icons/email_add.png', + 'image' => 'fa-solid fa-plus', 'sections' => array( 'section_a' => array( 'title' => $lng['emails']['account_add'], @@ -31,19 +31,22 @@ return array( 'email_password' => array( 'label' => $lng['login']['password'], 'type' => 'password', - 'autocomplete' => 'off' - ), - 'email_password_suggestion' => array( - 'label' => $lng['customer']['generated_pwd'], - 'type' => 'text', - 'visible' => (\Froxlor\Settings::Get('panel.password_regex') == ''), - 'value' => \Froxlor\System\Crypt::generatePassword() + 'autocomplete' => 'off', + 'next_to' => [ + 'admin_password_suggestion' => array( + 'next_to_prefix' => $lng['customer']['generated_pwd'].':', + 'type' => 'text', + 'visible' => (\Froxlor\Settings::Get('panel.password_regex') == ''), + 'value' => \Froxlor\System\Crypt::generatePassword(), + 'readonly' => true + ) + ] ), 'email_quota' => array( 'visible' => (\Froxlor\Settings::Get('system.mail_quota_enabled') == '1' ? true : false), 'label' => $lng['emails']['quota'], 'desc' => "MiB", - 'type' => 'text', + 'type' => 'number', 'value' => $quota ), 'alternative_email' => array( diff --git a/lib/formfields/customer/email/formfield.emails_addforwarder.php b/lib/formfields/customer/email/formfield.emails_addforwarder.php index 79cd4f4d..2b3fee44 100644 --- a/lib/formfields/customer/email/formfield.emails_addforwarder.php +++ b/lib/formfields/customer/email/formfield.emails_addforwarder.php @@ -17,7 +17,7 @@ return array( 'emails_addforwarder' => array( 'title' => $lng['emails']['forwarder_add'], - 'image' => 'icons/autoresponder_add.png', + 'image' => 'fa-solid fa-plus', 'sections' => array( 'section_a' => array( 'title' => $lng['emails']['forwarder_add'], @@ -30,7 +30,7 @@ return array( ), 'destination' => array( 'label' => $lng['emails']['to'], - 'type' => 'text' + 'type' => 'email' ) ) ) diff --git a/lib/formfields/customer/email/formfield.emails_edit.php b/lib/formfields/customer/email/formfield.emails_edit.php index f70dbc44..592bf5b5 100644 --- a/lib/formfields/customer/email/formfield.emails_edit.php +++ b/lib/formfields/customer/email/formfield.emails_edit.php @@ -30,7 +30,7 @@ return array( 'value' => $result['email_full'] ), 'account_yes' => array( - 'visible' => ($result['popaccountid'] != 0 ? true : false), + 'visible' => ((int) $result['popaccountid'] != 0 ? true : false), 'label' => $lng['emails']['account'], 'type' => 'label', 'value' => $lng['panel']['yes'], @@ -44,7 +44,7 @@ return array( ] ), 'account_no' => array( - 'visible' => ($result['popaccountid'] == 0 ? true : false), + 'visible' => ((int) $result['popaccountid'] == 0 ? true : false), 'label' => $lng['emails']['account'], 'type' => 'label', 'value' => $lng['panel']['no'], @@ -58,12 +58,13 @@ return array( ] ), 'mail_quota' => array( - 'visible' => ($result['popaccountid'] != 0 && \Froxlor\Settings::Get('system.mail_quota_enabled')), + 'visible' => ((int) $result['popaccountid'] != 0 && \Froxlor\Settings::Get('system.mail_quota_enabled')), 'label' => $lng['customer']['email_quota'], 'type' => 'label', 'value' => $result['quota'] . ' MiB', 'next_to' => [ 'add_link' => [ + 'visible' => ((int)$result['popaccountid'] != 0 && \Froxlor\Settings::Get('system.mail_quota_enabled')), 'type' => 'link', 'href' => $filename . '?page=accounts&action=changequota&id=' . $result['id'] . '&s=' . $s, 'label' => $lng['emails']['quota_edit'], @@ -74,20 +75,20 @@ return array( 'mail_catchall' => array( 'label' => $lng['emails']['catchall'], 'type' => 'label', - 'value' => ($result['iscatchall'] == 0 ? $lng['panel']['no'] : $lng['panel']['yes']), + 'value' => ((int)$result['iscatchall'] == 0 ? $lng['panel']['no'] : $lng['panel']['yes']), 'next_to' => [ 'add_link' => [ 'type' => 'link', 'href' => $filename . '?page=' . $page . '&action=togglecatchall&id=' . $result['id'] . '&s=' . $s, - 'label' => $lng['panel']['toggle'], + 'label' => ' ' . $lng['panel']['toggle'], 'classes' => 'btn btn-sm btn-secondary' ] ] ), 'mail_fwds' => array( 'label' => $lng['emails']['forwarders'] . ' (' . $forwarders_count . ')', - 'type' => 'label', - 'value' => $forwarders, + 'type' => 'itemlist', + 'values' => $forwarders, 'next_to' => [ 'add_link' => [ 'type' => 'link', diff --git a/templates/Froxlor/form/formfields.html.twig b/templates/Froxlor/form/formfields.html.twig index f7076a2a..4f71c5c1 100644 --- a/templates/Froxlor/form/formfields.html.twig +++ b/templates/Froxlor/form/formfields.html.twig @@ -1,30 +1,34 @@ {% macro fieldrow(id, field, norow = false) %} - {% if norow == false %} -
-