diff --git a/admin.php b/admin.php index ecb138a..c7dfc60 100644 --- a/admin.php +++ b/admin.php @@ -7,9 +7,25 @@ if (!isset($_SESSION['user_id']) || !in_array('Admin', $_SESSION['user_roles'])) exit; } -// If logged in, show the admin content require_once 'db/config.php'; +// Handle deletion of a submission +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['submission_id_to_delete'])) { + $submission_id = $_POST['submission_id_to_delete']; + + // First, delete the associated answers + $delete_answers_stmt = db()->prepare("DELETE FROM survey_answers WHERE submission_id = ?"); + $delete_answers_stmt->execute([$submission_id]); + + // Then, delete the submission itself + $delete_submission_stmt = db()->prepare("DELETE FROM feedback_submissions WHERE id = ?"); + $delete_submission_stmt->execute([$submission_id]); + + // Redirect to the same page to see the changes + header('Location: admin.php?page=' . (isset($_GET['page']) ? $_GET['page'] : 1)); + exit; +} + // Pagination $page = isset($_GET['page']) ? (int)$_GET['page'] : 1; $records_per_page = 10; @@ -54,7 +70,7 @@ require_once 'templates/header.php'; Submitter Email Submitted At - Answers + Actions @@ -73,7 +89,11 @@ require_once 'templates/header.php'; - View Answers + View +
+ + +
{ + step.classList.toggle('active', index === stepIndex); + }); + updateProgressBar(); + updateButtons(); + } + + function updateProgressBar() { + const progress = ((currentStep + 1) / steps.length) * 100; + progressBar.style.width = progress + '%'; + progressBar.setAttribute('aria-valuenow', progress); + } + + function updateButtons() { + prevBtn.style.display = currentStep === 0 ? 'none' : 'inline-block'; + nextBtn.style.display = currentStep === steps.length - 1 ? 'none' : 'inline-block'; + submitBtn.style.display = currentStep === steps.length - 1 ? 'inline-block' : 'none'; + } + + function validateStep(stepIndex) { + const currentStepElement = steps[stepIndex]; + const inputs = Array.from(currentStepElement.querySelectorAll('input, textarea')); + let isValid = true; + + inputs.forEach(input => { + if (input.hasAttribute('required')) { + if (input.type === 'radio' || input.type === 'checkbox') { + const name = input.name; + if (!surveyForm.querySelector(`input[name="${name}"]:checked`)) { + isValid = false; + } + } else if (!input.value.trim()) { + isValid = false; + } + } + }); + + return isValid; + } + + nextBtn.addEventListener('click', () => { + if (!validateStep(currentStep)) { + alert('Please answer the question before proceeding.'); + return; + } + + if (currentStep < steps.length - 1) { + currentStep++; + showStep(currentStep); + } + }); + + prevBtn.addEventListener('click', () => { + if (currentStep > 0) { + currentStep--; + showStep(currentStep); + } + }); + + showStep(currentStep); + const successMessage = document.getElementById('success-message'); const formContainer = document.querySelector('.form-container'); @@ -43,3 +112,4 @@ document.addEventListener('DOMContentLoaded', function () { } }); + diff --git a/survey.php b/survey.php index bd748ae..373d54b 100644 --- a/survey.php +++ b/survey.php @@ -9,6 +9,24 @@ if (!isset($_GET['id'])) { } $survey_id = $_GET['id']; +// --- Email Logic --- +$email = ''; +$isEmailDisabled = false; + +// 1. Check for email in URL parameter +if (isset($_GET['email']) && !empty($_GET['email'])) { + $email = $_GET['email']; + // Store it in a cookie for 1 year + setcookie('user_email', $email, time() + (86400 * 365), "/"); // 86400 = 1 day + $isEmailDisabled = true; +} +// 2. If not in URL, check for email in cookie +else if (isset($_COOKIE['user_email']) && !empty($_COOKIE['user_email'])) { + $email = $_COOKIE['user_email']; + $isEmailDisabled = true; +} +// 3. Otherwise, the field will be empty and enabled. + // Fetch survey details $survey_stmt = db()->prepare("SELECT * FROM surveys WHERE id = ?"); $survey_stmt->execute([$survey_id]); @@ -52,46 +70,58 @@ require_once 'templates/header.php';
- -
- - + +
+
-
- - + +
+
+ + +
+
+ + required> +
-
- - - - - - -
- - - - -
- - -
- - -
- - -
- -
- +
+
+ + + + + + +
+ + + + +
+ + +
+ + +
+ + +
+ +
+ +
- +
+ + + +
diff --git a/templates/header.php b/templates/header.php index d152ada..d469366 100644 --- a/templates/header.php +++ b/templates/header.php @@ -24,20 +24,25 @@ $isSurveyPage = basename($_SERVER['PHP_SELF']) == 'survey.php';