| Current Path : /home/seto/888mirror.pm/admin/ |
| Current File : /home/seto/888mirror.pm/admin/landings.php |
<?php
require_once __DIR__ . '/../includes/auth.php';
require_once __DIR__ . '/../includes/helpers.php';
auth_check();
$msg = $_GET['msg'] ?? '';
if (isset($_GET['delete'])) {
$del_id = (int)$_GET['delete'];
db()->prepare("DELETE FROM landings WHERE id=?")->execute([$del_id]);
header('Location: /admin/landings.php?msg=' . urlencode('Лендинг удалён'));
exit();
}
// Статистика за 30 дней
$since = date('Y-m-d H:i:s', strtotime('-30 days'));
$stats_raw = db()->query("
SELECT landing_id,
SUM(CASE WHEN event_type='impression' THEN 1 ELSE 0 END) as imp,
SUM(CASE WHEN event_type='click' THEN 1 ELSE 0 END) as clk
FROM stats
WHERE created_at >= '$since' AND landing_id IS NOT NULL
GROUP BY landing_id
")->fetchAll();
$stats = array_column($stats_raw, null, 'landing_id');
$landings = db()->query("SELECT * FROM landings ORDER BY created_at DESC")->fetchAll();
$templates_labels = [
'dark-premium' => 'Dark Premium',
'light-minimal' => 'Light Minimal',
'neon' => 'Neon Contrast',
'classic' => 'Classic Casino',
'table-dark' => 'Table Dark',
'table-light' => 'Table Light',
'row-dark' => 'Row Dark',
'row-light' => 'Row Light',
];
$status_badges = [
'active' => 'success',
'inactive' => 'secondary',
'draft' => 'warning',
'archived' => 'dark',
];
?>
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Landings — 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('landings') ?>
<div class="container-fluid px-4" style="max-width:1100px">
<div class="d-flex justify-content-between align-items-center mb-3">
<h5 class="mb-0">Landings</h5>
<a href="/admin/landing_edit.php" class="btn btn-primary btn-sm"><i class="bi bi-plus-lg me-1"></i>Новый</a>
</div>
<?php if ($msg): ?>
<div class="alert alert-success py-2"><?= h($msg) ?></div>
<?php endif ?>
<?php if (empty($landings)): ?>
<div class="text-muted text-center py-5">Нет лендингов. <a href="/admin/landing_edit.php">Создать первый</a></div>
<?php else: ?>
<div class="card shadow-sm">
<div class="table-responsive">
<table class="table table-hover table-sm mb-0">
<thead class="table-light">
<tr>
<th>Название / slug</th>
<th>Статус</th>
<th>Шаблон</th>
<th class="text-center">Показы (30д)</th>
<th class="text-center">Клики (30д)</th>
<th class="text-center">CTR</th>
<th class="text-end">Действия</th>
</tr>
</thead>
<tbody>
<?php foreach ($landings as $l):
$st = $stats[$l['id']] ?? [];
$imp = (int)($st['imp'] ?? 0);
$clk = (int)($st['clk'] ?? 0);
$ctr = $imp > 0 ? round($clk / $imp * 100, 1) . '%' : '—';
$badge = $status_badges[$l['status']] ?? 'secondary';
?>
<tr>
<td>
<div class="fw-semibold"><?= h($l['name']) ?></div>
<small class="text-muted">
<a href="/<?= h($l['slug']) ?>" target="_blank" class="text-decoration-none">/<?= h($l['slug']) ?></a>
</small>
</td>
<td><span class="badge bg-<?= $badge ?>"><?= h($l['status']) ?></span></td>
<td><small><?= h($templates_labels[$l['template']] ?? $l['template']) ?></small></td>
<td class="text-center"><?= number_format($imp) ?></td>
<td class="text-center"><?= number_format($clk) ?></td>
<td class="text-center"><?= $ctr ?></td>
<td class="text-end">
<div class="d-flex gap-1 justify-content-end flex-wrap">
<a href="/<?= h($l['slug']) ?>?preview=1" target="_blank"
class="btn btn-outline-secondary btn-sm" title="Превью"><i class="bi bi-eye"></i></a>
<a href="/admin/landing_stats.php?id=<?= $l['id'] ?>"
class="btn btn-outline-info btn-sm" title="Статистика"><i class="bi bi-bar-chart-line"></i></a>
<a href="/admin/landing_edit.php?id=<?= $l['id'] ?>"
class="btn btn-outline-primary btn-sm" title="Редактировать"><i class="bi bi-pencil"></i></a>
<a href="/admin/landing_edit.php?clone=<?= $l['id'] ?>"
class="btn btn-outline-success btn-sm" title="Дублировать"><i class="bi bi-copy"></i></a>
<a href="/admin/landings.php?delete=<?= $l['id'] ?>"
class="btn btn-outline-danger btn-sm" title="Удалить"
onclick="return confirm('Удалить лендинг «<?= h(addslashes($l['name'])) ?>»?')"><i class="bi bi-trash3"></i></a>
</div>
</td>
</tr>
<?php endforeach ?>
</tbody>
</table>
</div>
</div>
<?php endif ?>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>