diff --git a/class/comment.php b/class/comment.php index 70034bf..5645791 100644 --- a/class/comment.php +++ b/class/comment.php @@ -1341,37 +1341,62 @@ function commentAdminListShow($tpl_dir) $action = $_REQUEST['admin_action'] ?? ''; $items = []; - // Собираем ID из разных источников для универсальности if (!empty($_REQUEST['ids'])) { - // Если пришли ID через запятую (массово) $items = explode(',', $_REQUEST['ids']); } elseif (!empty($_REQUEST['id'])) { - // Если пришел один ID (иконка) $items = (is_array($_REQUEST['id'])) ? $_REQUEST['id'] : [$_REQUEST['id']]; } if (!empty($action) && !empty($items)) { $ids = array_map('intval', $items); - $id_list = implode(',', $ids); + + // --- СОБИРАЕМ ВСЕ ID ПОТОМКОВ (ЛЮБАЯ ГЛУБИНА) --- + $all_ids_to_process = $ids; + $current_parents = $ids; + + while (!empty($current_parents)) { + $parent_list = implode(',', $current_parents); + + // Получаем результат запроса + $res = $AVE_DB->Query("SELECT Id FROM " . PREFIX . "_module_comment_info WHERE parent_id IN ($parent_list)"); + + $found_children = []; + // Перебираем результат построчно через стандартный FetchAssocArray + if ($res) { + while ($row_child = $res->FetchAssocArray()) { + $found_children[] = (int)$row_child['Id']; + } + } + + if (!empty($found_children)) { + $all_ids_to_process = array_merge($all_ids_to_process, $found_children); + $current_parents = $found_children; + } else { + $current_parents = []; + } + } + $all_ids_to_process = array_unique($all_ids_to_process); + $final_id_list = implode(',', $all_ids_to_process); + // ------------------------------------------------ switch ($action) { case 'approve': case 'set_status_1': - $AVE_DB->Query("UPDATE " . PREFIX . "_module_comment_info SET comment_status = '1' WHERE Id IN ($id_list)"); + $AVE_DB->Query("UPDATE " . PREFIX . "_module_comment_info SET comment_status = '1' WHERE Id IN ($final_id_list)"); break; case 'unapprove': case 'set_status_0': - $AVE_DB->Query("UPDATE " . PREFIX . "_module_comment_info SET comment_status = '0' WHERE Id IN ($id_list)"); + $AVE_DB->Query("UPDATE " . PREFIX . "_module_comment_info SET comment_status = '0' WHERE Id IN ($final_id_list)"); break; case 'delete': - $AVE_DB->Query("DELETE FROM " . PREFIX . "_module_comment_info WHERE Id IN ($id_list)"); + $AVE_DB->Query("DELETE FROM " . PREFIX . "_module_comment_info WHERE Id IN ($final_id_list)"); break; } header("Location: index.php?do=modules&action=modedit&mod=comment&moduleaction=1&cp=" . $session_id); exit; } - // --- ОРИГИНАЛЬНАЯ ЛОГИКА ВЫВОДА --- + // --- ЛОГИКА ВЫВОДА (С ПАГИНАЦИЕЙ) --- $num = $AVE_DB->Query("SELECT COUNT(*) FROM " . PREFIX . "_module_comment_info")->GetCell(); $limit = $this->_limit; $seiten = ceil($num / $limit); @@ -1385,7 +1410,7 @@ function commentAdminListShow($tpl_dir) LIMIT " . (int)$start . "," . (int)$limit ); - $docs = array(); + $all_items = array(); $format = "%d %B %Y, %H:%M"; while ($row = $sql->FetchAssocArray()) { @@ -1400,36 +1425,25 @@ function commentAdminListShow($tpl_dir) $row['avatar_color_index'] = (abs(crc32($name)) % 12) + 1; } - // --- ОБРАБОТКА ФАЙЛОВ ДЛЯ АДМИНКИ --- - $row['images'] = []; - $row['files'] = []; - if (!empty($row['comment_file'])) { - $img_exts = ['jpg', 'jpeg', 'png', 'gif', 'webp']; - $all_files = explode(',', $row['comment_file']); - - foreach ($all_files as $f_name) { - $f_name = trim($f_name); - if (!$f_name) continue; - - $ext = strtolower(pathinfo($f_name, PATHINFO_EXTENSION)); - - // Чистим имя (убираем временную метку _12345678) - $clean_name = preg_replace('/_[0-9]+(?=\.[a-z0-9]+$)/i', '', $f_name); - - $file_data = [ - 'orig_name' => $f_name, - 'clean_name' => $clean_name, - 'ext' => $ext - ]; - - if (in_array($ext, $img_exts)) { - $row['images'][] = $file_data; - } else { - $row['files'][] = $file_data; + // ОБРАБОТКА ФАЙЛОВ + $row['images'] = []; + $row['files'] = []; + if (!empty($row['comment_file'])) { + $img_exts = ['jpg', 'jpeg', 'png', 'gif', 'webp']; + $all_files = explode(',', $row['comment_file']); + foreach ($all_files as $f_name) { + $f_name = trim($f_name); + if (!$f_name) continue; + $ext = strtolower(pathinfo($f_name, PATHINFO_EXTENSION)); + $clean_name = preg_replace('/_[0-9]+(?=\.[a-z0-9]+$)/i', '', $f_name); + $file_data = ['orig_name' => $f_name, 'clean_name' => $clean_name, 'ext' => $ext]; + if (in_array($ext, $img_exts)) { + $row['images'][] = $file_data; + } else { + $row['files'][] = $file_data; + } } } - } - // ------------------------------------ $row['CId'] = $row['Id']; $row['comment_text'] = stripslashes($row['comment_text']); @@ -1443,7 +1457,47 @@ function commentAdminListShow($tpl_dir) $row['r_count'] = (int)($row['rating_count'] ?? 0); $row['star_public'] = ($row['r_count'] > 0) ? round($row['rating_sum'] / $row['r_count']) : 0; - $docs[] = $row; + $all_items[$row['Id']] = $row; + } + + // --- ПОСТРОЕНИЕ ДЕРЕВА --- + $child_map = []; + foreach ($all_items as $id => $item) { + $p_id = (int)$item['parent_id']; + if ($p_id > 0) $child_map[$p_id][] = $id; + } + + $docs = []; + $processed = []; + + $buildTree = function($parent_id, $level) use (&$buildTree, &$docs, &$processed, &$all_items, &$child_map) { + if (isset($child_map[$parent_id])) { + foreach ($child_map[$parent_id] as $child_id) { + if (!in_array($child_id, $processed)) { + $item = $all_items[$child_id]; + $item['depth_level'] = $level; + $docs[] = $item; + $processed[] = $child_id; + $buildTree($child_id, $level + 1); + } + } + } + }; + + foreach ($all_items as $id => $item) { + if ($item['parent_id'] == 0 && !in_array($id, $processed)) { + $item['depth_level'] = 0; + $docs[] = $item; + $processed[] = $id; + $buildTree($id, 1); + } + } + + foreach ($all_items as $id => $item) { + if (!in_array($id, $processed)) { + $item['depth_level'] = 0; + $docs[] = $item; + } } $AVE_Template->assign([ diff --git a/templates/admin_comments.tpl b/templates/admin_comments.tpl index dabcb14..0c3d4a8 100644 --- a/templates/admin_comments.tpl +++ b/templates/admin_comments.tpl @@ -1,69 +1,73 @@
| - | ID | -Данные Автора | ++ | ID | +Данные Автора | Текст комментария и файлы |
| {$row.CId} | -- |