| 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/admin/ |
Upload File : |
<?php
$page_title = 'Manajemen Media Galeri';
require_once 'config/database.php';
require_once '../includes/config.php'; // Load BASE_URL
require_once 'includes/init.php';
requireLogin();
// =====================================================
// KONFIGURASI UPLOAD
// =====================================================
$target_dir = dirname(__DIR__) . "/uploads/gallery/";
$allowed_image_types = ['jpg', 'jpeg', 'png', 'gif', 'webp'];
$allowed_video_types = ['mp4', 'webm', 'ogg'];
$max_file_size = 10 * 1024 * 1024; // 10MB
$max_image_size = 5 * 1024 * 1024; // 5MB
// Buat folder jika belum ada
if (!file_exists($target_dir)) {
mkdir($target_dir, 0777, true);
}
// =====================================================
// HANDLE UPLOAD FILE
// =====================================================
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['upload'])) {
$title = sanitize($_POST['title'] ?? '');
$description = sanitize($_POST['description'] ?? '');
$category = sanitize($_POST['category'] ?? '');
$type = $_POST['type'] ?? 'image';
$video_url = sanitize($_POST['video_url'] ?? '');
$status = sanitize($_POST['status'] ?? 'active');
$featured = isset($_POST['featured']) ? 1 : 0;
$errors = [];
$upload_success = false;
// Validasi berdasarkan tipe
if ($type == 'video' && !empty($video_url)) {
// Handle video from URL (YouTube, etc)
$video_id = '';
if (strpos($video_url, 'youtube.com') !== false || strpos($video_url, 'youtu.be') !== false) {
// Extract YouTube ID
preg_match('/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/', $video_url, $matches);
if (isset($matches[1])) {
$video_id = $matches[1];
$video_url = 'https://www.youtube.com/embed/' . $video_id;
}
}
$filename = 'youtube_' . time() . '_' . uniqid();
$filepath = $video_url;
$filesize = 0;
$filetype = 'video/youtube';
// Simpan ke database
$query = "INSERT INTO gallery (title, description, image, category, type, video_url, status, featured, created_at)
VALUES ('$title', '$description', '$filename', '$category', 'video', '$video_url', '$status', $featured, NOW())";
if ($conn->query($query)) {
$upload_success = true;
$success_message = "Video berhasil ditambahkan!";
} else {
$errors[] = "Gagal menyimpan video: " . $conn->error;
}
} elseif ($type == 'image' && isset($_FILES['image_file']) && $_FILES['image_file']['error'] == 0) {
// Handle image upload
$file = $_FILES['image_file'];
$file_ext = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
$file_size = $file['size'];
// Validasi tipe file
if (!in_array($file_ext, $allowed_image_types)) {
$errors[] = "Tipe file tidak diizinkan. Gunakan: " . implode(', ', $allowed_image_types);
}
// Validasi ukuran file
if ($file_size > $max_image_size) {
$errors[] = "Ukuran file maksimal " . ($max_image_size / 1024 / 1024) . "MB";
}
if (empty($errors)) {
// Buat nama file unik
$new_filename = time() . '_' . uniqid() . '.' . $file_ext;
$target_file = $target_dir . $new_filename;
if (move_uploaded_file($file['tmp_name'], $target_file)) {
// Simpan ke database
$filepath = 'uploads/gallery/' . $new_filename;
$query = "INSERT INTO gallery (title, description, image, category, type, status, featured, created_at)
VALUES ('$title', '$description', '$filepath', '$category', 'image', '$status', $featured, NOW())";
if ($conn->query($query)) {
$upload_success = true;
$success_message = "Gambar berhasil diupload!";
} else {
$errors[] = "Gagal menyimpan ke database: " . $conn->error;
}
} else {
$errors[] = "Gagal mengupload file";
}
}
} else {
$errors[] = "Silakan pilih file atau masukkan URL video";
}
if (!empty($errors)) {
$error_message = implode('<br>', $errors);
}
}
// =====================================================
// HANDLE EDIT
// =====================================================
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['edit'])) {
$id = (int)$_POST['id'];
$title = sanitize($_POST['title']);
$description = sanitize($_POST['description']);
$category = sanitize($_POST['category']);
$status = sanitize($_POST['status']);
$featured = isset($_POST['featured']) ? 1 : 0;
$query = "UPDATE gallery SET
title = '$title',
description = '$description',
category = '$category',
status = '$status',
featured = $featured
WHERE id = $id";
if ($conn->query($query)) {
$success_message = "Data berhasil diupdate!";
} else {
$error_message = "Gagal mengupdate: " . $conn->error;
}
}
// =====================================================
// HANDLE DELETE
// =====================================================
if (isset($_GET['delete'])) {
$id = (int)$_GET['delete'];
// Ambil data untuk hapus file
$item = $conn->query("SELECT * FROM gallery WHERE id = $id")->fetch_assoc();
if ($item && $item['type'] == 'image' && !empty($item['image'])) {
$file_path = dirname(__DIR__) . "/" . $item['image'];
if (file_exists($file_path)) {
unlink($file_path);
}
}
if ($conn->query("DELETE FROM gallery WHERE id = $id")) {
$success_message = "Item berhasil dihapus!";
redirect(BASE_URL . '/admin/media.php?msg=deleted');
} else {
$error_message = "Gagal menghapus: " . $conn->error;
}
}
// =====================================================
// HANDLE TOGGLE FEATURED
// =====================================================
if (isset($_GET['toggle_featured'])) {
$id = (int)$_GET['toggle_featured'];
$current = $conn->query("SELECT featured FROM gallery WHERE id = $id")->fetch_assoc();
$new_value = $current['featured'] ? 0 : 1;
$conn->query("UPDATE gallery SET featured = $new_value WHERE id = $id");
redirect(BASE_URL . '/admin/media.php');
}
// =====================================================
// PAGINATION SETUP
// =====================================================
$limit = 12;
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
if ($page < 1) $page = 1;
$offset = ($page - 1) * $limit;
// =====================================================
// FILTER
// =====================================================
$type_filter = isset($_GET['type']) ? sanitize($_GET['type']) : '';
$category_filter = isset($_GET['category']) ? sanitize($_GET['category']) : '';
$status_filter = isset($_GET['status']) ? sanitize($_GET['status']) : '';
// Build WHERE clause
$where = ["1=1"];
if (!empty($type_filter)) {
$where[] = "type = '$type_filter'";
}
if (!empty($category_filter)) {
$where[] = "category = '$category_filter'";
}
if (!empty($status_filter)) {
$where[] = "status = '$status_filter'";
}
$where_clause = implode(' AND ', $where);
// =====================================================
// GET TOTAL RECORDS
// =====================================================
$total_query = "SELECT COUNT(*) as total FROM gallery WHERE $where_clause";
$total_result = $conn->query($total_query);
$total_records = $total_result->fetch_assoc()['total'];
$total_pages = ceil($total_records / $limit);
// =====================================================
// GET GALLERY ITEMS
// =====================================================
$items = $conn->query("
SELECT * FROM gallery
WHERE $where_clause
ORDER BY featured DESC, created_at DESC
LIMIT $offset, $limit
");
// =====================================================
// GET UNIQUE CATEGORIES FOR FILTER
// =====================================================
$categories = $conn->query("SELECT DISTINCT category FROM gallery WHERE category != '' ORDER BY category");
// 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">
<i class="fas fa-images me-2"></i>Manajemen Media Galeri
</h1>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#uploadModal">
<i class="fas fa-upload me-2"></i>Upload Media Baru
</button>
</div>
<!-- Success/Error Messages -->
<?php if (isset($success_message)): ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<i class="fas fa-check-circle me-2"></i><?php echo $success_message; ?>
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php endif; ?>
<?php if (isset($error_message)): ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<i class="fas fa-exclamation-circle me-2"></i><?php echo $error_message; ?>
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php endif; ?>
<!-- Filter Card -->
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-white">
<i class="fas fa-filter me-2"></i>Filter
</h6>
</div>
<div class="card-body">
<form method="GET" class="row g-3">
<div class="col-md-3">
<label class="form-label">Tipe</label>
<select class="form-control" name="type">
<option value="">Semua Tipe</option>
<option value="image" <?php echo $type_filter == 'image' ? 'selected' : ''; ?>>Gambar</option>
<option value="video" <?php echo $type_filter == 'video' ? 'selected' : ''; ?>>Video</option>
</select>
</div>
<div class="col-md-3">
<label class="form-label">Kategori</label>
<select class="form-control" name="category">
<option value="">Semua Kategori</option>
<?php while($cat = $categories->fetch_assoc()): ?>
<option value="<?php echo $cat['category']; ?>" <?php echo $category_filter == $cat['category'] ? 'selected' : ''; ?>>
<?php echo $cat['category']; ?>
</option>
<?php endwhile; ?>
</select>
</div>
<div class="col-md-3">
<label class="form-label">Status</label>
<select class="form-control" name="status">
<option value="">Semua Status</option>
<option value="active" <?php echo $status_filter == 'active' ? 'selected' : ''; ?>>Aktif</option>
<option value="inactive" <?php echo $status_filter == 'inactive' ? 'selected' : ''; ?>>Tidak Aktif</option>
</select>
</div>
<div class="col-md-3">
<label class="form-label">Aksi</label>
<div class="d-flex">
<button type="submit" class="btn btn-primary me-2">
<i class="fas fa-filter me-2"></i>Filter
</button>
<a href="<?php echo BASE_URL; ?>/admin/media.php" class="btn btn-secondary">
<i class="fas fa-sync-alt"></i>
</a>
</div>
</div>
</form>
</div>
</div>
<!-- Gallery Grid -->
<div class="card shadow mb-4">
<div class="card-header py-3 d-flex justify-content-between align-items-center">
<h6 class="m-0 font-weight-bold text-white">
<i class="fas fa-th me-2"></i>Daftar Media
<span class="badge bg-primary ms-2"><?php echo $total_records; ?> Total</span>
</h6>
<?php if ($total_pages > 1): ?>
<div class="pagination-info">
Halaman <?php echo $page; ?> dari <?php echo $total_pages; ?>
</div>
<?php endif; ?>
</div>
<div class="card-body">
<?php if ($items && $items->num_rows > 0): ?>
<div class="row" id="gallery-grid">
<?php while($item = $items->fetch_assoc()): ?>
<div class="col-xl-3 col-lg-4 col-md-6 mb-4">
<div class="card gallery-card h-100">
<div class="card-img-top position-relative" style="height: 180px; overflow: hidden;">
<?php if ($item['type'] == 'video'): ?>
<!-- Video Thumbnail -->
<?php if (!empty($item['image']) && strpos($item['image'], 'youtube') !== false): ?>
<img src="https://img.youtube.com/vi/<?php echo getYouTubeId($item['video_url']); ?>/hqdefault.jpg"
alt="<?php echo htmlspecialchars($item['title']); ?>"
style="width: 100%; height: 100%; object-fit: cover;">
<?php else: ?>
<div class="bg-secondary text-white d-flex align-items-center justify-content-center h-100">
<i class="fas fa-video fa-3x"></i>
</div>
<?php endif; ?>
<div class="position-absolute top-50 start-50 translate-middle">
<i class="fas fa-play-circle fa-3x text-white" style="opacity: 0.8;"></i>
</div>
<?php else: ?>
<!-- Image -->
<img src="<?php echo BASE_URL; ?>/<?php echo $item['image']; ?>"
alt="<?php echo htmlspecialchars($item['title']); ?>"
style="width: 100%; height: 100%; object-fit: cover;">
<?php endif; ?>
<!-- Featured Badge -->
<?php if ($item['featured']): ?>
<span class="position-absolute top-0 start-0 badge bg-warning m-2">
<i class="fas fa-star me-1"></i>Featured
</span>
<?php endif; ?>
<!-- Type Badge -->
<span class="position-absolute top-0 end-0 badge bg-<?php echo $item['type'] == 'video' ? 'danger' : 'primary'; ?> m-2">
<i class="fas fa-<?php echo $item['type'] == 'video' ? 'video' : 'camera'; ?> me-1"></i>
<?php echo ucfirst($item['type']); ?>
</span>
</div>
<div class="card-body">
<h6 class="card-title text-truncate"><?php echo htmlspecialchars($item['title']); ?></h6>
<?php if (!empty($item['category'])): ?>
<small class="text-muted d-block">
<i class="fas fa-tag me-1"></i><?php echo $item['category']; ?>
</small>
<?php endif; ?>
<small class="text-muted d-block">
<i class="far fa-calendar me-1"></i><?php echo date('d M Y', strtotime($item['created_at'])); ?>
</small>
<div class="mt-2">
<span class="badge bg-<?php echo $item['status'] == 'active' ? 'success' : 'secondary'; ?>">
<?php echo $item['status'] == 'active' ? 'Aktif' : 'Tidak Aktif'; ?>
</span>
</div>
</div>
<div class="card-footer bg-transparent">
<div class="btn-group w-100">
<button type="button" class="btn btn-sm btn-info" onclick="editItem(<?php echo $item['id']; ?>)">
<i class="fas fa-edit"></i> Edit
</button>
<a href="<?php echo BASE_URL; ?>/admin/media.php?toggle_featured=<?php echo $item['id']; ?>"
class="btn btn-sm btn-<?php echo $item['featured'] ? 'warning' : 'secondary'; ?>"
title="<?php echo $item['featured'] ? 'Hapus dari Featured' : 'Jadikan Featured'; ?>">
<i class="fas fa-star"></i>
</a>
<a href="<?php echo BASE_URL; ?>/admin/media.php?delete=<?php echo $item['id']; ?>"
class="btn btn-sm btn-danger"
onclick="return confirm('Yakin ingin menghapus item ini?')">
<i class="fas fa-trash"></i>
</a>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
<!-- Pagination -->
<?php if ($total_pages > 1): ?>
<nav aria-label="Page navigation" class="mt-4">
<ul class="pagination justify-content-center">
<li class="page-item <?php echo $page <= 1 ? 'disabled' : ''; ?>">
<a class="page-link" href="<?php echo BASE_URL; ?>/admin/media.php?page=1&type=<?php echo urlencode($type_filter); ?>&category=<?php echo urlencode($category_filter); ?>&status=<?php echo urlencode($status_filter); ?>">
<i class="fas fa-angle-double-left"></i>
</a>
</li>
<?php for($i = 1; $i <= $total_pages; $i++): ?>
<li class="page-item <?php echo $i == $page ? 'active' : ''; ?>">
<a class="page-link" href="<?php echo BASE_URL; ?>/admin/media.php?page=<?php echo $i; ?>&type=<?php echo urlencode($type_filter); ?>&category=<?php echo urlencode($category_filter); ?>&status=<?php echo urlencode($status_filter); ?>">
<?php echo $i; ?>
</a>
</li>
<?php endfor; ?>
<li class="page-item <?php echo $page >= $total_pages ? 'disabled' : ''; ?>">
<a class="page-link" href="<?php echo BASE_URL; ?>/admin/media.php?page=<?php echo $page+1; ?>&type=<?php echo urlencode($type_filter); ?>&category=<?php echo urlencode($category_filter); ?>&status=<?php echo urlencode($status_filter); ?>">
<i class="fas fa-angle-double-right"></i>
</a>
</li>
</ul>
</nav>
<?php endif; ?>
<?php else: ?>
<div class="text-center py-5">
<i class="fas fa-images fa-4x text-muted mb-3"></i>
<h5>Belum Ada Media</h5>
<p class="text-muted">Klik tombol "Upload Media Baru" untuk menambahkan foto atau video.</p>
</div>
<?php endif; ?>
</div>
</div>
</div>
<!-- Upload Modal -->
<div class="modal fade" id="uploadModal" tabindex="-1" data-bs-backdrop="static">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<form method="POST" enctype="multipart/form-data" id="uploadForm" action="<?php echo BASE_URL; ?>/admin/media.php">
<div class="modal-header">
<h5 class="modal-title">
<i class="fas fa-upload me-2"></i>Upload Media Baru
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<!-- Media Type Selection -->
<div class="mb-3">
<label class="form-label fw-bold">Tipe Media</label>
<div class="d-flex gap-3">
<div class="form-check">
<input class="form-check-input" type="radio" name="type" id="typeImage" value="image" checked>
<label class="form-check-label" for="typeImage">
<i class="fas fa-image me-1"></i>Gambar
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="type" id="typeVideo" value="video">
<label class="form-check-label" for="typeVideo">
<i class="fas fa-video me-1"></i>Video (YouTube)
</label>
</div>
</div>
</div>
<!-- Image Upload -->
<div id="imageUploadSection">
<div class="mb-3">
<label class="form-label">File Gambar</label>
<input type="file" class="form-control" name="image_file" accept="image/*" id="imageFile">
<small class="text-muted">
Format: JPG, PNG, GIF, WEBP. Maks 5MB. Ukuran ideal: 1200x800 pixel.
</small>
</div>
<div class="mb-3" id="imagePreview" style="display: none;">
<img src="" alt="Preview" class="img-fluid rounded" style="max-height: 200px;">
</div>
</div>
<!-- Video URL -->
<div id="videoUploadSection" style="display: none;">
<div class="mb-3">
<label class="form-label">URL Video (YouTube)</label>
<input type="url" class="form-control" name="video_url" placeholder="https://www.youtube.com/watch?v=...">
<small class="text-muted">
Masukkan URL video YouTube. Contoh: https://www.youtube.com/watch?v=xxxxx
</small>
</div>
</div>
<!-- Common Fields -->
<div class="mb-3">
<label class="form-label">Judul <span class="text-danger">*</span></label>
<input type="text" class="form-control" name="title" required>
</div>
<div class="mb-3">
<label class="form-label">Deskripsi</label>
<textarea class="form-control" name="description" rows="3"></textarea>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label">Kategori</label>
<input type="text" class="form-control" name="category" placeholder="Contoh: Kegiatan, Upacara, dll">
</div>
<div class="col-md-6 mb-3">
<label class="form-label">Status</label>
<select class="form-control" name="status">
<option value="active">Aktif</option>
<option value="inactive">Tidak Aktif</option>
</select>
</div>
</div>
<div class="mb-3">
<div class="form-check">
<input class="form-check-input" type="checkbox" name="featured" id="featured">
<label class="form-check-label" for="featured">
<i class="fas fa-star text-warning me-1"></i>Jadikan Featured (Unggulan)
</label>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
<button type="submit" name="upload" class="btn btn-primary" id="submitUpload">
<i class="fas fa-upload me-2"></i>Upload
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Edit Modal -->
<div class="modal fade" id="editModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<form method="POST" id="editForm" action="<?php echo BASE_URL; ?>/admin/media.php">
<div class="modal-header">
<h5 class="modal-title">
<i class="fas fa-edit me-2"></i>Edit Media
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<input type="hidden" name="id" id="editId">
<div class="mb-3">
<label class="form-label">Judul</label>
<input type="text" class="form-control" name="title" id="editTitle" required>
</div>
<div class="mb-3">
<label class="form-label">Deskripsi</label>
<textarea class="form-control" name="description" id="editDescription" rows="3"></textarea>
</div>
<div class="mb-3">
<label class="form-label">Kategori</label>
<input type="text" class="form-control" name="category" id="editCategory">
</div>
<div class="mb-3">
<label class="form-label">Status</label>
<select class="form-control" name="status" id="editStatus">
<option value="active">Aktif</option>
<option value="inactive">Tidak Aktif</option>
</select>
</div>
<div class="mb-3">
<div class="form-check">
<input class="form-check-input" type="checkbox" name="featured" id="editFeatured">
<label class="form-check-label" for="editFeatured">
<i class="fas fa-star text-warning me-1"></i>Jadikan Featured (Unggulan)
</label>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
<button type="submit" name="edit" class="btn btn-primary">
<i class="fas fa-save me-2"></i>Simpan Perubahan
</button>
</div>
</form>
</div>
</div>
</div>
<style>
.gallery-card {
transition: all 0.3s;
border: 1px solid #e3e6f0;
overflow: hidden;
}
.gallery-card:hover {
transform: translateY(-5px);
box-shadow: 0 10px 25px rgba(0,0,0,0.1);
border-color: var(--primary-color);
}
.gallery-card .card-img-top {
transition: transform 0.5s;
}
.gallery-card:hover .card-img-top img {
transform: scale(1.1);
}
.gallery-card .btn-group {
opacity: 0.8;
transition: opacity 0.3s;
}
.gallery-card:hover .btn-group {
opacity: 1;
}
/* Preview Image */
#imagePreview img {
max-width: 100%;
border: 2px dashed #e3e6f0;
padding: 5px;
}
</style>
<script>
// Pass BASE_URL ke JavaScript
const BASE_URL = '<?php echo BASE_URL; ?>';
// Toggle between image and video upload
document.querySelectorAll('input[name="type"]').forEach(radio => {
radio.addEventListener('change', function() {
if (this.value == 'image') {
document.getElementById('imageUploadSection').style.display = 'block';
document.getElementById('videoUploadSection').style.display = 'none';
document.getElementById('imageFile').required = true;
document.querySelector('input[name="video_url"]').required = false;
} else {
document.getElementById('imageUploadSection').style.display = 'none';
document.getElementById('videoUploadSection').style.display = 'block';
document.getElementById('imageFile').required = false;
document.querySelector('input[name="video_url"]').required = true;
}
});
});
// Image preview
document.getElementById('imageFile').addEventListener('change', function(e) {
const file = e.target.files[0];
if (file) {
if (file.size > 5 * 1024 * 1024) {
alert('Ukuran file maksimal 5MB!');
this.value = '';
return;
}
const reader = new FileReader();
reader.onload = function(e) {
const preview = document.getElementById('imagePreview');
preview.querySelector('img').src = e.target.result;
preview.style.display = 'block';
}
reader.readAsDataURL(file);
}
});
// Edit item function
function editItem(id) {
fetch(BASE_URL + '/admin/get_gallery_item.php?id=' + id)
.then(response => response.json())
.then(data => {
document.getElementById('editId').value = data.id;
document.getElementById('editTitle').value = data.title;
document.getElementById('editDescription').value = data.description || '';
document.getElementById('editCategory').value = data.category || '';
document.getElementById('editStatus').value = data.status;
document.getElementById('editFeatured').checked = data.featured == 1;
new bootstrap.Modal(document.getElementById('editModal')).show();
})
.catch(error => {
alert('Gagal memuat data');
});
}
// Prevent double submit
document.getElementById('uploadForm').addEventListener('submit', function(e) {
const submitBtn = document.getElementById('submitUpload');
submitBtn.disabled = true;
submitBtn.innerHTML = '<span class="spinner-border spinner-border-sm me-2"></span>Uploading...';
});
// Reset form when modal closed
document.getElementById('uploadModal').addEventListener('hidden.bs.modal', function() {
document.getElementById('uploadForm').reset();
document.getElementById('imagePreview').style.display = 'none';
});
</script>
<?php
// Helper function to get YouTube ID
function getYouTubeId($url) {
preg_match('/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/', $url, $matches);
return $matches[1] ?? '';
}
require_once 'includes/footer.php';
?>