diff --git a/api/chat.php b/api/chat.php index dbe026c..c6db2f4 100644 --- a/api/chat.php +++ b/api/chat.php @@ -7,7 +7,7 @@ $input = json_decode(file_get_contents('php://input'), true); $message = $input['message'] ?? ''; if (empty($message)) { - echo json_encode(['reply' => "I didn't catch that. Could you repeat?"]); + echo json_encode(['reply' => "لم أفهم ذلك. هل يمكنك التكرار؟"]); exit; } @@ -16,18 +16,18 @@ try { $stmt = db()->query("SELECT keywords, answer FROM faqs"); $faqs = $stmt->fetchAll(PDO::FETCH_ASSOC); - $knowledgeBase = "Here is the knowledge base for this website:\n\n"; + $knowledgeBase = "إليك قاعدة المعرفة لهذا الموقع:\n\n"; foreach ($faqs as $faq) { - $knowledgeBase .= "Q: " . $faq['keywords'] . "\nA: " . $faq['answer'] . "\n---\n"; + $knowledgeBase .= "س: " . $faq['keywords'] . "\nج: " . $faq['answer'] . "\n---\n"; } // 2. Construct Prompt for AI - $systemPrompt = "You are a helpful, friendly AI assistant for this website. " . - "Use the provided Knowledge Base to answer user questions accurately. " . - "If the answer is found in the Knowledge Base, rephrase it naturally. " . - "If the answer is NOT in the Knowledge Base, use your general knowledge to help, " . - "but politely mention that you don't have specific information about that if it seems like a site-specific question. " . - "Keep answers concise and professional.\n\n" . + $systemPrompt = "أنت مساعد ذكاء اصطناعي مفيد وودود لهذا الموقع. " . + "استخدم قاعدة المعرفة المقدمة للإجابة على أسئلة المستخدمين بدقة. " . + "إذا كانت الإجابة موجودة في قاعدة المعرفة، فقم بصياغتها بشكل طبيعي. " . + "إذا لم تكن الإجابة في قاعدة المعرفة، فاستخدم معرفتك العامة للمساعدة، " . + "ولكن اذكر بأدب أنك ليس لديك معلومات محددة حول ذلك إذا كان يبدو سؤالاً خاصاً بالموقع. " . + "اجعل الإجابات موجزة واحترافية وباللغة العربية.\n\n" . $knowledgeBase; // 3. Call AI API @@ -40,7 +40,12 @@ try { ]); if (!empty($response['success'])) { - $aiReply = LocalAIApi::extractText($response); + $text = LocalAIApi::extractText($response); + if ($text === '') { + $decoded = LocalAIApi::decodeJsonFromResponse($response); + $text = $decoded ? json_encode($decoded, JSON_UNESCAPED_UNICODE) : (string)($response['data'] ?? ''); + } + $aiReply = $text; // 4. Save to Database try { @@ -55,10 +60,10 @@ try { } else { // Fallback if AI fails error_log("AI Error: " . ($response['error'] ?? 'Unknown')); - echo json_encode(['reply' => "I'm having trouble connecting to my brain right now. Please try again later."]); + echo json_encode(['reply' => "أواجه مشكلة في الاتصال بذكائي الآن. يرجى المحاولة مرة أخرى لاحقاً."]); } } catch (Exception $e) { error_log("Chat Error: " . $e->getMessage()); - echo json_encode(['reply' => "An internal error occurred."]); -} + echo json_encode(['reply' => "حدث خطأ داخلي."]); +} \ No newline at end of file diff --git a/api/update_theme.php b/api/update_theme.php index 5c7fe8d..0cb41f1 100644 --- a/api/update_theme.php +++ b/api/update_theme.php @@ -3,7 +3,7 @@ session_start(); require_once __DIR__ . '/../db/config.php'; if (!isset($_SESSION['user_id'])) { - echo json_encode(['success' => false, 'error' => 'Not authenticated']); + echo json_encode(['success' => false, 'error' => 'غير مصرح لك بالوصول']); exit; } @@ -13,7 +13,7 @@ $theme = $data['theme'] ?? 'light'; // Validate theme $allowed_themes = ['light', 'dark', 'midnight', 'forest']; if (!in_array($theme, $allowed_themes)) { - echo json_encode(['success' => false, 'error' => 'Invalid theme']); + echo json_encode(['success' => false, 'error' => 'مظهر غير صالح']); exit; } @@ -23,4 +23,4 @@ try { echo json_encode(['success' => true]); } catch (PDOException $e) { echo json_encode(['success' => false, 'error' => $e->getMessage()]); -} +} \ No newline at end of file diff --git a/inbound.php b/inbound.php index 9de8786..db16ae0 100644 --- a/inbound.php +++ b/inbound.php @@ -406,7 +406,7 @@ function initEditors() { return tinymce.init({ selector: '#modalDescription', - language: 'ar', + language: 'ar', language_url: 'https://cdn.jsdelivr.net/npm/tinymce-i18n@23.10.9/langs6/ar.js', directionality: 'rtl', height: 300, plugins: 'advlist autolink lists link image charmap preview anchor searchreplace visualblocks code fullscreen insertdatetime media table help wordcount', diff --git a/internal_outbox.php b/internal_outbox.php index b7e08e9..6a75d7b 100644 --- a/internal_outbox.php +++ b/internal_outbox.php @@ -324,7 +324,7 @@ document.addEventListener('DOMContentLoaded', function() { if (typeof tinymce !== 'undefined') { tinymce.init({ selector: '#composeEditor', - language: 'ar', + language: 'ar', language_url: 'https://cdn.jsdelivr.net/npm/tinymce-i18n@23.10.9/langs6/ar.js', directionality: 'rtl', height: 400, plugins: 'advlist autolink lists link image charmap preview anchor searchreplace visualblocks code fullscreen insertdatetime media table help wordcount', diff --git a/outbound.php b/outbound.php index b909c0a..e0a67b6 100644 --- a/outbound.php +++ b/outbound.php @@ -385,7 +385,7 @@ function initEditors() { return tinymce.init({ selector: '#description_editor', - language: 'ar', + language: 'ar', language_url: 'https://cdn.jsdelivr.net/npm/tinymce-i18n@23.10.9/langs6/ar.js', directionality: 'rtl', height: 300, plugins: 'advlist autolink lists link image charmap preview anchor searchreplace visualblocks code fullscreen insertdatetime media table help wordcount', diff --git a/print_outbound.php b/print_outbound.php index d8279a0..6782b1d 100644 --- a/print_outbound.php +++ b/print_outbound.php @@ -42,6 +42,7 @@ if (!$mail) { $settings = get_settings(); $logo = !empty($settings['site_logo']) ? $settings['site_logo'] : ''; $site_name = $settings['site_name']; +$site_address = $settings['site_address']; /** * Convert Gregorian date to Hijri @@ -94,7 +95,7 @@ $hijriDate = gregorianToHijri($mail['date_registered']); @@ -238,7 +276,8 @@ $hijriDate = gregorianToHijri($mail['date_registered']);