change this design codes (<?php // p… · The Chat Archive
Explore / Programming change this design codes (<?php // public/orders/addorder.php // Enable error reporting… Save Share Download ▾ Reportchange this design codes (<?php
// public/orders/add_order.php
// Enable error reporting for debugging (disable in production)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Start output buffering to prevent "headers already sent" errors
ob_start();
// Include authentication, database connection, and functions
require_once DIR . '/../../includes/auth.php';
require_once DIR . '/../../includes/db_connect.php';
require_once DIR . '/../../includes/functions.php'; // Include the functions.php for sanitize_input()
// Initialize variables
s u c c e s s = ′ ′ ; success = '';
s u ccess = ′′ ; error = '';
// Fetch products for selection
p r o d u c t s s q l = " S E L E C T ∗ F R O M p r products_result = products_sql);
Assistant2024-11-12 09:12 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 12, 2024
Added to archive Nov 16, 2026
ID 01m7h427xw0g49we8b97q2s44sSource & license Imported from WildChat-4.8M (AI2) (source ). Imported records earn no Research Points.
Upstream record: c53ea863a0b656eac958fdd7caab2336
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
o d u c t s O R D E R B Y n a m e A S C " ; products_sql = "SELECT * FROM products ORDER BY name ASC";
p r o d u c t s s q l = " S E L E C T ∗ F R O M p r o d u c t s O R D E R B Y nam e A S C " ;
c o n n − > q u e r y ( conn->query( co nn − > q u er y ( if (!products_result) {
die("Error fetching products: " . conn->error);
}
// Handle form submission
if (_SERVER['REQUEST_METHOD'] == 'POST') {
// Sanitize and validate input
customer_name = sanitize_input(P O S T [ ′ c u s t o m e r n a m e ′ ] ) ; _POST['customer_name']);
P O S T [ ′ c u s t o m e r n am e ′ ]) ; contact = sanitize_input(P O S T [ ′ c o n t a c t ′ ] ) ; _POST['contact']);
P O S T [ ′ co n t a c t ′ ]) ; delivery_address = sanitize_input(P O S T [ ′ d e l i v e r y a d d r e s s ′ ] ) ; _POST['delivery_address']);
P O S T [ ′ d e l i v er y delivery_datetime = isset(_POST['delivery_datetime']) && !empty( _POST['delivery_datetime']) ? sanitize_input(P O S T [ ′ d e l i v e r y d a t e t i m e ′ ] ) : n u l l ; _POST['delivery_datetime']) : null;
P O S T [ ′ d e l i v er y priority = isset(P O S T [ ′ p r i o r i t y ′ ] ) ? s a n i t i z e i n p u t ( _POST['priority']) ? sanitize_input( P O S T [ ′ p r i or i t y _POST['priority']) : 'Normal';
// Validate priority
$valid_priorities = ['Normal', 'Important', 'Quick'];
if (!in_array($priority, $valid_priorities)) {
$priority = 'Normal';
}
// Handle multiple products
$product_ids = isset($_POST['product_id']) ? $_POST['product_id'] : [];
$quantities = isset($_POST['quantity']) ? $_POST['quantity'] : [];
$packaging_preferences = isset($_POST['packaging_preferences']) ? $_POST['packaging_preferences'] : [];
$apply_discount = isset($_POST['apply_discount']) ? $_POST['apply_discount'] : [];
$discount_percentages = isset($_POST['discount_percentage']) ? $_POST['discount_percentage'] : [];
$discount_reasons = isset($_POST['discount_reason']) ? $_POST['discount_reason'] : [];
// Basic validation
if (empty($customer_name)) {
$error = "Customer name is required.";
} elseif (empty($product_ids) || !is_array($product_ids) || count($product_ids) == 0) {
$error = "At least one product must be selected.";
} else {
// Validate each product entry
foreach ($product_ids as $index => $pid) {
if (empty($pid)) {
$error = "Product selection is required for all items.";
break;
}
if (!isset($quantities[$index]) || intval($quantities[$index]) <= 0) {
$error = "Quantity must be at least 1 for all items.";
break;
}
// If discount is applied, validate discount fields
if (isset($apply_discount[$index])) {
$discount = trim($discount_percentages[$index]);
$reason = trim($discount_reasons[$index]);
if ($discount === '') {
$error = "Discount percentage is required if discount is applied.";
break;
}
if (!is_numeric($discount) || floatval($discount) < 0 || floatval($discount) > 100) {
$error = "Invalid discount percentage for product. It should be between 0 and 100.";
break;
}
if (empty($reason)) {
$error = "Discount reason is required if discount is applied.";
break;
}
}
}
// Validate delivery_datetime
if ($delivery_datetime && !preg_match("/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/", $delivery_datetime)) {
$error = "Invalid delivery date and time format.";
} elseif ($delivery_datetime && strtotime(str_replace('T', ' ', $delivery_datetime)) < strtotime(date('Y-m-d H:i'))) {
$error = "Delivery date and time cannot be in the past.";
}
}
if (empty($error)) {
// Start transaction
$conn->begin_transaction();
try {
// Insert into customers table using prepared statement
$stmt = $conn->prepare("INSERT INTO customers (name, contact, delivery_address) VALUES (?, ?, ?)");
if (!$stmt) {
throw new Exception("Prepare statement failed: " . $conn->error);
}
$stmt->bind_param("sss", $customer_name, $contact, $delivery_address);
if (!$stmt->execute()) {
throw new Exception("Execute failed: " . $stmt->error);
}
$customer_id = $stmt->insert_id;
$stmt->close();
// Insert into orders table using prepared statement
$status = 'Pending'; // Default status
$stmt = $conn->prepare("INSERT INTO orders (customer_id, status, priority, delivery_datetime) VALUES (?, ?, ?, ?)");
if (!$stmt) {
throw new Exception("Prepare statement failed: " . $conn->error);
}
$stmt->bind_param("isss", $customer_id, $status, $priority, $delivery_datetime);
if (!$stmt->execute()) {
throw new Exception("Execute failed: " . $stmt->error);
}
$order_id = $stmt->insert_id;
$stmt->close();
// Insert products into order_items table
$stmt = $conn->prepare("INSERT INTO order_items (order_id, product_id, quantity, packaging_preferences, discount_percentage, discount_reason) VALUES (?, ?, ?, ?, ?, ?)");
if (!$stmt) {
throw new Exception("Prepare statement failed: " . $conn->error);
}
// Loop through each product
foreach ($product_ids as $index => $pid) {
$pid = intval($pid);
$qty = intval($quantities[$index]);
$pack_pref = sanitize_input($packaging_preferences[$index]);
// Handle discount
$discount_percent = 0.00;
$discount_rs = null;
if (isset($apply_discount[$index])) {
$discount_percent = floatval(trim($discount_percentages[$index]));
$discount_rs = sanitize_input($discount_reasons[$index]);
}
$stmt->bind_param("iiidds", $order_id, $pid, $qty, $pack_pref, $discount_percent, $discount_rs);
if (!$stmt->execute()) {
throw new Exception("Execute failed: " . $stmt->error);
}
}
$stmt->close();
// Commit transaction
$conn->commit();
// Redirect to view_orders.php after successful addition
header("Location: view_orders.php?success=1");
exit();
} catch (Exception $e) {
// Rollback transaction
$conn->rollback();
$error = "Error adding order: " . $e->getMessage();
}
}
// Now include the header AFTER form handling
require_once '../../includes/header.php';
?>
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700&family=Roboto:wght@400;500;700&family=Inter: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">
<!-- Custom Styles -->
<style>
/* ---------------------------------------------------
1. CSS Variables for Consistent Design
---------------------------------------------------- */
:root {
/* Primary Colors */
--background-color: #FFFFFF; /* Crisp White */
--light-grey: #F5F5F5;
--medium-grey: #CCCCCC;
--dark-grey: #333333;
--charcoal: #4A4A4A;
/* Accent Colors */
--accent-blue: #4A90E2;
--accent-green: #50C878;
--accent-red: #FF6B6B;
--accent-teal: #374151;
--accent-soft-blue: #A3D2CA;
--accent-purple: #8A65FF;
--accent-orange: #FFA500;
/* Text Colors */
--primary-text: var(--dark-grey);
--secondary-text: #666666;
/* UI Elements */
--input-border: var(--medium-grey);
--input-focus-border: var(--accent-teal);
--box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
--box-border-radius: 12px;
--hover-shadow: rgba(0, 0, 0, 0.1);
/* Button Colors */
--button-add-order: #6C63FF;
--button-view-orders: #FFA500;
--button-manage-products: #20B2AA;
--button-manage-users: #4B0082;
--button-generate-reports: #FF6B6B;
/* Status Badge Colors */
--badge-pending: #FFD166;
--badge-in-progress: #6A4C93;
--badge-completed: #4CAF50;
--badge-delivered: #20B2AA;
}
/* ---------------------------------------------------
2. Global Styles
---------------------------------------------------- */
body {
font-family: 'Roboto', sans-serif;
background-color: var(--light-grey);
margin: 0;
padding: 0;
color: var(--primary-text);
}
.container-body {
max-width: 1200px;
margin: 40px auto;
padding: 40px 20px;
box-sizing: border-box;
background-color: var(--background-color);
box-shadow: var(--box-shadow);
border-radius: var(--box-border-radius);
font-family: 'Roboto', sans-serif;
transition: all 0.3s ease;
}
/* ---------------------------------------------------
3. Header Styles
---------------------------------------------------- */
.header {
padding: 20px 30px;
background-color: var(--background-color);
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 30px;
border-bottom: 1px solid var(--light-grey);
}
.header h1 {
color: var(--charcoal);
font-size: 32px;
font-weight: 700;
font-family: 'Inter', sans-serif;
position: relative;
}
/* Decorative Line Under Header */
.header h1::after {
content: "";
display: block;
width: 80px;
height: 4px;
background: linear-gradient(90deg, var(--accent-teal), var(--accent-soft-blue));
margin: 8px auto 0;
border-radius: 2px;
}
/* ---------------------------------------------------
4. Welcome Section
---------------------------------------------------- */
.welcome-section {
background-color: var(--background-color);
box-shadow: var(--box-shadow);
border-radius: var(--box-border-radius);
padding: 30px;
text-align: center;
margin-bottom: 30px;
font-family: 'Inter', sans-serif;
}
.welcome-section h3 {
font-size: 24px;
color: var(--primary-text);
margin-bottom: 10px;
font-weight: 600;
}
.welcome-section hr {
width: 80px;
height: 4px;
background-color: var(--accent-teal);
border: none;
margin: 15px auto 0;
border-radius: 2px;
}
/* ---------------------------------------------------
5. Form Container Styles
---------------------------------------------------- */
.form-container {
background-color: var(--background-color);
box-shadow: var(--box-shadow);
border-radius: var(--box-border-radius);
padding: 30px;
max-width: 900px;
margin: auto;
font-family: 'Roboto', sans-serif;
}
.form-container h3 {
text-align: center;
margin-bottom: 30px;
color: var(--accent-teal);
font-family: 'Inter', sans-serif;
font-size: 28px;
font-weight: 700;
}
/* ---------------------------------------------------
6. Form Styles
---------------------------------------------------- */
.form-control {
border-radius: var(--box-border-radius);
border: 1px solid var(--input-border);
background-color: #ffffff;
padding: 12px;
box-shadow: var(--box-shadow);
transition: border-color 0.3s, box-shadow 0.3s;
width: 100%;
margin-bottom: 20px;
font-family: 'Roboto', sans-serif;
color: var(--primary-text);
font-size: 16px;
}
.form-control::placeholder {
color: #AAAAAA;
font-style: italic;
}
.form-control:focus {
border-color: var(--accent-teal);
box-shadow: 0 0 5px var(--accent-teal);
outline: none;
}
.form-label {
margin-bottom: 5px;
font-size: 14px;
text-align: left;
font-family: 'Inter', sans-serif;
font-weight: 600;
color: var(--secondary-text);
}
/* ---------------------------------------------------
7. Order Priority Styles
---------------------------------------------------- */
.order-priority {
display: flex;
gap: 25px;
margin-bottom: 25px;
flex-wrap: wrap;
}
.order-priority label {
cursor: pointer;
position: relative;
padding-left: 35px;
user-select: none;
font-weight: 600;
transition: color 0.3s;
font-family: 'Inter', sans-serif;
color: var(--secondary-text);
}
.order-priority input[type="radio"] {
position: absolute;
opacity: 0;
cursor: pointer;
}
.order-priority .custom-radio {
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
height: 20px;
width: 20px;
background-color: #fff;
border: 2px solid var(--input-border);
border-radius: 50%;
transition: background-color 0.3s, border-color 0.3s;
}
.order-priority label:hover input ~ .custom-radio {
border-color: var(--accent-teal);
}
.order-priority input:checked ~ .custom-radio {
background-color: var(--accent-teal);
border-color: var(--accent-teal);
}
.order-priority .custom-radio::after {
content: "";
position: absolute;
display: none;
}
.order-priority input:checked ~ .custom-radio::after {
display: block;
}
.order-priority .custom-radio::after {
top: 6px;
left: 6px;
width: 8px;
height: 8px;
border-radius: 50%;
background: white;
}
/* ---------------------------------------------------
8. Buttons Section
---------------------------------------------------- */
.add-product-button,
.remove-product-button,
.submit-button {
border: none;
border-radius: var(--box-border-radius);
padding: 10px 20px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s, transform 0.3s, box-shadow 0.3s;
font-family: 'Inter', sans-serif;
}
.add-product-button {
background-color: var(--accent-teal);
color: #ffffff;
margin-top: 10px;
display: flex;
align-items: center;
justify-content: center;
}
.add-product-button:hover {
background-color: #18A999;
}
.remove-product-button {
background-color: var(--accent-red);
color: #ffffff;
}
.remove-product-button:hover {
background-color: #e63946;
}
.submit-button {
width: 100%;
height: 50px;
font-weight: bold;
background-color: var(--accent-teal);
color: #ffffff;
display: block;
margin: 30px auto 0 auto;
text-align: center;
font-family: 'Inter', sans-serif;
box-shadow: var(--box-shadow);
}
.submit-button:hover {
background-color: #17A2B8;
transform: scale(1.02);
box-shadow: 0 4px 12px var(--hover-shadow);
}
/* ---------------------------------------------------
9. Alert Styles
---------------------------------------------------- */
.alert-success,
.alert-danger {
border-radius: var(--box-border-radius);
padding: 15px 20px;
margin-bottom: 20px;
text-align: center;
width: 100%;
margin: 20px auto;
font-family: 'Inter', sans-serif;
font-size: 16px;
}
.alert-success {
background-color: var(--badge-completed);
color: #ffffff;
}
.alert-danger {
background-color: var(--badge-delivered);
color: #ffffff;
}
/* ---------------------------------------------------
10. Footer Styles
---------------------------------------------------- */
.footer {
background-color: var(--background-color);
color: var(--secondary-text);
padding: 20px;
text-align: center;
border-radius: var(--box-border-radius);
font-size: 14px;
line-height: 22px;
margin-top: 40px;
font-family: 'Roboto', sans-serif;
box-shadow: var(--box-shadow);
}
/* ---------------------------------------------------
11. Responsive Design Enhancements
---------------------------------------------------- */
@media (max-width: 768px) {
.header h1 {
font-size: 24px;
}
.welcome-section h3 {
font-size: 20px;
}
.form-container h3 {
font-size: 24px;
}
.action-button {
flex: 1 1 100%;
height: 50px;
font-size: 14px;
}
.form-control {
font-size: 14px;
}
.form-label {
font-size: 13px;
}
.submit-button {
height: 50px;
font-size: 16px;
}
}
@media (max-width: 480px) {
.container-body {
padding: 20px 10px;
}
.header h1 {
font-size: 20px;
}
.welcome-section h3 {
font-size: 18px;
}
.form-container h3 {
font-size: 20px;
}
.form-control {
font-size: 13px;
}
.form-label {
font-size: 12px;
}
.submit-button {
height: 45px;
font-size: 14px;
}
.order-priority {
flex-direction: column;
}
}
</style>
<!-- Additional JavaScript for dynamic product addition and discount handling -->
<script>
let productCount = <?= isset($product_ids) ? count($product_ids) : 1; ?>;
function addProductRow() {
const productContainer = document.getElementById('products-container');
const productRow = document.createElement('div');
productRow.className = 'product-row border p-3 mb-3';
productRow.innerHTML = `
<div class="row">
<div class="col-md-4">
<label class="form-label" for="product_id_${productCount}">Product <span class="text-danger">*</span></label>
<select name="product_id[]" id="product_id_${productCount}" class="form-control" required>
<option value="">Select Product</option>
<?php
// Reset the products_result pointer
$products_result->data_seek(0);
while($product = $products_result->fetch_assoc()): ?>
<option value="<?= htmlspecialchars($product['id']) ?>">
<?= htmlspecialchars($product['name'] . " - " . $product['size'] . " (" . number_format($product['price'], 2) . " KD)") ?>
</option>
<?php endwhile; ?>
</select>
</div>
<div class="col-md-2">
<label class="form-label" for="quantity_${productCount}">Quantity <span class="text-danger">*</span></label>
<input type="number" name="quantity[]" id="quantity_${productCount}" class="form-control" min="1" value="1" required>
</div>
<div class="col-md-3">
<label class="form-label" for="packaging_preferences_${productCount}">Packaging Preferences</label>
<input type="text" name="packaging_preferences[]" id="packaging_preferences_${productCount}" class="form-control" placeholder="e.g., Gift Wrap">
</div>
<div class="col-md-3">
<label class="form-label" for="discount_${productCount}">Apply Discount</label>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="1" id="discount_checkbox_${productCount}" name="apply_discount[]">
<label class="form-check-label" for="discount_checkbox_${productCount}">
Yes
</label>
</div>
<div id="discount_fields_${productCount}" style="display: none; margin-top: 10px;">
<label class="form-label" for="discount_percentage_${productCount}">Discount Percentage (%) <span class="text-danger">*</span></label>
<input type="number" name="discount_percentage[]" id="discount_percentage_${productCount}" class="form-control" min="0" max="100" step="0.01" placeholder="Enter discount percentage">
<label class="form-label mt-2" for="discount_reason_${productCount}">Discount Reason <span class="text-danger">*</span></label>
<input type="text" name="discount_reason[]" id="discount_reason_${productCount}" class="form-control" placeholder="Enter reason for discount">
</div>
</div>
<div class="col-md-12 d-flex justify-content-end mt-3">
<button type="button" class="remove-product-button btn btn-danger btn-sm" onclick="removeProductRow(this)"><i class="bi bi-trash-fill"></i> Remove</button>
</div>
</div>
`;
productContainer.appendChild(productRow);
// Initialize discount toggle for the new row
const newCheckbox = productRow.querySelector(`input[name="apply_discount[]"]`);
newCheckbox.addEventListener('change', function() {
toggleDiscountFields(this, productCount);
});
productCount++;
}
function removeProductRow(button) {
const productRow = button.closest('.product-row');
productRow.remove();
}
// Toggle discount fields based on checkbox
function toggleDiscountFields(checkbox, count) {
const discountFields = document.getElementById(`discount_fields_${count}`);
if (checkbox.checked) {
discountFields.style.display = 'block';
} else {
discountFields.style.display = 'none';
// Clear discount inputs
discountFields.querySelectorAll('input').forEach(input => input.value = '');
}
}
// Add event listeners to existing discount checkboxes on page load
function initializeDiscountToggle() {
const discountCheckboxes = document.querySelectorAll('input[name="apply_discount[]"]');
discountCheckboxes.forEach((checkbox, index) => {
checkbox.addEventListener('change', function() {
toggleDiscountFields(this, index);
});
});
}
// Initialize on DOM content loaded
document.addEventListener('DOMContentLoaded', function() {
// Add initial product row if none exist
if (document.getElementById('products-container').children.length === 0) {
addProductRow();
}
// Initialize discount toggles
initializeDiscountToggle();
});
</script>
<main class='container-body'>
<!-- Welcome Section -->
<div class="welcome-section">
<h3>Add a New Order</h3>
<hr>
<p>Fill out the form below to add a new customer order.</p>
</div>
<!-- Form Container -->
<div class="form-container">
<h3>Add New Order</h3>
<?php if (!empty($error)): ?>
<div class="alert-danger"><?= htmlspecialchars($error) ?></div>
<?php endif; ?>
<?php if (!empty($success)): ?>
<div class="alert-success"><?= htmlspecialchars($success) ?></div>
<?php endif; ?>
<form method="POST" action="add_order.php">
<!-- Customer Details -->
<div class="form-section">
<h5>Customer Details</h5>
<label class="form-label" for="customer_name">Name <span class="text-danger">*</span></label>
<input type="text" id="customer_name" name="customer_name" class="form-control"
value="<?= isset($_POST['customer_name']) ? htmlspecialchars($_POST['customer_name']) : '' ?>"
required>
<label class="form-label" for="contact">Contact</label>
<input type="text" id="contact" name="contact" class="form-control"
value="<?= isset($_POST['contact']) ? htmlspecialchars($_POST['contact']) : '' ?>">
<label class="form-label" for="delivery_address">Delivery Address</label>
<textarea id="delivery_address" name="delivery_address" class="form-control"><?= isset($_POST['delivery_address']) ? htmlspecialchars($_POST['delivery_address']) : '' ?></textarea>
</div>
<hr>
<!-- Order Details -->
<div class="form-section">
<h5>Order Details</h5>
<!-- Priority Selection -->
<label class="form-label">Order Priority</label>
<div class="order-priority">
<label>
<input type="radio" name="priority" value="Normal" <?= (isset($_POST['priority']) && $_POST['priority'] === 'Normal') || !isset($_POST['priority']) ? 'checked' : '' ?>>
<span class="custom-radio"></span>
Normal (Default)
</label>
<label>
<input type="radio" name="priority" value="Important" <?= isset($_POST['priority']) && $_POST['priority'] === 'Important' ? 'checked' : '' ?>>
<span class="custom-radio"></span>
Important
</label>
<label>
<input type="radio" name="priority" value="Quick" <?= isset($_POST['priority']) && $_POST['priority'] === 'Quick' ? 'checked' : '' ?>>
<span class="custom-radio"></span>
Quick
</label>
</div>
<!-- Products Selection -->
<div id="products-container">
<!-- Product Rows will be added here -->
<?php
// If form was submitted with errors, repopulate the product rows
if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($error) && !empty($product_ids) && is_array($product_ids)) {
foreach ($product_ids as $i => $pid) {
?>
<div class="product-row border p-3 mb-3">
<div class="row">
<div class="col-md-4">
<label class="form-label" for="product_id_<?= $i ?>">Product <span class="text-danger">*</span></label>
<select name="product_id[]" id="product_id_<?= $i ?>" class="form-control" required>
<option value="">Select Product</option>
<?php
$products_result->data_seek(0);
while($product = $products_result->fetch_assoc()):
$selected = ($product['id'] == $pid) ? 'selected' : '';
?>
<option value="<?= htmlspecialchars($product['id']) ?>" <?= $selected ?>>
<?= htmlspecialchars($product['name'] . " - " . $product['size'] . " (" . number_format($product['price'], 2) . " KD)") ?>
</option>
<?php endwhile; ?>
</select>
</div>
<div class="col-md-2">
<label class="form-label" for="quantity_<?= $i ?>">Quantity <span class="text-danger">*</span></label>
<input type="number" name="quantity[]" id="quantity_<?= $i ?>" class="form-control" min="1" value="<?= isset($quantities[$i]) ? intval($quantities[$i]) : '1' ?>" required>
</div>
<div class="col-md-3">
<label class="form-label" for="packaging_preferences_<?= $i ?>">Packaging Preferences</label>
<input type="text" name="packaging_preferences[]" id="packaging_preferences_<?= $i ?>" class="form-control" placeholder="e.g., Gift Wrap" value="<?= isset($packaging_preferences[$i]) ? htmlspecialchars($packaging_preferences[$i]) : '' ?>">
</div>
<div class="col-md-3">
<label class="form-label" for="discount_<?= $i ?>">Apply Discount</label>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="1" id="discount_checkbox_<?= $i ?>" name="apply_discount[]" <?= isset($apply_discount[$i]) ? 'checked' : '' ?>>
<label class="form-check-label" for="discount_checkbox_<?= $i ?>">
Yes
</label>
</div>
<div id="discount_fields_<?= $i ?>" style="display: <?= isset($apply_discount[$i]) ? 'block' : 'none' ?>; margin-top: 10px;">
<label class="form-label" for="discount_percentage_<?= $i ?>">Discount Percentage (%) <span class="text-danger">*</span></label>
<input type="number" name="discount_percentage[]" id="discount_percentage_<?= $i ?>" class="form-control" min="0" max="100" step="0.01" placeholder="Enter discount percentage" value="<?= isset($discount_percentages[$i]) ? htmlspecialchars($discount_percentages[$i]) : '' ?>">
<label class="form-label mt-2" for="discount_reason_<?= $i ?>">Discount Reason <span class="text-danger">*</span></label>
<input type="text" name="discount_reason[]" id="discount_reason_<?= $i ?>" class="form-control" placeholder="Enter reason for discount" value="<?= isset($discount_reasons[$i]) ? htmlspecialchars($discount_reasons[$i]) : '' ?>">
</div>
</div>
<div class="col-md-12 d-flex justify-content-end mt-3">
<button type="button" class="remove-product-button btn btn-danger btn-sm" onclick="removeProductRow(this)"><i class="bi bi-trash-fill"></i> Remove</button>
</div>
</div>
</div>
<?php
}
} else {
// Add one default product row
?>
<div class="product-row border p-3 mb-3">
<div class="row">
<div class="col-md-4">
<label class="form-label" for="product_id_0">Product <span class="text-danger">*</span></label>
<select name="product_id[]" id="product_id_0" class="form-control" required>
<option value="">Select Product</option>
<?php
$products_result->data_seek(0);
while($product = $products_result->fetch_assoc()): ?>
<option value="<?= htmlspecialchars($product['id']) ?>">
<?= htmlspecialchars($product['name'] . " - " . $product['size'] . " (" . number_format($product['price'], 2) . " KD)") ?>
</option>
<?php endwhile; ?>
</select>
</div>
<div class="col-md-2">
<label class="form-label" for="quantity_0">Quantity <span class="text-danger">*</span></label>
<input type="number" name="quantity[]" id="quantity_0" class="form-control" min="1" value="1" required>
</div>
<div class="col-md-3">
<label class="form-label" for="packaging_preferences_0">Packaging Preferences</label>
<input type="text" name="packaging_preferences[]" id="packaging_preferences_0" class="form-control" placeholder="e.g., Gift Wrap">
</div>
<div class="col-md-3">
<label class="form-label" for="discount_0">Apply Discount</label>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="1" id="discount_checkbox_0" name="apply_discount[]">
<label class="form-check-label" for="discount_checkbox_0">
Yes
</label>
</div>
<div id="discount_fields_0" style="display: none; margin-top: 10px;">
<label class="form-label" for="discount_percentage_0">Discount Percentage (%) <span class="text-danger">*</span></label>
<input type="number" name="discount_percentage[]" id="discount_percentage_0" class="form-control" min="0" max="100" step="0.01" placeholder="Enter discount percentage">
<label class="form-label mt-2" for="discount_reason_0">Discount Reason <span class="text-danger">*</span></label>
<input type="text" name="discount_reason[]" id="discount_reason_0" class="form-control" placeholder="Enter reason for discount">
</div>
</div>
<div class="col-md-12 d-flex justify-content-end mt-3">
<button type="button" class="remove-product-button btn btn-danger btn-sm" onclick="removeProductRow(this)"><i class="bi bi-trash-fill"></i> Remove</button>
</div>
</div>
</div>
<?php
}
?>
</div>
<button type="button" class="add-product-button btn btn-secondary" onclick="addProductRow()"><i class="bi bi-plus-circle-fill"></i> Add Another Product</button>
<!-- Delivery DateTime Field -->
<hr>
<div class="form-section">
<h5>Delivery Details</h5>
<label class="form-label" for="delivery_datetime">Delivery Date and Time</label>
<input type="datetime-local" id="delivery_datetime" name="delivery_datetime" class="form-control"
value="<?= isset($_POST['delivery_datetime']) ? htmlspecialchars($_POST['delivery_datetime']) : '' ?>">
</div>
</div>
<!-- Submit Button -->
<button type="submit" class="submit-button btn btn-primary"><i class="bi bi-plus-lg"></i> Add Order</button>
</form>
</div>
<!-- Footer -->
<div class="footer">
© 2024 Kaak Alia Bakery. All rights reserved.
</div>
</main>
<!-- 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>
<!-- Flatpickr Initialization -->
<script>
flatpickr("#delivery_datetime", {
enableTime: true,
dateFormat: "Y-m-d\\TH:i",
minDate: "today"
});
</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>
Use a spacious layout with well-defined sections and ample padding around elements to create an airy, modern feel.
Apply soft shadows on containers to add depth, separating each section visually without overwhelming the interface.
Use a combination of Poppins and Roboto fonts for a contemporary look. Title and section headings should be bold and larger, while labels and descriptions use regular weights for clarity.
Dashboard Title & Subtitle:
Center-align the title, "Kaak Alia Dashboard," in a bold, large font with a thin accent underline in the brand's accent color (#D1C287) to give it a refined touch.
Directly below the title, add a subtitle in a smaller font, with the message: “Effortlessly manage your bakery’s orders, products, and reports.”
Statistic Cards (Total Orders, Pending Orders, etc.):
Each card has a rounded rectangular shape with a subtle shadow for depth.
Include an icon on the left side of each card, encased in a circle, using a lighter background color for distinction.
The main metric number (e.g., "2" for Total Orders) is in a large, bold font for emphasis. Below it, use a smaller, regular font for the label (e.g., "Total Orders").
On hover, the card subtly scales up slightly and the background gradient intensifies to create an interactive effect.
Action Buttons (Add New Order, View Orders, etc.):
Use vibrant button colors, keeping them consistent with the color scheme, and increase the border radius for a soft, pill-shaped look.
Place an icon on the left side of each button, corresponding to its function (e.g., a plus sign for "Add New Order").
Apply hover effects: buttons slightly change in color intensity and scale up slightly to enhance interactivity.
Ensure the buttons are of equal size and neatly aligned in a single row, adding balance and symmetry.
Recent Orders Table:
Display recent orders in a clean, organized table with alternate row colors (e.g., white and light grey) to improve readability.
Add subtle padding to each cell to create breathing space around the text.
Use a soft border around the table to define its boundaries gently.
In the “Status” column, use colored badges with rounded edges and a slight shadow for a modern badge look (e.g., a yellow badge with “Pending” in bold white text).
Display "View All Orders" as a subtle link below the table, with an underline that appears on hover.
Footer Text:
Display © 2024 Kaak Alia. All rights reserved. centered below the table in a small, light-grey font, unobtrusive yet visible.
Overall, the dashboard should be a welcoming, intuitive space where key metrics and functions are immediately accessible. It should feel professional yet friendly, with small visual flourishes (like hover animations) that create a modern, polished user experience. and type full codes
Certainly! Below is the complete PHP code for a modern, user-friendly dashboard tailored for the Kaak Alia Bakery Management System. This dashboard adheres to your design specifications, maintaining a consistent color scheme with shades of purple, yellow, blue, green, and red. It emphasizes a clean and sophisticated aesthetic, ensuring readability and ease of use.
Key Features Implemented:
Overall Layout:
Spacious layout with well-defined sections and ample padding for an airy feel.
Soft shadows on containers to add depth and visual separation.
Utilizes Poppins for titles and headings, and Roboto for labels and descriptions.
Dashboard Title & Subtitle:
Center-aligned title "Kaak Alia Dashboard" with a thin accent underline in the brand's accent color (#D1C287).
Subtitle directly below the title conveying the purpose of the dashboard.
Statistic Cards:
Rounded rectangular cards with subtle shadows.
Icons on the left side within circles using lighter background colors.
Prominent metric numbers with labels below.
Interactive hover effects with slight scaling and intensified background gradients.
Action Buttons:
Vibrant, pill-shaped buttons with corresponding icons.
Consistent sizing and alignment in a single row.
Hover effects that enhance interactivity with color intensity changes and slight scaling.
Recent Orders Table:
Clean and organized table with alternate row colors for better readability.
Subtle padding and soft borders.
Colored badges in the “Status” column for modern look.
"View All Orders" link below the table with an underline on hover.
Footer:
Centered footer text with © 2024 Kaak Alia. All rights reserved.
Styled in a small, light-grey font to be unobtrusive yet visible.
Complete dashboard.php Code:
<?php
// public/dashboard.php
// Enable error reporting for debugging (disable in production)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Start output buffering to prevent "headers already sent" errors
ob_start();
// Include authentication, database connection, and functions
require_once __DIR__ . '/../../includes/auth.php';
require_once __DIR__ . '/../../includes/db_connect.php';
require_once __DIR__ . '/../../includes/functions.php';
// Fetch statistics
$total_orders = 0;
$pending_orders = 0;
$in_progress_orders = 0;
$completed_orders = 0;
$delivered_orders = 0;
// Total Orders
$total_orders_sql = "SELECT COUNT(*) as total FROM orders";
$total_orders_result = $conn->query($total_orders_sql);
if ($total_orders_result) {
$total_orders = $total_orders_result->fetch_assoc()['total'];
}
// Pending Orders
$pending_orders_sql = "SELECT COUNT(*) as total FROM orders WHERE status = 'Pending'";
$pending_orders_result = $conn->query($pending_orders_sql);
if ($pending_orders_result) {
$pending_orders = $pending_orders_result->fetch_assoc()['total'];
}
// In-Progress Orders
$in_progress_orders_sql = "SELECT COUNT(*) as total FROM orders WHERE status = 'In Progress'";
$in_progress_orders_result = $conn->query($in_progress_orders_sql);
if ($in_progress_orders_result) {
$in_progress_orders = $in_progress_orders_result->fetch_assoc()['total'];
}
// Completed Orders
$completed_orders_sql = "SELECT COUNT(*) as total FROM orders WHERE status = 'Completed'";
$completed_orders_result = $conn->query($completed_orders_sql);
if ($completed_orders_result) {
$completed_orders = $completed_orders_result->fetch_assoc()['total'];
}
// Delivered Orders
$delivered_orders_sql = "SELECT COUNT(*) as total FROM orders WHERE status = 'Delivered'";
$delivered_orders_result = $conn->query($delivered_orders_sql);
if ($delivered_orders_result) {
$delivered_orders = $delivered_orders_result->fetch_assoc()['total'];
}
// Fetch recent orders (latest 5)
$recent_orders_sql = "
SELECT orders.id, customers.name, orders.status, orders.created_at
FROM orders
JOIN customers ON orders.customer_id = customers.id
ORDER BY orders.created_at DESC
LIMIT 5
";
$recent_orders_result = $conn->query($recent_orders_sql);
$recent_orders = [];
if ($recent_orders_result) {
while ($row = $recent_orders_result->fetch_assoc()) {
$recent_orders[] = $row;
}
}
// Now include the header AFTER data fetching
require_once '../../includes/header.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dashboard - Kaak Alia Management System</title>
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&family=Roboto:wght@400;500;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">
<!-- Custom Styles -->
<style>
/* ---------------------------------------------------
1. CSS Variables for Consistent Design
---------------------------------------------------- */
:root {
/* Primary Colors */
--background-color: #FFFFFF; /* Crisp White */
--light-grey: #F5F5F5;
--medium-grey: #CCCCCC;
--dark-grey: #333333;
--charcoal: #4A4A4A;
/* Accent Colors */
--accent-blue: #4A90E2;
--accent-green: #50C878;
--accent-red: #FF6B6B;
--accent-teal: #374151;
--accent-soft-blue: #A3D2CA;
--accent-purple: #8A65FF;
--accent-orange: #FFA500;
--accent-yellow: #FFD166; /* Added for badge colors */
/* Text Colors */
--primary-text: var(--dark-grey);
--secondary-text: #666666;
/* UI Elements */
--input-border: var(--medium-grey);
--input-focus-border: var(--accent-teal);
--box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
--box-border-radius: 12px;
--hover-shadow: rgba(0, 0, 0, 0.1);
/* Button Colors */
--button-add-order: #6C63FF;
--button-view-orders: #FFA500;
--button-manage-products: #20B2AA;
--button-manage-users: #4B0082;
--button-generate-reports: #FF6B6B;
/* Status Badge Colors */
--badge-pending: #FFD166;
--badge-in-progress: #6A4C93;
--badge-completed: #4CAF50;
--badge-delivered: #20B2AA;
}
/* ---------------------------------------------------
2. Global Styles
---------------------------------------------------- */
body {
font-family: 'Roboto', sans-serif;
background-color: var(--light-grey);
margin: 0;
padding: 0;
color: var(--primary-text);
}
.container-body {
max-width: 1200px;
margin: 40px auto;
padding: 40px 20px;
box-sizing: border-box;
background-color: var(--background-color);
box-shadow: var(--box-shadow);
border-radius: var(--box-border-radius);
font-family: 'Roboto', sans-serif;
transition: all 0.3s ease;
}
/* ---------------------------------------------------
3. Header Styles
---------------------------------------------------- */
.header-dashboard {
text-align: center;
margin-bottom: 40px;
font-family: 'Poppins', sans-serif;
}
.header-dashboard h1 {
color: var(--charcoal);
font-size: 36px;
font-weight: 700;
position: relative;
display: inline-block;
}
/* Decorative Line Under Header */
.header-dashboard h1::after {
content: "";
display: block;
width: 80px;
height: 4px;
background-color: #D1C287;
margin: 8px auto 0;
border-radius: 2px;
}
.header-dashboard p {
color: var(--secondary-text);
font-size: 18px;
margin-top: 10px;
font-weight: 400;
}
/* ---------------------------------------------------
4. Statistic Cards
---------------------------------------------------- */
.stats-cards {
display: flex;
flex-wrap: wrap;
gap: 20px;
margin-bottom: 40px;
}
.stat-card {
flex: 1 1 calc(20% - 20px);
background: linear-gradient(135deg, var(--accent-teal), var(--accent-soft-blue));
color: #ffffff;
padding: 20px;
border-radius: var(--box-border-radius);
display: flex;
align-items: center;
box-shadow: var(--box-shadow);
transition: transform 0.3s, background 0.3s;
cursor: pointer;
}
.stat-card:hover {
transform: scale(1.05);
background: linear-gradient(135deg, var(--accent-teal) 70%, var(--accent-soft-blue) 100%);
box-shadow: 0 4px 12px var(--hover-shadow);
}
.stat-card .icon {
flex-shrink: 0;
background-color: rgba(255, 255, 255, 0.2);
border-radius: 50%;
width: 50px;
height: 50px;
display: flex;
align-items: center;
justify-content: center;
margin-right: 15px;
font-size: 24px;
}
.stat-card .details {
flex-grow: 1;
}
.stat-card .details .number {
font-size: 24px;
font-weight: 700;
}
.stat-card .details .label {
font-size: 14px;
font-weight: 400;
text-transform: uppercase;
letter-spacing: 1px;
}
/* ---------------------------------------------------
5. Action Buttons
---------------------------------------------------- */
.action-buttons {
display: flex;
flex-wrap: wrap;
gap: 15px;
justify-content: center;
margin-bottom: 40px;
}
.action-button {
display: flex;
align-items: center;
gap: 10px;
padding: 15px 25px;
border: none;
border-radius: 50px;
font-size: 16px;
font-family: 'Poppins', sans-serif;
font-weight: 600;
color: #ffffff;
cursor: pointer;
transition: background-color 0.3s, transform 0.3s;
box-shadow: var(--box-shadow);
}
.action-button i {
font-size: 20px;
}
.btn-add-order {
background-color: var(--button-add-order);
}
.btn-add-order:hover {
background-color: #574b90;
transform: scale(1.05);
}
.btn-view-orders {
background-color: var(--button-view-orders);
}
.btn-view-orders:hover {
background-color: #e69500;
transform: scale(1.05);
}
.btn-manage-products {
background-color: var(--button-manage-products);
}
.btn-manage-products:hover {
background-color: #178d78;
transform: scale(1.05);
}
.btn-manage-users {
background-color: var(--button-manage-users);
}
.btn-manage-users:hover {
background-color: #3e006f;
transform: scale(1.05);
}
.btn-generate-reports {
background-color: var(--button-generate-reports);
}
.btn-generate-reports:hover {
background-color: #e63239;
transform: scale(1.05);
}
/* ---------------------------------------------------
6. Recent Orders Table
---------------------------------------------------- */
.recent-orders {
margin-bottom: 40px;
}
.recent-orders h3 {
margin-bottom: 20px;
font-family: 'Poppins', sans-serif;
font-weight: 600;
font-size: 24px;
color: var(--primary-text);
}
.recent-orders table {
width: 100%;
border-collapse: collapse;
background-color: #ffffff;
border-radius: var(--box-border-radius);
overflow: hidden;
box-shadow: var(--box-shadow);
}
.recent-orders th, .recent-orders td {
padding: 15px;
text-align: left;
font-family: 'Roboto', sans-serif;
font-size: 14px;
}
.recent-orders th {
background-color: var(--accent-soft-blue);
color: var(--primary-text);
font-weight: 600;
}
.recent-orders tr:nth-child(even) {
background-color: #f9f9f9;
}
.recent-orders tr:hover {
background-color: #f1f1f1;
}
.badge-status {
padding: 5px 10px;
border-radius: 12px;
color: #ffffff;
font-weight: 600;
font-size: 12px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.badge-pending {
background-color: var(--badge-pending);
}
.badge-in-progress {
background-color: var(--badge-in-progress);
}
.badge-completed {
background-color: var(--badge-completed);
}
.badge-delivered {
background-color: var(--badge-delivered);
}
.view-all-orders {
display: block;
text-align: right;
margin-top: 10px;
font-size: 14px;
color: var(--accent-teal);
text-decoration: none;
font-weight: 500;
transition: text-decoration 0.3s, color 0.3s;
}
.view-all-orders:hover {
text-decoration: underline;
color: var(--accent-soft-blue);
}
/* ---------------------------------------------------
7. Footer Styles
---------------------------------------------------- */
.footer {
background-color: var(--background-color);
color: var(--secondary-text);
padding: 20px;
text-align: center;
border-radius: var(--box-border-radius);
font-size: 14px;
line-height: 22px;
font-family: 'Roboto', sans-serif;
box-shadow: var(--box-shadow);
}
/* ---------------------------------------------------
8. Responsive Design Enhancements
---------------------------------------------------- */
@media (max-width: 992px) {
.stat-card {
flex: 1 1 calc(45% - 20px);
}
}
@media (max-width: 768px) {
.stat-card {
flex: 1 1 100%;
}
.action-buttons {
flex-direction: column;
align-items: center;
}
.action-button {
width: 100%;
justify-content: center;
}
.recent-orders table, .recent-orders th, .recent-orders td {
font-size: 12px;
}
}
@media (max-width: 480px) {
.header-dashboard h1 {
font-size: 28px;
}
.header-dashboard p {
font-size: 16px;
}
.stat-card .details .number {
font-size: 20px;
}
.stat-card .details .label {
font-size: 12px;
}
.action-button {
padding: 12px 20px;
font-size: 14px;
}
.recent-orders h3 {
font-size: 20px;
}
.recent-orders th, .recent-orders td {
padding: 10px;
font-size: 12px;
}
}
</style>
</head>
<body>
<main class='container-body'>
<!-- Dashboard Header -->
<div class="header-dashboard">
<h1>Kaak Alia Dashboard</h1>
<p>Effortlessly manage your bakery’s orders, products, and reports.</p>
</div>
<!-- Statistic Cards -->
<div class="stats-cards">
<!-- Total Orders Card -->
<div class="stat-card">
<div class="icon">
<i class="bi bi-basket3-fill"></i>
</div>
<div class="details">
<div class="number"><?= htmlspecialchars($total_orders) ?></div>
<div class="label">Total Orders</div>
</div>
</div>
<!-- Pending Orders Card -->
<div class="stat-card">
<div class="icon">
<i class="bi bi-hourglass-split"></i>
</div>
<div class="details">
<div class="number"><?= htmlspecialchars($pending_orders) ?></div>
<div class="label">Pending Orders</div>
</div>
</div>
<!-- In-Progress Orders Card -->
<div class="stat-card">
<div class="icon">
<i class="bi bi-hourglass"></i>
</div>
<div class="details">
<div class="number"><?= htmlspecialchars($in_progress_orders) ?></div>
<div class="label">In Progress</div>
</div>
</div>
<!-- Completed Orders Card -->
<div class="stat-card">
<div class="icon">
<i class="bi bi-check-circle-fill"></i>
</div>
<div class="details">
<div class="number"><?= htmlspecialchars($completed_orders) ?></div>
<div class="label">Completed</div>
</div>
</div>
<!-- Delivered Orders Card -->
<div class="stat-card">
<div class="icon">
<i class="bi bi-truck-fill"></i>
</div>
<div class="details">
<div class="number"><?= htmlspecialchars($delivered_orders) ?></div>
<div class="label">Delivered</div>
</div>
</div>
</div>
<!-- Action Buttons -->
<div class="action-buttons">
<button class="action-button btn-add-order" onclick="window.location.href='add_order.php'">
<i class="bi bi-plus-lg"></i> Add New Order
</button>
<button class="action-button btn-view-orders" onclick="window.location.href='view_orders.php'">
<i class="bi bi-list-task"></i> View Orders
</button>
<button class="action-button btn-manage-products" onclick="window.location.href='manage_products.php'">
<i class="bi bi-box-seam-fill"></i> Manage Products
</button>
<button class="action-button btn-manage-users" onclick="window.location.href='manage_users.php'">
<i class="bi bi-people-fill"></i> Manage Users
</button>
<button class="action-button btn-generate-reports" onclick="window.location.href='generate_reports.php'">
<i class="bi bi-bar-chart-fill"></i> Generate Reports
</button>
</div>
<!-- Recent Orders Table -->
<div class="recent-orders">
<h3>Recent Orders</h3>
<table>
<thead>
<tr>
<th>Order ID</th>
<th>Customer Name</th>
<th>Date</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php if (!empty($recent_orders)): ?>
<?php foreach ($recent_orders as $order): ?>
<tr>
<td><?= htmlspecialchars($order['id']) ?></td>
<td><?= htmlspecialchars($order['name']) ?></td>
<td><?= htmlspecialchars(date("d M Y, h:i A", strtotime($order['created_at']))) ?></td>
<td>
<?php
$status = strtolower($order['status']);
$badge_class = '';
switch ($status) {
case 'pending':
$badge_class = 'badge-pending';
break;
case 'in progress':
$badge_class = 'badge-in-progress';
break;
case 'completed':
$badge_class = 'badge-completed';
break;
case 'delivered':
$badge_class = 'badge-delivered';
break;
default:
$badge_class = 'badge-secondary';
}
?>
<span class="badge-status <?= $badge_class ?>">
<?= htmlspecialchars($order['status']) ?>
</span>
</td>
<td>
<a href="view_order.php?id=<?= htmlspecialchars($order['id']) ?>" class="text-primary" title="View Order Details">
<i class="bi bi-eye-fill"></i>
</a>
</td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="5" class="text-center">No recent orders found.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
<a href="view_orders.php" class="view-all-orders">View All Orders</a>
</div>
<!-- Footer -->
<div class="footer">
© 2024 Kaak Alia. All rights reserved.
</div>
</main>
<!-- Bootstrap JS Bundle -->
<script src="/kaak_alia_management_system/assets/bootstrap/js/bootstrap.bundle.min.js"></script>
</body>
</html>
<?php
// Flush the output buffer
ob_end_flush();
// No closing PHP tag to prevent unwanted output
?>
Explanation of the Code:
PHP Data Fetching:
Statistics: The dashboard fetches various statistics from the orders table, such as total orders, pending orders, in-progress orders, completed orders, and delivered orders.
Recent Orders: Retrieves the latest 5 orders, joining with the customers table to get customer names.
Header Inclusion:
The header.php is included after data fetching to ensure that any necessary headers or authentication checks are in place.
HTML Structure:
Google Fonts: Links to Poppins and Roboto fonts.
Bootstrap & Icons: Utilizes Bootstrap for responsive design and Bootstrap Icons for visual elements.
Custom Styles: Embedded CSS defines the aesthetic, adhering to the color scheme and design specifications provided.
Dashboard Sections:
Header: Displays the dashboard title and subtitle with a decorative underline.
Statistic Cards: Five cards display key metrics with icons. Each card has interactive hover effects.
Action Buttons: Five buttons allow navigation to different sections like adding orders, viewing orders, managing products/users, and generating reports. Each button has an icon and hover effects.
Recent Orders Table: Shows the latest five orders with details like Order ID, Customer Name, Date, Status (with colored badges), and an action icon to view details. A link is provided to view all orders.
Footer: Displays a centered footer with © 2024 Kaak Alia.
Responsive Design:
The dashboard is fully responsive, adjusting the layout for tablets and mobile devices to maintain usability and readability.
Interactivity:
Hover effects on statistic cards and action buttons enhance user experience by providing visual feedback.
The "View Order Details" icon in the recent orders table links to a detailed view of each order.
Additional Recommendations:
Security:
Ensure that all links and actions are protected and validated to prevent unauthorized access.
Implement proper sanitization and validation in the included functions.php and other included files.
Performance:
Optimize database queries, especially as the number of orders grows.
Implement caching strategies if necessary to reduce database load.
Accessibility:
Ensure that all interactive elements are accessible via keyboard navigation.
Provide aria-labels where necessary for screen readers.
Modularity:
For larger projects, consider separating CSS into external files for better maintainability.
Utilize templating engines like Twig or Blade for cleaner separation of PHP and HTML.
Error Handling:
Implement comprehensive error handling to gracefully manage potential issues, such as database connection failures.
This dashboard provides a comprehensive and modern interface for managing bakery operations, ensuring that key metrics and functionalities are readily accessible and visually appealing.
Copy first response
Not yet included in a published release.
a
dd
r
es
s ′
])
;
d
a
t
e
t
im
e ′
])
:
n u l l ;
′
])?
s
ani
t
i
z
e i
n
p
u
t
(