Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2928381868 | ||
|
|
13e2d4e415 | ||
|
|
4eda045a71 | ||
|
|
f31b27889f | ||
|
|
27d5988203 |
118
account_statement.php
Normal file
118
account_statement.php
Normal file
@ -0,0 +1,118 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
// If the user is not logged in, redirect to the login page
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once 'db/config.php';
|
||||
|
||||
// Fetch user's orders from the database
|
||||
$user_id = $_SESSION['user_id'];
|
||||
$stmt = db()->prepare("SELECT * FROM orders WHERE user_id = ? ORDER BY order_date DESC");
|
||||
$stmt->execute([$user_id]);
|
||||
$orders = $stmt->fetchAll();
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Account Statement</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="index.php">Fuel Management</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav ms-auto">
|
||||
<?php if (isset($_SESSION['user_id'])): ?>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="dashboard.php">Dashboard</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" href="account_statement.php">Account Statement</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="logout.php">Logout</a>
|
||||
</li>
|
||||
<?php else: ?>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="login.php">Login</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="admin.php">Admin</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="container mt-5">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2>Account Statement</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Your Order History</h5>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Order ID</th>
|
||||
<th>Order Date</th>
|
||||
<th>Fuel Type</th>
|
||||
<th>Quantity (Litres)</th>
|
||||
<th>Total Price</th>
|
||||
<th>Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($orders)): ?>
|
||||
<tr>
|
||||
<td colspan="6" class="text-center">You have no orders yet.</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<?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(ucfirst($order['fuel_type'])); ?></td>
|
||||
<td><?php echo htmlspecialchars($order['quantity']); ?></td>
|
||||
<td>$<?php echo htmlspecialchars(number_format($order['total_price'], 2)); ?></td>
|
||||
<td>
|
||||
<span class="badge bg-<?php
|
||||
switch ($order['status']) {
|
||||
case 'Completed':
|
||||
echo 'success';
|
||||
break;
|
||||
case 'Cancelled':
|
||||
echo 'danger';
|
||||
break;
|
||||
default:
|
||||
echo 'warning';
|
||||
}
|
||||
?>"><?php echo htmlspecialchars($order['status']); ?></span>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
222
admin.php
Normal file
222
admin.php
Normal file
@ -0,0 +1,222 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
// Hardcoded admin credentials
|
||||
define('ADMIN_USER', 'admin@example.com');
|
||||
define('ADMIN_PASS', 'password');
|
||||
|
||||
$error = null;
|
||||
$success = null;
|
||||
|
||||
// Handle login
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['login'])) {
|
||||
if ($_POST['email'] === ADMIN_USER && $_POST['password'] === ADMIN_PASS) {
|
||||
$_SESSION['admin_logged_in'] = true;
|
||||
header('Location: admin.php');
|
||||
exit;
|
||||
} else {
|
||||
$error = 'Invalid credentials.';
|
||||
}
|
||||
}
|
||||
|
||||
// Handle price update
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_prices'])) {
|
||||
if (!isset($_SESSION['admin_logged_in']) || !$_SESSION['admin_logged_in']) {
|
||||
header('Location: admin.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once 'db/config.php';
|
||||
$petrol_price = $_POST['petrol_price'] ?? 0;
|
||||
$diesel_price = $_POST['diesel_price'] ?? 0;
|
||||
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare("UPDATE prices SET price = :price WHERE fuel_type = :fuel_type");
|
||||
$stmt->execute(['price' => $petrol_price, 'fuel_type' => 'petrol']);
|
||||
$stmt->execute(['price' => $diesel_price, 'fuel_type' => 'diesel']);
|
||||
$success = 'Prices updated successfully!';
|
||||
} catch (PDOException $e) {
|
||||
$error = 'Database error: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch current prices and orders if admin is logged in
|
||||
$prices = [];
|
||||
$orders = [];
|
||||
if (isset($_SESSION['admin_logged_in']) && $_SESSION['admin_logged_in']) {
|
||||
require_once 'db/config.php';
|
||||
try {
|
||||
$pdo = db();
|
||||
// Fetch prices
|
||||
$stmt = $pdo->query("SELECT * FROM prices");
|
||||
$all_prices = $stmt->fetchAll();
|
||||
foreach ($all_prices as $p) {
|
||||
$prices[$p['fuel_type']] = $p['price'];
|
||||
}
|
||||
// Fetch orders
|
||||
$stmt = $pdo->query("SELECT * FROM orders ORDER BY order_date DESC");
|
||||
$orders = $stmt->fetchAll();
|
||||
|
||||
} catch (PDOException $e) {
|
||||
$error = 'Database error: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
// Check for status update messages
|
||||
if (isset($_SESSION['update_success'])) {
|
||||
$success = $_SESSION['update_success'];
|
||||
unset($_SESSION['update_success']);
|
||||
}
|
||||
if (isset($_SESSION['update_error'])) {
|
||||
$error = $_SESSION['update_error'];
|
||||
unset($_SESSION['update_error']);
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Admin - Petrol Price Management</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">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="index.php">Petrol Price Co.</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav ms-auto">
|
||||
<li class="nav-item"><a class="nav-link" href="index.php">Home</a></li>
|
||||
<?php if (isset($_SESSION['admin_logged_in']) && $_SESSION['admin_logged_in']): ?>
|
||||
<li class="nav-item"><a class="nav-link" href="logout.php">Logout</a></li>
|
||||
<?php else: ?>
|
||||
<li class="nav-item"><a class="nav-link" href="login.php">Customer Login</a></li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="container mt-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-10 col-lg-8">
|
||||
<?php if (!isset($_SESSION['admin_logged_in']) || !$_SESSION['admin_logged_in']): ?>
|
||||
<div class="card">
|
||||
<div class="card-header text-white text-center" style="background-color: #0a2351;">
|
||||
<h4>Admin Login</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if ($error): ?>
|
||||
<div class="alert alert-danger"><?php echo htmlspecialchars($error); ?></div>
|
||||
<?php endif; ?>
|
||||
<form action="admin.php" method="POST">
|
||||
<input type="hidden" name="login" value="1">
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">Email address</label>
|
||||
<input type="email" class="form-control" id="email" name="email" required value="admin@example.com">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Password</label>
|
||||
<input type="password" class="form-control" id="password" name="password" required value="password">
|
||||
</div>
|
||||
<div class="d-grid">
|
||||
<button type="submit" class="btn btn-primary">Login</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="card mb-4">
|
||||
<div class="card-header text-white text-center" style="background-color: #0a2351;">
|
||||
<h4>Update Fuel Prices</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if ($error && !isset($_SESSION['update_error']) && !isset($_SESSION['update_success'])): ?><div class="alert alert-danger"><?php echo htmlspecialchars($error); ?></div><?php endif; ?>
|
||||
<?php if ($success && !isset($_SESSION['update_success']) && !isset($_SESSION['update_error'])): ?><div class="alert alert-success"><?php echo htmlspecialchars($success); ?></div><?php endif; ?>
|
||||
<form action="admin.php" method="POST">
|
||||
<input type="hidden" name="update_prices" value="1">
|
||||
<div class="mb-3">
|
||||
<label for="petrol_price" class="form-label">Petrol Price (per litre)</label>
|
||||
<input type="number" step="0.01" class="form-control" id="petrol_price" name="petrol_price" required value="<?php echo htmlspecialchars($prices['petrol'] ?? '0.00'); ?>">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="diesel_price" class="form-label">Diesel Price (per litre)</label>
|
||||
<input type="number" step="0.01" class="form-control" id="diesel_price" name="diesel_price" required value="<?php echo htmlspecialchars($prices['diesel'] ?? '0.00'); ?>">
|
||||
</div>
|
||||
<div class="d-grid">
|
||||
<button type="submit" class="btn btn-primary">Update Prices</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header text-white text-center" style="background-color: #0a2351;">
|
||||
<h4>Order Management</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if (isset($_SESSION['update_error'])): ?><div class="alert alert-danger"><?php echo htmlspecialchars($_SESSION['update_error']); unset($_SESSION['update_error']); ?></div><?php endif; ?>
|
||||
<?php if (isset($_SESSION['update_success'])): ?><div class="alert alert-success"><?php echo htmlspecialchars($_SESSION['update_success']); unset($_SESSION['update_success']); ?></div><?php endif; ?>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Order ID</th>
|
||||
<th>Customer</th>
|
||||
<th>Fuel Type</th>
|
||||
<th>Quantity (L)</th>
|
||||
<th>Total Price</th>
|
||||
<th>Order Date</th>
|
||||
<th>Status</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($orders)): ?>
|
||||
<tr><td colspan="8" class="text-center">No orders found.</td></tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($orders as $order): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($order['id']); ?></td>
|
||||
<td><?php echo htmlspecialchars($order['user_id']); ?></td>
|
||||
<td><?php echo htmlspecialchars(ucfirst($order['fuel_type'])); ?></td>
|
||||
<td><?php echo htmlspecialchars($order['quantity']); ?></td>
|
||||
<td>$<?php echo htmlspecialchars(number_format($order['total_price'], 2)); ?></td>
|
||||
<td><?php echo htmlspecialchars(date("Y-m-d H:i", strtotime($order['order_date']))); ?></td>
|
||||
<form action="update_order_status.php" method="POST" class="d-inline">
|
||||
<td>
|
||||
<input type="hidden" name="order_id" value="<?php echo $order['id']; ?>">
|
||||
<select name="status" class="form-select form-select-sm">
|
||||
<option value="Pending" <?php echo $order['status'] === 'Pending' ? 'selected' : ''; ?>>Pending</option>
|
||||
<option value="Completed" <?php echo $order['status'] === 'Completed' ? 'selected' : ''; ?>>Completed</option>
|
||||
<option value="Cancelled" <?php echo $order['status'] === 'Cancelled' ? 'selected' : ''; ?>>Cancelled</option>
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
<button type="submit" class="btn btn-sm btn-primary">Update</button>
|
||||
</td>
|
||||
</form>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
46
assets/css/custom.css
Normal file
46
assets/css/custom.css
Normal file
@ -0,0 +1,46 @@
|
||||
:root {
|
||||
--brand-orange: #fd7e14;
|
||||
--brand-navy-blue: #0a2351;
|
||||
--brand-light-gray: #f8f9fa;
|
||||
--brand-dark-gray: #212529;
|
||||
--brand-white: #ffffff;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
||||
}
|
||||
|
||||
.bg-dark-blue {
|
||||
background-color: var(--brand-navy-blue);
|
||||
}
|
||||
|
||||
.btn-brand-orange {
|
||||
background-color: var(--brand-orange);
|
||||
color: var(--brand-white);
|
||||
border: none;
|
||||
}
|
||||
|
||||
.btn-brand-orange:hover {
|
||||
background-color: #e66a00;
|
||||
color: var(--brand-white);
|
||||
}
|
||||
|
||||
.hero-section {
|
||||
background-color: var(--brand-navy-blue);
|
||||
padding: 100px 0;
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
min-height: 400px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.navbar-brand {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
#contact form .form-control:focus {
|
||||
border-color: var(--brand-orange);
|
||||
box-shadow: 0 0 0 0.25rem rgba(253, 126, 20, 0.25);
|
||||
}
|
||||
38
assets/js/main.js
Normal file
38
assets/js/main.js
Normal file
@ -0,0 +1,38 @@
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const status = urlParams.get('status');
|
||||
|
||||
if (status) {
|
||||
let message = '';
|
||||
let type = 'success';
|
||||
|
||||
if (status === 'success') {
|
||||
message = 'Thank you for your message! We will get back to you shortly.';
|
||||
} else if (status === 'error') {
|
||||
message = 'Something went wrong. Please try again.';
|
||||
type = 'danger';
|
||||
}
|
||||
|
||||
if (message) {
|
||||
const toastContainer = document.getElementById('toast-container');
|
||||
const toastHTML = `
|
||||
<div class="toast align-items-center text-white bg-${type} border-0 show" role="alert" aria-live="assertive" aria-atomic="true">
|
||||
<div class="d-flex">
|
||||
<div class="toast-body">
|
||||
${message}
|
||||
</div>
|
||||
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
toastContainer.innerHTML = toastHTML;
|
||||
|
||||
const toastElement = toastContainer.querySelector('.toast');
|
||||
const toast = new bootstrap.Toast(toastElement, { delay: 5000 });
|
||||
toast.show();
|
||||
}
|
||||
|
||||
// Clean the URL
|
||||
window.history.replaceState({}, document.title, window.location.pathname);
|
||||
}
|
||||
});
|
||||
36
contact_handler.php
Normal file
36
contact_handler.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
require_once __DIR__ . '/mail/MailService.php';
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$name = filter_var(trim($_POST["name"]), FILTER_SANITIZE_STRING);
|
||||
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
|
||||
$message = filter_var(trim($_POST["message"]), FILTER_SANITIZE_STRING);
|
||||
|
||||
if (empty($name) || !filter_var($email, FILTER_VALIDATE_EMAIL) || empty($message)) {
|
||||
$_SESSION['status'] = ['type' => 'danger', 'message' => 'Invalid input. Please fill out all fields correctly.'];
|
||||
header("Location: index.php#contact");
|
||||
exit;
|
||||
}
|
||||
|
||||
// The email will be sent to the address configured in .env (MAIL_TO)
|
||||
// The user's email is used as the Reply-To address.
|
||||
$subject = 'New Account Request from ' . $name;
|
||||
|
||||
$res = MailService::sendContactMessage($name, $email, $message, null, $subject);
|
||||
|
||||
if (!empty($res['success'])) {
|
||||
$_SESSION['status'] = ['type' => 'success', 'message' => 'Thank you for your request! We will get back to you shortly.'];
|
||||
} else {
|
||||
// Avoid showing detailed errors to the user.
|
||||
// error_log('MailService Error: ' . ($res['error'] ?? 'Unknown error'));
|
||||
$_SESSION['status'] = ['type' => 'danger', 'message' => 'Sorry, there was an error sending your message. Please try again later.'];
|
||||
}
|
||||
|
||||
} else {
|
||||
$_SESSION['status'] = ['type' => 'danger', 'message' => 'Invalid request method.'];
|
||||
}
|
||||
|
||||
header("Location: index.php#contact");
|
||||
exit;
|
||||
233
dashboard.php
Normal file
233
dashboard.php
Normal file
@ -0,0 +1,233 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'db/config.php';
|
||||
|
||||
// Protect this page - redirect to login if user is not logged in
|
||||
if (!isset($_SESSION['user'])) {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$user = $_SESSION['user'];
|
||||
|
||||
// Fetch prices
|
||||
$petrol_price = 0.00;
|
||||
$diesel_price = 0.00;
|
||||
try {
|
||||
$pdoconn = db();
|
||||
$stmt = $pdoconn->query("SELECT * FROM prices ORDER BY updated_at DESC LIMIT 1");
|
||||
$latest_prices = $stmt->fetch();
|
||||
if ($latest_prices) {
|
||||
$petrol_price = $latest_prices['petrol_price'];
|
||||
$diesel_price = $latest_prices['diesel_price'];
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
error_log("Could not fetch prices: " . $e->getMessage());
|
||||
}
|
||||
|
||||
// Fetch user's orders
|
||||
$orders = [];
|
||||
try {
|
||||
$stmt = $pdoconn->prepare("SELECT * FROM orders WHERE user_id = :user_id ORDER BY order_date DESC");
|
||||
$stmt->execute([':user_id' => $user['id']]);
|
||||
$orders = $stmt->fetchAll();
|
||||
} catch (PDOException $e) {
|
||||
error_log("Could not fetch orders: " . $e->getMessage());
|
||||
}
|
||||
|
||||
require_once 'includes/pexels.php';
|
||||
$bg_image_data = pexels_get('https://api.pexels.com/v1/search?query=abstract+background&orientation=landscape&per_page=1&page=1');
|
||||
$bg_image = ''; // Default empty
|
||||
if ($bg_image_data && !empty($bg_image_data['photos'])) {
|
||||
$photo = $bg_image_data['photos'][0];
|
||||
$src = $photo['src']['large2x'] ?? ($photo['src']['large'] ?? $photo['src']['original']);
|
||||
$target = __DIR__ . '/assets/images/pexels/' . $photo['id'] . '.jpg';
|
||||
download_to($src, $target);
|
||||
$bg_image = 'assets/images/pexels/' . $photo['id'] . '.jpg';
|
||||
}
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Customer Dashboard</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
||||
<link rel="stylesheet" href="assets/css/custom.css">
|
||||
<style>
|
||||
body {
|
||||
display: flex;
|
||||
min-height: 100vh;
|
||||
flex-direction: column;
|
||||
}
|
||||
.main-container {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
}
|
||||
.sidebar {
|
||||
width: 280px;
|
||||
background-color: var(--brand-navy-blue);
|
||||
color: white;
|
||||
}
|
||||
.sidebar .nav-link {
|
||||
color: rgba(255, 255, 255, 0.7);
|
||||
padding: 1rem;
|
||||
}
|
||||
.sidebar .nav-link:hover, .sidebar .nav-link.active {
|
||||
color: white;
|
||||
background-color: var(--brand-orange);
|
||||
}
|
||||
.sidebar .nav-link .bi {
|
||||
margin-right: 10px;
|
||||
}
|
||||
.content {
|
||||
flex: 1;
|
||||
padding: 2rem;
|
||||
background-image: url('<?php echo $bg_image; ?>');
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
}
|
||||
.top-bar {
|
||||
background-color: rgba(255, 255, 255, 0.9);
|
||||
border-bottom: 1px solid #dee2e6;
|
||||
padding: 1rem;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
}
|
||||
.card {
|
||||
background-color: rgba(255, 255, 255, 0.9);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="main-container">
|
||||
<div class="sidebar d-flex flex-column p-3">
|
||||
<a href="dashboard.php" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto text-white text-decoration-none">
|
||||
<span class="fs-4">Petrol Price Co.</span>
|
||||
</a>
|
||||
<hr>
|
||||
<ul class="nav nav-pills flex-column mb-auto">
|
||||
<li class="nav-item">
|
||||
<a href="dashboard.php" class="nav-link active" aria-current="page">
|
||||
<i class="bi bi-speedometer2"></i>
|
||||
Dashboard
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#order-form" class="nav-link">
|
||||
<i class="bi bi-fuel-pump"></i>
|
||||
Place Order
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="account_statement.php" class="nav-link">
|
||||
<i class="bi bi-list-ul"></i>
|
||||
Account Statement
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="profile.php" class="nav-link">
|
||||
<i class="bi bi-person"></i>
|
||||
Profile
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<hr>
|
||||
<div class="dropdown">
|
||||
<a href="#" class="d-flex align-items-center text-white text-decoration-none dropdown-toggle" id="dropdownUser1" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="bi bi-person-circle fs-4 me-2"></i>
|
||||
<strong><?php echo htmlspecialchars($user['name']); ?></strong>
|
||||
</a>
|
||||
<ul class="dropdown-menu dropdown-menu-dark text-small shadow" aria-labelledby="dropdownUser1">
|
||||
<li><a class="dropdown-item" href="profile.php">Profile</a></li>
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li><a class="dropdown-item" href="logout.php">Sign out</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex flex-column flex-fill">
|
||||
<div class="top-bar">
|
||||
<span class="text-muted">Welcome, <?php echo htmlspecialchars($user['name']); ?>!</span>
|
||||
</div>
|
||||
<div class="content">
|
||||
<?php if (isset($_SESSION['order_success'])) { ?>
|
||||
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
||||
<?php echo $_SESSION['order_success']; ?>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
<?php unset($_SESSION['order_success']); ?>
|
||||
<?php } ?>
|
||||
<?php if (isset($_SESSION['order_error'])) { ?>
|
||||
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||
<?php echo $_SESSION['order_error']; ?>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
<?php unset($_SESSION['order_error']); ?>
|
||||
<?php } ?>
|
||||
|
||||
<h1 class="h2">Dashboard</h1>
|
||||
<p>Welcome to your customer portal. Here you can view prices, place orders, and see your account history.</p>
|
||||
|
||||
<div class="row mt-4">
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">Today's Prices</div>
|
||||
<div class="card-body">
|
||||
<p>Petrol: $<?php echo htmlspecialchars(number_format($petrol_price, 2)); ?> / litre</p>
|
||||
<p>Diesel: $<?php echo htmlspecialchars(number_format($diesel_price, 2)); ?> / litre</p>
|
||||
<small class="text-muted">Prices are updated daily.</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">Banking Details</div>
|
||||
<div class="card-body">
|
||||
<p>Please use the following details for payments:</p>
|
||||
<ul>
|
||||
<li><strong>Bank A:</strong> 123-456-7890</li>
|
||||
<li><strong>Bank B:</strong> 098-765-4321</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mt-4" id="order-form">
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
<div class="card-header">Place a New Order</div>
|
||||
<div class="card-body">
|
||||
<form action="order_handler.php" method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="fuel_type" class="form-label">Fuel Type</label>
|
||||
<select class="form-select" id="fuel_type" name="fuel_type" required>
|
||||
<option value="petrol">Petrol</option>
|
||||
<option value="diesel">Diesel</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="quantity" class="form-label">Quantity (litres)</label>
|
||||
<input type="number" class="form-control" id="quantity" name="quantity" min="1" step="0.01" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary" style="background-color: #fd7e14; border-color: #fd7e14;">Place Order</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@ -8,10 +8,29 @@ define('DB_PASS', 'e45f2778-db1f-450c-99c6-29efb4601472');
|
||||
function db() {
|
||||
static $pdo;
|
||||
if (!$pdo) {
|
||||
try {
|
||||
$pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8mb4', DB_USER, DB_PASS, [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
]);
|
||||
} catch (PDOException $e) {
|
||||
// If the database doesn't exist, create it.
|
||||
if ($e->getCode() === 1049) { // SQLSTATE[HY000] [1049] Unknown database
|
||||
try {
|
||||
$tempPdo = new PDO('mysql:host='.DB_HOST, DB_USER, DB_PASS);
|
||||
$tempPdo->exec('CREATE DATABASE IF NOT EXISTS `'. DB_NAME . '`');
|
||||
// Now, reconnect with the database name.
|
||||
$pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8mb4', DB_USER, DB_PASS, [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
]);
|
||||
} catch (PDOException $creationException) {
|
||||
die("DB ERROR: Failed to create database. " . $creationException->getMessage());
|
||||
}
|
||||
} else {
|
||||
die("DB ERROR: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
return $pdo;
|
||||
}
|
||||
|
||||
296
index.php
296
index.php
@ -1,150 +1,164 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
@ini_set('display_errors', '1');
|
||||
@error_reporting(E_ALL);
|
||||
@date_default_timezone_set('UTC');
|
||||
|
||||
$phpVersion = PHP_VERSION;
|
||||
$now = date('Y-m-d H:i:s');
|
||||
?>
|
||||
<!doctype html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>New Style</title>
|
||||
<?php
|
||||
// Read project preview data from environment
|
||||
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
|
||||
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
||||
?>
|
||||
<?php if ($projectDescription): ?>
|
||||
<!-- Meta description -->
|
||||
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
|
||||
<!-- Open Graph meta tags -->
|
||||
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<!-- Twitter meta tags -->
|
||||
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<?php endif; ?>
|
||||
<?php if ($projectImageUrl): ?>
|
||||
<!-- Open Graph image -->
|
||||
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<!-- Twitter image -->
|
||||
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<?php endif; ?>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--bg-color-start: #6a11cb;
|
||||
--bg-color-end: #2575fc;
|
||||
--text-color: #ffffff;
|
||||
--card-bg-color: rgba(255, 255, 255, 0.01);
|
||||
--card-border-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: 'Inter', sans-serif;
|
||||
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
|
||||
color: var(--text-color);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
body::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
|
||||
animation: bg-pan 20s linear infinite;
|
||||
z-index: -1;
|
||||
}
|
||||
@keyframes bg-pan {
|
||||
0% { background-position: 0% 0%; }
|
||||
100% { background-position: 100% 100%; }
|
||||
}
|
||||
main {
|
||||
padding: 2rem;
|
||||
}
|
||||
.card {
|
||||
background: var(--card-bg-color);
|
||||
border: 1px solid var(--card-border-color);
|
||||
border-radius: 16px;
|
||||
padding: 2rem;
|
||||
backdrop-filter: blur(20px);
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.loader {
|
||||
margin: 1.25rem auto 1.25rem;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border: 3px solid rgba(255, 255, 255, 0.25);
|
||||
border-top-color: #fff;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
.hint {
|
||||
opacity: 0.9;
|
||||
}
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px; height: 1px;
|
||||
padding: 0; margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap; border: 0;
|
||||
}
|
||||
h1 {
|
||||
font-size: 3rem;
|
||||
font-weight: 700;
|
||||
margin: 0 0 1rem;
|
||||
letter-spacing: -1px;
|
||||
}
|
||||
p {
|
||||
margin: 0.5rem 0;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
code {
|
||||
background: rgba(0,0,0,0.2);
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
}
|
||||
footer {
|
||||
position: absolute;
|
||||
bottom: 1rem;
|
||||
font-size: 0.8rem;
|
||||
opacity: 0.7;
|
||||
}
|
||||
</style>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Fuel Distribution Co.</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">
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<div class="card">
|
||||
<h1>Analyzing your requirements and generating your website…</h1>
|
||||
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
|
||||
<span class="sr-only">Loading…</span>
|
||||
|
||||
<?php
|
||||
session_start();
|
||||
?>
|
||||
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark-blue">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="#">FuelDistro</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav ms-auto">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#about">About</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#services">Services</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#contact">Contact</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="btn btn-brand-orange ms-lg-3" href="login.php">Customer Login</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="admin.php">Admin</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
|
||||
<p class="hint">This page will update automatically as the plan is implemented.</p>
|
||||
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
|
||||
</div>
|
||||
</main>
|
||||
<footer>
|
||||
Page updated: <?= htmlspecialchars($now) ?> (UTC)
|
||||
</nav>
|
||||
|
||||
|
||||
<?php
|
||||
require_once 'includes/pexels.php';
|
||||
$hero_image_data = pexels_get('https://api.pexels.com/v1/search?query=gas+station&orientation=landscape&per_page=1&page=1');
|
||||
$hero_image = 'https://images.pexels.com/photos/258154/pexels-photo-258154.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1'; // Fallback
|
||||
if ($hero_image_data && !empty($hero_image_data['photos'])) {
|
||||
$photo = $hero_image_data['photos'][0];
|
||||
$src = $photo['src']['large2x'] ?? ($photo['src']['large'] ?? $photo['src']['original']);
|
||||
$target = __DIR__ . '/assets/images/pexels/' . $photo['id'] . '.jpg';
|
||||
download_to($src, $target);
|
||||
$hero_image = 'assets/images/pexels/' . $photo['id'] . '.jpg';
|
||||
}
|
||||
|
||||
$about_image_data = pexels_get('https://api.pexels.com/v1/search?query=fuel+truck&orientation=landscape&per_page=1&page=1');
|
||||
$about_image = 'https://images.pexels.com/photos/3184418/pexels-photo-3184418.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1'; // Fallback
|
||||
if ($about_image_data && !empty($about_image_data['photos'])) {
|
||||
$photo = $about_image_data['photos'][0];
|
||||
$src = $photo['src']['large2x'] ?? ($photo['src']['large'] ?? $photo['src']['original']);
|
||||
$target = __DIR__ . '/assets/images/pexels/' . $photo['id'] . '.jpg';
|
||||
download_to($src, $target);
|
||||
$about_image = 'assets/images/pexels/' . $photo['id'] . '.jpg';
|
||||
}
|
||||
?>
|
||||
|
||||
<header class="hero-section text-white text-center" style="background-image: url('<?php echo $hero_image; ?>');">
|
||||
<div class="container">
|
||||
<h1 class="display-4">Reliable Fuel Distribution</h1>
|
||||
<p class="lead">Your trusted partner for timely petrol and diesel supply.</p>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<section id="about" class="py-5">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-lg-6">
|
||||
<h2>About Us</h2>
|
||||
<p>We are a leading fuel distribution company dedicated to providing businesses with high-quality petrol and diesel. Our commitment to efficiency and customer service ensures your operations never run dry. We offer customized pricing and delivery schedules to meet your specific needs.</p>
|
||||
</div>
|
||||
<div class="col-lg-6">
|
||||
<img src="<?php echo $about_image; ?>" class="img-fluid rounded" alt="About Us Image">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
<section id="services" class="bg-light py-5">
|
||||
<div class="container">
|
||||
<div class="text-center mb-5">
|
||||
<h2>Our Services</h2>
|
||||
<p class="lead">We deliver petrol and diesel directly to your business.</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="card mb-4">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Petrol Delivery</h5>
|
||||
<p class="card-text">High-octane petrol for your fleet and machinery, delivered on schedule.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="card mb-4">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Diesel Delivery</h5>
|
||||
<p class="card-text">Bulk diesel for commercial vehicles, generators, and industrial equipment.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="contact" class="py-5">
|
||||
<div class="container">
|
||||
<div class="text-center mb-5">
|
||||
<h2>Contact Us</h2>
|
||||
<p class="lead">Interested in opening an account? Fill out the form below.</p>
|
||||
</div>
|
||||
|
||||
<?php if (isset($_SESSION['status'])): ?>
|
||||
<div class="alert alert-<?php echo $_SESSION['status']['type']; ?> alert-dismissible fade show" role="alert">
|
||||
<?php echo $_SESSION['status']['message']; ?>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
<?php unset($_SESSION['status']); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-8">
|
||||
<form action="contact_handler.php" method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Your 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="message" class="form-label">Message</label>
|
||||
<textarea class="form-control" id="message" name="message" rows="5" required></textarea>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<button type="submit" class="btn btn-brand-orange btn-lg">Request Account</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<footer class="bg-dark-blue text-white text-center py-3">
|
||||
<div class="container">
|
||||
<p>© 2025 FuelDistro. All Rights Reserved.</p>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
75
login.php
Normal file
75
login.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
session_start();
|
||||
$error = $_SESSION['error'] ?? null;
|
||||
unset($_SESSION['error']);
|
||||
|
||||
require_once 'includes/pexels.php';
|
||||
$bg_image_data = pexels_get('https://api.pexels.com/v1/search?query=modern+gas+station&orientation=landscape&per_page=1&page=1');
|
||||
$bg_image = 'https://images.pexels.com/photos/1583884/pexels-photo-1583884.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1'; // Fallback
|
||||
if ($bg_image_data && !empty($bg_image_data['photos'])) {
|
||||
$photo = $bg_image_data['photos'][0];
|
||||
$src = $photo['src']['large2x'] ?? ($photo['src']['large'] ?? $photo['src']['original']);
|
||||
$target = __DIR__ . '/assets/images/pexels/' . $photo['id'] . '.jpg';
|
||||
download_to($src, $target);
|
||||
$bg_image = 'assets/images/pexels/' . $photo['id'] . '.jpg';
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Login - Petrol Price Management</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">
|
||||
<style>
|
||||
body {
|
||||
background-image: url('<?php echo $bg_image; ?>');
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.login-container {
|
||||
background-color: rgba(255, 255, 255, 0.9);
|
||||
padding: 30px;
|
||||
border-radius: 10px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-6 col-lg-5">
|
||||
<div class="login-container">
|
||||
<div class="text-center mb-4">
|
||||
<a href="index.php" class="h1 text-decoration-none text-dark">FuelDistro</a>
|
||||
</div>
|
||||
<h4 class="text-center mb-4">Customer Login</h4>
|
||||
<?php if ($error): ?>
|
||||
<div class="alert alert-danger"><?php echo htmlspecialchars($error); ?></div>
|
||||
<?php endif; ?>
|
||||
<form action="login_handler.php" method="POST">
|
||||
<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="password" class="form-label">Password</label>
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
</div>
|
||||
<div class="d-grid">
|
||||
<button type="submit" class="btn btn-primary">Login</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
37
login_handler.php
Normal file
37
login_handler.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
// IMPORTANT: This is a temporary, hardcoded user for demonstration purposes.
|
||||
// We will replace this with a proper database lookup later.
|
||||
$users = [
|
||||
'customer@example.com' => [
|
||||
'password' => 'password',
|
||||
'name' => 'Test Customer',
|
||||
'company' => 'Example Inc.'
|
||||
]
|
||||
];
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$email = $_POST['email'] ?? '';
|
||||
$password = $_POST['password'] ?? '';
|
||||
|
||||
if (isset($users[$email]) && $users[$email]['password'] === $password) {
|
||||
// Login successful
|
||||
$_SESSION['user'] = [
|
||||
'email' => $email,
|
||||
'name' => $users[$email]['name'],
|
||||
'company' => $users[$email]['company']
|
||||
];
|
||||
header('Location: dashboard.php');
|
||||
exit;
|
||||
} else {
|
||||
// Login failed
|
||||
$_SESSION['error'] = 'Invalid email or password.';
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
// Redirect if accessed directly
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
22
logout.php
Normal file
22
logout.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
// Unset all of the session variables.
|
||||
$_SESSION = [];
|
||||
|
||||
// If it's desired to kill the session, also delete the session cookie.
|
||||
// Note: This will destroy the session, and not just the session data!
|
||||
if (ini_get("session.use_cookies")) {
|
||||
$params = session_get_cookie_params();
|
||||
setcookie(session_name(), '', time() - 42000,
|
||||
$params["path"], $params["domain"],
|
||||
$params["secure"], $params["httponly"]
|
||||
);
|
||||
}
|
||||
|
||||
// Finally, destroy the session.
|
||||
session_destroy();
|
||||
|
||||
// Redirect to login page
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
64
order_handler.php
Normal file
64
order_handler.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'db/config.php';
|
||||
|
||||
// Protect this page - redirect to login if user is not logged in
|
||||
if (!isset($_SESSION['user'])) {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$user_id = $_SESSION['user']['id'];
|
||||
$fuel_type = $_POST['fuel_type'];
|
||||
$quantity = $_POST['quantity'];
|
||||
|
||||
// Validate input
|
||||
if (empty($fuel_type) || empty($quantity) || !is_numeric($quantity) || $quantity <= 0) {
|
||||
$_SESSION['order_error'] = "Invalid input.";
|
||||
header('Location: dashboard.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$pdoconn = db();
|
||||
|
||||
// Fetch the latest price
|
||||
$stmt = $pdoconn->query("SELECT * FROM prices ORDER BY updated_at DESC LIMIT 1");
|
||||
$latest_prices = $stmt->fetch();
|
||||
|
||||
if (!$latest_prices) {
|
||||
$_SESSION['order_error'] = "Could not retrieve latest prices. Please try again later.";
|
||||
header('Location: dashboard.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$price = ($fuel_type === 'petrol') ? $latest_prices['petrol_price'] : $latest_prices['diesel_price'];
|
||||
$total_price = $quantity * $price;
|
||||
|
||||
// Insert the order
|
||||
$sql = "INSERT INTO orders (user_id, fuel_type, quantity, total_price) VALUES (:user_id, :fuel_type, :quantity, :total_price)";
|
||||
$stmt = $pdoconn->prepare($sql);
|
||||
$stmt->execute([
|
||||
':user_id' => $user_id,
|
||||
':fuel_type' => $fuel_type,
|
||||
':quantity' => $quantity,
|
||||
':total_price' => $total_price
|
||||
]);
|
||||
|
||||
$_SESSION['order_success'] = "Your order has been placed successfully!";
|
||||
header('Location: dashboard.php');
|
||||
exit;
|
||||
|
||||
} catch (PDOException $e) {
|
||||
error_log("Order submission failed: " . $e->getMessage());
|
||||
$_SESSION['order_error'] = "There was an error placing your order. Please try again.";
|
||||
header('Location: dashboard.php');
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
// Redirect if accessed directly
|
||||
header('Location: dashboard.php');
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
77
profile.php
Normal file
77
profile.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
session_start();
|
||||
if (!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true) {
|
||||
header("location: login.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once 'db/config.php';
|
||||
|
||||
$user_id = $_SESSION["id"];
|
||||
$name = $email = "";
|
||||
$name_err = $email_err = "";
|
||||
$success_message = "";
|
||||
|
||||
// Fetch user data
|
||||
$pdo = db();
|
||||
$sql = "SELECT name, email FROM users WHERE id = :id";
|
||||
if ($stmt = $pdo->prepare($sql)) {
|
||||
$stmt->bindParam(":id", $user_id, PDO::PARAM_INT);
|
||||
if ($stmt->execute()) {
|
||||
if ($stmt->rowCount() == 1) {
|
||||
if ($row = $stmt->fetch()) {
|
||||
$name = $row["name"];
|
||||
$email = $row["email"];
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($stmt);
|
||||
}
|
||||
unset($pdo);
|
||||
|
||||
// Include header
|
||||
include 'includes/header.php';
|
||||
?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<h2>User Profile</h2>
|
||||
<p>Edit your personal information.</p>
|
||||
|
||||
<?php
|
||||
if (!empty($_SESSION['success_message'])) {
|
||||
echo '<div class="alert alert-success">' . $_SESSION['success_message'] . '</div>';
|
||||
unset($_SESSION['success_message']);
|
||||
}
|
||||
if (!empty($_SESSION['error_message'])) {
|
||||
echo '<div class="alert alert-danger">' . $_SESSION['error_message'] . '</div>';
|
||||
unset($_SESSION['error_message']);
|
||||
}
|
||||
?>
|
||||
|
||||
<form action="update_profile.php" method="post">
|
||||
<div class="form-group">
|
||||
<label>Name</label>
|
||||
<input type="text" name="name" class="form-control" value="<?php echo htmlspecialchars($name); ?>">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Email</label>
|
||||
<input type="email" name="email" class="form-control" value="<?php echo htmlspecialchars($email); ?>">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>New Password (optional)</label>
|
||||
<input type="password" name="new_password" class="form-control">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Confirm New Password</label>
|
||||
<input type="password" name="confirm_password" class="form-control">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="submit" class="btn btn-primary" value="Update Profile">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
// Include footer
|
||||
include 'includes/footer.php';
|
||||
?>
|
||||
42
update_order_status.php
Normal file
42
update_order_status.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
// Ensure only admins can access this script
|
||||
if (!isset($_SESSION['admin_logged_in']) || !$_SESSION['admin_logged_in']) {
|
||||
$_SESSION['update_error'] = 'You must be logged in to update orders.';
|
||||
header('Location: admin.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['order_id'], $_POST['status'])) {
|
||||
require_once 'db/config.php';
|
||||
|
||||
$order_id = $_POST['order_id'];
|
||||
$status = $_POST['status'];
|
||||
$allowed_statuses = ['Pending', 'Completed', 'Cancelled'];
|
||||
|
||||
if (!in_array($status, $allowed_statuses)) {
|
||||
$_SESSION['update_error'] = 'Invalid status value.';
|
||||
header('Location: admin.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare("UPDATE orders SET status = :status WHERE id = :order_id");
|
||||
$stmt->execute(['status' => $status, 'order_id' => $order_id]);
|
||||
|
||||
if ($stmt->rowCount()) {
|
||||
$_SESSION['update_success'] = "Order #{$order_id} has been updated to '{$status}'.";
|
||||
} else {
|
||||
$_SESSION['update_error'] = "Could not find Order #{$order_id} to update.";
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$_SESSION['update_error'] = 'Database error: ' . $e->getMessage();
|
||||
}
|
||||
} else {
|
||||
$_SESSION['update_error'] = 'Invalid request.';
|
||||
}
|
||||
|
||||
header('Location: admin.php');
|
||||
exit;
|
||||
60
update_profile.php
Normal file
60
update_profile.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true) {
|
||||
header("location: login.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once 'db/config.php';
|
||||
|
||||
$user_id = $_SESSION["id"];
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$name = trim($_POST["name"]);
|
||||
$email = trim($_POST["email"]);
|
||||
$new_password = $_POST["new_password"];
|
||||
$confirm_password = $_POST["confirm_password"];
|
||||
|
||||
$pdo = db();
|
||||
$sql = "UPDATE users SET name = :name, email = :email";
|
||||
|
||||
// Password update logic
|
||||
if (!empty($new_password)) {
|
||||
if (strlen($new_password) < 6) {
|
||||
$_SESSION['error_message'] = "Password must have at least 6 characters.";
|
||||
header("location: profile.php");
|
||||
exit;
|
||||
} elseif ($new_password != $confirm_password) {
|
||||
$_SESSION['error_message'] = "Passwords do not match.";
|
||||
header("location: profile.php");
|
||||
exit;
|
||||
}
|
||||
$sql .= ", password = :password";
|
||||
$hashed_password = password_hash($new_password, PASSWORD_DEFAULT);
|
||||
}
|
||||
|
||||
$sql .= " WHERE id = :id";
|
||||
|
||||
if ($stmt = $pdo->prepare($sql)) {
|
||||
$stmt->bindParam(":name", $name, PDO::PARAM_STR);
|
||||
$stmt->bindParam(":email", $email, PDO::PARAM_STR);
|
||||
$stmt->bindParam(":id", $user_id, PDO::PARAM_INT);
|
||||
|
||||
if (!empty($new_password)) {
|
||||
$stmt->bindParam(":password", $hashed_password, PDO::PARAM_STR);
|
||||
}
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$_SESSION['success_message'] = "Your profile has been updated successfully.";
|
||||
} else {
|
||||
$_SESSION['error_message'] = "Oops! Something went wrong. Please try again later.";
|
||||
}
|
||||
unset($stmt);
|
||||
}
|
||||
unset($pdo);
|
||||
|
||||
header("location: profile.php");
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
Loading…
x
Reference in New Issue
Block a user