38916-vm/admin.php
Flatlogic Bot fd8a2de90a z
2026-03-01 18:23:38 +00:00

96 lines
5.0 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require_once __DIR__ . '/auth.php';
$user = requireRole('curator');
$users = db()->query("SELECT * FROM users ORDER BY created_at DESC")->fetchAll();
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
if ($_POST['action'] === 'change_role') {
$stmt = db()->prepare("UPDATE users SET role = ? WHERE id = ?");
$stmt->execute([$_POST['role'], $_POST['user_id']]);
} elseif ($_POST['action'] === 'toggle_status') {
$newStatus = $_POST['status'] === 'active' ? 'blocked' : 'active';
$stmt = db()->prepare("UPDATE users SET status = ? WHERE id = ?");
$stmt->execute([$newStatus, $_POST['user_id']]);
}
header('Location: admin.php');
exit;
}
?>
<!doctype html>
<html lang="ru">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Админ-панель - Система поддержки</title>
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
</head>
<body>
<div class="bg-animations">
<div class="blob blob-1"></div>
<div class="blob blob-2"></div>
<div class="blob blob-3"></div>
</div>
<div class="main-wrapper">
<nav class="navbar">
<a href="index.php" class="logo" style="text-decoration: none;">SupportSystem</a>
<div class="user-info">
<span><?= htmlspecialchars($user['username']) ?> (<?= $user['role'] ?>)</span>
<a href="logout.php" class="logout-link">Выйти</a>
</div>
</nav>
<h1>Управление пользователями</h1>
<div style="background-color: var(--card-bg); border-radius: 1rem; border: 1px solid var(--border-color); overflow-x: auto; margin-top: 2rem;">
<table style="width: 100%; border-collapse: collapse;">
<thead>
<tr style="border-bottom: 1px solid var(--border-color);">
<th style="padding: 1rem; text-align: left;">ID</th>
<th style="padding: 1rem; text-align: left;">Имя</th>
<th style="padding: 1rem; text-align: left;">Роль</th>
<th style="padding: 1rem; text-align: left;">Статус</th>
<th style="padding: 1rem; text-align: left;">Дата рег.</th>
<th style="padding: 1rem; text-align: left;">Действия</th>
</tr>
</thead>
<tbody>
<?php foreach ($users as $u): ?>
<tr style="border-bottom: 1px solid var(--border-color);">
<td style="padding: 1rem;"><?= $u['id'] ?></td>
<td style="padding: 1rem;"><?= htmlspecialchars($u['username']) ?></td>
<td style="padding: 1rem;">
<form method="POST" style="display: flex; gap: 0.5rem; align-items: center;">
<input type="hidden" name="user_id" value="<?= $u['id'] ?>">
<input type="hidden" name="action" value="change_role">
<select name="role" onchange="this.form.submit()" style="padding: 0.25rem 0.5rem;">
<option value="user" <?= $u['role'] === 'user' ? 'selected' : '' ?>>Пользователь</option>
<option value="helper" <?= $u['role'] === 'helper' ? 'selected' : '' ?>>Помощник</option>
<option value="curator" <?= $u['role'] === 'curator' ? 'selected' : '' ?>>Куратор</option>
</select>
</form>
</td>
<td style="padding: 1rem;"><?= $u['status'] ?></td>
<td style="padding: 1rem;"><?= date('d.m.Y', strtotime($u['created_at'])) ?></td>
<td style="padding: 1rem;">
<?php if ($u['id'] != $user['id']): ?>
<form method="POST">
<input type="hidden" name="user_id" value="<?= $u['id'] ?>">
<input type="hidden" name="action" value="toggle_status">
<input type="hidden" name="status" value="<?= $u['status'] ?>">
<button type="submit" class="btn-primary" style="width: auto; padding: 0.25rem 0.75rem; background-color: <?= $u['status'] === 'active' ? 'var(--error)' : 'var(--success)' ?>;">
<?= $u['status'] === 'active' ? 'Блокировать' : 'Разблокировать' ?>
</button>
</form>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</body>
</html>