39496-vm/admin_landing.php
2026-04-07 07:11:44 +00:00

183 lines
9.9 KiB
PHP

<?php
// admin_landing.php
if (!isset($pdo)) {
$pdo = db();
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'save_landing') {
$settings = $_POST['settings'] ?? [];
// Save text settings
$stmt = $pdo->prepare("INSERT INTO landing_settings (setting_key, value_en, value_ar) VALUES (:key, :en, :ar) ON DUPLICATE KEY UPDATE value_en = :en, value_ar = :ar");
foreach ($settings as $key => $values) {
$stmt->execute([
'key' => $key,
'en' => $values['en'] ?? '',
'ar' => $values['ar'] ?? ''
]);
}
// Save image settings
$upload_dir = __DIR__ . '/assets/images/uploads/';
if (!is_dir($upload_dir)) {
mkdir($upload_dir, 0775, true);
}
$sections = ['hero', 'courses', 'subjects', 'flow', 'plans'];
foreach ($sections as $sec) {
if (isset($_FILES['images']['error'][$sec]) && $_FILES['images']['error'][$sec] === UPLOAD_ERR_OK) {
$filename = time() . '_' . basename($_FILES['images']['name'][$sec]);
$target_file = $upload_dir . $filename;
if (move_uploaded_file($_FILES['images']['tmp_name'][$sec], $target_file)) {
$picture = 'assets/images/uploads/' . $filename;
$stmt->execute([
'key' => $sec . '_image',
'en' => $picture,
'ar' => $picture
]);
}
}
}
header('Location: ' . app_url('admin.php', ['page' => 'landing', 'saved' => 1]));
exit;
}
$stmt = $pdo->query("SELECT setting_key, value_en, value_ar FROM landing_settings");
$all_settings = $stmt->fetchAll(PDO::FETCH_ASSOC);
$settings = [];
foreach ($all_settings as $row) {
$settings[$row['setting_key']] = $row;
}
$sections = [
'hero' => [
'label' => 'Hero Section / القسم الأول',
'fields' => [
'eyebrow' => ['label' => 'Eyebrow / النص الصغير', 'type' => 'text'],
'title' => ['label' => 'Title / العنوان الرئيسي', 'type' => 'textarea'],
'desc' => ['label' => 'Description / الوصف', 'type' => 'textarea'],
]
],
'courses' => [
'label' => 'Courses Section / قسم الدورات',
'fields' => [
'eyebrow' => ['label' => 'Eyebrow / النص الصغير', 'type' => 'text'],
'title' => ['label' => 'Title / العنوان الرئيسي', 'type' => 'textarea'],
]
],
'subjects' => [
'label' => 'Subjects Section / قسم المواد',
'fields' => [
'eyebrow' => ['label' => 'Eyebrow / النص الصغير', 'type' => 'text'],
'title' => ['label' => 'Title / العنوان الرئيسي', 'type' => 'textarea'],
]
],
'flow' => [
'label' => 'Delivery Flow Section / قسم مسار التسليم',
'fields' => [
'eyebrow' => ['label' => 'Eyebrow / النص الصغير', 'type' => 'text'],
'title' => ['label' => 'Title / العنوان الرئيسي', 'type' => 'textarea'],
]
],
'plans' => [
'label' => 'Plans Section / قسم الخطط',
'fields' => [
'eyebrow' => ['label' => 'Eyebrow / النص الصغير', 'type' => 'text'],
'title' => ['label' => 'Title / العنوان الرئيسي', 'type' => 'textarea'],
]
]
];
?>
<div class="section-header mb-4">
<div>
<span class="eyebrow"><?= h(t('Settings', 'الإعدادات')) ?></span>
<h1 class="section-title mb-2"><?= h(t('Landing Page Settings', 'إعدادات الصفحة الرئيسية')) ?></h1>
<p class="text-secondary mb-0"><?= h(t('Customize the content of the landing page in English and Arabic. Grouped by sections.', 'تخصيص محتوى الصفحة الرئيسية باللغتين الإنجليزية والعربية. مجمعة حسب الأقسام.')) ?></p>
</div>
</div>
<?php if (!empty($_GET['saved'])): ?>
<div class="alert alert-success"><?= h(t('Landing page settings updated successfully.', 'تم تحديث إعدادات الصفحة الرئيسية بنجاح.')) ?></div>
<?php endif; ?>
<div class="panel-card" style="max-width: 900px;">
<form method="POST" action="" enctype="multipart/form-data">
<input type="hidden" name="action" value="save_landing">
<div class="accordion" id="sectionsAccordion">
<?php foreach ($sections as $sec_key => $section): ?>
<div class="accordion-item mb-3 border rounded">
<h2 class="accordion-header" id="heading-<?= $sec_key ?>">
<button class="accordion-button <?= $sec_key === 'hero' ? '' : 'collapsed' ?> bg-light fw-bold" type="button" data-bs-toggle="collapse" data-bs-target="#collapse-<?= $sec_key ?>" aria-expanded="<?= $sec_key === 'hero' ? 'true' : 'false' ?>" aria-controls="collapse-<?= $sec_key ?>">
<?= h($section['label']) ?>
</button>
</h2>
<div id="collapse-<?= $sec_key ?>" class="accordion-collapse collapse <?= $sec_key === 'hero' ? 'show' : '' ?>" aria-labelledby="heading-<?= $sec_key ?>" data-bs-parent="#sectionsAccordion">
<div class="accordion-body">
<!-- Image Upload for Section -->
<div class="mb-4 p-3 border rounded bg-white">
<label class="form-label fw-bold"><?= h(t('Section Image', 'صورة القسم')) ?></label>
<?php if (!empty($settings[$sec_key . '_image']['value_en'])): ?>
<div class="mb-2">
<img src="<?= h($settings[$sec_key . '_image']['value_en']) ?>" alt="Current Image" style="max-height: 100px; border-radius: 8px;">
</div>
<?php endif; ?>
<input type="file" class="form-control" name="images[<?= $sec_key ?>]" accept="image/*">
<small class="text-muted"><?= h(t('Upload a new image to replace the current one.', 'قم برفع صورة جديدة لاستبدال الصورة الحالية.')) ?></small>
</div>
<ul class="nav nav-tabs mb-3" id="tab-<?= $sec_key ?>" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" data-bs-toggle="tab" data-bs-target="#<?= $sec_key ?>-en" type="button" role="tab">English</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#<?= $sec_key ?>-ar" type="button" role="tab">العربية</button>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane fade show active" id="<?= $sec_key ?>-en" role="tabpanel">
<?php foreach ($section['fields'] as $field_key => $field): ?>
<?php $full_key = $sec_key . '_' . $field_key; ?>
<div class="mb-3">
<label class="form-label fw-bold text-secondary"><?= h($field['label']) ?></label>
<?php if ($field['type'] === 'textarea'): ?>
<textarea class="form-control" name="settings[<?= $full_key ?>][en]" rows="2"><?= h($settings[$full_key]['value_en'] ?? '') ?></textarea>
<?php else: ?>
<input type="text" class="form-control" name="settings[<?= $full_key ?>][en]" value="<?= h($settings[$full_key]['value_en'] ?? '') ?>">
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<div class="tab-pane fade" id="<?= $sec_key ?>-ar" role="tabpanel" dir="rtl">
<?php foreach ($section['fields'] as $field_key => $field): ?>
<?php $full_key = $sec_key . '_' . $field_key; ?>
<div class="mb-3">
<label class="form-label fw-bold text-secondary"><?= h($field['label']) ?></label>
<?php if ($field['type'] === 'textarea'): ?>
<textarea class="form-control" name="settings[<?= $full_key ?>][ar]" rows="2"><?= h($settings[$full_key]['value_ar'] ?? '') ?></textarea>
<?php else: ?>
<input type="text" class="form-control" name="settings[<?= $full_key ?>][ar]" value="<?= h($settings[$full_key]['value_ar'] ?? '') ?>">
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<div class="mt-4">
<button type="submit" class="btn btn-dark btn-lg px-4"><?= h(t('Save All Sections', 'حفظ كل الأقسام')) ?></button>
</div>
</form>
</div>