<?php

include '../config/koneksi.php';

$id = $_POST['id'];

$status = $_POST['status'];

$keterangan = $_POST['keterangan'];



// ==========================
// AMBIL DATA BERKAS
// ==========================

$data = mysqli_fetch_assoc(

    mysqli_query(
        $conn,
        "SELECT * FROM berkas
         WHERE id='$id'"
    )
);



// ==========================
// SIMPAN KE HISTORY
// ==========================

mysqli_query(

    $conn,

    "INSERT INTO history_berkas
    (
        berkas_id,
        nomor_surat,
        nama_berkas,
        asal_kantor,
        file,
        status,
        keterangan
    )

    VALUES
    (
        '".$data['id']."',
        '".$data['nomor_surat']."',
        '".$data['nama_berkas']."',
        '".$data['asal_kantor']."',
        '".$data['file']."',
        '$status',
        '$keterangan'
    )"
);



// ==========================
// UPDATE STATUS BERKAS
// ==========================

mysqli_query(

    $conn,

    "UPDATE berkas
     SET
     status='$status',
     keterangan='$keterangan'
     WHERE id='$id'"
);

header("Location: dashboard.php");

?>