From 291449ae164a44d445eac244268a500ea6ef15de Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Tue, 24 Feb 2026 08:25:28 +0000 Subject: [PATCH] Autosave: 20260224-082528 --- admin/categories.php | 68 +++++++++++++++++-- .../030_add_name_ar_to_categories.sql | 2 + pos.php | 67 ++++++++++-------- 3 files changed, 102 insertions(+), 35 deletions(-) create mode 100644 db/migrations/030_add_name_ar_to_categories.sql diff --git a/admin/categories.php b/admin/categories.php index e58a544..07ce466 100644 --- a/admin/categories.php +++ b/admin/categories.php @@ -12,6 +12,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { $action = $_POST['action']; $id = isset($_POST['id']) ? (int)$_POST['id'] : null; $name = $_POST['name']; + $name_ar = $_POST['name_ar'] ?? ''; $description = $_POST['description']; $image_url = null; @@ -41,16 +42,16 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { if (!has_permission('categories_edit') && !has_permission('categories_add')) { $message = '
Access Denied: You do not have permission to edit categories.
'; } else { - $stmt = $pdo->prepare("UPDATE categories SET name = ?, description = ?, image_url = ? WHERE id = ?"); - $stmt->execute([$name, $description, $image_url, $id]); + $stmt = $pdo->prepare("UPDATE categories SET name = ?, name_ar = ?, description = ?, image_url = ? WHERE id = ?"); + $stmt->execute([$name, $name_ar, $description, $image_url, $id]); $message = '
Category updated successfully!
'; } } elseif ($action === 'add_category') { if (!has_permission('categories_add')) { $message = '
Access Denied: You do not have permission to add categories.
'; } else { - $stmt = $pdo->prepare("INSERT INTO categories (name, description, image_url) VALUES (?, ?, ?)"); - $stmt->execute([$name, $description, $image_url]); + $stmt = $pdo->prepare("INSERT INTO categories (name, name_ar, description, image_url) VALUES (?, ?, ?, ?)"); + $stmt->execute([$name, $name_ar, $description, $image_url]); $message = '
Category created successfully!
'; } } @@ -105,6 +106,7 @@ include 'includes/header.php'; Category + Arabic Name Description Actions @@ -118,6 +120,9 @@ include 'includes/header.php';
+ +
+
@@ -161,7 +166,17 @@ include 'includes/header.php';
- +
+ + +
+
+ +
+ +
@@ -203,6 +218,7 @@ function prepareEditForm(cat) { document.getElementById('categoryAction').value = 'edit_category'; document.getElementById('categoryId').value = cat.id; document.getElementById('categoryName').value = cat.name; + document.getElementById('categoryNameAr').value = cat.name_ar || ''; document.getElementById('categoryDescription').value = cat.description || ''; if (cat.image_url) { @@ -213,7 +229,47 @@ function prepareEditForm(cat) { document.getElementById('categoryImagePreview').style.display = 'none'; } } + +document.getElementById('btnTranslate').addEventListener('click', function() { + const text = document.getElementById('categoryName').value; + if (!text) { + alert('Please enter a category name first.'); + return; + } + + const btn = this; + const originalHtml = btn.innerHTML; + btn.disabled = true; + btn.innerHTML = ''; + + fetch('../api/translate.php', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + text: text, + target_lang: 'Arabic' + }), + }) + .then(response => response.json()) + .then(data => { + if (data.success) { + document.getElementById('categoryNameAr').value = data.translated_text; + } else { + alert('Translation failed: ' + (data.error || 'Unknown error')); + } + }) + .catch(error => { + console.error('Error:', error); + alert('An error occurred during translation.'); + }) + .finally(() => { + btn.disabled = false; + btn.innerHTML = originalHtml; + }); +}); - + \ No newline at end of file diff --git a/db/migrations/030_add_name_ar_to_categories.sql b/db/migrations/030_add_name_ar_to_categories.sql new file mode 100644 index 0000000..6b65467 --- /dev/null +++ b/db/migrations/030_add_name_ar_to_categories.sql @@ -0,0 +1,2 @@ +-- Add Arabic name to categories table +ALTER TABLE categories ADD COLUMN name_ar VARCHAR(255) AFTER name; diff --git a/pos.php b/pos.php index 229b26a..9c4f423 100644 --- a/pos.php +++ b/pos.php @@ -156,12 +156,19 @@ if (!$loyalty_settings) {
@@ -173,7 +180,7 @@ if (!$loyalty_settings) { @@ -500,17 +507,30 @@ if (!$loyalty_settings) {