based on this info (-- phpMyAdmin SQL Dump -- version… · The Chat Archive
Explore / Programming based on this info (-- phpMyAdmin SQL Dump -- version 5.2.1 --… Save Share Download ▾ Reportbased on this info (-- phpMyAdmin SQL Dump
-- version 5.2.1
-- https://www.phpmyadmin.net/
-- Host: 127.0.0.1:3306
-- Generation Time: Nov 06, 2024 at 04:20 PM
-- Server version: 10.11.9-MariaDB
-- PHP Version: 7.2.34
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT /;
/ !40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS /;
/ !40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION /;
/ !40101 SET NAMES utf8mb4 */;
--
-- Database: u406552082_kaakalia
--
-- Table structure for table customers
CREATE TABLE customers (
id int(11) NOT NULL,
name varchar(100) NOT NULL,
contact varchar(50) DEFAULT NULL,
delivery_address text DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table orders
CREATE TABLE orders (
id int(11) NOT NULL,
customer_id int(11) NOT NULL,
product_id int(11) NOT NULL,
status enum('Pending','In Progress','Completed','Delivered') DEFAULT 'Pending',
order_date datetime DEFAULT current_timestamp(),
delivery_datetime datetime DEFAULT NULL,
delivery_date date DEFAULT NULL,
quantity int(11) NOT NULL DEFAULT 1,
packaging_preferences varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table order_items
CREATE TABLE order_items (
id int(11) NOT NULL,
order_id int(11) NOT NULL,
product_id int(11) NOT NULL,
quantity int(11) NOT NULL,
packaging_preferences varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table products
CREATE TABLE products (
id int(11) NOT NULL,
name varchar(100) NOT NULL,
size varchar(50) DEFAULT NULL,
price decimal(10,2) NOT NULL,
category varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Show full message · 1,045 lines Assistant2024-11-06 19:10 UTC Copy response
Copy first prompt
Details
Provider OpenAI
Model provenance As recorded by source dataset
Turns 1 (2 messages)
Language en
Conversation date Nov 6, 2024
Added to archive Nov 16, 2026
ID 01m7h425nf9m5rfh423zm1x4hvSource & license Imported from WildChat-4.8M (AI2) (source ). Imported records earn no Research Points.
Upstream record: 12710423976af3403413b6f9e4f4dd77
Zhao et al., WildChat: 1M ChatGPT Interaction Logs in the Wild (ICLR 2024). Contains information from WildChat-4.8M, made available under the ODC Attribution License.
License: ODC-BY-1.0
--
-- Table structure for table users CREATE TABLE users (
id int(11) NOT NULL,
username varchar(50) NOT NULL,
password varchar(255) NOT NULL,
role enum('admin','staff') NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Indexes for dumped tables
--
-- Indexes for table customers ALTER TABLE customers
ADD PRIMARY KEY (id);
--
-- Indexes for table orders ALTER TABLE orders
ADD PRIMARY KEY (id),
ADD KEY customer_id (customer_id);
--
-- Indexes for table order_items ALTER TABLE order_items
ADD PRIMARY KEY (id),
ADD KEY order_id (order_id),
ADD KEY product_id (product_id);
--
-- Indexes for table products ALTER TABLE products
ADD PRIMARY KEY (id);
--
-- Indexes for table users ALTER TABLE users
ADD PRIMARY KEY (id),
ADD UNIQUE KEY username (username);
--
-- AUTO_INCREMENT for dumped tables
--
-- AUTO_INCREMENT for table customers ALTER TABLE customers
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table orders ALTER TABLE orders
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table order_items ALTER TABLE order_items
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table products ALTER TABLE products
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table users ALTER TABLE users
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- Constraints for dumped tables
--
-- Constraints for table orders ALTER TABLE orders
ADD CONSTRAINT orders_ibfk_1 FOREIGN KEY (customer_id) REFERENCES customers (id),
ADD CONSTRAINT orders_ibfk_2 FOREIGN KEY (product_id) REFERENCES products (id);
--
-- Constraints for table order_items ALTER TABLE order_items
ADD CONSTRAINT order_items_ibfk_1 FOREIGN KEY (order_id) REFERENCES orders (id) ON DELETE CASCADE,
ADD CONSTRAINT order_items_ibfk_2 FOREIGN KEY (product_id) REFERENCES products (id) ON DELETE CASCADE;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT /;
/ !40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS /;
/ !40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;) database, and fix this header (
code Copy code
<!-- Desktop Navigation Buttons -->
<nav class="cool-nav-buttons d-none d-md-flex">
<a href="/public/orders/add_order.php" class="cool-nav-btn">
<i class="bi bi-plus-circle-fill me-2"></i> Add New Order
</a>
<a href="/public/orders/view_orders.php" class="cool-nav-btn">
<i class="bi bi-eye-fill me-2"></i> View Orders
</a>
<a href="/public/products/manage_products.php" class="cool-nav-btn">
<i class="bi bi-box-seam-fill me-2"></i> Manage Products
</a>
<a href="/public/users/manage_users.php" class="cool-nav-btn">
<i class="bi bi-people-fill me-2"></i> Manage Users
</a>
<a href="/public/reports/generate_reports.php" class="cool-nav-btn">
<i class="bi bi-bar-chart-fill me-2"></i> Generate Reports
</a>
</nav>
<!-- Mobile Navigation Toggle -->
<button class="navbar-toggler d-md-none" type="button" data-bs-toggle="collapse" data-bs-target="#mobileNav" aria-controls="mobileNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon">
<i class="bi bi-list" style="font-size: 1.5rem; color: #FFFFFF;"></i>
</span>
</button>
<!-- Mobile Navigation Menu -->
<div class="collapse navbar-collapse d-md-none" id="mobileNav">
<nav class="cool-nav-mobile-buttons">
<a href="/public/orders/add_order.php" class="cool-nav-mobile-btn">
<i class="bi bi-plus-circle-fill me-2"></i> Add New Order
</a>
<a href="/public/orders/view_orders.php" class="cool-nav-mobile-btn">
<i class="bi bi-eye-fill me-2"></i> View Orders
</a>
<a href="/public/products/manage_products.php" class="cool-nav-mobile-btn">
<i class="bi bi-box-seam-fill me-2"></i> Manage Products
</a>
<a href="/public/users/manage_users.php" class="cool-nav-mobile-btn">
<i class="bi bi-people-fill me-2"></i> Manage Users
</a>
<a href="/public/reports/generate_reports.php" class="cool-nav-mobile-btn">
<i class="bi bi-bar-chart-fill me-2"></i> Generate Reports
</a>
</nav>
</div>
<!-- User Profile and Settings -->
<div class="cool-user-profile dropdown">
<img src="/assets/images/user-placeholder.png" alt="User Avatar" id="userDropdown" class="cool-user-avatar" data-bs-toggle="dropdown" aria-expanded="false">
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="userDropdown">
<li><a class="dropdown-item" href="/public/users/settings.php">Account Settings</a></li>
<li><a class="dropdown-item" href="/public/logout.php">Logout</a></li>
</ul>
</div>
</div>
) and make it clear header on dabasboard (<?php
// public/dashboard.php
// Enable error reporting for debugging (disable in production)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Include authentication and database connection
require_once '../includes/auth.php';
require_once '../includes/db_connect.php';
// Include Header
require_once '../includes/header.php';
Helper Function to Fetch Product Price by ID
@param mysqli $conn
@param int $product_id
@return float
*/
function get_product_price(c o n n , conn, co nn , product_id) {
p r i c e s q l = " S E L E C T p r i c e F R O M p r o d u c t s W H E R E i d = ? L I M I T 1 " ; price_sql = "SELECT price FROM products WHERE id = ? LIMIT 1";
p r i c e s q l = " S E L E C T p r i ce F R O M p r o d u c t s W H E R E i d = ? L I M I T 1" ; price_stmt = c o n n − > p r e p a r e ( conn->prepare( co nn − > p r e p a r e ( price_sql);
if (!p r i c e s t m t ) r e t u r n 0.00 ; price_stmt) {
return 0.00;
}
p r i c e s t m t ) r e t u r n 0.00 ; price_stmt->bind_param("i", p r o d u c t i d ) ; product_id);
p r o d u c t i d ) ; price_stmt->execute();
p r i c e r e s u l t = price_result = p r i c e r es u l t = price_stmt->get_result();
if (price_result && price_result->num_rows === 1) {
p r i c e = ( f l o a t ) price = (float) p r i ce = ( f l o a t ) price_result->fetch_assoc()['price'];
} else {
price = 0.00;
}
price_stmt->close();
return $price;
}
// Total Orders
t o t a l O r d e r s S q l = " S E L E C T C O U N T ( ∗ ) A S t o t a l F R O M o r d e r s " ; totalOrdersSql = "SELECT COUNT(*) AS total FROM orders";
t o t a l O r d er s S q l = " S E L E C T C O U N T ( ∗ ) A S t o t a l F R O M or d er s " ; totalOrdersResult = c o n n − > q u e r y ( conn->query( co nn − > q u er y ( totalOrdersSql);
t o t a l O r d e r s = ( totalOrders = ( t o t a l O r d er s = ( totalOrdersResult && r o w = row = r o w = totalOrdersResult->fetch_assoc()) ? (int)$row['total'] : 0;
// Pending Orders
p e n d i n g O r d e r s S q l = " S E L E C T C O U N T ( ∗ ) A S t o t a l F R O M o r d e r s W H E R E s t a t u s = ′ P e n d i n g ′ " ; pendingOrdersSql = "SELECT COUNT(*) AS total FROM orders WHERE status = 'Pending'";
p e n d in g O r d er s S q l = " S E L E C T C O U N T ( ∗ ) A S t o t a l F R O M or d er s W H E R E s t a t u s = ′ P e n d in g ′ " ; pendingOrdersResult = c o n n − > q u e r y ( conn->query( co nn − > q u er y ( pendingOrdersSql);
p e n d i n g O r d e r s = ( pendingOrders = ( p e n d in g O r d er s = ( pendingOrdersResult && r o w = row = r o w = pendingOrdersResult->fetch_assoc()) ? (int)$row['total'] : 0;
// Completed Orders
c o m p l e t e d O r d e r s S q l = " S E L E C T C O U N T ( ∗ ) A S t o t a l F R O M o r d e r s W H E R E s t a t u s = ′ C o m p l e t e d ′ " ; completedOrdersSql = "SELECT COUNT(*) AS total FROM orders WHERE status = 'Completed'";
co m pl e t e d O r d er s S q l = " S E L E C T C O U N T ( ∗ ) A S t o t a l F R O M or d er s W H E R E s t a t u s = ′ C o m pl e t e d ′ " ; completedOrdersResult = c o n n − > q u e r y ( conn->query( co nn − > q u er y ( completedOrdersSql);
c o m p l e t e d O r d e r s = ( completedOrders = ( co m pl e t e d O r d er s = ( completedOrdersResult && r o w = row = r o w = completedOrdersResult->fetch_assoc()) ? (int)$row['total'] : 0;
// Delivered Orders
d e l i v e r e d O r d e r s S q l = " S E L E C T C O U N T ( ∗ ) A S t o t a l F R O M o r d e r s W H E R E s t a t u s = ′ D e l i v e r e d ′ " ; deliveredOrdersSql = "SELECT COUNT(*) AS total FROM orders WHERE status = 'Delivered'";
d e l i v er e d O r d er s S q l = " S E L E C T C O U N T ( ∗ ) A S t o t a l F R O M or d er s W H E R E s t a t u s = ′ D e l i v er e d ′ " ; deliveredOrdersResult = c o n n − > q u e r y ( conn->query( co nn − > q u er y ( deliveredOrdersSql);
d e l i v e r e d O r d e r s = ( deliveredOrders = ( d e l i v er e d O r d er s = ( deliveredOrdersResult && r o w = row = r o w = deliveredOrdersResult->fetch_assoc()) ? (int)$row['total'] : 0;
// Total Sales from Orders (Primary Products)
t o t a l S a l e s O r d e r s S q l = " S E L E C T S U M ( p r o d u c t s . p r i c e ∗ o r d e r s . q u a n t i t y ) A S t o t a l F R O M o r d e r s J O I N p r o d u c t s O N o r d e r s . p r o d u c t i d = p r o d u c t s . i d W H E R E o r d e r s . s t a t u s I N ( ′ C o m p l e t e d ′ , ′ D e l i v e r e d ′ ) " ; totalSalesOrdersSql = "
SELECT SUM(products.price * orders.quantity) AS total
FROM orders
JOIN products ON orders.product_id = products.id
WHERE orders.status IN ('Completed', 'Delivered')
";
t o t a l S a l es O r d er s S q l = " S E L E C T S U M ( p r o d u c t s . p r i ce ∗ or d totalSalesOrdersResult = c o n n − > q u e r y ( conn->query( co nn − > q u er y ( totalSalesOrdersSql);
t o t a l S a l e s O r d e r s = ( totalSalesOrders = ( t o t a l S a l es O r d er s = ( totalSalesOrdersResult && r o w = row = r o w = totalSalesOrdersResult->fetch_assoc()) ? (float)$row['total'] : 0.00;
// Total Sales from Order Items (Additional Products)
t o t a l S a l e s O r d e r I t e m s S q l = " S E L E C T S U M ( p r o d u c t s . p r i c e ∗ o r d e r i t e m s . q u a n t i t y ) A S t o t a l F R O M o r d e r i t e m s J O I N p r o d u c t s O N o r d e r i t e m s . p r o d u c t i d = p r o d u c t s . i d J O I N o r d e r s O N o r d e r i t e m s . o r d e r i d = o r d e r s . i d W H E R E o r d e r s . s t a t u s I N ( ′ C o m p l e t e d ′ , ′ D e l i v e r e d ′ ) " ; totalSalesOrderItemsSql = "
SELECT SUM(products.price * order_items.quantity) AS total
FROM order_items
JOIN products ON order_items.product_id = products.id
JOIN orders ON order_items.order_id = orders.id
WHERE orders.status IN ('Completed', 'Delivered')
";
t o t a l S a l es O r d er I t e m s S q l = " S E L E C T S U M ( p r o d u c t s . p r i ce ∗ totalSalesOrderItemsResult = c o n n − > q u e r y ( conn->query( co nn − > q u er y ( totalSalesOrderItemsSql);
t o t a l S a l e s O r d e r I t e m s = ( totalSalesOrderItems = ( t o t a l S a l es O r d er I t e m s = ( totalSalesOrderItemsResult && r o w = row = r o w = totalSalesOrderItemsResult->fetch_assoc()) ? (float)$row['total'] : 0.00;
// Total Sales (Combined)
t o t a l S a l e s = totalSales = t o t a l S a l es = totalSalesOrders + $totalSalesOrderItems;
// Fetch Recent Orders (Primary and Additional Products)
r e c e n t O r d e r s S q l = " S E L E C T o r d e r s . i d A S o r d e r i d , c u s t o m e r s . n a m e A S c u s t o m e r n a m e , c u s t o m e r s . c o n t a c t , c u s t o m e r s . d e l i v e r y a d d r e s s , o r d e r s . s t a t u s , o r d e r s . o r d e r d a t e , o r d e r s . d e l i v e r y d a t e t i m e , p r o d u c t s . i d A S p r i m a r y p r o d u c t i d , − − A d d e d t h i s l i n e p r o d u c t s . n a m e A S p r i m a r y p r o d u c t n a m e , p r o d u c t s . s i z e A S p r i m a r y p r o d u c t s i z e , o r d e r s . q u a n t i t y A S p r i m a r y q u a n t i t y , o r d e r s . p a c k a g i n g p r e f e r e n c e s A S p r i m a r y p a c k a g i n g p r e f e r e n c e s F R O M o r d e r s J O I N c u s t o m e r s O N o r d e r s . c u s t o m e r i d = c u s t o m e r s . i d J O I N p r o d u c t s O N o r d e r s . p r o d u c t i d = p r o d u c t s . i d O R D E R B Y o r d e r s . o r d e r d a t e D E S C L I M I T 5 " ; recentOrdersSql = "
SELECT
orders.id AS order_id,
customers.name AS customer_name,
customers.contact,
customers.delivery_address,
orders.status,
orders.order_date,
orders.delivery_datetime,
products.id AS primary_product_id, -- Added this line
products.name AS primary_product_name,
products.size AS primary_product_size,
orders.quantity AS primary_quantity,
orders.packaging_preferences AS primary_packaging_preferences
FROM orders
JOIN customers ON orders.customer_id = customers.id
JOIN products ON orders.product_id = products.id
ORDER BY orders.order_date DESC
LIMIT 5
";
r ece n tO r d er s S q l = " S E L E C T or d er s . i d A S or d e r i d , c u s recentOrdersResult = c o n n − > q u e r y ( conn->query( co nn − > q u er y ( recentOrdersSql);
r e c e n t O r d e r s = ( recentOrders = ( r ece n tO r d er s = ( recentOrdersResult && r e c e n t O r d e r s R e s u l t − > n u m r o w s > 0 ) ? recentOrdersResult->num_rows > 0) ? r ece n tO r d er s R es u l t − > n u m r o w s recentOrdersResult : false;
// Fetch Order Items for Recent Orders
r e c e n t O r d e r I d s = [ ] ; i f ( recentOrderIds = [];
if ( r ece n tO r d er I d s = [ ] ; i f ( recentOrders) {
while (o r d e r = order = or d er = recentOrders->fetch_assoc()) {
r e c e n t O r d e r I d s [ ] = ( i n t ) recentOrderIds[] = (int) r ece n tO r d er I d s [ ] = ( in t ) order['order_id'];
}
}
// Reset the pointer of recentOrdersResult for later use
if (recentOrders) {
recentOrdersResult->data_seek(0);
}
// Fetch all additional products for recent orders
a d d i t i o n a l P r o d u c t s = [ ] ; i f ( ! e m p t y ( additionalProducts = [];
if (!empty( a dd i t i o na l P r o d u c t s = [ ] ; i f ( ! e m pt y ( recentOrderIds)) {
p l a c e h o l d e r s = i m p l o d e ( ′ , ′ , a r r a y f i l l ( 0 , c o u n t ( placeholders = implode(',', array_fill(0, count( pl a ce h o l d er s = im pl o d e ( ′ , ′ , a r r a y f recentOrderIds), '?'));
t y p e s = s t r r e p e a t ( ′ i ′ , c o u n t ( types = str_repeat('i', count( t y p es = s t r r e p e a t ( ′ i recentOrderIds));
a d d i t i o n a l P r o d u c t s S q l = " S E L E C T o r d e r i t e m s . o r d e r i d , p r o d u c t s . n a m e A S p r o d u c t n a m e , p r o d u c t s . s i z e A S p r o d u c t s i z e , o r d e r i t e m s . q u a n t i t y , o r d e placeholders)
";
a d d i t i o n a l P r o d u c t s S t m t = additionalProductsStmt = a dd i t i o na l P r o d u c t s S t m t = conn->prepare(a d d i t i o n a l P r o d u c t s S q l ) ; i f ( additionalProductsSql);
if ( a dd i t i o na l P r o d u c t s S q l ) ; i f ( additionalProductsStmt) {
a d d i t i o n a l P r o d u c t s S t m t − > b i n d p a r a m ( additionalProductsStmt->bind_param( a dd i t i o na l P r o d u c t s S t m t − > bin d p types, ...r e c e n t O r d e r I d s ) ; recentOrderIds);
r ece n tO r d er I d s ) ; additionalProductsStmt->execute();
a d d i t i o n a l P r o d u c t s R e s u l t = additionalProductsResult = a dd i t i o na l P r o d u c t s R es u l t = additionalProductsStmt->get_result();
while (i t e m = item = i t e m = additionalProductsResult->fetch_assoc()) {
a d d i t i o n a l P r o d u c t s [ additionalProducts[ a dd i t i o na l P r o d u c t s [ item['order_id']][] = item;
}
additionalProductsStmt->close();
}
}
?>
code Copy code
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700&display=swap" rel="stylesheet">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
<!-- Bootstrap Icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">
<!-- Embedded Custom Styles -->
<style>
/* ---------------------------------------------------
1. CSS Variables for Consistent Design
---------------------------------------------------- */
:root {
--dark-gray: #333333; /* Header and Footer Background */
--button-add-order: #e2a20c; /* Light Golden-Yellow */
--button-view-orders: #118AB2; /* Blue */
--button-manage-products: #06D6A0; /* Green */
--button-manage-users: #F4A261; /* Orange */
--button-generate-reports: #EF476F; /* Red-Pink */
--main-text: #333333;
--secondary-text: #666666;
--white: #FFFFFF;
--background-gradient: linear-gradient(to bottom, #f5f7fa, #c3cfe2);
--divider-color: #FFD166;
--hover-shadow: rgba(0, 0, 0, 0.2);
}
/* ---------------------------------------------------
2. Global Styles
---------------------------------------------------- */
body {
font-family: 'Cairo', sans-serif;
background-color: var(--white);
margin: 0;
padding: 30px;
box-sizing: border-box;
}
h2, h5, p {
margin: 0;
}
/* ---------------------------------------------------
3. Header Styles
---------------------------------------------------- */
.header {
padding: 20px 30px;
background-color: var(--dark-gray);
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 20px;
}
.header h1 {
color: var(--white);
font-size: 24px;
font-weight: bold;
}
/* ---------------------------------------------------
4. Welcome Section
---------------------------------------------------- */
.welcome-section {
background-color: var(--white);
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
border-radius: 8px;
padding: 20px;
text-align: center;
margin-bottom: 20px;
}
.welcome-section h3 {
font-size: 20px;
color: var(--main-text);
margin-bottom: 10px;
}
.welcome-section hr {
width: 50px;
height: 3px;
background-color: var(--button-add-order);
border: none;
margin: 10px auto;
}
/* ---------------------------------------------------
5. Statistics Section
---------------------------------------------------- */
.stats-section {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
margin-bottom: 20px;
}
.stat-card {
background-color: var(--white);
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
border-radius: 8px;
padding: 15px;
display: flex;
align-items: center;
transition: transform 0.2s;
}
.stat-card:hover {
transform: translateY(-5px);
}
.stat-icon {
font-size: 24px;
margin-right: 10px;
}
.stat-icon.total-orders { color: var(--secondary-text); }
.stat-icon.pending-orders { color: var(--button-add-order); }
.stat-icon.completed-orders { color: var(--button-view-orders); }
.stat-icon.delivered-orders { color: var(--button-generate-reports); }
.stat-icon.total-sales { color: var(--button-manage-products); }
.stat-info h5 {
font-size: 16px;
color: var(--main-text);
margin-bottom: 5px;
}
.stat-info p {
font-size: 20px;
font-weight: bold;
color: var(--main-text);
}
/* ---------------------------------------------------
6. Main Buttons Section
---------------------------------------------------- */
.buttons-section {
display: flex;
flex-wrap: wrap;
gap: 20px;
margin-bottom: 20px;
}
.action-button {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
max-width: 200px;
height: 60px;
font-size: 18px;
font-weight: bold;
color: var(--white);
border: none;
border-radius: 8px;
padding: 10px 20px;
cursor: pointer;
transition: transform 0.2s, box-shadow 0.2s;
text-decoration: none;
text-align: center;
}
.action-button.add-order { background-color: var(--button-add-order); }
.action-button.view-orders { background-color: var(--button-view-orders); }
.action-button.manage-products { background-color: var(--button-manage-products); }
.action-button.manage-users { background-color: var(--button-manage-users); }
.action-button.generate-reports { background-color: var(--button-generate-reports); }
.action-button:hover {
transform: scale(1.02);
box-shadow: 0 6px 10px var(--hover-shadow);
}
/* ---------------------------------------------------
7. Recent Orders Section
---------------------------------------------------- */
.recent-orders-section {
background-color: var(--white);
border-radius: 8px;
padding: 20px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.recent-orders-section h4 {
font-size: 16px;
font-weight: bold;
color: var(--main-text);
margin-bottom: 15px;
}
.recent-orders-section table {
width: 100%;
border-collapse: collapse;
}
.recent-orders-section th,
.recent-orders-section td {
padding: 12px;
text-align: left;
font-size: 16px;
vertical-align: top;
}
.recent-orders-section th {
background-color: #333333;
color: var(--white);
font-weight: bold;
}
.recent-orders-section tr:nth-child(even) {
background-color: #F9F9F9;
}
.recent-orders-section tr:hover {
background-color: #e6f7ff;
}
.recent-orders-section td {
font-size: 14px;
color: #333333;
}
.recent-orders-section .view-all {
display: block;
text-align: right;
margin-top: 10px;
font-size: 14px;
color: #118AB2;
font-weight: bold;
text-decoration: none;
}
.recent-orders-section .view-all:hover {
color: #075985;
}
/* Badge Styles */
.badge-status-pending {
background-color: #FFD166;
color: var(--white);
padding: 5px 10px;
border-radius: 12px;
font-size: 12px;
font-weight: bold;
}
.badge-status-in-progress {
background-color: #118AB2;
color: var(--white);
padding: 5px 10px;
border-radius: 12px;
font-size: 12px;
font-weight: bold;
}
.badge-status-completed {
background-color: #06D6A0;
color: var(--white);
padding: 5px 10px;
border-radius: 12px;
font-size: 12px;
font-weight: bold;
}
.badge-status-delivered {
background-color: #EF476F;
color: var(--white);
padding: 5px 10px;
border-radius: 12px;
font-size: 12px;
font-weight: bold;
}
/* ---------------------------------------------------
8. Footer Styles
---------------------------------------------------- */
.footer {
background-color: #333333;
color: var(--white);
padding: 15px;
text-align: center;
border-radius: 8px;
font-size: 14px;
line-height: 20px;
margin-top: 40px;
}
/* ---------------------------------------------------
9. Responsive Design Enhancements
---------------------------------------------------- */
@media (min-width: 768px) {
.buttons-section .action-button {
width: 48%;
}
}
@media (max-width: 767px) {
.buttons-section .action-button {
width: 100%;
}
.recent-orders-section table,
.recent-orders-section th,
.recent-orders-section td {
font-size: 12px;
}
}
@media (max-width: 480px) {
.header {
padding: 15px 20px;
}
.header h1 {
font-size: 20px;
}
.welcome-section h3 {
font-size: 18px;
}
.action-button {
font-size: 16px;
height: 50px;
}
.recent-orders-section th,
.recent-orders-section td {
padding: 10px;
font-size: 12px;
}
.recent-orders-section h4 {
font-size: 14px;
}
}
</style>
code Copy code
<!-- Header -->
<div class="header">
<h1>Kaak Alia Dashboard</h1>
</div>
<!-- Welcome Section -->
<div class="welcome-section">
<h3>Welcome to the Kaak Alia Management System!</h3>
<hr>
</div>
<!-- Statistics Section -->
<div class="stats-section">
<!-- Total Orders -->
<div class="stat-card">
<div class="stat-icon total-orders">
<i class="bi bi-cart-fill"></i>
</div>
<div class="stat-info">
<h5>Total Orders</h5>
<p><?= number_format($totalOrders) ?></p>
</div>
</div>
<!-- Pending Orders -->
<div class="stat-card">
<div class="stat-icon pending-orders">
<i class="bi bi-hourglass-top"></i>
</div>
<div class="stat-info">
<h5>Pending Orders</h5>
<p><?= number_format($pendingOrders) ?></p>
</div>
</div>
<!-- Completed Orders -->
<div class="stat-card">
<div class="stat-icon completed-orders">
<i class="bi bi-check-circle-fill"></i>
</div>
<div class="stat-info">
<h5>Completed Orders</h5>
<p><?= number_format($completedOrders) ?></p>
</div>
</div>
<!-- Delivered Orders -->
<div class="stat-card">
<div class="stat-icon delivered-orders">
<i class="bi bi-truck"></i>
</div>
<div class="stat-info">
<h5>Delivered Orders</h5>
<p><?= number_format($deliveredOrders) ?></p>
</div>
</div>
<!-- Total Sales -->
<div class="stat-card">
<div class="stat-icon total-sales">
<i class="bi bi-cash-stack"></i>
</div>
<div class="stat-info">
<h5>Total Sales (KD)</h5>
<p><?= number_format($totalSales, 2) ?></p>
</div>
</div>
</div>
<!-- Main Buttons Section -->
<div class="buttons-section">
<a href="orders/add_order.php" class="action-button add-order">
<i class="bi bi-plus-circle-fill me-2"></i>
Add New Order
</a>
<a href="orders/view_orders.php" class="action-button view-orders">
<i class="bi bi-eye-fill me-2"></i>
View Orders
</a>
<a href="products/manage_products.php" class="action-button manage-products">
<i class="bi bi-box-seam-fill me-2"></i>
Manage Products
</a>
<a href="users/manage_users.php" class="action-button manage-users">
<i class="bi bi-people-fill me-2"></i>
Manage Users
</a>
<a href="reports/generate_reports.php" class="action-button generate-reports">
<i class="bi bi-bar-chart-fill me-2"></i>
Generate Reports
</a>
</div>
<!-- Recent Orders Section -->
<div class="recent-orders-section">
<h4>Recent Orders</h4>
<table>
<thead>
<tr>
<th>#ID</th>
<th>Customer Name</th>
<th>Contact</th>
<th>Delivery Address</th>
<th>Primary Product</th>
<th>Additional Products</th>
<th>Status</th>
<th>Order Date</th>
<th>Delivery DateTime</th>
</tr>
</thead>
<tbody>
<?php if ($recentOrders && $recentOrders->num_rows > 0): ?>
<?php while($order = $recentOrders->fetch_assoc()): ?>
<tr>
<td><?= htmlspecialchars($order['order_id']) ?></td>
<td><?= htmlspecialchars($order['customer_name']) ?></td>
<td><?= htmlspecialchars($order['contact']) ?></td>
<td><?= nl2br(htmlspecialchars($order['delivery_address'])) ?></td>
<td>
<?= htmlspecialchars($order['primary_product_name'] . " - " . $order['primary_product_size'] . " (" . number_format(get_product_price($conn, $order['primary_product_id']), 2) . " KD)") ?><br>
Quantity: <?= htmlspecialchars($order['primary_quantity']) ?><br>
Packaging: <?= htmlspecialchars($order['primary_packaging_preferences'] ?? 'None') ?>
</td>
<td>
<?php
$orderId = (int)$order['order_id'];
if (isset($additionalProducts[$orderId])) {
foreach ($additionalProducts[$orderId] as $item) {
echo htmlspecialchars($item['product_name'] . " - " . $item['product_size'] . " (" . number_format($item['price'], 2) . " KD)") . "<br>";
echo "Quantity: " . htmlspecialchars($item['quantity']) . "<br>";
echo "Packaging: " . htmlspecialchars($item['packaging_preferences'] ?? 'None') . "<br><br>";
}
} else {
echo "None";
}
?>
</td>
<td>
<?php
switch ($order['status']) {
case 'Pending':
echo '<span class="badge-status-pending">Pending</span>';
break;
case 'In Progress':
echo '<span class="badge-status-in-progress">In Progress</span>';
break;
case 'Completed':
echo '<span class="badge-status-completed">Completed</span>';
break;
case 'Delivered':
echo '<span class="badge-status-delivered">Delivered</span>';
break;
default:
echo '<span class="badge bg-light text-dark">Unknown</span>';
}
?>
</td>
<td><?= htmlspecialchars(date("d M Y, h:i A", strtotime($order['order_date']))) ?></td>
<td><?= $order['delivery_datetime'] ? htmlspecialchars(date("d M Y, h:i A", strtotime($order['delivery_datetime']))) : 'N/A' ?></td>
</tr>
<?php endwhile; ?>
<?php else: ?>
<tr>
<td colspan="9" class="text-center">No recent orders.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
<a href="orders/view_orders.php" class="view-all">View All Orders</a>
</div>
<!-- Footer -->
<div class="footer">
© 2024 Kaak Alia Bakery. All rights reserved.
</div>
<!-- Embedded Bootstrap JS -->
<script src="bootstrap/js/bootstrap.bundle.min.js"></script>
To create a clear, functional, and maintainable header for your Kaak Alia Management System , we'll streamline your header.php, optimize the dashboard.php, and ensure that all paths and styles are correctly integrated based on your provided directory structure.
Here's a step-by-step guide to achieve this:
Organize CSS Styles
Revise header.php
Update dashboard.php
Ensure Paths and Asset Loading
Optional: Create a footer.php
1. Organize CSS Styles
For maintainability and better performance, it's recommended to move all CSS styles to external stylesheets rather than embedding them directly within PHP files. This approach keeps your PHP files clean and ensures that styles are cached by browsers, improving load times.
Steps:
Move Header Styles to assets/css/styles.css:
Extract the embedded <style> from your current header.php and append it to your assets/css/styles.css.
css Copy code
/* Header Styles */
.cool-admin-header {
background-color: #4F3F02;
padding: 10px 0;
position: fixed;
top: 0;
width: 100%;
z-index: 1000;
}
.cool-admin-header .cool-logo-image {
height: 40px;
}
/* Desktop Navigation Buttons */
.cool-nav-buttons .cool-nav-btn {
background: linear-gradient(45deg, #4F3F02, #D1C287);
color: #FFFFFF;
padding: 8px 15px;
border-radius: 5px;
text-decoration: none;
margin: 0 5px;
display: flex;
align-items: center;
transition: background 0.3s, transform 0.3s;
}
.cool-nav-buttons .cool-nav-btn:hover {
background: linear-gradient(45deg, #D1C287, #4F3F02);
transform: scale(1.05);
}
/* Mobile Navigation Buttons */
.cool-nav-mobile-buttons .cool-nav-mobile-btn {
background: linear-gradient(45deg, #4F3F02, #D1C287);
color: #FFFFFF;
padding: 10px;
border-radius: 5px;
text-decoration: none;
margin: 5px 0;
display: flex;
align-items: center;
transition: background 0.3s, transform 0.3s;
}
.cool-nav-mobile-buttons .cool-nav-mobile-btn:hover {
background: linear-gradient(45deg, #D1C287, #4F3F02);
transform: scale(1.02);
}
/* User Profile */
.cool-user-profile .cool-user-avatar {
width: 40px;
height: 40px;
border-radius: 50%;
cursor: pointer;
}
/* Dropdown Menu */
.dropdown-menu a.dropdown-item {
color: #333333;
transition: background 0.3s, color 0.3s;
}
.dropdown-menu a.dropdown-item:hover {
background-color: #D1C287;
color: #000000;
}
Ensure assets/css/styles.css is Linked in All Pages:
We'll link this stylesheet in the header.php to ensure all pages that include the header have access to these styles.
2. Revise header.php
We'll streamline your header.php by:
Removing embedded styles.
Linking external stylesheets.
Ensuring all asset paths are correctly referenced based on your directory structure.
Revised header.php
Key Changes:
External CSS Linking:
Bootstrap CSS: Updated the path to /assets/bootstrap/css/bootstrap.min.css.
Custom CSS: Linked the styles.css located at /assets/css/styles.css.
Dynamic CSS Inclusion: Added a PHP block to allow individual pages to include additional CSS if needed.
Removed Embedded Styles:
Moved all embedded <style> content to the external styles.css.
HTML Structure:
Added <!DOCTYPE html> and <html>, <head>, and opening <body> tags to ensure a complete HTML structure within header.php.
Included a <main> tag with top padding to prevent content from being hidden behind the fixed header.
3. Update dashboard.php
With the revised header.php, your dashboard.php should be updated to:
Remove any embedded headers and styles related to the header.
Ensure that all necessary styles are included via external CSS.
Include the footer.php appropriately.
Revised dashboard.php
Key Changes:
Removed Embedded Header and Styles:
The previous <div class="header"> and its styles have been removed to prevent duplication since header.php now includes the header.
External Styles Utilization:
Ensured that all styles are now managed via assets/css/styles.css and Bootstrap.
Bootstrap Table Classes:
Added Bootstrap classes like table and table-striped to the orders table for better styling and responsiveness.
Footer Inclusion:
Retained the require_once '../includes/footer.php'; to include a standardized footer.
4. Ensure Paths and Asset Loading
Given your directory structure, it's crucial to ensure that all paths in your header.php and other included files are correctly referenced. Here's a quick checklist:
CSS and JS Files:
Bootstrap CSS: /assets/bootstrap/css/bootstrap.min.css
Bootstrap JS: Should be included in the footer.php or at the end of your header.php before the closing </body> tag.
Custom Styles: /assets/css/styles.css
Custom Scripts: /assets/js/scripts.js
Images:
Logo: /assets/images/logo.png
User Placeholder: /assets/images/user-placeholder.png
Navigation Links:
Ensure all navigation links start with /public/ to reference the correct files.
Example: Including Bootstrap JS and Custom Scripts in footer.php
If you don't have a footer.php, it's recommended to create one to handle scripts and closing tags.
includes/footer.php:
php Copy code
<?php
// includes/footer.php
?>
</main> <!-- Closing main tag from header.php -->
<!-- Footer -->
<div class="footer">
© 2024 Kaak Alia Bakery. All rights reserved.
</div>
<!-- Bootstrap JS Bundle (includes Popper) -->
<script src="/assets/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- Custom JS -->
<script src="/assets/js/scripts.js"></script>
<!-- Include any additional page-specific JS here -->
<?php
if (isset($additional_js)) {
foreach ($additional_js as $js_file) {
echo '<script src="' . htmlspecialchars($js_file) . '"></script>' . PHP_EOL;
}
}
?>
</body>
</html>
Notes:
Closing Tags:
Ensure that the </main>, <div class="footer">, and closing </body></html> tags are present to maintain proper HTML structure.
Script Inclusion:
Include Bootstrap JS and any custom scripts here to ensure they load after the page content.
5. Optional: Create a footer.php
For consistency and maintainability, create a footer.php to handle footer content and script inclusions.
includes/footer.php:
php Copy code
<?php
// includes/footer.php
?>
</main> <!-- Closing main tag from header.php -->
<!-- Footer -->
<footer class="footer mt-4 py-3 bg-dark text-white text-center">
© 2024 Kaak Alia Bakery. All rights reserved.
</footer>
<!-- Bootstrap JS Bundle (includes Popper) -->
<script src="/assets/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- Custom JS -->
<script src="/assets/js/scripts.js"></script>
<!-- Include any additional page-specific JS here -->
<?php
if (isset($additional_js)) {
foreach ($additional_js as $js_file) {
echo '<script src="' . htmlspecialchars($js_file) . '"></script>' . PHP_EOL;
}
}
?>
</body>
</html>
Integration in dashboard.php
As shown in the revised dashboard.php, ensure you include the footer.php at the end:
php Copy code
<!-- Footer -->
<?php
// Include Footer
require_once '../includes/footer.php';
?>
Final Directory Structure Reference
Ensure your directory structure matches the following to maintain correct path references:
code Copy code
kaakalia.longevacare.com/
├── assets/
│ ├── css/
│ │ └── styles.css
│ ├── js/
│ │ └── scripts.js
│ ├── images/
│ │ ├── logo.png
│ │ └── user-placeholder.png
│ └── bootstrap/
│ ├── css/
│ │ └── bootstrap.min.css
│ └── js/
│ └── bootstrap.bundle.min.js
├── config/
│ └── config.php
├── includes/
│ ├── header.php
│ ├── footer.php
│ ├── auth.php
│ └── db_connect.php
├── public/
│ ├── index.php
│ ├── login.php
│ ├── logout.php
│ ├── dashboard.php
│ ├── orders/
│ │ ├── add_order.php
│ │ ├── view_orders.php
│ │ └── edit_order.php
│ ├── products/
│ │ └── manage_products.php
│ ├── users/
│ │ └── manage_users.php
│ └── reports/
│ └── generate_reports.php
├── index.php
Summary
By following the above steps:
Centralized Styles: Moved all embedded styles to assets/css/styles.css for better maintainability.
Streamlined Header: Revised header.php to include necessary CSS files and removed embedded styles.
Updated Dashboard: Cleaned up dashboard.php to prevent duplicate headers and leverage the centralized header and footer.
Consistent Asset Paths: Ensured all asset paths are correctly referenced based on your directory structure.
Footer Integration: Created a footer.php for consistent footer content and script inclusions across all pages.
This setup not only makes your header clear and functional but also enhances the overall maintainability and scalability of your application.
If you encounter any specific issues during implementation, feel free to ask for further assistance!
Show full message · 751 lines Copy first response
Not yet included in a published release.
er
s
.
q
u
an
t
i
t
y
)
A
S
t
o
t
a
l
F
R
O
M
or
d
er
s
J
O
I
N
p
r
o
d
u
c
t
s
O
N
or
d
er
s
.
p
r
o
d
u
c
t i
d
=
p r o d u c t s . i d W H E R E or d er s . s t a t u s I N ( ′ C o m pl e t e d ′ , ′ D e l i v er e d ′ ) " ;
or d e r i t e m s . q u an t i t y ) A S t o t a l F R O M or d e r i t e m s J O I N p r o d u c t s O N or d e r i t e m s . p r o d u c t i d =
p r o d u c t s . i dJ O I N or d er s O N or d e r i t e m s . or d e r i d =
or d er s . i d W H E R E or d er s . s t a t u s I N ( ′ C o m pl e t e d ′ , ′ D e l i v er e d ′ ) " ;
t
o
m
er
s
.
nam
e
A
S
c
u
s
t
o
m
e
r n
am
e
,
c
u
s
t
o
m
er
s
.
co
n
t
a
c
t
,
c
u
s
t
o
m
er
s
.
d
e
l
i
v
er
y a
dd
r
ess
,
or
d
er
s
.
s
t
a
t
u
s
,
or
d
er
s
.
or
d
e
r d
a
t
e
,
or
d
er
s
.
d
e
l
i
v
er
y d
a
t
e
t
im
e
,
p
r
o
d
u
c
t
s
.
i
d
A
S
p
r
ima
r
y p
r
o
d
u
c
t i
d
,
−
−
A dd e d t hi s l in e p r o d u c t s . nam e A S p r ima r y p r o d u c t n am e , p r o d u c t s . s i z e A S p r ima r y p r o d u c t s i z e , or d er s . q u an t i t y A S p r ima r y q u an t i t y , or d er s . p a c k a g in g p r e f er e n ces A S p r ima r y p a c k a g in g p r e f er e n ces F R O M or d er s J O I N c u s t o m er s O N or d er s . c u s t o m e r i d =
c u s t o m er s . i dJ O I N p r o d u c t s O N or d er s . p r o d u c t i d =
p r o d u c t s . i d O R D E R B Y or d er s . or d e r d a t eD E S C L I M I T 5" ;
>
0 )?
i
l
l
(
0
,
co
u
n
t
(
′
,
co
u
n
t
(
r i t e m s . p a c k a g i n g p r e f e r e n c e s , p r o d u c t s . p r i c e F R O M o r d e r i t e m s J O I N p r o d u c t s O N o r d e r i t e m s . p r o d u c t i d = p r o d u c t s . i d W H E R E o r d e r i t e m s . o r d e r i d I N ( additionalProductsSql = "
SELECT
order_items.order_id,
products.name AS product_name,
products.size AS product_size,
order_items.quantity,
order_items.packaging_preferences,
products.price
FROM order_items
JOIN products ON order_items.product_id = products.id
WHERE order_items.order_id IN ( a dd i t i o na l P r o d u c t s S q l = " S E L E C T or d e r i t e m s . or d e r i d , p r o d u c t s . nam e A S p r o d u c t n am e , p r o d u c t s . s i z e A S p r o d u c t s i z e , or d e r i t e m s . q u an t i t y , or d e r i t e m s . p a c k a g in g p r e f er e n ces , p r o d u c t s . p r i ce F R O M or d e r i t e m s J O I N p r o d u c t s O N or d e r i t e m s . p r o d u c t i d = p r o d u c t s . i d W H E R E or d e r i t e m s . or d e r i d I N (
a
r
am
(
<?php
// includes/header.php
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Kaak Alia Management System</title>
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700&display=swap" rel="stylesheet">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="/assets/bootstrap/css/bootstrap.min.css">
<!-- Bootstrap Icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">
<!-- Custom CSS -->
<link rel="stylesheet" href="/assets/css/styles.css">
<!-- Include any additional page-specific CSS here -->
<?php
if (isset($additional_css)) {
foreach ($additional_css as $css_file) {
echo '<link rel="stylesheet" href="' . htmlspecialchars($css_file) . '">' . PHP_EOL;
}
}
?>
</head>
<body>
<!-- Header -->
<header class="cool-admin-header">
<div class="container d-flex align-items-center justify-content-between">
<!-- Logo -->
<a href="/public/dashboard.php" class="cool-logo">
<img src="/assets/images/logo.png" alt="Kaak Alia Logo" class="cool-logo-image">
</a>
<!-- Desktop Navigation Buttons -->
<nav class="cool-nav-buttons d-none d-md-flex">
<a href="/public/orders/add_order.php" class="cool-nav-btn">
<i class="bi bi-plus-circle-fill me-2"></i> Add New Order
</a>
<a href="/public/orders/view_orders.php" class="cool-nav-btn">
<i class="bi bi-eye-fill me-2"></i> View Orders
</a>
<a href="/public/products/manage_products.php" class="cool-nav-btn">
<i class="bi bi-box-seam-fill me-2"></i> Manage Products
</a>
<a href="/public/users/manage_users.php" class="cool-nav-btn">
<i class="bi bi-people-fill me-2"></i> Manage Users
</a>
<a href="/public/reports/generate_reports.php" class="cool-nav-btn">
<i class="bi bi-bar-chart-fill me-2"></i> Generate Reports
</a>
</nav>
<!-- Mobile Navigation Toggle -->
<button class="navbar-toggler d-md-none" type="button" data-bs-toggle="collapse" data-bs-target="#mobileNav" aria-controls="mobileNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon">
<i class="bi bi-list" style="font-size: 1.5rem; color: #FFFFFF;"></i>
</span>
</button>
<!-- Mobile Navigation Menu -->
<div class="collapse navbar-collapse d-md-none" id="mobileNav">
<nav class="cool-nav-mobile-buttons">
<a href="/public/orders/add_order.php" class="cool-nav-mobile-btn">
<i class="bi bi-plus-circle-fill me-2"></i> Add New Order
</a>
<a href="/public/orders/view_orders.php" class="cool-nav-mobile-btn">
<i class="bi bi-eye-fill me-2"></i> View Orders
</a>
<a href="/public/products/manage_products.php" class="cool-nav-mobile-btn">
<i class="bi bi-box-seam-fill me-2"></i> Manage Products
</a>
<a href="/public/users/manage_users.php" class="cool-nav-mobile-btn">
<i class="bi bi-people-fill me-2"></i> Manage Users
</a>
<a href="/public/reports/generate_reports.php" class="cool-nav-mobile-btn">
<i class="bi bi-bar-chart-fill me-2"></i> Generate Reports
</a>
</nav>
</div>
<!-- User Profile and Settings -->
<div class="cool-user-profile dropdown">
<img src="/assets/images/user-placeholder.png" alt="User Avatar" id="userDropdown" class="cool-user-avatar" data-bs-toggle="dropdown" aria-expanded="false">
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="userDropdown">
<li><a class="dropdown-item" href="/public/users/settings.php">Account Settings</a></li>
<li><a class="dropdown-item" href="/public/logout.php">Logout</a></li>
</ul>
</div>
</div>
</header>
<!-- Optional: Main Content Wrapper -->
<main style="padding-top: 70px;">
<?php
// public/dashboard.php
// Enable error reporting for debugging (disable in production)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Include authentication and database connection
require_once '../includes/auth.php';
require_once '../includes/db_connect.php';
// Include Header
require_once '../includes/header.php';
/**
* Helper Function to Fetch Product Price by ID
*
* @param mysqli $conn
* @param int $product_id
* @return float
*/
function get_product_price($conn, $product_id) {
$price_sql = "SELECT price FROM products WHERE id = ? LIMIT 1";
$price_stmt = $conn->prepare($price_sql);
if (!$price_stmt) {
return 0.00;
}
$price_stmt->bind_param("i", $product_id);
$price_stmt->execute();
$price_result = $price_stmt->get_result();
if ($price_result && $price_result->num_rows === 1) {
$price = (float)$price_result->fetch_assoc()['price'];
} else {
$price = 0.00;
}
$price_stmt->close();
return $price;
}
/**
* Fetch Quick Stats
*/
// Total Orders
$totalOrdersSql = "SELECT COUNT(*) AS total FROM orders";
$totalOrdersResult = $conn->query($totalOrdersSql);
$totalOrders = ($totalOrdersResult && $row = $totalOrdersResult->fetch_assoc()) ? (int)$row['total'] : 0;
// Pending Orders
$pendingOrdersSql = "SELECT COUNT(*) AS total FROM orders WHERE status = 'Pending'";
$pendingOrdersResult = $conn->query($pendingOrdersSql);
$pendingOrders = ($pendingOrdersResult && $row = $pendingOrdersResult->fetch_assoc()) ? (int)$row['total'] : 0;
// Completed Orders
$completedOrdersSql = "SELECT COUNT(*) AS total FROM orders WHERE status = 'Completed'";
$completedOrdersResult = $conn->query($completedOrdersSql);
$completedOrders = ($completedOrdersResult && $row = $completedOrdersResult->fetch_assoc()) ? (int)$row['total'] : 0;
// Delivered Orders
$deliveredOrdersSql = "SELECT COUNT(*) AS total FROM orders WHERE status = 'Delivered'";
$deliveredOrdersResult = $conn->query($deliveredOrdersSql);
$deliveredOrders = ($deliveredOrdersResult && $row = $deliveredOrdersResult->fetch_assoc()) ? (int)$row['total'] : 0;
// Total Sales from Orders (Primary Products)
$totalSalesOrdersSql = "
SELECT SUM(products.price * orders.quantity) AS total
FROM orders
JOIN products ON orders.product_id = products.id
WHERE orders.status IN ('Completed', 'Delivered')
";
$totalSalesOrdersResult = $conn->query($totalSalesOrdersSql);
$totalSalesOrders = ($totalSalesOrdersResult && $row = $totalSalesOrdersResult->fetch_assoc()) ? (float)$row['total'] : 0.00;
// Total Sales from Order Items (Additional Products)
$totalSalesOrderItemsSql = "
SELECT SUM(products.price * order_items.quantity) AS total
FROM order_items
JOIN products ON order_items.product_id = products.id
JOIN orders ON order_items.order_id = orders.id
WHERE orders.status IN ('Completed', 'Delivered')
";
$totalSalesOrderItemsResult = $conn->query($totalSalesOrderItemsSql);
$totalSalesOrderItems = ($totalSalesOrderItemsResult && $row = $totalSalesOrderItemsResult->fetch_assoc()) ? (float)$row['total'] : 0.00;
// Total Sales (Combined)
$totalSales = $totalSalesOrders + $totalSalesOrderItems;
// Fetch Recent Orders (Primary and Additional Products)
$recentOrdersSql = "
SELECT
orders.id AS order_id,
customers.name AS customer_name,
customers.contact,
customers.delivery_address,
orders.status,
orders.order_date,
orders.delivery_datetime,
products.id AS primary_product_id,
products.name AS primary_product_name,
products.size AS primary_product_size,
orders.quantity AS primary_quantity,
orders.packaging_preferences AS primary_packaging_preferences
FROM orders
JOIN customers ON orders.customer_id = customers.id
JOIN products ON orders.product_id = products.id
ORDER BY orders.order_date DESC
LIMIT 5
";
$recentOrdersResult = $conn->query($recentOrdersSql);
$recentOrders = ($recentOrdersResult && $recentOrdersResult->num_rows > 0) ? $recentOrdersResult : false;
// Fetch Order Items for Recent Orders
$recentOrderIds = [];
if ($recentOrders) {
while ($order = $recentOrders->fetch_assoc()) {
$recentOrderIds[] = (int)$order['order_id'];
}
}
// Reset the pointer of recentOrdersResult for later use
if ($recentOrders) {
$recentOrdersResult->data_seek(0);
}
// Fetch all additional products for recent orders
$additionalProducts = [];
if (!empty($recentOrderIds)) {
$placeholders = implode(',', array_fill(0, count($recentOrderIds), '?'));
$types = str_repeat('i', count($recentOrderIds));
$additionalProductsSql = "
SELECT
order_items.order_id,
products.name AS product_name,
products.size AS product_size,
order_items.quantity,
order_items.packaging_preferences,
products.price
FROM order_items
JOIN products ON order_items.product_id = products.id
WHERE order_items.order_id IN ($placeholders)
";
$additionalProductsStmt = $conn->prepare($additionalProductsSql);
if ($additionalProductsStmt) {
$additionalProductsStmt->bind_param($types, ...$recentOrderIds);
$additionalProductsStmt->execute();
$additionalProductsResult = $additionalProductsStmt->get_result();
while ($item = $additionalProductsResult->fetch_assoc()) {
$additionalProducts[$item['order_id']][] = $item;
}
$additionalProductsStmt->close();
}
}
?>
<!-- Dashboard Content Starts Here -->
<h2 class="my-4">Dashboard</h2>
<!-- Welcome Section -->
<div class="welcome-section">
<h3>Welcome to the Kaak Alia Management System!</h3>
<hr>
</div>
<!-- Statistics Section -->
<div class="stats-section">
<!-- Total Orders -->
<div class="stat-card">
<div class="stat-icon total-orders">
<i class="bi bi-cart-fill"></i>
</div>
<div class="stat-info">
<h5>Total Orders</h5>
<p><?= number_format($totalOrders) ?></p>
</div>
</div>
<!-- Pending Orders -->
<div class="stat-card">
<div class="stat-icon pending-orders">
<i class="bi bi-hourglass-top"></i>
</div>
<div class="stat-info">
<h5>Pending Orders</h5>
<p><?= number_format($pendingOrders) ?></p>
</div>
</div>
<!-- Completed Orders -->
<div class="stat-card">
<div class="stat-icon completed-orders">
<i class="bi bi-check-circle-fill"></i>
</div>
<div class="stat-info">
<h5>Completed Orders</h5>
<p><?= number_format($completedOrders) ?></p>
</div>
</div>
<!-- Delivered Orders -->
<div class="stat-card">
<div class="stat-icon delivered-orders">
<i class="bi bi-truck"></i>
</div>
<div class="stat-info">
<h5>Delivered Orders</h5>
<p><?= number_format($deliveredOrders) ?></p>
</div>
</div>
<!-- Total Sales -->
<div class="stat-card">
<div class="stat-icon total-sales">
<i class="bi bi-cash-stack"></i>
</div>
<div class="stat-info">
<h5>Total Sales (KD)</h5>
<p><?= number_format($totalSales, 2) ?></p>
</div>
</div>
</div>
<!-- Main Buttons Section -->
<div class="buttons-section">
<a href="/public/orders/add_order.php" class="action-button add-order">
<i class="bi bi-plus-circle-fill me-2"></i>
Add New Order
</a>
<a href="/public/orders/view_orders.php" class="action-button view-orders">
<i class="bi bi-eye-fill me-2"></i>
View Orders
</a>
<a href="/public/products/manage_products.php" class="action-button manage-products">
<i class="bi bi-box-seam-fill me-2"></i>
Manage Products
</a>
<a href="/public/users/manage_users.php" class="action-button manage-users">
<i class="bi bi-people-fill me-2"></i>
Manage Users
</a>
<a href="/public/reports/generate_reports.php" class="action-button generate-reports">
<i class="bi bi-bar-chart-fill me-2"></i>
Generate Reports
</a>
</div>
<!-- Recent Orders Section -->
<div class="recent-orders-section">
<h4>Recent Orders</h4>
<table class="table table-striped">
<thead>
<tr>
<th>#ID</th>
<th>Customer Name</th>
<th>Contact</th>
<th>Delivery Address</th>
<th>Primary Product</th>
<th>Additional Products</th>
<th>Status</th>
<th>Order Date</th>
<th>Delivery DateTime</th>
</tr>
</thead>
<tbody>
<?php if ($recentOrders && $recentOrders->num_rows > 0): ?>
<?php while($order = $recentOrders->fetch_assoc()): ?>
<tr>
<td><?= htmlspecialchars($order['order_id']) ?></td>
<td><?= htmlspecialchars($order['customer_name']) ?></td>
<td><?= htmlspecialchars($order['contact']) ?></td>
<td><?= nl2br(htmlspecialchars($order['delivery_address'])) ?></td>
<td>
<?= htmlspecialchars($order['primary_product_name'] . " - " . $order['primary_product_size'] . " (" . number_format(get_product_price($conn, $order['primary_product_id']), 2) . " KD)") ?><br>
Quantity: <?= htmlspecialchars($order['primary_quantity']) ?><br>
Packaging: <?= htmlspecialchars($order['primary_packaging_preferences'] ?? 'None') ?>
</td>
<td>
<?php
$orderId = (int)$order['order_id'];
if (isset($additionalProducts[$orderId])) {
foreach ($additionalProducts[$orderId] as $item) {
echo htmlspecialchars($item['product_name'] . " - " . $item['product_size'] . " (" . number_format($item['price'], 2) . " KD)") . "<br>";
echo "Quantity: " . htmlspecialchars($item['quantity']) . "<br>";
echo "Packaging: " . htmlspecialchars($item['packaging_preferences'] ?? 'None') . "<br><br>";
}
} else {
echo "None";
}
?>
</td>
<td>
<?php
switch ($order['status']) {
case 'Pending':
echo '<span class="badge-status-pending">Pending</span>';
break;
case 'In Progress':
echo '<span class="badge-status-in-progress">In Progress</span>';
break;
case 'Completed':
echo '<span class="badge-status-completed">Completed</span>';
break;
case 'Delivered':
echo '<span class="badge-status-delivered">Delivered</span>';
break;
default:
echo '<span class="badge bg-light text-dark">Unknown</span>';
}
?>
</td>
<td><?= htmlspecialchars(date("d M Y, h:i A", strtotime($order['order_date']))) ?></td>
<td><?= $order['delivery_datetime'] ? htmlspecialchars(date("d M Y, h:i A", strtotime($order['delivery_datetime']))) : 'N/A' ?></td>
</tr>
<?php endwhile; ?>
<?php else: ?>
<tr>
<td colspan="9" class="text-center">No recent orders.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
<a href="/public/orders/view_orders.php" class="view-all">View All Orders</a>
</div>
<!-- Footer -->
<?php
// Include Footer
require_once '../includes/footer.php';
?>