This commit is contained in:
Flatlogic Bot 2025-10-07 22:38:32 +00:00
parent cab661dbb4
commit 6255e8b900
17 changed files with 598 additions and 274 deletions

View File

@ -33,16 +33,19 @@ require_once 'templates/header.php';
<main> <main>
<section class="survey-section"> <section class="survey-section">
<div class="container"> <div class="container">
<div class="d-flex justify-content-between align-items-center mb-4"> <div class="card">
<h1>Feedback Submissions</h1> <div class="card-header">
<div class="d-flex justify-content-between align-items-center">
<h1 class="h3">Feedback Submissions</h1>
<div> <div>
<a href="dashboard.php" class="btn btn-info">Dashboard</a> <a href="dashboard.php" class="btn btn-info">Dashboard</a>
<a href="surveys.php" class="btn btn-success">Manage Surveys</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="export.php" class="btn btn-primary">Export to CSV</a>
<a href="?logout=true" class="btn btn-secondary">Logout</a> <a href="logout.php" class="btn btn-secondary">Logout</a>
</div> </div>
</div> </div>
</div>
<div class="card-body">
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-striped table-bordered"> <table class="table table-striped table-bordered">
<thead class="thead-dark"> <thead class="thead-dark">
@ -55,12 +58,15 @@ require_once 'templates/header.php';
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php if (empty($submissions)): ?> <?php if (empty($submissions)):
?>
<tr> <tr>
<td colspan="5">No feedback submissions yet.</td> <td colspan="5">No feedback submissions yet.</td>
</tr> </tr>
<?php else: ?> <?php else:
<?php foreach ($submissions as $submission): ?> ?>
<?php foreach ($submissions as $submission):
?>
<tr> <tr>
<td><?= htmlspecialchars($submission['survey_title']) ?></td> <td><?= htmlspecialchars($submission['survey_title']) ?></td>
<td><?= htmlspecialchars($submission['name']) ?></td> <td><?= htmlspecialchars($submission['name']) ?></td>
@ -70,11 +76,15 @@ require_once 'templates/header.php';
<a href="view_submission.php?id=<?= $submission['id'] ?>" class="btn btn-sm btn-info">View Answers</a> <a href="view_submission.php?id=<?= $submission['id'] ?>" class="btn btn-sm btn-info">View Answers</a>
</td> </td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach;
<?php endif; ?> ?>
<?php endif;
?>
</tbody> </tbody>
</table> </table>
</div> </div>
</div>
</div>
<!-- Pagination Links --> <!-- Pagination Links -->
<nav aria-label="Page navigation"> <nav aria-label="Page navigation">

65
api.php
View File

@ -21,37 +21,62 @@ switch ($action) {
break; break;
case 'survey_question_analytics': case 'survey_question_analytics':
$surveys_stmt = db()->query("SELECT * FROM surveys"); $surveys_stmt = db()->query("SELECT id, title FROM surveys");
$surveys = $surveys_stmt->fetchAll(PDO::FETCH_ASSOC); $surveys = $surveys_stmt->fetchAll(PDO::FETCH_KEY_PAIR);
$questions_stmt = db()->query("SELECT survey_id, id, question_text, question_type FROM survey_questions WHERE question_type = 'rating' OR question_type = 'multiple-choice'");
$questions = $questions_stmt->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
$answers_stmt = db()->query("SELECT q.id as question_id, a.answer_text FROM survey_answers a JOIN survey_questions q ON a.question_id = q.id WHERE q.question_type = 'rating' OR q.question_type = 'multiple-choice'");
$answers_by_question = $answers_stmt->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_COLUMN);
$response = []; $response = [];
foreach ($surveys as $survey_id => $survey_title) {
foreach ($surveys as $survey) {
$questions_stmt = db()->prepare("SELECT * FROM survey_questions WHERE survey_id = ? AND (question_type = 'rating' OR question_type = 'multiple-choice')");
$questions_stmt->execute([$survey['id']]);
$questions = $questions_stmt->fetchAll(PDO::FETCH_ASSOC);
$survey_data = [ $survey_data = [
'id' => $survey['id'], 'id' => $survey_id,
'title' => $survey['title'], 'title' => $survey_title,
'questions' => [] 'questions' => []
]; ];
foreach ($questions as $question) { if (isset($questions[$survey_id])) {
$answers_stmt = db()->prepare("SELECT answer_text, COUNT(*) as count FROM survey_answers WHERE question_id = ? GROUP BY answer_text"); foreach ($questions[$survey_id] as $question) {
$answers_stmt->execute([$question['id']]); $question_id = $question['id'];
$answers = $answers_stmt->fetchAll(PDO::FETCH_ASSOC);
$question_data = [ $question_data = [
'id' => $question['id'], 'id' => $question_id,
'question_text' => $question['question_text'], 'question_text' => $question['question_text'],
'type' => $question['question_type'], 'type' => $question['question_type'],
'answers' => [
'labels' => array_column($answers, 'answer_text'),
'values' => array_column($answers, 'count')
]
]; ];
$answers = $answers_by_question[$question_id] ?? [];
if ($question['question_type'] == 'multiple-choice') {
$answer_counts = [];
foreach ($answers as $answer_row) {
$options = preg_split('/,\s*/', $answer_row);
foreach ($options as $option) {
$trimmed_option = trim($option);
if (!empty($trimmed_option)) {
if (!isset($answer_counts[$trimmed_option])) {
$answer_counts[$trimmed_option] = 0;
}
$answer_counts[$trimmed_option]++;
}
}
}
$question_data['answers'] = [
'labels' => array_keys($answer_counts),
'values' => array_values($answer_counts)
];
} else { // rating
$answer_counts = array_count_values($answers);
$question_data['answers'] = [
'labels' => array_keys($answer_counts),
'values' => array_values($answer_counts)
];
}
$survey_data['questions'][] = $question_data; $survey_data['questions'][] = $question_data;
} }
}
$response[] = $survey_data; $response[] = $survey_data;
} }
echo json_encode($response); echo json_encode($response);

View File

@ -63,12 +63,26 @@ document.addEventListener('DOMContentLoaded', function () {
surveyRow.appendChild(col); surveyRow.appendChild(col);
new Chart(canvas.getContext('2d'), { new Chart(canvas.getContext('2d'), {
type: 'pie', type: 'bar',
data: { data: {
labels: question.answers.labels, labels: question.answers.labels,
datasets: [{ datasets: [{
data: question.answers.values label: 'Count',
data: question.answers.values,
backgroundColor: 'rgba(54, 162, 235, 0.2)',
borderColor: 'rgba(54, 162, 235, 1)',
borderWidth: 1
}] }]
},
options: {
scales: {
y: {
beginAtZero: true,
ticks: {
stepSize: 1
}
}
}
} }
}); });
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

View File

@ -15,11 +15,14 @@ require_once 'templates/header.php';
<main> <main>
<section class="survey-section"> <section class="survey-section">
<div class="container"> <div class="container">
<div class="d-flex justify-content-between align-items-center mb-4"> <div class="card">
<h1>Analytics Dashboard</h1> <div class="card-header">
<div class="d-flex justify-content-between align-items-center">
<h1 class="h3">Analytics Dashboard</h1>
<a href="admin.php" class="btn btn-secondary">Back to Submissions</a> <a href="admin.php" class="btn btn-secondary">Back to Submissions</a>
</div> </div>
</div>
<div class="card-body">
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<div class="card mb-4"> <div class="card mb-4">
@ -33,7 +36,12 @@ require_once 'templates/header.php';
</div> </div>
</div> </div>
<hr>
<h2 class="h4 mb-4">Survey Question Analytics</h2>
<div id="survey-charts-container"></div> <div id="survey-charts-container"></div>
</div>
</div>
</div> </div>
</section> </section>

View File

@ -0,0 +1 @@
ALTER TABLE survey_questions ADD COLUMN options TEXT NULL AFTER question_type;

220
debug_log.txt Executable file
View File

@ -0,0 +1,220 @@
--- NEW REQUEST ---
Surveys:
Array
(
[1] => Your True Flatlogic Feedback
)
Questions:
Array
(
[1] => Array
(
[0] => Array
(
[survey_id] => 1
[question_text] => What stopped you from upgrading after creating your app?
[question_type] => multiple-choice
)
)
[2] => Array
(
[0] => Array
(
[survey_id] => 1
[question_text] => What would help you continue?
[question_type] => multiple-choice
)
)
)
Answers by Question:
Array
(
[1] => Array
(
[0] => The generated app didnt look good enough, Bugs or errors on the platform, It used too many credits / hosting felt expensive
)
[2] => Array
(
[0] => A short call with an engineer, Clearer tutorials/documentation, Access to a specific template/feature
)
)
Processing Survey ID: 1
Processing Question ID:
Answers for Question :
Array
(
)
Processed Question Data:
Array
(
[id] =>
[question_text] => What stopped you from upgrading after creating your app?
[type] => multiple-choice
[answers] => Array
(
[labels] => Array
(
)
[values] => Array
(
)
)
)
Final Response:
Array
(
[0] => Array
(
[id] => 1
[title] => Your True Flatlogic Feedback
[questions] => Array
(
[0] => Array
(
[id] =>
[question_text] => What stopped you from upgrading after creating your app?
[type] => multiple-choice
[answers] => Array
(
[labels] => Array
(
)
[values] => Array
(
)
)
)
)
)
)
--- NEW REQUEST ---
Surveys:
Array
(
[1] => Your True Flatlogic Feedback
)
Questions:
Array
(
[1] => Array
(
[0] => Array
(
[survey_id] => 1
[question_text] => What stopped you from upgrading after creating your app?
[question_type] => multiple-choice
)
)
[2] => Array
(
[0] => Array
(
[survey_id] => 1
[question_text] => What would help you continue?
[question_type] => multiple-choice
)
)
)
Answers by Question:
Array
(
[1] => Array
(
[0] => The generated app didnt look good enough, Bugs or errors on the platform, It used too many credits / hosting felt expensive
)
[2] => Array
(
[0] => A short call with an engineer, Clearer tutorials/documentation, Access to a specific template/feature
)
)
Processing Survey ID: 1
Processing Question ID:
Answers for Question :
Array
(
)
Processed Question Data:
Array
(
[id] =>
[question_text] => What stopped you from upgrading after creating your app?
[type] => multiple-choice
[answers] => Array
(
[labels] => Array
(
)
[values] => Array
(
)
)
)
Final Response:
Array
(
[0] => Array
(
[id] => 1
[title] => Your True Flatlogic Feedback
[questions] => Array
(
[0] => Array
(
[id] =>
[question_text] => What stopped you from upgrading after creating your app?
[type] => multiple-choice
[answers] => Array
(
[labels] => Array
(
)
[values] => Array
(
)
)
)
)
)
)

View File

@ -50,7 +50,9 @@ require_once 'templates/header.php';
</div> </div>
<!-- Edit Survey Form --> <!-- Edit Survey Form -->
<div class="form-container"> <div class="card">
<div class="card-body">
<h2 class="card-title">Edit Survey</h2>
<form method="POST"> <form method="POST">
<div class="form-group"> <div class="form-group">
<label for="title" class="form-label">Survey Title</label> <label for="title" class="form-label">Survey Title</label>
@ -64,6 +66,7 @@ require_once 'templates/header.php';
</form> </form>
</div> </div>
</div> </div>
</div>
</section> </section>
</main> </main>

View File

@ -34,20 +34,32 @@ require_once 'templates/header.php';
<section class="survey-section"> <section class="survey-section">
<div class="container"> <div class="container">
<div class="list-group"> <div class="row">
<?php if (empty($surveys)): ?> <?php if (empty($surveys)):
<p class="list-group-item">No surveys available at the moment.</p> ?>
<?php else: ?> <div class="col">
<?php foreach ($surveys as $survey): ?> <p>No surveys available at the moment.</p>
<a href="survey.php?id=<?= $survey['id'] ?>" class="list-group-item list-group-item-action">
<div class="d-flex w-100 justify-content-between">
<h5 class="mb-1"><?= htmlspecialchars($survey['title']) ?></h5>
<small><?= date('M j, Y', strtotime($survey['created_at'])) ?></small>
</div> </div>
<p class="mb-1"><?= htmlspecialchars($survey['description']) ?></p> <?php else:
</a> ?>
<?php endforeach; ?> <?php foreach ($surveys as $survey):
<?php endif; ?> ?>
<div class="col-md-4 mb-4">
<div class="card h-100">
<div class="card-body d-flex flex-column">
<h5 class="card-title"><?= htmlspecialchars($survey['title']) ?></h5>
<p class="card-text flex-grow-1"><?= htmlspecialchars($survey['description']) ?></p>
<a href="survey.php?id=<?= $survey['id'] ?>" class="btn btn-primary mt-auto">Take Survey</a>
</div>
<div class="card-footer">
<small class="text-muted">Created: <?= date('M j, Y', strtotime($survey['created_at'])) ?></small>
</div>
</div>
</div>
<?php endforeach;
?>
<?php endif;
?>
</div> </div>
<!-- Pagination Links --> <!-- Pagination Links -->

View File

@ -58,11 +58,16 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
<main> <main>
<section class="survey-section"> <section class="survey-section">
<div class="container"> <div class="container">
<div class="form-container"> <div class="row justify-content-center">
<h1>Login</h1> <div class="col-md-6">
<?php if ($error): ?> <div class="card">
<div class="card-body">
<h1 class="card-title text-center">Login</h1>
<?php if ($error):
?>
<div class="alert alert-danger"><?= $error ?></div> <div class="alert alert-danger"><?= $error ?></div>
<?php endif; ?> <?php endif;
?>
<form method="POST"> <form method="POST">
<div class="form-group"> <div class="form-group">
<label for="username" class="form-label">Username</label> <label for="username" class="form-label">Username</label>
@ -72,9 +77,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
<label for="password" class="form-label">Password</label> <label for="password" class="form-label">Password</label>
<input type="password" id="password" name="password" class="form-control" required> <input type="password" id="password" name="password" class="form-control" required>
</div> </div>
<button type="submit" class="btn btn-primary">Login</button> <button type="submit" class="btn btn-primary btn-block">Login</button>
</form> </form>
<p class="mt-3">Don't have an account? <a href="register.php">Register here</a>.</p> <p class="mt-3 text-center">Don't have an account? <a href="register.php">Register here</a>.</p>
</div>
</div>
</div>
</div> </div>
</div> </div>
</section> </section>

View File

@ -39,8 +39,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['question_text'])) {
} }
// Handle question deletion // Handle question deletion
if (isset($_GET['delete_question'])) { if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_question'])) {
$question_id = $_GET['delete_question']; $question_id = $_POST['delete_question'];
$stmt = db()->prepare("DELETE FROM survey_questions WHERE id = ? AND survey_id = ?"); $stmt = db()->prepare("DELETE FROM survey_questions WHERE id = ? AND survey_id = ?");
$stmt->execute([$question_id, $survey_id]); $stmt->execute([$question_id, $survey_id]);
header("Location: manage_questions.php?survey_id=" . $survey_id); header("Location: manage_questions.php?survey_id=" . $survey_id);
@ -65,8 +65,9 @@ require_once 'templates/header.php';
</div> </div>
<!-- Add New Question Form --> <!-- Add New Question Form -->
<div class="form-container mb-5"> <div class="card mb-5">
<h2>Add New Question</h2> <div class="card-body">
<h2 class="card-title">Add New Question</h2>
<form method="POST"> <form method="POST">
<div class="form-group"> <div class="form-group">
<label for="question_text" class="form-label">Question Text</label> <label for="question_text" class="form-label">Question Text</label>
@ -88,38 +89,45 @@ require_once 'templates/header.php';
<button type="submit" class="btn btn-primary">Add Question</button> <button type="submit" class="btn btn-primary">Add Question</button>
</form> </form>
</div> </div>
</div>
<!-- List of Existing Questions --> <!-- List of Existing Questions -->
<h2>Existing Questions</h2> <h2>Existing Questions</h2>
<div class="table-responsive"> <div class="row">
<table class="table table-striped table-bordered"> <?php if (empty($questions)):
<thead class="thead-dark"> ?>
<tr> <div class="col">
<th>Question Text</th> <p>No questions added to this survey yet.</p>
<th>Type</th> </div>
<th>Options</th> <?php else:
<th>Actions</th> ?>
</tr> <?php foreach ($questions as $question):
</thead> ?>
<tbody> <div class="col-md-6 mb-4">
<?php if (empty($questions)): ?> <div class="card h-100">
<tr> <div class="card-body">
<td colspan="4">No questions added to this survey yet.</td> <h5 class="card-title"><?= htmlspecialchars($question['question_text']) ?></h5>
</tr> <p class="card-text">
<?php else: ?> <strong>Type:</strong> <?= htmlspecialchars($question['question_type']) ?><br>
<?php foreach ($questions as $question): ?> <?php if (!empty($question['options'])):
<tr> ?>
<td><?= htmlspecialchars($question['question_text']) ?></td> <strong>Options:</strong> <?= htmlspecialchars($question['options']) ?>
<td><?= htmlspecialchars($question['question_type']) ?></td> <?php endif;
<td><?= htmlspecialchars($question['options'] ?? '') ?></td> ?>
<td> </p>
<a href="?survey_id=<?= $survey_id ?>&delete_question=<?= $question['id'] ?>" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure you want to delete this question?')">Delete</a> </div>
</td> <div class="card-footer">
</tr> <form method="POST" action="?survey_id=<?= $survey_id ?>" style="display: inline-block;">
<?php endforeach; ?> <input type="hidden" name="delete_question" value="<?= $question['id'] ?>">
<?php endif; ?> <button type="submit" class="btn btn-danger" onclick="return confirm('Are you sure you want to delete this question?')">Delete</button>
</tbody> </form>
</table> </div>
</div>
</div>
<?php endforeach;
?>
<?php endif;
?>
</div> </div>
</div> </div>
</section> </section>

View File

@ -55,14 +55,21 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
<main> <main>
<section class="survey-section"> <section class="survey-section">
<div class="container"> <div class="container">
<div class="form-container"> <div class="row justify-content-center">
<h1>Register</h1> <div class="col-md-6">
<?php if ($error): ?> <div class="card">
<div class="card-body">
<h1 class="card-title text-center">Register</h1>
<?php if ($error):
?>
<div class="alert alert-danger"><?= $error ?></div> <div class="alert alert-danger"><?= $error ?></div>
<?php endif; ?> <?php endif;
<?php if ($success): ?> ?>
<?php if ($success):
?>
<div class="alert alert-success"><?= $success ?></div> <div class="alert alert-success"><?= $success ?></div>
<?php else: ?> <?php else:
?>
<form method="POST"> <form method="POST">
<div class="form-group"> <div class="form-group">
<label for="username" class="form-label">Username</label> <label for="username" class="form-label">Username</label>
@ -80,9 +87,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
<label for="password_confirm" class="form-label">Confirm Password</label> <label for="password_confirm" class="form-label">Confirm Password</label>
<input type="password" id="password_confirm" name="password_confirm" class="form-control" required> <input type="password" id="password_confirm" name="password_confirm" class="form-control" required>
</div> </div>
<button type="submit" class="btn btn-primary">Register</button> <button type="submit" class="btn btn-primary btn-block">Register</button>
</form> </form>
<?php endif; ?> <?php endif;
?>
<p class="mt-3 text-center">Already have an account? <a href="login.php">Login here</a>.</p>
</div>
</div>
</div>
</div> </div>
</div> </div>
</section> </section>

View File

@ -45,7 +45,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$subject = "New Submission for Survey: " . $survey_title; $subject = "New Submission for Survey: " . $survey_title;
$submission_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'] . '/view_submission.php?id=' . $submission_id; $submission_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'] . '/view_submission.php?id=' . $submission_id;
$htmlBody = "<p>A new submission has been received for the survey: <strong>{$survey_title}</strong></p>\n <p><strong>Submitter:</strong> {$name} ({$email})</p>\n <p><a href=\"{$submission_url}\">Click here to view the full submission.</a></p>"; $safe_name = htmlspecialchars($name);
$safe_email = htmlspecialchars($email);
$htmlBody = "<p>A new submission has been received for the survey: <strong>{$survey_title}</strong></p>\n <p><strong>Submitter:</strong> {$safe_name} ({$safe_email})</p>\n <p><a href=\"{$submission_url}\">Click here to view the full submission.</a></p>";
$textBody = "A new submission has been received for the survey: {$survey_title}. Submitter: {$name} ({$email}). View the submission here: {$submission_url}"; $textBody = "A new submission has been received for the survey: {$survey_title}. Submitter: {$name} ({$email}). View the submission here: {$submission_url}";
MailService::sendMail(null, $subject, $htmlBody, $textBody); MailService::sendMail(null, $subject, $htmlBody, $textBody);

View File

@ -51,8 +51,9 @@ require_once 'templates/header.php';
</div> </div>
<!-- Create New Survey Form --> <!-- Create New Survey Form -->
<div class="form-container mb-5"> <div class="card mb-5">
<h2>Create New Survey</h2> <div class="card-body">
<h2 class="card-title">Create New Survey</h2>
<form method="POST"> <form method="POST">
<div class="form-group"> <div class="form-group">
<label for="title" class="form-label">Survey Title</label> <label for="title" class="form-label">Survey Title</label>
@ -65,39 +66,37 @@ require_once 'templates/header.php';
<button type="submit" class="btn btn-primary">Create Survey</button> <button type="submit" class="btn btn-primary">Create Survey</button>
</form> </form>
</div> </div>
</div>
<!-- List of Existing Surveys --> <!-- List of Existing Surveys -->
<h2>Existing Surveys</h2> <h2>Existing Surveys</h2>
<div class="table-responsive"> <div class="row">
<table class="table table-striped table-bordered"> <?php if (empty($surveys)):
<thead class="thead-dark"> ?>
<tr> <div class="col">
<th>Title</th> <p>No surveys created yet.</p>
<th>Description</th> </div>
<th>Created At</th> <?php else:
<th>Actions</th> ?>
</tr> <?php foreach ($surveys as $survey):
</thead> ?>
<tbody> <div class="col-md-6 mb-4">
<?php if (empty($surveys)): ?> <div class="card h-100">
<tr> <div class="card-body">
<td colspan="4">No surveys created yet.</td> <h5 class="card-title"><?= htmlspecialchars($survey['title']) ?></h5>
</tr> <p class="card-text"><?= htmlspecialchars($survey['description']) ?></p>
<?php else: ?> </div>
<?php foreach ($surveys as $survey): ?> <div class="card-footer">
<tr> <a href="manage_questions.php?survey_id=<?= $survey['id'] ?>" class="btn btn-primary">Manage Questions</a>
<td><?= htmlspecialchars($survey['title']) ?></td> <a href="edit_survey.php?id=<?= $survey['id'] ?>" class="btn btn-secondary">Edit</a>
<td><?= htmlspecialchars($survey['description']) ?></td> <small class="text-muted float-right">Created: <?= date('M j, Y', strtotime($survey['created_at'])) ?></small>
<td><?= $survey['created_at'] ?></td> </div>
<td> </div>
<a href="manage_questions.php?survey_id=<?= $survey['id'] ?>" class="btn btn-sm btn-primary">Manage Questions</a> </div>
<a href="edit_survey.php?id=<?= $survey['id'] ?>" class="btn btn-sm btn-secondary">Edit</a> <?php endforeach;
</td> ?>
</tr> <?php endif;
<?php endforeach; ?> ?>
<?php endif; ?>
</tbody>
</table>
</div> </div>
<!-- Pagination Links --> <!-- Pagination Links -->

View File

@ -46,12 +46,7 @@ $isSurveyPage = basename($_SERVER['PHP_SELF']) == 'survey.php';
<a class="nav-link" href="logout.php">Logout</a> <a class="nav-link" href="logout.php">Logout</a>
</li> </li>
<?php else: ?> <?php else: ?>
<li class="nav-item">
<a class="nav-link" href="login.php">Login</a>
</li>
<li class="nav-item">
<a class="nav-link" href="register.php">Register</a>
</li>
<?php endif; ?> <?php endif; ?>
</ul> </ul>
</div> </div>

View File

@ -3,8 +3,8 @@ session_start();
require_once 'db/config.php'; require_once 'db/config.php';
// Ensure admin is logged in // Ensure admin is logged in
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) { if (!isset($_SESSION['user_id']) || !in_array('Admin', $_SESSION['user_roles'])) {
header('Location: admin.php'); header('Location: login.php');
exit; exit;
} }
@ -43,32 +43,39 @@ require_once 'templates/header.php';
<div class="card"> <div class="card">
<div class="card-header"> <div class="card-header">
<h3>Survey: <?= htmlspecialchars($submission['survey_title']) ?></h3> <h3 class="mb-0">Submission for "<?= htmlspecialchars($submission['survey_title']) ?>"</h3>
</div> </div>
<div class="card-body"> <div class="card-body">
<p><strong>Submitter:</strong> <?= htmlspecialchars($submission['name']) ?></p> <div class="mb-4">
<p><strong>Email:</strong> <?= htmlspecialchars($submission['email']) ?></p> <h5>Submission Details</h5>
<p><strong>Submitted At:</strong> <?= $submission['created_at'] ?></p> <p class="mb-1"><strong>Submitter:</strong> <?= htmlspecialchars($submission['name']) ?></p>
<p class="mb-1"><strong>Email:</strong> <?= htmlspecialchars($submission['email']) ?></p>
<p class="mb-0"><strong>Submitted At:</strong> <?= $submission['created_at'] ?></p>
</div> </div>
</div> <hr>
<div>
<div class="card mt-4"> <h5>Answers</h5>
<div class="card-header"> <table class="table table-striped table-bordered">
<h3>Answers</h3> <thead class="thead-light">
</div>
<div class="card-body">
<table class="table table-striped">
<tbody>
<?php foreach ($answers as $answer): ?>
<tr> <tr>
<th style="width: 30%;"><?= htmlspecialchars($answer['question_text']) ?></th> <th style="width: 30%;">Question</th>
<th>Answer</th>
</tr>
</thead>
<tbody>
<?php foreach ($answers as $answer):
?>
<tr>
<td><?= htmlspecialchars($answer['question_text']) ?></td>
<td><?= nl2br(htmlspecialchars($answer['answer_text'])) ?></td> <td><?= nl2br(htmlspecialchars($answer['answer_text'])) ?></td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach;
?>
</tbody> </tbody>
</table> </table>
</div> </div>
</div> </div>
</div>
</div> </div>
</section> </section>