100 lines
4.3 KiB
PHP
100 lines
4.3 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
// Check if user is logged in and is an Admin
|
|
if (!isset($_SESSION['user_id']) || !in_array('Admin', $_SESSION['user_roles'])) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
// If logged in, show the admin content
|
|
require_once 'db/config.php';
|
|
|
|
// Pagination
|
|
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
|
|
$records_per_page = 10;
|
|
$offset = ($page - 1) * $records_per_page;
|
|
|
|
// Get total number of submissions
|
|
$total_stmt = db()->query("SELECT COUNT(*) FROM feedback_submissions");
|
|
$total_records = $total_stmt->fetchColumn();
|
|
$total_pages = ceil($total_records / $records_per_page);
|
|
|
|
// Fetch submissions for the current page
|
|
$submissions_stmt = db()->prepare("SELECT s.id, s.name, s.email, s.created_at, sv.title as survey_title, sv.id as survey_id FROM feedback_submissions s JOIN surveys sv ON s.survey_id = sv.id ORDER BY s.created_at DESC LIMIT :limit OFFSET :offset");
|
|
$submissions_stmt->bindValue(':limit', $records_per_page, PDO::PARAM_INT);
|
|
$submissions_stmt->bindValue(':offset', $offset, PDO::PARAM_INT);
|
|
$submissions_stmt->execute();
|
|
$submissions = $submissions_stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
$pageTitle = "Admin - Feedback Submissions";
|
|
require_once 'templates/header.php';
|
|
?>
|
|
<main>
|
|
<section class="survey-section">
|
|
<div class="container">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1>Feedback Submissions</h1>
|
|
<div>
|
|
<a href="dashboard.php" class="btn btn-info">Dashboard</a>
|
|
<a href="surveys.php" class="btn btn-success">Manage Surveys</a>
|
|
<a href="export.php" class="btn btn-primary">Export to CSV</a>
|
|
<a href="?logout=true" class="btn btn-secondary">Logout</a>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="table-responsive">
|
|
<table class="table table-striped table-bordered">
|
|
<thead class="thead-dark">
|
|
<tr>
|
|
<th>Survey</th>
|
|
<th>Submitter</th>
|
|
<th>Email</th>
|
|
<th>Submitted At</th>
|
|
<th>Answers</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($submissions)): ?>
|
|
<tr>
|
|
<td colspan="5">No feedback submissions yet.</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($submissions as $submission): ?>
|
|
<tr>
|
|
<td><?= htmlspecialchars($submission['survey_title']) ?></td>
|
|
<td><?= htmlspecialchars($submission['name']) ?></td>
|
|
<td><?= htmlspecialchars($submission['email']) ?></td>
|
|
<td><?= $submission['created_at'] ?></td>
|
|
<td>
|
|
<a href="view_submission.php?id=<?= $submission['id'] ?>" class="btn btn-sm btn-info">View Answers</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<!-- Pagination Links -->
|
|
<nav aria-label="Page navigation">
|
|
<ul class="pagination justify-content-center">
|
|
<?php if ($page > 1): ?>
|
|
<li class="page-item"><a class="page-link" href="?page=<?= $page - 1 ?>">Previous</a></li>
|
|
<?php endif; ?>
|
|
<?php for ($i = 1; $i <= $total_pages; $i++): ?>
|
|
<li class="page-item <?= ($i == $page) ? 'active' : '' ?>"><a class="page-link" href="?page=<?= $i ?>"><?= $i ?></a></li>
|
|
<?php endfor; ?>
|
|
<?php if ($page < $total_pages): ?>
|
|
<li class="page-item"><a class="page-link" href="?page=<?= $page + 1 ?>">Next</a></li>
|
|
<?php endif; ?>
|
|
</ul>
|
|
</nav>
|
|
|
|
</div>
|
|
</section>
|
|
</main>
|
|
<?php
|
|
require_once 'templates/footer.php';
|
|
?>
|