more work on formfields and display

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2022-02-20 16:53:47 +01:00
parent e6d12be7b3
commit e0540ceb7c
7 changed files with 99 additions and 76 deletions

View File

@@ -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 {

View File

@@ -28,7 +28,7 @@ return array(
'type' => 'text',
'next_to' => [
'domain' => [
'next_to_prefix' => '&nbsp;.&nbsp;',
'next_to_prefix' => '.',
'type' => 'select',
'select_var' => $domains
]

View File

@@ -28,7 +28,7 @@ return array(
'type' => 'text',
'next_to' => [
'domain' => [
'next_to_prefix' => '&nbsp;@&nbsp;',
'next_to_prefix' => '@',
'type' => 'select',
'select_var' => $domains
]

View File

@@ -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(

View File

@@ -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'
)
)
)

View File

@@ -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&amp;action=changequota&amp;id=' . $result['id'] . '&amp;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 . '&amp;action=togglecatchall&amp;id=' . $result['id'] . '&amp;s=' . $s,
'label' => $lng['panel']['toggle'],
'label' => '<i class="fa-solid fa-arrow-right-arrow-left"></i> ' . $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',

View File

@@ -1,30 +1,34 @@
{% macro fieldrow(id, field, norow = false) %}
{% if norow == false %}
<div class="row mb-3">
<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.visible is not defined or (field.visible is defined and field.visible) %}
{% if norow == false %}
<div class="row mb-3">
<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>
{% endif %}
</label>
<div class="col-sm-8">
{% endif %}
</label>
<div class="col-sm-8">
{% endif %}
{% if field.type == 'text' or field.type == 'password' or field.type == 'number' or field.type == 'file' %}
{{ _self.input(id, field) }}
{% elseif field.type == 'textul' %}
{{ _self.input_ul(id, field) }}
{% elseif field.type == 'checkbox' %}
{{ _self.bool(id, field) }}
{% elseif field.type == 'select' %}
{{ _self.select(id, field) }}
{% elseif field.type == 'textarea' %}
{{ _self.textarea(id, field) }}
{% elseif field.type == 'label' %}
{{ _self.plain(id, field) }}
{% elseif field.type == 'link' %}
{{ _self.link(id, field) }}
{% endif %}
{% if norow == false %}
{% if field.type == 'text' or field.type == 'password' or field.type == 'number' or field.type == 'file' or field.type == 'email' %}
{{ _self.input(id, field) }}
{% elseif field.type == 'textul' %}
{{ _self.input_ul(id, field) }}
{% elseif field.type == 'checkbox' %}
{{ _self.bool(id, field) }}
{% elseif field.type == 'select' %}
{{ _self.select(id, field) }}
{% elseif field.type == 'textarea' %}
{{ _self.textarea(id, field) }}
{% elseif field.type == 'label' %}
{{ _self.plain(id, field) }}
{% elseif field.type == 'link' %}
{{ _self.link(id, field) }}
{% elseif field.type == 'itemlist' %}
{{ _self.itemlist(id, field) }}
{% endif %}
{% if norow == false %}
</div>
</div>
</div>
{% endif %}
{% endif %}
{% endmacro %}
@@ -32,7 +36,7 @@
{% if field.is_array is defined and field.is_array == 1 and field.values is not empty %}
{% for subfield in field.values %}
<div class="form-check form-switch">
<input type="checkbox" value="{{ subfield.value }}" name="{{ id }}[]" class="form-check-input" {% if field.value is defined and subfield.value in field.value %} checked="checked" {% endif %} {% if field.visible is defined and field.visible == false %} disabled {% endif %}>
<input type="checkbox" value="{{ subfield.value }}" name="{{ id }}[]" class="form-check-input" {% if field.value is defined and subfield.value in field.value %} checked="checked" {% endif %}>
<label class="form-check-label">
{{ subfield.label|raw }}
</label>
@@ -40,7 +44,7 @@
{% endfor %}
{% else %}
<div class="form-check form-switch">
<input type="checkbox" value="{{ field.value }}" id="{{ id }}" name="{{ id }}" class="form-check-input {% if field.valid is defined and field.valid == false %}is-invalid{% endif %}" {% if field.checked is defined and field.checked == 1 %} checked="checked" {% endif %} {% if field.visible is defined and field.visible == false %} disabled {% endif %}>
<input type="checkbox" value="{{ field.value }}" id="{{ id }}" name="{{ id }}" class="form-check-input {% if field.valid is defined and field.valid == false %}is-invalid{% endif %}" {% if field.checked is defined and field.checked == 1 %} checked="checked" {% endif %}>
</div>
{% endif %}
{% endmacro %}
@@ -65,7 +69,7 @@
{% if field.next_to is defined %}
<div class="input-group">
{% endif %}
<input type="{{ field.type }}" {% if field.type == 'number' and field.min is defined %} min="{{ field.min }}" {% endif %} {% if field.type == 'number' and field.max is defined %} max="{{ field.max }}" {% endif %} {% if field.type != 'number' and field.maxlength is defined %} maxlength="{{ field.maxlength }}" {% endif %} id="{{ id }}" name="{{ id }}" value="{{ field.value }}" class="form-control {% if field.valid is defined and field.valid == false %}is-invalid{% endif %}" {% if field.mandatory is defined and field.mandatory %} required {% endif %} {% if field.visible is defined and field.visible == false %} disabled {% endif %} {% if field.readonly is defined and field.readonly %} readonly {% endif %} {% if field.autocomplete is defined %} autocomplete="{{ field.autocomplete }}" {% endif %} {% if field.placeholder is defined %} placeholder="{{ field.placeholder }}" {% endif %}/>
<input type="{{ field.type }}" {% if field.type == 'number' and field.min is defined %} min="{{ field.min }}" {% endif %} {% if field.type == 'number' and field.max is defined %} max="{{ field.max }}" {% endif %} {% if field.type != 'number' and field.maxlength is defined %} maxlength="{{ field.maxlength }}" {% endif %} id="{{ id }}" name="{{ id }}" value="{{ field.value }}" class="form-control {% if field.valid is defined and field.valid == false %}is-invalid{% endif %}" {% if field.mandatory is defined and field.mandatory %} required {% endif %} {% if field.readonly is defined and field.readonly %} readonly {% endif %} {% if field.autocomplete is defined %} autocomplete="{{ field.autocomplete }}" {% endif %} {% if field.placeholder is defined %} placeholder="{{ field.placeholder }}" {% endif %}/>
{% if field.type == 'hidden' and field.display is defined %}
<input type="text" readonly class="form-control-plaintext" value="{{ field.display }}">
{% endif %}
@@ -88,7 +92,7 @@
{% endfor %}
{% endif %}
<div class="input-group">
<input type="number" min="0" {% if max is not empty %} max="{{ max }}" {% endif %} id="{{ id }}" name="{{ id }}" value="{% if field.value >= 0 %}{{ field.value }}{% endif %}" class="form-control {% if field.valid is defined and field.valid == false %}is-invalid{% endif %}" {% if field.mandatory is defined and field.mandatory %} required {% endif %} {% if field.visible is defined and field.visible == false %} disabled {% endif %} {% if field.readonly is defined and field.readonly %} readonly {% endif %} {% if field.autocomplete is defined %} autocomplete="{{ field.autocomplete }}" {% endif %} {% if field.placeholder is defined %} placeholder="{{ field.placeholder }}" {% endif %}/>
<input type="number" min="0" {% if max is not empty %} max="{{ max }}" {% endif %} id="{{ id }}" name="{{ id }}" value="{% if field.value >= 0 %}{{ field.value }}{% endif %}" class="form-control {% if field.valid is defined and field.valid == false %}is-invalid{% endif %}" {% if field.mandatory is defined and field.mandatory %} required {% endif %} {% if field.readonly is defined and field.readonly %} readonly {% endif %} {% if field.autocomplete is defined %} autocomplete="{{ field.autocomplete }}" {% endif %} {% if field.placeholder is defined %} placeholder="{{ field.placeholder }}" {% endif %}/>
<div class="input-group-text">
<input class="form-check-input mt-0" type="checkbox" name="{{ id }}_ul" value="1" {% if field.value == -1 %} checked="checked" {% endif %}>
</div>
@@ -100,7 +104,7 @@
{% if field.next_to is defined %}
<div class="input-group">
{% endif %}
<select class="form-select {% if field.valid is defined and field.valid == false %}is-invalid{% endif %}" name="{{ id }}" id="{{ id }}" {% if field.mandatory is defined and field.mandatory %} required {% endif %} {% if field.visible is defined and field.visible == false %} disabled {% endif %}>
<select class="form-select {% if field.valid is defined and field.valid == false %}is-invalid{% endif %}" name="{{ id }}" id="{{ id }}" {% if field.mandatory is defined and field.mandatory %} required {% endif %}>
{% for val,txt in field.select_var %}
<option value="{{ val }}" {% if field.selected is defined and field.selected == val %} selected="selected" {% endif %}>{{ txt|raw }}</option>
{% endfor %}
@@ -117,9 +121,26 @@
{% endmacro %}
{% macro textarea(id, field) %}
<textarea {% if field.rows is defined %} rows="{{ field.rows }}" {% endif %} {% if field.cols is defined %} cols="{{ field.cols }}" {% endif %} id="{{ id }}" name="{{ id }}" class="form-control {% if field.valid is defined and field.valid == false %}is-invalid{% endif %}" {% if field.mandatory is defined and field.mandatory %} required {% endif %} {% if field.visible is defined and field.visible == false %} disabled {% endif %} {% if field.readonly is defined and field.readonly %} readonly {% endif %} {% if field.placeholder is defined %} placeholder="{{ field.placeholder }}" {% endif %}>{{ field.value }}</textarea>
<textarea {% if field.rows is defined %} rows="{{ field.rows }}" {% endif %} {% if field.cols is defined %} cols="{{ field.cols }}" {% endif %} id="{{ id }}" name="{{ id }}" class="form-control {% if field.valid is defined and field.valid == false %}is-invalid{% endif %}" {% if field.mandatory is defined and field.mandatory %} required {% endif %} {% if field.readonly is defined and field.readonly %} readonly {% endif %} {% if field.placeholder is defined %} placeholder="{{ field.placeholder }}" {% endif %}>{{ field.value }}</textarea>
{% endmacro %}
{% macro link(id, field) %}
<a href="{{ field.href|raw }}" class="{{ field.classes }}">{{ field.label|raw }}</a>
{% endmacro %}
{% macro itemlist(id, field) %}
{% if field.values is not empty %}
{% for value in field.values %}
<p>{{ value.item|raw }}
{% if value.href is defined and value.href is not empty %}
{{ _self.link(id, value) }}
{% endif %}
</p>
{% endfor %}
{% endif %}
{% if field.next_to is defined %}
{% for nid, nfield in field.next_to %}
{{ _self.fieldrow(nid, nfield, true) }}
{% endfor %}
{% endif %}
{% endmacro %}