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,47 +33,57 @@ 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 class="card">
<div class="card-header">
<div class="d-flex justify-content-between align-items-center">
<h1 class="h3">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.php" class="btn btn-secondary">Logout</a>
</div>
</div>
</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): ?>
<div class="card-body">
<div class="table-responsive">
<table class="table table-striped table-bordered">
<thead class="thead-dark">
<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>
<th>Survey</th>
<th>Submitter</th>
<th>Email</th>
<th>Submitted At</th>
<th>Answers</th>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</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>
</div>
</div>
<!-- Pagination Links -->

75
api.php
View File

@ -21,36 +21,61 @@ switch ($action) {
break;
case 'survey_question_analytics':
$surveys_stmt = db()->query("SELECT * FROM surveys");
$surveys = $surveys_stmt->fetchAll(PDO::FETCH_ASSOC);
$surveys_stmt = db()->query("SELECT id, title FROM surveys");
$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 = [];
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);
foreach ($surveys as $survey_id => $survey_title) {
$survey_data = [
'id' => $survey['id'],
'title' => $survey['title'],
'id' => $survey_id,
'title' => $survey_title,
'questions' => []
];
foreach ($questions as $question) {
$answers_stmt = db()->prepare("SELECT answer_text, COUNT(*) as count FROM survey_answers WHERE question_id = ? GROUP BY answer_text");
$answers_stmt->execute([$question['id']]);
$answers = $answers_stmt->fetchAll(PDO::FETCH_ASSOC);
if (isset($questions[$survey_id])) {
foreach ($questions[$survey_id] as $question) {
$question_id = $question['id'];
$question_data = [
'id' => $question_id,
'question_text' => $question['question_text'],
'type' => $question['question_type'],
];
$question_data = [
'id' => $question['id'],
'question_text' => $question['question_text'],
'type' => $question['question_type'],
'answers' => [
'labels' => array_column($answers, 'answer_text'),
'values' => array_column($answers, 'count')
]
];
$survey_data['questions'][] = $question_data;
$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;
}
}
$response[] = $survey_data;
}
@ -60,4 +85,4 @@ switch ($action) {
default:
echo json_encode(['error' => 'Invalid action']);
break;
}
}

View File

@ -63,12 +63,26 @@ document.addEventListener('DOMContentLoaded', function () {
surveyRow.appendChild(col);
new Chart(canvas.getContext('2d'), {
type: 'pie',
type: 'bar',
data: {
labels: question.answers.labels,
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,25 +15,33 @@ 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>Analytics Dashboard</h1>
<a href="admin.php" class="btn btn-secondary">Back to Submissions</a>
</div>
<div class="row">
<div class="col-md-12">
<div class="card mb-4">
<div class="card-header">
<h3>Submissions per Survey</h3>
</div>
<div class="card-body">
<canvas id="submissions-chart"></canvas>
</div>
<div class="card">
<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>
</div>
</div>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-12">
<div class="card mb-4">
<div class="card-header">
<h3>Submissions per Survey</h3>
</div>
<div class="card-body">
<canvas id="submissions-chart"></canvas>
</div>
</div>
</div>
</div>
<div id="survey-charts-container"></div>
<hr>
<h2 class="h4 mb-4">Survey Question Analytics</h2>
<div id="survey-charts-container"></div>
</div>
</div>
</div>
</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,18 +50,21 @@ require_once 'templates/header.php';
</div>
<!-- Edit Survey Form -->
<div class="form-container">
<form method="POST">
<div class="form-group">
<label for="title" class="form-label">Survey Title</label>
<input type="text" id="title" name="title" class="form-control" value="<?= htmlspecialchars($survey['title']) ?>" required>
</div>
<div class="form-group">
<label for="description" class="form-label">Description (Optional)</label>
<textarea id="description" name="description" rows="3" class="form-control"><?= htmlspecialchars($survey['description']) ?></textarea>
</div>
<button type="submit" class="btn btn-primary">Save Changes</button>
</form>
<div class="card">
<div class="card-body">
<h2 class="card-title">Edit Survey</h2>
<form method="POST">
<div class="form-group">
<label for="title" class="form-label">Survey Title</label>
<input type="text" id="title" name="title" class="form-control" value="<?= htmlspecialchars($survey['title']) ?>" required>
</div>
<div class="form-group">
<label for="description" class="form-label">Description (Optional)</label>
<textarea id="description" name="description" rows="3" class="form-control"><?= htmlspecialchars($survey['description']) ?></textarea>
</div>
<button type="submit" class="btn btn-primary">Save Changes</button>
</form>
</div>
</div>
</div>
</section>

View File

@ -34,20 +34,32 @@ require_once 'templates/header.php';
<section class="survey-section">
<div class="container">
<div class="list-group">
<?php if (empty($surveys)): ?>
<p class="list-group-item">No surveys available at the moment.</p>
<?php else: ?>
<?php foreach ($surveys as $survey): ?>
<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 class="row">
<?php if (empty($surveys)):
?>
<div class="col">
<p>No surveys available at the moment.</p>
</div>
<?php else:
?>
<?php foreach ($surveys as $survey):
?>
<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>
<p class="mb-1"><?= htmlspecialchars($survey['description']) ?></p>
</a>
<?php endforeach; ?>
<?php endif; ?>
</div>
<?php endforeach;
?>
<?php endif;
?>
</div>
<!-- Pagination Links -->

View File

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

View File

@ -39,8 +39,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['question_text'])) {
}
// Handle question deletion
if (isset($_GET['delete_question'])) {
$question_id = $_GET['delete_question'];
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_question'])) {
$question_id = $_POST['delete_question'];
$stmt = db()->prepare("DELETE FROM survey_questions WHERE id = ? AND survey_id = ?");
$stmt->execute([$question_id, $survey_id]);
header("Location: manage_questions.php?survey_id=" . $survey_id);
@ -65,61 +65,69 @@ require_once 'templates/header.php';
</div>
<!-- Add New Question Form -->
<div class="form-container mb-5">
<h2>Add New Question</h2>
<form method="POST">
<div class="form-group">
<label for="question_text" class="form-label">Question Text</label>
<input type="text" id="question_text" name="question_text" class="form-control" required>
</div>
<div class="form-group">
<label for="question_type" class="form-label">Question Type</label>
<select id="question_type" name="question_type" class="form-control" required onchange="toggleOptions(this.value)">
<option value="text">Text (Single Line)</option>
<option value="textarea">Textarea (Multi-line)</option>
<option value="rating">Rating (1-5)</option>
<option value="multiple-choice">Multiple Choice</option>
</select>
</div>
<div class="form-group" id="options-container" style="display: none;">
<label for="options" class="form-label">Options (comma-separated)</label>
<input type="text" id="options" name="options" class="form-control">
</div>
<button type="submit" class="btn btn-primary">Add Question</button>
</form>
<div class="card mb-5">
<div class="card-body">
<h2 class="card-title">Add New Question</h2>
<form method="POST">
<div class="form-group">
<label for="question_text" class="form-label">Question Text</label>
<input type="text" id="question_text" name="question_text" class="form-control" required>
</div>
<div class="form-group">
<label for="question_type" class="form-label">Question Type</label>
<select id="question_type" name="question_type" class="form-control" required onchange="toggleOptions(this.value)">
<option value="text">Text (Single Line)</option>
<option value="textarea">Textarea (Multi-line)</option>
<option value="rating">Rating (1-5)</option>
<option value="multiple-choice">Multiple Choice</option>
</select>
</div>
<div class="form-group" id="options-container" style="display: none;">
<label for="options" class="form-label">Options (comma-separated)</label>
<input type="text" id="options" name="options" class="form-control">
</div>
<button type="submit" class="btn btn-primary">Add Question</button>
</form>
</div>
</div>
<!-- List of Existing Questions -->
<h2>Existing Questions</h2>
<div class="table-responsive">
<table class="table table-striped table-bordered">
<thead class="thead-dark">
<tr>
<th>Question Text</th>
<th>Type</th>
<th>Options</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($questions)): ?>
<tr>
<td colspan="4">No questions added to this survey yet.</td>
</tr>
<?php else: ?>
<?php foreach ($questions as $question): ?>
<tr>
<td><?= htmlspecialchars($question['question_text']) ?></td>
<td><?= htmlspecialchars($question['question_type']) ?></td>
<td><?= htmlspecialchars($question['options'] ?? '') ?></td>
<td>
<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>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
<div class="row">
<?php if (empty($questions)):
?>
<div class="col">
<p>No questions added to this survey yet.</p>
</div>
<?php else:
?>
<?php foreach ($questions as $question):
?>
<div class="col-md-6 mb-4">
<div class="card h-100">
<div class="card-body">
<h5 class="card-title"><?= htmlspecialchars($question['question_text']) ?></h5>
<p class="card-text">
<strong>Type:</strong> <?= htmlspecialchars($question['question_type']) ?><br>
<?php if (!empty($question['options'])):
?>
<strong>Options:</strong> <?= htmlspecialchars($question['options']) ?>
<?php endif;
?>
</p>
</div>
<div class="card-footer">
<form method="POST" action="?survey_id=<?= $survey_id ?>" style="display: inline-block;">
<input type="hidden" name="delete_question" value="<?= $question['id'] ?>">
<button type="submit" class="btn btn-danger" onclick="return confirm('Are you sure you want to delete this question?')">Delete</button>
</form>
</div>
</div>
</div>
<?php endforeach;
?>
<?php endif;
?>
</div>
</div>
</section>

View File

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

View File

@ -45,7 +45,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$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;
$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}";
MailService::sendMail(null, $subject, $htmlBody, $textBody);

View File

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

View File

@ -46,12 +46,7 @@ $isSurveyPage = basename($_SERVER['PHP_SELF']) == 'survey.php';
<a class="nav-link" href="logout.php">Logout</a>
</li>
<?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; ?>
</ul>
</div>

View File

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