';
+}
+
$query = "SELECT * FROM ads_images ORDER BY sort_order ASC, created_at DESC";
$promos_pagination = paginate_query($pdo, $query);
$promos = $promos_pagination['data'];
@@ -278,4 +286,4 @@ function preparePromoEditForm(data) {
-
\ No newline at end of file
+
diff --git a/admin/areas.php b/admin/areas.php
index cce2a30..796900f 100644
--- a/admin/areas.php
+++ b/admin/areas.php
@@ -40,23 +40,33 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
}
}
-// Handle Delete
+// Handle Delete (Soft Delete)
if (isset($_GET['delete'])) {
if (!has_permission('areas_del')) {
$message = '
Access Denied: You do not have permission to delete areas.
';
} else {
- $id = $_GET['delete'];
- $pdo->prepare("DELETE FROM areas WHERE id = ?")->execute([$id]);
- header("Location: areas.php");
- exit;
+ try {
+ $id = (int)$_GET['delete'];
+ // Soft delete to preserve relations with tables
+ $pdo->prepare("UPDATE areas SET is_deleted = 1 WHERE id = ?")->execute([$id]);
+ header("Location: areas.php?deleted=1");
+ exit;
+ } catch (PDOException $e) {
+ $message = '
Error removing area: ' . $e->getMessage() . '
';
+ }
}
}
-$outlets = $pdo->query("SELECT * FROM outlets ORDER BY name ASC")->fetchAll();
+if (isset($_GET['deleted'])) {
+ $message = '
Area removed successfully!
';
+}
+
+$outlets = $pdo->query("SELECT * FROM outlets WHERE is_deleted = 0 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
+ WHERE a.is_deleted = 0
ORDER BY a.id DESC";
$areas_pagination = paginate_query($pdo, $query);
$areas = $areas_pagination['data'];
@@ -104,7 +114,7 @@ include 'includes/header.php';
-
+
diff --git a/admin/categories.php b/admin/categories.php
index 79f760c..54b0272 100644
--- a/admin/categories.php
+++ b/admin/categories.php
@@ -60,19 +60,28 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
}
}
-// Handle Delete
+// Handle Delete (Soft Delete)
if (isset($_GET['delete'])) {
if (!has_permission('categories_del')) {
$message = '
Access Denied: You do not have permission to delete categories.
';
} else {
- $id = $_GET['delete'];
- $pdo->prepare("DELETE FROM categories WHERE id = ?")->execute([$id]);
- header("Location: categories.php");
- exit;
+ try {
+ $id = (int)$_GET['delete'];
+ // Soft delete to avoid breaking product relations and historical order integrity
+ $pdo->prepare("UPDATE categories SET is_deleted = 1 WHERE id = ?")->execute([$id]);
+ header("Location: categories.php?deleted=1");
+ exit;
+ } catch (PDOException $e) {
+ $message = '
Error removing category: ' . $e->getMessage() . '
';
+ }
}
}
-$query = "SELECT * FROM categories ORDER BY name ASC";
+if (isset($_GET['deleted'])) {
+ $message = '
Category removed successfully!
';
+}
+
+$query = "SELECT * FROM categories WHERE is_deleted = 0 ORDER BY name ASC";
$categories_pagination = paginate_query($pdo, $query);
$categories = $categories_pagination['data'];
@@ -135,7 +144,7 @@ include 'includes/header.php';
- = t('delete') ?>
+ = t('delete') ?>
diff --git a/admin/customers.php b/admin/customers.php
index ef3160d..1b8f3a9 100644
--- a/admin/customers.php
+++ b/admin/customers.php
@@ -48,13 +48,25 @@ if (isset($_GET['delete'])) {
if (!has_permission('customers_del')) {
$message = '
Access Denied: You do not have permission to delete customers.
';
} else {
- $id = $_GET['delete'];
- $pdo->prepare("DELETE FROM customers WHERE id = ?")->execute([$id]);
- header("Location: customers.php");
- exit;
+ try {
+ $id = $_GET['delete'];
+ $pdo->prepare("DELETE FROM customers WHERE id = ?")->execute([$id]);
+ header("Location: customers.php?deleted=1");
+ exit;
+ } catch (PDOException $e) {
+ if ($e->getCode() == '23000') {
+ $message = '
Cannot delete this customer because they are linked to other records (e.g., orders).