From f72c5f11b8028d4b3405f6c9cf4516155c33a6fe Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Wed, 25 Mar 2026 08:05:46 +0000 Subject: [PATCH] add categories --- admin.php | 220 +++++++++++++++++++++++++++++++++++++++---- api/translate.php | 14 ++- includes/library.php | 30 +++++- 3 files changed, 239 insertions(+), 25 deletions(-) diff --git a/admin.php b/admin.php index a8df133..54c4c17 100644 --- a/admin.php +++ b/admin.php @@ -12,6 +12,7 @@ $successMessage = ''; // Handle POST request if ($_SERVER['REQUEST_METHOD'] === 'POST') { $action = $_POST['action'] ?? ''; + $id = isset($_POST['id']) ? (int)$_POST['id'] : 0; try { if ($action === 'upload_document') { @@ -29,6 +30,24 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { library_set_flash('success', 'Category created successfully.'); header('Location: /admin.php'); exit; + } elseif ($action === 'update_category') { + $nameEn = trim($_POST['name_en'] ?? ''); + $nameAr = trim($_POST['name_ar'] ?? ''); + if (!$id || !$nameEn || !$nameAr) { + throw new RuntimeException('ID, English name, and Arabic name are required.'); + } + library_update_category($id, $nameEn, $nameAr); + library_set_flash('success', 'Category updated successfully.'); + header('Location: /admin.php'); + exit; + } elseif ($action === 'delete_category') { + if (!$id) { + throw new RuntimeException('Invalid Category ID.'); + } + library_delete_category($id); + library_set_flash('success', 'Category deleted successfully.'); + header('Location: /admin.php'); + exit; } elseif ($action === 'create_subcategory') { $catId = (int)($_POST['category_id'] ?? 0); $nameEn = trim($_POST['name_en'] ?? ''); @@ -40,6 +59,25 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { library_set_flash('success', 'Subcategory created successfully.'); header('Location: /admin.php'); exit; + } elseif ($action === 'update_subcategory') { + $catId = (int)($_POST['category_id'] ?? 0); + $nameEn = trim($_POST['name_en'] ?? ''); + $nameAr = trim($_POST['name_ar'] ?? ''); + if (!$id || !$catId || !$nameEn || !$nameAr) { + throw new RuntimeException('ID, Category, English name, and Arabic name are required.'); + } + library_update_subcategory($id, $catId, $nameEn, $nameAr); + library_set_flash('success', 'Subcategory updated successfully.'); + header('Location: /admin.php'); + exit; + } elseif ($action === 'delete_subcategory') { + if (!$id) { + throw new RuntimeException('Invalid Subcategory ID.'); + } + library_delete_subcategory($id); + library_set_flash('success', 'Subcategory deleted successfully.'); + header('Location: /admin.php'); + exit; } } catch (Throwable $exception) { $errors[] = $exception->getMessage(); @@ -86,10 +124,10 @@ $flashes = library_get_flashes();
Metadata
- -
@@ -109,8 +147,9 @@ $flashes = library_get_flashes();
-
+ +

Upload New Document

@@ -132,7 +171,7 @@ $flashes = library_get_flashes(); - +
@@ -142,7 +181,7 @@ $flashes = library_get_flashes(); - + @@ -175,8 +214,8 @@ $flashes = library_get_flashes();
-

Recent Documents

-
+

Recent Documents

+
@@ -220,6 +259,88 @@ $flashes = library_get_flashes();
+ +
+
+
+

Categories

+ +
+
+ + + + + + + + + + + + + + + + + + + +
NameActions
No categories.
+
+ +
+ + +
+
+
+
+
+

Subcategories

+ +
+
+ + + + + + + + + + + + + + + + + + + + + +
NameParentActions
No subcategories.
+
+ +
+ + +
+
+
+
+
@@ -227,10 +348,11 @@ $flashes = library_get_flashes();