| 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 : D:/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');
}
// 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);
}
// Cek apakah slug sudah digunakan oleh halaman lain
$check_slug = $conn->query("SELECT id FROM pages WHERE slug = '$slug' AND id != $id");
if ($check_slug->num_rows > 0) {
$slug = $slug . '-' . rand(100, 999);
}
// Handle file upload (support gambar dan PDF)
$featured_file = $page['featured_image'];
$file_type = $page['file_type'] ?? '';
if (isset($_FILES['featured_file']) && $_FILES['featured_file']['error'] == 0) {
$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)) {
// Delete old 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',
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;
}
}
}
?>
<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>
<a href="../halaman/<?php echo $page['slug']; ?>" 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; ?>
<form method="POST" enctype="multipart/form-data" id="pageForm">
<div class="row">
<!-- Main Content Column -->
<div class="col-lg-8">
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">
<i class="fas fa-edit me-2"></i>Konten Halaman
</h6>
</div>
<div class="card-body">
<!-- Title -->
<div class="mb-3">
<label class="form-label fw-bold">
Judul Halaman <span class="text-danger">*</span>
</label>
<input type="text" class="form-control form-control-lg" name="title"
value="<?php echo htmlspecialchars($page['title']); ?>" required>
</div>
<!-- Slug -->
<div class="mb-3">
<label class="form-label fw-bold">
Slug (URL)
</label>
<div class="input-group">
<span class="input-group-text"><?php echo $_SERVER['HTTP_HOST']; ?>/halaman/</span>
<input type="text" class="form-control" name="slug"
value="<?php echo htmlspecialchars($page['slug']); ?>"
placeholder="nama-halaman-anda">
</div>
<small class="text-muted">Biarkan kosong untuk generate otomatis dari judul</small>
</div>
<!-- Content with CKEditor -->
<div class="mb-3">
<label class="form-label fw-bold">
Konten <span class="text-danger">*</span>
</label>
<textarea id="content-editor" name="content" rows="20"><?php echo htmlspecialchars($page['content']); ?></textarea>
</div>
<!-- Excerpt -->
<div class="mb-3">
<label class="form-label fw-bold">
Ringkasan (Excerpt)
</label>
<textarea class="form-control" name="excerpt" rows="4"
placeholder="Ringkasan singkat halaman (untuk SEO)"><?php echo htmlspecialchars($page['excerpt']); ?></textarea>
<small class="text-muted">Ringkasan akan muncul di meta description dan hasil pencarian</small>
</div>
</div>
</div>
</div>
<!-- Sidebar Column -->
<div class="col-lg-4">
<!-- Publish Box -->
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">
<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">Urutan Menu</label>
<input type="number" class="form-control" name="menu_order"
value="<?php echo $page['menu_order']; ?>" min="0">
<small class="text-muted">Semakin kecil angka, semakin atas posisinya</small>
</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>
<div class="mb-3">
<label class="form-label">Terakhir diupdate</label>
<p class="form-control-static">
<?php echo date('d M Y H:i', strtotime($page['updated_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 shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">
<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
if ($parent_pages && $parent_pages->num_rows > 0) {
while($parent = $parent_pages->fetch_assoc()):
?>
<option value="<?php echo $parent['id']; ?>"
<?php echo $parent['id'] == $page['parent_id'] ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($parent['title']); ?>
</option>
<?php
endwhile;
}
?>
</select>
<small class="text-muted">Membuat halaman ini menjadi sub-halaman</small>
</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>
<option value="blank" <?php echo $page['template'] == 'blank' ? 'selected' : ''; ?>>Blank (Kosong)</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
$is_image = in_array($page['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 else: ?>
<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 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>
<!-- Preview untuk Gambar Baru -->
<div class="featured-image-preview mt-3" id="imagePreview" style="display: none;">
<img src="" alt="Preview" id="previewImg" class="img-fluid rounded">
</div>
<!-- Preview untuk PDF Baru -->
<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 shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">
<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"><?php echo $_SERVER['HTTP_HOST']; ?>/halaman/</div>
<div class="fw-bold text-success" id="seoUrl"><?php echo $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 class="mt-2 small text-muted">
<i class="fas fa-lightbulb me-1"></i>Judul 50-60 karakter, deskripsi 150-160 karakter untuk SEO optimal
</div>
</div>
</div>
</div>
</div>
</form>
</div>
<!-- Loading Overlay -->
<div class="loading-overlay" id="loadingOverlay">
<div class="loading-spinner"></div>
</div>
<!-- CKEditor 5 -->
<script src="https://cdn.ckeditor.com/ckeditor5/39.0.1/classic/ckeditor.js"></script>
<script src="https://cdn.ckeditor.com/ckeditor5/39.0.1/classic/translations/id.js"></script>
<style>
/* Custom styles untuk form halaman */
.current-image {
position: relative;
}
.current-image img {
transition: all 0.3s;
}
.current-image:hover img {
opacity: 0.9;
}
.featured-image-preview {
position: relative;
border-radius: 5px;
overflow: hidden;
}
.featured-image-preview img {
width: 100%;
max-height: 200px;
object-fit: cover;
}
.loading-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(255,255,255,0.8);
display: none;
justify-content: center;
align-items: center;
z-index: 9999;
}
.loading-overlay.active {
display: flex;
}
.loading-spinner {
width: 50px;
height: 50px;
border: 5px solid #f3f3f3;
border-top: 5px solid #4e73df;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.seo-preview {
border: 1px solid #e9ecef;
}
</style>
<script>
// CKEditor Configuration
ClassicEditor
.create(document.querySelector('#content-editor'), {
language: 'id',
toolbar: {
items: [
'heading', '|',
'bold', 'italic', 'underline', 'strikethrough', '|',
'bulletedList', 'numberedList', '|',
'alignment', '|',
'indent', 'outdent', '|',
'link', 'blockQuote', 'insertTable', '|',
'undo', 'redo', '|',
'fontFamily', 'fontSize', 'fontColor', 'fontBackgroundColor', '|',
'codeBlock', 'subscript', 'superscript', '|',
'horizontalLine', 'pageBreak', '|',
'specialCharacters'
],
shouldNotGroupWhenFull: true
},
image: {
toolbar: [
'imageStyle:inline',
'imageStyle:block',
'imageStyle:side',
'|',
'toggleImageCaption',
'imageTextAlternative',
'|',
'linkImage'
]
},
table: {
contentToolbar: [
'tableColumn',
'tableRow',
'mergeTableCells',
'tableCellProperties',
'tableProperties'
]
},
heading: {
options: [
{ model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph' },
{ model: 'heading1', view: 'h1', title: 'Heading 1', class: 'ck-heading_heading1' },
{ model: 'heading2', view: 'h2', title: 'Heading 2', class: 'ck-heading_heading2' },
{ model: 'heading3', view: 'h3', title: 'Heading 3', class: 'ck-heading_heading3' },
{ model: 'heading4', view: 'h4', title: 'Heading 4', class: 'ck-heading_heading4' },
{ model: 'heading5', view: 'h5', title: 'Heading 5', class: 'ck-heading_heading5' },
{ model: 'heading6', view: 'h6', title: 'Heading 6', class: 'ck-heading_heading6' }
]
},
placeholder: 'Mulai menulis konten halaman di sini...',
removePlugins: ['Title']
})
.then(editor => {
window.editor = editor;
})
.catch(error => {
console.error(error);
alert('Gagal memuat editor: ' + error.message);
});
// Generate slug from title
document.querySelector('input[name="title"]').addEventListener('keyup', function() {
const titleInput = document.querySelector('input[name="slug"]');
if (titleInput.value === '') {
const slug = this.value.toLowerCase()
.replace(/[^a-z0-9\s]/g, '')
.replace(/\s+/g, '-')
.replace(/-+/g, '-')
.replace(/^-|-$/g, '');
titleInput.value = slug;
}
updateSEOPreview();
});
// Update SEO preview on input
document.querySelector('input[name="title"]').addEventListener('input', updateSEOPreview);
document.querySelector('input[name="slug"]').addEventListener('input', updateSEOPreview);
document.querySelector('textarea[name="excerpt"]').addEventListener('input', updateSEOPreview);
function updateSEOPreview() {
const title = document.querySelector('input[name="title"]').value || 'Judul Halaman';
const slug = document.querySelector('input[name="slug"]').value || 'nama-halaman';
const excerpt = document.querySelector('textarea[name="excerpt"]').value || 'Ringkasan halaman akan muncul di sini...';
document.getElementById('seoTitle').textContent = title;
document.getElementById('seoUrl').textContent = slug;
document.getElementById('seoDesc').textContent = excerpt;
}
// Featured image preview
document.getElementById('featuredImage').addEventListener('change', function(e) {
const file = e.target.files[0];
if (file) {
// Validasi ukuran file
if (file.size > 2 * 1024 * 1024) {
alert('Ukuran file maksimal 2MB!');
this.value = '';
return;
}
const reader = new FileReader();
reader.onload = function(e) {
const preview = document.getElementById('imagePreview');
document.getElementById('previewImg').src = e.target.result;
preview.style.display = 'block';
}
reader.readAsDataURL(file);
}
});
// Remove image function
function removeImage() {
if (confirm('Hapus gambar ini?')) {
document.getElementById('remove_image').value = '1';
document.querySelector('.current-image').style.display = 'none';
}
}
// Form submit with loading
document.getElementById('pageForm').addEventListener('submit', function() {
document.getElementById('loadingOverlay').classList.add('active');
});
// Confirmation before leaving if form dirty
let formChanged = false;
document.querySelectorAll('input, textarea, select').forEach(element => {
element.addEventListener('change', () => formChanged = true);
});
window.addEventListener('beforeunload', function(e) {
if (formChanged) {
e.preventDefault();
e.returnValue = 'Perubahan belum disimpan. Yakin ingin meninggalkan halaman ini?';
}
});
// Character counter for excerpt
const excerptInput = document.querySelector('textarea[name="excerpt"]');
excerptInput.addEventListener('input', function() {
const length = this.value.length;
let counter = document.querySelector('.excerpt-counter');
if (!counter) {
counter = document.createElement('small');
counter.className = 'excerpt-counter text-muted float-end';
this.parentNode.appendChild(counter);
}
counter.textContent = length + '/300';
if (length > 280) counter.style.color = '#e74a3b';
else if (length > 250) counter.style.color = '#f6c23e';
else counter.style.color = '#6c757d';
});
// File preview function (same as page-add.php)
document.getElementById('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';
if (isImage) {
const reader = new FileReader();
reader.onload = function(e) {
document.getElementById('imagePreview').style.display = 'block';
document.getElementById('pdfPreview').style.display = 'none';
document.getElementById('previewImg').src = e.target.result;
}
reader.readAsDataURL(file);
} else if (isPdf) {
document.getElementById('imagePreview').style.display = 'none';
document.getElementById('pdfPreview').style.display = 'block';
document.getElementById('pdfName').textContent = file.name;
} else {
alert('Format file tidak didukung! Gunakan gambar atau PDF.');
this.value = '';
}
});
</script>
<?php require_once 'includes/footer.php'; ?>