131 lines
4.9 KiB
PHP
131 lines
4.9 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: login.php?redirect_to=rewards.php');
|
|
exit();
|
|
}
|
|
|
|
require_once 'db/config.php';
|
|
|
|
$user_id = $_SESSION['user_id'];
|
|
$points = 0;
|
|
$tier = 'Bronze';
|
|
$history = [];
|
|
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("SELECT points, tier FROM user_rewards WHERE user_id = ?");
|
|
$stmt->execute([$user_id]);
|
|
$result = $stmt->fetch();
|
|
|
|
if ($result) {
|
|
$points = $result['points'];
|
|
$tier = $result['tier'];
|
|
} else {
|
|
// If user has no entry, create one
|
|
$insert_stmt = $pdo->prepare("INSERT INTO user_rewards (user_id, points, tier) VALUES (?, ?, ?)");
|
|
$insert_stmt->execute([$user_id, 0, 'Bronze']);
|
|
}
|
|
|
|
$history_stmt = $pdo->prepare("SELECT points_change, reason, created_at FROM reward_history WHERE user_id = ? ORDER BY created_at DESC LIMIT 10");
|
|
$history_stmt->execute([$user_id]);
|
|
$history = $history_stmt->fetchAll();
|
|
|
|
} catch (PDOException $e) {
|
|
// Handle database errors
|
|
error_log($e->getMessage());
|
|
// You might want to show a generic error message to the user
|
|
}
|
|
|
|
|
|
include 'header.php';
|
|
?>
|
|
|
|
<div class="container" style="padding-top: 20px; padding-bottom: 20px;">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<h1 class="card-title">Your Rewards</h1>
|
|
<p class="card-text">Welcome to the MajuroEats Rewards Program! Here you can see your points, your tier, and the rewards you can claim.</p>
|
|
|
|
<?php if (isset($_SESSION['success_message'])): ?>
|
|
<div class="alert alert-success mt-3" role="alert">
|
|
<?php echo htmlspecialchars($_SESSION['success_message']); ?>
|
|
</div>
|
|
<?php unset($_SESSION['success_message']); ?>
|
|
<?php endif; ?>
|
|
|
|
<?php if (isset($_SESSION['error_message'])): ?>
|
|
<div class="alert alert-danger mt-3" role="alert">
|
|
<?php echo htmlspecialchars($_SESSION['error_message']); ?>
|
|
</div>
|
|
<?php unset($_SESSION['error_message']); ?>
|
|
<?php endif; ?>
|
|
|
|
<div class="mt-4">
|
|
<h2>Your Current Points</h2>
|
|
<p>You have <strong><?php echo htmlspecialchars($points); ?> points</strong>.</p>
|
|
</div>
|
|
|
|
<div class="mt-4">
|
|
<h2>Your Current Tier</h2>
|
|
<p>You are in the <strong><?php echo htmlspecialchars($tier); ?></strong> tier.</p>
|
|
</div>
|
|
|
|
<div class="mt-4">
|
|
<h2>Reward Tiers</h2>
|
|
<ul class="list-group">
|
|
<li class="list-group-item"><strong>Bronze</strong>: 0+ points</li>
|
|
<li class="list-group-item"><strong>Silver</strong>: 1000+ points (1.2x point multiplier)</li>
|
|
<li class="list-group-item"><strong>Gold</strong>: 5000+ points (1.5x point multiplier)</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="mt-4">
|
|
<h2>Available Rewards</h2>
|
|
<ul class="list-group">
|
|
<li class="list-group-item"><strong>$5 off</strong> your next order (500 points)</li>
|
|
<li class="list-group-item"><strong>Free delivery</strong> on your next order (1000 points)</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="mt-4">
|
|
<h2>Redeem Points</h2>
|
|
<form action="redeem_points.php" method="post">
|
|
<div class="list-group">
|
|
<label class="list-group-item">
|
|
<input type="radio" name="reward" value="5_off" required>
|
|
<strong>$5 off coupon</strong> - 500 points
|
|
</label>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary mt-3">Redeem</button>
|
|
</form>
|
|
</div>
|
|
|
|
<div class="mt-4">
|
|
<h2>Reward History</h2>
|
|
<table class="table">
|
|
<thead>
|
|
<tr>
|
|
<th>Date</th>
|
|
<th>Reason</th>
|
|
<th>Points</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($history as $entry): ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars(date('Y-m-d', strtotime($entry['created_at']))); ?></td>
|
|
<td><?php echo htmlspecialchars($entry['reason']); ?></td>
|
|
<td><?php echo htmlspecialchars($entry['points_change']); ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include 'footer.php'; ?>
|