<?php
require_once 'config.php';
if(!isset($_SESSION['opd_patient'])) { header('Location: index.php'); exit; }

$appt_id = (int)$_GET['appt_id'];
$appt = $conn->query("SELECT * FROM opd_appointments WHERE id=$appt_id")->fetch_assoc();

if(isset($_POST['submit'])) {
    $txn = $conn->real_escape_string($_POST['transaction_id']);
    $conn->query("UPDATE opd_appointments SET payment_status='paid', transaction_id='$txn' WHERE id=$appt_id");
    header('Location: dashboard.php?msg=paid');
    exit;
}
?>
<!DOCTYPE html>
<html lang="bn">
<head>
    <meta charset="UTF-8">
    <title>Payment</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-4">
    <h4>Pay for Appointment #<?=$appt['serial_no']?></h4>
    <p>Amount: ৳<?=number_format($appt['amount'])?></p>
    <p>Send payment to <strong>01712-345678</strong> (bKash/Nagad) and enter the Transaction ID below.</p>
    <form method="POST">
        <input type="text" name="transaction_id" class="form-control" placeholder="TrxID" required>
        <button type="submit" name="submit" class="btn btn-success mt-2">Submit Payment</button>
    </form>
</body>
</html>