151 lines
7.3 KiB
PHP
151 lines
7.3 KiB
PHP
<?php
|
|
session_start();
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
// If user is not logged in, redirect to login page
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header("Location: login.php");
|
|
exit;
|
|
}
|
|
|
|
$user_id = $_SESSION['user_id'];
|
|
$errors = [];
|
|
$success_message = '';
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
$goal = $_POST['goal'] ?? '';
|
|
$skill_level = $_POST['skill_level'] ?? '';
|
|
$interests = $_POST['interests'] ?? [];
|
|
|
|
if (empty($goal) || empty($skill_level) || empty($interests)) {
|
|
$errors[] = "Please answer all questions.";
|
|
} else {
|
|
$profile_data = [
|
|
'goal' => $goal,
|
|
'skill_level' => $skill_level,
|
|
'interests' => $interests
|
|
];
|
|
$profile_json = json_encode($profile_data);
|
|
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("UPDATE users SET profile = ? WHERE id = ?");
|
|
if ($stmt->execute([$profile_json, $user_id])) {
|
|
$_SESSION['success_message'] = "Thank you! Your personalized recommendations are ready.";
|
|
header("Location: dashboard.php");
|
|
exit;
|
|
} else {
|
|
$errors[] = "Failed to save your preferences. Please try again.";
|
|
}
|
|
} catch (PDOException $e) {
|
|
$errors[] = "Database error: " . $e->getMessage();
|
|
}
|
|
}
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Personalization Quiz - SunSkills</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
</head>
|
|
<body>
|
|
|
|
<nav class="navbar navbar-expand-lg navbar-light sticky-top">
|
|
<div class="container">
|
|
<a class="navbar-brand" href="index.php">SunSkills</a>
|
|
</div>
|
|
</nav>
|
|
|
|
<main class="container py-5">
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-8">
|
|
<div class="card">
|
|
<div class="card-body p-5">
|
|
<h1 class="card-title text-center mb-4">Tell Us About Yourself</h1>
|
|
<p class="text-center text-muted mb-5">Help us tailor your learning experience.</p>
|
|
|
|
<?php if (!empty($errors)): ?>
|
|
<div class="alert alert-danger">
|
|
<?php foreach ($errors as $error): ?>
|
|
<p class="mb-0"><?php echo $error; ?></p>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<form action="quiz.php" method="POST">
|
|
<!-- Question 1: Goal -->
|
|
<div class="mb-4">
|
|
<p class="fw-bold">1. What is your primary goal?</p>
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="radio" name="goal" id="goal_earn" value="earn_money" required>
|
|
<label class="form-check-label" for="goal_earn">Earn more money</label>
|
|
</div>
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="radio" name="goal" id="goal_business" value="start_business">
|
|
<label class="form-check-label" for="goal_business">Start a business</label>
|
|
</div>
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="radio" name="goal" id="goal_hobby" value="learn_hobby">
|
|
<label class="form-check-label" for="goal_hobby">Learn a new hobby</label>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Question 2: Skill Level -->
|
|
<div class="mb-4">
|
|
<p class="fw-bold">2. What is your current skill level in your area of interest?</p>
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="radio" name="skill_level" id="level_beginner" value="beginner" required>
|
|
<label class="form-check-label" for="level_beginner">Beginner (Just starting out)</label>
|
|
</div>
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="radio" name="skill_level" id="level_intermediate" value="intermediate">
|
|
<label class="form-check-label" for="level_intermediate">Intermediate (I have some experience)</label>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Question 3: Interests -->
|
|
<div class="mb-4">
|
|
<p class="fw-bold">3. Which topics are you most interested in?</p>
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="checkbox" name="interests[]" id="interest_auto" value="auto">
|
|
<label class="form-check-label" for="interest_auto">Automotive & Vehicle Repair</label>
|
|
</div>
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="checkbox" name="interests[]" id="interest_electronics" value="electronics">
|
|
<label class="form-check-label" for="interest_electronics">Electronics & Gadgets</label>
|
|
</div>
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="checkbox" name="interests[]" id="interest_cooking" value="cooking">
|
|
<label class="form-check-label" for="interest_cooking">Cooking & Culinary Skills</label>
|
|
</div>
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="checkbox" name="interests[]" id="interest_home" value="home">
|
|
<label class="form-check-label" for="interest_home">Home Improvement</label>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="d-grid">
|
|
<button type="submit" class="btn btn-primary btn-lg">Submit Answers</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<footer class="footer mt-auto py-3 bg-light">
|
|
<div class="container text-center">
|
|
<p>© <?php echo date("Y"); ?> SunSkills. All Rights Reserved.</p>
|
|
<p><a href="privacy.php">Privacy Policy</a></p>
|
|
</div>
|
|
</footer>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|