@@ -405,4 +415,39 @@ function showDeleteDepartmentModal(id) {
var modal = new bootstrap.Modal(document.getElementById('deleteDepartmentModal'));
modal.show();
}
+
+async function translateDepartment(source, target) {
+ const text = document.getElementById(source === 'en' ? 'deptNameEn' : 'deptNameAr').value;
+ if (!text) return;
+
+ const btn = event.currentTarget;
+ const originalContent = btn.innerHTML;
+ btn.disabled = true;
+ btn.innerHTML = '
';
+
+ try {
+ const response = await fetch('api/ai_report.php', {
+ method: 'POST',
+ headers: {'Content-Type': 'application/json'},
+ body: JSON.stringify({
+ target: 'translate',
+ text: text,
+ from: source === 'en' ? 'English' : 'Arabic',
+ to: target === 'en' ? 'English' : 'Arabic'
+ })
+ });
+ const data = await response.json();
+ if (data.success) {
+ document.getElementById(target === 'en' ? 'deptNameEn' : 'deptNameAr').value = data.report;
+ } else {
+ alert('Translation failed: ' + (data.error || 'Unknown error'));
+ }
+ } catch (e) {
+ console.error(e);
+ alert('Network error');
+ } finally {
+ btn.disabled = false;
+ btn.innerHTML = originalContent;
+ }
+}
\ No newline at end of file
diff --git a/includes/pages/positions.php b/includes/pages/positions.php
index 592e643..5156741 100644
--- a/includes/pages/positions.php
+++ b/includes/pages/positions.php
@@ -257,11 +257,21 @@ if (isset($_GET['ajax_search'])) {
@@ -399,4 +409,39 @@ function showDeletePositionModal(id) {
var modal = new bootstrap.Modal(document.getElementById('deletePositionModal'));
modal.show();
}
+
+async function translatePosition(source, target) {
+ const text = document.getElementById(source === 'en' ? 'positionNameEn' : 'positionNameAr').value;
+ if (!text) return;
+
+ const btn = event.currentTarget;
+ const originalContent = btn.innerHTML;
+ btn.disabled = true;
+ btn.innerHTML = '';
+
+ try {
+ const response = await fetch('api/ai_report.php', {
+ method: 'POST',
+ headers: {'Content-Type': 'application/json'},
+ body: JSON.stringify({
+ target: 'translate',
+ text: text,
+ from: source === 'en' ? 'English' : 'Arabic',
+ to: target === 'en' ? 'English' : 'Arabic'
+ })
+ });
+ const data = await response.json();
+ if (data.success) {
+ document.getElementById(target === 'en' ? 'positionNameEn' : 'positionNameAr').value = data.report;
+ } else {
+ alert('Translation failed: ' + (data.error || 'Unknown error'));
+ }
+ } catch (e) {
+ console.error(e);
+ alert('Network error');
+ } finally {
+ btn.disabled = false;
+ btn.innerHTML = originalContent;
+ }
+}
\ No newline at end of file