Create New Item
×
Item Type
File
Folder
Item Name
×
Search file in folder and subfolders...
File Manager
/
admin
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
<!DOCTYPE html> <html lang="en"> <head> <title>Footer Menu Editor</title> <?php include "data/styles.php"?> <style> @keyframes fade-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } } .animate-fade-in { animation: fade-in 0.6s ease-out both; } </style> </head> <body class="bg-gray-100 min-h-screen"> <div class="max-w-4xl mx-auto p-6"> <div class="bg-white rounded-lg shadow-lg p-6 animate-fade-in"> <div class="flex items-center gap-3 mb-6"> <i data-lucide="panel-bottom" class="w-6 h-6 text-blue-600"></i> <h1 class="text-2xl font-bold text-gray-800">Edit Footer Menu</h1> </div> <?php require_once '../config.php'; // Load footer menus with a fallback $footer_menus = []; if (file_exists('../inc/data.footer.php')) { $footer_menus = include '../inc/data.footer.php'; } // Ensure footer_menus is an array with default structure $footer_menus = array_merge([ 'company' => ['title' => 'Company', 'items' => []], 'support' => ['title' => 'Support', 'items' => []], 'legal' => ['title' => 'Legal', 'items' => []] ], is_array($footer_menus) ? $footer_menus : []); $success = false; $error = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $company_items = $_POST['company']['items'] ?? []; $support_items = $_POST['support']['items'] ?? []; $legal_items = $_POST['legal']['items'] ?? []; $menu_data = [ 'company' => [ 'title' => $_POST['company']['title'] ?? 'Company', 'items' => array_filter($company_items, fn($item) => !empty($item['title']) && !empty($item['url'])) ], 'support' => [ 'title' => $_POST['support']['title'] ?? 'Support', 'items' => array_filter($support_items, fn($item) => !empty($item['title']) && !empty($item['url'])) ], 'legal' => [ 'title' => $_POST['legal']['title'] ?? 'Legal', 'items' => array_filter($legal_items, fn($item) => !empty($item['title']) && !empty($item['url'])) ] ]; // Beautify the array output $content = "<?php\nreturn [\n"; foreach ($menu_data as $section => $data) { $content .= " '$section' => [\n"; $content .= " 'title' => '" . addslashes($data['title']) . "',\n"; $content .= " 'items' => [\n"; foreach ($data['items'] as $item) { $content .= " ['title' => '" . addslashes($item['title']) . "', 'url' => '" . addslashes($item['url']) . "'],\n"; } $content .= " ],\n"; $content .= " ],\n"; } $content .= "];\n"; if (file_put_contents('../inc/data.footer.php', $content)) { $success = true; $footer_menus = $menu_data; // Update local variable after save } else { $error = 'Failed to save menu data. Check file permissions.'; } } ?> <?php if ($success): ?> <div class="mb-6 p-4 bg-green-100 text-green-700 rounded-md flex items-center gap-2"> <i data-lucide="check-circle" class="w-5 h-5"></i> Menu saved successfully! </div> <?php endif; ?> <?php if ($error): ?> <div class="mb-6 p-4 bg-red-100 text-red-700 rounded-md flex items-center gap-2"> <i data-lucide="alert-circle" class="w-5 h-5"></i> <?php echo htmlspecialchars($error); ?> </div> <?php endif; ?> <form method="POST" class="space-y-6"> <!-- Company Section --> <div class="border-t pt-4"> <div class="flex items-center gap-4 mb-4"> <label class="block text-sm mb-2 font-medium text-gray-400">Section Title:</label> <input type="text" name="company[title]" value="<?php echo htmlspecialchars($footer_menus['company']['title']); ?>" placeholder="Company Title" class="flex-1 p-2 border rounded-md focus:ring-2 focus:ring-blue-500"> </div> <div id="company-items" class="space-y-4"> <?php foreach ($footer_menus['company']['items'] as $index => $item): ?> <div class="flex flex-col sm:flex-row sm:items-center gap-2 sm:gap-4 menu-item"> <input type="text" name="company[items][<?php echo $index; ?>][title]" value="<?php echo htmlspecialchars($item['title'] ?? ''); ?>" placeholder="Menu Title" class="flex-1 p-2 border rounded-md focus:ring-2 focus:ring-blue-500"> <input type="text" name="company[items][<?php echo $index; ?>][url]" value="<?php echo htmlspecialchars($item['url'] ?? ''); ?>" placeholder="Menu URL" class="flex-1 p-2 border rounded-md focus:ring-2 focus:ring-blue-500 text-blue-700 font-sans"> <button type="button" onclick="this.parentElement.remove()" class="p-2 text-red-600 hover:text-red-800"> <i data-lucide="trash-2" class="w-5 h-5"></i> </button> </div> <?php endforeach; ?> </div> <button type="button" onclick="addMenuItem('company')" class="mt-4 inline-flex items-center gap-2 px-4 py-2 text-sm bg-blue-100 text-blue-700 rounded-md hover:bg-blue-200"> <i data-lucide="plus" class="w-5 h-5"></i> Add Company Item </button> </div> <!-- Support Section --> <div class="border-t pt-4"> <div class="flex items-center gap-4 mb-4"> <label class="block text-sm mb-2 font-medium text-gray-400">Section Title:</label> <input type="text" name="support[title]" value="<?php echo htmlspecialchars($footer_menus['support']['title']); ?>" placeholder="Support Title" class="flex-1 p-2 border rounded-md focus:ring-2 focus:ring-blue-500"> </div> <div id="support-items" class="space-y-4"> <?php foreach ($footer_menus['support']['items'] as $index => $item): ?> <div class="flex flex-col sm:flex-row sm:items-center gap-2 sm:gap-4 menu-item"> <input type="text" name="support[items][<?php echo $index; ?>][title]" value="<?php echo htmlspecialchars($item['title'] ?? ''); ?>" placeholder="Menu Title" class="flex-1 p-2 border rounded-md focus:ring-2 focus:ring-blue-500"> <input type="text" name="support[items][<?php echo $index; ?>][url]" value="<?php echo htmlspecialchars($item['url'] ?? ''); ?>" placeholder="Menu URL" class="flex-1 p-2 border rounded-md focus:ring-2 focus:ring-blue-500 text-blue-700 font-sans"> <button type="button" onclick="this.parentElement.remove()" class="p-2 text-red-600 hover:text-red-800"> <i data-lucide="trash-2" class="w-5 h-5"></i> </button> </div> <?php endforeach; ?> </div> <button type="button" onclick="addMenuItem('support')" class="mt-4 inline-flex items-center gap-2 px-4 py-2 text-sm bg-blue-100 text-blue-700 rounded-md hover:bg-blue-200"> <i data-lucide="plus" class="w-5 h-5"></i> Add Support Item </button> </div> <!-- Legal Section --> <div class="border-t pt-4"> <div class="flex items-center gap-4 mb-4"> <label class="block text-sm mb-2 font-medium text-gray-400">Section Title:</label> <input type="text" name="legal[title]" value="<?php echo htmlspecialchars($footer_menus['legal']['title']); ?>" placeholder="Legal Title" class="flex-1 p-2 border rounded-md focus:ring-2 focus:ring-blue-500"> </div> <div id="legal-items" class="space-y-4"> <?php foreach ($footer_menus['legal']['items'] as $index => $item): ?> <div class="flex flex-col sm:flex-row sm:items-center gap-2 sm:gap-4 menu-item"> <input type="text" name="legal[items][<?php echo $index; ?>][title]" value="<?php echo htmlspecialchars($item['title'] ?? ''); ?>" placeholder="Menu Title" class="flex-1 p-2 border rounded-md focus:ring-2 focus:ring-blue-500"> <input type="text" name="legal[items][<?php echo $index; ?>][url]" value="<?php echo htmlspecialchars($item['url'] ?? ''); ?>" placeholder="Menu URL" class="flex-1 p-2 border rounded-md focus:ring-2 focus:ring-blue-500 text-blue-700 font-sans"> <button type="button" onclick="this.parentElement.remove()" class="p-2 text-red-600 hover:text-red-800"> <i data-lucide="trash-2" class="w-5 h-5"></i> </button> </div> <?php endforeach; ?> </div> <button type="button" onclick="addMenuItem('legal')" class="mt-4 inline-flex items-center gap-2 px-4 py-2 text-sm bg-blue-100 text-blue-700 rounded-md hover:bg-blue-200"> <i data-lucide="plus" class="w-5 h-5"></i> Add Legal Item </button> </div> <div class="flex justify-end"> <button type="submit" class="bg-blue-600 text-white px-6 py-2 shadow rounded-xl hover:bg-blue-700 flex items-center justify-center gap-2 transition-transform w-full sm:w-auto"> <i data-lucide="save" class="w-5 h-5"></i> Save Menu </button> </div> </form> </div> </div> <script> let companyIndex = <?php echo count($footer_menus['company']['items']); ?>; let supportIndex = <?php echo count($footer_menus['support']['items']); ?>; let legalIndex = <?php echo count($footer_menus['legal']['items']); ?>; function addMenuItem(section) { const container = document.getElementById(`${section}-items`); const index = section === 'company' ? companyIndex++ : section === 'support' ? supportIndex++ : legalIndex++; const div = document.createElement('div'); div.className = 'flex flex-col sm:flex-row sm:items-center gap-2 sm:gap-4 menu-item animate-fade-in'; div.innerHTML = ` <input type="text" name="${section}[items][${index}][title]" placeholder="Menu Title" class="flex-1 p-2 border rounded-md focus:ring-2 focus:ring-blue-500"> <input type="text" name="${section}[items][${index}][url]" placeholder="Menu URL" class="flex-1 p-2 border rounded-md focus:ring-2 focus:ring-blue-500 text-blue-700 font-sans"> <button type="button" onclick="this.parentElement.remove()" class="p-2 text-red-600 hover:text-red-800"> <i data-lucide="trash-2" class="w-5 h-5"></i> </button> `; container.appendChild(div); lucide.createIcons(); } lucide.createIcons(); </script> </body> </html>