Skip to content
This repository was archived by the owner on Mar 30, 2024. It is now read-only.

Commit

Permalink
add: fitur update artikel dan komentar, update db
Browse files Browse the repository at this point in the history
  • Loading branch information
ftiannisa committed Mar 30, 2024
1 parent efc219c commit c614705
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 48 deletions.
6 changes: 3 additions & 3 deletions artikel/detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
</div>

<!-- comment section -->
<div class="container w-75" id="comment_section">
<div class="container w-75" id="comment_section" style="display:<?php $status = ($row['status_komentar']) ? 'block' : 'none'; echo $status; ?>">
<div class="row">
<!-- post komentar -->
<div class="d-flex pt-2 col justify-content-start">
Expand Down Expand Up @@ -143,7 +143,7 @@ class="form-control form-control-lg bg-light fs-6"
<div class="col">

<?php // get comments
$query = "SELECT * FROM t_artikel JOIN t_komentar ON t_artikel.id_artikel = t_komentar.id_artikel WHERE t_artikel.id_artikel = ?";
$query = "SELECT * FROM t_artikel JOIN t_komentar ON t_artikel.id_artikel = t_komentar.id_artikel WHERE t_artikel.id_artikel = ? AND t_komentar.status_tampil = 1";
$stmt = $connection->prepare($query);
$stmt->bind_param("i", $id_artikel);
$stmt->execute();
Expand All @@ -157,8 +157,8 @@ class="form-control form-control-lg bg-light fs-6"
<div class="d-flex flex-row mb-3">
<i class="bi bi-person-circle me-3" style="font-size: 30px;"></i>
<div class="d-flex flex-column">
<div class="d-inline-flex p-3 bg-warning rounded-4 text-break text-wrap" style="max-width: 500px;">' . $row['isi_komentar'] . '</div>
<div>' . $row['nama_user'] . ' - <span class="text-muted">' . $tanggal_baru . '</span></div>
<div class="d-inline-flex p-3 bg-warning rounded-4 text-break text-wrap" style="max-width: 500px;">' . $row['isi_komentar'] . '</div>
</div>
</div>
';
Expand Down
20 changes: 18 additions & 2 deletions artikel/insert.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
$judul_post = $_POST['judul'];
$gambar_url = $_POST['gambar'];
$isi_artikel = $_POST['isi_artikel'];
$status_komentar = (int)$_POST['flexRadioDefault'];
$id_admin = $_SESSION['id_adm'];

$query = "INSERT INTO t_artikel (judul_artikel, isi_artikel, gambar, id_admin) VALUES (?, ?, ?, ?)";
$query = "INSERT INTO t_artikel (judul_artikel, isi_artikel, gambar, id_admin, status_komentar) VALUES (?, ?, ?, ?, ?)";
$stmt = $connection->prepare($query);

$stmt->bind_param("sssi", $judul_post, $isi_artikel, $gambar_url, $id_admin);
$stmt->bind_param("sssii", $judul_post, $isi_artikel, $gambar_url, $id_admin, $status_komentar);

try {
$stmt->execute();
Expand Down Expand Up @@ -91,6 +92,21 @@ class="form-control"
name="isi_artikel"
></textarea>
</div>
<div class="form-group mb-3">
<label for="flexRadioDefault" class="poppins">Status Komentar</label>
<div class="form-check">
<input class="form-check-input" type="radio" name="flexRadioDefault" value="1" id="flexRadioDefault1" checked>
<label class="form-check-label" for="flexRadioDefault1">
Buka komentar
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="flexRadioDefault" value="0" id="flexRadioDefault2">
<label class="form-check-label" for="flexRadioDefault2">
Tutup komentar
</label>
</div>
</div>
<div class="input-group mb-5">
<button name="upload" class="btn btn-warning fs-6 poppins">POST</button>
</div>
Expand Down
19 changes: 14 additions & 5 deletions artikel/list_artikel.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@
<thead>
<tr>
<th scope="col" style="width: 10%">#</th>
<th scope="col" style="width: 60%">Title</th>
<th scope="col" style="width: 20%">Author</th>
<th scope="col" style="width: 10%">Action</th>
<th scope="col" style="width: 30%">Title</th>
<th scope="col" style="width: 10%">Author</th>
<th scope="col" style="width: 10%">Kolom Komentar</th>
<th scope="col" style="width: 20%">Action</th>
</tr>
</thead>
<tbody>
Expand All @@ -72,13 +73,21 @@ class="img-thumbnail"
</a>
</td>
<td><?php echo $row['nama']; ?></td>
<td><?php $status = ($row['status_komentar']) ? 'Buka' : 'Tutup'; echo $status; ?></td>
<td>
<a href="./artikel/delete.php?id_artikel=<?php echo $row['id_artikel']; ?>"
onclick="return confirm('Apakah Anda yakin ingin menghapus data ini?')"
><button name="hapus_post" class="btn btn-danger poppins">
onclick="return confirm('Apakah Anda yakin ingin menghapus data ini?')">
<button name="hapus_post" class="btn btn-danger poppins">
HAPUS
</button>
</a>
<br>
<a href="./artikel/update.php?id_artikel=<?php echo $row['id_artikel']; ?>"
onclick="return confirm('Apakah Anda yakin ingin mengubah data ini?')">
<button name="buka_tutup" class="btn btn-primary btn-sm m-1 poppins">
Buka/Tutup Komentar
</button>
</a>
</td>
</tr>
<?php endforeach; ?>
Expand Down
32 changes: 32 additions & 0 deletions artikel/update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
require_once '../templates/config/db_connection.php';

if (!isset($_SESSION['name'])) {
header("Location: index.php");
}

$id_artikel = (int)$_GET['id_artikel'];

// check if id_artikel is exist
$query = "SELECT * FROM t_artikel WHERE id_artikel=?";
$stmt = $connection->prepare($query);
$stmt->bind_param("i", $id_artikel);
$stmt->execute();
$result = $stmt->get_result();

if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$new_status = !$row['status_komentar'];
// update data
$status = ($new_status) ? "DIBUKA" : "DITUTUP";
echo "<script>alert('KOLOM KOMENTAR BERHASIL " . $status . ")</script>";
$query = "UPDATE t_artikel SET status_komentar = ? WHERE id_artikel=?";
$stmt = $connection->prepare($query);
$stmt->bind_param("ii", $new_status, $id_artikel);
$stmt->execute();
header("Location: ../dashboard.php");
} else {
echo "<script>alert('GAGAL MENGUBAH DATA')</script>";
}

?>
Loading

0 comments on commit c614705

Please sign in to comment.