TIF_NGANJUK_E41212035/forms/kelolakegiatan.php

183 lines
6.4 KiB
PHP

<?php
session_start();
// Cek apakah pengguna sudah login
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
header('Location: ../auth/login.php');
exit;
}
// Include file koneksi ke database
include '../config/database.php';
// Ambil kata kunci pencarian dari parameter GET
$search = isset($_GET['search']) ? $_GET['search'] : '';
// Buat query awal tanpa id_admin
$query = "SELECT * FROM kegiatan";
// Tambahkan filter pencarian jika ada input pencarian
if (!empty($search)) {
$query .= " WHERE kegiatan_nama LIKE ?";
}
$query .= " ORDER BY kegiatan_tglmulai DESC";
$stmt = mysqli_prepare($conn, $query);
if (!empty($search)) {
$search_param = "%$search%";
mysqli_stmt_bind_param($stmt, "s", $search_param);
}
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<title>Kelola Kegiatan - Masjid-E</title>
<meta content="" name="description">
<meta content="" name="keywords">
<!-- Favicons -->
<link href="../assets/img/favicon.png" rel="icon">
<link href="../assets/img/apple-touch-icon.png" rel="apple-touch-icon">
<!-- Google Fonts -->
<link href="https://fonts.gstatic.com" rel="preconnect">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Nunito:300,300i,400,400i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700" rel="stylesheet">
<!-- Vendor CSS Files -->
<link href="../assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="../assets/vendor/bootstrap-icons/bootstrap-icons.css" rel="stylesheet">
<link href="../assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet">
<link href="../assets/vendor/quill/quill.snow.css" rel="stylesheet">
<link href="../assets/vendor/quill/quill.bubble.css" rel="stylesheet">
<link href="../assets/vendor/remixicon/remixicon.css" rel="stylesheet">
<link href="../assets/vendor/simple-datatables/style.css" rel="stylesheet">
<!-- Template Main CSS File -->
<link href="../assets/css/admin.css" rel="stylesheet">
<!-- Add jQuery -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<?php
include '../forms/section/header.php';
include '../forms/section/sidebar.php';
?>
<main id="main" class="main">
<div class="pagetitle">
<h1>Kelola Kegiatan</h1>
<nav>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="dashboard.php">Home</a></li>
<li class="breadcrumb-item active">Kelola Kegiatan</li>
</ol>
</nav>
</div><!-- End Page Title -->
<section class="section">
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<h5 class="card-title">Daftar Kegiatan</h5>
<!-- Search Bar -->
<div class="row mb-3">
<div class="col-md-8">
<input type="text" class="form-control" id="search" placeholder="Cari Kegiatan...">
</div>
<div class="col-md-4 text-md-end text-end">
<a href="tambahkegiatan.php" class="btn btn-primary">Tambahkan Kegiatan</a>
</div>
</div>
<!-- Table with stripped rows -->
<table class="table table-striped" id="kegiatan-table">
<thead>
<tr>
<th scope="col">No.</th>
<th scope="col">Nama Kegiatan</th>
<th scope="col">Tanggal Mulai</th>
<th scope="col">Tanggal Akhir</th>
<th scope="col">Deskripsi</th>
<th scope="col">Gambar</th>
<th scope="col">Aksi</th>
</tr>
</thead>
<tbody>
<?php
if (mysqli_num_rows($result) > 0) {
$no = 1;
while($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td data-label scope='row'>" . $no . "</td>";
echo "<td data-label>" . htmlspecialchars($row['kegiatan_nama']) . "</td>";
echo "<td data-label>" . htmlspecialchars(date('d M Y', strtotime($row['kegiatan_tglmulai']))) . "</td>";
echo "<td data-label>" . htmlspecialchars(date('d M Y', strtotime($row['kegiatan_tglakhir']))) . "</td>";
$deskripsi = htmlspecialchars($row['kegiatan_keterangan']);
$deskripsi_pendek = strlen($deskripsi) > 200 ? substr($deskripsi, 0, 200) . '...' : $deskripsi;
echo "<td data-label>" . $deskripsi_pendek . "</td>";
echo "<td data-label><img src='../assets/img/kegiatan/" . htmlspecialchars($row['kegiatan_gambar']) . "' alt='Gambar Kegiatan' style='width: 100px;'></td>";
echo "<td data-label class='kegiatan-actions'>
<a href='editkegiatan.php?id=" . $row['kegiatan_id'] . "' class='btn btn-warning btn-sm'>Edit</a>
<a href='hapuskegiatan.php?id=" . $row['kegiatan_id'] . "' class='btn btn-danger btn-sm' onclick='return confirm(\"Yakin ingin menghapus kegiatan ini?\");'>Hapus</a>
</td>";
echo "</tr>";
$no++;
}
} else {
echo "<tr><td colspan='7' class='text-center'>Tidak ada kegiatan yang tersedia.</td></tr>";
}
// Tutup koneksi
mysqli_close($conn);
?>
</tbody>
</table>
<!-- End Table with stripped rows -->
</div>
</div>
</div>
</div>
</section>
</main><!-- End #main -->
<!-- ======= Footer ======= -->
<?php include('../forms/section/footer.php'); ?>
<!-- End Footer -->
<!-- JavaScript for AJAX Search -->
<script>
$(document).ready(function(){
$('#search').on('input', function() {
var search = $(this).val();
$.ajax({
url: 'search_kegiatan.php',
type: 'GET',
data: {search: search},
success: function(data) {
$('#kegiatan-table tbody').html(data);
}
});
});
});
</script>
</body>
</html>