<?php
include '../config.php';

$id = $_POST['id'];
$pesan = $_POST['pesan'];

/* Ambil kode tiket */
$q = mysqli_query($conn,"
SELECT kode_tiket
FROM pengajuan
WHERE id='$id'
");

$d = mysqli_fetch_assoc($q);
$kode_tiket = $d['kode_tiket'];

/* Update status */
mysqli_query($conn,"
UPDATE pengajuan
SET status='Ditolak',
    pesan_balasan='$pesan'
WHERE id='$id'
");

/* Simpan log */
mysqli_query($conn,"
INSERT INTO log_status
(kode_tiket,status,tanggal)
VALUES
('$kode_tiket','Ditolak',NOW())
") or die(mysqli_error($conn));

header("location:surat_ditolak.php");
exit;
?>