more work on add/edit forms

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2022-02-22 19:31:28 +01:00
parent 4af1dff6fd
commit 56519b4072
8 changed files with 77 additions and 92 deletions

View File

@@ -119,6 +119,7 @@ if ($page == 'ipsandports' || $page == 'overview') {
$ipsandports_add_data = include_once dirname(__FILE__) . '/lib/formfields/admin/ipsandports/formfield.ipsandports_add.php'; $ipsandports_add_data = include_once dirname(__FILE__) . '/lib/formfields/admin/ipsandports/formfield.ipsandports_add.php';
UI::twigBuffer('user/form.html.twig', [ UI::twigBuffer('user/form.html.twig', [
'formaction' => $linker->getLink(array('section' => 'ipsandports')),
'formdata' => $ipsandports_add_data['ipsandports_add'] 'formdata' => $ipsandports_add_data['ipsandports_add']
]); ]);
UI::twigOutputBuffer(); 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'; $ipsandports_edit_data = include_once dirname(__FILE__) . '/lib/formfields/admin/ipsandports/formfield.ipsandports_edit.php';
UI::twigBuffer('user/form.html.twig', [ UI::twigBuffer('user/form.html.twig', [
'formaction' => $linker->getLink(array('section' => 'ipsandports', 'id' => $id)),
'formdata' => $ipsandports_edit_data['ipsandports_edit'] 'formdata' => $ipsandports_edit_data['ipsandports_edit']
]); ]);
UI::twigOutputBuffer(); UI::twigOutputBuffer();

View File

@@ -21,6 +21,7 @@ require __DIR__ . '/lib/init.php';
use Froxlor\Api\Commands\HostingPlans; use Froxlor\Api\Commands\HostingPlans;
use Froxlor\Database\Database; use Froxlor\Database\Database;
use Froxlor\Settings; use Froxlor\Settings;
use Froxlor\UI\Panel\UI;
use Froxlor\UI\Request; use Froxlor\UI\Request;
$id = (int) Request::get('id'); $id = (int) Request::get('id');
@@ -60,7 +61,7 @@ if ($page == '' || $page == 'overview') {
$row = \Froxlor\PhpHelper::htmlentitiesArray($row); $row = \Froxlor\PhpHelper::htmlentitiesArray($row);
$row['ts_format'] = date("d.m.Y H:i", $row['ts']); $row['ts_format'] = date("d.m.Y H:i", $row['ts']);
eval("\$plans.=\"" . \Froxlor\UI\Template::getTemplate("plans/plans_plan") . "\";"); eval("\$plans.=\"" . \Froxlor\UI\Template::getTemplate("plans/plans_plan") . "\";");
$count ++; $count++;
} }
eval("echo \"" . \Froxlor\UI\Template::getTemplate("plans/plans") . "\";"); eval("echo \"" . \Froxlor\UI\Template::getTemplate("plans/plans") . "\";");
@@ -114,17 +115,7 @@ if ($page == '' || $page == 'overview') {
)); ));
} else { } else {
$diskspace_ul = \Froxlor\UI\HTML::makecheckbox('diskspace_ul', $lng['customer']['unlimited'], '-1', false, '0', true, true); $phpconfigs = [];
$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();
$configs = Database::query(" $configs = Database::query("
SELECT c.*, fc.description as interpreter SELECT c.*, fc.description as interpreter
FROM `" . TABLE_PANEL_PHPCONFIGS . "` c FROM `" . TABLE_PANEL_PHPCONFIGS . "` c
@@ -133,12 +124,12 @@ if ($page == '' || $page == 'overview') {
while ($row = $configs->fetch(PDO::FETCH_ASSOC)) { while ($row = $configs->fetch(PDO::FETCH_ASSOC)) {
if ((int) Settings::Get('phpfpm.enabled') == 1) { if ((int) Settings::Get('phpfpm.enabled') == 1) {
$phpconfigs[] = array( $phpconfigs[] = array(
'label' => $row['description'] . " [" . $row['interpreter'] . "]<br />", 'label' => $row['description'] . " [" . $row['interpreter'] . "]",
'value' => $row['id'] 'value' => $row['id']
); );
} else { } else {
$phpconfigs[] = array( $phpconfigs[] = array(
'label' => $row['description'] . "<br />", 'label' => $row['description'],
'value' => $row['id'] 'value' => $row['id']
); );
} }
@@ -157,12 +148,12 @@ if ($page == '' || $page == 'overview') {
unset($cust_add_data['customer_add']['sections']['section_cpre']); unset($cust_add_data['customer_add']['sections']['section_cpre']);
// merge // merge
$plans_add_data['plans_add']['sections'] = array_merge($plans_add_data['plans_add']['sections'], $cust_add_data['customer_add']['sections']); $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']; UI::twigBuffer('user/form.html.twig', [
$image = $plans_add_data['plans_add']['image']; 'formaction' => $linker->getLink(array('section' => 'plans')),
'formdata' => $plans_add_data['plans_add']
eval("echo \"" . \Froxlor\UI\Template::getTemplate("plans/plans_add") . "\";"); ]);
UI::twigOutputBuffer();
} }
} elseif ($action == 'edit' && $id != 0) { } elseif ($action == 'edit' && $id != 0) {
try { try {
@@ -197,52 +188,7 @@ if ($page == '' || $page == 'overview') {
)); ));
} else { } else {
$diskspace_ul = \Froxlor\UI\HTML::makecheckbox('diskspace_ul', $lng['customer']['unlimited'], '-1', false, $result['diskspace'], true, true); $phpconfigs = [];
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();
$configs = Database::query(" $configs = Database::query("
SELECT c.*, fc.description as interpreter SELECT c.*, fc.description as interpreter
FROM `" . TABLE_PANEL_PHPCONFIGS . "` c FROM `" . TABLE_PANEL_PHPCONFIGS . "` c
@@ -251,12 +197,12 @@ if ($page == '' || $page == 'overview') {
while ($row = $configs->fetch(PDO::FETCH_ASSOC)) { while ($row = $configs->fetch(PDO::FETCH_ASSOC)) {
if ((int) Settings::Get('phpfpm.enabled') == 1) { if ((int) Settings::Get('phpfpm.enabled') == 1) {
$phpconfigs[] = array( $phpconfigs[] = array(
'label' => $row['description'] . " [" . $row['interpreter'] . "]<br />", 'label' => $row['description'] . " [" . $row['interpreter'] . "]",
'value' => $row['id'] 'value' => $row['id']
); );
} else { } else {
$phpconfigs[] = array( $phpconfigs[] = array(
'label' => $row['description'] . "<br />", 'label' => $row['description'],
'value' => $row['id'] 'value' => $row['id']
); );
} }
@@ -296,12 +242,12 @@ if ($page == '' || $page == 'overview') {
unset($cust_edit_data['customer_edit']['sections']['section_cpre']); unset($cust_edit_data['customer_edit']['sections']['section_cpre']);
// merge // merge
$plans_edit_data['plans_edit']['sections'] = array_merge($plans_edit_data['plans_edit']['sections'], $cust_edit_data['customer_edit']['sections']); $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']; UI::twigBuffer('user/form.html.twig', [
$image = $plans_edit_data['plans_edit']['image']; 'formaction' => $linker->getLink(array('section' => 'plans', 'id' => $id)),
'formdata' => $plans_add_data['plans_add']
eval("echo \"" . \Froxlor\UI\Template::getTemplate("plans/plans_edit") . "\";"); ]);
UI::twigOutputBuffer();
} }
} }
} elseif ($action == 'jqGetPlanValues') { } elseif ($action == 'jqGetPlanValues') {

View File

@@ -22,6 +22,7 @@ require __DIR__ . '/lib/init.php';
use Froxlor\Database\Database; use Froxlor\Database\Database;
use Froxlor\Settings; use Froxlor\Settings;
use Froxlor\UI\Panel\UI;
use Froxlor\UI\Request; use Froxlor\UI\Request;
$id = (int) Request::get('id'); $id = (int) Request::get('id');
@@ -218,12 +219,12 @@ if ($action == '') {
$lng = $lng_bak; $lng = $lng_bak;
$template_add_data = include_once dirname(__FILE__) . '/lib/formfields/admin/templates/formfield.template_add.php'; $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']; UI::twigBuffer('user/form.html.twig', [
$image = $template_add_data['template_add']['image']; 'formaction' => $linker->getLink(array('section' => 'templates')),
'formdata' => $template_add_data['template_add']
eval("echo \"" . \Froxlor\UI\Template::getTemplate("templates/templates_add_2") . "\";"); ]);
UI::twigOutputBuffer();
} elseif (isset($_POST['send']) && $_POST['send'] == 'send') { } elseif (isset($_POST['send']) && $_POST['send'] == 'send') {
// email templates // email templates
$language = htmlentities(\Froxlor\Validate\Validate::validate($_POST['language'], 'language', '/^[^\r\n\0"\']+$/', 'nolanguageselect')); $language = htmlentities(\Froxlor\Validate\Validate::validate($_POST['language'], 'language', '/^[^\r\n\0"\']+$/', 'nolanguageselect'));
@@ -305,12 +306,12 @@ if ($action == '') {
'page' => $page, 'page' => $page,
's' => $s 's' => $s
)); ));
} elseif (! isset($_GET['files'])) { } elseif (!isset($_GET['files'])) {
// email templates // email templates
$add = false; $add = false;
$language_options = ''; $language_options = [];
$template_options = ''; $template_options = [];
foreach ($languages as $language_file => $language_name) { foreach ($languages as $language_file => $language_name) {
$templates = array(); $templates = array();
@@ -329,18 +330,47 @@ if ($action == '') {
if (count(array_diff($available_templates, $templates)) > 0) { if (count(array_diff($available_templates, $templates)) > 0) {
$add = true; $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); $templates = array_diff($available_templates, $templates);
foreach ($templates as $template) { 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) { 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 { } else {
\Froxlor\UI\Response::standard_error('alltemplatesdefined'); \Froxlor\UI\Response::standard_error('alltemplatesdefined');
} }

View File

@@ -25,13 +25,16 @@ return array(
'fields' => array( 'fields' => array(
'ip' => array( 'ip' => array(
'label' => $lng['admin']['ipsandports']['ip'], 'label' => $lng['admin']['ipsandports']['ip'],
'type' => 'text' 'type' => 'text',
'mandatory' => true
), ),
'port' => array( 'port' => array(
'label' => $lng['admin']['ipsandports']['port'], 'label' => $lng['admin']['ipsandports']['port'],
'type' => 'number', 'type' => 'number',
'min' => 1, 'min' => 1,
'max' => 65535 'max' => 65535,
'value' => 80,
'mandatory' => true
) )
) )
), ),

View File

@@ -26,14 +26,16 @@ return array(
'ip' => array( 'ip' => array(
'label' => $lng['admin']['ipsandports']['ip'], 'label' => $lng['admin']['ipsandports']['ip'],
'type' => 'text', 'type' => 'text',
'value' => $result['ip'] 'value' => $result['ip'],
'mandatory' => true
), ),
'port' => array( 'port' => array(
'label' => $lng['admin']['ipsandports']['port'], 'label' => $lng['admin']['ipsandports']['port'],
'type' => 'number', 'type' => 'number',
'value' => $result['port'], 'value' => $result['port'],
'min' => 1, 'min' => 1,
'max' => 65535 'max' => 65535,
'mandatory' => true
) )
) )
), ),

View File

@@ -25,7 +25,8 @@ return array(
'fields' => array( 'fields' => array(
'name' => array( 'name' => array(
'label' => $lng['admin']['plans']['name'], 'label' => $lng['admin']['plans']['name'],
'type' => 'text' 'type' => 'text',
'mandatory' => true
), ),
'description' => array( 'description' => array(
'label' => $lng['admin']['plans']['description'], 'label' => $lng['admin']['plans']['description'],

View File

@@ -26,7 +26,8 @@ return array(
'name' => array( 'name' => array(
'label' => $lng['admin']['plans']['name'], 'label' => $lng['admin']['plans']['name'],
'type' => 'text', 'type' => 'text',
'value' => $result['name'] 'value' => $result['name'],
'mandatory' => true
), ),
'description' => array( 'description' => array(
'label' => $lng['admin']['plans']['description'], 'label' => $lng['admin']['plans']['description'],

View File

@@ -1,6 +1,6 @@
{% macro fieldrow(id, field, norow = false) %} {% macro fieldrow(id, field, norow = false) %}
{% if field.visible is not defined or (field.visible is defined and field.visible) %} {% if field.visible is not defined or (field.visible is defined and field.visible) %}
{% if norow == false %} {% if norow == false and field.type != 'hidden' %}
<div class="row mb-3"> <div class="row mb-3">
<label for="{{ id }}" class="col-sm-4 col-form-label">{{ field.label|raw }} <label for="{{ id }}" class="col-sm-4 col-form-label">{{ field.label|raw }}
{% if field.desc is defined and field.desc is not empty %}<br><small>{{ field.desc|raw }}</small> {% if field.desc is defined and field.desc is not empty %}<br><small>{{ field.desc|raw }}</small>
@@ -8,7 +8,7 @@
</label> </label>
<div class="col-sm-8"> <div class="col-sm-8">
{% endif %} {% 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) }} {{ _self.input(id, field) }}
{% elseif field.type == 'textul' %} {% elseif field.type == 'textul' %}
{{ _self.input_ul(id, field) }} {{ _self.input_ul(id, field) }}
@@ -25,7 +25,7 @@
{% elseif field.type == 'itemlist' %} {% elseif field.type == 'itemlist' %}
{{ _self.itemlist(id, field) }} {{ _self.itemlist(id, field) }}
{% endif %} {% endif %}
{% if norow == false %} {% if norow == false and field.type != 'hidden' %}
</div> </div>
</div> </div>
{% endif %} {% endif %}