This commit is contained in:
kirill.khorkov
2025-12-17 01:24:01 +03:00
parent fe288b3caf
commit f4f57bd153
18 changed files with 4 additions and 115 deletions

View File

@@ -4,7 +4,6 @@ header('Content-Type: application/json; charset=utf-8');
session_start();
require_once __DIR__ . '/../config/database.php';
// Проверка прав администратора
if (!isset($_SESSION['isAdmin']) || !$_SESSION['isAdmin']) {
echo json_encode(['success' => false, 'message' => 'Доступ запрещен']);
exit();
@@ -21,7 +20,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
try {
$db = Database::getInstance()->getConnection();
// Проверяем, есть ли товары в этой категории
$checkStmt = $db->prepare("SELECT COUNT(*) FROM products WHERE category_id = ?");
$checkStmt->execute([$categoryId]);
$productCount = $checkStmt->fetchColumn();
@@ -31,7 +29,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
exit();
}
// Удаляем категорию
$stmt = $db->prepare("DELETE FROM categories WHERE category_id = ?");
$stmt->execute([$categoryId]);

View File

@@ -150,7 +150,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$material = trim($_POST['material'] ?? '');
if ($category_id <= 0) {
$firstCat = $db->query("SELECT category_id FROM categories LIMIT 1")->fetchColumn();
$category_id = $firstCat ?: 1;
}
@@ -192,24 +191,18 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$childCount = $checkChildren->fetchColumn();
if ($productCount > 0) {
$stmt = $db->prepare("UPDATE categories SET is_active = FALSE WHERE category_id = ?");
$stmt->execute([$categoryId]);
header('Location: index.php?action=categories&message=Категория+скрыта+(содержит+товары)');
exit();
} elseif ($childCount > 0) {
$stmt = $db->prepare("UPDATE categories SET is_active = FALSE WHERE category_id = ?");
$stmt->execute([$categoryId]);
header('Location: index.php?action=categories&message=Категория+скрыта+(имеет+дочерние+категории)');
exit();
} else {
$stmt = $db->prepare("DELETE FROM categories WHERE category_id = ?");
$stmt->execute([$categoryId]);
header('Location: index.php?action=categories&message=Категория+удалена');
exit();
}
@@ -224,7 +217,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
}
try {
$stats = [
'total_products' => $db->query("SELECT COUNT(*) FROM products")->fetchColumn(),
'active_products' => $db->query("SELECT COUNT(*) FROM products WHERE is_available = TRUE")->fetchColumn(),
@@ -502,13 +494,11 @@ try {
<td><?= htmlspecialchars($category['name']) ?></td>
<td><?= htmlspecialchars($category['slug']) ?></td>
<td><?= htmlspecialchars($category['parent_name'] ?? '—') ?></td>
<td><?= $category['product_count'] ?></td>
<td><?= $category['product_count'] ?> </td>
<td class="action-buttons">
<a href="index.php?action=edit_category&id=<?= $category['category_id'] ?>" class="btn btn-warning btn-sm">
<i class="fas fa-edit"></i> Редактировать
</a>
<button type="button" class="btn btn-danger btn-sm delete-category-btn"
data-id="<?= $category['category_id'] ?>"
<?= $category['product_count'] > 0 ? 'disabled' : '' ?>>
@@ -752,7 +742,6 @@ try {
<?php endif; ?>
</div>
<script>
$('.delete-category-btn').click(function() {
const categoryId = $(this).data('id');
const btn = $(this);