diff --git a/src/app/components/admin/index.php b/src/app/components/admin/index.php index 22821dc218f7cad9d429aafeee972676368b4958..85c58d9eb503760419ad2a3c10d54bbb4e521c8d 100644 --- a/src/app/components/admin/index.php +++ b/src/app/components/admin/index.php @@ -74,6 +74,7 @@ $result = mysqli_query($conn, $query); <th>Kronologi</th> <th>Bukti</th> <th>Status</th> + <th>Aksi</th> </tr> <form for="save" action="/src/backend/save-lapor.php" method="post"> @@ -111,6 +112,10 @@ $result = mysqli_query($conn, $query); echo "<option value='completed' " . ($row["lapor_status"] == 'completed' ? 'selected' : '') . ">Completed</option>"; echo "</select>"; echo "</td>"; + echo "<td>"; + echo "<input type='hidden' name='lapor_id' value='" . $row['lapor_id'] . "'>"; + echo "<button type='submit' class='delete-button' name='delete'>Delete</button>"; + echo "</td>"; echo "</tr>"; } } else { @@ -121,7 +126,7 @@ $result = mysqli_query($conn, $query); </tbdody> </table> - <button type="submit" class="savebtn" name="save">Save</button> + <button type="submit" class="savebtn" name="save" href='/?admin'>Save</button> </form> </section> diff --git a/src/backend/save-lapor.php b/src/backend/save-lapor.php index db469f6253d23c77fb12826aa34340e3132e7126..16461b30be065605db84d85a4421cecf49f83490 100644 --- a/src/backend/save-lapor.php +++ b/src/backend/save-lapor.php @@ -4,7 +4,7 @@ $mysqli = require __DIR__ . "/../db.php"; $stmt = $mysqli->stmt_init(); if (isset($_POST["save"])) { - echo "disini"; + // echo "disini"; // Prepare the SQL query outside the loop $sql = "UPDATE lapor SET lapor_status = ? WHERE lapor_id = ?"; $stmt->prepare($sql); @@ -19,7 +19,7 @@ if (isset($_POST["save"])) { // echo $_POST["lapor_status"]; if (isset($_POST["lapor_status"]) && is_array($_POST["lapor_status"])) { foreach ($_POST["lapor_status"] as $key => $status) { - echo "haha"; + // echo "haha"; // Get the corresponding lapor_id for each status $lapor_id = $key + 1; // Add appropriate logic to get the correct lapor_id @@ -28,7 +28,8 @@ if (isset($_POST["save"])) { $stmt->execute(); } } - echo "close"; + // echo "close"; + // Close the statement $stmt->close(); @@ -36,6 +37,35 @@ if (isset($_POST["save"])) { $mysqli->close(); // Redirect or provide a success response + echo "<script>alert('Status berhasil diubah!');</script>"; + echo "<script>window.location.href='/?admin';</script>"; exit; } + +if (isset($_POST['delete'])){ + $laporID = $_POST['lapor_id']; // Use uppercase "ID" to match the variable name + $query = 'DELETE FROM lapor WHERE lapor_id = ?'; + $mysqli = require __DIR__ . '/../db.php'; + $stmt = $mysqli->stmt_init(); + + if ($stmt->prepare($query)) { + $stmt->bind_param('i', $laporID); // Use uppercase "ID" to match the variable name + + if ($stmt->execute()) { + //direct to home + // echo "berhasil"; + // header('Location: /?ruangdiskusi'); + echo "<script>alert('Laporan berhasil dihapus!');</script>"; + echo "<script>window.location.href='/?admin';</script>"; + exit; // Add this line to stop script execution after redirection + } else { + echo $mysqli->error; + } + } else { + die('Prepare failed: (' . $mysqli->errno . ') ' . $mysqli->error); + } + + $stmt->close(); + $mysqli->close(); +} ?> diff --git a/src/public/css/adminLapor.css b/src/public/css/adminLapor.css index 3c45e3b423d9890cdbf979d1b416678b8b869229..5f26f5119a9e0c29f2dff77044caa33a36e1d433 100644 --- a/src/public/css/adminLapor.css +++ b/src/public/css/adminLapor.css @@ -306,4 +306,16 @@ vide{ width: 100%; height: auto; margin-top: 20px; +} + +.delete-button{ + background-color: #FD6B39; + color: #FAF9F4; + padding: 10px; + border-radius: 5px; + border: none; + cursor: pointer; + font-size: 15px; + font-weight: bold; + margin-top: 10px; } \ No newline at end of file