From 29283818686dccd9356bb9115e0ba329f4ed2f32 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Wed, 8 Oct 2025 11:45:34 +0000 Subject: [PATCH] Revert to version 27d5988 --- account_statement.php | 118 ++++++++++++++++ admin.php | 222 +++++++++++++++++++++++++++++ assets/css/custom.css | 46 ++++++ assets/js/main.js | 38 +++++ contact_handler.php | 36 +++++ dashboard.php | 233 ++++++++++++++++++++++++++++++ db/config.php | 27 +++- index.php | 304 +++++++++++++++++++++------------------- login.php | 75 ++++++++++ login_handler.php | 37 +++++ logout.php | 22 +++ order_handler.php | 64 +++++++++ profile.php | 77 ++++++++++ update_order_status.php | 42 ++++++ update_profile.php | 60 ++++++++ 15 files changed, 1252 insertions(+), 149 deletions(-) create mode 100644 account_statement.php create mode 100644 admin.php create mode 100644 assets/css/custom.css create mode 100644 assets/js/main.js create mode 100644 contact_handler.php create mode 100644 dashboard.php create mode 100644 login.php create mode 100644 login_handler.php create mode 100644 logout.php create mode 100644 order_handler.php create mode 100644 profile.php create mode 100644 update_order_status.php create mode 100644 update_profile.php diff --git a/account_statement.php b/account_statement.php new file mode 100644 index 0000000..e3df0aa --- /dev/null +++ b/account_statement.php @@ -0,0 +1,118 @@ +prepare("SELECT * FROM orders WHERE user_id = ? ORDER BY order_date DESC"); +$stmt->execute([$user_id]); +$orders = $stmt->fetchAll(); +?> + + + + + + Account Statement + + + + + + + +
+
+
+

Account Statement

+
+
+
Your Order History
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Order IDOrder DateFuel TypeQuantity (Litres)Total PriceStatus
You have no orders yet.
$ + +
+
+
+
+
+ + + + diff --git a/admin.php b/admin.php new file mode 100644 index 0000000..9c7e319 --- /dev/null +++ b/admin.php @@ -0,0 +1,222 @@ +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']); +} + + +?> + + + + + + Admin - Petrol Price Management + + + + + + + +
+
+
+ +
+
+

Admin Login

+
+
+ +
+ +
+ +
+ + +
+
+ + +
+
+ +
+
+
+
+ +
+
+

Update Fuel Prices

+
+
+
+
+
+ +
+ + +
+
+ + +
+
+ +
+
+
+
+ +
+
+

Order Management

+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Order IDCustomerFuel TypeQuantity (L)Total PriceOrder DateStatusAction
No orders found.
$
+ + + + +
+
+
+
+ +
+
+
+ + + + \ No newline at end of file diff --git a/assets/css/custom.css b/assets/css/custom.css new file mode 100644 index 0000000..f7cd582 --- /dev/null +++ b/assets/css/custom.css @@ -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); +} \ No newline at end of file diff --git a/assets/js/main.js b/assets/js/main.js new file mode 100644 index 0000000..8b87476 --- /dev/null +++ b/assets/js/main.js @@ -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 = ` + + `; + 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); + } +}); diff --git a/contact_handler.php b/contact_handler.php new file mode 100644 index 0000000..fad0e6f --- /dev/null +++ b/contact_handler.php @@ -0,0 +1,36 @@ + '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; \ No newline at end of file diff --git a/dashboard.php b/dashboard.php new file mode 100644 index 0000000..32cbdca --- /dev/null +++ b/dashboard.php @@ -0,0 +1,233 @@ +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'; +} + +?> + + + + + + Customer Dashboard + + + + + + + +
+ + +
+
+ Welcome, ! +
+
+ + + + + + + + + +

Dashboard

+

Welcome to your customer portal. Here you can view prices, place orders, and see your account history.

+ +
+
+
+
Today's Prices
+
+

Petrol: $ / litre

+

Diesel: $ / litre

+ Prices are updated daily. +
+
+
+
+
+
Banking Details
+
+

Please use the following details for payments:

+
    +
  • Bank A: 123-456-7890
  • +
  • Bank B: 098-765-4321
  • +
+
+
+
+
+ +
+
+
+
Place a New Order
+
+
+
+ + +
+
+ + +
+ +
+
+
+
+
+ + + +
+
+
+ + + + \ No newline at end of file diff --git a/db/config.php b/db/config.php index bb98f7d..1edff8c 100644 --- a/db/config.php +++ b/db/config.php @@ -8,10 +8,29 @@ define('DB_PASS', 'e45f2778-db1f-450c-99c6-29efb4601472'); function db() { static $pdo; if (!$pdo) { - $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, - ]); + 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; } diff --git a/index.php b/index.php index 7205f3d..55eba60 100644 --- a/index.php +++ b/index.php @@ -1,150 +1,164 @@ - - + - - - New Style - - - - - - - - - - - - - - - - - - - + + + Fuel Distribution Co. + + -
-
-

Analyzing your requirements and generating your website…

-
- Loading… -
-

AI is collecting your requirements and applying the first changes.

-

This page will update automatically as the plan is implemented.

-

Runtime: PHP — UTC

-
-
- + + + + + + + + +
+
+

Reliable Fuel Distribution

+

Your trusted partner for timely petrol and diesel supply.

+
+
+ +
+
+
+
+

About Us

+

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.

+
+
+ About Us Image +
+
+
+
+ + +
+
+
+

Our Services

+

We deliver petrol and diesel directly to your business.

+
+
+
+
+
+
Petrol Delivery
+

High-octane petrol for your fleet and machinery, delivered on schedule.

+
+
+
+
+
+
+
Diesel Delivery
+

Bulk diesel for commercial vehicles, generators, and industrial equipment.

+
+
+
+
+
+
+ +
+
+
+

Contact Us

+

Interested in opening an account? Fill out the form below.

+
+ + + + + + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+
+
+
+ + + + - + \ No newline at end of file diff --git a/login.php b/login.php new file mode 100644 index 0000000..63ab76a --- /dev/null +++ b/login.php @@ -0,0 +1,75 @@ + + + + + + + Login - Petrol Price Management + + + + + + +
+
+
+ +
+
+
+ + + + diff --git a/login_handler.php b/login_handler.php new file mode 100644 index 0000000..26d8062 --- /dev/null +++ b/login_handler.php @@ -0,0 +1,37 @@ + [ + '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; +} diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..e58edd6 --- /dev/null +++ b/logout.php @@ -0,0 +1,22 @@ +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; +} +?> \ No newline at end of file diff --git a/profile.php b/profile.php new file mode 100644 index 0000000..aca0472 --- /dev/null +++ b/profile.php @@ -0,0 +1,77 @@ +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'; +?> + +
+

User Profile

+

Edit your personal information.

+ + ' . $_SESSION['success_message'] . '
'; + unset($_SESSION['success_message']); + } + if (!empty($_SESSION['error_message'])) { + echo '
' . $_SESSION['error_message'] . '
'; + unset($_SESSION['error_message']); + } + ?> + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+ + + diff --git a/update_order_status.php b/update_order_status.php new file mode 100644 index 0000000..169b557 --- /dev/null +++ b/update_order_status.php @@ -0,0 +1,42 @@ +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; diff --git a/update_profile.php b/update_profile.php new file mode 100644 index 0000000..591623a --- /dev/null +++ b/update_profile.php @@ -0,0 +1,60 @@ +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; +} +?> \ No newline at end of file