// 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>
Here’s a tailored description for a bakery management system UI:
Input Fields
Style: Inputs feature a clean and inviting design, with smooth, rounded corners that make fields feel approachable and user-friendly.
Border and Shadow: Each input field has a subtle, 1px border in a soft, bakery-themed tone (e.g., light brown or beige, like #E8D8C3). Adding a light shadow (0px 2px 4px rgba(0,0,0,0.1)) gives the inputs a sense of depth without overpowering other elements.
Focus State: On focus, the input field border shifts to a warm accent color (e.g., #D19A66), enhancing the user's focus on their task. A slight drop shadow accentuates this focused state.
Text and Font: The input text uses a modern serif or friendly sans-serif font (such as Roboto or Nunito), in a mid-gray color (#555555) with a 16px font size for clear readability.
Placeholder Text: Placeholder text is in a lighter shade (e.g., #AAAAAA) and italicized for a soft, helpful look that fades as users type.
Padding and Space: Each input field is padded generously (10-12px), making each input comfortable to tap on mobile and ensuring it feels spacious.
Content Boxes and Containers
Background: Boxes and containers feature a light, bakery-inspired background color (e.g., a soft cream #F9F4EC), creating a gentle contrast with the page background.
Border and Shadow: Borders are rounded (8px to 12px radius), with a delicate shadow (2px 4px 8px rgba(0,0,0,0.1)), giving boxes a warm, welcoming effect.
Spacing: Generous padding within each box (around 20px) ensures content is separated from the edges, and margin around the boxes contributes to a balanced layout. The additional space keeps each section tidy, emphasizing a clean design.
Hover and Interaction: On hover, the background color subtly shifts (slightly darker shade of the background) or the shadow deepens, signaling interactivity in a gentle, bakery-themed way.
Titles and Headings
Typography: Titles use a bold yet friendly font (e.g., Nunito or Lora) with a weight around 600-700 for main sections. Font sizes vary depending on the heading level:
Primary Titles (e.g., H1): 32px, bold, reserved for main headings on key pages.
Secondary Titles (e.g., H2): 24px, slightly less bold, used for subsections.
Tertiary Titles (e.g., H3): 20px, medium weight, for specific breakdowns.
Color and Contrast: Titles are in a warm dark brown or dark gray (#3A2F1B or #333333) to give the page a grounded and inviting bakery feel, while ensuring high contrast against light backgrounds.
Alignment and Spacing: Titles are left-aligned by default, with extra top and bottom margins (20px) to keep sections clearly separated and easy to read.
Highlighting: For drawing attention to important keywords within titles, a subtle underline or an accent color like #D19A66 is used, reflecting a consistent bakery-inspired theme.
) and i won't create style file css, just make it into one file view orders and tpye full codes plz with changes and make it best ux design and make it cool
Certainly! Below is the updated view_orders.php file for your bakery management system. The design has been revamped to follow a consistent, reusable design language tailored specifically for a bakery-themed UI. All styles are centralized within the <style> tag for ease of management, as per your request. Additionally, enhancements have been made to improve the overall user experience (UX) and ensure a modern, inviting interface.
Key Changes Implemented:
Centralized Design Language:
Colors: Updated CSS variables to reflect warm, bakery-inspired tones.
Typography: Incorporated friendly sans-serif fonts (Nunito) for a modern and approachable feel.
Input Fields: Styled with rounded corners, soft borders, subtle shadows, and clear focus states.
Containers & Boxes: Feature light cream backgrounds, rounded borders, and gentle shadows to create a welcoming environment.
Titles & Headings: Utilized consistent font sizes, weights, and colors to enhance readability and aesthetics.
Buttons & Interactive Elements: Redesigned with smooth transitions, consistent padding, and hover effects to indicate interactivity.
Enhanced UX:
Responsive Design: Improved responsiveness across various screen sizes for optimal usability on all devices.
Accessibility: Ensured high contrast for better readability and included tooltips for better user guidance.
Interactivity: Enhanced interactive elements like buttons and inputs with smooth transitions and visual feedback.
Cleaned & Organized Code:
Removed redundant styles and streamlined the CSS for better maintainability.
Ensured semantic HTML structure for improved accessibility and SEO.
Introduced variables like --light-brown, --warm-accent, --cream, etc., to maintain consistency across the design.
These variables are used throughout the CSS to ensure a cohesive color scheme.
Typography Enhancements:
Incorporated the Nunito and Lora fonts from Google Fonts for a modern and friendly appearance.
Titles use Lora for a serif touch, while body and interactive elements use Nunito for readability.
Input Fields Styled:
Rounded corners (var(--border-radius)) and soft borders (var(--light-brown)) make the inputs approachable.
Subtle shadows (var(--shadow-light)) add depth without distraction.
Focus states shift the border color to --warm-accent and add a slight drop shadow for emphasis.
Containers & Boxes:
The .recent-orders-section features a --cream background with rounded borders and a deep shadow for a welcoming feel.
Generous padding and margins ensure content is well-spaced and organized.
Titles & Headings:
Titles (h4) use Lora with increased font sizes and weights for prominence.
Consistent bottom borders and padding enhance separation from other content.
Buttons & Interactive Elements:
Buttons have consistent padding, border-radius, and transition effects.
Hover states change background colors and slightly scale the buttons to indicate interactivity.
Tables & Badges:
Updated table headers with consistent styling, including color changes on hover for better user experience.
Status badges are color-coded (Pending, Completed, Delivered) for quick visual identification.
Responsive Design:
Enhanced media queries ensure the layout adapts gracefully to different screen sizes.
Inputs and buttons adjust their widths and padding for better usability on smaller devices.
Best Practices Followed:
Maintainability: By centralizing styles within CSS variables and the <style> tag, future updates can be made easily without sifting through inline styles.
Accessibility: High contrast colors and readable font sizes ensure content is accessible to all users.
Responsiveness: The design adapts to various screen sizes, ensuring usability across devices.
User Experience: Interactive elements provide visual feedback, guiding users intuitively through their tasks.
This updated design not only aligns with the specific aesthetic and functional requirements of a bakery management system but also ensures a pleasant and efficient user experience. Feel free to further customize the styles or functionality as needed to best suit your specific needs.