<?php
require_once __DIR__.'/../db.php';

$id = (int)($_GET['id'] ?? 0);

if(!$id){
    die("الرابط غير صالح");
}

$pdo = db();

$stmt = $pdo->prepare("SELECT token FROM contract_sign_links WHERE contract_id=? LIMIT 1");
$stmt->execute([$id]);

$row = $stmt->fetch();

if(!$row){
    die("الرابط غير موجود");
}

$token = $row['token'];

header("Location: /HLG-Justice-Hub/contracts/sign/signing.php?token=".$token);
exit;