change this design 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 before including the header
require_once DIR . '/../../includes/auth.php';
require_once DIR . '/../../includes/db_connect.php';
// Now include the header
require_once '../../includes/header.php';
// Constants for pagination
define('ORDERS_PER_PAGE', 10);
// Helper function to get product price
function get_product_price(conn,product_id) {
pprice_stmt = price_sql);
if (!price_stmt->bind_param("i", price_stmt->execute();
price_stmt->get_result();
if (price = price = "0.00";
}
price;
}
Assistant
r
i
c
es
q
l
=
"SELECTpriceFROMproductsWHEREid=
?LIMIT1";
conn−>prepare(
pricestmt)return"0.00";
productid);
priceresult=
price_result->num_rows == 1) {
price_result->fetch_assoc()['price'];
} else {
pricestmt−>close();return
// 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(currentparams[key]); // Remove if value is null
}
}
// Remove parameters that shouldn't persist
unset(currentparams[′pagequery = http_build_query(currentparams);returnquery ? '&' . $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 '';
} 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') {
orderid=isset(_GET['order_id']) ? intval(GET[′orderid′]):0;new_status = isset(GET[′news_GET['new_status']) : '';
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();
}
// Initialize where conditions
whereconditions=[];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;
paramtypes.="s";break;case′yesterday′:yesterday = date('Y-m-d', strtotime('-1 day'));
whereconditions[]=parameters[] = yesterday;param_types .= "s";
break;
case 'week':
startofend_of_week = date('Y-m-d', strtotime('sunday this week'));
whereconditions[]parameters[] = startofweek;parameters[] = endofweek;param_types .= "ss";
break;
case 'month':
startofmonth=dend_of_month = date('Y-m-t');
whereconditions[]parameters[] = startofmonth;parameters[] = endofmonth;param_types .= "ss";
break;
case 'custom':
if (!empty(from_date) && !empty(to_date)) {
whereconditions[]parameters[] = fromdate;parameters[] = todate;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 ?)";
searchterm="search . "%";
parameters[]=search_term;
parameters[]=search_term;
parameters[]=search_term;
$param_types .= "sss";
}
// Combine all where conditions
whereclause="";if(count(where_conditions) > 0) {
whereclause="WHERE".implode("AND",where_conditions);
}
// Fetch total number of orders for pagination
countsql="SELECTCOUNT(∗)astotalFROMordersJwhere_clause
";
countstmt=conn->prepare(countsql);if(count_stmt) {
if (!empty(where_clause)) {
count_stmt->bind_param(paramtypes,...parameters);
}
countstmt−>execute();count_result = countstmt−>getresulttotal_orders = countresult−>fetchcount_stmt->close();
} else {
// Handle SQL preparation error
die("Failed to prepare the count query: " . $conn->error);
}
// Calculate total pages
totalpages=ceil(total_orders / ORDERS_PER_PAGE);
// Fetch orders with customer and product details based on filters and sorting
orderssql="SELECTorders.idASorderidwhere_clause
orderclauseLIMIToffset, " . ORDERS_PER_PAGE . "
";
ordersstmt=conn->prepare(orderssql);if(orders_stmt) {
if (!empty(where_clause)) {
orders_stmt->bind_param(paramtypes,...parameters);
}
ordersstmt−>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
orderitemssql="SELECTorderorder_items_result = conn−>query(order_items_sql);
// Organize order items by order_id
orderitems=[];if(order_items_result && order_items_result->num_rows > 0) {
while (item = order_items_result->fetch_assoc()) {
order_items[item[′orderid′]][]=item;
}
}
?>
Instead of using text labels for order statuses ("Pending," "Completed," "Delivered"), use color-coded tags or badges with icons (e.g., ⏳ for Pending, ✅ for Completed, 📦 for Delivered). This makes the status easily recognizable at a glance.
Use different colors for each status (e.g., yellow for Pending, green for Completed, blue for Delivered).
Better Spacing and Alignment:
Increase the padding between rows and columns to enhance readability.
Ensure all text elements are aligned properly (especially in the "Primary Product" and "Additional Products" columns).
Enhanced Filtering Options:
Add a dropdown filter for the order status (e.g., "All," "Pending," "Completed," "Delivered"). This will help users quickly find orders based on their status.
Consider adding a search bar with placeholder text like "Search by Customer Name, Order ID, or Product."
Interactive Sorting:
Make the table headers clickable to sort orders by ID, date, or status (ascending/descending). Add small icons (▲/▼) to indicate sorting order.
Improved Date Range Filter:
Use a calendar date picker instead of manual input for the "From" and "To" date fields. This will reduce errors and improve user experience.
Action Icons Redesign:
Use modern icons (e.g., pencil for edit, trash bin for delete, and eye for view) with hover effects to make them more interactive.
Add tooltips for each icon (e.g., "Edit Order," "Delete Order," "View Details").
Pagination Enhancement:
Display the total number of orders (e.g., "Showing 1-10 of 50 orders") for better user clarity.
Allow users to choose how many orders to display per page (e.g., 10, 20, 50).
Mobile Responsiveness:
Make sure the table is responsive on smaller screens. Consider using a collapsible design where less important columns are hidden on mobile, and detailed information is accessible via an "Expand" button.
Dark Mode Support:
Add a toggle for dark mode/light mode to enhance accessibility and user experience, especially for users who prefer dark mode interfaces.
Functional Enhancements
Order Actions:
When clicking "View" (eye icon), consider opening a modal popup with detailed order information instead of redirecting to another page. This keeps users on the same page and reduces navigation time.
Add an "Export" button to download the list of orders as a CSV or PDF for easy reporting.
Order Status Update:
Allow users to update the status of the order directly from the table by clicking the status label and selecting a new status from a dropdown menu. This saves time for the admin.
Customer Contact Integration:
Add quick action buttons to directly call or message the customer if the platform supports it. For example, clicking on the "Contact" field could open a call prompt or messaging app.
Enhanced Product Details:
Show product thumbnails next to the "Primary Product" for a more visual representation of the order. This is particularly useful for bakery items and gift boxes.
Example Layout Enhancements
Consider a design with alternating row colors for better readability (e.g., light gray background for every other row).
Use a card-based layout for each order if the list is not too long. Cards can make it easier to visually separate information.
Implementation Tips
Use CSS Grid or Flexbox for better layout control, especially for mobile responsiveness.
Utilize JavaScript or a front-end library (e.g., React, Vue) for dynamic sorting, filtering, and modal popups to enhance interactivity.
Leverage a UI library like Bootstrap or Tailwind CSS for faster implementation of common design components and consistent styling.
These enhancements will improve both the appearance and functionality of the page, leading to a better user experience. Let me know if you'd like detailed code suggestions or further design mockups!
) and don't change the styles colors
Certainly! Below is the enhanced version of your view_orders.php script incorporating the design and functional improvements you've outlined. The modifications include:
Status Indicators with Icons and Color-Coded Badges
Better Spacing and Alignment
Enhanced Filtering Options (Including Status Filter)
Interactive Sorting with Improved Icons
Improved Date Range Filter with Calendar Pickers
Redesigned Action Icons with Hover Effects and Tooltips
Pagination Enhancements (Total Orders Display and Records Per Page Selection)
Mobile Responsiveness Improvements
Dark Mode Support with Toggle
Functional Enhancements (Modals for Viewing Orders, Export Button, Inline Status Updates, Customer Contact Integration, and Product Thumbnails)
Note: To keep the colors consistent, I've preserved your existing CSS variables and only added new classes or modified existing ones without altering the color codes.
This script should accept an order_id as a GET parameter and return detailed HTML content for the modal. It can include all order information, customer details, and product listings without badges or action buttons.
Implement Export Functionality:
Depending on your needs, you can implement CSV or PDF export. Libraries like PhpSpreadsheet for CSV or TCPDF for PDF can be useful.
Enhance Security:
Ensure that all inputs are properly sanitized and validated.
Use prepared statements (as you've done) to prevent SQL injection.
Implement proper authentication and authorization checks.
Optimize Performance:
Consider using AJAX for filtering, sorting, and pagination to make the user experience smoother.
Implement caching strategies if needed.
Accessibility:
Ensure that all interactive elements are accessible via keyboard.
Use ARIA labels where necessary for better accessibility.
Testing:
Test the functionalities across different browsers and devices to ensure consistency.
Validate the mobile responsiveness extensively.
Code Organization:
For larger projects, consider separating PHP logic from HTML using templating engines or MVC frameworks to improve maintainability.
These enhancements should significantly improve both the aesthetics and functionality of your view_orders.php page, providing a better user experience while maintaining consistent styling as per your requirements. Let me know if you need further assistance with any specific feature or implementation!
// Function to open view details modal
function openViewModal(orderId) {
const modal = new bootstrap.Modal(document.getElementById('viewDetailsModal'));
const modalContent = document.getElementById('modalContent');
// Show the modal
modal.show();
// Fetch order details via AJAX
fetch(`view_order_details.php?order_id=${orderId}`)
.then(response => response.text())
.then(data => {
modalContent.innerHTML = data;
})
.catch(error => {
modalContent.innerHTML = '<div class="alert alert-danger">Failed to load order details.</div>';
});
}
Note: You'll need to create a separate view_order_details.php script that returns the detailed HTML content for the modal based on the order_id parameter.
Export Button:
Added an "Export" button that allows users to export the current list of orders. The actual export functionality needs to be implemented in the if block handling the export action.
Although status updates are handled via the "Change Status" dropdown, you can further enhance this by making the status badge clickable to open the dropdown directly.
Customer Contact Integration:
Made the contact number clickable, allowing users to initiate a call directly if their device supports it.