39301-vm/admin_library_profile.php
2026-04-09 18:45:07 +00:00

237 lines
15 KiB
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/includes/admin_layout.php';
library_bootstrap();
$lang = library_get_language();
$isRtl = $lang === 'ar';
$pageTitle = $isRtl ? 'ملف المكتبة' : 'Library Profile';
$saveMessage = $isRtl ? 'تم حفظ ملف المكتبة بنجاح.' : 'Library profile saved successfully.';
$introText = $isRtl
? 'حدّث هوية المكتبة العامة: الاسم، الشعار، الأيقونة، الوصف، وبيانات التواصل التي تظهر في الواجهة.'
: 'Update the public library identity: name, logo, favicon, descriptions, and contact details shown on the site.';
$errors = [];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
try {
library_save_profile($_POST, $_FILES);
library_set_flash('success', $saveMessage);
header('Location: /admin_library_profile.php');
exit;
} catch (Throwable $exception) {
$errors[] = $exception->getMessage();
}
}
$profile = library_get_profile();
$fields = [
'library_name_en', 'library_name_ar', 'short_name', 'tagline_en', 'tagline_ar',
'description_en', 'description_ar', 'contact_email', 'contact_phone', 'whatsapp_number',
'website_url', 'address_en', 'address_ar', 'opening_hours_en', 'opening_hours_ar',
'facebook_url', 'instagram_url', 'x_url', 'youtube_url', 'copyright_text_en', 'copyright_text_ar'
];
foreach ($fields as $field) {
if (isset($_POST[$field])) {
$profile[$field] = trim((string) $_POST[$field]);
}
}
admin_render_header($pageTitle, 'library_profile');
?>
<?php if ($errors): ?>
<div class="alert alert-danger">
<h6 class="alert-heading fw-bold mb-2"><i class="bi bi-exclamation-triangle-fill me-2"></i><?= $isRtl ? 'تعذّر حفظ البيانات' : 'Unable to save profile' ?></h6>
<ul class="mb-0 ps-3">
<?php foreach ($errors as $error): ?>
<li><?= h($error) ?></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<div class="d-flex flex-column flex-lg-row justify-content-between align-items-lg-end gap-3 mb-4">
<div>
<p class="text-secondary mb-1"><?= h($introText) ?></p>
<div class="small text-muted"><?= $isRtl ? 'الملف المحفوظ هنا سيظهر في الشريط العلوي، التذييل، العنوان، والـ favicon.' : 'Saved here will appear in the top bar, footer, page title, and favicon.' ?></div>
</div>
<a href="/index.php" target="_blank" class="btn btn-outline-primary">
<i class="bi bi-box-arrow-up-right me-1"></i> <?= $isRtl ? 'معاينة الموقع' : 'Preview site' ?>
</a>
</div>
<form method="post" action="/admin_library_profile.php" enctype="multipart/form-data" class="row g-4">
<div class="col-12 col-xl-8">
<div class="card shadow-sm border-0 mb-4">
<div class="card-header bg-white py-3 border-bottom">
<h5 class="card-title mb-0"><i class="bi bi-stars me-2 text-primary"></i><?= $isRtl ? 'هوية المكتبة' : 'Library identity' ?></h5>
</div>
<div class="card-body p-4">
<div class="row g-3">
<div class="col-md-6">
<label class="form-label"><?= $isRtl ? 'اسم المكتبة بالإنجليزية' : 'Library name (English)' ?></label>
<input type="text" class="form-control" name="library_name_en" value="<?= h($profile['library_name_en'] ?? '') ?>">
</div>
<div class="col-md-6">
<label class="form-label"><?= $isRtl ? 'اسم المكتبة بالعربية' : 'Library name (Arabic)' ?></label>
<input type="text" class="form-control" name="library_name_ar" dir="rtl" value="<?= h($profile['library_name_ar'] ?? '') ?>">
</div>
<div class="col-md-4">
<label class="form-label"><?= $isRtl ? 'الاختصار / العلامة القصيرة' : 'Short name / monogram' ?></label>
<input type="text" class="form-control" name="short_name" maxlength="32" value="<?= h($profile['short_name'] ?? '') ?>">
</div>
<div class="col-md-4">
<label class="form-label"><?= $isRtl ? 'الشعار النصي بالإنجليزية' : 'Tagline (English)' ?></label>
<input type="text" class="form-control" name="tagline_en" value="<?= h($profile['tagline_en'] ?? '') ?>">
</div>
<div class="col-md-4">
<label class="form-label"><?= $isRtl ? 'الشعار النصي بالعربية' : 'Tagline (Arabic)' ?></label>
<input type="text" class="form-control" name="tagline_ar" dir="rtl" value="<?= h($profile['tagline_ar'] ?? '') ?>">
</div>
<div class="col-md-6">
<label class="form-label"><?= $isRtl ? 'وصف المكتبة بالإنجليزية' : 'Library description (English)' ?></label>
<textarea class="form-control" name="description_en" rows="4"><?= h($profile['description_en'] ?? '') ?></textarea>
</div>
<div class="col-md-6">
<label class="form-label"><?= $isRtl ? 'وصف المكتبة بالعربية' : 'Library description (Arabic)' ?></label>
<textarea class="form-control" name="description_ar" rows="4" dir="rtl"><?= h($profile['description_ar'] ?? '') ?></textarea>
</div>
<div class="col-md-6">
<label class="form-label"><?= $isRtl ? 'نص حقوق النشر بالإنجليزية' : 'Copyright line (English)' ?></label>
<input type="text" class="form-control" name="copyright_text_en" value="<?= h($profile['copyright_text_en'] ?? '') ?>">
</div>
<div class="col-md-6">
<label class="form-label"><?= $isRtl ? 'نص حقوق النشر بالعربية' : 'Copyright line (Arabic)' ?></label>
<input type="text" class="form-control" name="copyright_text_ar" dir="rtl" value="<?= h($profile['copyright_text_ar'] ?? '') ?>">
</div>
</div>
</div>
</div>
<div class="card shadow-sm border-0 mb-4">
<div class="card-header bg-white py-3 border-bottom">
<h5 class="card-title mb-0"><i class="bi bi-telephone me-2 text-primary"></i><?= $isRtl ? 'التواصل والموقع' : 'Contact and location' ?></h5>
</div>
<div class="card-body p-4">
<div class="row g-3">
<div class="col-md-6">
<label class="form-label"><?= $isRtl ? 'البريد الإلكتروني' : 'Email' ?></label>
<input type="email" class="form-control" name="contact_email" value="<?= h($profile['contact_email'] ?? '') ?>">
</div>
<div class="col-md-3">
<label class="form-label"><?= $isRtl ? 'الهاتف' : 'Phone' ?></label>
<input type="text" class="form-control" name="contact_phone" value="<?= h($profile['contact_phone'] ?? '') ?>">
</div>
<div class="col-md-3">
<label class="form-label"><?= $isRtl ? 'واتساب' : 'WhatsApp' ?></label>
<input type="text" class="form-control" name="whatsapp_number" value="<?= h($profile['whatsapp_number'] ?? '') ?>">
</div>
<div class="col-12">
<label class="form-label"><?= $isRtl ? 'الموقع الإلكتروني' : 'Website URL' ?></label>
<input type="text" class="form-control" name="website_url" placeholder="https://example.com" value="<?= h($profile['website_url'] ?? '') ?>">
</div>
<div class="col-md-6">
<label class="form-label"><?= $isRtl ? 'العنوان بالإنجليزية' : 'Address (English)' ?></label>
<input type="text" class="form-control" name="address_en" value="<?= h($profile['address_en'] ?? '') ?>">
</div>
<div class="col-md-6">
<label class="form-label"><?= $isRtl ? 'العنوان بالعربية' : 'Address (Arabic)' ?></label>
<input type="text" class="form-control" name="address_ar" dir="rtl" value="<?= h($profile['address_ar'] ?? '') ?>">
</div>
<div class="col-md-6">
<label class="form-label"><?= $isRtl ? 'ساعات العمل بالإنجليزية' : 'Opening hours (English)' ?></label>
<input type="text" class="form-control" name="opening_hours_en" value="<?= h($profile['opening_hours_en'] ?? '') ?>">
</div>
<div class="col-md-6">
<label class="form-label"><?= $isRtl ? 'ساعات العمل بالعربية' : 'Opening hours (Arabic)' ?></label>
<input type="text" class="form-control" name="opening_hours_ar" dir="rtl" value="<?= h($profile['opening_hours_ar'] ?? '') ?>">
</div>
</div>
</div>
</div>
<div class="card shadow-sm border-0">
<div class="card-header bg-white py-3 border-bottom">
<h5 class="card-title mb-0"><i class="bi bi-share me-2 text-primary"></i><?= $isRtl ? 'الروابط الاجتماعية' : 'Social links' ?></h5>
</div>
<div class="card-body p-4">
<div class="row g-3">
<div class="col-md-6">
<label class="form-label">Facebook</label>
<input type="text" class="form-control" name="facebook_url" placeholder="https://facebook.com/..." value="<?= h($profile['facebook_url'] ?? '') ?>">
</div>
<div class="col-md-6">
<label class="form-label">Instagram</label>
<input type="text" class="form-control" name="instagram_url" placeholder="https://instagram.com/..." value="<?= h($profile['instagram_url'] ?? '') ?>">
</div>
<div class="col-md-6">
<label class="form-label">X / Twitter</label>
<input type="text" class="form-control" name="x_url" placeholder="https://x.com/..." value="<?= h($profile['x_url'] ?? '') ?>">
</div>
<div class="col-md-6">
<label class="form-label">YouTube</label>
<input type="text" class="form-control" name="youtube_url" placeholder="https://youtube.com/..." value="<?= h($profile['youtube_url'] ?? '') ?>">
</div>
</div>
</div>
</div>
</div>
<div class="col-12 col-xl-4">
<div class="card shadow-sm border-0 mb-4">
<div class="card-header bg-white py-3 border-bottom">
<h5 class="card-title mb-0"><i class="bi bi-image me-2 text-primary"></i><?= $isRtl ? 'الهوية البصرية' : 'Brand assets' ?></h5>
</div>
<div class="card-body p-4">
<div class="mb-4">
<label class="form-label fw-semibold"><?= $isRtl ? 'شعار المكتبة' : 'Library logo' ?></label>
<input type="file" class="form-control" name="logo_file" accept=".png,.jpg,.jpeg,.webp">
<div class="form-text"><?= $isRtl ? 'PNG / JPG / WEBP حتى 4MB' : 'PNG / JPG / WEBP up to 4MB' ?></div>
<div class="mt-3 p-3 border rounded-4 bg-light text-center">
<?php if (!empty($profile['logo_path'])): ?>
<img src="/<?= h($profile['logo_path']) ?>?v=<?= time() ?>" alt="Library logo" style="max-width: 100%; max-height: 140px; object-fit: contain;">
<?php else: ?>
<div class="text-muted small"><?= $isRtl ? 'لا يوجد شعار مرفوع بعد.' : 'No logo uploaded yet.' ?></div>
<?php endif; ?>
</div>
</div>
<div>
<label class="form-label fw-semibold"><?= $isRtl ? 'أيقونة الموقع (Favicon)' : 'Favicon' ?></label>
<input type="file" class="form-control" name="favicon_file" accept=".ico,.png,.webp">
<div class="form-text"><?= $isRtl ? 'ICO / PNG / WEBP حتى 1MB' : 'ICO / PNG / WEBP up to 1MB' ?></div>
<div class="mt-3 p-3 border rounded-4 bg-light text-center">
<?php if (!empty($profile['favicon_path'])): ?>
<img src="/<?= h($profile['favicon_path']) ?>?v=<?= time() ?>" alt="Favicon" style="width: 64px; height: 64px; object-fit: contain;">
<?php else: ?>
<div class="text-muted small"><?= $isRtl ? 'لا توجد أيقونة مرفوعة بعد.' : 'No favicon uploaded yet.' ?></div>
<?php endif; ?>
</div>
</div>
</div>
</div>
<div class="card shadow-sm border-0 mb-4">
<div class="card-body p-4">
<h6 class="text-uppercase text-secondary small fw-bold mb-3"><?= $isRtl ? 'ما الذي سيتغيّر؟' : 'What this updates' ?></h6>
<ul class="small text-secondary mb-0 ps-3">
<li class="mb-2"><?= $isRtl ? 'اسم المكتبة ووصفها في الواجهة العامة والعناوين.' : 'Library name and description across the public site and page titles.' ?></li>
<li class="mb-2"><?= $isRtl ? 'الشعار في الشريط العلوي والتذييل ولوحة الإدارة.' : 'Logo in the top bar, footer, and admin sidebar.' ?></li>
<li class="mb-2"><?= $isRtl ? 'أيقونة المتصفح / favicon للموقع.' : 'Browser tab favicon for the site.' ?></li>
<li><?= $isRtl ? 'معلومات التواصل، العنوان، الروابط الاجتماعية، وساعات العمل.' : 'Contact details, address, social links, and opening hours.' ?></li>
</ul>
</div>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-primary btn-lg">
<i class="bi bi-save me-2"></i> <?= $isRtl ? 'حفظ ملف المكتبة' : 'Save library profile' ?>
</button>
</div>
</div>
</form>
<?php admin_render_footer(); ?>