35591-vm/admin.php
Flatlogic Bot bfa71e661d 2
2025-11-09 09:57:02 +00:00

75 lines
2.8 KiB
PHP

<?php
require_once 'includes/header.php';
require_once 'db/config.php';
// Security check: only admins can access this page
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'admin') {
// You can redirect them to the home page or show an error
header('HTTP/1.0 403 Forbidden');
echo "<h1>403 Forbidden</h1><p>You do not have permission to access this page.</p>";
exit();
}
// Fetch all users for display
try {
$pdo = db();
$stmt = $pdo->query("SELECT id, email, role, subscription_plan, subscription_expires_at, created_at FROM users ORDER BY created_at DESC");
$users = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
$error = "Database error: " . $e->getMessage();
$users = [];
}
?>
<main class="container">
<div class="page-header">
<h1><?= t('admin_panel_title') ?></h1>
<p><?= t('admin_panel_subtitle') ?></p>
</div>
<?php if (!empty($error)): ?>
<div class="alert alert-danger"><?= htmlspecialchars($error) ?></div>
<?php endif; ?>
<div class="card">
<div class="card-header">
<h3><?= t('registered_users') ?></h3>
</div>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th><?= t('email') ?></th>
<th><?= t('role') ?></th>
<th><?= t('subscription_plan') ?></th>
<th><?= t('subscription_expires_at') ?></th>
<th><?= t('registered_on') ?></th>
</tr>
</thead>
<tbody>
<?php if (empty($users)): ?>
<tr>
<td colspan="6" class="text-center"><?= t('no_users_found') ?></td>
</tr>
<?php else: ?>
<?php foreach ($users as $user): ?>
<tr>
<td><?= htmlspecialchars($user['id']) ?></td>
<td><?= htmlspecialchars($user['email']) ?></td>
<td><?= htmlspecialchars($user['role']) ?></td>
<td><?= htmlspecialchars($user['subscription_plan'] ?? 'N/A') ?></td>
<td><?= htmlspecialchars($user['subscription_expires_at'] ?? 'N/A') ?></td>
<td><?= date("Y-m-d", strtotime($user['created_at'])) ?></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</main>
<?php require_once 'includes/footer.php'; ?>