<?php
session_start();
include "../config.php";

if (!isset($_SESSION['id_user']) || $_SESSION['role'] != 'dfo') {
    header("Location: ../index.php");
    exit;
}

// Cek submit
if (isset($_POST['submit_arsip'])) {

    $id_jv = (int)$_POST['id_jv'];
    $alasan = trim($_POST['alasan_dikembalikan']);

    // Validasi
    if ($id_jv <= 0 || empty($alasan)) {
        die("Dadus la kompletu.");
    }

    // Update status
    $stmt = $koneksi->prepare("
        UPDATE jv_documents 
        SET 
            status = 'dikembalikan',
            alasan_dikembalikan = ?
        WHERE id_jv = ?
    ");

    $stmt->bind_param("si", $alasan, $id_jv);

    if ($stmt->execute()) {

        // Redirect supaya form clear
        $_SESSION['success'] = "Dokumentu konsege fo fila ho susesu.";

        header("Location: verifikasi.php");
        exit;

    } else {
        die("Falha update dadus.");
    }
}
?>