From 6cbe1c3306a57aa75cb34edee48e5fcf75de1d41 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Tue, 24 Feb 2026 09:29:33 +0000 Subject: [PATCH] arabic translate for qr order --- admin/expense_categories.php | 67 +++++- admin/outlets.php | 67 +++++- admin/product_variants.php | 63 +++++- admin/reports.php | 20 +- admin/users.php | 71 +++++- .../031_add_name_ar_to_product_variants.sql | 2 + .../032_add_full_name_ar_to_users.sql | 2 + ...33_add_name_ar_to_outlets_and_expenses.sql | 3 + qorder.php | 212 ++++++++++++++---- rate.php | 185 ++++++++++++--- 10 files changed, 588 insertions(+), 104 deletions(-) create mode 100644 db/migrations/031_add_name_ar_to_product_variants.sql create mode 100644 db/migrations/032_add_full_name_ar_to_users.sql create mode 100644 db/migrations/033_add_name_ar_to_outlets_and_expenses.sql diff --git a/admin/expense_categories.php b/admin/expense_categories.php index 11011d5..cfcfd31 100644 --- a/admin/expense_categories.php +++ b/admin/expense_categories.php @@ -10,6 +10,7 @@ $message = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { $action = $_POST['action']; $name = trim($_POST['name']); + $name_ar = trim($_POST['name_ar'] ?? ''); $description = trim($_POST['description']); $id = isset($_POST['id']) ? (int)$_POST['id'] : null; @@ -21,16 +22,16 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { if (!has_permission('expense_categories_add')) { $message = '
Access Denied.
'; } else { - $stmt = $pdo->prepare("UPDATE expense_categories SET name = ?, description = ? WHERE id = ?"); - $stmt->execute([$name, $description, $id]); + $stmt = $pdo->prepare("UPDATE expense_categories SET name = ?, name_ar = ?, description = ? WHERE id = ?"); + $stmt->execute([$name, $name_ar, $description, $id]); $message = '
Expense category updated successfully!
'; } } elseif ($action === 'add_expense_category') { if (!has_permission('expense_categories_add')) { $message = '
Access Denied.
'; } else { - $stmt = $pdo->prepare("INSERT INTO expense_categories (name, description) VALUES (?, ?)"); - $stmt->execute([$name, $description]); + $stmt = $pdo->prepare("INSERT INTO expense_categories (name, name_ar, description) VALUES (?, ?, ?)"); + $stmt->execute([$name, $name_ar, $description]); $message = '
Expense category created successfully!
'; } } @@ -82,6 +83,7 @@ include 'includes/header.php'; ID Name + Arabic Name Description Actions @@ -91,6 +93,7 @@ include 'includes/header.php'; # + @@ -106,7 +109,7 @@ include 'includes/header.php'; - No expense categories found. + No expense categories found. @@ -134,7 +137,16 @@ include 'includes/header.php';
- +
+ + +
+
+
+ +
@@ -177,11 +189,52 @@ function openEditModal(cat) { document.getElementById('expenseCategoryAction').value = 'edit_expense_category'; document.getElementById('expenseCategoryId').value = cat.id; document.getElementById('expenseCategoryName').value = cat.name || ''; + document.getElementById('expenseCategoryNameAr').value = cat.name_ar || ''; document.getElementById('expenseCategoryDescription').value = cat.description || ''; modal.show(); } + +document.getElementById('btnTranslate').addEventListener('click', function() { + const text = document.getElementById('expenseCategoryName').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('expenseCategoryNameAr').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/admin/outlets.php b/admin/outlets.php index 3ec4309..7483fc3 100644 --- a/admin/outlets.php +++ b/admin/outlets.php @@ -10,6 +10,7 @@ $message = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { $action = $_POST['action']; $name = trim($_POST['name']); + $name_ar = trim($_POST['name_ar'] ?? ''); $address = trim($_POST['address']); $id = isset($_POST['id']) ? (int)$_POST['id'] : null; @@ -21,16 +22,16 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { if (!has_permission('outlets_add')) { $message = '
Access Denied.
'; } else { - $stmt = $pdo->prepare("UPDATE outlets SET name = ?, address = ? WHERE id = ?"); - $stmt->execute([$name, $address, $id]); + $stmt = $pdo->prepare("UPDATE outlets SET name = ?, name_ar = ?, address = ? WHERE id = ?"); + $stmt->execute([$name, $name_ar, $address, $id]); $message = '
Outlet updated successfully!
'; } } elseif ($action === 'add_outlet') { if (!has_permission('outlets_add')) { $message = '
Access Denied.
'; } else { - $stmt = $pdo->prepare("INSERT INTO outlets (name, address) VALUES (?, ?)"); - $stmt->execute([$name, $address]); + $stmt = $pdo->prepare("INSERT INTO outlets (name, name_ar, address) VALUES (?, ?, ?)"); + $stmt->execute([$name, $name_ar, $address]); $message = '
Outlet created successfully!
'; } } @@ -82,6 +83,7 @@ include 'includes/header.php'; ID Name + Arabic Name Address Actions @@ -91,6 +93,7 @@ include 'includes/header.php'; # + @@ -107,7 +110,7 @@ include 'includes/header.php'; - No outlets found. + No outlets found. @@ -135,7 +138,16 @@ include 'includes/header.php';
- +
+ + +
+
+
+ +
@@ -165,9 +177,50 @@ function prepareEditForm(outlet) { document.getElementById('outletAction').value = 'edit_outlet'; document.getElementById('outletId').value = outlet.id; document.getElementById('outletName').value = outlet.name || ''; + document.getElementById('outletNameAr').value = outlet.name_ar || ''; document.getElementById('outletAddress').value = outlet.address || ''; } + +document.getElementById('btnTranslate').addEventListener('click', function() { + const text = document.getElementById('outletName').value; + if (!text) { + alert('Please enter an outlet 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('outletNameAr').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/admin/product_variants.php b/admin/product_variants.php index 3fe296d..47dd030 100644 --- a/admin/product_variants.php +++ b/admin/product_variants.php @@ -23,10 +23,11 @@ if (!$product) { // Handle Add Variant if (isset($_POST['action']) && $_POST['action'] === 'add_variant') { $name = $_POST['name']; + $name_ar = $_POST['name_ar'] ?? ''; $price_adj = $_POST['price_adjustment']; - $stmt = $pdo->prepare("INSERT INTO product_variants (product_id, name, price_adjustment) VALUES (?, ?, ?)"); - $stmt->execute([$product_id, $name, $price_adj]); + $stmt = $pdo->prepare("INSERT INTO product_variants (product_id, name, name_ar, price_adjustment) VALUES (?, ?, ?, ?)"); + $stmt->execute([$product_id, $name, $name_ar, $price_adj]); header("Location: product_variants.php?product_id=$product_id"); exit; } @@ -35,10 +36,11 @@ if (isset($_POST['action']) && $_POST['action'] === 'add_variant') { if (isset($_POST['action']) && $_POST['action'] === 'edit_variant') { $id = $_POST['variant_id']; $name = $_POST['name']; + $name_ar = $_POST['name_ar'] ?? ''; $price_adj = $_POST['price_adjustment']; - $stmt = $pdo->prepare("UPDATE product_variants SET name = ?, price_adjustment = ? WHERE id = ?"); - $stmt->execute([$name, $price_adj, $id]); + $stmt = $pdo->prepare("UPDATE product_variants SET name = ?, name_ar = ?, price_adjustment = ? WHERE id = ?"); + $stmt->execute([$name, $name_ar, $price_adj, $id]); header("Location: product_variants.php?product_id=$product_id"); exit; } @@ -83,6 +85,7 @@ $effective_base_price = get_product_price($product); Variant Name + Arabic Name Price Adjustment Final Price (Est.) Actions @@ -92,6 +95,7 @@ $effective_base_price = get_product_price($product); +
0): ?> + @@ -113,6 +117,7 @@ $effective_base_price = get_product_price($product); data-bs-target="#editVariantModal" data-id="" data-name="" + data-name-ar="" data-price=""> @@ -122,7 +127,7 @@ $effective_base_price = get_product_price($product); - No variants defined (e.g., Small, Large, Spicy). + No variants defined (e.g., Small, Large, Spicy). @@ -147,8 +152,17 @@ $effective_base_price = get_product_price($product);
@@ -132,11 +176,11 @@ foreach ($variants_raw as $v) { @@ -146,7 +190,7 @@ foreach ($variants_raw as $v) {