<?php
require '../koneksi.php';

$id_pengaduan = $_POST['id_pengaduan'];
$tgl          = $_POST['tgl_tanggapan'];
$tanggapan    = $_POST['tanggapan'];
$id_petugas   = $_POST['id_petugas'];
$status       = 'selesai';

// Insert tanggapan
$stmt = $conn->prepare("INSERT INTO tanggapan (id_pengaduan, tgl_tanggapan, tanggapan, id_petugas) VALUES (?, ?, ?, ?)");
$stmt->bind_param("isss", $id_pengaduan, $tgl, $tanggapan, $id_petugas);

// Update status pengaduan
$update = $conn->prepare("UPDATE pengaduan SET status = ? WHERE id_pengaduan = ?");
$update->bind_param("si", $status, $id_pengaduan);

if ($stmt->execute() && $update->execute()) {
    echo "<script>
        alert('Data Sudah Ditanggapi!');
        window.location='admin.php?url=validasi_tanggapan';
    </script>";
} else {
    echo "<script>
        alert('Gagal menyimpan tanggapan: " . $stmt->error . "');
        window.history.back();
    </script>";
}

// Tutup koneksi
$stmt->close();
$update->close();
$conn->close();
?>
