mail & filetemplates listing/forms

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2022-03-06 09:43:06 +01:00
parent 54ce296018
commit a3a33c0da4
8 changed files with 241 additions and 33 deletions

View File

@@ -41,6 +41,9 @@ $available_templates = array(
if ((int) Settings::Get('system.report_enable') == 1) {
array_push($available_templates, 'trafficmaxpercent', 'diskmaxpercent');
}
if (Settings::Get('panel.sendalternativemail') == 1) {
array_push($available_templates, 'pop_success_alternative');
}
$file_templates = array(
'index_html'
@@ -50,15 +53,12 @@ if ($action == '') {
// email templates
$log->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_NOTICE, "viewed admin_templates");
if (Settings::Get('panel.sendalternativemail') == 1) {
$available_templates[] = 'pop_success_alternative';
}
$templates_array = array();
$result_stmt = Database::prepare("
SELECT `id`, `language`, `varname` FROM `" . TABLE_PANEL_TEMPLATES . "`
WHERE `adminid` = :adminid AND `templategroup`='mails'
ORDER BY `language`, `varname`");
ORDER BY `language`, `varname`
");
Database::pexecute($result_stmt, array(
'adminid' => $userinfo['adminid']
));
@@ -69,24 +69,27 @@ if ($action == '') {
$templates_array[$row['language']][$parts[1]][$parts[3]] = $row['id'];
}
$templates = '';
$templates = [];
foreach ($templates_array as $language => $template_defs) {
foreach ($template_defs as $action => $email) {
$subjectid = $email['subject'];
$mailbodyid = $email['mailbody'];
$template = $lng['admin']['templates'][$action];
eval("\$templates.=\"" . \Froxlor\UI\Template::getTemplate("templates/templates_template") . "\";");
$templates[] = [
'subjectid' => $email['subject'],
'mailbodyid' => $email['mailbody'],
'template' => $lng['admin']['templates'][$action],
'language' => $language
];
}
}
$add = false;
$mail_actions_links = false;
foreach ($languages as $language_file => $language_name) {
$templates_done = array();
$result_stmt = Database::prepare("
SELECT `varname` FROM `" . TABLE_PANEL_TEMPLATES . "`
WHERE `adminid` = :adminid AND `language`= :lang
AND `templategroup` = 'mails' AND `varname` LIKE '%_subject'");
AND `templategroup` = 'mails' AND `varname` LIKE '%_subject'
");
Database::pexecute($result_stmt, array(
'adminid' => $userinfo['adminid'],
'lang' => $language_name
@@ -97,13 +100,20 @@ if ($action == '') {
}
if (count(array_diff($available_templates, $templates_done)) > 0) {
$add = true;
$mail_actions_links = [[
'href' => $linker->getLink(['section' => 'templates', 'page' => $page, 'action' => 'add']),
'label' => $lng['admin']['templates']['template_add']
]];
}
}
$mailtpl_list_data = include_once dirname(__FILE__) . '/lib/tablelisting/admin/tablelisting.mailtemplates.php';
$collection_mail = [
'data' => $templates,
'pagination' => []
];
// filetemplates
$filetemplates = '';
$filetemplateadd = false;
$result_stmt = Database::prepare("
SELECT `id`, `varname` FROM `" . TABLE_PANEL_TEMPLATES . "`
WHERE `adminid` = :adminid AND `templategroup`='files'");
@@ -111,14 +121,35 @@ if ($action == '') {
'adminid' => $userinfo['adminid']
));
if (Database::num_rows() != count($file_templates)) {
$filetemplateadd = true;
$filetemplates = [];
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
$filetemplates[] = [
'id' => $row['id'],
'template' => $lng['admin']['templates'][$row['varname']]
];
}
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
eval("\$filetemplates.=\"" . \Froxlor\UI\Template::getTemplate("templates/templates_filetemplate") . "\";");
$file_actions_links = false;
if (Database::num_rows() != count($file_templates)) {
$file_actions_links = [[
'href' => $linker->getLink(['section' => 'templates', 'page' => $page, 'action' => 'add', 'files' => 'files']),
'label' => $lng['admin']['templates']['template_fileadd']
]];
}
eval("echo \"" . \Froxlor\UI\Template::getTemplate("templates/templates") . "\";");
$filetpl_list_data = include_once dirname(__FILE__) . '/lib/tablelisting/admin/tablelisting.filetemplates.php';
$collection_file = [
'data' => $filetemplates,
'pagination' => []
];
UI::twigBuffer('user/table-tpl.html.twig', [
'maillisting' => \Froxlor\UI\Listing::formatFromArray($collection_mail, $mailtpl_list_data['mailtpl_list']),
'filelisting' => \Froxlor\UI\Listing::formatFromArray($collection_file, $filetpl_list_data['filetpl_list']),
'mail_actions_links' => $mail_actions_links,
'file_actions_links' => $file_actions_links
]);
UI::twigOutputBuffer();
} elseif ($action == 'delete' && $subjectid != 0 && $mailbodyid != 0) {
// email templates
$result_stmt = Database::prepare("
@@ -194,15 +225,25 @@ if ($action == '') {
}
} elseif ($action == 'add') {
if (Settings::Get('panel.sendalternativemail') == 1) {
$available_templates[] = 'pop_success_alternative';
}
if (isset($_POST['prepare']) && $_POST['prepare'] == 'prepare') {
// email templates
$language = htmlentities(\Froxlor\Validate\Validate::validate($_POST['language'], 'language', '/^[^\r\n\0"\']+$/', 'nolanguageselect'));
$template = \Froxlor\Validate\Validate::validate($_POST['template'], 'template');
$result_stmt = Database::prepare("
SELECT COUNT(*) as def FROM `" . TABLE_PANEL_TEMPLATES . "`
WHERE `adminid` = :adminid AND `language` = :lang
AND `templategroup` = 'mails' AND `varname` LIKE :template
");
$result = Database::pexecute_first($result_stmt, array(
'adminid' => $userinfo['adminid'],
'lang' => $language,
'template' => $template . '%'
));
if ($result && $result['def'] > 0) {
\Froxlor\UI\Response::standard_error('templatelanguagecombodefined');
}
$lng_bak = $lng;
foreach ($langs['English'] as $key => $value) {
include_once \Froxlor\FileDir::makeSecurePath($value['file']);
@@ -226,7 +267,7 @@ if ($action == '') {
'replacers' => $template_add_data['template_replacers']
]);
UI::twigOutputBuffer();
} elseif (isset($_POST['send']) && $_POST['send'] == 'send') {
} elseif (isset($_POST['send']) && $_POST['send'] == 'send' && !isset($_POST['filesend'])) {
// email templates
$language = htmlentities(\Froxlor\Validate\Validate::validate($_POST['language'], 'language', '/^[^\r\n\0"\']+$/', 'nolanguageselect'));
$template = \Froxlor\Validate\Validate::validate($_POST['template'], 'template');
@@ -369,7 +410,8 @@ if ($action == '') {
]
]
]
]
],
'editid' => $id
]);
UI::twigOutputBuffer();
} else {
@@ -515,12 +557,14 @@ if ($action == '') {
$row = \Froxlor\PhpHelper::htmlentitiesArray($row);
$filetemplate_edit_data = include_once dirname(__FILE__) . '/lib/formfields/admin/templates/formfield.filetemplate_edit.php';
$filetemplate_edit_form = \Froxlor\UI\HtmlForm::genHTMLForm($filetemplate_edit_data);
$title = $filetemplate_edit_data['filetemplate_edit']['title'];
$image = $filetemplate_edit_data['filetemplate_edit']['image'];
eval("echo \"" . \Froxlor\UI\Template::getTemplate("templates/filetemplates_edit") . "\";");
UI::twigBuffer('user/form-replacers.html.twig', [
'formaction' => $linker->getLink(array('section' => 'templates')),
'formdata' => $filetemplate_edit_data['filetemplate_edit'],
'replacers' => $filetemplate_edit_data['filetemplate_replacers'],
'editid' => $id
]);
UI::twigOutputBuffer();
}
} else {
\Froxlor\UI\Response::standard_error('templatenotfound');

View File

@@ -35,9 +35,37 @@ return array(
'cols' => 60,
'rows' => 12,
'value' => $row['value']
),
'filesend' => array(
'type' => 'hidden',
'value' => 'filesend'
)
)
)
)
)
),
'filetemplate_replacers' => [
'replacers' => [
[
'var' => 'SERVERNAME',
'description' => $lng['admin']['templates']['SERVERNAME']
],
[
'var' => 'CUSTOMER',
'description' => $lng['admin']['templates']['CUSTOMER']
],
[
'var' => 'ADMIN',
'description' => $lng['admin']['templates']['ADMIN']
],
[
'var' => 'CUSTOMER_EMAIL',
'description' => $lng['admin']['templates']['CUSTOMER_EMAIL']
],
[
'var' => 'ADMIN_EMAIL',
'description' => $lng['admin']['templates']['ADMIN_EMAIL']
]
]
]
);

View File

@@ -0,0 +1,57 @@
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2010 the Froxlor Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Tabellisting
*
*/
use Froxlor\UI\Listing;
return [
'filetpl_list' => [
'title' => $lng['admin']['templates']['filetemplates'],
'icon' => 'fa-solid fa-file-lines',
'columns' => [
'template' => [
'label' => $lng['admin']['templates']['action'],
'field' => 'template'
],
],
'visible_columns' => Listing::getVisibleColumnsForListing('filetpl_list', [
'template'
]),
'actions' => [
'edit' => [
'icon' => 'fa fa-edit',
'title' => $lng['panel']['edit'],
'href' => [
'section' => 'templates',
'page' => $page,
'action' => 'editf',
'id' => ':id'
],
],
'delete' => [
'icon' => 'fa fa-trash',
'title' => $lng['panel']['delete'],
'class' => 'text-danger',
'href' => [
'section' => 'templates',
'page' => $page,
'action' => 'deletef',
'id' => ':id'
],
],
],
]
];

View File

@@ -0,0 +1,64 @@
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2010 the Froxlor Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Tabellisting
*
*/
use Froxlor\UI\Listing;
return [
'mailtpl_list' => [
'title' => $lng['admin']['templates']['templates'],
'icon' => 'fa-solid fa-envelope',
'columns' => [
'language' => [
'label' => $lng['login']['language'],
'field' => 'language'
],
'template' => [
'label' => $lng['admin']['templates']['action'],
'field' => 'template'
],
],
'visible_columns' => Listing::getVisibleColumnsForListing('mailtpl_list', [
'language',
'template'
]),
'actions' => [
'edit' => [
'icon' => 'fa fa-edit',
'title' => $lng['panel']['edit'],
'href' => [
'section' => 'templates',
'page' => $page,
'action' => 'edit',
'subjectid' => ':subjectid',
'mailbodyid' => ':mailbodyid'
],
],
'delete' => [
'icon' => 'fa fa-trash',
'title' => $lng['panel']['delete'],
'class' => 'text-danger',
'href' => [
'section' => 'templates',
'page' => $page,
'action' => 'delete',
'subjectid' => ':subjectid',
'mailbodyid' => ':mailbodyid'
],
],
],
]
];

View File

@@ -231,6 +231,7 @@ $lng['error']['destinationalreadyexistasmail'] = 'The forwarder to %s already ex
$lng['error']['destinationalreadyexist'] = 'You have already defined a forwarder to "%s"';
$lng['error']['destinationiswrong'] = 'The forwarder %s contains invalid character(s) or is incomplete.';
$lng['error']['backupfoldercannotbedocroot'] = 'The folder for backups cannot be your homedir, please chose a folder within your homedir, e.g. /backups';
$lng['error']['templatelanguagecombodefined'] = 'The selected language/template combination has already been defined.';
/**
* Questions
@@ -305,6 +306,7 @@ $lng['admin']['ownvhostsettings'] = 'Own vHost-settings';
$lng['admin']['configfiles']['serverconfiguration'] = 'Configuration';
$lng['admin']['templates']['templates'] = 'Email-templates';
$lng['admin']['templates']['template_add'] = 'Add template';
$lng['admin']['templates']['template_fileadd'] = 'Add file template';
$lng['admin']['templates']['template_edit'] = 'Edit template';
$lng['admin']['templates']['action'] = 'Action';
$lng['admin']['templates']['email'] = 'Email & file templates';

View File

@@ -301,6 +301,7 @@ $lng['admin']['ownvhostsettings'] = 'Eigene vHost-Einstellungen';
$lng['admin']['configfiles']['serverconfiguration'] = 'Konfiguration';
$lng['admin']['templates']['templates'] = 'E-Mail-Vorlagen';
$lng['admin']['templates']['template_add'] = 'Vorlage hinzufügen';
$lng['admin']['templates']['template_fileadd'] = 'Dateivorlage hinzufügen';
$lng['admin']['templates']['template_edit'] = 'Vorlage bearbeiten';
$lng['admin']['templates']['action'] = 'Aktion';
$lng['admin']['templates']['email'] = 'E-Mail- & Dateivorlagen';
@@ -318,6 +319,7 @@ $lng['admin']['templates']['PASSWORD'] = 'Wird mit dem Passwort des neuen Kunden
$lng['admin']['templates']['EMAIL'] = 'Wird mit der Adresse des neuen E-Mail-Kontos ersetzt.';
$lng['admin']['templates']['CUSTOMER_NO'] = 'Wir mit der Kunden-Nummer ersetzt';
$lng['admin']['bindzonewarning'] = $lng['panel']['emptyfordefault'] . '<br /><strong class="text-danger">WARNUNG:</strong> Bei der Verwendung einer Zonendatei müssen alle benötigten Records aller Subdomains ebenfalls manuell verwaltet werden.';
$lng['error']['templatelanguagecombodefined'] = 'Die gewählte Kombination aus Sprache und Vorlage ist bereits definiert.';
/**
* Serversettings

View File

@@ -14,7 +14,7 @@
</p>
{% endif %}
{% if redirect_link %}
<p class="mt-1">
<p class="mt-1 pb-3">
<a href="{{ redirect_link|raw }}" class="btn btn-{{ btntype }}">
{% if type == 'danger' %}
{{ lng('panel.back') }}

View File

@@ -0,0 +1,11 @@
{% extends "Froxlor/user/table.html.twig" %}
{% block content %}
{% set listing = maillisting %}
{% set actions_links = mail_actions_links %}
{{ parent() }}
{% set listing = filelisting %}
{% set actions_links = file_actions_links %}
{{ parent() }}
{% endblock %}