| 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 = 'Manajemen Shortcut';
require_once 'config/database.php';
require_once 'includes/init.php';
requireLogin();
// Cek apakah user adalah admin
if (!in_array($_SESSION['role'], ['superadmin','admin'])) {
redirect('dashboard.php');
}
// Handle add
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['add'])) {
$title = sanitize($_POST['title']);
$description = sanitize($_POST['description']);
$icon = sanitize($_POST['icon']);
$link = sanitize($_POST['link']);
$link_type = sanitize($_POST['link_type']);
$target = sanitize($_POST['target']);
$status = sanitize($_POST['status']);
$shortcut_order = (int)$_POST['shortcut_order'];
$image_type = sanitize($_POST['image_type']);
$image_path = '';
// Handle image upload jika tipe gambar
if ($image_type == 'image' && isset($_FILES['shortcut_image']) && $_FILES['shortcut_image']['error'] == 0) {
$target_dir = "../uploads/shortcuts/";
if (!file_exists($target_dir)) {
mkdir($target_dir, 0777, true);
}
$file_ext = strtolower(pathinfo($_FILES['shortcut_image']['name'], PATHINFO_EXTENSION));
$allowed = ['jpg', 'jpeg', 'png', 'gif', 'webp'];
if (in_array($file_ext, $allowed)) {
if ($_FILES['shortcut_image']['size'] <= 1 * 1024 * 1024) {
$image_name = time() . '_' . uniqid() . '.' . $file_ext;
$target_file = $target_dir . $image_name;
if (move_uploaded_file($_FILES['shortcut_image']['tmp_name'], $target_file)) {
$image_path = 'uploads/shortcuts/' . $image_name;
}
}
}
}
$query = "INSERT INTO shortcuts (title, description, icon, image, image_type, link, link_type, target, status, shortcut_order)
VALUES ('$title', '$description', '$icon', '$image_path', '$image_type', '$link', '$link_type', '$target', '$status', $shortcut_order)";
if ($conn->query($query)) {
redirect('shortcuts.php?msg=added');
} else {
$error = "Error: " . $conn->error;
}
}
// Handle edit
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['edit'])) {
$id = (int)$_POST['id'];
$title = sanitize($_POST['title']);
$description = sanitize($_POST['description']);
$icon = sanitize($_POST['icon']);
$link = sanitize($_POST['link']);
$link_type = sanitize($_POST['link_type']);
$target = sanitize($_POST['target']);
$status = sanitize($_POST['status']);
$shortcut_order = (int)$_POST['shortcut_order'];
$image_type = sanitize($_POST['image_type']);
$image_path = '';
$query = "UPDATE shortcuts SET
title = '$title',
description = '$description',
icon = '$icon',
image = '$image_path',
image_type = '$image_type',
link = '$link',
link_type = '$link_type',
target = '$target',
status = '$status',
shortcut_order = $shortcut_order
WHERE id = $id";
if ($conn->query($query)) {
redirect('shortcuts.php?msg=updated');
} else {
$error = "Error: " . $conn->error;
}
}
// Handle delete
if (isset($_GET['delete'])) {
$id = (int)$_GET['delete'];
$conn->query("DELETE FROM shortcuts WHERE id = $id");
redirect('shortcuts.php?msg=deleted');
}
// Get all shortcuts
$shortcuts = $conn->query("SELECT * FROM shortcuts ORDER BY shortcut_order ASC, id ASC");
// Get for edit
$edit_shortcut = null;
if (isset($_GET['edit'])) {
$id = (int)$_GET['edit'];
$result = $conn->query("SELECT * FROM shortcuts WHERE id = $id");
$edit_shortcut = $result->fetch_assoc();
}
$msg = '';
if (isset($_GET['msg'])) {
if ($_GET['msg'] == 'added') $msg = '<div class="alert alert-success">Shortcut berhasil ditambahkan!</div>';
if ($_GET['msg'] == 'updated') $msg = '<div class="alert alert-success">Shortcut berhasil diupdate!</div>';
if ($_GET['msg'] == 'deleted') $msg = '<div class="alert alert-success">Shortcut berhasil dihapus!</div>';
}
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-th-large me-2"></i>Manajemen Shortcut
</h1>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addModal">
<i class="fas fa-plus me-2"></i>Tambah Shortcut
</button>
</div>
<?php echo $msg; ?>
<?php if (isset($error)) echo '<div class="alert alert-danger">' . $error . '</div>'; ?>
<!-- Shortcuts List -->
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-white">Daftar Shortcut</h6>
</div>
<div class="card-body">
<?php if ($shortcuts && $shortcuts->num_rows > 0): ?>
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Icon</th>
<th>Judul</th>
<th>Deskripsi</th>
<th>Link</th>
<th>Tipe</th>
<th>Target</th>
<th>Status</th>
<th>Urutan</th>
<th>Aksi</th>
</tr>
</thead>
<tbody>
<?php while($shortcut = $shortcuts->fetch_assoc()): ?>
<tr>
<td class="text-center" style="font-size: 24px;">
<i class="<?php echo $shortcut['icon']; ?> text-primary"></i>
</td>
<td><strong><?php echo htmlspecialchars($shortcut['title']); ?></strong></td>
<td><small><?php echo substr(htmlspecialchars($shortcut['description']), 0, 50); ?></small></td>
<td><code><?php echo htmlspecialchars($shortcut['link']); ?></code></td>
<td>
<span class="badge bg-<?php echo $shortcut['link_type'] == 'internal' ? 'info' : 'warning'; ?>">
<?php echo $shortcut['link_type'] == 'internal' ? 'Internal' : 'Eksternal'; ?>
</span>
</td>
<td>
<span class="badge bg-<?php echo $shortcut['target'] == '_blank' ? 'secondary' : 'primary'; ?>">
<?php echo $shortcut['target'] == '_blank' ? 'Tab Baru' : 'Halaman Sama'; ?>
</span>
</td>
<td>
<span class="badge bg-<?php echo $shortcut['status'] == 'active' ? 'success' : 'secondary'; ?>">
<?php echo ucfirst($shortcut['status']); ?>
</span>
</td>
<td><?php echo $shortcut['shortcut_order']; ?></td>
<td>
<div class="btn-group">
<a href="?edit=<?php echo $shortcut['id']; ?>" class="btn btn-sm btn-info">
<i class="fas fa-edit"></i>
</a>
<a href="?delete=<?php echo $shortcut['id']; ?>" class="btn btn-sm btn-danger" onclick="return confirm('Yakin ingin menghapus shortcut ini?')">
<i class="fas fa-trash"></i>
</a>
</div>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
<?php else: ?>
<div class="text-center py-5">
<i class="fas fa-th-large fa-4x text-muted mb-3"></i>
<h5>Belum ada shortcut</h5>
<p class="text-muted">Klik tombol "Tambah Shortcut" untuk menambahkan shortcut pertama.</p>
</div>
<?php endif; ?>
</div>
</div>
</div>
<!-- Add Modal -->
<div class="modal fade" id="addModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<form method="POST">
<div class="modal-header">
<h5 class="modal-title">
<i class="fas fa-plus-circle me-2"></i>Tambah Shortcut Baru
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<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="2"></textarea>
</div>
<div class="mb-3">
<label class="form-label">Icon (Font Awesome)</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-icons"></i></span>
<input type="text" class="form-control" name="icon" value="fas fa-external-link-alt" required>
</div>
<small class="text-muted">Contoh: fas fa-info-circle, fas fa-building, fas fa-envelope</small>
</div>
<div class="mb-3">
<label class="form-label">Link/URL <span class="text-danger">*</span></label>
<input type="text" class="form-control" name="link" required>
<small class="text-muted">Untuk internal: profil, berita | Untuk eksternal: https://example.com</small>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label">Tipe Link</label>
<select class="form-control" name="link_type">
<option value="internal">Internal (Halaman dalam website)</option>
<option value="external">Eksternal (Website lain)</option>
</select>
</div>
<div class="col-md-6 mb-3">
<label class="form-label">Target</label>
<select class="form-control" name="target">
<option value="_self">Halaman yang Sama</option>
<option value="_blank">Tab Baru</option>
</select>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label">Urutan</label>
<input type="number" class="form-control" name="shortcut_order" value="0" min="0">
</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>
<!-- Di bagian form add/edit, tambahkan field untuk gambar -->
<div class="mb-3">
<label class="form-label">Tipe Tampilan</label>
<div class="d-flex gap-3">
<div class="form-check">
<input class="form-check-input" type="radio" name="image_type" id="type_icon" value="icon" checked>
<label class="form-check-label" for="type_icon">
<i class="fas fa-icons me-1"></i> Icon Font Awesome
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="image_type" id="type_image" value="image">
<label class="form-check-label" for="type_image">
<i class="fas fa-image me-1"></i> Gambar PNG/JPG
</label>
</div>
</div>
</div>
<div class="mb-3" id="icon_field">
<label class="form-label">Icon (Font Awesome) <span class="text-danger">*</span></label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-icons"></i></span>
<input type="text" class="form-control" name="icon" value="fas fa-external-link-alt" required>
</div>
<small class="text-muted">Contoh: fas fa-info-circle, fas fa-building, fas fa-envelope</small>
</div>
<div class="mb-3" id="image_field" >
<label class="form-label">Gambar (PNG/JPG) <span class="text-danger">*</span></label>
<input type="file" class="form-control" name="shortcut_image" accept="image/*" id="shortcutImage">
<small class="text-muted">Ukuran ideal: 200x200 pixel, format PNG atau JPG. Maks 1MB.</small>
<div id="imagePreview" class="mt-2" >
<img src="" alt="Preview" id="previewImg" style="max-height: 80px;">
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
<button type="submit" name="add" class="btn btn-primary">
<i class="fas fa-save me-2"></i>Simpan
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Edit Modal -->
<?php if ($edit_shortcut): ?>
<div class="modal fade" id="editModal" tabindex="-1" data-bs-backdrop="static">
<div class="modal-dialog">
<div class="modal-content">
<form method="POST">
<div class="modal-header">
<h5 class="modal-title">
<i class="fas fa-edit me-2"></i>Edit Shortcut
</h5>
<a href="shortcuts.php" class="btn-close"></a>
</div>
<div class="modal-body">
<input type="hidden" name="id" value="<?php echo $edit_shortcut['id']; ?>">
<div class="mb-3">
<label class="form-label">Judul <span class="text-danger">*</span></label>
<input type="text" class="form-control" name="title" value="<?php echo htmlspecialchars($edit_shortcut['title']); ?>" required>
</div>
<div class="mb-3">
<label class="form-label">Deskripsi</label>
<textarea class="form-control" name="description" rows="2"><?php echo htmlspecialchars($edit_shortcut['description']); ?></textarea>
</div>
<div class="mb-3">
<label class="form-label">Icon (Font Awesome)</label>
<div class="input-group">
<span class="input-group-text"><i class="<?php echo $edit_shortcut['icon']; ?>"></i></span>
<input type="text" class="form-control" name="icon" value="<?php echo $edit_shortcut['icon']; ?>" required>
</div>
</div>
<div class="mb-3">
<label class="form-label">Link/URL <span class="text-danger">*</span></label>
<input type="text" class="form-control" name="link" value="<?php echo $edit_shortcut['link']; ?>" required>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label">Tipe Link</label>
<select class="form-control" name="link_type">
<option value="internal" <?php echo $edit_shortcut['link_type'] == 'internal' ? 'selected' : ''; ?>>Internal</option>
<option value="external" <?php echo $edit_shortcut['link_type'] == 'external' ? 'selected' : ''; ?>>Eksternal</option>
</select>
</div>
<div class="col-md-6 mb-3">
<label class="form-label">Target</label>
<select class="form-control" name="target">
<option value="_self" <?php echo $edit_shortcut['target'] == '_self' ? 'selected' : ''; ?>>Halaman yang Sama</option>
<option value="_blank" <?php echo $edit_shortcut['target'] == '_blank' ? 'selected' : ''; ?>>Tab Baru</option>
</select>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label">Urutan</label>
<input type="number" class="form-control" name="shortcut_order" value="<?php echo $edit_shortcut['shortcut_order']; ?>" min="0">
</div>
<div class="col-md-6 mb-3">
<label class="form-label">Status</label>
<select class="form-control" name="status">
<option value="active" <?php echo $edit_shortcut['status'] == 'active' ? 'selected' : ''; ?>>Aktif</option>
<option value="inactive" <?php echo $edit_shortcut['status'] == 'inactive' ? 'selected' : ''; ?>>Tidak Aktif</option>
</select>
</div>
</div>
<!-- Di bagian form add/edit, tambahkan field untuk gambar -->
<div class="mb-3">
<label class="form-label">Tipe Tampilan</label>
<div class="d-flex gap-3">
<div class="form-check">
<input class="form-check-input" type="radio" name="image_type" id="type_icon" value="icon" checked>
<label class="form-check-label" for="type_icon">
<i class="fas fa-icons me-1"></i> Icon Font Awesome
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="image_type" id="type_image" value="image">
<label class="form-check-label" for="type_image">
<i class="fas fa-image me-1"></i> Gambar PNG/JPG
</label>
</div>
</div>
</div>
<div class="mb-3" id="icon_field">
<label class="form-label">Icon (Font Awesome) <span class="text-danger">*</span></label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-icons"></i></span>
<input type="text" class="form-control" name="icon" value="fas fa-external-link-alt" required>
</div>
<small class="text-muted">Contoh: fas fa-info-circle, fas fa-building, fas fa-envelope</small>
</div>
<div class="mb-3" id="image_field" >
<label class="form-label">Gambar (PNG/JPG) <span class="text-danger">*</span></label>
<input type="file" class="form-control" name="shortcut_image" accept="image/*" id="shortcutImage">
<small class="text-muted">Ukuran ideal: 200x200 pixel, format PNG atau JPG. Maks 1MB.</small>
<div id="imagePreview" class="mt-2" >
<img src="" alt="Preview" id="previewImg" style="max-height: 80px;">
</div>
</div>
</div>
<div class="modal-footer">
<a href="shortcuts.php" class="btn btn-secondary">Batal</a>
<button type="submit" name="edit" class="btn btn-primary">
<i class="fas fa-save me-2"></i>Update
</button>
</div>
</form>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
new bootstrap.Modal(document.getElementById('editModal')).show();
});
// Toggle icon/image field
document.querySelectorAll('input[name="image_type"]').forEach(radio => {
radio.addEventListener('change', function() {
if (this.value === 'icon') {
document.getElementById('icon_field').style.display = 'block';
document.getElementById('image_field').style.display = 'none';
document.querySelector('input[name="icon"]').required = true;
document.querySelector('input[name="shortcut_image"]').required = false;
} else {
document.getElementById('icon_field').style.display = 'none';
document.getElementById('image_field').style.display = 'block';
document.querySelector('input[name="icon"]').required = false;
document.querySelector('input[name="shortcut_image"]').required = true;
}
});
});
// Image preview
document.getElementById('shortcutImage')?.addEventListener('change', function(e) {
const file = e.target.files[0];
if (file) {
if (file.size > 1 * 1024 * 1024) {
alert('Ukuran file maksimal 1MB!');
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);
}
});
</script>
<?php endif; ?>
<?php require_once 'includes/footer.php'; ?>