Autosave: 20260301-025324
This commit is contained in:
parent
627842bf5c
commit
e9893232d6
29
api/chat.php
29
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' => "حدث خطأ داخلي."]);
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -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']);
|
||||
<style>
|
||||
@page {
|
||||
size: A4;
|
||||
margin: 1.5cm;
|
||||
margin: 1cm 1.5cm 2cm 1.5cm; /* Reserved 2cm at bottom for fixed footer */
|
||||
}
|
||||
body {
|
||||
font-family: 'Cairo', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
@ -113,7 +114,7 @@ $hijriDate = gregorianToHijri($mail['date_registered']);
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
align-items: flex-start; /* Aligned to start for better header-info layout */
|
||||
border-bottom: 3px double #333;
|
||||
padding-bottom: 20px;
|
||||
margin-bottom: 40px;
|
||||
@ -124,7 +125,20 @@ $hijriDate = gregorianToHijri($mail['date_registered']);
|
||||
}
|
||||
.header-info {
|
||||
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 {
|
||||
text-align: center;
|
||||
@ -173,12 +187,28 @@ $hijriDate = gregorianToHijri($mail['date_registered']);
|
||||
text-align: justify;
|
||||
}
|
||||
.footer {
|
||||
margin-top: 50px;
|
||||
padding-top: 20px;
|
||||
border-top: 1px solid #eee;
|
||||
margin-top: 40px;
|
||||
padding-top: 20px; /* Matched to header padding-bottom */
|
||||
border-top: 3px double #333; /* Equal to the top line style */
|
||||
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;
|
||||
color: #666;
|
||||
}
|
||||
.footer-sep {
|
||||
color: #999;
|
||||
margin: 0 2px;
|
||||
}
|
||||
.no-print {
|
||||
position: fixed;
|
||||
@ -216,6 +246,14 @@ $hijriDate = gregorianToHijri($mail['date_registered']);
|
||||
border: none;
|
||||
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>
|
||||
</head>
|
||||
@ -238,7 +276,8 @@ $hijriDate = gregorianToHijri($mail['date_registered']);
|
||||
<!-- Title removed as per user request -->
|
||||
</div>
|
||||
<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>
|
||||
|
||||
@ -264,12 +303,22 @@ $hijriDate = gregorianToHijri($mail['date_registered']);
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
<p>
|
||||
<?php if(!empty($settings['site_address'])): ?> العنوان: <?= htmlspecialchars($settings['site_address']) ?> | <?php endif; ?>
|
||||
<?php if(!empty($settings['site_phone'])): ?> هاتف: <?= htmlspecialchars($settings['site_phone']) ?> | <?php endif; ?>
|
||||
<?php if(!empty($settings['site_email'])): ?> بريد: <?= htmlspecialchars($settings['site_email']) ?><?php endif; ?>
|
||||
</p>
|
||||
<p>النظام الإلكتروني لإدارة البريد - <?= htmlspecialchars($site_name) ?></p>
|
||||
<div class="footer-content">
|
||||
<span>
|
||||
<strong>وسائل التواصل:</strong> ahlalhkair
|
||||
<span class="social-icons">
|
||||
<i class="fab fa-twitter"></i>
|
||||
<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>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user