<?php
include "db.php";

if(isset($_POST['generate'])){

    $token  = bin2hex(random_bytes(16));
    $expiry = date("Y-m-d H:i:s", strtotime("+1 day"));

    $stmt = $conn->prepare("INSERT INTO capture_links (token, expires_at) VALUES (?, ?)");
    $stmt->bind_param("ss", $token, $expiry);
    $stmt->execute();

    $link = "https://img.urlnowshort.com/capture.php?token=".$token;
}
?>

<!DOCTYPE html>
<html>
<head>
<title>Owner Dashboard</title>
</head>
<body>

<h2>Generate Secure Capture Link (Valid 24 Hours)</h2>

<form method="POST">
    <button name="generate">Generate Link</button>
</form>

<?php if(isset($link)){ ?>
    <h3>Your Secure Link:</h3>
    <input type="text" value="<?php echo $link; ?>" style="width:400px;">
    <p>Expiry: <?php echo $expiry; ?></p>
<?php } ?>

</body>
</html>