From 56519b407244ab927f82b933dd7d2c784818cb97 Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Tue, 22 Feb 2022 19:31:28 +0100 Subject: [PATCH] more work on add/edit forms Signed-off-by: Michael Kaufmann --- admin_ipsandports.php | 2 + admin_plans.php | 90 ++++--------------- admin_templates.php | 52 ++++++++--- .../ipsandports/formfield.ipsandports_add.php | 7 +- .../formfield.ipsandports_edit.php | 6 +- .../admin/plans/formfield.plans_add.php | 3 +- .../admin/plans/formfield.plans_edit.php | 3 +- templates/Froxlor/form/formfields.html.twig | 6 +- 8 files changed, 77 insertions(+), 92 deletions(-) diff --git a/admin_ipsandports.php b/admin_ipsandports.php index 0a127b13..0eb6ac90 100644 --- a/admin_ipsandports.php +++ b/admin_ipsandports.php @@ -119,6 +119,7 @@ if ($page == 'ipsandports' || $page == 'overview') { $ipsandports_add_data = include_once dirname(__FILE__) . '/lib/formfields/admin/ipsandports/formfield.ipsandports_add.php'; UI::twigBuffer('user/form.html.twig', [ + 'formaction' => $linker->getLink(array('section' => 'ipsandports')), 'formdata' => $ipsandports_add_data['ipsandports_add'] ]); UI::twigOutputBuffer(); @@ -152,6 +153,7 @@ if ($page == 'ipsandports' || $page == 'overview') { $ipsandports_edit_data = include_once dirname(__FILE__) . '/lib/formfields/admin/ipsandports/formfield.ipsandports_edit.php'; UI::twigBuffer('user/form.html.twig', [ + 'formaction' => $linker->getLink(array('section' => 'ipsandports', 'id' => $id)), 'formdata' => $ipsandports_edit_data['ipsandports_edit'] ]); UI::twigOutputBuffer(); diff --git a/admin_plans.php b/admin_plans.php index 5bc71835..adbb822f 100644 --- a/admin_plans.php +++ b/admin_plans.php @@ -21,6 +21,7 @@ require __DIR__ . '/lib/init.php'; use Froxlor\Api\Commands\HostingPlans; use Froxlor\Database\Database; use Froxlor\Settings; +use Froxlor\UI\Panel\UI; use Froxlor\UI\Request; $id = (int) Request::get('id'); @@ -60,7 +61,7 @@ if ($page == '' || $page == 'overview') { $row = \Froxlor\PhpHelper::htmlentitiesArray($row); $row['ts_format'] = date("d.m.Y H:i", $row['ts']); eval("\$plans.=\"" . \Froxlor\UI\Template::getTemplate("plans/plans_plan") . "\";"); - $count ++; + $count++; } eval("echo \"" . \Froxlor\UI\Template::getTemplate("plans/plans") . "\";"); @@ -114,17 +115,7 @@ if ($page == '' || $page == 'overview') { )); } else { - $diskspace_ul = \Froxlor\UI\HTML::makecheckbox('diskspace_ul', $lng['customer']['unlimited'], '-1', false, '0', true, true); - $traffic_ul = \Froxlor\UI\HTML::makecheckbox('traffic_ul', $lng['customer']['unlimited'], '-1', false, '0', true, true); - $subdomains_ul = \Froxlor\UI\HTML::makecheckbox('subdomains_ul', $lng['customer']['unlimited'], '-1', false, '0', true, true); - $emails_ul = \Froxlor\UI\HTML::makecheckbox('emails_ul', $lng['customer']['unlimited'], '-1', false, '0', true, true); - $email_accounts_ul = \Froxlor\UI\HTML::makecheckbox('email_accounts_ul', $lng['customer']['unlimited'], '-1', false, '0', true, true); - $email_forwarders_ul = \Froxlor\UI\HTML::makecheckbox('email_forwarders_ul', $lng['customer']['unlimited'], '-1', false, '0', true, true); - $email_quota_ul = \Froxlor\UI\HTML::makecheckbox('email_quota_ul', $lng['customer']['unlimited'], '-1', false, '0', true, true); - $ftps_ul = \Froxlor\UI\HTML::makecheckbox('ftps_ul', $lng['customer']['unlimited'], '-1', false, '0', true, true); - $mysqls_ul = \Froxlor\UI\HTML::makecheckbox('mysqls_ul', $lng['customer']['unlimited'], '-1', false, '0', true, true); - - $phpconfigs = array(); + $phpconfigs = []; $configs = Database::query(" SELECT c.*, fc.description as interpreter FROM `" . TABLE_PANEL_PHPCONFIGS . "` c @@ -133,12 +124,12 @@ if ($page == '' || $page == 'overview') { while ($row = $configs->fetch(PDO::FETCH_ASSOC)) { if ((int) Settings::Get('phpfpm.enabled') == 1) { $phpconfigs[] = array( - 'label' => $row['description'] . " [" . $row['interpreter'] . "]
", + 'label' => $row['description'] . " [" . $row['interpreter'] . "]", 'value' => $row['id'] ); } else { $phpconfigs[] = array( - 'label' => $row['description'] . "
", + 'label' => $row['description'], 'value' => $row['id'] ); } @@ -157,12 +148,12 @@ if ($page == '' || $page == 'overview') { unset($cust_add_data['customer_add']['sections']['section_cpre']); // merge $plans_add_data['plans_add']['sections'] = array_merge($plans_add_data['plans_add']['sections'], $cust_add_data['customer_add']['sections']); - $plans_add_form = \Froxlor\UI\HtmlForm::genHTMLForm($plans_add_data); - $title = $plans_add_data['plans_add']['title']; - $image = $plans_add_data['plans_add']['image']; - - eval("echo \"" . \Froxlor\UI\Template::getTemplate("plans/plans_add") . "\";"); + UI::twigBuffer('user/form.html.twig', [ + 'formaction' => $linker->getLink(array('section' => 'plans')), + 'formdata' => $plans_add_data['plans_add'] + ]); + UI::twigOutputBuffer(); } } elseif ($action == 'edit' && $id != 0) { try { @@ -197,52 +188,7 @@ if ($page == '' || $page == 'overview') { )); } else { - $diskspace_ul = \Froxlor\UI\HTML::makecheckbox('diskspace_ul', $lng['customer']['unlimited'], '-1', false, $result['diskspace'], true, true); - if ($result['diskspace'] == '-1') { - $result['diskspace'] = ''; - } - - $traffic_ul = \Froxlor\UI\HTML::makecheckbox('traffic_ul', $lng['customer']['unlimited'], '-1', false, $result['traffic'], true, true); - if ($result['traffic'] == '-1') { - $result['traffic'] = ''; - } - - $subdomains_ul = \Froxlor\UI\HTML::makecheckbox('subdomains_ul', $lng['customer']['unlimited'], '-1', false, $result['subdomains'], true, true); - if ($result['subdomains'] == '-1') { - $result['subdomains'] = ''; - } - - $emails_ul = \Froxlor\UI\HTML::makecheckbox('emails_ul', $lng['customer']['unlimited'], '-1', false, $result['emails'], true, true); - if ($result['emails'] == '-1') { - $result['emails'] = ''; - } - - $email_accounts_ul = \Froxlor\UI\HTML::makecheckbox('email_accounts_ul', $lng['customer']['unlimited'], '-1', false, $result['email_accounts'], true, true); - if ($result['email_accounts'] == '-1') { - $result['email_accounts'] = ''; - } - - $email_forwarders_ul = \Froxlor\UI\HTML::makecheckbox('email_forwarders_ul', $lng['customer']['unlimited'], '-1', false, $result['email_forwarders'], true, true); - if ($result['email_forwarders'] == '-1') { - $result['email_forwarders'] = ''; - } - - $email_quota_ul = \Froxlor\UI\HTML::makecheckbox('email_quota_ul', $lng['customer']['unlimited'], '-1', false, $result['email_quota'], true, true); - if ($result['email_quota'] == '-1') { - $result['email_quota'] = ''; - } - - $ftps_ul = \Froxlor\UI\HTML::makecheckbox('ftps_ul', $lng['customer']['unlimited'], '-1', false, $result['ftps'], true, true); - if ($result['ftps'] == '-1') { - $result['ftps'] = ''; - } - - $mysqls_ul = \Froxlor\UI\HTML::makecheckbox('mysqls_ul', $lng['customer']['unlimited'], '-1', false, $result['mysqls'], true, true); - if ($result['mysqls'] == '-1') { - $result['mysqls'] = ''; - } - - $phpconfigs = array(); + $phpconfigs = []; $configs = Database::query(" SELECT c.*, fc.description as interpreter FROM `" . TABLE_PANEL_PHPCONFIGS . "` c @@ -251,12 +197,12 @@ if ($page == '' || $page == 'overview') { while ($row = $configs->fetch(PDO::FETCH_ASSOC)) { if ((int) Settings::Get('phpfpm.enabled') == 1) { $phpconfigs[] = array( - 'label' => $row['description'] . " [" . $row['interpreter'] . "]
", + 'label' => $row['description'] . " [" . $row['interpreter'] . "]", 'value' => $row['id'] ); } else { $phpconfigs[] = array( - 'label' => $row['description'] . "
", + 'label' => $row['description'], 'value' => $row['id'] ); } @@ -296,12 +242,12 @@ if ($page == '' || $page == 'overview') { unset($cust_edit_data['customer_edit']['sections']['section_cpre']); // merge $plans_edit_data['plans_edit']['sections'] = array_merge($plans_edit_data['plans_edit']['sections'], $cust_edit_data['customer_edit']['sections']); - $plans_edit_form = \Froxlor\UI\HtmlForm::genHTMLForm($plans_edit_data); - $title = $plans_edit_data['plans_edit']['title']; - $image = $plans_edit_data['plans_edit']['image']; - - eval("echo \"" . \Froxlor\UI\Template::getTemplate("plans/plans_edit") . "\";"); + UI::twigBuffer('user/form.html.twig', [ + 'formaction' => $linker->getLink(array('section' => 'plans', 'id' => $id)), + 'formdata' => $plans_add_data['plans_add'] + ]); + UI::twigOutputBuffer(); } } } elseif ($action == 'jqGetPlanValues') { diff --git a/admin_templates.php b/admin_templates.php index 38089d37..21088873 100644 --- a/admin_templates.php +++ b/admin_templates.php @@ -22,6 +22,7 @@ require __DIR__ . '/lib/init.php'; use Froxlor\Database\Database; use Froxlor\Settings; +use Froxlor\UI\Panel\UI; use Froxlor\UI\Request; $id = (int) Request::get('id'); @@ -218,12 +219,12 @@ if ($action == '') { $lng = $lng_bak; $template_add_data = include_once dirname(__FILE__) . '/lib/formfields/admin/templates/formfield.template_add.php'; - $template_add_form = \Froxlor\UI\HtmlForm::genHTMLForm($template_add_data); - $title = $template_add_data['template_add']['title']; - $image = $template_add_data['template_add']['image']; - - eval("echo \"" . \Froxlor\UI\Template::getTemplate("templates/templates_add_2") . "\";"); + UI::twigBuffer('user/form.html.twig', [ + 'formaction' => $linker->getLink(array('section' => 'templates')), + 'formdata' => $template_add_data['template_add'] + ]); + UI::twigOutputBuffer(); } elseif (isset($_POST['send']) && $_POST['send'] == 'send') { // email templates $language = htmlentities(\Froxlor\Validate\Validate::validate($_POST['language'], 'language', '/^[^\r\n\0"\']+$/', 'nolanguageselect')); @@ -305,12 +306,12 @@ if ($action == '') { 'page' => $page, 's' => $s )); - } elseif (! isset($_GET['files'])) { + } elseif (!isset($_GET['files'])) { // email templates $add = false; - $language_options = ''; - $template_options = ''; + $language_options = []; + $template_options = []; foreach ($languages as $language_file => $language_name) { $templates = array(); @@ -329,18 +330,47 @@ if ($action == '') { if (count(array_diff($available_templates, $templates)) > 0) { $add = true; - $language_options .= \Froxlor\UI\HTML::makeoption($language_name, $language_file, $userinfo['language'], true, true); + $language_options[$language_file] = $language_name; $templates = array_diff($available_templates, $templates); foreach ($templates as $template) { - $template_options .= \Froxlor\UI\HTML::makeoption($lng['admin']['templates'][$template], $template, NULL, true, true, $language_file) . "\n"; + $template_options[$template] = $lng['admin']['templates'][$template]; } } } if ($add) { - eval("echo \"" . \Froxlor\UI\Template::getTemplate("templates/templates_add_1") . "\";"); + UI::twigBuffer('user/form.html.twig', [ + 'formaction' => $linker->getLink(array('section' => 'templates')), + 'formdata' => [ + 'title' => $lng['admin']['templates']['template_add'], + 'image' => 'fa-solid fa-plus', + 'sections' => [ + 'section_a' => [ + 'title' => $lng['admin']['templates']['template_add'], + 'fields' => [ + 'language' => [ + 'label' => $lng['login']['language'], + 'type' => 'select', + 'select_var' => $language_options, + 'selected' => $userinfo['language'] + ], + 'template' => [ + 'label' => $lng['admin']['templates']['action'], + 'type' => 'select', + 'select_var' => $template_options + ], + 'prepare' => [ + 'type' => 'hidden', + 'value' => 'prepare' + ] + ] + ] + ] + ] + ]); + UI::twigOutputBuffer(); } else { \Froxlor\UI\Response::standard_error('alltemplatesdefined'); } diff --git a/lib/formfields/admin/ipsandports/formfield.ipsandports_add.php b/lib/formfields/admin/ipsandports/formfield.ipsandports_add.php index c9b734e9..85fdc27b 100644 --- a/lib/formfields/admin/ipsandports/formfield.ipsandports_add.php +++ b/lib/formfields/admin/ipsandports/formfield.ipsandports_add.php @@ -25,13 +25,16 @@ return array( 'fields' => array( 'ip' => array( 'label' => $lng['admin']['ipsandports']['ip'], - 'type' => 'text' + 'type' => 'text', + 'mandatory' => true ), 'port' => array( 'label' => $lng['admin']['ipsandports']['port'], 'type' => 'number', 'min' => 1, - 'max' => 65535 + 'max' => 65535, + 'value' => 80, + 'mandatory' => true ) ) ), diff --git a/lib/formfields/admin/ipsandports/formfield.ipsandports_edit.php b/lib/formfields/admin/ipsandports/formfield.ipsandports_edit.php index b156e353..59bff462 100644 --- a/lib/formfields/admin/ipsandports/formfield.ipsandports_edit.php +++ b/lib/formfields/admin/ipsandports/formfield.ipsandports_edit.php @@ -26,14 +26,16 @@ return array( 'ip' => array( 'label' => $lng['admin']['ipsandports']['ip'], 'type' => 'text', - 'value' => $result['ip'] + 'value' => $result['ip'], + 'mandatory' => true ), 'port' => array( 'label' => $lng['admin']['ipsandports']['port'], 'type' => 'number', 'value' => $result['port'], 'min' => 1, - 'max' => 65535 + 'max' => 65535, + 'mandatory' => true ) ) ), diff --git a/lib/formfields/admin/plans/formfield.plans_add.php b/lib/formfields/admin/plans/formfield.plans_add.php index 71a43129..053c5869 100644 --- a/lib/formfields/admin/plans/formfield.plans_add.php +++ b/lib/formfields/admin/plans/formfield.plans_add.php @@ -25,7 +25,8 @@ return array( 'fields' => array( 'name' => array( 'label' => $lng['admin']['plans']['name'], - 'type' => 'text' + 'type' => 'text', + 'mandatory' => true ), 'description' => array( 'label' => $lng['admin']['plans']['description'], diff --git a/lib/formfields/admin/plans/formfield.plans_edit.php b/lib/formfields/admin/plans/formfield.plans_edit.php index 5c84d84e..49f1fdb2 100644 --- a/lib/formfields/admin/plans/formfield.plans_edit.php +++ b/lib/formfields/admin/plans/formfield.plans_edit.php @@ -26,7 +26,8 @@ return array( 'name' => array( 'label' => $lng['admin']['plans']['name'], 'type' => 'text', - 'value' => $result['name'] + 'value' => $result['name'], + 'mandatory' => true ), 'description' => array( 'label' => $lng['admin']['plans']['description'], diff --git a/templates/Froxlor/form/formfields.html.twig b/templates/Froxlor/form/formfields.html.twig index d71b96bc..1304ef99 100644 --- a/templates/Froxlor/form/formfields.html.twig +++ b/templates/Froxlor/form/formfields.html.twig @@ -1,6 +1,6 @@ {% macro fieldrow(id, field, norow = false) %} {% if field.visible is not defined or (field.visible is defined and field.visible) %} - {% if norow == false %} + {% if norow == false and field.type != 'hidden' %}
{% endif %} - {% if field.type == 'text' or field.type == 'password' or field.type == 'number' or field.type == 'file' or field.type == 'email' %} + {% if field.type == 'text' or field.type == 'password' or field.type == 'number' or field.type == 'file' or field.type == 'email' or field.type == 'hidden' %} {{ _self.input(id, field) }} {% elseif field.type == 'textul' %} {{ _self.input_ul(id, field) }} @@ -25,7 +25,7 @@ {% elseif field.type == 'itemlist' %} {{ _self.itemlist(id, field) }} {% endif %} - {% if norow == false %} + {% if norow == false and field.type != 'hidden' %}
{% endif %}