добавлено AJAX сохранение настроек модуля

This commit is contained in:
2025-12-24 18:28:27 +05:00
parent e9bd93daa0
commit 07cc626bab
2 changed files with 84 additions and 24 deletions

View File

@@ -1229,12 +1229,11 @@ function commentPostDelete($comment_id)
*/
function commentAdminSettingsEdit($tpl_dir)
{
global $AVE_DB, $AVE_Template;
global $AVE_DB, $AVE_Template, $sess; // Добавили $sess в global для редиректа
$request_sub = $_REQUEST['sub'] ?? '';
$post_max_chars = $_POST['comment_max_chars'] ?? 0;
$post_user_groups = $_POST['comment_user_groups'] ?? array();
$post_user_groups_read = $_POST['comment_user_groups_read'] ?? array();
$post_need_approve = $_POST['comment_need_approve'] ?? 0;
@@ -1243,25 +1242,13 @@ function commentAdminSettingsEdit($tpl_dir)
$post_use_page_nav = $_POST['comment_use_page_nav'] ?? 0;
$post_page_nav_count = $_POST['comment_page_nav_count'] ?? 0;
// НОВОЕ: Настройка разрешения загрузки файлов
$post_allow_files = $_POST['comment_allow_files'] ?? 0;
// ДОБАВЛЕНО: Разрешение анонимам загружать изображения
$post_allow_files_anon = $_POST['comment_allow_files_anon'] ?? 0;
// НОВОЕ: Тип рейтинга (0 - звезды, 1 - лайки)
$post_rating_type = $_POST['comment_rating_type'] ?? 0;
// НОВОЕ: ВКЛ/ВЫКЛ авторских звезд
$post_show_user_rating = $_POST['comment_show_user_rating'] ?? 0;
// НОВОЕ: Разрешение голосования анонимам
$post_rating_anon_vote = $_POST['comment_rating_anon_vote'] ?? 0;
// НОВОЕ: Разрешение анонимам ставить звезды (Авторский рейтинг)
$post_rating_anon_set = $_POST['comment_rating_anon_set'] ?? 0;
// Данные для универсальных полей
$post_show_f1 = $_POST['comment_show_f1'] ?? 0;
$post_req_f1 = $_POST['comment_req_f1'] ?? 0;
$post_name_f1 = $_POST['comment_name_f1'] ?? '';
@@ -1270,10 +1257,10 @@ function commentAdminSettingsEdit($tpl_dir)
$post_req_f2 = $_POST['comment_req_f2'] ?? 0;
$post_name_f2 = $_POST['comment_name_f2'] ?? '';
if ($request_sub == 'save')
// Обработка сохранения (и для AJAX 'apply', и для формы 'save')
if ($request_sub == 'save' || $request_sub == 'apply')
{
$max_chars = (empty($post_max_chars) || $post_max_chars < 50) ? 50 : $post_max_chars;
$clean_name_f1 = htmlspecialchars(stripslashes($post_name_f1), ENT_QUOTES);
$clean_name_f2 = htmlspecialchars(stripslashes($post_name_f2), ENT_QUOTES);
@@ -1281,8 +1268,8 @@ function commentAdminSettingsEdit($tpl_dir)
UPDATE " . PREFIX . "_module_comments
SET
comment_max_chars = '" . (int)$max_chars . "',
comment_user_groups = '" . implode(',', $post_user_groups) . "',
comment_user_groups_read = '" . implode(',', $post_user_groups_read) . "',
comment_user_groups = '" . addslashes(implode(',', $post_user_groups)) . "',
comment_user_groups_read = '" . addslashes(implode(',', $post_user_groups_read)) . "',
comment_need_approve = '" . (int)$post_need_approve . "',
comment_active = '" . (int)$post_active . "',
comment_use_antispam = '" . (int)$post_use_antispam . "',
@@ -1296,23 +1283,36 @@ function commentAdminSettingsEdit($tpl_dir)
comment_rating_anon_set = '" . (int)$post_rating_anon_set . "',
comment_show_f1 = '" . (int)$post_show_f1 . "',
comment_req_f1 = '" . (int)$post_req_f1 . "',
comment_name_f1 = '" . $clean_name_f1 . "',
comment_name_f1 = '" . addslashes($clean_name_f1) . "',
comment_show_f2 = '" . (int)$post_show_f2 . "',
comment_req_f2 = '" . (int)$post_req_f2 . "',
comment_name_f2 = '" . $clean_name_f2 . "'
comment_name_f2 = '" . addslashes($clean_name_f2) . "'
WHERE
Id = 1
");
// Если это AJAX запрос "Применить"
if ($request_sub == 'apply') {
@ob_clean();
echo "success";
exit;
}
// Если это обычное "Сохранить" - уходим на главную модулей
if ($request_sub == 'save') {
header("Location: index.php?do=modules&cp=" . $sess);
exit;
}
}
$row = $this->_commentSettingsGet();
$row['comment_user_groups'] = explode(',', $row['comment_user_groups']);
$row['comment_user_groups_read'] = explode(',', $row['comment_user_groups_read']);
$AVE_Template->assign($row);
$AVE_Template->assign('content', $AVE_Template->fetch($tpl_dir . $this->_admin_settings_tpl));
}
}
?>

View File

@@ -23,7 +23,7 @@
<div class="num"><a class="basicNum" href="index.php?do=modules&action=modedit&mod=comment&moduleaction=1&cp={$sess}">{#COMMENT_MODULE_COMENTS#}</a></div>
</div>
<form action="index.php?do=modules&action=modedit&mod=comment&moduleaction=settings&cp={$sess}&sub=save" method="post" class="mainForm">
<form id="commentSettingsForm" action="index.php?do=modules&action=modedit&mod=comment&moduleaction=settings&cp={$sess}&sub=save" method="post" class="mainForm">
<table cellpadding="0" cellspacing="0" width="100%" class="tableStatic">
<thead>
<tr>
@@ -183,10 +183,70 @@
<tr>
<td colspan="4" class="submitArea">
<input type="submit" value="{#COMMENT_BUTTON_SAVE#}" class="basicBtn" style="float: left; margin: 10px;" />
<div class="rowElem" style="border:none; padding: 10px;">
<div class="saveBtn" style="float: left; width: 100%;">
<input type="submit" class="basicBtn" value="{#COMMENT_BUTTON_SAVE#}" style="margin-right: 5px;" />
<span style="margin: 0 5px;">или</span>
<input type="button" id="apply_comment_settings" class="blackBtn" value="Применить" style="margin-left: 5px;" />
<a class="button redBtn" href="index.php?do=modules&cp={$sess}" style="float:right; height: 18px; padding: 0 10px; line-height: 18px;">Отменить</a>
</div>
</div>
<div class="fix"></div>
</td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
// Выносим логику сохранения в отдельную функцию, чтобы вызывать её и по клику, и по кнопкам
function saveCommentSettings() {
var form = $("#commentSettingsForm");
var formData = form.serialize();
var actionUrl = form.attr("action").replace("sub=save", "sub=apply");
$.ajax({
type: "POST",
url: actionUrl,
data: formData,
beforeSend: function() {
$("#apply_comment_settings").val("Сохранение...").attr("disabled", true);
},
success: function (data) {
if (data.trim() === "success") {
$.jGrowl("Настройки модуля успешно обновлены (Ctrl+S)", { theme: "accept", life: 3000 });
} else {
$.jGrowl("Ошибка: " + data, { theme: "error", life: 5000 });
}
},
error: function () {
$.jGrowl("Ошибка связи с сервером", { theme: "error" });
},
complete: function() {
$("#apply_comment_settings").val("Применить").attr("disabled", false);
}
});
}
// 1. Обработка клика по кнопке "Применить"
$(document).on("click", "#apply_comment_settings", function () {
saveCommentSettings();
return false;
});
// 2. Обработка Ctrl + S (или Cmd + S на Mac)
$(document).keydown(function(e) {
// Проверяем: нажата S (код 83) + Ctrl (или Meta для Mac)
if ((e.ctrlKey || e.metaKey) && e.which === 83) {
e.preventDefault(); // Отменяем стандартное сохранение страницы браузером
saveCommentSettings();
return false;
}
});
});
</script>