+++ правки для редактирования комментария в админке
This commit is contained in:
@@ -111,7 +111,7 @@ class Comment
|
||||
/**
|
||||
* Редактирование Авторской оценки (1-разрешено, 0-запрещено)
|
||||
*/
|
||||
private $_edit_avtor_rating = 1;
|
||||
private $_edit_avtor_rating = 0;
|
||||
|
||||
/**
|
||||
* Конструктор класса
|
||||
@@ -1750,16 +1750,6 @@ $AVE_Template->assign([
|
||||
$AVE_Template->assign('content', $AVE_Template->fetch($tpl_dir . $this->_admin_comments_tpl));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Метод, предназначенный для редактирования комментариев в Административной части.
|
||||
*
|
||||
@@ -1773,22 +1763,24 @@ function commentAdminPostEdit($tpl_dir)
|
||||
$request_id = (int)($_REQUEST['Id'] ?? 0);
|
||||
$is_ajax = isset($_REQUEST['ajax']);
|
||||
|
||||
// 1. Получаем данные и настройки одним запросом
|
||||
$row = $AVE_DB->Query("
|
||||
SELECT
|
||||
msg.*,
|
||||
cmnt.comment_allowed_extensions,
|
||||
cmnt.comment_max_file_size,
|
||||
cmnt.comment_max_files,
|
||||
cmnt.comment_allow_files,
|
||||
cmnt.comment_show_f1,
|
||||
cmnt.comment_show_f2,
|
||||
cmnt.comment_show_user_rating
|
||||
FROM " . PREFIX . "_module_comment_info AS msg
|
||||
JOIN " . PREFIX . "_module_comments AS cmnt ON cmnt.Id = 1
|
||||
WHERE msg.Id = '" . (int)$request_id . "'
|
||||
LIMIT 1
|
||||
")->FetchAssocArray();
|
||||
// 1. Получаем данные и настройки одним запросом
|
||||
$row = $AVE_DB->Query("
|
||||
SELECT
|
||||
msg.*,
|
||||
cmnt.comment_allowed_extensions,
|
||||
cmnt.comment_max_file_size,
|
||||
cmnt.comment_max_files,
|
||||
cmnt.comment_allow_files,
|
||||
cmnt.comment_show_f1,
|
||||
cmnt.comment_show_f2,
|
||||
cmnt.comment_name_f1,
|
||||
cmnt.comment_name_f2,
|
||||
cmnt.comment_show_user_rating
|
||||
FROM " . PREFIX . "_module_comment_info AS msg
|
||||
JOIN " . PREFIX . "_module_comments AS cmnt ON cmnt.Id = 1
|
||||
WHERE msg.Id = '" . (int)$request_id . "'
|
||||
LIMIT 1
|
||||
")->FetchAssocArray();
|
||||
|
||||
if ($post_sub == 'send' && $row)
|
||||
{
|
||||
@@ -1806,12 +1798,11 @@ function commentAdminPostEdit($tpl_dir)
|
||||
if (file_exists($upload_dir . $rem_file)) {
|
||||
@unlink($upload_dir . $rem_file);
|
||||
}
|
||||
// Используем стрелочную функцию (PHP 7.4+)
|
||||
$current_files = array_filter($current_files, fn($v) => trim($v) !== $rem_file);
|
||||
}
|
||||
}
|
||||
|
||||
// --- Б. Загрузка новых файлов ---
|
||||
// Загрузка новых файлов ---
|
||||
if ($row['comment_allow_files'] == 1 && isset($_FILES['comment_image']) && is_array($_FILES['comment_image']['name'])) {
|
||||
|
||||
if (!is_dir($upload_dir)) {
|
||||
@@ -1828,7 +1819,7 @@ function commentAdminPostEdit($tpl_dir)
|
||||
|
||||
foreach ($_FILES['comment_image']['name'] as $k => $fname) {
|
||||
if ($_FILES['comment_image']['error'][$k] == UPLOAD_ERR_OK) {
|
||||
// Важно: проверяем лимит на каждой итерации
|
||||
// проверяем лимит на каждой итерации
|
||||
if (count($current_files) >= $max_limit) break;
|
||||
|
||||
$tmp_name = $_FILES['comment_image']['tmp_name'][$k];
|
||||
@@ -1859,7 +1850,7 @@ function commentAdminPostEdit($tpl_dir)
|
||||
// Финальная строка файлов для базы
|
||||
$final_files_str = implode(',', array_unique(array_filter($current_files)));
|
||||
|
||||
// --- В. Рейтинг ---
|
||||
// --- Рейтинг ---
|
||||
$new_rating = ($this->_edit_avtor_rating == 1 && isset($_POST['user_rating']))
|
||||
? (int)$_POST['user_rating']
|
||||
: (int)($row['user_rating'] ?? 0);
|
||||
@@ -1906,14 +1897,6 @@ function commentAdminPostEdit($tpl_dir)
|
||||
$AVE_Template->assign('content', $AVE_Template->fetch($tpl_dir . $this->_admin_edit_link_tpl));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Метод, предназначенный для управления настройками модуля
|
||||
*
|
||||
|
||||
@@ -254,3 +254,5 @@ COMMENT_TABLE_TEXT_COMM = "Текст комментария"
|
||||
COMMENT_TABLE_FILES = "Файлы"
|
||||
COMMENT_TABLE_ACTIONS = "Действия"
|
||||
COMMENT_RATING_ADMIN = "Рейтинг комментариев"
|
||||
COMMENT_RATING_TITEL = "Авторская оценка"
|
||||
COMMENT_RATING_RESET = "Сбросить"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script type="text/javascript" language="JavaScript">
|
||||
{literal}
|
||||
$(document).ready(function(){
|
||||
// 1. Инициализация параметров из Smarty
|
||||
// Инициализация параметров из Smarty
|
||||
var maxFiles = {/literal}{$row.comment_max_files|default:5}{literal};
|
||||
var maxFileSize = {/literal}{$row.comment_max_file_size|default:2048}{literal} * 1024;
|
||||
var allowedExts = {/literal}'{$row.comment_allowed_extensions|default:"jpg,jpeg,png,gif,webp,zip,txt"}'{literal}.split(',');
|
||||
@@ -10,41 +10,93 @@ $(document).ready(function(){
|
||||
var left = {/literal}{$comment_max_chars|default:1000}{literal};
|
||||
$('#text_counter').text(left);
|
||||
|
||||
// 2. Счетчик символов в текстовом поле
|
||||
// Счетчик символов в текстовом поле
|
||||
$('#in_message').on('keyup change', function () {
|
||||
left = {/literal}{$comment_max_chars|default:1000}{literal} - $(this).val().length;
|
||||
$('#text_counter').toggleClass("overlimit", left < 0).text(left);
|
||||
});
|
||||
|
||||
// 3. Проверки файлов "на лету" при выборе
|
||||
// Универсальная функция для вывода предупреждений в админке
|
||||
function showFileAlert(message, $container) {
|
||||
$container.find('.file-limit-alert').remove(); // Удаляем старые, если есть
|
||||
|
||||
var alertHtml = `
|
||||
<div class="file-limit-alert alert alert-warning py-1 px-2 mb-2 small d-flex align-items-center border-0 shadow-sm"
|
||||
style="background: #fff3cd; color: #856404; border-left: 4px solid #ffeeba !important; margin-bottom: 10px; position: relative;">
|
||||
<i class="bi bi-exclamation-triangle-fill me-2"></i>
|
||||
<span>${message}</span>
|
||||
</div>`;
|
||||
|
||||
$container.prepend(alertHtml);
|
||||
|
||||
// Плавное удаление через 5 секунд
|
||||
setTimeout(function() {
|
||||
$container.find('.file-limit-alert').fadeOut(500, function() { $(this).remove(); });
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
// Проверки файлов и генерация превью "на лету"
|
||||
$('input[name="comment_image[]"]').on('change', function() {
|
||||
var $input = $(this);
|
||||
var files = this.files;
|
||||
var $previewContainer = $('#new_images_preview');
|
||||
var $uploadBox = $input.closest('.upload-info-box');
|
||||
|
||||
$previewContainer.empty();
|
||||
|
||||
var deletedCount = $('input[name="delete_files[]"]:checked').length;
|
||||
var currentTotal = existingFilesCount - deletedCount;
|
||||
|
||||
// Проверка общего лимита количества
|
||||
if ((currentTotal + files.length) > maxFiles) {
|
||||
alert("Лимит: " + maxFiles + " шт.");
|
||||
$(this).val('');
|
||||
showFileAlert("Превышен лимит: максимум " + maxFiles + " файлов.", $uploadBox);
|
||||
$input.val('');
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
var file = files[i];
|
||||
// Пофайловая проверка (Формат и Размер)
|
||||
var hasError = false;
|
||||
$.each(files, function(i, file) {
|
||||
var ext = file.name.split('.').pop().toLowerCase();
|
||||
|
||||
if ($.inArray(ext, allowedExts) == -1) {
|
||||
alert("Запрещенный формат: " + ext);
|
||||
$(this).val('');
|
||||
return false;
|
||||
showFileAlert("Формат <b>." + ext + "</b> не разрешен!", $uploadBox);
|
||||
hasError = true;
|
||||
return false; // break loop
|
||||
}
|
||||
|
||||
if (file.size > maxFileSize) {
|
||||
alert("Файл слишком велик: " + (maxFileSize/1024) + " KB");
|
||||
$(this).val('');
|
||||
return false;
|
||||
showFileAlert("Файл слишком большой: " + (file.size/1024).toFixed(1) + " KB", $uploadBox);
|
||||
hasError = true;
|
||||
return false; // break loop
|
||||
}
|
||||
|
||||
// Если ошибок нет, читаем превью (FileReader)
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(e) {
|
||||
var isImg = ['jpg','jpeg','png','gif','webp'].indexOf(ext) !== -1;
|
||||
var content = isImg
|
||||
? '<img src="' + e.target.result + '">'
|
||||
: '<div class="ext-placeholder">' + ext + '</div>';
|
||||
|
||||
var html = `
|
||||
<div class="new-file-preview" title="${file.name}">
|
||||
<div class="cancel-new-file" onclick="resetNewFiles()">×</div>
|
||||
${content}
|
||||
<span class="file-name-label">${file.name}</span>
|
||||
</div>`;
|
||||
$previewContainer.append(html);
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
});
|
||||
|
||||
if (hasError) {
|
||||
$input.val('');
|
||||
$previewContainer.empty();
|
||||
}
|
||||
});
|
||||
|
||||
// 4. Логика Авторского рейтинга (звезды)
|
||||
// Логика Авторского рейтинга (звезды)
|
||||
$('.rating-star').click(function() {
|
||||
var val = $(this).data('value');
|
||||
$('#user_rating_input').val(val);
|
||||
@@ -58,7 +110,7 @@ $(document).ready(function(){
|
||||
$('.rating-star').removeClass('active');
|
||||
});
|
||||
|
||||
// 5. Удаление существующих файлов (клик по крестику)
|
||||
// Удаление существующих файлов (клик по крестику)
|
||||
$('.del-file-btn').on('click', function(e) {
|
||||
e.preventDefault(); // Предотвращаем стандартное поведение
|
||||
var $checkbox = $(this).find('input[type="checkbox"]');
|
||||
@@ -76,7 +128,7 @@ $(document).ready(function(){
|
||||
}
|
||||
});
|
||||
|
||||
// 6. Отправка формы через AJAX с прогресс-баром
|
||||
// Отправка формы через AJAX с прогресс-баром
|
||||
$(".SaveCommentAjax").on('click', function(e){
|
||||
e.preventDefault();
|
||||
var $btn = $(this);
|
||||
@@ -95,10 +147,10 @@ $(document).ready(function(){
|
||||
success: function(data){
|
||||
$.jGrowl(data['message'], { header: data['header'], theme: data['theme'] });
|
||||
if (data['theme'] !== 'error') {
|
||||
// Короткая задержка перед релоадом, чтобы юзер увидел 100% и jGrowl
|
||||
// Короткая задержка перед релоадом, чтобы юзер увидел 100% полосы загрузки и jGrowl
|
||||
setTimeout(function() {
|
||||
if (window.parent) window.parent.location.reload();
|
||||
}, 600);
|
||||
}, 900);
|
||||
} else {
|
||||
$btn.attr('disabled', false);
|
||||
$('#comment-upload-progress').hide();
|
||||
@@ -112,12 +164,18 @@ $(document).ready(function(){
|
||||
});
|
||||
});
|
||||
|
||||
// 7. Закрытие диалогового окна
|
||||
// Закрытие диалогового окна
|
||||
var dialogId = '#ajax-dialog-edit-comment-{/literal}{$smarty.request.Id|escape}{literal}';
|
||||
$(".CloseCommentDialog").on('click', function(e){
|
||||
e.preventDefault();
|
||||
$(dialogId).dialog('destroy').remove();
|
||||
});
|
||||
|
||||
// Функция сброса новых файлов (вызывается крестиком на новом превью)
|
||||
window.resetNewFiles = function() {
|
||||
$('input[name="comment_image[]"]').val('');
|
||||
$('#new_images_preview').empty();
|
||||
};
|
||||
});
|
||||
{/literal}
|
||||
</script>
|
||||
@@ -169,6 +227,36 @@ $(document).ready(function(){
|
||||
|
||||
.upload-info-box { margin-top:10px; padding: 10px; border: 1px dashed #ccc; background: #fcfcfc; }
|
||||
.overlimit { color: #dc3545; font-weight: bold; }
|
||||
|
||||
/* Стили для новых превью */
|
||||
.new-file-preview { position: relative; width: 60px; text-align: center; }
|
||||
.new-file-preview img { width: 60px; height: 60px; object-fit: cover; border-radius: 4px; border: 1px solid #0d6efd; }
|
||||
.new-file-preview .ext-placeholder { background: #0d6efd; } /* Синий цвет для новых файлов */
|
||||
|
||||
/* Кнопка отмены для НОВОГО файла */
|
||||
.cancel-new-file {
|
||||
position: absolute; top: -5px; right: -5px; background: #000; color: #fff;
|
||||
border-radius: 50%; width: 18px; height: 18px; cursor: pointer;
|
||||
line-height: 17px; text-align: center; font-size: 12px; border: 1px solid #fff; z-index: 11;
|
||||
}
|
||||
|
||||
.file-limit-alert {
|
||||
transition: opacity 0.5s ease-in-out;
|
||||
animation: slideDown 0.3s ease-out;
|
||||
border-radius: 4px;
|
||||
font-family: Tahoma, sans-serif;
|
||||
line-height: 1.4;
|
||||
z-index: 5;
|
||||
}
|
||||
.file-limit-alert i {
|
||||
font-style: normal;
|
||||
font-weight: bold;
|
||||
margin-right: 5px;
|
||||
}
|
||||
@keyframes slideDown {
|
||||
from { transform: translateY(-10px); opacity: 0; }
|
||||
to { transform: translateY(0); opacity: 1; }
|
||||
}
|
||||
{/literal}
|
||||
</style>
|
||||
|
||||
@@ -189,19 +277,25 @@ $(document).ready(function(){
|
||||
<td><input name="comment_author_email" type="text" style="width:300px" value="{$row.comment_author_email|stripslashes|escape}" /></td>
|
||||
</tr>
|
||||
|
||||
{if $row.comment_show_f2 == 1}
|
||||
<tr>
|
||||
<td>{#COMMENT_YOUR_SITE#}</td>
|
||||
<td><input name="comment_author_website" type="text" style="width:300px" value="{$row.comment_author_website|stripslashes|escape}" /></td>
|
||||
</tr>
|
||||
{/if}
|
||||
{* Поле F1 - Город *}
|
||||
{if $row.comment_show_f1 == 1}
|
||||
<tr>
|
||||
<td>
|
||||
{if $row.comment_name_f1}{$row.comment_name_f1|stripslashes|escape}{else}{#COMMENT_YOUR_FROM#}{/if}
|
||||
</td>
|
||||
<td><input name="comment_author_city" type="text" style="width:300px" value="{$row.comment_author_city|stripslashes|escape}" /></td>
|
||||
</tr>
|
||||
{/if}
|
||||
|
||||
{if $row.comment_show_f1 == 1}
|
||||
<tr>
|
||||
<td>{#COMMENT_YOUR_FROM#}</td>
|
||||
<td><input name="comment_author_city" type="text" style="width:300px" value="{$row.comment_author_city|stripslashes|escape}" /></td>
|
||||
</tr>
|
||||
{/if}
|
||||
{* Поле F2 - Веб-сайт *}
|
||||
{if $row.comment_show_f2 == 1}
|
||||
<tr>
|
||||
<td>
|
||||
{if $row.comment_name_f2}{$row.comment_name_f2|stripslashes|escape}{else}{#COMMENT_YOUR_SITE#}{/if}
|
||||
</td>
|
||||
<td><input name="comment_author_website" type="text" style="width:300px" value="{$row.comment_author_website|stripslashes|escape}" /></td>
|
||||
</tr>
|
||||
{/if}
|
||||
|
||||
{if $row.comment_show_user_rating == 1}
|
||||
<tr>
|
||||
@@ -212,7 +306,13 @@ $(document).ready(function(){
|
||||
{section name=r start=1 loop=6}
|
||||
<span class="rating-star {if $row.user_rating >= $smarty.section.r.index}active{/if}" data-value="{$smarty.section.r.index}">★</span>
|
||||
{/section}
|
||||
<span class="reset-rating" title="{#COMMENT_RATING_RESET#}">×</span>
|
||||
<span class="reset-rating" title="{#COMMENT_RATING_RESET#}">×</span><span>{#COMMENT_RATING_RESET#}</span>
|
||||
{* Проверка разрешения на редактирование *}
|
||||
{if $edit_rating_enabled == 0}
|
||||
<span style="color: #dc3545; font-size: 11px; margin-left: 15px; font-weight: bold;">
|
||||
(Редактирование Авторской оценки отключено)
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -235,7 +335,8 @@ $(document).ready(function(){
|
||||
</div>
|
||||
{/foreach}
|
||||
</div>
|
||||
|
||||
{* превью новых только что загруженных файлов *}
|
||||
<div id="new_images_preview" style="display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px;"></div>
|
||||
{if $row.comment_allow_files == 1}
|
||||
<div class="upload-info-box">
|
||||
<input type="file" name="comment_image[]" multiple />
|
||||
|
||||
Reference in New Issue
Block a user