From 3d24190863e56aefc96528cae62833fab1e7c4bd Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sun, 22 Feb 2026 11:09:10 +0000 Subject: [PATCH] Autosave: 20260222-110909 --- admin/area_edit.php | 74 ++++ admin/areas.php | 5 +- admin/categories.php | 65 ++-- admin/category_edit.php | 150 ++++++++ admin/company.php | 114 +++++- admin/customer_edit.php | 81 ++++ admin/customers.php | 121 ++++++ admin/includes/header.php | 49 ++- admin/index.php | 5 +- admin/orders.php | 21 +- admin/supplier_edit.php | 93 +++++ admin/suppliers.php | 136 +++++++ admin/table_edit.php | 80 ++++ admin/tables.php | 5 +- api/order.php | 71 +++- api/search_customers.php | 23 ++ api/tables.php | 39 ++ .../images/categories/cat_699ad97b80a9f.jpg | Bin 0 -> 32355 bytes .../images/categories/cat_699ad9936c7f7.jpeg | Bin 0 -> 4568 bytes .../images/categories/cat_699ad9aca9529.jpeg | Bin 0 -> 5121 bytes .../images/categories/cat_699ad9c24cfdf.jpeg | Bin 0 -> 17410 bytes .../images/company/favicon_699ada16cc653.png | Bin 0 -> 7750 bytes assets/images/company/logo_699ada16cc482.png | Bin 0 -> 90545 bytes assets/js/main.js | 359 +++++++++++++++--- index.php | 224 ++++++++--- 25 files changed, 1529 insertions(+), 186 deletions(-) create mode 100644 admin/area_edit.php create mode 100644 admin/category_edit.php create mode 100644 admin/customer_edit.php create mode 100644 admin/customers.php create mode 100644 admin/supplier_edit.php create mode 100644 admin/suppliers.php create mode 100644 admin/table_edit.php create mode 100644 api/search_customers.php create mode 100644 api/tables.php create mode 100644 assets/images/categories/cat_699ad97b80a9f.jpg create mode 100644 assets/images/categories/cat_699ad9936c7f7.jpeg create mode 100644 assets/images/categories/cat_699ad9aca9529.jpeg create mode 100644 assets/images/categories/cat_699ad9c24cfdf.jpeg create mode 100644 assets/images/company/favicon_699ada16cc653.png create mode 100644 assets/images/company/logo_699ada16cc482.png 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'; +?> + +
+

Edit Area

+ + Back + +
+ +
+
+
+
+ + +
+ +
+ + +
+ +
+ Cancel + +
+
+
+
+ + 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'; - + + @@ -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

- +
@@ -34,49 +27,45 @@ include 'includes/header.php'; ID + Image Name - Actions + Sort Order + Actions # - + + <?= htmlspecialchars($cat['name']) ?> + +
+ +
+ + + + + + + + + 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'; +?> + +
+ Back to Categories +

+
+ + + +
+
+
+
+
+
+ + +
+
+ + +
Lower numbers appear first. Default is 0.
+
+
+
+
+ + +
+ Category Image +
+ +
+
No Image +
+ + + +
Allowed: JPG, PNG, GIF, WEBP. Leave empty to keep current.
+
+
+
+
+
+ Cancel + +
+
+
+
+ + \ 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';
-
+
@@ -74,6 +113,19 @@ include 'includes/header.php';
+
+
Legal & Tax Information
+
+
+ + +
+
+ + +
+
+
Financial Settings
@@ -95,6 +147,36 @@ include 'includes/header.php';
+
+
Branding
+
+
+ +
+ +
+ Logo +
+ + +
+
Recommended: PNG or SVG with transparent background.
+
+ +
+ +
+ +
+ Favicon +
+ + +
+
Recommended: 32x32 ICO or PNG.
+
+
+
- + \ 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'; +?> + +
+ Back to Customers +

Edit Customer:

+
+ + + +
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ Cancel + +
+ +
+
+ + \ 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

+ +
+ + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
NameEmailPhoneAddressActions
... +
+ + +
+
No customers found.
+
+
+
+ + + + + \ 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) {