76 lines
2.5 KiB
PHP
76 lines
2.5 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
// Ensure admin is logged in
|
|
if (!isset($_SESSION['user_id']) || !in_array('Admin', $_SESSION['user_roles'])) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
// Check for Survey ID
|
|
if (!isset($_GET['id'])) {
|
|
header('Location: surveys.php');
|
|
exit;
|
|
}
|
|
$survey_id = $_GET['id'];
|
|
|
|
// Fetch survey details
|
|
$survey_stmt = db()->prepare("SELECT * FROM surveys WHERE id = ?");
|
|
$survey_stmt->execute([$survey_id]);
|
|
$survey = $survey_stmt->fetch();
|
|
if (!$survey) {
|
|
header('Location: surveys.php');
|
|
exit;
|
|
}
|
|
|
|
// Handle form submission for updating survey
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['title'])) {
|
|
$title = trim($_POST['title']);
|
|
$description = trim($_POST['description']);
|
|
|
|
if (!empty($title)) {
|
|
$stmt = db()->prepare("UPDATE surveys SET title = ?, description = ? WHERE id = ?");
|
|
$stmt->execute([$title, $description, $survey_id]);
|
|
header("Location: surveys.php"); // Redirect to the survey list
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$pageTitle = "Edit Survey";
|
|
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>Edit Survey</h1>
|
|
<a href="surveys.php" class="btn btn-secondary">Back to Surveys</a>
|
|
</div>
|
|
|
|
<!-- Edit Survey 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>
|
|
</main>
|
|
|
|
<?php
|
|
require_once 'templates/footer.php';
|
|
?>
|