34988-vm/admin.php
2025-10-15 18:14:20 +00:00

90 lines
3.2 KiB
PHP

<?php
require_once 'session.php';
require_once 'db/config.php';
$surveys = [];
try {
$pdo = db();
$stmt = $pdo->query("SELECT id, title, created_at FROM surveys ORDER BY created_at DESC");
$surveys = $stmt->fetchAll();
} catch (PDOException $e) {
// Handle error properly in a real app
error_log("Database error: " . $e->getMessage());
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<a class="navbar-brand" href="admin.php">Admin Panel</a>
<div class="collapse navbar-collapse">
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="create_survey.php">Create Survey</a>
</li>
<li class="nav-item">
<a class="nav-link" href="logout.php">Logout</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container mt-5">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1>Survey Dashboard</h1>
<a href="create_survey.php" class="btn btn-primary">Create New Survey</a>
</div>
<div class="card">
<div class="card-header">
Existing Surveys
</div>
<div class="card-body">
<table class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>Title</th>
<th>Created At</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($surveys)): ?>
<tr>
<td colspan="4" class="text-center">No surveys found.</td>
</tr>
<?php else: ?>
<?php foreach ($surveys as $survey): ?>
<tr>
<td><?php echo htmlspecialchars($survey['id']); ?></td>
<td><?php echo htmlspecialchars($survey['title']); ?></td>
<td><?php echo htmlspecialchars($survey['created_at']); ?></td>
<td>
<a href="view_survey.php?id=<?php echo $survey['id']; ?>" class="btn btn-sm btn-info">View</a>
<a href="view_responses.php?survey_id=<?php echo $survey['id']; ?>" class="btn btn-sm btn-secondary">View Responses</a>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>