| Server IP : 127.0.0.1 / Your IP : 192.168.99.1 Web Server : Apache/2.4.35 (Win64) OpenSSL/1.1.1b mod_fcgid/2.3.9 System : Windows NT WIN-JEJMB9EN0L0 10.0 build 14393 (Windows Server 2016) AMD64 User : Administrator ( 0) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /bpkd_29052026/admin/ |
Upload File : |
<?php
$page_title = 'Edit Halaman';
require_once 'config/database.php';
require_once 'includes/header.php';
require_once 'includes/init.php';
requireLogin();
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
if ($id <= 0) {
redirect('pages.php');
}
// Get page data
$page = $conn->query("SELECT * FROM pages WHERE id = $id")->fetch_assoc();
if (!$page) {
redirect('pages.php');
}
// Opsi URL prefix yang tersedia
$url_prefixes = [
'halaman' => '/halaman/',
'profil' => '/profil/',
'informasi' => '/informasi/',
'dokumen' => '/dokumen/',
'custom' => 'Custom URL (isi sendiri)'
];
// Get current prefix value
$current_prefix = $page['url_prefix'] ?? 'halaman';
$is_custom = !in_array($current_prefix, array_keys($url_prefixes));
// Get parent pages
$parent_pages = $conn->query("SELECT id, title FROM pages WHERE parent_id = 0 AND id != $id ORDER BY title");
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$title = sanitize($_POST['title']);
$content = $_POST['content'];
$excerpt = sanitize($_POST['excerpt']);
$parent_id = (int)$_POST['parent_id'];
$template = sanitize($_POST['template']);
$status = sanitize($_POST['status']);
// Handle slug
$slug = sanitize($_POST['slug']);
if (empty($slug)) {
$slug = createSlug($title);
} else {
$slug = strtolower(trim($slug));
$slug = preg_replace('/[^a-z0-9-]/', '', $slug);
$slug = preg_replace('/-+/', '-', $slug);
$slug = trim($slug, '-');
}
// Handle URL prefix
$url_prefix = sanitize($_POST['url_prefix']);
if ($url_prefix == 'custom') {
$url_prefix = sanitize($_POST['custom_prefix']);
if (empty($url_prefix)) {
$url_prefix = $page['url_prefix'] ?? 'halaman';
} else {
$url_prefix = strtolower(trim($url_prefix));
$url_prefix = preg_replace('/[^a-z0-9-]/', '', $url_prefix);
$url_prefix = trim($url_prefix, '-');
}
} elseif (empty($url_prefix)) {
$url_prefix = $page['url_prefix'] ?? 'halaman';
}
// Cek apakah slug sudah ada dengan prefix yang sama (kecuali halaman ini)
$check_slug = $conn->query("SELECT id FROM pages WHERE slug = '$slug' AND url_prefix = '$url_prefix' AND id != $id");
if ($check_slug->num_rows > 0) {
$slug = $slug . '-' . rand(100, 999);
}
// Handle file upload (sama seperti sebelumnya)
$featured_file = $page['featured_image'];
$file_type = $page['file_type'] ?? '';
if (isset($_FILES['featured_file']) && $_FILES['featured_file']['error'] == 0 && !empty($_FILES['featured_file']['name'])) {
$target_dir = "../uploads/pages/";
if (!file_exists($target_dir)) {
mkdir($target_dir, 0777, true);
}
$file_ext = strtolower(pathinfo($_FILES['featured_file']['name'], PATHINFO_EXTENSION));
$allowed = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'pdf'];
if (in_array($file_ext, $allowed)) {
if ($_FILES['featured_file']['size'] <= 5 * 1024 * 1024) {
$file_name = time() . '_' . uniqid() . '.' . $file_ext;
$target_file = $target_dir . $file_name;
if (move_uploaded_file($_FILES['featured_file']['tmp_name'], $target_file)) {
if (!empty($page['featured_image']) && file_exists("../" . $page['featured_image'])) {
unlink("../" . $page['featured_image']);
}
$featured_file = 'uploads/pages/' . $file_name;
$file_type = $file_ext;
} else {
$error = "Gagal mengupload file!";
}
} else {
$error = "Ukuran file maksimal 5MB!";
}
} else {
$error = "Format file tidak diizinkan! Gunakan JPG, PNG, GIF, WEBP, atau PDF.";
}
}
// Remove file
if (isset($_POST['remove_file']) && $_POST['remove_file'] == '1') {
if (!empty($page['featured_image']) && file_exists("../" . $page['featured_image'])) {
unlink("../" . $page['featured_image']);
}
$featured_file = '';
$file_type = '';
}
if (!isset($error)) {
$query = "UPDATE pages SET
title = '$title',
slug = '$slug',
url_prefix = '$url_prefix',
content = '$content',
excerpt = '$excerpt',
featured_image = '$featured_file',
file_type = '$file_type',
parent_id = $parent_id,
template = '$template',
status = '$status'
WHERE id = $id";
if ($conn->query($query)) {
redirect('pages.php?msg=updated');
} else {
$error = "Error: " . $conn->error;
}
}
}
// Include header
require_once 'includes/header.php';
?>
<div class="container-fluid">
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h1 class="h3 mb-0 text-gray-800">Edit Halaman: <?php echo htmlspecialchars($page['title']); ?></h1>
<div>
<a href="pages.php" class="btn btn-secondary me-2">
<i class="fas fa-arrow-left me-2"></i>Kembali
</a>
<?php
$full_url = '/' . ($page['url_prefix'] ?? 'halaman') . '/' . $page['slug'];
?>
<a href="<?php echo $full_url; ?>" target="_blank" class="btn btn-info">
<i class="fas fa-eye me-2"></i>Lihat Halaman
</a>
</div>
</div>
<?php if (isset($error)): ?>
<div class="alert alert-danger"><?php echo $error; ?></div>
<?php endif; ?>
<div class="card shadow mb-4">
<div class="card-body">
<form method="POST" enctype="multipart/form-data" id="pageForm">
<div class="row">
<div class="col-md-8">
<!-- Title -->
<div class="mb-3">
<label class="form-label">Judul Halaman <span class="text-danger">*</span></label>
<input type="text" class="form-control" name="title" id="title"
value="<?php echo htmlspecialchars($page['title']); ?>" required>
</div>
<!-- URL Settings -->
<div class="card mb-3">
<div class="card-header bg-light">
<h6 class="mb-0"><i class="fas fa-link me-2"></i>Pengaturan URL</h6>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-5 mb-3">
<label class="form-label">Prefix URL</label>
<select class="form-control" name="url_prefix" id="url_prefix">
<?php foreach ($url_prefixes as $key => $label): ?>
<option value="<?php echo $key; ?>"
<?php echo ($page['url_prefix'] ?? 'halaman') == $key ? 'selected' : ''; ?>>
<?php echo $label; ?>
</option>
<?php endforeach; ?>
</select>
<small class="text-muted">Pilih struktur URL untuk halaman ini</small>
</div>
<div class="col-md-7 mb-3" id="custom_prefix_container" style="display: <?php echo $is_custom ? 'block' : 'none'; ?>;">
<label class="form-label">Custom Prefix</label>
<div class="input-group">
<span class="input-group-text">/</span>
<input type="text" class="form-control" name="custom_prefix" id="custom_prefix"
value="<?php echo $is_custom ? htmlspecialchars($current_prefix) : ''; ?>"
placeholder="contoh: berita, pengumuman, galeri">
</div>
<small class="text-muted">Hanya huruf kecil, angka, dan tanda hubung (-)</small>
</div>
</div>
<!-- Slug dengan Prefix Dinamis -->
<div class="mb-3">
<label class="form-label fw-bold">Slug (URL)</label>
<div class="input-group">
<span class="input-group-text" id="url_prefix_display">
/<?php echo htmlspecialchars($page['url_prefix'] ?? 'halaman'); ?>/
</span>
<input type="text" class="form-control" name="slug" id="slug"
value="<?php echo htmlspecialchars($page['slug']); ?>"
placeholder="nama-halaman-anda">
</div>
<small class="text-muted">
Biarkan kosong untuk generate otomatis dari judul.<br>
<strong>Preview URL:</strong>
<code id="url_preview">
http://localhost:8080/bpkd/<?php echo htmlspecialchars($page['url_prefix'] ?? 'halaman'); ?>/<?php echo htmlspecialchars($page['slug']); ?>
</code>
</small>
</div>
</div>
</div>
<!-- Content with CKEditor -->
<div class="mb-3">
<label class="form-label">Konten <span class="text-danger">*</span></label>
<textarea id="content-editor" name="content" rows="15"><?php echo htmlspecialchars($page['content']); ?></textarea>
</div>
<!-- Excerpt -->
<div class="mb-3">
<label class="form-label">Ringkasan (Excerpt)</label>
<textarea class="form-control" name="excerpt" rows="3"><?php echo htmlspecialchars($page['excerpt']); ?></textarea>
<small class="text-muted">Max 160 karakter untuk meta description</small>
</div>
</div>
<div class="col-md-4">
<!-- Publish Status -->
<div class="card mb-3">
<div class="card-header">
<h6 class="mb-0"><i class="fas fa-globe me-2"></i>Publish</h6>
</div>
<div class="card-body">
<div class="mb-3">
<label class="form-label">Status</label>
<select class="form-control" name="status">
<option value="published" <?php echo $page['status'] == 'published' ? 'selected' : ''; ?>>Published</option>
<option value="draft" <?php echo $page['status'] == 'draft' ? 'selected' : ''; ?>>Draft</option>
</select>
</div>
<div class="mb-3">
<label class="form-label">Dibuat pada</label>
<p class="form-control-static"><?php echo date('d M Y H:i', strtotime($page['created_at'])); ?></p>
</div>
<button type="submit" class="btn btn-primary w-100">
<i class="fas fa-save me-2"></i>Update Halaman
</button>
</div>
</div>
<!-- Page Settings -->
<div class="card mb-3">
<div class="card-header">
<h6 class="mb-0"><i class="fas fa-cog me-2"></i>Pengaturan Halaman</h6>
</div>
<div class="card-body">
<div class="mb-3">
<label class="form-label">Induk Halaman</label>
<select class="form-control" name="parent_id">
<option value="0">Tidak Ada (Halaman Utama)</option>
<?php while($parent = $parent_pages->fetch_assoc()): ?>
<option value="<?php echo $parent['id']; ?>" <?php echo $parent['id'] == $page['parent_id'] ? 'selected' : ''; ?>>
<?php echo $parent['title']; ?>
</option>
<?php endwhile; ?>
</select>
</div>
<div class="mb-3">
<label class="form-label">Template</label>
<select class="form-control" name="template">
<option value="default" <?php echo $page['template'] == 'default' ? 'selected' : ''; ?>>Default</option>
<option value="fullwidth" <?php echo $page['template'] == 'fullwidth' ? 'selected' : ''; ?>>Full Width</option>
<option value="sidebar" <?php echo $page['template'] == 'sidebar' ? 'selected' : ''; ?>>Dengan Sidebar</option>
<option value="contact" <?php echo $page['template'] == 'contact' ? 'selected' : ''; ?>>Kontak</option>
</select>
</div>
</div>
</div>
<!-- Featured File -->
<div class="card mb-3">
<div class="card-header">
<h6 class="mb-0"><i class="fas fa-paperclip me-2"></i>File Utama (Gambar/PDF)</h6>
</div>
<div class="card-body">
<?php if (!empty($page['featured_image'])): ?>
<div class="current-file mb-3">
<label class="form-label">File Saat Ini:</label>
<?php
$current_file_type = $page['file_type'] ?? '';
$is_image = in_array($current_file_type, ['jpg', 'jpeg', 'png', 'gif', 'webp']);
if ($is_image): ?>
<img src="../<?php echo $page['featured_image']; ?>"
alt="Current"
class="img-fluid rounded border mb-2"
style="max-height: 150px; width: 100%; object-fit: cover;">
<?php elseif ($current_file_type == 'pdf'): ?>
<div class="alert alert-info p-3">
<i class="fas fa-file-pdf fa-2x me-2 text-danger"></i>
<strong>PDF:</strong> <?php echo basename($page['featured_image']); ?>
<br>
<a href="../<?php echo $page['featured_image']; ?>" target="_blank" class="btn btn-sm btn-primary mt-2">
<i class="fas fa-download me-1"></i>Lihat PDF
</a>
</div>
<?php else: ?>
<div class="alert alert-secondary p-3">
<i class="fas fa-file fa-2x me-2"></i>
<strong>File:</strong> <?php echo basename($page['featured_image']); ?>
<br>
<a href="../<?php echo $page['featured_image']; ?>" target="_blank" class="btn btn-sm btn-secondary mt-2">
<i class="fas fa-external-link-alt me-1"></i>Lihat File
</a>
</div>
<?php endif; ?>
<div class="form-check mt-2">
<input class="form-check-input" type="checkbox" name="remove_file" id="remove_file" value="1">
<label class="form-check-label text-danger" for="remove_file">
<i class="fas fa-trash me-1"></i> Hapus file ini
</label>
</div>
</div>
<?php endif; ?>
<label class="form-label">Ganti File</label>
<input type="file" class="form-control" name="featured_file"
accept="image/*,.pdf" id="featuredFile">
<small class="text-muted d-block mt-2">
<i class="fas fa-info-circle me-1"></i>Format: JPG, PNG, GIF, WEBP, PDF. Maks 5MB
</small>
<div class="featured-image-preview mt-3" id="imagePreview" style="display: none;">
<img src="" alt="Preview" id="previewImg" class="img-fluid rounded">
</div>
<div class="pdf-preview mt-3" id="pdfPreview" style="display: none;">
<div class="alert alert-info p-3">
<i class="fas fa-file-pdf fa-2x me-2 text-danger"></i>
<strong>File PDF:</strong> <span id="pdfName"></span>
</div>
</div>
</div>
</div>
<!-- SEO Preview -->
<div class="card mb-3">
<div class="card-header">
<h6 class="mb-0"><i class="fas fa-search me-2"></i>Pratinjau SEO</h6>
</div>
<div class="card-body">
<div class="seo-preview p-3 bg-light rounded">
<div class="text-primary small">http://localhost/bpkd/</div>
<div class="fw-bold text-success" id="seoUrl">
<?php echo htmlspecialchars($page['url_prefix'] ?? 'halaman'); ?>/<?php echo htmlspecialchars($page['slug']); ?>
</div>
<div class="fw-bold text-primary mt-2" id="seoTitle"><?php echo htmlspecialchars($page['title']); ?></div>
<div class="small text-muted mt-1" id="seoDesc">
<?php echo htmlspecialchars($page['excerpt'] ?: 'Ringkasan halaman akan muncul di sini...'); ?>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<!-- CKEditor 5 -->
<script src="https://cdn.ckeditor.com/ckeditor5/39.0.1/classic/ckeditor.js"></script>
<script>
// CKEditor Configuration
ClassicEditor
.create(document.querySelector('#content-editor'), {
language: 'id',
toolbar: [
'heading', '|',
'bold', 'italic', 'underline', 'strikethrough', '|',
'bulletedList', 'numberedList', '|',
'alignment', '|',
'indent', 'outdent', '|',
'link', 'blockQuote', 'insertTable', '|',
'undo', 'redo'
],
placeholder: 'Lanjutkan menulis konten halaman...',
removePlugins: ['Title']
})
.then(editor => {
window.editor = editor;
})
.catch(error => {
console.error(error);
});
// URL Prefix handling
const urlPrefixSelect = document.getElementById('url_prefix');
const customPrefixContainer = document.getElementById('custom_prefix_container');
const customPrefixInput = document.getElementById('custom_prefix');
const slugInput = document.getElementById('slug');
const urlPrefixDisplay = document.getElementById('url_prefix_display');
const seoUrl = document.getElementById('seoUrl');
const urlPreview = document.getElementById('url_preview');
// Toggle custom prefix field
if (urlPrefixSelect) {
urlPrefixSelect.addEventListener('change', function() {
if (this.value === 'custom') {
customPrefixContainer.style.display = 'block';
} else {
customPrefixContainer.style.display = 'none';
}
updateUrlPreview();
});
}
// Update URL preview function
function updateUrlPreview() {
let prefix = '';
if (urlPrefixSelect && urlPrefixSelect.value === 'custom') {
const customPrefix = customPrefixInput ? customPrefixInput.value.trim() : '';
prefix = customPrefix ? customPrefix : 'halaman';
} else if (urlPrefixSelect) {
prefix = urlPrefixSelect.value;
} else {
prefix = '<?php echo $page['url_prefix'] ?? 'halaman'; ?>';
}
const slug = slugInput ? slugInput.value.trim() || '<?php echo $page['slug']; ?>' : '<?php echo $page['slug']; ?>';
const fullUrl = prefix + '/' + slug;
if (urlPrefixDisplay) {
urlPrefixDisplay.textContent = '/' + prefix + '/';
}
if (seoUrl) {
seoUrl.textContent = fullUrl;
}
if (urlPreview) {
urlPreview.textContent = 'http://localhost/bpkd/' + fullUrl;
}
}
// Update SEO preview
function updateSEOPreview() {
const title = document.getElementById('title') ? document.getElementById('title').value : '<?php echo addslashes($page['title']); ?>';
const excerpt = document.querySelector('textarea[name="excerpt"]') ?
(document.querySelector('textarea[name="excerpt"]').value || 'Ringkasan halaman akan muncul di sini...') :
'Ringkasan halaman akan muncul di sini...';
const seoTitle = document.getElementById('seoTitle');
const seoDesc = document.getElementById('seoDesc');
if (seoTitle) seoTitle.textContent = title;
if (seoDesc) seoDesc.textContent = excerpt;
updateUrlPreview();
}
// Generate slug from title
const titleInput = document.getElementById('title');
if (titleInput && slugInput) {
titleInput.addEventListener('keyup', function() {
if (slugInput.value === '' || slugInput.value === '<?php echo $page['slug']; ?>') {
const slug = this.value.toLowerCase()
.replace(/[^a-z0-9\s]/g, '')
.replace(/\s+/g, '-')
.replace(/-+/g, '-')
.replace(/^-|-$/g, '');
slugInput.value = slug;
updateSEOPreview();
}
});
}
// Update on input events
if (slugInput) slugInput.addEventListener('input', updateUrlPreview);
if (customPrefixInput) customPrefixInput.addEventListener('input', updateUrlPreview);
if (titleInput) titleInput.addEventListener('input', updateSEOPreview);
const excerptTextarea = document.querySelector('textarea[name="excerpt"]');
if (excerptTextarea) excerptTextarea.addEventListener('input', updateSEOPreview);
// File preview
const featuredFile = document.getElementById('featuredFile');
if (featuredFile) {
featuredFile.addEventListener('change', function(e) {
const file = e.target.files[0];
if (!file) return;
if (file.size > 5 * 1024 * 1024) {
alert('Ukuran file maksimal 5MB!');
this.value = '';
return;
}
const fileExt = file.name.split('.').pop().toLowerCase();
const isImage = ['jpg', 'jpeg', 'png', 'gif', 'webp'].includes(fileExt);
const isPdf = fileExt === 'pdf';
const imagePreview = document.getElementById('imagePreview');
const pdfPreview = document.getElementById('pdfPreview');
const previewImg = document.getElementById('previewImg');
const pdfName = document.getElementById('pdfName');
if (isImage && imagePreview && previewImg) {
const reader = new FileReader();
reader.onload = function(e) {
imagePreview.style.display = 'block';
if (pdfPreview) pdfPreview.style.display = 'none';
previewImg.src = e.target.result;
}
reader.readAsDataURL(file);
} else if (isPdf && pdfPreview && pdfName) {
if (imagePreview) imagePreview.style.display = 'none';
pdfPreview.style.display = 'block';
pdfName.textContent = file.name;
} else {
alert('Format file tidak didukung! Gunakan gambar atau PDF.');
this.value = '';
}
});
}
// Initial update
updateUrlPreview();
</script>
<style>
.featured-image-preview img {
max-width: 100%;
max-height: 200px;
object-fit: cover;
border: 1px solid #e9ecef;
border-radius: 5px;
}
.pdf-preview .alert {
border-left: 4px solid #dc3545;
}
.seo-preview {
border: 1px solid #e9ecef;
}
.ck-editor__editable {
min-height: 400px !important;
}
</style>
<?php require_once 'includes/footer.php'; ?>