| Current Path : /home/seto/888mirror.pm/admin/ |
| Current File : /home/seto/888mirror.pm/admin/brands.php |
<?php
require_once __DIR__ . '/../includes/auth.php';
require_once __DIR__ . '/../includes/helpers.php';
auth_check();
$brands = db()->query("
SELECT b.*,
COUNT(bc.country_code) as country_count,
MAX(CASE WHEN bc.country_code = 'en' THEN 1 ELSE 0 END) as has_global,
MAX(CASE WHEN bc.country_code = 'crypto' THEN 1 ELSE 0 END) as has_crypto
FROM brands b
LEFT JOIN brand_countries bc ON bc.brand_id = b.id
GROUP BY b.id
ORDER BY b.is_featured DESC, b.weight DESC, b.id DESC
")->fetchAll();
$total_langs = (int)db()->query("SELECT COUNT(*) FROM languages WHERE is_active = 1")->fetchColumn();
$partners_map = array_column(
db()->query("SELECT id, name, affiliate_url FROM partners")->fetchAll(),
null, 'id'
);
$lang_fill_raw = db()->query("
SELECT brand_id, COUNT(*) as filled
FROM brand_translations
WHERE bonus != '' AND bonus IS NOT NULL
GROUP BY brand_id
")->fetchAll();
$lang_fill = array_column($lang_fill_raw, 'filled', 'brand_id');
$status_labels = ['active' => 'Активен', 'inactive' => 'Неактивен', 'draft' => 'Черновик'];
$status_badge = ['active' => 'success', 'inactive' => 'secondary', 'draft' => 'warning'];
?>
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Бренды — Admin</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css" rel="stylesheet">
</head>
<body>
<?= admin_nav('brands') ?>
<div class="container-fluid px-4">
<div class="d-flex justify-content-between align-items-center mb-3">
<h4 class="mb-0">Бренды <span class="text-muted fw-normal fs-6">(<?= count($brands) ?>)</span></h4>
<a href="/admin/brand_edit.php" class="btn btn-primary btn-sm">+ Добавить бренд</a>
</div>
<?php if (isset($_GET['msg'])): ?>
<div class="alert alert-success alert-dismissible fade show py-2">
<?= h($_GET['msg']) ?>
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php endif ?>
<div class="table-responsive">
<table class="table table-hover align-middle">
<thead class="table-light">
<tr>
<th style="width:60px">Лого</th>
<th>Название</th>
<th>Вес</th>
<th>GEO</th>
<th>Языки</th>
<th>Badge</th>
<th>Статус</th>
<th>Featured</th>
<th style="width:60px" class="text-center">Global</th>
<th style="width:60px" class="text-center">Crypto</th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach ($brands as $b): ?>
<tr>
<td>
<?php if ($b['logo']): ?>
<img src="<?= h($b['logo']) ?>" style="height:32px;max-width:60px;object-fit:contain">
<?php else: ?>
<span class="text-muted">—</span>
<?php endif ?>
</td>
<td>
<strong><?= h($b['name']) ?></strong>
<?php if (!empty($b['partner_id']) && !empty($partners_map[$b['partner_id']])): ?>
<?php $pp = $partners_map[$b['partner_id']]; ?>
<i class="bi bi-briefcase-fill text-success ms-1"
data-bs-toggle="tooltip"
title="ПП: <?= h($pp['name']) ?><?= $pp['affiliate_url'] ? ' · ' . h(preg_replace('#^https?://#','',$pp['affiliate_url'])) : '' ?>"
style="font-size:.85rem"></i>
<?php if ($pp['affiliate_url']): ?>
<a href="<?= h($pp['affiliate_url']) ?>" target="_blank" rel="noopener"
class="ms-1 text-muted" style="font-size:.85rem; text-decoration:none">
<i class="bi bi-box-arrow-up-right"></i>
</a>
<?php endif ?>
<?php endif ?>
</td>
<td><?= (int)$b['weight'] ?></td>
<td><span class="badge bg-light text-dark"><?= (int)$b['country_count'] ?> стран</span></td>
<td style="min-width:110px">
<?php
$filled = (int)($lang_fill[$b['id']] ?? 0);
$pct = $total_langs > 0 ? round($filled / $total_langs * 100) : 0;
$color = $pct >= 80 ? 'success' : ($pct >= 30 ? 'warning' : 'danger');
?>
<div class="progress" style="height:8px" title="<?= $filled ?>/<?= $total_langs ?> языков заполнено">
<div class="progress-bar bg-<?= $color ?>" style="width:<?= $pct ?>%"></div>
</div>
<small class="text-muted"><?= $filled ?>/<?= $total_langs ?></small>
</td>
<td>
<?php if ($b['badge']): ?>
<span class="badge <?= badge_class($b['badge']) ?>"><?= badge_label($b['badge']) ?></span>
<?php else: ?>—<?php endif ?>
</td>
<td>
<span class="badge bg-<?= $status_badge[$b['status']] ?? 'secondary' ?>">
<?= $status_labels[$b['status']] ?? $b['status'] ?>
</span>
</td>
<td><?= $b['is_featured'] ? '⭐' : '' ?></td>
<td class="text-center"><?= $b['has_global'] ? '🌐' : '' ?></td>
<td class="text-center"><?= $b['has_crypto'] ? '💎' : '' ?></td>
<td class="text-end text-nowrap">
<a href="/admin/translations.php?brand_id=<?= $b['id'] ?>" class="btn btn-sm btn-outline-info" title="Переводы">
<span class="d-none d-md-inline">Переводы</span><span class="d-md-none">🌐</span>
</a>
<a href="/admin/brand_edit.php?id=<?= $b['id'] ?>" class="btn btn-sm btn-outline-secondary" title="Редактировать">
<span class="d-none d-md-inline">Ред.</span><span class="d-md-none">✏️</span>
</a>
<a href="/admin/brand_delete.php?id=<?= $b['id'] ?>"
class="btn btn-sm btn-outline-danger" title="Удалить"
onclick="return confirm('Удалить бренд <?= h(addslashes($b['name'])) ?>?')">
<span class="d-none d-md-inline">Удалить</span><span class="d-md-none">🗑</span>
</a>
</td>
</tr>
<?php endforeach ?>
<?php if (empty($brands)): ?>
<tr><td colspan="11" class="text-center text-muted py-4">Брендов пока нет. <a href="/admin/brand_edit.php">Добавить</a></td></tr>
<?php endif ?>
</tbody>
</table>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
document.querySelectorAll('[data-bs-toggle="tooltip"]').forEach(function(el) {
new bootstrap.Tooltip(el);
});
</script>
</body>
</html>