Autosave: 20260301-025324

This commit is contained in:
Flatlogic Bot 2026-03-01 02:53:25 +00:00
parent 627842bf5c
commit e9893232d6
6 changed files with 88 additions and 34 deletions

View File

@ -7,7 +7,7 @@ $input = json_decode(file_get_contents('php://input'), true);
$message = $input['message'] ?? ''; $message = $input['message'] ?? '';
if (empty($message)) { if (empty($message)) {
echo json_encode(['reply' => "I didn't catch that. Could you repeat?"]); echo json_encode(['reply' => "لم أفهم ذلك. هل يمكنك التكرار؟"]);
exit; exit;
} }
@ -16,18 +16,18 @@ try {
$stmt = db()->query("SELECT keywords, answer FROM faqs"); $stmt = db()->query("SELECT keywords, answer FROM faqs");
$faqs = $stmt->fetchAll(PDO::FETCH_ASSOC); $faqs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$knowledgeBase = "Here is the knowledge base for this website:\n\n"; $knowledgeBase = "إليك قاعدة المعرفة لهذا الموقع:\n\n";
foreach ($faqs as $faq) { 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 // 2. Construct Prompt for AI
$systemPrompt = "You are a helpful, friendly AI assistant for this website. " . $systemPrompt = "أنت مساعد ذكاء اصطناعي مفيد وودود لهذا الموقع. " .
"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" . "اجعل الإجابات موجزة واحترافية وباللغة العربية.\n\n" .
$knowledgeBase; $knowledgeBase;
// 3. Call AI API // 3. Call AI API
@ -40,7 +40,12 @@ try {
]); ]);
if (!empty($response['success'])) { 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 // 4. Save to Database
try { try {
@ -55,10 +60,10 @@ try {
} else { } else {
// Fallback if AI fails // Fallback if AI fails
error_log("AI Error: " . ($response['error'] ?? 'Unknown')); 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) { } catch (Exception $e) {
error_log("Chat Error: " . $e->getMessage()); error_log("Chat Error: " . $e->getMessage());
echo json_encode(['reply' => "An internal error occurred."]); echo json_encode(['reply' => "حدث خطأ داخلي."]);
} }

View File

@ -3,7 +3,7 @@ session_start();
require_once __DIR__ . '/../db/config.php'; require_once __DIR__ . '/../db/config.php';
if (!isset($_SESSION['user_id'])) { if (!isset($_SESSION['user_id'])) {
echo json_encode(['success' => false, 'error' => 'Not authenticated']); echo json_encode(['success' => false, 'error' => 'غير مصرح لك بالوصول']);
exit; exit;
} }
@ -13,7 +13,7 @@ $theme = $data['theme'] ?? 'light';
// Validate theme // Validate theme
$allowed_themes = ['light', 'dark', 'midnight', 'forest']; $allowed_themes = ['light', 'dark', 'midnight', 'forest'];
if (!in_array($theme, $allowed_themes)) { if (!in_array($theme, $allowed_themes)) {
echo json_encode(['success' => false, 'error' => 'Invalid theme']); echo json_encode(['success' => false, 'error' => 'مظهر غير صالح']);
exit; exit;
} }
@ -23,4 +23,4 @@ try {
echo json_encode(['success' => true]); echo json_encode(['success' => true]);
} catch (PDOException $e) { } catch (PDOException $e) {
echo json_encode(['success' => false, 'error' => $e->getMessage()]); echo json_encode(['success' => false, 'error' => $e->getMessage()]);
} }

View File

@ -406,7 +406,7 @@ function initEditors() {
return tinymce.init({ return tinymce.init({
selector: '#modalDescription', selector: '#modalDescription',
language: 'ar', language: 'ar', language_url: 'https://cdn.jsdelivr.net/npm/tinymce-i18n@23.10.9/langs6/ar.js',
directionality: 'rtl', directionality: 'rtl',
height: 300, height: 300,
plugins: 'advlist autolink lists link image charmap preview anchor searchreplace visualblocks code fullscreen insertdatetime media table help wordcount', plugins: 'advlist autolink lists link image charmap preview anchor searchreplace visualblocks code fullscreen insertdatetime media table help wordcount',

View File

@ -324,7 +324,7 @@ document.addEventListener('DOMContentLoaded', function() {
if (typeof tinymce !== 'undefined') { if (typeof tinymce !== 'undefined') {
tinymce.init({ tinymce.init({
selector: '#composeEditor', selector: '#composeEditor',
language: 'ar', language: 'ar', language_url: 'https://cdn.jsdelivr.net/npm/tinymce-i18n@23.10.9/langs6/ar.js',
directionality: 'rtl', directionality: 'rtl',
height: 400, height: 400,
plugins: 'advlist autolink lists link image charmap preview anchor searchreplace visualblocks code fullscreen insertdatetime media table help wordcount', plugins: 'advlist autolink lists link image charmap preview anchor searchreplace visualblocks code fullscreen insertdatetime media table help wordcount',

View File

@ -385,7 +385,7 @@ function initEditors() {
return tinymce.init({ return tinymce.init({
selector: '#description_editor', selector: '#description_editor',
language: 'ar', language: 'ar', language_url: 'https://cdn.jsdelivr.net/npm/tinymce-i18n@23.10.9/langs6/ar.js',
directionality: 'rtl', directionality: 'rtl',
height: 300, height: 300,
plugins: 'advlist autolink lists link image charmap preview anchor searchreplace visualblocks code fullscreen insertdatetime media table help wordcount', plugins: 'advlist autolink lists link image charmap preview anchor searchreplace visualblocks code fullscreen insertdatetime media table help wordcount',

View File

@ -42,6 +42,7 @@ if (!$mail) {
$settings = get_settings(); $settings = get_settings();
$logo = !empty($settings['site_logo']) ? $settings['site_logo'] : ''; $logo = !empty($settings['site_logo']) ? $settings['site_logo'] : '';
$site_name = $settings['site_name']; $site_name = $settings['site_name'];
$site_address = $settings['site_address'];
/** /**
* Convert Gregorian date to Hijri * Convert Gregorian date to Hijri
@ -94,7 +95,7 @@ $hijriDate = gregorianToHijri($mail['date_registered']);
<style> <style>
@page { @page {
size: A4; size: A4;
margin: 1.5cm; margin: 1cm 1.5cm 2cm 1.5cm; /* Reserved 2cm at bottom for fixed footer */
} }
body { body {
font-family: 'Cairo', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; font-family: 'Cairo', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
@ -113,7 +114,7 @@ $hijriDate = gregorianToHijri($mail['date_registered']);
.header { .header {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: flex-start; /* Aligned to start for better header-info layout */
border-bottom: 3px double #333; border-bottom: 3px double #333;
padding-bottom: 20px; padding-bottom: 20px;
margin-bottom: 40px; margin-bottom: 40px;
@ -124,7 +125,20 @@ $hijriDate = gregorianToHijri($mail['date_registered']);
} }
.header-info { .header-info {
text-align: left; text-align: left;
font-size: 14px; line-height: 1.2;
margin-left: 1.5cm; /* Bring a little to the right from the left edge */
margin-top: 15px; /* Shifting a little down from the top edge */
}
.charity-name-header {
font-size: 24px;
font-weight: bold;
margin-bottom: 5px;
color: #00827F;
}
.charity-address-header {
font-size: 12px;
color: #00827F;
opacity: 0.85;
} }
.header-title { .header-title {
text-align: center; text-align: center;
@ -173,12 +187,28 @@ $hijriDate = gregorianToHijri($mail['date_registered']);
text-align: justify; text-align: justify;
} }
.footer { .footer {
margin-top: 50px; margin-top: 40px;
padding-top: 20px; padding-top: 20px; /* Matched to header padding-bottom */
border-top: 1px solid #eee; border-top: 3px double #333; /* Equal to the top line style */
text-align: center; text-align: center;
font-size: 11px;
color: #000;
}
.footer-content {
display: flex;
justify-content: center;
align-items: center;
flex-wrap: nowrap;
gap: 8px;
white-space: nowrap;
}
.social-icons i {
margin: 0 2px;
font-size: 12px; font-size: 12px;
color: #666; }
.footer-sep {
color: #999;
margin: 0 2px;
} }
.no-print { .no-print {
position: fixed; position: fixed;
@ -216,6 +246,14 @@ $hijriDate = gregorianToHijri($mail['date_registered']);
border: none; border: none;
padding: 10px 0; padding: 10px 0;
} }
.footer {
position: fixed;
bottom: 0.5cm; /* Positioned inside the reserved 2cm bottom margin */
left: 1.5cm;
right: 1.5cm;
margin-top: 0;
background: white;
}
} }
</style> </style>
</head> </head>
@ -238,7 +276,8 @@ $hijriDate = gregorianToHijri($mail['date_registered']);
<!-- Title removed as per user request --> <!-- Title removed as per user request -->
</div> </div>
<div class="header-info"> <div class="header-info">
<!-- Date and time removed as per user request --> <div class="charity-name-header"><?= htmlspecialchars($site_name) ?></div>
<div class="charity-address-header"><?= htmlspecialchars($site_address) ?></div>
</div> </div>
</div> </div>
@ -264,14 +303,24 @@ $hijriDate = gregorianToHijri($mail['date_registered']);
</div> </div>
<div class="footer"> <div class="footer">
<p> <div class="footer-content">
<?php if(!empty($settings['site_address'])): ?> العنوان: <?= htmlspecialchars($settings['site_address']) ?> | <?php endif; ?> <span>
<?php if(!empty($settings['site_phone'])): ?> هاتف: <?= htmlspecialchars($settings['site_phone']) ?> | <?php endif; ?> <strong>وسائل التواصل:</strong> ahlalhkair
<?php if(!empty($settings['site_email'])): ?> بريد: <?= htmlspecialchars($settings['site_email']) ?><?php endif; ?> <span class="social-icons">
</p> <i class="fab fa-twitter"></i>
<p>النظام الإلكتروني لإدارة البريد - <?= htmlspecialchars($site_name) ?></p> <i class="fab fa-instagram"></i>
<i class="fab fa-facebook"></i>
</span>
</span>
<span class="footer-sep">|</span>
<span><strong>هاتف:</strong> 99621515</span>
<span class="footer-sep">|</span>
<span><strong>الايميل:</strong> ahlalhkair@gmail.com</span>
<span class="footer-sep">|</span>
<span><strong>الموقع:</strong> https://alkhairteam.net/</span>
</div>
</div> </div>
</div> </div>
</body> </body>
</html> </html>