34968-vm/profile.php
Flatlogic Bot a6434721b7 V5
2025-10-15 00:36:03 +00:00

107 lines
4.9 KiB
PHP

<?php
session_start();
require_once 'db/config.php';
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit();
}
$user_id = $_SESSION['user_id'];
// Fetch user's orders and restaurant info
$stmt = $db()->prepare("
SELECT o.*, r.id AS restaurant_id, r.name AS restaurant_name
FROM orders o
JOIN order_items oi ON o.id = oi.order_id
JOIN menu_items mi ON oi.menu_item_id = mi.id
JOIN restaurants r ON mi.restaurant_id = r.id
WHERE o.user_id = ?
GROUP BY o.id
ORDER BY o.order_date DESC
");
$stmt->execute([$user_id]);
$orders = $stmt->fetchAll(PDO::FETCH_ASSOC);
include 'header.php';
?>
<div class="container mt-5">
<h2>My Profile</h2>
<h4>My Orders</h4>
<?php
if (isset($_SESSION['rating_success'])) {
echo '<div class="alert alert-success">' . $_SESSION['rating_success'] . '</div>';
unset($_SESSION['rating_success']);
}
if (isset($_SESSION['rating_error'])) {
echo '<div class="alert alert-danger">' . $_SESSION['rating_error'] . '</div>';
unset($_SESSION['rating_error']);
}
?>
<?php if (count($orders) > 0): ?>
<table class="table table-bordered">
<thead>
<tr>
<th>Order ID</th>
<th>Order Date</th>
<th>Restaurant</th>
<th>Total Amount</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($orders as $order): ?>
<tr>
<td><?php echo htmlspecialchars($order['id']); ?></td>
<td><?php echo htmlspecialchars($order['order_date']); ?></td>
<td><?php echo htmlspecialchars($order['restaurant_name']); ?></td>
<td>$<?php echo htmlspecialchars(number_format($order['total_amount'], 2)); ?></td>
<td><?php echo htmlspecialchars($order['status']); ?></td>
<td>
<a href="order_details.php?order_id=<?php echo $order['id']; ?>" class="btn btn-primary">View Details</a>
<?php if ($order['status'] == 'Completed'): ?>
<button type="button" class="btn btn-success" data-bs-toggle="modal" data-bs-target="#rateModal-<?php echo $order['id']; ?>">
Rate Restaurant
</button>
<?php endif; ?>
</td>
</tr>
<!-- Rating Modal -->
<div class="modal fade" id="rateModal-<?php echo $order['id']; ?>" tabindex="-1" aria-labelledby="rateModalLabel-<?php echo $order['id']; ?>" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="rateModalLabel-<?php echo $order['id']; ?>">Rate <?php echo htmlspecialchars($order['restaurant_name']); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form action="rate.php" method="POST">
<input type="hidden" name="order_id" value="<?php echo $order['id']; ?>">
<input type="hidden" name="restaurant_id" value="<?php echo $order['restaurant_id']; ?>">
<div class="mb-3">
<label for="rating-<?php echo $order['id']; ?>" class="form-label">Rating (1-5)</label>
<input type="number" class="form-control" id="rating-<?php echo $order['id']; ?>" name="rating" min="1" max="5" required>
</div>
<div class="mb-3">
<label for="comment-<?php echo $order['id']; ?>" class="form-label">Comment</label>
<textarea class="form-control" id="comment-<?php echo $order['id']; ?>" name="comment" rows="3"></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit Rating</button>
</form>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
</tbody>
</table>
<?php else: ?>
<p>You have no past orders.</p>
<?php endif; ?>
</div>
<?php include 'footer.php'; ?>