diff --git a/admin/area_edit.php b/admin/area_edit.php
new file mode 100644
index 0000000..fd089f9
--- /dev/null
+++ b/admin/area_edit.php
@@ -0,0 +1,74 @@
+prepare("UPDATE areas SET name = ?, outlet_id = ? WHERE id = ?");
+ $stmt->execute([$name, $outlet_id, $id]);
+ header('Location: areas.php');
+ exit;
+ }
+}
+
+// Fetch Area Details
+$stmt = $pdo->prepare("SELECT * FROM areas WHERE id = ?");
+$stmt->execute([$id]);
+$area = $stmt->fetch();
+
+if (!$area) {
+ die("Area not found.");
+}
+
+// Fetch Outlets for Dropdown
+$outlets = $pdo->query("SELECT id, name FROM outlets ORDER BY name ASC")->fetchAll();
+
+include 'includes/header.php';
+?>
+
+
+
+
+
+
diff --git a/admin/areas.php b/admin/areas.php
index 5147ecf..688a9e1 100644
--- a/admin/areas.php
+++ b/admin/areas.php
@@ -55,7 +55,8 @@ include 'includes/header.php';
= htmlspecialchars($area['name']) ?>
= htmlspecialchars($area['outlet_name'] ?? 'N/A') ?>
-
+
+
@@ -104,4 +105,4 @@ include 'includes/header.php';
-
+
\ No newline at end of file
diff --git a/admin/categories.php b/admin/categories.php
index 6f24f7d..32ccebe 100644
--- a/admin/categories.php
+++ b/admin/categories.php
@@ -2,29 +2,22 @@
require_once __DIR__ . '/../db/config.php';
$pdo = db();
-if (isset($_POST['action']) && $_POST['action'] === 'add_category') {
- $stmt = $pdo->prepare("INSERT INTO categories (name) VALUES (?)");
- $stmt->execute([$_POST['name']]);
- header("Location: categories.php");
- exit;
-}
-
if (isset($_GET['delete'])) {
$pdo->prepare("DELETE FROM categories WHERE id = ?")->execute([$_GET['delete']]);
header("Location: categories.php");
exit;
}
-$categories = $pdo->query("SELECT * FROM categories ORDER BY sort_order")->fetchAll();
+$categories = $pdo->query("SELECT * FROM categories ORDER BY sort_order ASC, name ASC")->fetchAll();
include 'includes/header.php';
?>
Categories
-
+
Add Category
-
+
@@ -34,49 +27,45 @@ include 'includes/header.php';
ID
+ Image
Name
- Actions
+ Sort Order
+ Actions
#= $cat['id'] ?>
- = htmlspecialchars($cat['name']) ?>
+
+
+
+
+
+
+
+
+ = htmlspecialchars($cat['name']) ?>
+ = $cat['sort_order'] ?>
+
+
+
+
+ No categories found.
+
+
-
-
-
-
+
\ No newline at end of file
diff --git a/admin/category_edit.php b/admin/category_edit.php
new file mode 100644
index 0000000..c335d25
--- /dev/null
+++ b/admin/category_edit.php
@@ -0,0 +1,150 @@
+prepare("SELECT * FROM categories WHERE id = ?");
+ $stmt->execute([$id]);
+ $category = $stmt->fetch();
+ if ($category) {
+ $isEdit = true;
+ } else {
+ // ID not found, redirect to list
+ header("Location: categories.php");
+ exit;
+ }
+}
+
+// Handle Form Submission
+if ($_SERVER['REQUEST_METHOD'] === 'POST') {
+ $name = trim($_POST['name']);
+ $sort_order = (int)$_POST['sort_order'];
+ $image_url = $isEdit ? $category['image_url'] : null;
+
+ // Basic Validation
+ if (empty($name)) {
+ $message = 'Category name is required.
';
+ } else {
+ // Image Upload Handling
+ if (isset($_FILES['image']) && $_FILES['image']['error'] === UPLOAD_ERR_OK) {
+ $uploadDir = __DIR__ . '/../assets/images/categories/';
+ if (!is_dir($uploadDir)) {
+ mkdir($uploadDir, 0755, true);
+ }
+
+ $fileInfo = pathinfo($_FILES['image']['name']);
+ $fileExt = strtolower($fileInfo['extension']);
+ $allowedExts = ['jpg', 'jpeg', 'png', 'gif', 'webp'];
+
+ if (in_array($fileExt, $allowedExts)) {
+ $fileName = uniqid('cat_') . '.' . $fileExt;
+ $targetFile = $uploadDir . $fileName;
+
+ if (move_uploaded_file($_FILES['image']['tmp_name'], $targetFile)) {
+ // Remove old image if exists and not default placeholder (optional, strict cleanup)
+ if ($isEdit && !empty($category['image_url']) && file_exists(__DIR__ . '/../' . $category['image_url'])) {
+ // unlink(__DIR__ . '/../' . $category['image_url']); // Uncomment to auto-delete old images
+ }
+ $image_url = 'assets/images/categories/' . $fileName;
+ } else {
+ $message = 'Failed to upload image. Check permissions.
';
+ }
+ } else {
+ $message = 'Invalid file type. Allowed: jpg, png, gif, webp.
';
+ }
+ }
+
+ if (empty($message)) {
+ try {
+ if ($isEdit) {
+ $stmt = $pdo->prepare("UPDATE categories SET name = ?, sort_order = ?, image_url = ? WHERE id = ?");
+ $stmt->execute([$name, $sort_order, $image_url, $id]);
+ $message = 'Category updated successfully!
';
+ // Refresh data
+ $stmt = $pdo->prepare("SELECT * FROM categories WHERE id = ?");
+ $stmt->execute([$id]);
+ $category = $stmt->fetch();
+ } else {
+ $stmt = $pdo->prepare("INSERT INTO categories (name, sort_order, image_url) VALUES (?, ?, ?)");
+ $stmt->execute([$name, $sort_order, $image_url]);
+ header("Location: categories.php?success=created");
+ exit;
+ }
+ } catch (PDOException $e) {
+ $message = 'Database error: ' . $e->getMessage() . '
';
+ }
+ }
+ }
+}
+
+// Defaults for Add Mode or Error State
+if (!$isEdit) {
+ $category = [
+ 'name' => $_POST['name'] ?? '',
+ 'sort_order' => $_POST['sort_order'] ?? 0,
+ 'image_url' => ''
+ ];
+}
+
+include 'includes/header.php';
+?>
+
+
+
+= $message ?>
+
+
+
+
\ No newline at end of file
diff --git a/admin/company.php b/admin/company.php
index b11ba27..6f152f9 100644
--- a/admin/company.php
+++ b/admin/company.php
@@ -14,30 +14,69 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$vat_rate = $_POST['vat_rate'] ?? 0;
$currency_symbol = $_POST['currency_symbol'] ?? '$';
$currency_decimals = $_POST['currency_decimals'] ?? 2;
+ $ctr_number = $_POST['ctr_number'] ?? '';
+ $vat_number = $_POST['vat_number'] ?? '';
+
+ // Handle File Uploads
+ $uploadDir = __DIR__ . '/../assets/images/company/';
+ if (!is_dir($uploadDir)) {
+ mkdir($uploadDir, 0755, true);
+ }
+
+ $logo_url = $settings['logo_url'] ?? null;
+ $favicon_url = $settings['favicon_url'] ?? null;
+
+ // Logo Upload
+ if (isset($_FILES['logo']) && $_FILES['logo']['error'] === UPLOAD_ERR_OK) {
+ $fileInfo = pathinfo($_FILES['logo']['name']);
+ $fileExt = strtolower($fileInfo['extension']);
+ $allowedExts = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg'];
+
+ if (in_array($fileExt, $allowedExts)) {
+ $fileName = 'logo_' . uniqid() . '.' . $fileExt;
+ $targetFile = $uploadDir . $fileName;
+ if (move_uploaded_file($_FILES['logo']['tmp_name'], $targetFile)) {
+ $logo_url = 'assets/images/company/' . $fileName;
+ }
+ }
+ }
+
+ // Favicon Upload
+ if (isset($_FILES['favicon']) && $_FILES['favicon']['error'] === UPLOAD_ERR_OK) {
+ $fileInfo = pathinfo($_FILES['favicon']['name']);
+ $fileExt = strtolower($fileInfo['extension']);
+ $allowedExts = ['ico', 'png', 'svg']; // Favicons are usually ico/png/svg
+
+ if (in_array($fileExt, $allowedExts)) {
+ $fileName = 'favicon_' . uniqid() . '.' . $fileExt;
+ $targetFile = $uploadDir . $fileName;
+ if (move_uploaded_file($_FILES['favicon']['tmp_name'], $targetFile)) {
+ $favicon_url = 'assets/images/company/' . $fileName;
+ }
+ }
+ }
try {
- // Check if row exists (it should, from our functions.php logic or migration)
+ // Check if row exists
$exists = $pdo->query("SELECT COUNT(*) FROM company_settings")->fetchColumn();
if ($exists) {
- $stmt = $pdo->prepare("UPDATE company_settings SET company_name=?, address=?, phone=?, email=?, vat_rate=?, currency_symbol=?, currency_decimals=?, updated_at=NOW()");
- $stmt->execute([$company_name, $address, $phone, $email, $vat_rate, $currency_symbol, $currency_decimals]);
+ $stmt = $pdo->prepare("UPDATE company_settings SET company_name=?, address=?, phone=?, email=?, vat_rate=?, currency_symbol=?, currency_decimals=?, ctr_number=?, vat_number=?, logo_url=?, favicon_url=?, updated_at=NOW()");
+ $stmt->execute([$company_name, $address, $phone, $email, $vat_rate, $currency_symbol, $currency_decimals, $ctr_number, $vat_number, $logo_url, $favicon_url]);
} else {
- $stmt = $pdo->prepare("INSERT INTO company_settings (company_name, address, phone, email, vat_rate, currency_symbol, currency_decimals) VALUES (?, ?, ?, ?, ?, ?, ?)");
- $stmt->execute([$company_name, $address, $phone, $email, $vat_rate, $currency_symbol, $currency_decimals]);
+ $stmt = $pdo->prepare("INSERT INTO company_settings (company_name, address, phone, email, vat_rate, currency_symbol, currency_decimals, ctr_number, vat_number, logo_url, favicon_url) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
+ $stmt->execute([$company_name, $address, $phone, $email, $vat_rate, $currency_symbol, $currency_decimals, $ctr_number, $vat_number, $logo_url, $favicon_url]);
}
$message = 'Company settings updated successfully!
';
// Refresh settings
- $settings = [
- 'company_name' => $company_name,
- 'address' => $address,
- 'phone' => $phone,
- 'email' => $email,
- 'vat_rate' => $vat_rate,
- 'currency_symbol' => $currency_symbol,
- 'currency_decimals' => $currency_decimals
- ];
+ $settings = get_company_settings(); // Re-fetch to get updated values
+ // Manually update immediate values for display if fetch is cached/laggy (though re-fetch is better)
+ $settings['ctr_number'] = $ctr_number;
+ $settings['vat_number'] = $vat_number;
+ $settings['logo_url'] = $logo_url;
+ $settings['favicon_url'] = $favicon_url;
+
} catch (Exception $e) {
$message = 'Error updating settings: ' . htmlspecialchars($e->getMessage()) . '
';
}
@@ -54,7 +93,7 @@ include 'includes/header.php';
+
+ Branding
+
+
+
Company Logo
+
+
+
+
+
+
+
+
+
Recommended: PNG or SVG with transparent background.
+
+
+
+
Favicon
+
+
+
+
+
+
+
+
+
Recommended: 32x32 ICO or PNG.
+
+
+
Save Changes
@@ -104,4 +186,4 @@ include 'includes/header.php';
-
+
\ No newline at end of file
diff --git a/admin/customer_edit.php b/admin/customer_edit.php
new file mode 100644
index 0000000..428ba8c
--- /dev/null
+++ b/admin/customer_edit.php
@@ -0,0 +1,81 @@
+prepare("SELECT * FROM customers WHERE id = ?");
+$stmt->execute([$id]);
+$customer = $stmt->fetch();
+
+if (!$customer) {
+ header("Location: customers.php");
+ exit;
+}
+
+// Handle Update
+if ($_SERVER['REQUEST_METHOD'] === 'POST') {
+ $name = $_POST['name'];
+ $email = $_POST['email'];
+ $phone = $_POST['phone'];
+ $address = $_POST['address'];
+
+ $stmt = $pdo->prepare("UPDATE customers SET name = ?, email = ?, phone = ?, address = ? WHERE id = ?");
+ if ($stmt->execute([$name, $email, $phone, $address, $id])) {
+ $message = 'Customer updated successfully!
';
+ // Refresh data
+ $stmt = $pdo->prepare("SELECT * FROM customers WHERE id = ?");
+ $stmt->execute([$id]);
+ $customer = $stmt->fetch();
+ } else {
+ $message = 'Error updating customer.
';
+ }
+}
+
+include 'includes/header.php';
+?>
+
+
+
+= $message ?>
+
+
+
+
\ No newline at end of file
diff --git a/admin/customers.php b/admin/customers.php
new file mode 100644
index 0000000..3ef17bd
--- /dev/null
+++ b/admin/customers.php
@@ -0,0 +1,121 @@
+prepare("INSERT INTO customers (name, email, phone, address) VALUES (?, ?, ?, ?)");
+ if ($stmt->execute([$name, $email, $phone, $address])) {
+ $message = 'Customer added successfully!
';
+ } else {
+ $message = 'Error adding customer.
';
+ }
+}
+
+// Handle Delete
+if (isset($_GET['delete'])) {
+ $id = $_GET['delete'];
+ $pdo->prepare("DELETE FROM customers WHERE id = ?")->execute([$id]);
+ header("Location: customers.php");
+ exit;
+}
+
+// Fetch Customers
+$customers = $pdo->query("SELECT * FROM customers ORDER BY id DESC")->fetchAll();
+
+include 'includes/header.php';
+?>
+
+
+
Customers
+
+ Add Customer
+
+
+
+= $message ?>
+
+
+
+
+
+
+
+ Name
+ Email
+ Phone
+ Address
+ Actions
+
+
+
+
+
+ = htmlspecialchars($customer['name']) ?>
+ = htmlspecialchars($customer['email']) ?>
+ = htmlspecialchars($customer['phone']) ?>
+ = htmlspecialchars(substr($customer['address'] ?? '', 0, 30)) ?>...
+
+
+
+
+
+
+
+ No customers found.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Name
+
+
+
+ Email
+
+
+
+ Phone
+
+
+
+ Address
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/admin/includes/header.php b/admin/includes/header.php
index afe63db..bde3348 100644
--- a/admin/includes/header.php
+++ b/admin/includes/header.php
@@ -1,8 +1,20 @@
- Foody Admin Panel
+ = htmlspecialchars($companyName) ?> Admin Panel
+
+
+
@@ -41,7 +56,13 @@ function isActive($page) {