From b26eab2ba0c0f51e8712a52af5fade6eb22135c9 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Tue, 24 Feb 2026 05:19:16 +0000 Subject: [PATCH] Autosave: 20260224-051916 --- admin/ad_edit.php | 164 --- admin/ads.php | 277 ++-- admin/area_edit.php | 74 -- admin/areas.php | 135 +- admin/backup.php | 215 ++++ admin/categories.php | 213 +++- admin/category_edit.php | 150 --- admin/customers.php | 233 ++-- admin/expense_categories.php | 143 ++- admin/expense_category_edit.php | 88 -- admin/includes/header.php | 16 +- admin/order_view.php | 41 +- admin/outlet_edit.php | 75 -- admin/outlets.php | 95 +- admin/payment_type_edit.php | 85 -- admin/payment_types.php | 262 ++-- admin/product_edit.php | 178 --- admin/products.php | 452 +++---- admin/purchases.php | 57 +- admin/ratings.php | 405 +++--- admin/suppliers.php | 160 +-- admin/table_edit.php | 83 -- admin/tables.php | 210 ++-- admin/user_edit.php | 311 ----- admin/user_group_edit.php | 47 +- admin/user_groups.php | 234 ++-- admin/users.php | 324 +++-- api/order.php | 15 +- assets/js/main.js | 62 +- db/migrations/026_backup_settings.sql | 2 + includes/functions.php | 58 + pos.php | 26 +- .../backups/backup_2026-02-24_05-08-06.sql | 1120 +++++++++++++++++ .../backups/backup_2026-02-24_05-11-43.sql | 1120 +++++++++++++++++ 34 files changed, 4604 insertions(+), 2526 deletions(-) delete mode 100644 admin/ad_edit.php delete mode 100644 admin/area_edit.php create mode 100644 admin/backup.php delete mode 100644 admin/category_edit.php delete mode 100644 admin/expense_category_edit.php delete mode 100644 admin/outlet_edit.php delete mode 100644 admin/payment_type_edit.php delete mode 100644 admin/product_edit.php delete mode 100644 admin/table_edit.php delete mode 100644 admin/user_edit.php create mode 100644 db/migrations/026_backup_settings.sql create mode 100644 storage/backups/backup_2026-02-24_05-08-06.sql create mode 100644 storage/backups/backup_2026-02-24_05-11-43.sql diff --git a/admin/ad_edit.php b/admin/ad_edit.php deleted file mode 100644 index 6bb518f..0000000 --- a/admin/ad_edit.php +++ /dev/null @@ -1,164 +0,0 @@ -prepare("SELECT * FROM ads_images WHERE id = ?"); - $stmt->execute([$id]); - $ad = $stmt->fetch(); - if ($ad) { - $isEdit = true; - } else { - header("Location: ads.php"); - exit; - } -} - -if ($_SERVER['REQUEST_METHOD'] === 'POST') { - $title = trim($_POST['title']); - $sort_order = (int)$_POST['sort_order']; - $is_active = isset($_POST['is_active']) ? 1 : 0; - $display_layout = $_POST['display_layout'] ?? 'both'; - $image_path = $isEdit ? $ad['image_path'] : null; - - if (isset($_FILES['image']) && $_FILES['image']['error'] === UPLOAD_ERR_OK) { - $uploadDir = __DIR__ . '/../assets/images/ads/'; - 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('ad_') . '.' . $fileExt; - $targetFile = $uploadDir . $fileName; - - if (move_uploaded_file($_FILES['image']['tmp_name'], $targetFile)) { - $image_path = 'assets/images/ads/' . $fileName; - } else { - $message = '
Failed to upload image.
'; - } - } else { - $message = '
Invalid file type. Allowed: jpg, png, gif, webp.
'; - } - } - - if (empty($image_path) && !$isEdit) { - $message = '
Image is required for new advertisements.
'; - } - - if (empty($message)) { - try { - if ($isEdit) { - $stmt = $pdo->prepare("UPDATE ads_images SET title = ?, sort_order = ?, is_active = ?, display_layout = ?, image_path = ? WHERE id = ?"); - $stmt->execute([$title, $sort_order, $is_active, $display_layout, $image_path, $id]); - header("Location: ads.php?success=updated"); - exit; - } else { - $stmt = $pdo->prepare("INSERT INTO ads_images (title, sort_order, is_active, display_layout, image_path) VALUES (?, ?, ?, ?, ?)"); - $stmt->execute([$title, $sort_order, $is_active, $display_layout, $image_path]); - header("Location: ads.php?success=created"); - exit; - } - } catch (PDOException $e) { - $message = '
Database error: ' . $e->getMessage() . '
'; - } - } -} - -if (!$isEdit) { - $ad = [ - 'title' => $_POST['title'] ?? '', - 'sort_order' => $_POST['sort_order'] ?? 0, - 'is_active' => 1, - 'display_layout' => 'both', - 'image_path' => '' - ]; -} - -include 'includes/header.php'; -?> - -
- Back to Ads Management -

-
- - - -
-
-
-
-
-
- - -
This will be shown as a caption on the image.
-
-
- - -
Lower numbers appear first in the slider.
-
- -
- -
- > - - - > - - - > - -
-
Choose where this advertisement should be visible.
-
- -
-
- > - -
-
-
-
-
- - -
- Ad Image -
- -
-
No Image Selected -
- - - > -
Recommended size: 1920x1080 (HD) or 16:9 aspect ratio.
-
-
-
-
-
- Cancel - -
-
-
-
- - \ No newline at end of file diff --git a/admin/ads.php b/admin/ads.php index 35c3641..895236c 100644 --- a/admin/ads.php +++ b/admin/ads.php @@ -1,82 +1,121 @@ exec("CREATE TABLE IF NOT EXISTS ads_images ( - id INT AUTO_INCREMENT PRIMARY KEY, - image_path VARCHAR(255) NOT NULL, - title VARCHAR(255) DEFAULT NULL, - sort_order INT DEFAULT 0, - is_active TINYINT(1) DEFAULT 1, - display_layout ENUM('both', 'split', 'fullscreen') DEFAULT 'both', - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP -)"); +// Handle Add/Edit Promo +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { + $action = $_POST['action']; + $title = trim($_POST['title']); + $sort_order = (int)$_POST['sort_order']; + $is_active = isset($_POST['is_active']) ? 1 : 0; + $display_layout = $_POST['display_layout'] ?? 'both'; + $id = isset($_POST['id']) ? (int)$_POST['id'] : null; -// Ensure display_layout column exists (for older installations) -$pdo->exec("ALTER TABLE ads_images ADD COLUMN IF NOT EXISTS display_layout ENUM('both', 'split', 'fullscreen') DEFAULT 'both' AFTER is_active"); - -if (isset($_GET['delete'])) { - if (!has_permission('ads_del')) { - $message = '
Access Denied: You do not have permission to delete advertisements.
'; - } else { - $id = $_GET['delete']; - - // Get image path to delete file + $image_path = null; + if ($id) { $stmt = $pdo->prepare("SELECT image_path FROM ads_images WHERE id = ?"); $stmt->execute([$id]); - $ad = $stmt->fetch(); - - if ($ad) { - $fullPath = __DIR__ . '/../' . $ad['image_path']; - if (file_exists($fullPath) && is_file($fullPath)) { - unlink($fullPath); + $image_path = $stmt->fetchColumn(); + } + + if (isset($_FILES['image']) && $_FILES['image']['error'] !== UPLOAD_ERR_NO_FILE) { + if ($_FILES['image']['error'] === UPLOAD_ERR_OK) { + $uploadDir = __DIR__ . '/../assets/images/ads/'; + if (!is_dir($uploadDir)) mkdir($uploadDir, 0755, true); + + $file_ext = strtolower(pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION)); + if (in_array($file_ext, ['jpg', 'jpeg', 'png', 'gif', 'webp'])) { + $new_file_name = uniqid('promo_') . '.' . $file_ext; + if (move_uploaded_file($_FILES['image']['tmp_name'], $uploadDir . $new_file_name)) { + $image_path = 'assets/images/ads/' . $new_file_name; + } else { + $message = '
Failed to move uploaded file.
'; + } + } else { + $message = '
Invalid file type.
'; } + } else { + $message = '
File upload error.
'; + } + } + + if (empty($image_path) && $action === 'add_promo' && empty($message)) { + $message = '
Image is required for new advertisements.
'; + } + + if (empty($message)) { + try { + if ($action === 'edit_promo' && $id) { + if (!has_permission('ads')) { + $message = '
Access Denied.
'; + } else { + $stmt = $pdo->prepare("UPDATE ads_images SET title = ?, sort_order = ?, is_active = ?, display_layout = ?, image_path = ? WHERE id = ?"); + $stmt->execute([$title, $sort_order, $is_active, $display_layout, $image_path, $id]); + $message = '
Advertisement updated successfully!
'; + } + } elseif ($action === 'add_promo') { + if (!has_permission('ads')) { + $message = '
Access Denied.
'; + } else { + $stmt = $pdo->prepare("INSERT INTO ads_images (title, sort_order, is_active, display_layout, image_path) VALUES (?, ?, ?, ?, ?)"); + $stmt->execute([$title, $sort_order, $is_active, $display_layout, $image_path]); + $message = '
Advertisement created successfully!
'; + } + } + } catch (PDOException $e) { + $message = '
Database error: ' . $e->getMessage() . '
'; + } + } +} + +if (isset($_GET['delete'])) { + if (!has_permission('ads')) { + $message = '
Access Denied.
'; + } else { + $id = $_GET['delete']; + $stmt = $pdo->prepare("SELECT image_path FROM ads_images WHERE id = ?"); + $stmt->execute([$id]); + $promo = $stmt->fetch(); + if ($promo) { + $fullPath = __DIR__ . '/../' . $promo['image_path']; + if (file_exists($fullPath) && is_file($fullPath)) unlink($fullPath); $pdo->prepare("DELETE FROM ads_images WHERE id = ?")->execute([$id]); } - header("Location: ads.php"); exit; } } $query = "SELECT * FROM ads_images ORDER BY sort_order ASC, created_at DESC"; -$ads_pagination = paginate_query($pdo, $query); -$ads = $ads_pagination['data']; +$promos_pagination = paginate_query($pdo, $query); +$promos = $promos_pagination['data']; include 'includes/header.php'; ?>
-

Advertisement Slider

-

Manage pictures for the public ads display page.

+

Advertisement Slider

+

Manage pictures for the public display page.

- - - Add Image - + +
-
- -
- These images will be displayed in a slider on the ads.php page. - You can now choose to show specific images in Split View or Fullscreen layout. -
-
- -
+
-
- +
+
Items List
+
@@ -91,66 +130,152 @@ include 'includes/header.php'; - + - + - - - - -
- + <?= htmlspecialchars($ad['title'] ?? '') ?> + width="120" height="70"> + +
No Image
+
-
- +
- + Active Inactive - - - - - - + + + Delete
- - No advertisement images found. Click "Add Image" to get started. -
- +
+ + + + + + + \ No newline at end of file diff --git a/admin/area_edit.php b/admin/area_edit.php deleted file mode 100644 index fd089f9..0000000 --- a/admin/area_edit.php +++ /dev/null @@ -1,74 +0,0 @@ -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 76cd92c..cce2a30 100644 --- a/admin/areas.php +++ b/admin/areas.php @@ -6,46 +6,68 @@ $pdo = db(); $message = ''; -if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'add_area') { - if (!has_permission('areas_add')) { - $message = '
Access Denied: You do not have permission to add areas.
'; +// Handle Add/Edit Area +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { + $action = $_POST['action']; + $name = trim($_POST['name']); + $outlet_id = (int)$_POST['outlet_id']; + $id = isset($_POST['id']) ? (int)$_POST['id'] : null; + + if (empty($name)) { + $message = '
Area name is required.
'; } else { - $stmt = $pdo->prepare("INSERT INTO areas (outlet_id, name) VALUES (?, ?)"); - $stmt->execute([$_POST['outlet_id'], $_POST['name']]); - header("Location: areas.php"); - exit; + try { + if ($action === 'edit_area' && $id) { + if (!has_permission('areas_add')) { + $message = '
Access Denied.
'; + } else { + $stmt = $pdo->prepare("UPDATE areas SET name = ?, outlet_id = ? WHERE id = ?"); + $stmt->execute([$name, $outlet_id, $id]); + $message = '
Area updated successfully!
'; + } + } elseif ($action === 'add_area') { + if (!has_permission('areas_add')) { + $message = '
Access Denied.
'; + } else { + $stmt = $pdo->prepare("INSERT INTO areas (name, outlet_id) VALUES (?, ?)"); + $stmt->execute([$name, $outlet_id]); + $message = '
Area created successfully!
'; + } + } + } catch (PDOException $e) { + $message = '
Database error: ' . $e->getMessage() . '
'; + } } } +// Handle Delete if (isset($_GET['delete'])) { if (!has_permission('areas_del')) { $message = '
Access Denied: You do not have permission to delete areas.
'; } else { - $pdo->prepare("DELETE FROM areas WHERE id = ?")->execute([$_GET['delete']]); + $id = $_GET['delete']; + $pdo->prepare("DELETE FROM areas WHERE id = ?")->execute([$id]); header("Location: areas.php"); exit; } } -// Fetch areas with outlet names -$query = "SELECT areas.*, outlets.name as outlet_name - FROM areas - LEFT JOIN outlets ON areas.outlet_id = outlets.id - ORDER BY areas.id DESC"; - +$outlets = $pdo->query("SELECT * FROM outlets ORDER BY name ASC")->fetchAll(); + +$query = "SELECT a.*, o.name as outlet_name + FROM areas a + LEFT JOIN outlets o ON a.outlet_id = o.id + ORDER BY a.id DESC"; $areas_pagination = paginate_query($pdo, $query); $areas = $areas_pagination['data']; -// Fetch outlets for dropdown -$outlets = $pdo->query("SELECT id, name FROM outlets ORDER BY name ASC")->fetchAll(); - include 'includes/header.php'; ?>

Areas

- @@ -66,7 +88,7 @@ include 'includes/header.php'; ID Name Outlet - Actions + Actions @@ -74,22 +96,23 @@ include 'includes/header.php'; # - - + + - + - + - - No areas found. Add one to get started. - + + No areas found. + @@ -101,28 +124,29 @@ include 'includes/header.php';
- + -