2010-01-27 08:54:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This file is part of the Froxlor project.
|
|
|
|
* Copyright (c) 2010 the Froxlor Team (see authors).
|
|
|
|
*
|
2022-04-28 18:48:00 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2010-01-27 08:54:31 +00:00
|
|
|
*
|
2022-04-28 18:48:00 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2011-05-04 09:59:20 +00:00
|
|
|
*
|
2022-04-28 18:48:00 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you can also view it online at
|
|
|
|
* https://files.froxlor.org/misc/COPYING.txt
|
|
|
|
*
|
|
|
|
* @copyright the authors
|
|
|
|
* @author Froxlor team <team@froxlor.org>
|
|
|
|
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
|
2010-01-27 08:54:31 +00:00
|
|
|
*/
|
2022-02-20 17:00:44 +00:00
|
|
|
|
|
|
|
const AREA = 'admin';
|
|
|
|
require __DIR__ . '/lib/init.php';
|
2010-01-27 08:54:31 +00:00
|
|
|
|
2018-12-21 18:16:49 +00:00
|
|
|
use Froxlor\Database\Database;
|
2022-04-28 18:48:00 +00:00
|
|
|
use Froxlor\FroxlorLogger;
|
2022-04-29 08:33:42 +00:00
|
|
|
use Froxlor\Language;
|
2022-04-28 18:48:00 +00:00
|
|
|
use Froxlor\PhpHelper;
|
2018-12-21 18:16:49 +00:00
|
|
|
use Froxlor\Settings;
|
2022-04-28 18:48:00 +00:00
|
|
|
use Froxlor\UI\HTML;
|
|
|
|
use Froxlor\UI\Listing;
|
2022-02-22 18:31:28 +00:00
|
|
|
use Froxlor\UI\Panel\UI;
|
2022-02-20 17:00:44 +00:00
|
|
|
use Froxlor\UI\Request;
|
2022-04-28 18:48:00 +00:00
|
|
|
use Froxlor\UI\Response;
|
|
|
|
use Froxlor\Validate\Validate;
|
2022-08-09 22:17:11 +00:00
|
|
|
use Froxlor\CurrentUser;
|
2018-12-18 12:45:05 +00:00
|
|
|
|
2022-12-30 20:43:27 +00:00
|
|
|
$id = (int)Request::any('id');
|
|
|
|
$subjectid = intval(Request::any('subjectid'));
|
|
|
|
$mailbodyid = intval(Request::any('mailbodyid'));
|
2010-01-27 08:54:31 +00:00
|
|
|
|
2022-04-28 18:48:00 +00:00
|
|
|
$available_templates = [
|
2010-01-27 08:54:31 +00:00
|
|
|
'createcustomer',
|
|
|
|
'pop_success',
|
2010-08-10 09:21:07 +00:00
|
|
|
'new_database_by_customer',
|
2010-08-17 06:19:57 +00:00
|
|
|
'new_ftpaccount_by_customer',
|
|
|
|
'password_reset'
|
2022-04-28 18:48:00 +00:00
|
|
|
];
|
2013-04-15 06:56:50 +00:00
|
|
|
|
|
|
|
// only show templates of features that are enabled #1191
|
2022-04-28 18:48:00 +00:00
|
|
|
if ((int)Settings::Get('system.report_enable') == 1) {
|
2018-12-21 11:24:07 +00:00
|
|
|
array_push($available_templates, 'trafficmaxpercent', 'diskmaxpercent');
|
2013-04-15 06:56:50 +00:00
|
|
|
}
|
2022-03-06 08:43:06 +00:00
|
|
|
if (Settings::Get('panel.sendalternativemail') == 1) {
|
|
|
|
array_push($available_templates, 'pop_success_alternative');
|
|
|
|
}
|
2013-11-02 11:07:34 +00:00
|
|
|
|
2022-04-28 18:48:00 +00:00
|
|
|
$file_templates = [
|
2023-11-26 09:53:41 +00:00
|
|
|
'index_html',
|
|
|
|
'unconfigured_html'
|
2022-04-28 18:48:00 +00:00
|
|
|
];
|
2010-01-27 08:54:31 +00:00
|
|
|
|
2022-05-21 15:29:14 +00:00
|
|
|
$languages = Language::getLanguages();
|
|
|
|
|
2013-11-02 11:07:34 +00:00
|
|
|
if ($action == '') {
|
2018-12-21 11:24:07 +00:00
|
|
|
// email templates
|
2022-04-28 18:48:00 +00:00
|
|
|
$log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, "viewed admin_templates");
|
2010-01-27 08:54:31 +00:00
|
|
|
|
2022-04-28 18:48:00 +00:00
|
|
|
$templates_array = [];
|
2013-11-02 11:07:34 +00:00
|
|
|
$result_stmt = Database::prepare("
|
|
|
|
SELECT `id`, `language`, `varname` FROM `" . TABLE_PANEL_TEMPLATES . "`
|
|
|
|
WHERE `adminid` = :adminid AND `templategroup`='mails'
|
2022-03-06 08:43:06 +00:00
|
|
|
ORDER BY `language`, `varname`
|
|
|
|
");
|
2022-04-28 18:48:00 +00:00
|
|
|
Database::pexecute($result_stmt, [
|
2018-12-22 07:15:31 +00:00
|
|
|
'adminid' => $userinfo['adminid']
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2010-01-27 08:54:31 +00:00
|
|
|
|
2013-11-02 11:07:34 +00:00
|
|
|
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
|
2022-04-28 18:48:00 +00:00
|
|
|
$parts = [];
|
2010-01-27 08:54:31 +00:00
|
|
|
preg_match('/^([a-z]([a-z_]+[a-z])*)_(mailbody|subject)$/', $row['varname'], $parts);
|
|
|
|
$templates_array[$row['language']][$parts[1]][$parts[3]] = $row['id'];
|
|
|
|
}
|
|
|
|
|
2022-03-06 08:43:06 +00:00
|
|
|
$templates = [];
|
2013-11-02 11:07:34 +00:00
|
|
|
foreach ($templates_array as $language => $template_defs) {
|
|
|
|
foreach ($template_defs as $action => $email) {
|
2022-03-06 08:43:06 +00:00
|
|
|
$templates[] = [
|
|
|
|
'subjectid' => $email['subject'],
|
|
|
|
'mailbodyid' => $email['mailbody'],
|
2022-04-28 18:48:00 +00:00
|
|
|
'template' => lng('admin.templates.' . $action),
|
2022-03-06 08:43:06 +00:00
|
|
|
'language' => $language
|
|
|
|
];
|
2010-01-27 08:54:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-06 08:43:06 +00:00
|
|
|
$mail_actions_links = false;
|
2017-10-31 12:03:06 +00:00
|
|
|
foreach ($languages as $language_file => $language_name) {
|
2022-04-28 18:48:00 +00:00
|
|
|
$templates_done = [];
|
2013-11-02 11:07:34 +00:00
|
|
|
$result_stmt = Database::prepare("
|
|
|
|
SELECT `varname` FROM `" . TABLE_PANEL_TEMPLATES . "`
|
|
|
|
WHERE `adminid` = :adminid AND `language`= :lang
|
2022-03-06 08:43:06 +00:00
|
|
|
AND `templategroup` = 'mails' AND `varname` LIKE '%_subject'
|
|
|
|
");
|
2022-04-28 18:48:00 +00:00
|
|
|
Database::pexecute($result_stmt, [
|
2018-12-22 07:15:31 +00:00
|
|
|
'adminid' => $userinfo['adminid'],
|
2018-12-21 11:24:07 +00:00
|
|
|
'lang' => $language_name
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2013-11-02 11:07:34 +00:00
|
|
|
|
|
|
|
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
|
2010-01-27 08:54:31 +00:00
|
|
|
$templates_done[] = str_replace('_subject', '', $row['varname']);
|
|
|
|
}
|
|
|
|
|
2013-11-02 11:07:34 +00:00
|
|
|
if (count(array_diff($available_templates, $templates_done)) > 0) {
|
2022-04-28 18:48:00 +00:00
|
|
|
$mail_actions_links = [
|
|
|
|
[
|
|
|
|
'href' => $linker->getLink(['section' => 'templates', 'page' => $page, 'action' => 'add']),
|
|
|
|
'label' => lng('admin.templates.template_add')
|
|
|
|
]
|
|
|
|
];
|
2010-01-27 08:54:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-06 08:43:06 +00:00
|
|
|
$mailtpl_list_data = include_once dirname(__FILE__) . '/lib/tablelisting/admin/tablelisting.mailtemplates.php';
|
|
|
|
$collection_mail = [
|
|
|
|
'data' => $templates,
|
|
|
|
'pagination' => []
|
|
|
|
];
|
|
|
|
|
2018-12-21 11:24:07 +00:00
|
|
|
// filetemplates
|
2013-11-02 11:07:34 +00:00
|
|
|
$result_stmt = Database::prepare("
|
|
|
|
SELECT `id`, `varname` FROM `" . TABLE_PANEL_TEMPLATES . "`
|
2018-12-21 11:24:07 +00:00
|
|
|
WHERE `adminid` = :adminid AND `templategroup`='files'");
|
2022-04-28 18:48:00 +00:00
|
|
|
Database::pexecute($result_stmt, [
|
2018-12-22 07:15:31 +00:00
|
|
|
'adminid' => $userinfo['adminid']
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2010-01-27 08:54:31 +00:00
|
|
|
|
2022-03-06 08:43:06 +00:00
|
|
|
$filetemplates = [];
|
|
|
|
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
|
|
|
|
$filetemplates[] = [
|
|
|
|
'id' => $row['id'],
|
2022-04-28 18:48:00 +00:00
|
|
|
'template' => lng('admin.templates.' . $row['varname'])
|
2022-03-06 08:43:06 +00:00
|
|
|
];
|
2013-11-02 11:07:34 +00:00
|
|
|
}
|
2010-01-27 08:54:31 +00:00
|
|
|
|
2022-03-06 08:43:06 +00:00
|
|
|
$file_actions_links = false;
|
|
|
|
if (Database::num_rows() != count($file_templates)) {
|
2022-04-28 18:48:00 +00:00
|
|
|
$file_actions_links = [
|
|
|
|
[
|
|
|
|
'href' => $linker->getLink([
|
|
|
|
'section' => 'templates',
|
|
|
|
'page' => $page,
|
|
|
|
'action' => 'add',
|
|
|
|
'files' => 'files'
|
|
|
|
]),
|
|
|
|
'label' => lng('admin.templates.template_fileadd')
|
|
|
|
]
|
|
|
|
];
|
2010-01-27 08:54:31 +00:00
|
|
|
}
|
2022-03-06 08:43:06 +00:00
|
|
|
|
|
|
|
$filetpl_list_data = include_once dirname(__FILE__) . '/lib/tablelisting/admin/tablelisting.filetemplates.php';
|
|
|
|
$collection_file = [
|
|
|
|
'data' => $filetemplates,
|
|
|
|
'pagination' => []
|
|
|
|
];
|
|
|
|
|
2022-05-21 15:29:14 +00:00
|
|
|
if ($mail_actions_links === false) {
|
|
|
|
$mail_actions_links = [];
|
|
|
|
}
|
|
|
|
if ($file_actions_links === false) {
|
|
|
|
$file_actions_links = [];
|
|
|
|
}
|
|
|
|
|
2022-03-18 11:53:34 +00:00
|
|
|
UI::view('user/table-tpl.html.twig', [
|
2022-10-16 11:35:50 +00:00
|
|
|
'maillisting' => Listing::formatFromArray($collection_mail, $mailtpl_list_data['mailtpl_list'], 'mailtpl_list'),
|
|
|
|
'filelisting' => Listing::formatFromArray($collection_file, $filetpl_list_data['filetpl_list'], 'filetpl_list'),
|
2022-03-16 12:22:59 +00:00
|
|
|
'actions_links' => array_merge($mail_actions_links, $file_actions_links)
|
2022-03-06 08:43:06 +00:00
|
|
|
]);
|
2018-12-21 11:24:07 +00:00
|
|
|
} elseif ($action == 'delete' && $subjectid != 0 && $mailbodyid != 0) {
|
|
|
|
// email templates
|
2013-11-02 11:07:34 +00:00
|
|
|
$result_stmt = Database::prepare("
|
|
|
|
SELECT `language`, `varname` FROM `" . TABLE_PANEL_TEMPLATES . "`
|
2018-12-21 11:24:07 +00:00
|
|
|
WHERE `adminid` = :adminid AND `id` = :id");
|
2022-04-28 18:48:00 +00:00
|
|
|
Database::pexecute($result_stmt, [
|
2018-12-22 07:15:31 +00:00
|
|
|
'adminid' => $userinfo['adminid'],
|
2018-12-21 11:24:07 +00:00
|
|
|
'id' => $subjectid
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2013-11-02 11:07:34 +00:00
|
|
|
$result = $result_stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
if ($result['varname'] != '') {
|
2024-05-09 13:48:23 +00:00
|
|
|
if (Request::post('send') == 'send') {
|
2013-11-02 11:07:34 +00:00
|
|
|
$del_stmt = Database::prepare("
|
|
|
|
DELETE FROM `" . TABLE_PANEL_TEMPLATES . "`
|
|
|
|
WHERE `adminid` = :adminid
|
2018-12-21 11:24:07 +00:00
|
|
|
AND (`id` = :ida OR `id` = :idb)");
|
2022-04-28 18:48:00 +00:00
|
|
|
Database::pexecute($del_stmt, [
|
2018-12-22 07:15:31 +00:00
|
|
|
'adminid' => $userinfo['adminid'],
|
2013-11-02 11:07:34 +00:00
|
|
|
'ida' => $subjectid,
|
|
|
|
'idb' => $mailbodyid
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
|
|
|
$log->logAction(FroxlorLogger::ADM_ACTION, LOG_INFO, "deleted template '" . $result['language'] . ' - ' . lng('admin.templates.' . str_replace('_subject', '', $result['varname'])) . "'");
|
|
|
|
Response::redirectTo($filename, [
|
2022-03-14 21:51:59 +00:00
|
|
|
'page' => $page
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2013-11-02 11:07:34 +00:00
|
|
|
} else {
|
2022-04-28 18:48:00 +00:00
|
|
|
HTML::askYesNo('admin_template_reallydelete', $filename, [
|
2018-12-21 11:24:07 +00:00
|
|
|
'subjectid' => $subjectid,
|
|
|
|
'mailbodyid' => $mailbodyid,
|
|
|
|
'page' => $page,
|
|
|
|
'action' => $action
|
2022-04-28 18:48:00 +00:00
|
|
|
], $result['language'] . ' - ' . lng('admin.templates.' . str_replace('_subject', '', $result['varname'])));
|
2010-01-27 08:54:31 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-21 11:24:07 +00:00
|
|
|
} elseif ($action == 'deletef' && $id != 0) {
|
|
|
|
// file templates
|
2013-11-02 11:07:34 +00:00
|
|
|
$result_stmt = Database::prepare("
|
|
|
|
SELECT * FROM `" . TABLE_PANEL_TEMPLATES . "`
|
2018-12-21 11:24:07 +00:00
|
|
|
WHERE `adminid` = :adminid AND `id` = :id");
|
2022-04-28 18:48:00 +00:00
|
|
|
Database::pexecute($result_stmt, [
|
2018-12-22 07:15:31 +00:00
|
|
|
'adminid' => $userinfo['adminid'],
|
2018-12-21 11:24:07 +00:00
|
|
|
'id' => $id
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2010-01-27 08:54:31 +00:00
|
|
|
|
2013-11-02 11:07:34 +00:00
|
|
|
if (Database::num_rows() > 0) {
|
|
|
|
$row = $result_stmt->fetch(PDO::FETCH_ASSOC);
|
2010-01-27 08:54:31 +00:00
|
|
|
|
2024-05-09 13:48:23 +00:00
|
|
|
if (Request::post('send') == 'send') {
|
2013-11-02 11:07:34 +00:00
|
|
|
$del_stmt = Database::prepare("
|
|
|
|
DELETE FROM `" . TABLE_PANEL_TEMPLATES . "`
|
2018-12-21 11:24:07 +00:00
|
|
|
WHERE `adminid` = :adminid AND `id` = :id");
|
2022-04-28 18:48:00 +00:00
|
|
|
Database::pexecute($del_stmt, [
|
2018-12-22 07:15:31 +00:00
|
|
|
'adminid' => $userinfo['adminid'],
|
2018-12-21 11:24:07 +00:00
|
|
|
'id' => $id
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
|
|
|
$log->logAction(FroxlorLogger::ADM_ACTION, LOG_INFO, "deleted template '" . lng('admin.templates.' . $row['varname']) . "'");
|
|
|
|
Response::redirectTo($filename, [
|
2022-03-14 21:51:59 +00:00
|
|
|
'page' => $page
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2013-11-02 11:07:34 +00:00
|
|
|
} else {
|
2022-04-28 18:48:00 +00:00
|
|
|
HTML::askYesNo('admin_template_reallydelete', $filename, [
|
2018-12-21 11:24:07 +00:00
|
|
|
'id' => $id,
|
|
|
|
'page' => $page,
|
|
|
|
'action' => $action
|
2022-04-28 18:48:00 +00:00
|
|
|
], lng('admin.templates.' . $row['varname']));
|
2010-01-27 08:54:31 +00:00
|
|
|
}
|
2013-11-02 11:07:34 +00:00
|
|
|
} else {
|
2022-04-28 18:48:00 +00:00
|
|
|
Response::standardError('templatenotfound');
|
2010-01-27 08:54:31 +00:00
|
|
|
}
|
2018-12-21 11:24:07 +00:00
|
|
|
} elseif ($action == 'add') {
|
2024-05-09 13:48:23 +00:00
|
|
|
if (Request::post('prepare') == 'prepare') {
|
2018-12-21 11:24:07 +00:00
|
|
|
// email templates
|
2024-05-09 13:48:23 +00:00
|
|
|
$language = htmlentities(Validate::validate(Request::post('language'), 'language', '/^[^\r\n\0"\']+$/', 'nolanguageselect'));
|
2023-01-28 11:16:40 +00:00
|
|
|
if (!array_key_exists($language, $languages)) {
|
|
|
|
Response::standardError('templatelanguageinvalid');
|
|
|
|
}
|
2024-05-09 13:48:23 +00:00
|
|
|
$template = Validate::validate(Request::post('template'), 'template');
|
2013-11-02 11:07:34 +00:00
|
|
|
|
2022-03-06 08:43:06 +00:00
|
|
|
$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
|
|
|
|
");
|
2022-04-28 18:48:00 +00:00
|
|
|
$result = Database::pexecute_first($result_stmt, [
|
2022-03-06 08:43:06 +00:00
|
|
|
'adminid' => $userinfo['adminid'],
|
|
|
|
'lang' => $language,
|
|
|
|
'template' => $template . '%'
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2022-03-06 08:43:06 +00:00
|
|
|
if ($result && $result['def'] > 0) {
|
2022-04-28 18:48:00 +00:00
|
|
|
Response::standardError('templatelanguagecombodefined');
|
2022-03-06 08:43:06 +00:00
|
|
|
}
|
|
|
|
|
2022-04-29 08:33:42 +00:00
|
|
|
// set target language
|
|
|
|
Language::setLanguage($language);
|
2010-01-27 08:54:31 +00:00
|
|
|
|
2022-04-28 18:48:00 +00:00
|
|
|
$subject = lng('mails.' . $template . '.subject');
|
|
|
|
$body = str_replace('\n', "\n", lng('mails.' . $template . '.mailbody'));
|
2014-12-11 13:07:18 +00:00
|
|
|
|
2022-04-29 08:33:42 +00:00
|
|
|
// re set language to user
|
|
|
|
Language::setLanguage(CurrentUser::getField('def_language'));
|
2014-12-11 13:07:18 +00:00
|
|
|
|
2018-12-21 11:24:07 +00:00
|
|
|
$template_add_data = include_once dirname(__FILE__) . '/lib/formfields/admin/templates/formfield.template_add.php';
|
2011-02-08 11:53:24 +00:00
|
|
|
|
2022-03-18 11:53:34 +00:00
|
|
|
UI::view('user/form-replacers.html.twig', [
|
2022-04-28 18:48:00 +00:00
|
|
|
'formaction' => $linker->getLink(['section' => 'templates']),
|
2022-03-05 10:46:35 +00:00
|
|
|
'formdata' => $template_add_data['template_add'],
|
|
|
|
'replacers' => $template_add_data['template_replacers']
|
2022-02-22 18:31:28 +00:00
|
|
|
]);
|
2024-05-09 13:48:23 +00:00
|
|
|
} elseif (Request::post('send') == 'send' && empty(Request::post('filesend'))) {
|
2018-12-21 11:24:07 +00:00
|
|
|
// email templates
|
2024-05-09 13:48:23 +00:00
|
|
|
$language = htmlentities(Validate::validate(Request::post('language'), 'language', '/^[^\r\n\0"\']+$/', 'nolanguageselect'));
|
2023-01-28 11:16:40 +00:00
|
|
|
if (!array_key_exists($language, $languages)) {
|
|
|
|
Response::standardError('templatelanguageinvalid');
|
|
|
|
}
|
2024-05-09 13:48:23 +00:00
|
|
|
$template = Validate::validate(Request::post('template'), 'template');
|
|
|
|
$subject = Validate::validate(Request::post('subject'), 'subject', '/^[^\r\n\0]+$/', 'nosubjectcreate');
|
|
|
|
$mailbody = Validate::validate(Request::post('mailbody'), 'mailbody', '/^[^\0]+$/', 'nomailbodycreate');
|
2022-04-28 18:48:00 +00:00
|
|
|
$templates = [];
|
2013-11-02 11:07:34 +00:00
|
|
|
$result_stmt = Database::prepare("
|
|
|
|
SELECT `varname` FROM `" . TABLE_PANEL_TEMPLATES . "`
|
|
|
|
WHERE `adminid` = :adminid AND `language` = :lang
|
2018-12-21 11:24:07 +00:00
|
|
|
AND `templategroup` = 'mails' AND `varname` LIKE '%_subject'");
|
2022-04-28 18:48:00 +00:00
|
|
|
Database::pexecute($result_stmt, [
|
2018-12-22 07:15:31 +00:00
|
|
|
'adminid' => $userinfo['adminid'],
|
2018-12-21 11:24:07 +00:00
|
|
|
'lang' => $language
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2013-11-02 11:07:34 +00:00
|
|
|
|
2018-12-21 11:24:07 +00:00
|
|
|
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
|
2010-01-27 08:54:31 +00:00
|
|
|
$templates[] = str_replace('_subject', '', $row['varname']);
|
|
|
|
}
|
|
|
|
|
|
|
|
$templates = array_diff($available_templates, $templates);
|
2022-04-14 07:02:10 +00:00
|
|
|
if (!in_array($template, $templates)) {
|
2022-04-28 18:48:00 +00:00
|
|
|
Response::standardError('templatenotfound');
|
2013-11-02 11:07:34 +00:00
|
|
|
} else {
|
|
|
|
$ins_stmt = Database::prepare("
|
|
|
|
INSERT INTO `" . TABLE_PANEL_TEMPLATES . "` SET
|
|
|
|
`adminid` = :adminid,
|
|
|
|
`language` = :lang,
|
|
|
|
`templategroup` = 'mails',
|
|
|
|
`varname` = :var,
|
2018-12-21 11:24:07 +00:00
|
|
|
`value` = :value");
|
2013-11-02 11:07:34 +00:00
|
|
|
|
|
|
|
// mail-subject
|
2022-04-28 18:48:00 +00:00
|
|
|
$ins_data = [
|
2018-12-22 07:15:31 +00:00
|
|
|
'adminid' => $userinfo['adminid'],
|
2013-11-02 11:07:34 +00:00
|
|
|
'lang' => $language,
|
2018-12-21 11:24:07 +00:00
|
|
|
'var' => $template . '_subject',
|
2013-11-02 11:07:34 +00:00
|
|
|
'value' => $subject
|
2022-04-28 18:48:00 +00:00
|
|
|
];
|
2013-11-02 11:07:34 +00:00
|
|
|
Database::pexecute($ins_stmt, $ins_data);
|
|
|
|
|
|
|
|
// mail-body
|
2022-04-28 18:48:00 +00:00
|
|
|
$ins_data = [
|
2018-12-22 07:15:31 +00:00
|
|
|
'adminid' => $userinfo['adminid'],
|
2013-11-02 11:07:34 +00:00
|
|
|
'lang' => $language,
|
2018-12-21 11:24:07 +00:00
|
|
|
'var' => $template . '_mailbody',
|
2013-11-02 11:07:34 +00:00
|
|
|
'value' => $mailbody
|
2022-04-28 18:48:00 +00:00
|
|
|
];
|
2013-11-02 11:07:34 +00:00
|
|
|
Database::pexecute($ins_stmt, $ins_data);
|
|
|
|
|
2022-04-28 18:48:00 +00:00
|
|
|
$log->logAction(FroxlorLogger::ADM_ACTION, LOG_INFO, "added template '" . $language . ' - ' . $template . "'");
|
|
|
|
Response::redirectTo($filename, [
|
2022-03-14 21:51:59 +00:00
|
|
|
'page' => $page
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2010-01-27 08:54:31 +00:00
|
|
|
}
|
2024-05-09 13:48:23 +00:00
|
|
|
} elseif (Request::post('filesend') == 'filesend') {
|
2018-12-21 11:24:07 +00:00
|
|
|
// file templates
|
2024-05-09 13:48:23 +00:00
|
|
|
$template = Validate::validate(Request::post('template'), 'template');
|
|
|
|
$filecontent = Validate::validate(Request::post('filecontent'), 'filecontent', '/^[^\0]+$/', 'filecontentnotset');
|
2013-11-02 11:07:34 +00:00
|
|
|
|
|
|
|
$ins_stmt = Database::prepare("
|
|
|
|
INSERT INTO `" . TABLE_PANEL_TEMPLATES . "` SET
|
|
|
|
`adminid` = :adminid,
|
|
|
|
`language` = '',
|
2013-11-07 10:16:38 +00:00
|
|
|
`templategroup` = 'files',
|
2013-11-02 11:07:34 +00:00
|
|
|
`varname` = :var,
|
2018-12-21 11:24:07 +00:00
|
|
|
`value` = :value");
|
2013-11-02 11:07:34 +00:00
|
|
|
|
2022-04-28 18:48:00 +00:00
|
|
|
$ins_data = [
|
2018-12-22 07:15:31 +00:00
|
|
|
'adminid' => $userinfo['adminid'],
|
2013-11-02 11:07:34 +00:00
|
|
|
'var' => $template,
|
|
|
|
'value' => $filecontent
|
2022-04-28 18:48:00 +00:00
|
|
|
];
|
2013-11-02 11:07:34 +00:00
|
|
|
Database::pexecute($ins_stmt, $ins_data);
|
|
|
|
|
2022-04-28 18:48:00 +00:00
|
|
|
$log->logAction(FroxlorLogger::ADM_ACTION, LOG_INFO, "added template '" . $template . "'");
|
|
|
|
Response::redirectTo($filename, [
|
2022-03-14 21:51:59 +00:00
|
|
|
'page' => $page
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2024-05-09 14:03:46 +00:00
|
|
|
} elseif (empty(Request::get('files'))) {
|
2018-12-21 11:24:07 +00:00
|
|
|
// email templates
|
2010-01-27 08:54:31 +00:00
|
|
|
$add = false;
|
2022-02-22 18:31:28 +00:00
|
|
|
$language_options = [];
|
|
|
|
$template_options = [];
|
2010-01-27 08:54:31 +00:00
|
|
|
|
2017-10-31 12:03:06 +00:00
|
|
|
foreach ($languages as $language_file => $language_name) {
|
2022-04-28 18:48:00 +00:00
|
|
|
$templates = [];
|
2013-11-02 11:07:34 +00:00
|
|
|
$result_stmt = Database::prepare("
|
|
|
|
SELECT `varname` FROM `" . TABLE_PANEL_TEMPLATES . "`
|
|
|
|
WHERE `adminid` = :adminid AND `language` = :lang
|
2018-12-21 11:24:07 +00:00
|
|
|
AND `templategroup` = 'mails' AND `varname` LIKE '%_subject'");
|
2022-04-28 18:48:00 +00:00
|
|
|
Database::pexecute($result_stmt, [
|
2018-12-22 07:15:31 +00:00
|
|
|
'adminid' => $userinfo['adminid'],
|
2018-12-21 11:24:07 +00:00
|
|
|
'lang' => $language_name
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2013-11-02 11:07:34 +00:00
|
|
|
|
|
|
|
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
|
2010-01-27 08:54:31 +00:00
|
|
|
$templates[] = str_replace('_subject', '', $row['varname']);
|
|
|
|
}
|
|
|
|
|
2013-11-02 11:07:34 +00:00
|
|
|
if (count(array_diff($available_templates, $templates)) > 0) {
|
2010-01-27 08:54:31 +00:00
|
|
|
$add = true;
|
2022-02-22 18:31:28 +00:00
|
|
|
$language_options[$language_file] = $language_name;
|
2014-12-11 13:07:18 +00:00
|
|
|
|
|
|
|
$templates = array_diff($available_templates, $templates);
|
|
|
|
|
|
|
|
foreach ($templates as $template) {
|
2022-04-28 18:48:00 +00:00
|
|
|
$template_options[$template] = lng('admin.templates.' . $template);
|
2014-12-11 13:07:18 +00:00
|
|
|
}
|
2010-01-27 08:54:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-02 11:07:34 +00:00
|
|
|
if ($add) {
|
2022-03-18 11:53:34 +00:00
|
|
|
UI::view('user/form.html.twig', [
|
2022-04-28 18:48:00 +00:00
|
|
|
'formaction' => $linker->getLink(['section' => 'templates']),
|
2022-02-22 18:31:28 +00:00
|
|
|
'formdata' => [
|
2022-04-28 18:48:00 +00:00
|
|
|
'title' => lng('admin.templates.template_add'),
|
2022-02-22 18:31:28 +00:00
|
|
|
'image' => 'fa-solid fa-plus',
|
2022-10-18 18:39:01 +00:00
|
|
|
'self_overview' => ['section' => 'templates', 'page' => 'email'],
|
2022-02-22 18:31:28 +00:00
|
|
|
'sections' => [
|
|
|
|
'section_a' => [
|
2022-04-28 18:48:00 +00:00
|
|
|
'title' => lng('admin.templates.template_add'),
|
2022-02-22 18:31:28 +00:00
|
|
|
'fields' => [
|
|
|
|
'language' => [
|
2022-04-28 18:48:00 +00:00
|
|
|
'label' => lng('login.language'),
|
2022-02-22 18:31:28 +00:00
|
|
|
'type' => 'select',
|
|
|
|
'select_var' => $language_options,
|
|
|
|
'selected' => $userinfo['language']
|
|
|
|
],
|
|
|
|
'template' => [
|
2022-04-28 18:48:00 +00:00
|
|
|
'label' => lng('admin.templates.action'),
|
2022-02-22 18:31:28 +00:00
|
|
|
'type' => 'select',
|
|
|
|
'select_var' => $template_options
|
|
|
|
],
|
|
|
|
'prepare' => [
|
|
|
|
'type' => 'hidden',
|
|
|
|
'value' => 'prepare'
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
2022-03-06 08:43:06 +00:00
|
|
|
],
|
|
|
|
'editid' => $id
|
2022-02-22 18:31:28 +00:00
|
|
|
]);
|
2013-11-02 11:07:34 +00:00
|
|
|
} else {
|
2022-04-28 18:48:00 +00:00
|
|
|
Response::standardError('alltemplatesdefined');
|
2010-01-27 08:54:31 +00:00
|
|
|
}
|
2013-11-02 11:07:34 +00:00
|
|
|
} else {
|
2018-12-21 11:24:07 +00:00
|
|
|
// filetemplates
|
2013-11-02 11:07:34 +00:00
|
|
|
$result_stmt = Database::prepare("
|
|
|
|
SELECT `id`, `varname` FROM `" . TABLE_PANEL_TEMPLATES . "`
|
2018-12-21 11:24:07 +00:00
|
|
|
WHERE `adminid` = :adminid AND `templategroup`='files'");
|
2022-04-28 18:48:00 +00:00
|
|
|
Database::pexecute($result_stmt, [
|
2018-12-22 07:15:31 +00:00
|
|
|
'adminid' => $userinfo['adminid']
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2010-01-27 08:54:31 +00:00
|
|
|
|
2013-11-02 11:07:34 +00:00
|
|
|
if (Database::num_rows() == count($file_templates)) {
|
2022-04-28 18:48:00 +00:00
|
|
|
Response::standardError('alltemplatesdefined');
|
2013-11-02 11:07:34 +00:00
|
|
|
} else {
|
2022-04-28 18:48:00 +00:00
|
|
|
$templatesdefined = [];
|
2022-03-05 10:46:35 +00:00
|
|
|
$free_templates = [];
|
2010-01-27 08:54:31 +00:00
|
|
|
|
2013-11-02 11:07:34 +00:00
|
|
|
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
|
|
|
|
$templatesdefined[] = $row['varname'];
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (array_diff($file_templates, $templatesdefined) as $template) {
|
2022-04-28 18:48:00 +00:00
|
|
|
$free_templates[$template] = lng('admin.templates.' . $template);
|
2010-01-27 08:54:31 +00:00
|
|
|
}
|
|
|
|
|
2018-12-21 11:24:07 +00:00
|
|
|
$filetemplate_add_data = include_once dirname(__FILE__) . '/lib/formfields/admin/templates/formfield.filetemplate_add.php';
|
2011-02-08 11:53:24 +00:00
|
|
|
|
2022-03-18 11:53:34 +00:00
|
|
|
UI::view('user/form-replacers.html.twig', [
|
2022-04-28 18:48:00 +00:00
|
|
|
'formaction' => $linker->getLink(['section' => 'templates']),
|
2022-03-05 10:46:35 +00:00
|
|
|
'formdata' => $filetemplate_add_data['filetemplate_add'],
|
|
|
|
'replacers' => $filetemplate_add_data['filetemplate_replacers']
|
|
|
|
]);
|
2010-01-27 08:54:31 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-21 11:24:07 +00:00
|
|
|
} elseif ($action == 'edit' && $subjectid != 0 && $mailbodyid != 0) {
|
|
|
|
// email templates
|
2013-11-02 11:07:34 +00:00
|
|
|
$result_stmt = Database::prepare("
|
|
|
|
SELECT `language`, `varname`, `value` FROM `" . TABLE_PANEL_TEMPLATES . "`
|
2018-12-21 11:24:07 +00:00
|
|
|
WHERE `adminid` = :adminid AND `id` = :subjectid");
|
2022-04-28 18:48:00 +00:00
|
|
|
Database::pexecute($result_stmt, [
|
2018-12-22 07:15:31 +00:00
|
|
|
'adminid' => $userinfo['adminid'],
|
2018-12-21 11:24:07 +00:00
|
|
|
'subjectid' => $subjectid
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2013-11-02 11:07:34 +00:00
|
|
|
$result = $result_stmt->fetch(PDO::FETCH_ASSOC);
|
2010-01-27 08:54:31 +00:00
|
|
|
|
2013-11-02 11:07:34 +00:00
|
|
|
if ($result['varname'] != '') {
|
2024-05-09 13:48:23 +00:00
|
|
|
if (Request::post('send') == 'send') {
|
|
|
|
$subject = Validate::validate(Request::post('subject'), 'subject', '/^[^\r\n\0]+$/', 'nosubjectcreate');
|
|
|
|
$mailbody = Validate::validate(Request::post('mailbody'), 'mailbody', '/^[^\0]+$/', 'nomailbodycreate');
|
2013-11-02 11:07:34 +00:00
|
|
|
|
|
|
|
$upd_stmt = Database::prepare("
|
|
|
|
UPDATE `" . TABLE_PANEL_TEMPLATES . "` SET
|
|
|
|
`value` = :value
|
2018-12-21 11:24:07 +00:00
|
|
|
WHERE `adminid` = :adminid AND `id` = :id");
|
2013-11-02 11:07:34 +00:00
|
|
|
// subject
|
2022-04-28 18:48:00 +00:00
|
|
|
Database::pexecute($upd_stmt, [
|
2013-11-02 11:07:34 +00:00
|
|
|
'value' => $subject,
|
2018-12-22 07:15:31 +00:00
|
|
|
'adminid' => $userinfo['adminid'],
|
2013-11-02 11:07:34 +00:00
|
|
|
'id' => $subjectid
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2013-11-02 11:07:34 +00:00
|
|
|
// same query but mailbody
|
2022-04-28 18:48:00 +00:00
|
|
|
Database::pexecute($upd_stmt, [
|
2013-11-02 11:07:34 +00:00
|
|
|
'value' => $mailbody,
|
2018-12-22 07:15:31 +00:00
|
|
|
'adminid' => $userinfo['adminid'],
|
2013-11-02 11:07:34 +00:00
|
|
|
'id' => $mailbodyid
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2013-11-02 11:07:34 +00:00
|
|
|
|
2022-04-28 18:48:00 +00:00
|
|
|
$log->logAction(FroxlorLogger::ADM_ACTION, LOG_INFO, "edited template '" . $result['varname'] . "'");
|
|
|
|
Response::redirectTo($filename, [
|
2022-03-14 21:51:59 +00:00
|
|
|
'page' => $page
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2013-11-02 11:07:34 +00:00
|
|
|
} else {
|
2022-04-28 18:48:00 +00:00
|
|
|
$result = PhpHelper::htmlentitiesArray($result);
|
|
|
|
$template_name = lng('admin.templates.' . str_replace('_subject', '', $result['varname']));
|
2010-01-27 08:54:31 +00:00
|
|
|
$subject = $result['value'];
|
2013-11-02 11:07:34 +00:00
|
|
|
$result_stmt = Database::prepare("
|
|
|
|
SELECT `language`, `varname`, `value`
|
|
|
|
FROM `" . TABLE_PANEL_TEMPLATES . "`
|
2018-12-21 11:24:07 +00:00
|
|
|
WHERE `id` = :id");
|
2022-04-28 18:48:00 +00:00
|
|
|
Database::pexecute($result_stmt, [
|
2018-12-21 11:24:07 +00:00
|
|
|
'id' => $mailbodyid
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2013-11-02 11:07:34 +00:00
|
|
|
$result = $result_stmt->fetch(PDO::FETCH_ASSOC);
|
2018-12-21 11:24:07 +00:00
|
|
|
|
2022-03-05 10:46:35 +00:00
|
|
|
$template = str_replace('_mailbody', '', $result['varname']);
|
2013-11-02 11:07:34 +00:00
|
|
|
|
2015-02-08 18:45:15 +00:00
|
|
|
// don't escape the already escaped language-string so save up before htmlentities()
|
|
|
|
$language = $result['language'];
|
2022-04-28 18:48:00 +00:00
|
|
|
$result = PhpHelper::htmlentitiesArray($result);
|
2010-01-27 08:54:31 +00:00
|
|
|
$mailbody = $result['value'];
|
2011-02-08 11:53:24 +00:00
|
|
|
|
2018-12-21 11:24:07 +00:00
|
|
|
$template_edit_data = include_once dirname(__FILE__) . '/lib/formfields/admin/templates/formfield.template_edit.php';
|
2011-02-08 11:53:24 +00:00
|
|
|
|
2022-03-18 11:53:34 +00:00
|
|
|
UI::view('user/form-replacers.html.twig', [
|
2022-04-28 18:48:00 +00:00
|
|
|
'formaction' => $linker->getLink(['section' => 'templates']),
|
2022-03-05 10:46:35 +00:00
|
|
|
'formdata' => $template_edit_data['template_edit'],
|
|
|
|
'replacers' => $template_edit_data['template_replacers']
|
|
|
|
]);
|
2010-01-27 08:54:31 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-21 11:24:07 +00:00
|
|
|
} elseif ($action == 'editf' && $id != 0) {
|
|
|
|
// file templates
|
2013-11-02 11:07:34 +00:00
|
|
|
$result_stmt = Database::prepare("
|
|
|
|
SELECT * FROM `" . TABLE_PANEL_TEMPLATES . "`
|
2018-12-21 11:24:07 +00:00
|
|
|
WHERE `adminid` = :adminid AND `id` = :id");
|
2022-04-28 18:48:00 +00:00
|
|
|
Database::pexecute($result_stmt, [
|
2018-12-22 07:15:31 +00:00
|
|
|
'adminid' => $userinfo['adminid'],
|
2018-12-21 11:24:07 +00:00
|
|
|
'id' => $id
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2010-01-27 08:54:31 +00:00
|
|
|
|
2018-12-21 11:24:07 +00:00
|
|
|
if (Database::num_rows() > 0) {
|
2013-11-02 11:07:34 +00:00
|
|
|
$row = $result_stmt->fetch(PDO::FETCH_ASSOC);
|
2010-01-27 08:54:31 +00:00
|
|
|
|
2018-12-21 11:24:07 +00:00
|
|
|
// filetemplates
|
2024-05-09 13:48:23 +00:00
|
|
|
if (Request::post('filesend') == 'filesend') {
|
|
|
|
$filecontent = Validate::validate(Request::post('filecontent'), 'filecontent', '/^[^\0]+$/', 'filecontentnotset');
|
2013-11-02 11:07:34 +00:00
|
|
|
$upd_stmt = Database::prepare("
|
|
|
|
UPDATE `" . TABLE_PANEL_TEMPLATES . "` SET
|
|
|
|
`value` = :value
|
2018-12-21 11:24:07 +00:00
|
|
|
WHERE `adminid` = :adminid AND `id` = :id");
|
2022-04-28 18:48:00 +00:00
|
|
|
Database::pexecute($upd_stmt, [
|
2013-11-02 11:07:34 +00:00
|
|
|
'value' => $filecontent,
|
2018-12-22 07:15:31 +00:00
|
|
|
'adminid' => $userinfo['adminid'],
|
2013-11-02 11:07:34 +00:00
|
|
|
'id' => $id
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2013-11-02 11:07:34 +00:00
|
|
|
|
2022-04-28 18:48:00 +00:00
|
|
|
$log->logAction(FroxlorLogger::ADM_ACTION, LOG_INFO, "edited template '" . $row['varname'] . "'");
|
|
|
|
Response::redirectTo($filename, [
|
2022-03-14 21:51:59 +00:00
|
|
|
'page' => $page
|
2022-04-28 18:48:00 +00:00
|
|
|
]);
|
2013-11-02 11:07:34 +00:00
|
|
|
} else {
|
2022-04-28 18:48:00 +00:00
|
|
|
$row = PhpHelper::htmlentitiesArray($row);
|
2011-02-08 11:53:24 +00:00
|
|
|
|
2018-12-21 11:24:07 +00:00
|
|
|
$filetemplate_edit_data = include_once dirname(__FILE__) . '/lib/formfields/admin/templates/formfield.filetemplate_edit.php';
|
2011-02-08 11:53:24 +00:00
|
|
|
|
2022-03-18 11:53:34 +00:00
|
|
|
UI::view('user/form-replacers.html.twig', [
|
2022-04-28 18:48:00 +00:00
|
|
|
'formaction' => $linker->getLink(['section' => 'templates']),
|
2022-03-06 08:43:06 +00:00
|
|
|
'formdata' => $filetemplate_edit_data['filetemplate_edit'],
|
|
|
|
'replacers' => $filetemplate_edit_data['filetemplate_replacers'],
|
|
|
|
'editid' => $id
|
|
|
|
]);
|
2010-01-27 08:54:31 +00:00
|
|
|
}
|
2013-11-02 11:07:34 +00:00
|
|
|
} else {
|
2022-04-28 18:48:00 +00:00
|
|
|
Response::standardError('templatenotfound');
|
2010-01-27 08:54:31 +00:00
|
|
|
}
|
|
|
|
}
|