// Include authentication and database connection before any output
require_once DIR . '/../../includes/auth.php';
require_once DIR . '/../../includes/db_connect.php';
// Helper Functions
/**
Sanitize input to prevent XSS and other injections.
@param string $input The input string to sanitize.
@return string The sanitized string.
*/
function sanitize_input(input) {
return htmlspecialchars(trim(input), ENT_QUOTES, 'UTF-8');
}
/**
Build a query string while preserving existing parameters.
@param array $new_params Associative array of new parameters to add or update.
@return string The resulting query string.
*/
function build_query(new_params = []) {
current_params = GETnew_params as value) {
if (current_params[value;
} else {
unset(key]); // Remove if value is null
}
}
// Remove parameters that shouldn't persist
unset(query = http_build_query(query ? '?' . $query : '';
}
Assistant
;
f
or
e
a
c
h
(
key=>
value !== null) { // Only set if value is not null
key]=
currentparams[
currentparams[′page′]);
currentparams);return
/**
Get the appropriate sort icon based on current sorting.
@param string $column The column to check.
@param string $current_sort_by The current column being sorted by.
@param string $current_sort_order The current sort order ('ASC' or 'DESC').
@return string The HTML for the sort icon.
*/
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 '';
}
/**
Generate a WhatsApp link from a contact number.
@param string $contact The contact number.
@return string The WhatsApp URL.
*/
function generate_whatsapp_link(contact) {
// Remove any non-digit characters
digits = preg_replace('/\D+/', '', $contact);
// Assuming Egypt country code (+20). Adjust as needed.
if (substr(digits, 0, 2) !== '20') {
digits = '20' . $digits;
}
if (isset(_GET['action'])) {
if (_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
$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();
}
} elseif ($_GET['action'] === 'export') {
// Implement export functionality here
// For brevity, this is left as a placeholder
// You can generate CSV or PDF based on current filters
// Redirect back with success message
header("Location: view_orders.php?export=1");
exit();
}
}
// Now include the header after handling actions
require_once DIR . '/../../includes/header.php';
// Constants for pagination
define('ORDERS_PER_PAGE_DEFAULT', 10);
// Search Filter
if (!empty(search)) {
where_conditions[] = "(c.name LIKE ? OR o.id LIKE ? OR c.contact LIKE ?)";
searchterm="search . "%";
parameters[]=search_term;
parameters[]=search_term;
parameters[]=search_term;
$param_types .= "sss";
}
// Date Range Filter on order_date
if (!empty(from_date)) {
where_conditions[] = "o.order_date >= ?";
parameters[]=from_date . " 00:00:00";
$param_types .= "s";
}
// Combine all where conditions
whereclause="";if(count(where_conditions) > 0) {
whereclause="WHERE".implode("AND",where_conditions);
}
// Sorting
// To prevent SQL injection in ORDER BY, use a mapping
sortcolumnmap=[′id′=sort_column = isset(sortcolumnmap[sort_by]) ? sortcolumnmap[sort_by] : 'o.order_date';
orderclause="ORDERBYsort_column $sort_order";
<!-- Flatpickr JS for Date Picker -->
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
<!-- Bootstrap Tooltip and Popover 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, Deletion, and Filtering -->
<script>
// Initialize Flatpickr for date inputs if present
flatpickr("#fromDate", {
dateFormat: "Y-m-d",
maxDate: "today"
});
flatpickr("#toDate", {
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 using browser confirm dialog
function confirmDelete(orderId) {
if (window.confirm("Are you sure you want to delete this order? This action cannot be undone.")) {
window.location.href = 'delete_order.php?order_id=' + orderId;
}
}
// Function to toggle Change Status Controls
function toggleChangeStatus(orderId) {
const controls = document.getElementById('changeStatusControls' + orderId);
const originalButtons = controls.previousElementSibling; // action-buttons div
if (controls.classList.contains('active')) {
controls.classList.remove('active');
originalButtons.style.display = 'flex';
} else {
// Hide other change status controls
document.querySelectorAll('.change-status-controls.active').forEach(function(el) {
el.classList.remove('active');
const siblings = el.previousElementSibling;
if (siblings) {
siblings.style.display = 'flex';
}
});
controls.classList.add('active');
originalButtons.style.display = 'none';
}
}
// Function to confirm status change
function confirmChangeStatus(orderId) {
const newStatus = document.getElementById('newStatus' + orderId).value;
if (newStatus) {
window.location.href = `view_orders.php?action=update_status&order_id=${orderId}&new_status=${newStatus}`;
}
}
// Function to cancel status change
function cancelChangeStatus(orderId) {
const controls = document.getElementById('changeStatusControls' + orderId);
const originalButtons = controls.previousElementSibling; // action-buttons div
controls.classList.remove('active');
originalButtons.style.display = 'flex';
}
// Function to validate Change Status button
function validateChangeStatus(orderId) {
const newStatus = document.getElementById('newStatus' + orderId).value;
const confirmBtn = document.getElementById('confirmChangeStatusBtn' + orderId);
if (newStatus) {
confirmBtn.disabled = false;
} else {
confirmBtn.disabled = true;
}
}
// Function to edit order
function editOrder(orderId) {
window.location.href = `edit_order.php?id=${orderId}`;
}
// Function to apply filters (on status change, priority change, date filters, and records per page)
function applyFilters() {
const urlParams = new URLSearchParams(window.location.search);
const statusFilter = document.getElementById('statusFilter').value;
const priorityFilter = document.getElementById('priorityFilter').value;
const ordersPerPage = document.getElementById('entriesPerPage').value;
const fromDate = document.getElementById('fromDate').value;
const toDate = document.getElementById('toDate').value;
urlParams.set('status_filter', statusFilter);
urlParams.set('priority_filter', priorityFilter);
urlParams.set('orders_per_page', ordersPerPage);
urlParams.set('from_date', fromDate);
urlParams.set('to_date', toDate);
urlParams.set('page', 1); // Reset to first page
window.location.search = urlParams.toString();
}
// Function to apply date filters separately
function applyDateFilters() {
applyFilters();
}
// Close action rows when clicking outside the table
document.addEventListener('click', function(event) {
const isClickInside = event.target.closest('.orders-table');
if (!isClickInside) {
document.querySelectorAll('.change-status-controls.active').forEach(function(el) {
el.classList.remove('active');
const siblings = el.previousElementSibling;
if (siblings) {
siblings.style.display = 'flex';
}
});
}
});
</script>
Background and Layout
Background Color: Use a crisp white background for the entire interface. This creates a professional, high-end look and allows the products to be the main focus.
Card and Table Shadows: Implement minimal shadows on product cards and tables for a sleek "floating" effect. This adds depth without overcrowding the design, keeping it light and professional.
Padding and Spacing: Increase spacing around elements to create an airy layout, making the interface feel open and reducing visual clutter.
Filters Section
Filter Buttons: Use pill-shaped filter buttons in a neutral palette, like cool greys or soft charcoal, with a gradient accent. This keeps the design sleek and modern while adding a subtle highlight.
Date Pickers and Dropdowns: Use outlined fields with a thin grey border. When clicked, the border color changes to a soft accent color (e.g., light grey or teal) to enhance interactivity.
Search Bar
Search Field Styling: Incorporate a modern search bar with a grey border and a magnifying glass icon inside the field for usability. On focus, the border color should change to a darker grey, creating a professional highlight effect.
Search Button: Use a rounded, solid button in a soft grey or cool-toned accent color. Adding a slight shadow or a darkened border on hover makes it feel interactive while remaining understated.
Product Display and Table
Column Headers: Use a sans-serif font like "Inter" or "Roboto" in a slightly larger size and bold weight for headers. Style headers with a very light grey background and a single underline to separate them from the content rows, giving a minimalist appearance.
Row Backgrounds: Use alternating light grey and white backgrounds for rows to improve readability without adding visual noise.
Product Details: Arrange product details in a clean, vertical layout within each cell. This could include the product name, price, and description, each on a new line in a smaller, lighter font.
Status Badges: Design status labels with modern colors and rounded edges. For example:
Available: A muted green label with white text.
Out of Stock: Light grey with dark text to indicate unavailability in a subtle way.
New Arrival: Soft blue with white text to add a touch of vibrancy without overpowering the layout.
Action Buttons
Button Colors and Layout: Use clean, solid-colored buttons with slight gradients for emphasis, keeping the colors muted to match the professional tone:
Add to Cart: Soft grey-blue or charcoal to fit the modern look.
View Details: Neutral grey with a slight hover effect, like darkening the button or adding a shadow.
Remove: Soft, muted red for "Remove" to indicate caution without looking aggressive.
Button Shape and Iconography: Use rounded buttons with slight shadowing to give them a subtle, floating effect. Small icons next to the text (e.g., shopping cart icon for "Add to Cart") can add clarity to the buttons without adding too much visual weight.
Typography
Font Choice: Choose a modern sans-serif font like "Inter," "Roboto," or "Open Sans" to keep the text clean and professional. Use different weights to establish hierarchy, such as bold for product names and regular or light for details.
Hierarchy and Emphasis: Increase font sizes for key information like product names and headers. Keep secondary details in a smaller, lighter font for contrast and readability.
Color Palette
Primary Colors: White and light grey for a clean, modern background. Dark grey or charcoal can be used for text to maintain high contrast.
Accent Colors: Muted blues, greens, and a touch of soft red for status indicators or subtle highlights on buttons.
Text Colors: Dark grey or black for primary text for readability, with lighter shades of grey for secondary information.
Image and Visuals
Product Images: Use high-resolution images with a subtle shadow around each to give them a polished look. Keeping the images well-lit and professionally styled adds to the upscale aesthetic.
Minimal Decorative Elements: For a more modern and professional look, limit decorative elements. Instead, rely on clean lines, soft shadows, and whitespace for visual structure.
Interactive Elements and Transitions
Hover and Focus Effects: Add subtle transitions when hovering over interactive elements like buttons and filter options. For instance, slightly darken the color or add a shadow to indicate interactivity.
Load Animations: When loading new products or applying filters, consider adding a minimalist fade-in effect to maintain a smooth, modern user experience.
Product Highlights and Labels
Featured Products or Discounts: Use a sleek "badge" design in a soft accent color like muted teal or grey-blue for featured products, bestsellers, or discounts. Keep the text small and centered for a refined look.
This design approach will create a clean, modern UI that feels both professional and sophisticated, with a hint of bakery warmth through subtle accent colors. By using minimalistic layouts, rounded buttons, and a balanced color palette, the interface will look polished and user-friendly, ideal for an online bakery platform focused on a professional shopping experience.) and based on this styles (
) and type full codes
Certainly! Below is the fully updated view_orders.php file for the Kaak Alia Management System. The design has been refined to be modern, clean, and professional, with subtle hints of the bakery theme to maintain a warm and sophisticated feel. The new CSS styles provided have been integrated, ensuring a cohesive and polished user interface.
CSS Variables: Defined a set of CSS variables to maintain consistency across the design. These include primary colors, accent colors, text colors, UI elements, button colors, and status badge colors.
Global Styles: Applied a clean and modern font (Roboto and Inter), set a light grey background for the body, and ensured the main container has ample padding and a subtle box shadow for depth.
Header: Simplified the header with a stylish font and a decorative gradient line beneath the title for a polished look.
Alerts: Styled success and error alerts with subtle colors and shadows to align with the modern aesthetic.
Filter and Search Section: Utilized flexbox for responsive layout, with pill-shaped buttons and outlined inputs that change border color on focus for better interactivity.
Orders Table: Modernized the table with alternating row colors, clean fonts, and minimalistic header styles. Status badges have rounded edges and distinct colors based on the order status.
Action Buttons: Redesigned action buttons with rounded corners, subtle hover effects, and clear iconography for intuitive user interactions.
Pagination: Styled pagination links with rounded buttons and clear active states to enhance navigation.
Modals and Controls: Ensured modals and status change controls align with the overall design theme, featuring consistent border radii and color schemes.
Responsive Design: Enhanced responsiveness with media queries to ensure the interface remains user-friendly across different devices.
HTML Structure Adjustments:
Filter and Search Forms: Organized filters and search inputs into dedicated sections with appropriate labels and placeholders for better user experience.
Orders Table: Maintained the existing structure but applied new classes and styles to align with the updated CSS. Incorporated badges and tooltips for better status indication.
Action Buttons: Positioned action buttons within collapsible rows for each order, providing options to edit, change status, delete, or view customer orders.
Footer: Styled the footer to match the modern design with subtle colors and typography.
JavaScript Enhancements:
Sorting Functionality: Enhanced sorting interactions with clean transitions and accurate URL parameter adjustments.
By implementing these changes, the view_orders.php page now boasts a modern, clean, and professional design that subtly reflects the warmth and sophistication of an upscale online bakery platform. The interface is intuitive, responsive, and visually appealing, making it ideal for enhancing user experience and operational efficiency.