Explore / Programming based on thsi info database (-- phpMyAdmin SQL Dump -- version 5.2.1 --… Save Share Download ▾ Reportbased on thsi info database (-- phpMyAdmin SQL Dump
-- version 5.2.1
-- https://www.phpmyadmin.net/
-- Host: 127.0.0.1:3306
-- Generation Time: Nov 07, 2024 at 04:01 AM
-- 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;
--
-- Dumping data for table customers
INSERT INTO customers (id, name, contact, delivery_address) VALUES
(1, 'order_94513', '5162154 84561', 'Qena, 332 host'),
(2, 'order_94513', '8888 5461', 'Qina, Egpyt'),
(3, 'order_94513', '5162154 84561', 'Qena, Egypt'),
(4, 'order_8496', '15546843', 'Qena,Egpyt');
--
-- 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;
--
-- Dumping data for table orders
INSERT INTO orders (id, customer_id, product_id, status, order_date, delivery_datetime, delivery_date, quantity, packaging_preferences) VALUES
(3, 3, 8, 'Completed', '2024-11-06 16:29:21', '2024-11-08 06:31:00', NULL, 1, 'This Order is so Important and type card, (Mahmoud Tawfik)'),
(4, 4, 10, 'Pending', '2024-11-06 18:00:08', '2024-11-07 10:01:00', NULL, 2, 'This Order is so Important and type card, (Mahmoud Tawfik)');
Show full message · 1,157 lines Assistant2024-11-07 04:06 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 7, 2024
Added to archive Nov 16, 2026
ID 01m7h425nfjnj75pa20s967zsqSource & license Imported from WildChat-4.8M (AI2) (source ). Imported records earn no Research Points.
Upstream record: 95856a5b6c93aa3b51121b0878c8c278
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 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;
--
-- Dumping data for table order_items INSERT INTO order_items (id, order_id, product_id, quantity, packaging_preferences) VALUES
(1, 3, 6, 1, '');
--
-- 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;
--
-- Dumping data for table products INSERT INTO products (id, name, size, price, category) VALUES
(1, 'Savory Cake', 'Large', 12.00, 'Savory Cake'),
(2, 'Mini Savory Cake', 'Mini', 6.00, 'Savory Cake'),
(3, 'Mini Savory Cake', 'Mini x24', 9.00, 'Savory Cake'),
(4, 'Mini Savory Cake', 'Mini x36', 12.00, 'Savory Cake'),
(5, 'Special Occasion Box', '35 pieces', 14.50, 'Savory Cake'),
(6, 'Crunchy Pudding', '12 pieces', 12.00, 'Crunchy Pudding'),
(7, 'Kaak - Regular Box Half-kilo', 'Half-kilo', 6.00, 'Kaak'),
(8, 'Kaak - Regular Box One-kilo', 'One-kilo', 8.00, 'Kaak'),
(9, 'Visitor’s Basket - Small', 'Small Basket', 8.00, 'Kaak'),
(10, 'Visitor’s Basket - Large', 'Large Basket', 10.00, 'Kaak'),
(11, 'Special Occasion Box - Kaak', '33 pieces', 11.00, 'Kaak');
--
-- 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;
--
-- Dumping data for table users INSERT INTO users (id, username, password, role) VALUES
(1, 'admin', '2 y 2y 2 y 10e 0 N R 4 E J k O 3 j U u L 1 K q J x 3 E . E 0 I o j b 95 c z j J G b 2 a 7 v 0 G f N 0 V 8 p Q B v 8 W ′ , ′ a d m i n ′ ) , ( 2 , ′ k a a k a l i a ′ , ′ e0NR4EJkO3jUuL1KqJx3E.E0Iojb95czjJGb2a7v0GfN0V8pQBv8W', 'admin'),
(2, 'kaakalia', ' e 0 N R 4 E J k O 3 j U uL 1 K q J x 3 E . E 0 I o j b 95 cz j J G b 2 a 7 v 0 G f N 0 V 8 pQB v 8 W 2y10 10 10 xHUvBhNLyy4eN8WVtCrdzuX0j8wYOVCH6m.czPtqfiWImUCC9w9aO', 'admin');
--
-- 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=5;
--
-- AUTO_INCREMENT for table orders ALTER TABLE orders
MODIFY id int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;
--
-- AUTO_INCREMENT for table order_items ALTER TABLE order_items
MODIFY id int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
--
-- AUTO_INCREMENT for table products ALTER TABLE products
MODIFY id int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=12;
--
-- AUTO_INCREMENT for table users ALTER TABLE users
MODIFY id int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
--
-- 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 */;) , in this codes (<?php
// public/orders/view_orders.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 DIR . '/../../includes/auth.php';
require_once DIR . '/../../includes/db_connect.php';
// Constants for pagination
define('ORDERS_PER_PAGE', 10);
// Helper function to get product price
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->num_rows == 1) {
price = price_result->fetch_assoc()['price'];
} else {
price = "0.00";
}
p r i c e s t m t − > c l o s e ( ) ; r e t u r n price_stmt->close();
return p r i c e s t m t − > c l ose ( ) ; r e t u r n price;
}
// Function to build query string for filter buttons while preserving other parameters
function build_query(new_params = []) {
current_params = G E T ; f o r e a c h ( _GET;
foreach ( G E T ; f or e a c h ( new_params as k e y = > key => k ey => value) {
if (value !== null) { // Only set if value is not null
current_params[k e y ] = key] = k ey ] = value;
} else {
unset(c u r r e n t p a r a m s [ current_params[ c u r r e n t p a r am s [ key]); // Remove if value is null
}
}
// Remove parameters that shouldn't persist
unset(c u r r e n t p a r a m s [ ′ p a g e ′ ] ) ; current_params['page']);
c u r r e n t p a r am s [ ′ p a g e query = http_build_query(c u r r e n t p a r a m s ) ; r e t u r n current_params);
return c u r r e n t p a r am s ) ; r e t u r n query ? '&' . $query : '';
}
// Function to get sort icon HTML based on current sorting
function get_sort_icon(c o l u m n , column, co l u mn , current_sort_by, current_sort_order) {
if ( current_sort_by === column) {
if ( current_sort_order === 'ASC') {
return '';
} else {
return '';
}
}
return '';
}
// Function to sanitize input for SQL
function sanitize_input(input) {
return htmlspecialchars(trim( input));
}
// Handle status update
if (isset(_GET['action']) && _GET['action'] === 'update_status') {
o r d e r i d = i s s e t ( order_id = isset( or d e r i d = i sse t ( _GET['order_id']) ? intval(G E T [ ′ o r d e r i d ′ ] ) : 0 ; _GET['order_id']) : 0;
G E T [ ′ or d e r i d ′ ]) : 0 ; new_status = isset(G E T [ ′ n e w s t a t u s ′ ] ) ? s a n i t i z e i n p u t ( _GET['new_status']) ? sanitize_input( G E T [ ′ n e w s _GET['new_status']) : '';
code Copy code
// Validate new_status (Removed 'In Progress')
$valid_statuses = ['Pending', 'Completed', 'Delivered'];
if ($order_id > 0 && in_array($new_status, $valid_statuses)) {
// If setting to 'Delivered', ensure delivery_datetime is set
if ($new_status === 'Delivered') {
$check_sql = "SELECT delivery_datetime FROM orders WHERE id = ?";
$check_stmt = $conn->prepare($check_sql);
if ($check_stmt) {
$check_stmt->bind_param("i", $order_id);
$check_stmt->execute();
$check_result = $check_stmt->get_result();
if ($check_result->num_rows == 1) {
$order = $check_result->fetch_assoc();
if (empty($order['delivery_datetime'])) {
header("Location: view_orders.php?error=3"); // Delivery datetime not set
exit();
}
}
$check_stmt->close();
} else {
header("Location: view_orders.php?error=2");
exit();
}
}
// Update status using prepared statement
$update_sql = "UPDATE orders SET status = ? WHERE id = ?";
$stmt = $conn->prepare($update_sql);
if ($stmt) {
$stmt->bind_param("si", $new_status, $order_id);
if ($stmt->execute()) {
$stmt->close();
header("Location: view_orders.php?success=1");
exit();
} else {
$stmt->close();
header("Location: view_orders.php?error=1");
exit();
}
} else {
header("Location: view_orders.php?error=2");
exit();
}
} else {
header("Location: view_orders.php?error=2");
exit();
}
// Handle Filters, Sorting, and Pagination
f i l t e r = i s s e t ( filter = isset( f i l t er = i sse t ( _GET['filter']) ? sanitize_input(G E T [ ′ f i l t e r ′ ] ) : ′ a l l ′ ; _GET['filter']) : 'all';
G E T [ ′ f i l t e r ′ ]) : ′ a l l ′ ; search = isset(G E T [ ′ s e a r c h ′ ] ) ? s a n i t i z e i n p u t ( _GET['search']) ? sanitize_input( G E T [ ′ se a r c h _GET['search']) : '';
f r o m d a t e = i s s e t ( from_date = isset( f r o m d a t e = i sse t ( _GET['from_date']) ? sanitize_input(G E T [ ′ f r o m d a t e ′ ] ) : ′ ′ ; _GET['from_date']) : '';
G E T [ ′ f r o m d to_date = isset(G E T [ ′ t o d a t e ′ ] ) ? s a n i t i z e i n p u t ( _GET['to_date']) ? sanitize_input( G E T [ ′ t o d _GET['to_date']) : '';
s o r t b y = i s s e t ( sort_by = isset( sor t b y = i sse t ( _GET['sort_by']) ? sanitize_input(G E T [ ′ s o r t b y ′ ] ) : ′ o r d e r d a t e ′ ; _GET['sort_by']) : 'order_date';
G E T [ ′ sor t b sort_order = isset(G E T [ ′ s o r t o r d e r ′ ] ) ? s a n i t i z e i n p u t ( _GET['sort_order']) ? sanitize_input( G E T [ ′ sor t o _GET['sort_order']) : 'DESC';
p a g e = i s s e t ( page = isset( p a g e = i sse t ( _GET['page']) ? intval($_GET['page']) : 1;
// Validate sort_by and sort_order
a l l o w e d s o r t c o l u m n s = [ ′ o r d e r i d ′ , ′ c u s t o m e r n a m e ′ , ′ c o n t a c t ′ , ′ s t a t u s ′ , ′ o r d e r d a t e ′ , ′ d e l i v e r y d a t e t i m e ′ ] ; i f ( ! i n a r r a y ( allowed_sort_columns = ['order_id', 'customer_name', 'contact', 'status', 'order_date', 'delivery_datetime'];
if (!in_array( a l l o w e d s or t c o l u mn s = [ ′ or d e r sort_by, allowed_sort_columns)) {
sort_by = 'order_date';
}
a l l o w e d s o r t o r d e r s = [ ′ A S C ′ , ′ D E S C ′ ] ; i f ( ! i n a r r a y ( allowed_sort_orders = ['ASC', 'DESC'];
if (!in_array( a l l o w e d s or t o r d er s = [ ′ A S C ′ , ′ D E S C ′ ] ; i f ( ! i n sort_order, allowed_sort_orders)) {
sort_order = 'DESC';
}
// Initialize where conditions
w h e r e c o n d i t i o n s = [ ] ; where_conditions = [];
w h er e c o n d i t i o n s = [ ] ; parameters = [];
$param_types = "";
// Predefined Date Filters
$current_date = date('Y-m-d');
switch (filter) {
case 'today':
where_conditions[] = "DATE(orders.order_date) = ?";
p a r a m e t e r s [ ] = parameters[] = p a r am e t er s [ ] = current_date;
p a r a m t y p e s . = " s " ; b r e a k ; c a s e ′ y e s t e r d a y ′ : param_types .= "s";
break;
case 'yesterday':
p a r a m t y p es . = " s " ; b r e ak ; c a s e ′ y es t er d a y ′ : yesterday = date('Y-m-d', strtotime('-1 day'));
w h e r e c o n d i t i o n s [ ] = " D A T E ( o r d e r s . o r d e r d a t e ) = ? " ; where_conditions[] = "DATE(orders.order_date) = ?";
w h er e c o n d i t i o n s [ ] = parameters[] = y e s t e r d a y ; yesterday;
y es t er d a y ; param_types .= "s";
break;
case 'week':
s t a r t o f w e e k = d a t e ( ′ Y − m − d ′ , s t r t o t i m e ( ′ m o n d a y t h i s w e e k ′ ) ) ; start_of_week = date('Y-m-d', strtotime('monday this week'));
s t a r t o f end_of_week = date('Y-m-d', strtotime('sunday this week'));
w h e r e c o n d i t i o n s [ ] = " D A T E ( o r d e r s . o r d e r d a t e ) B E T W E E N ? A N D ? " ; where_conditions[] = "DATE(orders.order_date) BETWEEN ? AND ?";
w h er e c o n d i t i o n s [ ] parameters[] = s t a r t o f w e e k ; start_of_week;
s t a r t o f w ee k ; parameters[] = e n d o f w e e k ; end_of_week;
e n d o f w ee k ; param_types .= "ss";
break;
case 'month':
s t a r t o f m o n t h = d a t e ( ′ Y − m − 01 ′ ) ; start_of_month = date('Y-m-01');
s t a r t o f m o n t h = d end_of_month = date('Y-m-t');
w h e r e c o n d i t i o n s [ ] = " D A T E ( o r d e r s . o r d e r d a t e ) B E T W E E N ? A N D ? " ; where_conditions[] = "DATE(orders.order_date) BETWEEN ? AND ?";
w h er e c o n d i t i o n s [ ] parameters[] = s t a r t o f m o n t h ; start_of_month;
s t a r t o f m o n t h ; parameters[] = e n d o f m o n t h ; end_of_month;
e n d o f m o n t h ; param_types .= "ss";
break;
case 'custom':
if (!empty(from_date) && !empty( to_date)) {
w h e r e c o n d i t i o n s [ ] = " D A T E ( o r d e r s . o r d e r d a t e ) B E T W E E N ? A N D ? " ; where_conditions[] = "DATE(orders.order_date) BETWEEN ? AND ?";
w h er e c o n d i t i o n s [ ] parameters[] = f r o m d a t e ; from_date;
f r o m d a t e ; parameters[] = t o d a t e ; to_date;
t o d a t e ; param_types .= "ss";
}
break;
case 'all':
default:
// No predefined filter
break;
}
// Search Filter
if (!empty(search)) {
where_conditions[] = "(customers.name LIKE ? OR orders.id LIKE ? OR customers.contact LIKE ?)";
s e a r c h t e r m = " search_term = "%" . se a r c h t er m = " search . "%";
p a r a m e t e r s [ ] = parameters[] = p a r am e t er s [ ] = search_term;
p a r a m e t e r s [ ] = parameters[] = p a r am e t er s [ ] = search_term;
p a r a m e t e r s [ ] = parameters[] = p a r am e t er s [ ] = search_term;
$param_types .= "sss";
}
// Combine all where conditions
w h e r e c l a u s e = " " ; i f ( c o u n t ( where_clause = "";
if (count( w h er e c l a u se = "" ; i f ( co u n t ( where_conditions) > 0) {
w h e r e c l a u s e = " W H E R E " . i m p l o d e ( " A N D " , where_clause = "WHERE " . implode(" AND ", w h er e c l a u se = " W H E R E ". im pl o d e ( " A N D " , where_conditions);
}
// Sorting
o r d e r c l a u s e = " O R D E R B Y order_clause = "ORDER BY or d e r c l a u se = " O R D E R B Y sort_by $sort_order";
// Pagination Calculations
o f f s e t = ( offset = ( o f f se t = ( page - 1) * ORDERS_PER_PAGE;
// Fetch total number of orders for pagination
c o u n t 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 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 count_sql = "
SELECT COUNT(*) as total
FROM orders
JOIN customers ON orders.customer_id = customers.id
JOIN products ON orders.product_id = products.id
co u n t 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 J where_clause
";
c o u n t s t m t = count_stmt = co u n t s t m t = conn->prepare(c o u n t s q l ) ; i f ( count_sql);
if ( co u n t s q l ) ; i f ( count_stmt) {
if (!empty(where_clause)) {
count_stmt->bind_param(p a r a m t y p e s , . . . param_types, ... p a r a m t y p es , ... parameters);
}
c o u n t s t m t − > e x e c u t e ( ) ; count_stmt->execute();
co u n t s t m t − > e x ec u t e ( ) ; count_result = c o u n t s t m t − > g e t r e s u l t ( ) ; count_stmt->get_result();
co u n t s t m t − > g e t r es u l t total_orders = c o u n t r e s u l t − > f e t c h a s s o c ( ) [ ′ t o t a l ′ ] ; count_result->fetch_assoc()['total'];
co u n t r es u l t − > f e t c h count_stmt->close();
} else {
// Handle SQL preparation error
die("Failed to prepare the count query: " . $conn->error);
}
// Calculate total pages
t o t a l p a g e s = c e i l ( total_pages = ceil( t o t a l p a g es = ce i l ( total_orders / ORDERS_PER_PAGE);
// Fetch orders with customer and product details based on filters and sorting
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 , 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 , 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 . p r o d u c t i d A S p r i m a r y p r o d u c t i d , 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 , 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 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 orders_sql = "
SELECT
orders.id AS order_id,
orders.status,
orders.order_date,
orders.delivery_datetime,
customers.name AS customer_name,
customers.contact,
customers.delivery_address,
orders.product_id AS primary_product_id,
orders.quantity AS primary_quantity,
orders.packaging_preferences AS primary_packaging_preferences,
products.name AS primary_product_name,
products.size AS primary_product_size
FROM
orders
JOIN
customers ON orders.customer_id = customers.id
JOIN
products ON orders.product_id = products.id
or 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 where_clause
o r d e r c l a u s e L I M I T order_clause
LIMIT or d e r c l a u se L I M I T offset, " . ORDERS_PER_PAGE . "
";
o r d e r s s t m t = orders_stmt = or d er s s t m t = conn->prepare(o r d e r s s q l ) ; i f ( orders_sql);
if ( or d er s s q l ) ; i f ( orders_stmt) {
if (!empty(where_clause)) {
orders_stmt->bind_param(p a r a m t y p e s , . . . param_types, ... p a r a m t y p es , ... parameters);
}
o r d e r s s t m t − > e x e c u t e ( ) ; orders_stmt->execute();
or d er s s t m t − > e x ec u t e ( ) ; orders_result = orders_stmt->get_result();
} else {
// Handle SQL preparation error
die("Failed to prepare the orders query: " . conn->error);
}
// Fetch order items for all orders
o r d e r i t e m 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 , o r d e r i t e m s . p r o d u c t i d , o r d e r i t e m s . q u a n t i t y , o r d e 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 . 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 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 " ; order_items_sql = "
SELECT
order_items.order_id,
order_items.product_id,
order_items.quantity,
order_items.packaging_preferences,
products.name AS product_name,
products.size AS product_size
FROM
order_items
JOIN
products ON order_items.product_id = products.id
";
or d e r i t e m s s q l = " S E L E C T or d e r order_items_result = c o n n − > q u e r y ( conn->query( co nn − > q u er y ( order_items_sql);
// Organize order items by order_id
o r d e r i t e m s = [ ] ; i f ( order_items = [];
if ( or d e r i t e m s = [ ] ; i f ( order_items_result && order_items_result->num_rows > 0) {
while ( item = order_items_result->fetch_assoc()) {
order_items[i t e m [ ′ o r d e r i d ′ ] ] [ ] = item['order_id']][] = i t e m [ ′ or d e r i d ′ ]] [ ] = item;
}
}
?>
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="/kaak_alia_management_system/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">
<!-- Flatpickr CSS for Date Picker -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
<!-- Embedded Custom Styles -->
<style>
/* ---------------------------------------------------
1. CSS Variables for Consistent Design
---------------------------------------------------- */
:root {
--dark-gray: #343a40; /* Header and Footer Background */
--soft-brown: #FFD166; /* Add New Order Button */
--blue: #118AB2; /* Primary Button */
--green: #06D6A0; /* Success Button */
--orange: #F4A261; /* Warning Button */
--red-pink: #EF476F; /* Danger Button */
--main-text: #333333;
--secondary-text: #666666;
--white: #FFFFFF;
--light-gray: #F9F9F9;
--divider-color: #FFD166;
--transition-speed: 0.3s;
--hover-shadow: rgba(0, 0, 0, 0.2);
}
/* ---------------------------------------------------
2. Global Styles
---------------------------------------------------- */
body {
font-family: 'Cairo', sans-serif;
background: linear-gradient(to bottom, #f5f7fa, #c3cfe2);
margin: 0;
padding: 30px;
box-sizing: border-box;
}
/* ---------------------------------------------------
3. Header Styles
---------------------------------------------------- */
.header {
padding: 20px 30px;
background-color: var(--dark-gray);
border-radius: 8px;
text-align: center;
margin-bottom: 30px;
color: var(--white);
font-size: 28px;
font-weight: bold;
box-shadow: 0 4px 6px var(--hover-shadow);
}
/* ---------------------------------------------------
4. Success and Error Alerts
---------------------------------------------------- */
.alert-success-custom {
background-color: var(--green);
color: var(--white);
border-radius: 8px;
padding: 15px 20px;
margin-bottom: 20px;
text-align: center;
width: 70%;
margin: 20px auto;
box-shadow: 0 4px 6px var(--hover-shadow);
}
.alert-error-custom {
background-color: var(--red-pink);
color: var(--white);
border-radius: 8px;
padding: 15px 20px;
margin-bottom: 20px;
text-align: center;
width: 70%;
margin: 20px auto;
box-shadow: 0 4px 6px var(--hover-shadow);
}
/* ---------------------------------------------------
5. 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: 24px;
font-weight: bold;
color: var(--main-text);
margin-bottom: 20px;
border-bottom: 2px solid var(--divider-color);
padding-bottom: 10px;
}
/* ---------------------------------------------------
6. Filter and Search Section
---------------------------------------------------- */
.filter-search-section {
margin-bottom: 20px;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
}
.filter-search-section .filter-group,
.filter-search-section .search-group {
display: flex;
align-items: center;
margin-bottom: 10px;
}
/* Enhanced Styles for Filter Buttons */
.filter-search-section .filter-group .btn-group .btn {
margin-left: 5px;
background-color: var(--soft-brown);
padding: 8px 12px;
border: none;
border-radius: 5px;
color: var(--dark-gray);
transition: background-color var(--transition-speed), transform var(--transition-speed);
}
.filter-search-section .filter-group .btn-group .btn.active,
.filter-search-section .filter-group .btn-group .btn:hover {
background-color: var(--dark-gray);
color: var(--white);
transform: scale(1.05);
}
.filter-search-section .search-group input,
.filter-search-section .search-group button {
margin-left: 5px;
}
.filter-search-section .date-range-group input {
margin-left: 5px;
width: 150px;
}
/* ---------------------------------------------------
7. Orders Table Styles
---------------------------------------------------- */
.orders-table {
width: 100%;
border-collapse: collapse;
}
.orders-table th,
.orders-table td {
padding: 12px;
text-align: left;
font-size: 16px;
vertical-align: middle;
}
.orders-table th {
background-color: var(--dark-gray);
color: var(--white);
font-weight: bold;
cursor: pointer;
position: relative;
user-select: none;
}
.orders-table th .sort-icon {
margin-left: 5px;
font-size: 12px;
}
.orders-table tr:nth-child(even) {
background-color: var(--light-gray);
}
.orders-table tr:hover {
background-color: #e6f7ff;
}
.orders-table td {
font-size: 14px;
color: var(--main-text);
position: relative;
}
/* 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-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;
}
/* Highlight New Order IDs */
.new-order {
color: #EF476F;
font-weight: bold;
}
/* ---------------------------------------------------
8. Actions Column Styles
---------------------------------------------------- */
.action-buttons .btn {
margin-right: 5px;
transition: transform var(--transition-speed);
}
.action-buttons .btn:hover {
transform: scale(1.1);
}
/* Dropdown Styles */
.dropdown-menu > a {
cursor: pointer;
}
/* ---------------------------------------------------
9. Footer Styles
---------------------------------------------------- */
.footer {
background-color: var(--dark-gray);
color: var(--white);
padding: 15px;
text-align: center;
border-radius: 8px;
font-size: 14px;
line-height: 20px;
margin-top: 40px;
box-shadow: 0 4px 6px var(--hover-shadow);
}
/* ---------------------------------------------------
10. Responsive Design Enhancements
---------------------------------------------------- */
@media (max-width: 992px) {
.filter-search-section {
flex-direction: column;
align-items: flex-start;
}
.filter-search-section .filter-group,
.filter-search-section .search-group,
.filter-search-section .date-range-group {
width: 100%;
justify-content: space-between;
}
.orders-table th, .orders-table td {
font-size: 14px;
}
}
@media (max-width: 768px) {
/* Adjust filter and search input widths */
.filter-search-section .filter-group .btn-group .btn,
.filter-search-section .search-group input,
.filter-search-section .date-range-group input {
width: 100%;
margin: 5px 0;
}
.filter-search-section .search-group button {
width: 100%;
}
.orders-table {
display: block;
overflow-x: auto;
white-space: nowrap;
}
.orders-table th, .orders-table td {
padding: 8px;
}
}
/* Additional Styles */
.btn-reset {
margin-left: 10px;
}
</style>
code Copy code
<!-- Header -->
<div class="header">
View Orders
</div>
<!-- Display Success or Error Messages -->
<?php if (isset($_GET['success']) && $_GET['success'] == 1): ?>
<div class="alert alert-success alert-success-custom" role="alert">
Order status updated successfully!
</div>
<?php endif; ?>
<?php if (isset($_GET['error'])): ?>
<?php if ($_GET['error'] == 1): ?>
<div class="alert alert-danger alert-error-custom" role="alert">
Failed to update order status.
</div>
<?php elseif ($_GET['error'] == 2): ?>
<div class="alert alert-danger alert-error-custom" role="alert">
Invalid status selected.
</div>
<?php elseif ($_GET['error'] == 3): ?>
<div class="alert alert-danger alert-error-custom" role="alert">
Cannot set status to Delivered without a delivery date and time.
</div>
<?php endif; ?>
<?php endif; ?>
<!-- Container -->
<div class="recent-orders-section">
<h4>All Orders</h4>
<!-- Filter and Search Section -->
<div class="filter-search-section">
<!-- Predefined Date Filters -->
<div class="filter-group mb-3">
<span class="me-2">Filter:</span>
<div class="btn-group" role="group" aria-label="Date Filters">
<a href="view_orders.php?filter=all<?php echo build_query(['filter' => 'all', 'page' => null]); ?>" class="btn <?php echo $filter === 'all' ? 'active' : 'btn-outline-primary'; ?>">All</a>
<a href="view_orders.php?filter=today<?php echo build_query(['filter' => 'today', 'page' => null]); ?>" class="btn <?php echo $filter === 'today' ? 'active' : 'btn-outline-primary'; ?>">Today</a>
<a href="view_orders.php?filter=yesterday<?php echo build_query(['filter' => 'yesterday', 'page' => null]); ?>" class="btn <?php echo $filter === 'yesterday' ? 'active' : 'btn-outline-primary'; ?>">Yesterday</a>
<a href="view_orders.php?filter=week<?php echo build_query(['filter' => 'week', 'page' => null]); ?>" class="btn <?php echo $filter === 'week' ? 'active' : 'btn-outline-primary'; ?>">This Week</a>
<a href="view_orders.php?filter=month<?php echo build_query(['filter' => 'month', 'page' => null]); ?>" class="btn <?php echo $filter === 'month' ? 'active' : 'btn-outline-primary'; ?>">This Month</a>
</div>
</div>
<!-- Date Range Filters -->
<div class="date-range-group mb-3">
<form method="GET" action="view_orders.php" class="d-flex align-items-center flex-wrap">
<input type="hidden" name="filter" value="custom">
<input type="hidden" name="search" value="<?php echo htmlspecialchars($search); ?>">
<input type="hidden" name="sort_by" value="<?php echo htmlspecialchars($sort_by); ?>">
<input type="hidden" name="sort_order" value="<?php echo htmlspecialchars($sort_order); ?>">
<label for="from_date" class="me-2">From:</label>
<input type="text" id="from_date" name="from_date" class="form-control me-3 mb-2" placeholder="YYYY-MM-DD" value="<?php echo htmlspecialchars($from_date); ?>" readonly>
<label for="to_date" class="me-2">To:</label>
<input type="text" id="to_date" name="to_date" class="form-control me-3 mb-2" placeholder="YYYY-MM-DD" value="<?php echo htmlspecialchars($to_date); ?>" readonly>
<button type="submit" class="btn btn-success mb-2">Apply</button>
</form>
</div>
<!-- Search Group -->
<div class="search-group">
<form method="GET" action="view_orders.php" class="d-flex align-items-center flex-wrap">
<input type="hidden" name="filter" value="<?php echo htmlspecialchars($filter); ?>">
<input type="hidden" name="from_date" value="<?php echo htmlspecialchars($from_date); ?>">
<input type="hidden" name="to_date" value="<?php echo htmlspecialchars($to_date); ?>">
<input type="hidden" name="sort_by" value="<?php echo htmlspecialchars($sort_by); ?>">
<input type="hidden" name="sort_order" value="<?php echo htmlspecialchars($sort_order); ?>">
<input type="text" name="search" class="form-control me-2 mb-2" placeholder="Search by Customer, ID, or Contact" value="<?php echo htmlspecialchars($search); ?>">
<button type="submit" class="btn btn-primary mb-2">Search</button>
<?php if (!empty($search) || !empty($from_date) || !empty($to_date)): ?>
<a href="view_orders.php<?php echo build_query(['search' => null, 'from_date' => null, 'to_date' => null]); ?>" class="btn btn-outline-secondary ms-2 mb-2">Reset</a>
<?php endif; ?>
</form>
</div>
</div>
<!-- Orders Table -->
<div class="table-responsive">
<table class="table table-striped table-hover orders-table">
<thead>
<tr>
<th onclick="sortTable('order_id')">
ID
<?php echo get_sort_icon('order_id', $sort_by, $sort_order); ?>
</th>
<th onclick="sortTable('customer_name')">
Customer
<?php echo get_sort_icon('customer_name', $sort_by, $sort_order); ?>
</th>
<th onclick="sortTable('contact')">
Contact
<?php echo get_sort_icon('contact', $sort_by, $sort_order); ?>
</th>
<th>Delivery Address</th>
<th>Primary Product</th>
<th>Additional Products</th>
<th onclick="sortTable('status')">
Status
<?php echo get_sort_icon('status', $sort_by, $sort_order); ?>
</th>
<th onclick="sortTable('order_date')">
Order Date
<?php echo get_sort_icon('order_date', $sort_by, $sort_order); ?>
</th>
<th onclick="sortTable('delivery_datetime')">
Delivery DateTime
<?php echo get_sort_icon('delivery_datetime', $sort_by, $sort_order); ?>
</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if ($orders_result && $orders_result->num_rows > 0): ?>
<?php while($order = $orders_result->fetch_assoc()): ?>
<?php
// Check if the order is new (created within last 24 hours)
$is_new = (strtotime($order['order_date']) >= strtotime('-1 day'));
?>
<tr>
<td class="<?php echo $is_new ? 'new-order' : ''; ?>">
<?= htmlspecialchars($order['order_id']) ?>
</td>
<td><?= htmlspecialchars($order['customer_name']) ?></td>
<td><?= htmlspecialchars($order['contact']) ?></td>
<td><?= nl2br(htmlspecialchars($order['delivery_address'])) ?></td>
<td>
<strong><?= htmlspecialchars($order['primary_product_name']) ?></strong> - <?= htmlspecialchars($order['primary_product_size']) ?><br>
Price: <?= 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']) ?>
</td>
<td>
<?php
if (isset($order_items[$order['order_id']])) {
foreach ($order_items[$order['order_id']] as $item) {
echo "<strong>" . htmlspecialchars($item['product_name']) . "</strong> - " . htmlspecialchars($item['product_size']) . "<br>";
echo "Price: " . number_format(get_product_price($conn, $item['product_id']), 2) . " KD<br>";
echo "Qty: " . htmlspecialchars($item['quantity']) . "<br>";
echo "Packaging: " . htmlspecialchars($item['packaging_preferences']) . "<br><br>";
}
} else {
echo "None";
}
?>
</td>
<td>
<?php
switch ($order['status']) {
case 'Pending':
echo '<span class="badge-status-pending">Pending</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><?= date("d M Y, h:i A", strtotime($order['order_date'])) ?></td>
<td><?= $order['delivery_datetime'] ? date("d M Y, h:i A", strtotime($order['delivery_datetime'])) : 'N/A' ?></td>
<td>
<div class="btn-group action-buttons" role="group" aria-label="Actions">
<!-- View Details -->
<a href="view_order_customer.php?order_id=<?= htmlspecialchars($order['order_id']) ?>" class="btn btn-sm btn-outline-primary" title="View Details" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-original-title="View Details">
<i class="bi bi-eye-fill"></i>
</a>
<!-- Edit Order -->
<a href="edit_order.php?id=<?= htmlspecialchars($order['order_id']) ?>" class="btn btn-sm btn-outline-secondary" title="Edit Order" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-original-title="Edit Order">
<i class="bi bi-pencil-fill"></i>
</a>
<!-- Change Status Dropdown -->
<div class="btn-group">
<button type="button" class="btn btn-sm btn-outline-info dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false" title="Change Status" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-original-title="Change Status">
<i class="bi bi-arrow-repeat"></i>
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="?action=update_status&order_id=<?= htmlspecialchars($order['order_id']) ?>&new_status=Pending">Pending</a></li>
<li><a class="dropdown-item" href="?action=update_status&order_id=<?= htmlspecialchars($order['order_id']) ?>&new_status=Completed">Completed</a></li>
<li><a class="dropdown-item" href="?action=update_status&order_id=<?= htmlspecialchars($order['order_id']) ?>&new_status=Delivered">Delivered</a></li>
</ul>
</div>
<!-- Delete Order -->
<button type="button" class="btn btn-sm btn-outline-danger" title="Delete Order" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-original-title="Delete Order" onclick="confirmDelete(<?= htmlspecialchars($order['order_id']) ?>)">
<i class="bi bi-trash-fill"></i>
</button>
</div>
</td>
</tr>
<?php endwhile; ?>
<?php else: ?>
<tr>
<td colspan="10" class="text-center">No orders found.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
<!-- Pagination -->
<?php if ($total_pages > 1): ?>
<nav aria-label="Order pagination">
<ul class="pagination justify-content-center">
<!-- Previous -->
<li class="page-item <?php echo ($page <= 1) ? 'disabled' : ''; ?>">
<a class="page-link" href="view_orders.php?<?php echo http_build_query(array_merge($_GET, ['page' => $page - 1])); ?>" tabindex="-1">Previous</a>
</li>
<!-- Page Numbers -->
<?php for ($i = 1; $i <= $total_pages; $i++): ?>
<li class="page-item <?php echo ($page == $i) ? 'active' : ''; ?>">
<a class="page-link" href="view_orders.php?<?php echo http_build_query(array_merge($_GET, ['page' => $i])); ?>"><?php echo $i; ?></a>
</li>
<?php endfor; ?>
<!-- Next -->
<li class="page-item <?php echo ($page >= $total_pages) ? 'disabled' : ''; ?>">
<a class="page-link" href="view_orders.php?<?php echo http_build_query(array_merge($_GET, ['page' => $page + 1])); ?>">Next</a>
</li>
</ul>
</nav>
<?php endif; ?>
</div>
<!-- Footer -->
<div class="footer">
© 2024 Kaak Alia Bakery. All rights reserved.
</div>
<!-- Bootstrap JS Bundle -->
<script src="/kaak_alia_management_system/assets/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- Flatpickr JS for Date Picker -->
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
<!-- Bootstrap Tooltip Initialization -->
<script>
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl)
})
</script>
<!-- Custom JS for Sorting and Deletion -->
<script>
// Initialize Flatpickr for date inputs
flatpickr("#from_date", {
dateFormat: "Y-m-d",
maxDate: "today"
});
flatpickr("#to_date", {
dateFormat: "Y-m-d",
maxDate: "today"
});
// Function to handle sorting
function sortTable(column) {
const urlParams = new URLSearchParams(window.location.search);
let currentSortBy = urlParams.get('sort_by') || 'order_date';
let currentSortOrder = urlParams.get('sort_order') || 'DESC';
if (currentSortBy === column) {
// Toggle sort order
currentSortOrder = currentSortOrder === 'ASC' ? 'DESC' : 'ASC';
} else {
currentSortBy = column;
currentSortOrder = 'ASC';
}
urlParams.set('sort_by', currentSortBy);
urlParams.set('sort_order', currentSortOrder);
// Reset to first page if pagination is implemented
urlParams.set('page', 1);
window.location.search = urlParams.toString();
}
// Function to confirm deletion
function confirmDelete(orderId) {
if (confirm('Are you sure you want to delete this order? This action cannot be undone.')) {
window.location.href = 'delete_order.php?order_id=' + orderId;
}
}
</script>
Certainly! To enhance the View Orders page by making the table more flexible and visually appealing, improving the Actions column, and adding a Back to Dashboard button underneath the title, follow the steps below. These adjustments will maintain the existing styles while introducing enhancements for a better user experience.
1. Add "Back to Dashboard" Button Under the Header
First, we'll add a Back to Dashboard button right below the header. This button will allow users to navigate back easily.
Modification Steps:
Locate the header section in your HTML.
Add a button below the header div with appropriate Bootstrap classes for styling and positioning.
Code Changes:
php Copy code
<!-- Header -->
<div class="header">
View Orders
</div>
<!-- Back to Dashboard Button -->
<div class="mb-4 text-center">
<a href="../dashboard.php" class="btn btn-secondary">
<i class="bi bi-arrow-left-square"></i> Back to Dashboard
</a>
</div>
Explanation:
mb-4 : Adds margin-bottom for spacing.
text-center : Centers the button horizontally.
btn btn-secondary : Uses Bootstrap's secondary button styling.
<i class="bi bi-arrow-left-square"></i> : Adds a Bootstrap Icon for visual flair.
2. Make the Orders Table More Flexible and Visually Appealing
To enhance the table's flexibility and aesthetics, we'll implement responsive design techniques and modern styling practices.
Modification Steps:
Utilize Bootstrap's responsive table classes.
Enhance table styling with subtle shadows, rounded corners, and hover effects.
Ensure text wraps appropriately without breaking the layout.
Code Changes:
Update CSS Styles
Add or modify the existing styles to improve the table's appearance. Insert these styles within your <style> tag.
css Copy code
/* Enhancements for Orders Table */
.orders-table {
width: 100%;
border-collapse: separate;
border-spacing: 0 10px; /* Adds space between rows */
}
.orders-table thead tr {
background-color: var(--dark-gray);
color: var(--white);
border-radius: 8px 8px 0 0;
}
.orders-table tbody tr {
background-color: var(--white);
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
transition: transform var(--transition-speed), box-shadow var(--transition-speed);
}
.orders-table tbody tr:hover {
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
.orders-table th, .orders-table td {
padding: 16px;
vertical-align: middle;
}
.orders-table th {
position: sticky;
top: 0;
z-index: 1;
}
.orders-table td {
word-wrap: break-word;
min-width: 100px;
}
.table-responsive {
overflow-x: auto;
}
Explanation:
border-spacing: 0 10px : Adds vertical spacing between table rows.
border-radius and box-shadow : Creates a card-like appearance with rounded corners and subtle shadows.
transform and box-shadow on hover : Adds a lift effect when hovering over rows.
position: sticky : Keeps the table headers fixed when scrolling horizontally.
3. Enhance the "Actions" Column Styles
The Actions column can be made more intuitive and visually appealing by refining the button styles and adding tooltips for better usability.
Modification Steps:
Adjust button sizes and colors for better distinction.
Use consistent iconography.
Add spacing between buttons.
Ensure buttons are accessible and user-friendly.
Code Changes:
Update HTML for Actions Column
Modify the Actions column within the table to utilize enhanced button styles and spacing.
php Copy code
<!-- Actions Column in the Table -->
<td>
<div class="btn-group action-buttons" role="group" aria-label="Actions">
<!-- View Details -->
<a href="view_order_customer.php?order_id=<?= htmlspecialchars($order['order_id']) ?>" class="btn btn-sm btn-info me-1" title="View Details" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-original-title="View Details">
<i class="bi bi-eye-fill"></i>
</a>
<!-- Edit Order -->
<a href="edit_order.php?id=<?= htmlspecialchars($order['order_id']) ?>" class="btn btn-sm btn-warning me-1" title="Edit Order" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-original-title="Edit Order">
<i class="bi bi-pencil-fill"></i>
</a>
<!-- Change Status Dropdown -->
<div class="btn-group me-1">
<button type="button" class="btn btn-sm btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false" title="Change Status" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-original-title="Change Status">
<i class="bi bi-arrow-repeat"></i>
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="?action=update_status&order_id=<?= htmlspecialchars($order['order_id']) ?>&new_status=Pending">Pending</a></li>
<li><a class="dropdown-item" href="?action=update_status&order_id=<?= htmlspecialchars($order['order_id']) ?>&new_status=Completed">Completed</a></li>
<li><a class="dropdown-item" href="?action=update_status&order_id=<?= htmlspecialchars($order['order_id']) ?>&new_status=Delivered">Delivered</a></li>
</ul>
</div>
<!-- Delete Order -->
<button type="button" class="btn btn-sm btn-danger" title="Delete Order" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-original-title="Delete Order" onclick="confirmDelete(<?= htmlspecialchars($order['order_id']) ?>)">
<i class="bi bi-trash-fill"></i>
</button>
</div>
</td>
Explanation:
btn-info, btn-warning, btn-primary, btn-danger : Utilizes different Bootstrap button classes for visual distinction.
me-1 : Adds right margin between buttons for spacing.
Consistent Icon Sizes : Ensures icons are uniform across different action buttons.
Update CSS for Action Buttons (Optional Enhancements)
While Bootstrap provides robust styling, you can further customize the Actions column with additional CSS if desired.
css Copy code
/* Enhancements for Action Buttons */
.action-buttons .btn {
padding: 6px 10px;
font-size: 14px;
border-radius: 5px;
}
.action-buttons .btn:hover {
opacity: 0.85;
}
Explanation:
padding and font-size : Adjusts the size of the buttons for better readability and clickability.
border-radius : Rounds the corners of the buttons for a modern look.
opacity on hover : Provides a subtle feedback effect when users interact with the buttons.
4. Complete Updated Code
Below is the complete updated view_orders.php file incorporating all the changes mentioned above. The modifications include adding the Back to Dashboard button, enhancing the table's flexibility and appearance, and refining the Actions column.
5. Summary of Enhancements
Back to Dashboard Button : Provides easy navigation back to the dashboard, enhancing user flow.
Responsive and Modern Table Design : Improves readability and usability across different devices with spacing, shadows, and hover effects.
Enhanced Actions Column : Utilizes distinct button colors and icons for intuitive action identification, along with proper spacing for better interaction.
Consistent Styling : Maintains the existing design language while introducing subtle improvements to enhance the overall look and feel.
These enhancements will make the View Orders page more user-friendly, visually appealing, and functionally efficient without disrupting the existing styles.
6. Additional Recommendations
Accessibility : Ensure all interactive elements are accessible via keyboard navigation and have appropriate aria labels.
Performance : Optimize the number of database queries, especially when fetching order items, to enhance page loading times.
Security : Validate and sanitize all user inputs thoroughly to prevent SQL injection and other security vulnerabilities.
By implementing these changes, your View Orders page will not only look great but also provide a seamless experience for the users interacting with the Kaak Alia Management System.
Show full message · 1,153 lines Copy first response
Not yet included in a published release.
′
, ′
a
d
mi
n ′
)
,
(
2
, ′
k
aak
a
l
i
a ′
, ′
′
])
;
t
a
t
u
s ′
])?
s
ani
t
i
z
e i
n
p
u
t
(
′
])?
s
ani
t
i
z
e i
n
p
u
t
(
a
t
e ′
])
: ′′
;
a
t
e ′
])?
s
ani
t
i
z
e i
n
p
u
t
(
y ′
])
: ′
or d e r d a t e ′ ;
r
d
e
r ′
])?
s
ani
t
i
z
e i
n
p
u
t
(
i
d ′
, ′
c
u
s
t
o
m
e
r n
am
e ′
, ′
co
n
t
a
c
t ′
, ′
s
t
a
t
u
s ′
, ′
or
d
e
r d
a
t
e ′
, ′
d
e
l
i
v
er
y d
a
t
e
t
im
e ′
]
;
i
f
(
!
i
n a
r
r
a
y
(
a
r
r
a
y
(
"
D
A
T
E
(
or
d
er
s
.
or
d
e
r d
a
t
e
)
=
? " ;
w
ee
k
=
d a t e ( ′ Y −
m −
d ′ , s t r t o t im e ( ′ m o n d a y t hi s w ee k ′ )) ;
=
" D A T E ( or d er s . or d e r d a t e ) B E T W E E N ? A N D ? " ;
a
t
e
( ′
Y
−
m −
0 1 ′ ) ;
=
" D A T E ( or d er s . or d e r d a t e ) B E T W E E N ? A N D ? " ;
=
" D A T E ( or d er s . or d e r d a t e ) B E T W E E N ? A N D ? " ;
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
(
)
;
a
ssoc
(
)
[ ′
t
o
t
a
l ′
]
;
,
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
,
c
u
s
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
.
p
r
o
d
u
c
t i
d
A
S
p
r
ima
r
y p
r
o
d
u
c
t i
d
,
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
,
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
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
i
t
e
m
s
.
or
d
e
r i
d
,
or
d
e
r i
t
e
m
s
.
p
r
o
d
u
c
t i
d
,
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
.
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
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 " ;
<?php
// public/orders/view_orders.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 __DIR__ . '/../../includes/auth.php';
require_once __DIR__ . '/../../includes/db_connect.php';
// Constants for pagination
define('ORDERS_PER_PAGE', 10);
// Helper function to get product price
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->num_rows == 1) {
$price = $price_result->fetch_assoc()['price'];
} else {
$price = "0.00";
}
$price_stmt->close();
return $price;
}
// Function to build query string for filter buttons while preserving other parameters
function build_query($new_params = []) {
$current_params = $_GET;
foreach ($new_params as $key => $value) {
if ($value !== null) { // Only set if value is not null
$current_params[$key] = $value;
} else {
unset($current_params[$key]); // Remove if value is null
}
}
// Remove parameters that shouldn't persist
unset($current_params['page']);
$query = http_build_query($current_params);
return $query ? '&' . $query : '';
}
// Function to get sort icon HTML based on current sorting
function get_sort_icon($column, $current_sort_by, $current_sort_order) {
if ($current_sort_by === $column) {
if ($current_sort_order === 'ASC') {
return '<i class="bi bi-arrow-up sort-icon"></i>';
} else {
return '<i class="bi bi-arrow-down sort-icon"></i>';
}
}
return '';
}
// Function to sanitize input for SQL
function sanitize_input($input) {
return htmlspecialchars(trim($input));
}
// Handle status update
if (isset($_GET['action']) && $_GET['action'] === 'update_status') {
$order_id = isset($_GET['order_id']) ? intval($_GET['order_id']) : 0;
$new_status = isset($_GET['new_status']) ? sanitize_input($_GET['new_status']) : '';
// Validate new_status (Removed 'In Progress')
$valid_statuses = ['Pending', 'Completed', 'Delivered'];
if ($order_id > 0 && in_array($new_status, $valid_statuses)) {
// If setting to 'Delivered', ensure delivery_datetime is set
if ($new_status === 'Delivered') {
$check_sql = "SELECT delivery_datetime FROM orders WHERE id = ?";
$check_stmt = $conn->prepare($check_sql);
if ($check_stmt) {
$check_stmt->bind_param("i", $order_id);
$check_stmt->execute();
$check_result = $check_stmt->get_result();
if ($check_result->num_rows == 1) {
$order = $check_result->fetch_assoc();
if (empty($order['delivery_datetime'])) {
header("Location: view_orders.php?error=3"); // Delivery datetime not set
exit();
}
}
$check_stmt->close();
} else {
header("Location: view_orders.php?error=2");
exit();
}
}
// Update status using prepared statement
$update_sql = "UPDATE orders SET status = ? WHERE id = ?";
$stmt = $conn->prepare($update_sql);
if ($stmt) {
$stmt->bind_param("si", $new_status, $order_id);
if ($stmt->execute()) {
$stmt->close();
header("Location: view_orders.php?success=1");
exit();
} else {
$stmt->close();
header("Location: view_orders.php?error=1");
exit();
}
} else {
header("Location: view_orders.php?error=2");
exit();
}
} else {
header("Location: view_orders.php?error=2");
exit();
}
}
// Handle Filters, Sorting, and Pagination
$filter = isset($_GET['filter']) ? sanitize_input($_GET['filter']) : 'all';
$search = isset($_GET['search']) ? sanitize_input($_GET['search']) : '';
$from_date = isset($_GET['from_date']) ? sanitize_input($_GET['from_date']) : '';
$to_date = isset($_GET['to_date']) ? sanitize_input($_GET['to_date']) : '';
$sort_by = isset($_GET['sort_by']) ? sanitize_input($_GET['sort_by']) : 'order_date';
$sort_order = isset($_GET['sort_order']) ? sanitize_input($_GET['sort_order']) : 'DESC';
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Validate sort_by and sort_order
$allowed_sort_columns = ['order_id', 'customer_name', 'contact', 'status', 'order_date', 'delivery_datetime'];
if (!in_array($sort_by, $allowed_sort_columns)) {
$sort_by = 'order_date';
}
$allowed_sort_orders = ['ASC', 'DESC'];
if (!in_array($sort_order, $allowed_sort_orders)) {
$sort_order = 'DESC';
}
// Initialize where conditions
$where_conditions = [];
$parameters = [];
$param_types = "";
// Predefined Date Filters
$current_date = date('Y-m-d');
switch ($filter) {
case 'today':
$where_conditions[] = "DATE(orders.order_date) = ?";
$parameters[] = $current_date;
$param_types .= "s";
break;
case 'yesterday':
$yesterday = date('Y-m-d', strtotime('-1 day'));
$where_conditions[] = "DATE(orders.order_date) = ?";
$parameters[] = $yesterday;
$param_types .= "s";
break;
case 'week':
$start_of_week = date('Y-m-d', strtotime('monday this week'));
$end_of_week = date('Y-m-d', strtotime('sunday this week'));
$where_conditions[] = "DATE(orders.order_date) BETWEEN ? AND ?";
$parameters[] = $start_of_week;
$parameters[] = $end_of_week;
$param_types .= "ss";
break;
case 'month':
$start_of_month = date('Y-m-01');
$end_of_month = date('Y-m-t');
$where_conditions[] = "DATE(orders.order_date) BETWEEN ? AND ?";
$parameters[] = $start_of_month;
$parameters[] = $end_of_month;
$param_types .= "ss";
break;
case 'custom':
if (!empty($from_date) && !empty($to_date)) {
$where_conditions[] = "DATE(orders.order_date) BETWEEN ? AND ?";
$parameters[] = $from_date;
$parameters[] = $to_date;
$param_types .= "ss";
}
break;
case 'all':
default:
// No predefined filter
break;
}
// Search Filter
if (!empty($search)) {
$where_conditions[] = "(customers.name LIKE ? OR orders.id LIKE ? OR customers.contact LIKE ?)";
$search_term = "%" . $search . "%";
$parameters[] = $search_term;
$parameters[] = $search_term;
$parameters[] = $search_term;
$param_types .= "sss";
}
// Combine all where conditions
$where_clause = "";
if (count($where_conditions) > 0) {
$where_clause = "WHERE " . implode(" AND ", $where_conditions);
}
// Sorting
$order_clause = "ORDER BY $sort_by $sort_order";
// Pagination Calculations
$offset = ($page - 1) * ORDERS_PER_PAGE;
// Fetch total number of orders for pagination
$count_sql = "
SELECT COUNT(*) as total
FROM orders
JOIN customers ON orders.customer_id = customers.id
JOIN products ON orders.product_id = products.id
$where_clause
";
$count_stmt = $conn->prepare($count_sql);
if ($count_stmt) {
if (!empty($where_clause)) {
$count_stmt->bind_param($param_types, ...$parameters);
}
$count_stmt->execute();
$count_result = $count_stmt->get_result();
$total_orders = $count_result->fetch_assoc()['total'];
$count_stmt->close();
} else {
// Handle SQL preparation error
die("Failed to prepare the count query: " . $conn->error);
}
// Calculate total pages
$total_pages = ceil($total_orders / ORDERS_PER_PAGE);
// Fetch orders with customer and product details based on filters and sorting
$orders_sql = "
SELECT
orders.id AS order_id,
orders.status,
orders.order_date,
orders.delivery_datetime,
customers.name AS customer_name,
customers.contact,
customers.delivery_address,
orders.product_id AS primary_product_id,
orders.quantity AS primary_quantity,
orders.packaging_preferences AS primary_packaging_preferences,
products.name AS primary_product_name,
products.size AS primary_product_size
FROM
orders
JOIN
customers ON orders.customer_id = customers.id
JOIN
products ON orders.product_id = products.id
$where_clause
$order_clause
LIMIT $offset, " . ORDERS_PER_PAGE . "
";
$orders_stmt = $conn->prepare($orders_sql);
if ($orders_stmt) {
if (!empty($where_clause)) {
$orders_stmt->bind_param($param_types, ...$parameters);
}
$orders_stmt->execute();
$orders_result = $orders_stmt->get_result();
} else {
// Handle SQL preparation error
die("Failed to prepare the orders query: " . $conn->error);
}
// Fetch order items for all orders
$order_items_sql = "
SELECT
order_items.order_id,
order_items.product_id,
order_items.quantity,
order_items.packaging_preferences,
products.name AS product_name,
products.size AS product_size
FROM
order_items
JOIN
products ON order_items.product_id = products.id
";
$order_items_result = $conn->query($order_items_sql);
// Organize order items by order_id
$order_items = [];
if ($order_items_result && $order_items_result->num_rows > 0) {
while ($item = $order_items_result->fetch_assoc()) {
$order_items[$item['order_id']][] = $item;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>View Orders - 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="/kaak_alia_management_system/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">
<!-- Flatpickr CSS for Date Picker -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
<!-- Embedded Custom Styles -->
<style>
/* ---------------------------------------------------
1. CSS Variables for Consistent Design
---------------------------------------------------- */
:root {
--dark-gray: #343a40; /* Header and Footer Background */
--soft-brown: #FFD166; /* Add New Order Button */
--blue: #118AB2; /* Primary Button */
--green: #06D6A0; /* Success Button */
--orange: #F4A261; /* Warning Button */
--red-pink: #EF476F; /* Danger Button */
--main-text: #333333;
--secondary-text: #666666;
--white: #FFFFFF;
--light-gray: #F9F9F9;
--divider-color: #FFD166;
--transition-speed: 0.3s;
--hover-shadow: rgba(0, 0, 0, 0.2);
}
/* ---------------------------------------------------
2. Global Styles
---------------------------------------------------- */
body {
font-family: 'Cairo', sans-serif;
background: linear-gradient(to bottom, #f5f7fa, #c3cfe2);
margin: 0;
padding: 30px;
box-sizing: border-box;
}
/* ---------------------------------------------------
3. Header Styles
---------------------------------------------------- */
.header {
padding: 20px 30px;
background-color: var(--dark-gray);
border-radius: 8px;
text-align: center;
margin-bottom: 10px; /* Reduced margin to fit Back button */
color: var(--white);
font-size: 28px;
font-weight: bold;
box-shadow: 0 4px 6px var(--hover-shadow);
}
/* ---------------------------------------------------
4. Success and Error Alerts
---------------------------------------------------- */
.alert-success-custom {
background-color: var(--green);
color: var(--white);
border-radius: 8px;
padding: 15px 20px;
margin-bottom: 20px;
text-align: center;
width: 70%;
margin: 20px auto;
box-shadow: 0 4px 6px var(--hover-shadow);
}
.alert-error-custom {
background-color: var(--red-pink);
color: var(--white);
border-radius: 8px;
padding: 15px 20px;
margin-bottom: 20px;
text-align: center;
width: 70%;
margin: 20px auto;
box-shadow: 0 4px 6px var(--hover-shadow);
}
/* ---------------------------------------------------
5. 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: 24px;
font-weight: bold;
color: var(--main-text);
margin-bottom: 20px;
border-bottom: 2px solid var(--divider-color);
padding-bottom: 10px;
}
/* ---------------------------------------------------
6. Filter and Search Section
---------------------------------------------------- */
.filter-search-section {
margin-bottom: 20px;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
}
.filter-search-section .filter-group,
.filter-search-section .search-group {
display: flex;
align-items: center;
margin-bottom: 10px;
}
/* Enhanced Styles for Filter Buttons */
.filter-search-section .filter-group .btn-group .btn {
margin-left: 5px;
background-color: var(--soft-brown);
padding: 8px 12px;
border: none;
border-radius: 5px;
color: var(--dark-gray);
transition: background-color var(--transition-speed), transform var(--transition-speed);
}
.filter-search-section .filter-group .btn-group .btn.active,
.filter-search-section .filter-group .btn-group .btn:hover {
background-color: var(--dark-gray);
color: var(--white);
transform: scale(1.05);
}
.filter-search-section .search-group input,
.filter-search-section .search-group button {
margin-left: 5px;
}
.filter-search-section .date-range-group input {
margin-left: 5px;
width: 150px;
}
/* ---------------------------------------------------
7. Orders Table Styles
---------------------------------------------------- */
.orders-table {
width: 100%;
border-collapse: separate;
border-spacing: 0 10px; /* Adds space between rows */
}
.orders-table thead tr {
background-color: var(--dark-gray);
color: var(--white);
border-radius: 8px 8px 0 0;
}
.orders-table thead th {
position: sticky;
top: 0;
z-index: 1;
}
.orders-table tbody tr {
background-color: var(--white);
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
transition: transform var(--transition-speed), box-shadow var(--transition-speed);
}
.orders-table tbody tr:hover {
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
.orders-table th,
.orders-table td {
padding: 16px;
text-align: left;
font-size: 16px;
vertical-align: middle;
word-wrap: break-word;
min-width: 100px;
}
.orders-table tbody tr:nth-child(even) {
background-color: var(--light-gray);
}
.orders-table tbody td {
font-size: 14px;
color: var(--main-text);
position: relative;
}
/* 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-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;
}
/* Highlight New Order IDs */
.new-order {
color: #EF476F;
font-weight: bold;
}
/* ---------------------------------------------------
8. Actions Column Styles
---------------------------------------------------- */
.action-buttons .btn {
padding: 6px 10px;
font-size: 14px;
border-radius: 5px;
margin-right: 5px;
transition: opacity var(--transition-speed);
}
.action-buttons .btn:hover {
opacity: 0.85;
}
/* Dropdown Styles */
.dropdown-menu > a {
cursor: pointer;
}
/* ---------------------------------------------------
9. Footer Styles
---------------------------------------------------- */
.footer {
background-color: var(--dark-gray);
color: var(--white);
padding: 15px;
text-align: center;
border-radius: 8px;
font-size: 14px;
line-height: 20px;
margin-top: 40px;
box-shadow: 0 4px 6px var(--hover-shadow);
}
/* ---------------------------------------------------
10. Responsive Design Enhancements
---------------------------------------------------- */
@media (max-width: 992px) {
.filter-search-section {
flex-direction: column;
align-items: flex-start;
}
.filter-search-section .filter-group,
.filter-search-section .search-group,
.filter-search-section .date-range-group {
width: 100%;
justify-content: space-between;
}
.orders-table th, .orders-table td {
font-size: 14px;
}
}
@media (max-width: 768px) {
/* Adjust filter and search input widths */
.filter-search-section .filter-group .btn-group .btn,
.filter-search-section .search-group input,
.filter-search-section .date-range-group input {
width: 100%;
margin: 5px 0;
}
.filter-search-section .search-group button {
width: 100%;
}
.orders-table {
display: block;
overflow-x: auto;
white-space: nowrap;
}
.orders-table th, .orders-table td {
padding: 8px;
}
}
/* Additional Styles */
.btn-reset {
margin-left: 10px;
}
</style>
</head>
<body>
<!-- Header -->
<div class="header">
View Orders
</div>
<!-- Back to Dashboard Button -->
<div class="mb-4 text-center">
<a href="../dashboard.php" class="btn btn-secondary">
<i class="bi bi-arrow-left-square"></i> Back to Dashboard
</a>
</div>
<!-- Display Success or Error Messages -->
<?php if (isset($_GET['success']) && $_GET['success'] == 1): ?>
<div class="alert alert-success alert-success-custom" role="alert">
Order status updated successfully!
</div>
<?php endif; ?>
<?php if (isset($_GET['error'])): ?>
<?php if ($_GET['error'] == 1): ?>
<div class="alert alert-danger alert-error-custom" role="alert">
Failed to update order status.
</div>
<?php elseif ($_GET['error'] == 2): ?>
<div class="alert alert-danger alert-error-custom" role="alert">
Invalid status selected.
</div>
<?php elseif ($_GET['error'] == 3): ?>
<div class="alert alert-danger alert-error-custom" role="alert">
Cannot set status to Delivered without a delivery date and time.
</div>
<?php endif; ?>
<?php endif; ?>
<!-- Container -->
<div class="recent-orders-section">
<h4>All Orders</h4>
<!-- Filter and Search Section -->
<div class="filter-search-section">
<!-- Predefined Date Filters -->
<div class="filter-group mb-3">
<span class="me-2">Filter:</span>
<div class="btn-group" role="group" aria-label="Date Filters">
<a href="view_orders.php?filter=all<?php echo build_query(['filter' => 'all', 'page' => null]); ?>" class="btn <?php echo $filter === 'all' ? 'active' : 'btn-outline-primary'; ?>">All</a>
<a href="view_orders.php?filter=today<?php echo build_query(['filter' => 'today', 'page' => null]); ?>" class="btn <?php echo $filter === 'today' ? 'active' : 'btn-outline-primary'; ?>">Today</a>
<a href="view_orders.php?filter=yesterday<?php echo build_query(['filter' => 'yesterday', 'page' => null]); ?>" class="btn <?php echo $filter === 'yesterday' ? 'active' : 'btn-outline-primary'; ?>">Yesterday</a>
<a href="view_orders.php?filter=week<?php echo build_query(['filter' => 'week', 'page' => null]); ?>" class="btn <?php echo $filter === 'week' ? 'active' : 'btn-outline-primary'; ?>">This Week</a>
<a href="view_orders.php?filter=month<?php echo build_query(['filter' => 'month', 'page' => null]); ?>" class="btn <?php echo $filter === 'month' ? 'active' : 'btn-outline-primary'; ?>">This Month</a>
</div>
</div>
<!-- Date Range Filters -->
<div class="date-range-group mb-3">
<form method="GET" action="view_orders.php" class="d-flex align-items-center flex-wrap">
<input type="hidden" name="filter" value="custom">
<input type="hidden" name="search" value="<?php echo htmlspecialchars($search); ?>">
<input type="hidden" name="sort_by" value="<?php echo htmlspecialchars($sort_by); ?>">
<input type="hidden" name="sort_order" value="<?php echo htmlspecialchars($sort_order); ?>">
<label for="from_date" class="me-2">From:</label>
<input type="text" id="from_date" name="from_date" class="form-control me-3 mb-2" placeholder="YYYY-MM-DD" value="<?php echo htmlspecialchars($from_date); ?>" readonly>
<label for="to_date" class="me-2">To:</label>
<input type="text" id="to_date" name="to_date" class="form-control me-3 mb-2" placeholder="YYYY-MM-DD" value="<?php echo htmlspecialchars($to_date); ?>" readonly>
<button type="submit" class="btn btn-success mb-2">Apply</button>
</form>
</div>
<!-- Search Group -->
<div class="search-group">
<form method="GET" action="view_orders.php" class="d-flex align-items-center flex-wrap">
<input type="hidden" name="filter" value="<?php echo htmlspecialchars($filter); ?>">
<input type="hidden" name="from_date" value="<?php echo htmlspecialchars($from_date); ?>">
<input type="hidden" name="to_date" value="<?php echo htmlspecialchars($to_date); ?>">
<input type="hidden" name="sort_by" value="<?php echo htmlspecialchars($sort_by); ?>">
<input type="hidden" name="sort_order" value="<?php echo htmlspecialchars($sort_order); ?>">
<input type="text" name="search" class="form-control me-2 mb-2" placeholder="Search by Customer, ID, or Contact" value="<?php echo htmlspecialchars($search); ?>">
<button type="submit" class="btn btn-primary mb-2">Search</button>
<?php if (!empty($search) || !empty($from_date) || !empty($to_date)): ?>
<a href="view_orders.php<?php echo build_query(['search' => null, 'from_date' => null, 'to_date' => null]); ?>" class="btn btn-outline-secondary ms-2 mb-2">Reset</a>
<?php endif; ?>
</form>
</div>
</div>
<!-- Orders Table -->
<div class="table-responsive">
<table class="table table-striped table-hover orders-table">
<thead>
<tr>
<th onclick="sortTable('order_id')" style="cursor:pointer;">
ID
<?php echo get_sort_icon('order_id', $sort_by, $sort_order); ?>
</th>
<th onclick="sortTable('customer_name')" style="cursor:pointer;">
Customer
<?php echo get_sort_icon('customer_name', $sort_by, $sort_order); ?>
</th>
<th onclick="sortTable('contact')" style="cursor:pointer;">
Contact
<?php echo get_sort_icon('contact', $sort_by, $sort_order); ?>
</th>
<th>Delivery Address</th>
<th>Primary Product</th>
<th>Additional Products</th>
<th onclick="sortTable('status')" style="cursor:pointer;">
Status
<?php echo get_sort_icon('status', $sort_by, $sort_order); ?>
</th>
<th onclick="sortTable('order_date')" style="cursor:pointer;">
Order Date
<?php echo get_sort_icon('order_date', $sort_by, $sort_order); ?>
</th>
<th onclick="sortTable('delivery_datetime')" style="cursor:pointer;">
Delivery DateTime
<?php echo get_sort_icon('delivery_datetime', $sort_by, $sort_order); ?>
</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if ($orders_result && $orders_result->num_rows > 0): ?>
<?php while($order = $orders_result->fetch_assoc()): ?>
<?php
// Check if the order is new (created within last 24 hours)
$is_new = (strtotime($order['order_date']) >= strtotime('-1 day'));
?>
<tr>
<td class="<?php echo $is_new ? 'new-order' : ''; ?>">
<?= htmlspecialchars($order['order_id']) ?>
</td>
<td><?= htmlspecialchars($order['customer_name']) ?></td>
<td><?= htmlspecialchars($order['contact']) ?></td>
<td><?= nl2br(htmlspecialchars($order['delivery_address'])) ?></td>
<td>
<strong><?= htmlspecialchars($order['primary_product_name']) ?></strong> - <?= htmlspecialchars($order['primary_product_size']) ?><br>
Price: <?= 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']) ?>
</td>
<td>
<?php
if (isset($order_items[$order['order_id']])) {
foreach ($order_items[$order['order_id']] as $item) {
echo "<strong>" . htmlspecialchars($item['product_name']) . "</strong> - " . htmlspecialchars($item['product_size']) . "<br>";
echo "Price: " . number_format(get_product_price($conn, $item['product_id']), 2) . " KD<br>";
echo "Qty: " . htmlspecialchars($item['quantity']) . "<br>";
echo "Packaging: " . htmlspecialchars($item['packaging_preferences']) . "<br><br>";
}
} else {
echo "None";
}
?>
</td>
<td>
<?php
switch ($order['status']) {
case 'Pending':
echo '<span class="badge-status-pending">Pending</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><?= date("d M Y, h:i A", strtotime($order['order_date'])) ?></td>
<td><?= $order['delivery_datetime'] ? date("d M Y, h:i A", strtotime($order['delivery_datetime'])) : 'N/A' ?></td>
<td>
<div class="btn-group action-buttons" role="group" aria-label="Actions">
<!-- View Details -->
<a href="view_order_customer.php?order_id=<?= htmlspecialchars($order['order_id']) ?>" class="btn btn-sm btn-info me-1" title="View Details" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-original-title="View Details">
<i class="bi bi-eye-fill"></i>
</a>
<!-- Edit Order -->
<a href="edit_order.php?id=<?= htmlspecialchars($order['order_id']) ?>" class="btn btn-sm btn-warning me-1" title="Edit Order" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-original-title="Edit Order">
<i class="bi bi-pencil-fill"></i>
</a>
<!-- Change Status Dropdown -->
<div class="btn-group me-1">
<button type="button" class="btn btn-sm btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false" title="Change Status" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-original-title="Change Status">
<i class="bi bi-arrow-repeat"></i>
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="?action=update_status&order_id=<?= htmlspecialchars($order['order_id']) ?>&new_status=Pending">Pending</a></li>
<li><a class="dropdown-item" href="?action=update_status&order_id=<?= htmlspecialchars($order['order_id']) ?>&new_status=Completed">Completed</a></li>
<li><a class="dropdown-item" href="?action=update_status&order_id=<?= htmlspecialchars($order['order_id']) ?>&new_status=Delivered">Delivered</a></li>
</ul>
</div>
<!-- Delete Order -->
<button type="button" class="btn btn-sm btn-danger" title="Delete Order" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-original-title="Delete Order" onclick="confirmDelete(<?= htmlspecialchars($order['order_id']) ?>)">
<i class="bi bi-trash-fill"></i>
</button>
</div>
</td>
</tr>
<?php endwhile; ?>
<?php else: ?>
<tr>
<td colspan="10" class="text-center">No orders found.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
<!-- Pagination -->
<?php if ($total_pages > 1): ?>
<nav aria-label="Order pagination">
<ul class="pagination justify-content-center">
<!-- Previous -->
<li class="page-item <?php echo ($page <= 1) ? 'disabled' : ''; ?>">
<a class="page-link" href="view_orders.php?<?php echo http_build_query(array_merge($_GET, ['page' => $page - 1])); ?>" tabindex="-1">Previous</a>
</li>
<!-- Page Numbers -->
<?php for ($i = 1; $i <= $total_pages; $i++): ?>
<li class="page-item <?php echo ($page == $i) ? 'active' : ''; ?>">
<a class="page-link" href="view_orders.php?<?php echo http_build_query(array_merge($_GET, ['page' => $i])); ?>"><?php echo $i; ?></a>
</li>
<?php endfor; ?>
<!-- Next -->
<li class="page-item <?php echo ($page >= $total_pages) ? 'disabled' : ''; ?>">
<a class="page-link" href="view_orders.php?<?php echo http_build_query(array_merge($_GET, ['page' => $page + 1])); ?>">Next</a>
</li>
</ul>
</nav>
<?php endif; ?>
</div>
<!-- Footer -->
<div class="footer">
© 2024 Kaak Alia Bakery. All rights reserved.
</div>
<!-- Bootstrap JS Bundle -->
<script src="/kaak_alia_management_system/assets/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- Flatpickr JS for Date Picker -->
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
<!-- Bootstrap Tooltip Initialization -->
<script>
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl)
})
</script>
<!-- Custom JS for Sorting and Deletion -->
<script>
// Initialize Flatpickr for date inputs
flatpickr("#from_date", {
dateFormat: "Y-m-d",
maxDate: "today"
});
flatpickr("#to_date", {
dateFormat: "Y-m-d",
maxDate: "today"
});
// Function to handle sorting
function sortTable(column) {
const urlParams = new URLSearchParams(window.location.search);
let currentSortBy = urlParams.get('sort_by') || 'order_date';
let currentSortOrder = urlParams.get('sort_order') || 'DESC';
if (currentSortBy === column) {
// Toggle sort order
currentSortOrder = currentSortOrder === 'ASC' ? 'DESC' : 'ASC';
} else {
currentSortBy = column;
currentSortOrder = 'ASC';
}
urlParams.set('sort_by', currentSortBy);
urlParams.set('sort_order', currentSortOrder);
// Reset to first page if pagination is implemented
urlParams.set('page', 1);
window.location.search = urlParams.toString();
}
// Function to confirm deletion
function confirmDelete(orderId) {
if (confirm('Are you sure you want to delete this order? This action cannot be undone.')) {
window.location.href = 'delete_order.php?order_id=' + orderId;
}
}
</script>
</body>
</html>
<?php
// No closing PHP tag to prevent unwanted output
?>