V18
This commit is contained in:
parent
64ad8fe24a
commit
44a5c2df2d
@ -14,19 +14,70 @@ unset($_SESSION['login_error']);
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Admin Login</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-icons/1.11.3/font/bootstrap-icons.min.css">
|
||||
<style>
|
||||
body, html {
|
||||
height: 100%;
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
.main-container {
|
||||
display: flex;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
.form-section {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 50%;
|
||||
padding: 40px;
|
||||
}
|
||||
.image-section {
|
||||
width: 50%;
|
||||
background: url('https://images.pexels.com/photos/376464/pexels-photo-376464.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2') no-repeat center center;
|
||||
background-size: cover;
|
||||
}
|
||||
.form-container {
|
||||
width: 100%;
|
||||
max-width: 450px;
|
||||
}
|
||||
.form-container h1 {
|
||||
font-weight: 700;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
.form-container .form-text {
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
.form-control {
|
||||
padding: 0.75rem 1rem;
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
.btn-primary {
|
||||
padding: 0.75rem;
|
||||
border-radius: 0.5rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
.back-button {
|
||||
position: absolute;
|
||||
top: 20px;
|
||||
left: 20px;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container mt-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Admin Login
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<a href="../index.php" class="btn btn-light back-button"><i class="bi bi-arrow-left"></i> Back to Site</a>
|
||||
<div class="main-container">
|
||||
<div class="form-section">
|
||||
<div class="form-container">
|
||||
<h1>Admin Login</h1>
|
||||
<p class="text-muted">Please enter your credentials to access the admin dashboard.</p>
|
||||
|
||||
<?php if ($error): ?>
|
||||
<div class="alert alert-danger"><?php echo htmlspecialchars($error); ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form action="login_process.php" method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">Email</label>
|
||||
@ -36,12 +87,11 @@ unset($_SESSION['login_error']);
|
||||
<label for="password" class="form-label">Password</label>
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Login</button>
|
||||
<button type="submit" class="btn btn-primary w-100">Login</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="image-section"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
15
footer.php
15
footer.php
@ -5,5 +5,20 @@
|
||||
</footer>
|
||||
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
|
||||
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
||||
|
||||
<!--Start of Tawk.to Script-->
|
||||
<script type="text/javascript">
|
||||
var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
|
||||
(function(){
|
||||
var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
|
||||
s1.async=true;
|
||||
s1.src='https://embed.tawk.to/68ed54c73744141950704532/1j7fh6b6i';
|
||||
s1.charset='UTF-8';
|
||||
s1.setAttribute('crossorigin','*');
|
||||
s0.parentNode.insertBefore(s1,s0);
|
||||
})();
|
||||
</script>
|
||||
<!--End of Tawk.to Script-->
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@ -27,9 +27,9 @@ session_start();
|
||||
<ul class="nav-links">
|
||||
<li><a href="/">Home</a></li>
|
||||
<li><a href="index.php">Restaurants</a></li>
|
||||
<li><a href="#">Rewards</a></li>
|
||||
<li><a href="rewards.php">Rewards</a></li>
|
||||
<li><a href="driver_signup.php">Driver</a></li>
|
||||
<li><a href="#">Help</a></li>
|
||||
<li><a href="help.php">Help</a></li>
|
||||
</ul>
|
||||
<div class="nav-actions">
|
||||
<?php if (isset($_SESSION['user_id'])): ?>
|
||||
|
||||
135
help.php
Normal file
135
help.php
Normal file
@ -0,0 +1,135 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'header.php';
|
||||
?>
|
||||
|
||||
<style>
|
||||
.faq-section {
|
||||
background-color: #f8f9fa;
|
||||
padding: 40px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
.faq-item {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.faq-question {
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
position: relative;
|
||||
}
|
||||
.faq-question::after {
|
||||
content: '+';
|
||||
position: absolute;
|
||||
right: 0;
|
||||
transition: transform 0.3s;
|
||||
}
|
||||
.faq-answer {
|
||||
display: none;
|
||||
margin-top: 10px;
|
||||
padding-left: 20px;
|
||||
border-left: 2px solid #007bff;
|
||||
}
|
||||
.faq-item.active .faq-question::after {
|
||||
transform: rotate(45deg);
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="container my-5">
|
||||
<div class="text-center mb-5">
|
||||
<h1 class="display-4">Help & Support</h1>
|
||||
<p class="lead text-muted">We're here to help. Find answers to common questions or get in touch with our team.</p>
|
||||
</div>
|
||||
|
||||
<?php if (isset($_SESSION['success_message'])): ?>
|
||||
<div class="alert alert-success">
|
||||
<?php echo $_SESSION['success_message']; unset($_SESSION['success_message']); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION['error_message'])): ?>
|
||||
<div class="alert alert-danger">
|
||||
<?php echo $_SESSION['error_message']; unset($_SESSION['error_message']); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="row g-5">
|
||||
<div class="col-lg-6">
|
||||
<h3 class="mb-4">Contact Us</h3>
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body p-4">
|
||||
<form action="help_process.php" method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Full Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">Email Address</label>
|
||||
<input type="email" class="form-control" id="email" name="email" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="phone" class="form-label">Phone Number (Optional)</label>
|
||||
<input type="tel" class="form-control" id="phone" name="phone">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="message" class="form-label">How can we help?</label>
|
||||
<textarea class="form-control" id="message" name="message" rows="5" required></textarea>
|
||||
</div>
|
||||
<div class="d-grid">
|
||||
<button type="submit" class="btn btn-primary btn-lg">Send Message</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-lg-6">
|
||||
<h3 class="mb-4">Frequently Asked Questions</h3>
|
||||
<div class="faq-section">
|
||||
<div class="faq-item">
|
||||
<div class="faq-question">How do I track my order?</div>
|
||||
<div class="faq-answer">
|
||||
<p>You can track your order in real-time from the "Order Status" page. Once a driver is assigned, you'll see their location on the map.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="faq-item">
|
||||
<div class="faq-question">What payment methods do you accept?</div>
|
||||
<div class="faq-answer">
|
||||
<p>We accept all major credit cards, PayPal, and Stripe. You can save your payment method for faster checkout next time.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="faq-item">
|
||||
<div class="faq-question">How is the delivery fee calculated?</div>
|
||||
<div class="faq-answer">
|
||||
<p>The delivery fee is based on the distance between the restaurant and your location. You'll see the exact fee at checkout before you confirm your order.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="faq-item">
|
||||
<div class="faq-question">Can I change my delivery address?</div>
|
||||
<div class="faq-answer">
|
||||
<p>If the restaurant has not yet accepted your order, you may be able to cancel it and place a new one with the correct address. Once the order is being prepared, it cannot be changed.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const faqItems = document.querySelectorAll('.faq-item');
|
||||
faqItems.forEach(item => {
|
||||
const question = item.querySelector('.faq-question');
|
||||
question.addEventListener('click', () => {
|
||||
const answer = item.querySelector('.faq-answer');
|
||||
if (item.classList.contains('active')) {
|
||||
item.classList.remove('active');
|
||||
answer.style.display = 'none';
|
||||
} else {
|
||||
item.classList.add('active');
|
||||
answer.style.display = 'block';
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php require_once 'footer.php'; ?>
|
||||
45
help_process.php
Normal file
45
help_process.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once __DIR__ . '/mail/MailService.php';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$name = trim($_POST['name'] ?? '');
|
||||
$email = trim($_POST['email'] ?? '');
|
||||
$phone = trim($_POST['phone'] ?? '');
|
||||
$message = trim($_POST['message'] ?? '');
|
||||
|
||||
if (empty($name) || empty($email) || empty($message)) {
|
||||
$_SESSION['error_message'] = 'Please fill in all required fields.';
|
||||
header('Location: help.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$_SESSION['error_message'] = 'Invalid email format.';
|
||||
header('Location: help.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$subject = 'New Help Request from ' . $name;
|
||||
$html_content = "<p><strong>Name:</strong> {$name}</p>\n <p><strong>Email:</strong> {$email}</p>\n <p><strong>Phone:</strong> {$phone}</p>\n <p><strong>Message:</strong></p>\n <p>{$message}</p>";
|
||||
$text_content = "Name: {$name}\nEmail: {$email}\nPhone: {$phone}\nMessage:\n{$message}";
|
||||
|
||||
// The recipient's email address. Using environment variable or a default.
|
||||
$to = getenv('MAIL_TO') ?: 'support@majuroeats.com';
|
||||
|
||||
$result = MailService::sendMail($to, $subject, $html_content, $text_content, ['reply_to' => $email]);
|
||||
|
||||
if ($result['success']) {
|
||||
$_SESSION['success_message'] = 'Thank you for your message! We will get back to you shortly.';
|
||||
} else {
|
||||
$_SESSION['error_message'] = 'Sorry, there was an error sending your message. Please try again later.';
|
||||
// Optional: Log the error for debugging
|
||||
// error_log('MailService Error: ' . $result['error']);
|
||||
}
|
||||
|
||||
header('Location: help.php');
|
||||
exit;
|
||||
} else {
|
||||
header('Location: help.php');
|
||||
exit;
|
||||
}
|
||||
118
login.php
118
login.php
@ -1,24 +1,120 @@
|
||||
<?php include 'header.php'; ?>
|
||||
<?php
|
||||
session_start();
|
||||
if (isset($_SESSION['user_id'])) {
|
||||
header('Location: index.php');
|
||||
exit();
|
||||
}
|
||||
$page_title = "Login";
|
||||
include 'header.php';
|
||||
?>
|
||||
|
||||
<main>
|
||||
<div class="auth-container">
|
||||
<h1>Login</h1>
|
||||
<form action="login_process.php" method="POST">
|
||||
<style>
|
||||
.form-container {
|
||||
display: flex;
|
||||
min-height: 80vh;
|
||||
}
|
||||
.form-column {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 40px;
|
||||
}
|
||||
.image-column {
|
||||
flex: 1;
|
||||
background: url('assets/images/hero.jpg') no-repeat center center;
|
||||
background-size: cover;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
color: white;
|
||||
text-align: center;
|
||||
}
|
||||
.form-box {
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
}
|
||||
.form-box h2 {
|
||||
margin-bottom: 20px;
|
||||
font-size: 2.5rem;
|
||||
font-weight: bold;
|
||||
}
|
||||
.form-box .form-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.form-box .form-control {
|
||||
border-radius: 5px;
|
||||
padding: 15px;
|
||||
border: 1px solid #ddd;
|
||||
}
|
||||
.form-box .btn-primary {
|
||||
width: 100%;
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
background-color: #007bff;
|
||||
border: none;
|
||||
}
|
||||
.social-login {
|
||||
margin-top: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
.social-login p {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.social-login .btn {
|
||||
width: 100%;
|
||||
margin-bottom: 10px;
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
.social-login .btn-google {
|
||||
background-color: #db4437;
|
||||
color: white;
|
||||
}
|
||||
.social-login .btn-facebook {
|
||||
background-color: #3b5998;
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="form-container">
|
||||
<div class="form-column">
|
||||
<div class="form-box">
|
||||
<h2>Welcome Back!</h2>
|
||||
<p>Log in to continue to your account.</p>
|
||||
<?php if (isset($_GET['error'])): ?>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<?php echo htmlspecialchars($_GET['error']); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<form action="login_process.php" method="post">
|
||||
<div class="form-group">
|
||||
<label for="email">Email</label>
|
||||
<input type="email" id="email" name="email" required>
|
||||
<label for="email">Email address</label>
|
||||
<input type="email" class="form-control" id="email" name="email" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password">Password</label>
|
||||
<input type="password" id="password" name="password" required>
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
</div>
|
||||
<button type="submit" class="btn-submit">Login</button>
|
||||
<button type="submit" class="btn btn-primary">Login</button>
|
||||
</form>
|
||||
<div class="form-footer">
|
||||
<div class="social-login">
|
||||
<p>Or log in with</p>
|
||||
<button class="btn btn-google"><i class="fab fa-google"></i> Log in with Google</button>
|
||||
<button class="btn btn-facebook"><i class="fab fa-facebook-f"></i> Log in with Facebook</button>
|
||||
</div>
|
||||
<div class="mt-3 text-center">
|
||||
<p>Don't have an account? <a href="signup.php">Sign up</a></p>
|
||||
<p><a href="forgot_password.php">Forgot your password?</a></p>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
<div class="image-column">
|
||||
<div>
|
||||
<h1>Your next meal, delivered.</h1>
|
||||
<p>The best local restaurants, right at your fingertips.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include 'footer.php'; ?>
|
||||
1
migrations/20251016_add_referral_code_to_users.sql
Normal file
1
migrations/20251016_add_referral_code_to_users.sql
Normal file
@ -0,0 +1 @@
|
||||
ALTER TABLE users ADD COLUMN referral_code VARCHAR(255) UNIQUE;
|
||||
1
migrations/20251016_add_tier_to_user_rewards.sql
Normal file
1
migrations/20251016_add_tier_to_user_rewards.sql
Normal file
@ -0,0 +1 @@
|
||||
ALTER TABLE user_rewards ADD COLUMN tier VARCHAR(255) NOT NULL DEFAULT 'Bronze';
|
||||
@ -0,0 +1 @@
|
||||
ALTER TABLE user_rewards ADD UNIQUE (user_id);
|
||||
8
migrations/20251016_create_reward_history_table.sql
Normal file
8
migrations/20251016_create_reward_history_table.sql
Normal file
@ -0,0 +1,8 @@
|
||||
CREATE TABLE IF NOT EXISTS reward_history (
|
||||
id SERIAL PRIMARY KEY,
|
||||
user_id INT NOT NULL,
|
||||
points_change INT NOT NULL,
|
||||
reason VARCHAR(255) NOT NULL,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id)
|
||||
);
|
||||
6
migrations/20251016_create_rewards_table.sql
Normal file
6
migrations/20251016_create_rewards_table.sql
Normal file
@ -0,0 +1,6 @@
|
||||
CREATE TABLE IF NOT EXISTS user_rewards (
|
||||
id SERIAL PRIMARY KEY,
|
||||
user_id INT NOT NULL,
|
||||
points INT NOT NULL DEFAULT 0,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id)
|
||||
);
|
||||
@ -72,6 +72,43 @@ try {
|
||||
$stmt->execute([$order_id, $item['menu_item_id'], $item['quantity'], $item['price']]);
|
||||
}
|
||||
|
||||
// Award points to the user
|
||||
if (!$is_guest) {
|
||||
$stmt = $pdo->prepare("SELECT points, tier FROM user_rewards WHERE user_id = ?");
|
||||
$stmt->execute([$user_id]);
|
||||
$user_reward = $stmt->fetch();
|
||||
|
||||
$current_points = $user_reward ? $user_reward['points'] : 0;
|
||||
$current_tier = $user_reward ? $user_reward['tier'] : 'Bronze';
|
||||
|
||||
$multiplier = 1;
|
||||
if ($current_tier === 'Silver') {
|
||||
$multiplier = 1.2;
|
||||
} elseif ($current_tier === 'Gold') {
|
||||
$multiplier = 1.5;
|
||||
}
|
||||
|
||||
$points_to_award = floor($total_price * $multiplier);
|
||||
$new_total_points = $current_points + $points_to_award;
|
||||
|
||||
$new_tier = $current_tier;
|
||||
if ($new_total_points >= 5000) {
|
||||
$new_tier = 'Gold';
|
||||
} elseif ($new_total_points >= 1000) {
|
||||
$new_tier = 'Silver';
|
||||
}
|
||||
|
||||
$reward_stmt = $pdo->prepare(
|
||||
"INSERT INTO user_rewards (user_id, points, tier) VALUES (?, ?, ?) " .
|
||||
"ON DUPLICATE KEY UPDATE points = VALUES(points), tier = VALUES(tier)"
|
||||
);
|
||||
$reward_stmt->execute([$user_id, $new_total_points, $new_tier]);
|
||||
|
||||
// Log the transaction in reward_history
|
||||
$history_stmt = $pdo->prepare("INSERT INTO reward_history (user_id, points_change, reason) VALUES (?, ?, ?)");
|
||||
$history_stmt->execute([$user_id, $points_to_award, 'Order completion']);
|
||||
}
|
||||
|
||||
// Clear cart
|
||||
$stmt = $pdo->prepare("DELETE FROM cart WHERE $cart_column = ?");
|
||||
$stmt->execute([$cart_identifier]);
|
||||
|
||||
80
redeem_points.php
Normal file
80
redeem_points.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'db/config.php';
|
||||
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header('Location: login.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST' || !isset($_POST['reward'])) {
|
||||
header('Location: rewards.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
$user_id = $_SESSION['user_id'];
|
||||
$reward = $_POST['reward'];
|
||||
|
||||
$rewards = [
|
||||
'5_off' => [
|
||||
'points' => 500,
|
||||
'discount' => 5,
|
||||
'type' => 'fixed'
|
||||
]
|
||||
];
|
||||
|
||||
if (!array_key_exists($reward, $rewards)) {
|
||||
$_SESSION['error_message'] = 'Invalid reward selected.';
|
||||
header('Location: rewards.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
$reward_details = $rewards[$reward];
|
||||
$points_required = $reward_details['points'];
|
||||
|
||||
$pdo = db();
|
||||
|
||||
// Get user's current points
|
||||
$stmt = $pdo->prepare("SELECT points FROM user_rewards WHERE user_id = ?");
|
||||
$stmt->execute([$user_id]);
|
||||
$user_reward = $stmt->fetch();
|
||||
|
||||
$current_points = $user_reward ? $user_reward['points'] : 0;
|
||||
|
||||
if ($current_points < $points_required) {
|
||||
$_SESSION['error_message'] = 'You do not have enough points to redeem this reward.';
|
||||
header('Location: rewards.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
// Deduct points and create coupon
|
||||
try {
|
||||
$pdo->beginTransaction();
|
||||
|
||||
// Deduct points
|
||||
$new_points = $current_points - $points_required;
|
||||
$stmt = $pdo->prepare("UPDATE user_rewards SET points = ? WHERE user_id = ?");
|
||||
$stmt->execute([$new_points, $user_id]);
|
||||
|
||||
// Log history
|
||||
$stmt = $pdo->prepare("INSERT INTO reward_history (user_id, points_change, reason) VALUES (?, ?, ?)");
|
||||
$stmt->execute([$user_id, -$points_required, 'Redeemed ' . $reward]);
|
||||
|
||||
// Create coupon
|
||||
$coupon_code = 'REWARD-' . strtoupper(bin2hex(random_bytes(4))) . '-' . $user_id;
|
||||
$stmt = $pdo->prepare("INSERT INTO coupons (code, type, value, expires_at, is_active) VALUES (?, ?, ?, DATE_ADD(NOW(), INTERVAL 30 DAY), 1)");
|
||||
$stmt->execute([$coupon_code, $reward_details['type'], $reward_details['discount']]);
|
||||
|
||||
$pdo->commit();
|
||||
|
||||
$_SESSION['success_message'] = 'Reward redeemed successfully! Your coupon code is: ' . $coupon_code;
|
||||
header('Location: rewards.php');
|
||||
exit();
|
||||
|
||||
} catch (Exception $e) {
|
||||
$pdo->rollBack();
|
||||
$_SESSION['error_message'] = 'There was an error redeeming your reward. Please try again.';
|
||||
error_log($e->getMessage());
|
||||
header('Location: rewards.php');
|
||||
exit();
|
||||
}
|
||||
130
rewards.php
Normal file
130
rewards.php
Normal file
@ -0,0 +1,130 @@
|
||||
<?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'; ?>
|
||||
122
signup.php
122
signup.php
@ -1,27 +1,123 @@
|
||||
<?php include 'header.php'; ?>
|
||||
<?php
|
||||
session_start();
|
||||
if (isset($_SESSION['user_id'])) {
|
||||
header('Location: index.php');
|
||||
exit();
|
||||
}
|
||||
$page_title = "Sign Up";
|
||||
include 'header.php';
|
||||
?>
|
||||
|
||||
<main>
|
||||
<div class="auth-container">
|
||||
<h1>Create Account</h1>
|
||||
<form action="signup_process.php" method="POST">
|
||||
<style>
|
||||
.form-container {
|
||||
display: flex;
|
||||
min-height: 80vh;
|
||||
}
|
||||
.form-column {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 40px;
|
||||
}
|
||||
.image-column {
|
||||
flex: 1;
|
||||
background: url('assets/images/hero.jpg') no-repeat center center;
|
||||
background-size: cover;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
color: white;
|
||||
text-align: center;
|
||||
}
|
||||
.form-box {
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
}
|
||||
.form-box h2 {
|
||||
margin-bottom: 20px;
|
||||
font-size: 2.5rem;
|
||||
font-weight: bold;
|
||||
}
|
||||
.form-box .form-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.form-box .form-control {
|
||||
border-radius: 5px;
|
||||
padding: 15px;
|
||||
border: 1px solid #ddd;
|
||||
}
|
||||
.form-box .btn-primary {
|
||||
width: 100%;
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
background-color: #007bff;
|
||||
border: none;
|
||||
}
|
||||
.social-login {
|
||||
margin-top: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
.social-login p {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.social-login .btn {
|
||||
width: 100%;
|
||||
margin-bottom: 10px;
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
.social-login .btn-google {
|
||||
background-color: #db4437;
|
||||
color: white;
|
||||
}
|
||||
.social-login .btn-facebook {
|
||||
background-color: #3b5998;
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="form-container">
|
||||
<div class="form-column">
|
||||
<div class="form-box">
|
||||
<h2>Create Your Account</h2>
|
||||
<p>Sign up to start ordering your favorite food.</p>
|
||||
<?php if (isset($_GET['error'])): ?>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<?php echo htmlspecialchars($_GET['error']); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<form action="signup_process.php" method="post">
|
||||
<div class="form-group">
|
||||
<label for="name">Name</label>
|
||||
<input type="text" id="name" name="name" required>
|
||||
<label for="name">Full Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="email">Email</label>
|
||||
<input type="email" id="email" name="email" required>
|
||||
<label for="email">Email address</label>
|
||||
<input type="email" class="form-control" id="email" name="email" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password">Password</label>
|
||||
<input type="password" id="password" name="password" required>
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
</div>
|
||||
<button type="submit" class="btn-submit">Sign Up</button>
|
||||
<button type="submit" class="btn btn-primary">Sign Up</button>
|
||||
</form>
|
||||
<div class="form-footer">
|
||||
<div class="social-login">
|
||||
<p>Or sign up with</p>
|
||||
<button class="btn btn-google"><i class="fab fa-google"></i> Sign up with Google</button>
|
||||
<button class="btn btn-facebook"><i class="fab fa-facebook-f"></i> Sign up with Facebook</button>
|
||||
</div>
|
||||
<div class="mt-3 text-center">
|
||||
<p>Already have an account? <a href="login.php">Log in</a></p>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
<div class="image-column">
|
||||
<div>
|
||||
<h1>Your next meal, delivered.</h1>
|
||||
<p>The best local restaurants, right at your fingertips.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include 'footer.php'; ?>
|
||||
Loading…
x
Reference in New Issue
Block a user