36716-vm/review-booking.php
2025-12-07 05:00:42 +00:00

114 lines
4.4 KiB
PHP

<?php
session_start();
require_once 'db/config.php';
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'client') {
header('Location: login.php');
exit;
}
if (!isset($_GET['id'])) {
header('Location: dashboard.php?status=error');
exit;
}
$booking_id = $_GET['id'];
$client_id = $_SESSION['user_id'];
// Verify the client owns this booking and it's completed
$stmt = db()->prepare("SELECT * FROM bookings WHERE id = ? AND client_id = ? AND status = 'completed'");
$stmt->execute([$booking_id, $client_id]);
$booking = $stmt->fetch();
if (!$booking) {
header('Location: dashboard.php?status=error');
exit;
}
// Check if already reviewed
$stmt = db()->prepare("SELECT id FROM reviews WHERE booking_id = ?");
$stmt->execute([$booking_id]);
if ($stmt->fetch()) {
header('Location: dashboard.php?status=already_reviewed');
exit;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$rating = $_POST['rating'] ?? null;
$review = $_POST['review'] ?? null;
$coach_id = $booking['coach_id'];
if ($rating && $rating >= 1 && $rating <= 5) {
$stmt = db()->prepare("INSERT INTO reviews (booking_id, coach_id, client_id, rating, review) VALUES (?, ?, ?, ?, ?)");
$stmt->execute([$booking_id, $coach_id, $client_id, $rating, $review]);
header('Location: dashboard.php?status=review_success');
exit;
} else {
$error = "Please select a rating between 1 and 5.";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Review Booking - CoachConnect</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css">
</head>
<body class="bg-gray-50">
<header class="bg-white shadow-md">
<nav class="container mx-auto px-6 py-4 flex justify-between items-center">
<a href="index.php" class="text-2xl font-bold text-gray-800">CoachConnect</a>
<div class="flex space-x-4">
<a href="dashboard.php" class="text-gray-600 hover:text-blue-500">Dashboard</a>
<a href="logout.php" class="text-gray-600 hover:text-blue-500">Logout</a>
</div>
</nav>
</header>
<main class="container mx-auto px-6 py-12">
<div class="bg-white shadow-md rounded-lg p-6">
<h1 class="text-2xl font-bold text-gray-800 mb-4">Review Your Session</h1>
<?php if (isset($error)): ?>
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative mb-4" role="alert">
<span class="block sm:inline"><?php echo $error; ?></span>
</div>
<?php endif; ?>
<form action="review-booking.php?id=<?php echo $booking_id; ?>" method="post">
<div class="mb-4">
<label class="block text-gray-700 text-sm font-bold mb-2">Rating</label>
<div class="flex space-x-2">
<?php for ($i = 1; $i <= 5; $i++): ?>
<label class="flex items-center space-x-1">
<input type="radio" name="rating" value="<?php echo $i; ?>" class="form-radio text-blue-500" required>
<span><?php echo $i; ?> &#9733;</span>
</label>
<?php endfor; ?>
</div>
</div>
<div class="mb-4">
<label for="review" class="block text-gray-700 text-sm font-bold mb-2">Review (optional)</label>
<textarea name="review" id="review" rows="4" class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"></textarea>
</div>
<div class="mt-6">
<button type="submit" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline">
Submit Review
</button>
</div>
</form>
</div>
</main>
<footer class="bg-gray-800 text-white py-6 mt-12">
<div class="container mx-auto px-6 text-center">
<p>&copy; <?php echo date("Y"); ?> CoachConnect. All rights reserved.</p>
</div>
</footer>
</body>
</html>