<?php
require_once __DIR__ . "/../config/db.php";

// Generate resi random
$sampleResi = "JP" . rand(100000000, 999999999);
$status = (rand(0,1)===1) ? "berhasil" : "gagal";
$pesan  = ($status==="berhasil") ? "Resi valid, akses dibuka." : "Resi tidak terdaftar.";

// Insert log
$stmt = $conn->prepare("INSERT INTO log_akses (nomor_resi, status, pesan) VALUES (?,?,?)");
$stmt->bind_param("sss", $sampleResi, $status, $pesan);
$stmt->execute();
$stmt->close();

// Redirect pakai cara aman
echo "<script>window.location.href='/smart-drop-point/public/log.php';</script>";
exit;