37684-vm/apply.php
2026-02-28 20:31:20 +00:00

1536 lines
116 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require_once 'db/config.php';
$project_name = $_SERVER['PROJECT_NAME'] ?? 'LPA Builder';
$step = isset($_GET['step']) ? (int)$_GET['step'] : 1;
$lpa_id = isset($_GET['id']) ? (int)$_GET['id'] : null;
$lpa_data = null;
if ($lpa_id) {
$stmt = db()->prepare("SELECT * FROM lpa_applications WHERE id = ?");
$stmt->execute([$lpa_id]);
$lpa_data = $stmt->fetch();
}
// Redirect to step 1 if no ID but step > 1
if ($step > 1 && !$lpa_id) {
header("Location: apply.php?step=1");
exit;
}
$attorneys = [];
$replacement_attorneys = [];
$notified_persons = [];
if ($lpa_id) {
$stmt = db()->prepare("SELECT * FROM lpa_attorneys WHERE lpa_id = ? AND type = 'replacement'");
$stmt->execute([$lpa_id]);
$replacement_attorneys = $stmt->fetchAll();
$stmt = db()->prepare("SELECT * FROM lpa_attorneys WHERE lpa_id = ? AND type = 'primary'");
$stmt->execute([$lpa_id]);
$attorneys = $stmt->fetchAll();
$stmt = db()->prepare("SELECT * FROM lpa_notified_persons WHERE application_id = ?");
$stmt->execute([$lpa_id]);
$notified_persons = $stmt->fetchAll();
}
$num_attorneys = count($attorneys); // This is now count of primary attorneys
$num_replacements = count($replacement_attorneys);
$all_attorneys = array_merge($attorneys, $replacement_attorneys);
$potential_witnesses = [];
if ($lpa_data) {
if (!empty($lpa_data["witness_first_name"])) {
$potential_witnesses[] = [
"type" => "Donor Witness",
"title" => $lpa_data["witness_title"],
"first_name" => $lpa_data["witness_first_name"],
"last_name" => $lpa_data["witness_last_name"],
"address1" => $lpa_data["witness_address_line1"],
"address2" => $lpa_data["witness_address_line2"],
"address3" => $lpa_data["witness_address_line3"],
"postcode" => $lpa_data["witness_postcode"]
];
}
if (!empty($lpa_data["certificate_provider_first_name"])) {
$potential_witnesses[] = [
"type" => "Certificate Provider",
"title" => $lpa_data["certificate_provider_title"],
"first_name" => $lpa_data["certificate_provider_first_name"],
"last_name" => $lpa_data["certificate_provider_last_name"],
"address1" => $lpa_data["certificate_provider_address_line1"],
"address2" => $lpa_data["certificate_provider_address_line2"],
"address3" => $lpa_data["certificate_provider_address_line3"],
"postcode" => $lpa_data["certificate_provider_postcode"]
];
}
}
foreach ($notified_persons as $np) {
$potential_witnesses[] = [
"type" => "Notified Person",
"title" => $np["title"],
"first_name" => $np["first_name"],
"last_name" => $np["last_name"],
"address1" => $np["address_line1"],
"address2" => $np["address_line2"],
"address3" => $np["address_line3"],
"postcode" => $np["postcode"]
];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Start Application — <?php echo htmlspecialchars($project_name); ?></title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="assets/css/custom.css" rel="stylesheet">
<style>
.summary-section {
border-bottom: 1px solid #eee;
padding-bottom: 1.5rem;
margin-bottom: 1.5rem;
}
.summary-section:last-child {
border-bottom: none;
}
.summary-label {
font-weight: 600;
color: #666;
font-size: 0.85rem;
text-transform: uppercase;
letter-spacing: 0.025em;
}
.summary-value {
color: #111;
}
.edit-link {
font-size: 0.8rem;
text-decoration: none;
}
.extra-small {
font-size: 0.75rem;
}
</style>
</head>
<body class="bg-light">
<nav class="navbar navbar-expand-lg bg-white border-bottom shadow-sm">
<div class="container">
<a class="navbar-brand d-flex align-items-center" href="/">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="me-2 text-primary"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline><line x1="16" y1="13" x2="8" y2="13"></line><line x1="16" y1="17" x2="8" y2="17"></line><polyline points="10 9 9 9 8 9"></polyline></svg>
<span class="fw-bold"><?php echo htmlspecialchars($project_name); ?></span>
</a>
<a href="/dashboard.php" class="btn btn-sm btn-outline-secondary">Back to Dashboard</a>
</div>
</nav>
<div class="container py-5">
<div class="row justify-content-center">
<div class="col-lg-10">
<div class="mb-5">
<div class="d-flex justify-content-between align-items-center mb-2">
<span class="small fw-semibold text-muted text-uppercase tracking-wider">Step <?php echo $step; ?> of 13</span>
<span class="small fw-semibold text-primary">
<?php
switch($step) {
case 1: echo "Donor Information & Address"; break;
case 2: echo "Attorneys"; break;
case 3: echo "How decisions are made"; break;
case 4: echo "Replacement Attorneys"; break;
case 5: echo "Life-sustaining treatment & Witness"; break;
case 6: echo "People to notify"; break;
case 7: echo "Preferences and instructions"; break;
case 8: echo "Certificate Provider"; break;
case 9: echo "Attorney Witnesses"; break;
case 10: echo "Who is registering the LPA?"; break;
case 11: echo "Who should receive the LPA?"; break;
case 12: echo "Application fee"; break;
case 13: echo "Review Summary"; break;
}
?>
</span>
</div>
</div>
<div class="card p-4 p-md-5">
<?php if ($step === 1): ?>
<h2 class="h4 fw-bold mb-4">Let's get started.</h2>
<p class="text-muted mb-5">Please select the type of LPA and provide the donor's details and address. You can save your progress and return later.</p>
<form id="lpaFormStep1" class="lpa-form" method="POST" action="api/save_lpa.php">
<input type="hidden" name="step" value="1">
<?php if ($lpa_id): ?><input type="hidden" name="lpa_id" value="<?php echo $lpa_id; ?>"><?php endif; ?>
<div class="mb-4">
<label class="form-label fw-semibold">Type of LPA</label>
<div class="row g-3">
<div class="col-md-6">
<input type="radio" class="btn-check" name="lpa_type" id="type_hw" value="Health & Welfare" <?php echo ($lpa_data && $lpa_data['lpa_type'] === 'Health & Welfare') ? 'checked' : 'checked'; ?>>
<label class="btn btn-outline-secondary w-100 p-3 text-start h-100" for="type_hw">
<div class="fw-bold text-dark mb-1">Health & Welfare</div>
<div class="small text-muted">Decisions about medical care, moving into care, and daily routine.</div>
</label>
</div>
<div class="col-md-6">
<input type="radio" class="btn-check" name="lpa_type" id="type_pf" value="Property & Financial" <?php echo ($lpa_data && $lpa_data['lpa_type'] === 'Property & Financial') ? 'checked' : ''; ?>>
<label class="btn btn-outline-secondary w-100 p-3 text-start h-100" for="type_pf">
<div class="fw-bold text-dark mb-1">Property & Financial</div>
<div class="small text-muted">Managing bank accounts, paying bills, and selling property.</div>
</label>
</div>
</div>
</div>
<hr class="my-5 text-muted opacity-25">
<div class="row g-4">
<div class="col-12">
<h3 class="h6 fw-bold text-uppercase tracking-wider text-muted mb-3">Basic Information</h3>
</div>
<div class="col-12">
<label for="donor_name" class="form-label fw-semibold">Donor Full Name</label>
<input type="text" class="form-control" id="donor_name" name="donor_name" placeholder="As shown on official ID" value="<?php echo htmlspecialchars($lpa_data['donor_name'] ?? ''); ?>" required>
</div>
<div class="col-12">
<label for="other_names" class="form-label fw-semibold">Other names (Optional)</label>
<input type="text" class="form-control" id="other_names" name="other_names" placeholder="Any other names you are or have been known by" value="<?php echo htmlspecialchars($lpa_data['other_names'] ?? ''); ?>">
</div>
<div class="col-md-6">
<label for="donor_dob" class="form-label fw-semibold">Date of Birth</label>
<input type="date" class="form-control" id="donor_dob" name="donor_dob" value="<?php echo $lpa_data['donor_dob'] ?? ''; ?>" required>
</div>
<div class="col-md-6">
<label for="customer_email" class="form-label fw-semibold">Your Email Address</label>
<input type="email" class="form-control" id="customer_email" name="customer_email" placeholder="To track your progress" value="<?php echo htmlspecialchars($lpa_data['customer_email'] ?? ''); ?>" required>
</div>
<div class="col-12 mt-5">
<h3 class="h6 fw-bold text-uppercase tracking-wider text-muted mb-3">Donor Address</h3>
</div>
<div class="col-12">
<label for="donor_address_line1" class="form-label fw-semibold">Address Line 1</label>
<input type="text" class="form-control" id="donor_address_line1" name="donor_address_line1" placeholder="House number and street" value="<?php echo htmlspecialchars($lpa_data['donor_address_line1'] ?? ''); ?>" required>
</div>
<div class="col-12">
<label for="donor_address_line2" class="form-label fw-semibold">Address Line 2 (Optional)</label>
<input type="text" class="form-control" id="donor_address_line2" name="donor_address_line2" placeholder="Apartment, suite, unit, etc." value="<?php echo htmlspecialchars($lpa_data['donor_address_line2'] ?? ''); ?>">
</div>
<div class="col-md-8">
<label for="donor_town" class="form-label fw-semibold">Town / City</label>
<input type="text" class="form-control" id="donor_town" name="donor_town" value="<?php echo htmlspecialchars($lpa_data['donor_town'] ?? ''); ?>" required>
</div>
<div class="col-md-4">
<label for="donor_postcode" class="form-label fw-semibold">Postcode</label>
<input type="text" class="form-control" id="donor_postcode" name="donor_postcode" value="<?php echo htmlspecialchars($lpa_data['donor_postcode'] ?? ''); ?>" required>
</div>
</div>
<div class="mt-5 d-flex justify-content-between align-items-center">
<a href="/dashboard.php" class="btn btn-link text-decoration-none text-muted p-0">Cancel</a>
<button type="submit" class="btn btn-primary btn-lg px-5">Continue to Step 2</button>
</div>
</form>
<?php elseif ($step === 2): ?>
<h2 class="h4 fw-bold mb-4">Attorneys</h2>
<p class="text-muted mb-5">Add the people who will make decisions for you. You can add multiple attorneys. They must be over 18 and have mental capacity.</p>
<?php if (!empty($attorneys)): ?>
<div class="mb-5">
<h3 class="h6 fw-bold text-uppercase tracking-wider text-muted mb-3">Currently Added Attorneys</h3>
<div class="list-group shadow-sm">
<?php foreach ($attorneys as $attorney): ?>
<div class="list-group-item p-3 d-flex justify-content-between align-items-center">
<div>
<div class="fw-bold"><?php echo htmlspecialchars(($attorney['title'] ? $attorney['title'] . ' ' : '') . $attorney['first_name'] . ' ' . $attorney['last_name']); ?></div>
<div class="small text-muted"><?php echo htmlspecialchars($attorney['email']); ?> &bull; <?php echo htmlspecialchars($attorney['postcode']); ?></div>
</div>
<button type="button" class="btn btn-sm btn-outline-danger border-0 btn-delete-attorney" data-id="<?php echo $attorney['id']; ?>" data-lpa-id="<?php echo $lpa_id; ?>">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path><line x1="10" y1="11" x2="10" y2="17"></line><line x1="14" y1="11" x2="14" y2="17"></line></svg>
</button>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<div class="card bg-light border-0 p-4 mb-4">
<h3 class="h6 fw-bold mb-4">Add an Attorney</h3>
<form id="lpaFormStep2" class="lpa-form" method="POST" action="api/save_lpa.php">
<input type="hidden" name="step" value="2">
<input type="hidden" name="lpa_id" value="<?php echo $lpa_id; ?>">
<div class="row g-3">
<div class="col-md-2">
<label for="title" class="form-label fw-semibold">Title</label>
<input type="text" class="form-control" id="title" name="title" placeholder="Mr/Ms" required>
</div>
<div class="col-md-5">
<label for="first_name" class="form-label fw-semibold">First Name</label>
<input type="text" class="form-control" id="first_name" name="first_name" required>
</div>
<div class="col-md-5">
<label for="last_name" class="form-label fw-semibold">Last Name</label>
<input type="text" class="form-control" id="last_name" name="last_name" required>
</div>
<div class="col-md-6">
<label for="email" class="form-label fw-semibold">Email Address</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="col-md-6">
<label for="dob" class="form-label fw-semibold">Date of Birth</label>
<input type="date" class="form-control" id="dob" name="dob" required>
</div>
<div class="col-12 mt-4">
<label class="form-label fw-bold small text-uppercase">Attorney Address</label>
</div>
<div class="col-12">
<label for="address_line1" class="form-label fw-semibold">Address Line 1</label>
<input type="text" class="form-control" id="address_line1" name="address_line1" required>
</div>
<div class="col-12">
<label for="address_line2" class="form-label fw-semibold">Address Line 2 (Optional)</label>
<input type="text" class="form-control" id="address_line2" name="address_line2">
</div>
<div class="col-12">
<label for="address_line3" class="form-label fw-semibold">Address Line 3 (Optional)</label>
<input type="text" class="form-control" id="address_line3" name="address_line3">
</div>
<div class="col-md-8">
<label for="town" class="form-label fw-semibold">Town / City</label>
<input type="text" class="form-control" id="town" name="town" required>
</div>
<div class="col-md-4">
<label for="postcode" class="form-label fw-semibold">Postcode</label>
<input type="text" class="form-control" id="postcode" name="postcode" required>
</div>
</div>
<div class="mt-4 d-flex gap-3">
<button type="submit" name="next_action" value="add_another" class="btn btn-outline-primary w-100">Add Another Attorney</button>
<button type="submit" name="next_action" value="next_step" class="btn btn-primary w-100">Save & Continue to Step 3</button>
</div>
</form>
</div>
<div class="mt-5 d-flex justify-content-between align-items-center">
<a href="apply.php?step=1&id=<?php echo $lpa_id; ?>" class="btn btn-link text-decoration-none text-muted p-0">Back to Step 1</a>
<?php if (!empty($attorneys)): ?>
<a href="apply.php?step=3&id=<?php echo $lpa_id; ?>" class="btn btn-primary btn-lg px-5">Continue to Step 3</a>
<?php endif; ?>
</div>
<?php elseif ($step === 3): ?>
<h2 class="h4 fw-bold mb-4">How should your attorneys make decisions?</h2>
<p class="text-muted mb-5">Specify how you want your attorneys to work together when making decisions on your behalf.</p>
<form id="lpaFormStep3" class="lpa-form" method="POST" action="api/save_lpa.php">
<input type="hidden" name="step" value="3">
<input type="hidden" name="lpa_id" value="<?php echo $lpa_id; ?>">
<div class="row g-3">
<div class="col-12">
<div class="form-check p-0 mb-3">
<input type="radio" class="btn-check" name="attorney_decision_type" id="dec_one" value="I only appointed one attorney"
<?php echo ($num_attorneys === 1) ? 'checked' : ''; ?>
<?php echo ($num_attorneys > 1) ? 'disabled' : ''; ?> required>
<label class="btn btn-outline-secondary w-100 p-3 text-start h-100 d-flex align-items-center <?php echo ($num_attorneys > 1) ? 'opacity-50' : ''; ?>" for="dec_one">
<div class="flex-grow-1">
<div class="fw-bold text-dark mb-1">I only appointed one attorney</div>
<div class="small text-muted">Select this if you only have one person acting as your attorney.</div>
</div>
<div class="ms-3">
<div class="form-check-input-placeholder"></div>
</div>
</label>
</div>
<div class="form-check p-0 mb-3">
<input type="radio" class="btn-check" name="attorney_decision_type" id="dec_js" value="Jointly and severally"
<?php echo ($lpa_data && $lpa_data['attorney_decision_type'] === 'Jointly and severally') ? 'checked' : ''; ?>
<?php echo ($num_attorneys === 1) ? 'disabled' : ''; ?>>
<label class="btn btn-outline-secondary w-100 p-3 text-start h-100 d-flex align-items-center <?php echo ($num_attorneys === 1) ? 'opacity-50' : ''; ?>" for="dec_js">
<div class="flex-grow-1">
<div class="fw-bold text-dark mb-1">Jointly and severally</div>
<div class="small text-muted">Attorneys can make decisions together or on their own.</div>
</div>
<div class="ms-3">
<div class="form-check-input-placeholder"></div>
</div>
</label>
</div>
<div class="form-check p-0 mb-3">
<input type="radio" class="btn-check" name="attorney_decision_type" id="dec_j" value="Jointly"
<?php echo ($lpa_data && $lpa_data['attorney_decision_type'] === 'Jointly') ? 'checked' : ''; ?>
<?php echo ($num_attorneys === 1) ? 'disabled' : ''; ?>>
<label class="btn btn-outline-secondary w-100 p-3 text-start h-100 d-flex align-items-center <?php echo ($num_attorneys === 1) ? 'opacity-50' : ''; ?>" for="dec_j">
<div class="flex-grow-1">
<div class="fw-bold text-dark mb-1">Jointly</div>
<div class="small text-muted">Attorneys must agree on all decisions together.</div>
</div>
<div class="ms-3">
<div class="form-check-input-placeholder"></div>
</div>
</label>
</div>
<div class="form-check p-0 mb-3">
<input type="radio" class="btn-check" name="attorney_decision_type" id="dec_some" value="Jointly for some decisions, jointly and severally for other decisions"
<?php echo ($lpa_data && $lpa_data['attorney_decision_type'] === 'Jointly for some decisions, jointly and severally for other decisions') ? 'checked' : ''; ?>
<?php echo ($num_attorneys === 1) ? 'disabled' : ''; ?>>
<label class="btn btn-outline-secondary w-100 p-3 text-start h-100 d-flex align-items-center <?php echo ($num_attorneys === 1) ? 'opacity-50' : ''; ?>" for="dec_some">
<div class="flex-grow-1">
<div class="fw-bold text-dark mb-1">Jointly for some decisions, jointly and severally for other decisions</div>
<div class="small text-muted">You can specify which decisions must be made together.</div>
</div>
<div class="ms-3">
<div class="form-check-input-placeholder"></div>
</div>
</label>
</div>
</div>
</div>
<?php if ($num_attorneys === 1): ?>
<input type="hidden" name="attorney_decision_type" value="I only appointed one attorney">
<?php endif; ?>
<div class="mt-5 d-flex justify-content-between align-items-center">
<a href="apply.php?step=2&id=<?php echo $lpa_id; ?>" class="btn btn-link text-decoration-none text-muted p-0">Back to Step 2</a>
<button type="submit" class="btn btn-primary btn-lg px-5">Continue to Step 4</button>
</div>
</form>
<?php elseif ($step === 4): ?>
<h2 class="h4 fw-bold mb-4">Replacement Attorneys</h2>
<p class="text-muted mb-5">You can choose to appoint replacement attorneys who can step in if your original attorneys are no longer able to act for you.</p>
<?php if (!empty($replacement_attorneys)): ?>
<div class="mb-4">
<h3 class="h6 fw-bold mb-3 text-uppercase tracking-wider">Added Replacement Attorneys</h3>
<div class="list-group shadow-sm">
<?php foreach ($replacement_attorneys as $ra): ?>
<div class="list-group-item list-group-item-action d-flex justify-content-between align-items-center p-3 border-0 border-bottom">
<div>
<div class="fw-bold text-dark"><?php echo htmlspecialchars($ra['title'] . ' ' . $ra['first_name'] . ' ' . $ra['last_name']); ?></div>
<div class="small text-muted"><?php echo htmlspecialchars($ra['postcode']); ?></div>
</div>
<button type="button" class="btn btn-sm btn-outline-danger border-0 btn-delete-attorney" data-id="<?php echo $ra['id']; ?>" data-lpa-id="<?php echo $lpa_id; ?>">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path><line x1="10" y1="11" x2="10" y2="17"></line><line x1="14" y1="11" x2="14" y2="17"></line></svg>
</button>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<div class="card bg-light border-0 p-4 mb-4">
<h3 class="h6 fw-bold mb-4">Add a Replacement Attorney</h3>
<form id="lpaFormStep4" class="lpa-form" method="POST" action="api/save_lpa.php">
<input type="hidden" name="step" value="4">
<input type="hidden" name="lpa_id" value="<?php echo $lpa_id; ?>">
<div class="row g-3">
<div class="col-md-2">
<label for="title" class="form-label fw-semibold">Title</label>
<input type="text" class="form-control" id="title" name="title" placeholder="Mr/Ms" required>
</div>
<div class="col-md-5">
<label for="first_name" class="form-label fw-semibold">First Name</label>
<input type="text" class="form-control" id="first_name" name="first_name" required>
</div>
<div class="col-md-5">
<label for="last_name" class="form-label fw-semibold">Last Name</label>
<input type="text" class="form-control" id="last_name" name="last_name" required>
</div>
<div class="col-md-6">
<label for="email" class="form-label fw-semibold">Email Address</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="col-md-6">
<label for="dob" class="form-label fw-semibold">Date of Birth</label>
<input type="date" class="form-control" id="dob" name="dob" required>
</div>
<div class="col-12 mt-4">
<label class="form-label fw-bold small text-uppercase">Replacement Attorney Address</label>
</div>
<div class="col-12">
<label for="address_line1" class="form-label fw-semibold">Address Line 1</label>
<input type="text" class="form-control" id="address_line1" name="address_line1" required>
</div>
<div class="col-12">
<label for="address_line2" class="form-label fw-semibold">Address Line 2 (Optional)</label>
<input type="text" class="form-control" id="address_line2" name="address_line2">
</div>
<div class="col-12">
<label for="address_line3" class="form-label fw-semibold">Address Line 3 (Optional)</label>
<input type="text" class="form-control" id="address_line3" name="address_line3">
</div>
<div class="col-md-8">
<label for="town" class="form-label fw-semibold">Town / City</label>
<input type="text" class="form-control" id="town" name="town" required>
</div>
<div class="col-md-4">
<label for="postcode" class="form-label fw-semibold">Postcode</label>
<input type="text" class="form-control" id="postcode" name="postcode" required>
</div>
</div>
<div class="mt-4 d-flex gap-3">
<button type="submit" name="next_action" value="add_another" class="btn btn-outline-primary w-100">Add Another Replacement</button>
<button type="submit" name="next_action" value="next_step" class="btn btn-primary w-100">Save & Continue to Step 5</button>
</div>
</form>
</div>
<div class="mt-5 d-flex justify-content-between align-items-center">
<a href="apply.php?step=3&id=<?php echo $lpa_id; ?>" class="btn btn-link text-decoration-none text-muted p-0">Back to Step 3</a>
<a href="apply.php?step=5&id=<?php echo $lpa_id; ?>" class="btn btn-outline-secondary btn-lg px-4">Skip to Step 5</a>
</div>
<?php elseif ($step === 5): ?>
<h2 class="h4 fw-bold mb-4">Life-sustaining treatment & Witness</h2>
<p class="text-muted mb-5">Provide final details regarding life-sustaining treatment and witness information.</p>
<form id="lpaFormStep5" class="lpa-form" method="POST" action="api/save_lpa.php">
<input type="hidden" name="step" value="5">
<input type="hidden" name="lpa_id" value="<?php echo $lpa_id; ?>">
<div class="mb-5">
<h3 class="h5 fw-bold mb-4">Life-sustaining treatment</h3>
<div class="row g-3">
<div class="col-12">
<input type="radio" class="btn-check" name="life_sustaining_treatment" id="lst_a" value="Option A" <?php echo ($lpa_data && $lpa_data['life_sustaining_treatment'] === 'Option A') ? 'checked' : ''; ?> required>
<label class="btn btn-outline-secondary w-100 p-4 text-start h-100 mb-3 d-flex align-items-center" for="lst_a">
<div class="flex-grow-1">
<div class="fw-bold text-dark mb-1">Option A</div>
<div class="text-muted small">I give my attorneys authority to give or refuse consent to life-sustaining treatment on my behalf.</div>
</div>
<div class="ms-3">
<div class="form-check-input-placeholder"></div>
</div>
</label>
<input type="radio" class="btn-check" name="life_sustaining_treatment" id="lst_b" value="Option B" <?php echo ($lpa_data && $lpa_data['life_sustaining_treatment'] === 'Option B') ? 'checked' : ''; ?>>
<label class="btn btn-outline-secondary w-100 p-4 text-start h-100 d-flex align-items-center" for="lst_b">
<div class="flex-grow-1">
<div class="fw-bold text-dark mb-1">Option B</div>
<div class="text-muted small">I do not give my attorneys authority to give or refuse consent to life-sustaining treatment on my behalf.</div>
</div>
<div class="ms-3">
<div class="form-check-input-placeholder"></div>
</div>
</label>
</div>
</div>
</div>
<hr class="my-5 text-muted opacity-25">
<div class="mb-5">
<h3 class="h5 fw-bold mb-4">Witness Information</h3>
<div class="row g-4">
<div class="col-md-2">
<label for="witness_title" class="form-label fw-semibold">Title</label>
<input type="text" class="form-control" id="witness_title" name="witness_title" placeholder="Mr/Ms" value="<?php echo htmlspecialchars($lpa_data['witness_title'] ?? ''); ?>" required>
</div>
<div class="col-md-5">
<label for="witness_first_name" class="form-label fw-semibold">First Name</label>
<input type="text" class="form-control" id="witness_first_name" name="witness_first_name" value="<?php echo htmlspecialchars($lpa_data['witness_first_name'] ?? ''); ?>" required>
</div>
<div class="col-md-5">
<label for="witness_last_name" class="form-label fw-semibold">Last Name</label>
<input type="text" class="form-control" id="witness_last_name" name="witness_last_name" value="<?php echo htmlspecialchars($lpa_data['witness_last_name'] ?? ''); ?>" required>
</div>
<div class="col-12">
<label for="witness_address_line1" class="form-label fw-semibold">Address Line 1</label>
<input type="text" class="form-control" id="witness_address_line1" name="witness_address_line1" value="<?php echo htmlspecialchars($lpa_data['witness_address_line1'] ?? ''); ?>" required>
</div>
<div class="col-12">
<label for="witness_address_line2" class="form-label fw-semibold">Address Line 2 (Optional)</label>
<input type="text" class="form-control" id="witness_address_line2" name="witness_address_line2" value="<?php echo htmlspecialchars($lpa_data['witness_address_line2'] ?? ''); ?>">
</div>
<div class="col-md-8">
<label for="witness_address_line3" class="form-label fw-semibold">Address Line 3 (Optional)</label>
<input type="text" class="form-control" id="witness_address_line3" name="witness_address_line3" value="<?php echo htmlspecialchars($lpa_data['witness_address_line3'] ?? ''); ?>">
</div>
<div class="col-md-4">
<label for="witness_postcode" class="form-label fw-semibold">Postcode</label>
<input type="text" class="form-control" id="witness_postcode" name="witness_postcode" value="<?php echo htmlspecialchars($lpa_data['witness_postcode'] ?? ''); ?>" required>
</div>
</div>
</div>
<div class="mt-5 d-flex justify-content-between align-items-center">
<a href="apply.php?step=4&id=<?php echo $lpa_id; ?>" class="btn btn-link text-decoration-none text-muted p-0">Back to Step 4</a>
<button type="submit" class="btn btn-primary btn-lg px-5">Continue to Step 6</button>
</div>
</form>
<?php elseif ($step === 6): ?>
<h2 class="h4 fw-bold mb-4">People to notify</h2>
<p class="text-muted mb-5">Do you wish to notify anyone else when the LPA is registered?</p>
<div id="notifyQuestionSection" class="mb-5 <?php echo !empty($notified_persons) ? 'd-none' : ''; ?>">
<div class="d-flex gap-3">
<button type="button" class="btn btn-outline-primary btn-lg px-5" onclick="document.getElementById('notifyFormSection').classList.remove('d-none'); document.getElementById('notifyQuestionSection').classList.add('d-none');">Yes</button>
<a href="apply.php?step=7&id=<?php echo $lpa_id; ?>" class="btn btn-outline-secondary btn-lg px-5">No</a>
</div>
</div>
<div id="notifyFormSection" class="<?php echo !empty($notified_persons) ? '' : 'd-none'; ?>">
<?php if (!empty($notified_persons)): ?>
<div class="mb-4">
<h3 class="h6 fw-bold mb-3 text-uppercase tracking-wider">Currently Notified Persons</h3>
<div class="list-group shadow-sm mb-4">
<?php foreach ($notified_persons as $np): ?>
<div class="list-group-item d-flex justify-content-between align-items-center p-3">
<div>
<div class="fw-bold"><?php echo htmlspecialchars($np['title'] . ' ' . $np['first_name'] . ' ' . $np['last_name']); ?></div>
<div class="small text-muted"><?php echo htmlspecialchars($np['postcode']); ?></div>
</div>
<button type="button" class="btn btn-sm btn-outline-danger border-0 btn-delete-notified" data-id="<?php echo $np['id']; ?>" data-lpa-id="<?php echo $lpa_id; ?>">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path><line x1="10" y1="11" x2="10" y2="17"></line><line x1="14" y1="11" x2="14" y2="17"></line></svg>
</button>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<div class="card bg-light border-0 p-4 mb-4">
<h3 class="h6 fw-bold mb-4">Add a Person to Notify</h3>
<form id="lpaFormStep6" class="lpa-form" method="POST" action="api/save_lpa.php">
<input type="hidden" name="step" value="6">
<input type="hidden" name="lpa_id" value="<?php echo $lpa_id; ?>">
<div class="row g-3">
<div class="col-md-2">
<label for="title" class="form-label fw-semibold">Title</label>
<input type="text" class="form-control" id="title" name="title" placeholder="Mr/Ms" required>
</div>
<div class="col-md-5">
<label for="first_name" class="form-label fw-semibold">First Name</label>
<input type="text" class="form-control" id="first_name" name="first_name" required>
</div>
<div class="col-md-5">
<label for="last_name" class="form-label fw-semibold">Last Name</label>
<input type="text" class="form-control" id="last_name" name="last_name" required>
</div>
<div class="col-12 mt-4">
<label class="form-label fw-bold small text-uppercase">Address</label>
</div>
<div class="col-12">
<label for="address_line1" class="form-label fw-semibold">Address Line 1</label>
<input type="text" class="form-control" id="address_line1" name="address_line1" required>
</div>
<div class="col-12">
<label for="address_line2" class="form-label fw-semibold">Address Line 2 (Optional)</label>
<input type="text" class="form-control" id="address_line2" name="address_line2">
</div>
<div class="col-12">
<label for="address_line3" class="form-label fw-semibold">Address Line 3 (Optional)</label>
<input type="text" class="form-control" id="address_line3" name="address_line3">
</div>
<div class="col-md-4">
<label for="postcode" class="form-label fw-semibold">Postcode</label>
<input type="text" class="form-control" id="postcode" name="postcode" required>
</div>
</div>
<div class="mt-4 d-flex gap-3">
<button type="submit" name="next_action" value="add_another" class="btn btn-outline-primary w-100">Notify another person</button>
<button type="submit" name="next_action" value="next_step" class="btn btn-primary w-100">Step 7</button>
</div>
</form>
</div>
<div class="mt-5 d-flex justify-content-between align-items-center">
<a href="apply.php?step=5&id=<?php echo $lpa_id; ?>" class="btn btn-link text-decoration-none text-muted p-0">Back to Step 5</a>
</div>
</div>
<?php elseif ($step === 7): ?>
<h2 class="h4 fw-bold mb-4">Preferences and instructions</h2>
<p class="text-muted mb-5">Provide any specific preferences or instructions for your attorneys.</p>
<form id="lpaFormStep7" class="lpa-form" method="POST" action="api/save_lpa.php">
<input type="hidden" name="step" value="7">
<input type="hidden" name="lpa_id" value="<?php echo $lpa_id; ?>">
<div class="mb-5">
<h3 class="h5 fw-bold mb-3">Preferences</h3>
<p class="mb-2">Your attorneys dont have to follow your preferences but they should keep them in mind. For examples of preferences, see the Guide, part A7.</p>
<p class="mb-3 text-muted small">Preferences use words like prefer and would like</p>
<textarea class="form-control" name="preferences" rows="6" placeholder="Enter your preferences here..."><?php echo htmlspecialchars($lpa_data['preferences'] ?? ''); ?></textarea>
</div>
<div class="mb-5">
<h3 class="h5 fw-bold mb-3">Instructions</h3>
<p class="mb-2">Your attorneys will have to follow your instructions exactly. For examples of instructions, see the Guide, part A7.</p>
<p class="mb-2 text-danger small fw-semibold">Be careful if you give instructions that are not legally correct they would have to be removed before your LPA could be registered.</p>
<p class="mb-3 text-muted small">Instructions use words like must and have to</p>
<textarea class="form-control" name="instructions" rows="6" placeholder="Enter your instructions here..."><?php echo htmlspecialchars($lpa_data['instructions'] ?? ''); ?></textarea>
</div>
<div class="mt-5 d-flex justify-content-between align-items-center">
<a href="apply.php?step=6&id=<?php echo $lpa_id; ?>" class="btn btn-link text-decoration-none text-muted p-0">Back to Step 6</a>
<button type="submit" class="btn btn-primary btn-lg px-5">Step 8</button>
</div>
</form>
<?php elseif ($step === 8): ?>
<h2 class="h4 fw-bold mb-4">Certificate Provider</h2>
<p class="text-muted mb-5">Please provide the details of the person who will be your certificate provider.</p>
<form id="lpaFormStep8" class="lpa-form" method="POST" action="api/save_lpa.php">
<input type="hidden" name="step" value="8">
<input type="hidden" name="lpa_id" value="<?php echo $lpa_id; ?>">
<div class="row g-4">
<div class="col-md-2">
<label for="certificate_provider_title" class="form-label fw-semibold">Title</label>
<input type="text" class="form-control" id="certificate_provider_title" name="certificate_provider_title" placeholder="Mr/Ms" value="<?php echo htmlspecialchars($lpa_data['certificate_provider_title'] ?? ''); ?>" required>
</div>
<div class="col-md-5">
<label for="certificate_provider_first_name" class="form-label fw-semibold">First Name</label>
<input type="text" class="form-control" id="certificate_provider_first_name" name="certificate_provider_first_name" value="<?php echo htmlspecialchars($lpa_data['certificate_provider_first_name'] ?? ''); ?>" required>
</div>
<div class="col-md-5">
<label for="certificate_provider_last_name" class="form-label fw-semibold">Last Name</label>
<input type="text" class="form-control" id="certificate_provider_last_name" name="certificate_provider_last_name" value="<?php echo htmlspecialchars($lpa_data['certificate_provider_last_name'] ?? ''); ?>" required>
</div>
<div class="col-12">
<label for="certificate_provider_address_line1" class="form-label fw-semibold">Address Line 1</label>
<input type="text" class="form-control" id="certificate_provider_address_line1" name="certificate_provider_address_line1" value="<?php echo htmlspecialchars($lpa_data['certificate_provider_address_line1'] ?? ''); ?>" required>
</div>
<div class="col-12">
<label for="certificate_provider_address_line2" class="form-label fw-semibold">Address Line 2 (Optional)</label>
<input type="text" class="form-control" id="certificate_provider_address_line2" name="certificate_provider_address_line2" value="<?php echo htmlspecialchars($lpa_data['certificate_provider_address_line2'] ?? ''); ?>">
</div>
<div class="col-md-8">
<label for="certificate_provider_address_line3" class="form-label fw-semibold">Address Line 3 (Optional)</label>
<input type="text" class="form-control" id="certificate_provider_address_line3" name="certificate_provider_address_line3" value="<?php echo htmlspecialchars($lpa_data['certificate_provider_address_line3'] ?? ''); ?>">
</div>
<div class="col-md-4">
<label for="certificate_provider_postcode" class="form-label fw-semibold">Postcode</label>
<input type="text" class="form-control" id="certificate_provider_postcode" name="certificate_provider_postcode" value="<?php echo htmlspecialchars($lpa_data['certificate_provider_postcode'] ?? ''); ?>" required>
</div>
</div>
<div class="mt-5 d-flex justify-content-between align-items-center">
<a href="apply.php?step=7&id=<?php echo $lpa_id; ?>" class="btn btn-link text-decoration-none text-muted p-0">Back to Step 7</a>
<button type="submit" class="btn btn-primary btn-lg px-5">Step 9</button>
</div>
</form>
<?php elseif ($step === 9): ?>
<h2 class="h4 fw-bold mb-4">Attorney Witnesses</h2>
<p class="text-muted mb-5">Select a witness for each attorney's signature. You can use an existing person or add a new witness.</p>
<form id="lpaFormStep9" class="lpa-form" method="POST" action="api/save_lpa.php">
<input type="hidden" name="step" value="9">
<input type="hidden" name="lpa_id" value="<?php echo $lpa_id; ?>">
<?php foreach ($all_attorneys as $index => $attorney): ?>
<div class="card bg-light border-0 p-4 mb-4">
<h3 class="h6 fw-bold mb-3">Witness for <?php echo htmlspecialchars($attorney['first_name'] . ' ' . $attorney['last_name']); ?></h3>
<div class="mb-3">
<label class="form-label fw-semibold">Select Witness</label>
<select name="attorney_witness[<?php echo $attorney['id']; ?>][selection]" class="form-select witness-selector" data-attorney-id="<?php echo $attorney['id']; ?>" required>
<option value="">Select a witness...</option>
<?php foreach ($potential_witnesses as $pw): ?>
<?php
$pw_json = json_encode($pw);
$selected = '';
if ($attorney['witness_first_name'] === $pw['first_name'] && $attorney['witness_last_name'] === $pw['last_name']) {
$selected = 'selected';
}
?>
<option value='<?php echo htmlspecialchars($pw_json); ?>' <?php echo $selected; ?>>
<?php echo htmlspecialchars($pw['first_name'] . ' ' . $pw['last_name'] . ' (' . $pw['type'] . ')'); ?>
</option>
<?php endforeach; ?>
<option value="new" <?php echo ($attorney['witness_first_name'] && !empty($attorney['witness_address_line1']) && empty($selected)) ? 'selected' : ''; ?>>Enter a new witness...</option>
</select>
</div>
<div id="new_witness_fields_<?php echo $attorney['id']; ?>" class="<?php echo ($attorney['witness_first_name'] && !empty($attorney['witness_address_line1']) && empty($selected)) ? '' : 'd-none'; ?> mt-4 border-top pt-4">
<div class="row g-3">
<div class="col-md-2">
<label class="form-label fw-semibold small">Title</label>
<input type="text" class="form-control form-control-sm" name="attorney_witness[<?php echo $attorney['id']; ?>][title]" value="<?php echo htmlspecialchars($attorney['witness_title'] ?? ''); ?>">
</div>
<div class="col-md-5">
<label class="form-label fw-semibold small">First Name</label>
<input type="text" class="form-control form-control-sm" name="attorney_witness[<?php echo $attorney['id']; ?>][first_name]" value="<?php echo htmlspecialchars($attorney['witness_first_name'] ?? ''); ?>">
</div>
<div class="col-md-5">
<label class="form-label fw-semibold small">Last Name</label>
<input type="text" class="form-control form-control-sm" name="attorney_witness[<?php echo $attorney['id']; ?>][last_name]" value="<?php echo htmlspecialchars($attorney['witness_last_name'] ?? ''); ?>">
</div>
<div class="col-12">
<label class="form-label fw-semibold small">Address Line 1</label>
<input type="text" class="form-control form-control-sm" name="attorney_witness[<?php echo $attorney['id']; ?>][address_line1]" value="<?php echo htmlspecialchars($attorney['witness_address_line1'] ?? ''); ?>">
</div>
<div class="col-12">
<label class="form-label fw-semibold small">Address Line 2 (Optional)</label>
<input type="text" class="form-control form-control-sm" name="attorney_witness[<?php echo $attorney['id']; ?>][address_line2]" value="<?php echo htmlspecialchars($attorney['witness_address_line2'] ?? ''); ?>">
</div>
<div class="col-md-8">
<label class="form-label fw-semibold small">Address Line 3 (Optional)</label>
<input type="text" class="form-control form-control-sm" name="attorney_witness[<?php echo $attorney['id']; ?>][address_line3]" value="<?php echo htmlspecialchars($attorney['witness_address_line3'] ?? ''); ?>">
</div>
<div class="col-md-4">
<label class="form-label fw-semibold small">Postcode</label>
<input type="text" class="form-control form-control-sm" name="attorney_witness[<?php echo $attorney['id']; ?>][postcode]" value="<?php echo htmlspecialchars($attorney['witness_postcode'] ?? ''); ?>">
</div>
</div>
</div>
</div>
<?php endforeach; ?>
<div class="mt-5 d-flex justify-content-between align-items-center">
<a href="apply.php?step=8&id=<?php echo $lpa_id; ?>" class="btn btn-link text-decoration-none text-muted p-0">Back to Step 8</a>
<button type="submit" class="btn btn-primary btn-lg px-5">Step 10</button>
</div>
</form>
<?php elseif ($step === 10): ?>
<h2 class="h4 fw-bold mb-4">Who is registering the LPA?</h2>
<p class="text-muted mb-5">Select whether the donor or the attorney(s) will register this lasting power of attorney.</p>
<form id="lpaFormStep10" class="lpa-form" method="POST" action="api/save_lpa.php">
<input type="hidden" name="step" value="10">
<input type="hidden" name="lpa_id" value="<?php echo $lpa_id; ?>">
<div class="mb-5">
<div class="form-check p-0 mb-4">
<input type="radio" class="btn-check" name="registration_who" id="reg_donor" value="donor"
<?php echo ($lpa_data && $lpa_data['registration_who'] === 'donor') ? 'checked' : 'checked'; ?> required>
<label class="btn btn-outline-secondary w-100 p-4 text-start h-100 d-flex align-items-center" for="reg_donor" onclick="document.getElementById('attorney_selection').classList.add('d-none')">
<div class="flex-grow-1">
<div class="fw-bold text-dark mb-1">The donor</div>
<div class="small text-muted">The person who is making the LPA.</div>
</div>
<div class="ms-3">
<div class="form-check-input-placeholder"></div>
</div>
</label>
</div>
<div class="form-check p-0 mb-4">
<input type="radio" class="btn-check" name="registration_who" id="reg_attorneys" value="attorneys"
<?php echo ($lpa_data && $lpa_data['registration_who'] === 'attorneys') ? 'checked' : ''; ?>>
<label class="btn btn-outline-secondary w-100 p-4 text-start h-100 d-flex align-items-center" for="reg_attorneys" onclick="document.getElementById('attorney_selection').classList.remove('d-none')">
<div class="flex-grow-1">
<div class="fw-bold text-dark mb-1">The attorney(s)</div>
<div class="small text-muted">One or more of the attorneys appointed in this LPA.</div>
</div>
<div class="ms-3">
<div class="form-check-input-placeholder"></div>
</div>
</label>
</div>
</div>
<div id="attorney_selection" class="<?php echo ($lpa_data && $lpa_data['registration_who'] === 'attorneys') ? '' : 'd-none'; ?> mb-5 animate-fade-in">
<h3 class="h6 fw-bold mb-4 text-uppercase tracking-wider text-muted">Select the registering attorneys</h3>
<div class="list-group shadow-sm">
<?php
$selected_attorneys = !empty($lpa_data['registering_attorneys_ids']) ? explode(',', $lpa_data['registering_attorneys_ids']) : [];
foreach ($attorneys as $attorney):
$is_checked = in_array($attorney['id'], $selected_attorneys) ? 'checked' : '';
?>
<label class="list-group-item p-3 d-flex align-items-center">
<input class="form-check-input me-3" type="checkbox" name="registering_attorneys[]" value="<?php echo $attorney['id']; ?>" <?php echo $is_checked; ?>>
<div>
<div class="fw-bold"><?php echo htmlspecialchars($attorney['first_name'] . ' ' . $attorney['last_name']); ?></div>
<div class="small text-muted"><?php echo htmlspecialchars($attorney['email']); ?></div>
</div>
</label>
<?php endforeach; ?>
</div>
<p class="small text-muted mt-3">If you appointed attorneys jointly, they must all register the LPA together.</p>
</div>
<div class="mt-5 d-flex justify-content-between align-items-center">
<a href="apply.php?step=9&id=<?php echo $lpa_id; ?>" class="btn btn-link text-decoration-none text-muted p-0">Back to Step 9</a>
<button type="submit" class="btn btn-primary btn-lg px-5">Continue to Step 11</button>
</div>
</form>
<?php elseif ($step === 11): ?>
<h2 class="h4 fw-bold mb-4">Who should receive the LPA?</h2>
<p class="text-muted mb-5">Nominate the person who should receive the registered LPA document.</p>
<form id="lpaFormStep11" class="lpa-form" method="POST" action="api/save_lpa.php">
<input type="hidden" name="step" value="11">
<input type="hidden" name="lpa_id" value="<?php echo $lpa_id; ?>">
<div class="mb-5">
<div class="form-check p-0 mb-4">
<input type="radio" class="btn-check" name="correspondence_who" id="corr_donor" value="Donor"
<?php echo ($lpa_data && $lpa_data['correspondence_who'] === 'Donor') ? 'checked' : 'checked'; ?> required>
<label class="btn btn-outline-secondary w-100 p-4 text-start h-100 d-flex align-items-center" for="corr_donor">
<div class="flex-grow-1">
<div class="fw-bold text-dark mb-1">The donor</div>
<div class="small text-muted">Send the registered LPA to the donor's address.</div>
</div>
<div class="ms-3">
<div class="form-check-input-placeholder"></div>
</div>
</label>
</div>
<div class="form-check p-0 mb-4">
<input type="radio" class="btn-check" name="correspondence_who" id="corr_attorney" value="Attorney"
<?php echo ($lpa_data && $lpa_data['correspondence_who'] === 'Attorney') ? 'checked' : ''; ?>>
<label class="btn btn-outline-secondary w-100 p-4 text-start h-100 d-flex align-items-center" for="corr_attorney">
<div class="flex-grow-1">
<div class="fw-bold text-dark mb-1">An Attorney</div>
<div class="small text-muted">Send the registered LPA to one of the attorneys.</div>
</div>
<div class="ms-3">
<div class="form-check-input-placeholder"></div>
</div>
</label>
</div>
<div class="form-check p-0 mb-4">
<input type="radio" class="btn-check" name="correspondence_who" id="corr_other" value="Other"
<?php echo ($lpa_data && $lpa_data['correspondence_who'] === 'Other') ? 'checked' : ''; ?>>
<label class="btn btn-outline-secondary w-100 p-4 text-start h-100 d-flex align-items-center" for="corr_other">
<div class="flex-grow-1">
<div class="fw-bold text-dark mb-1">Other</div>
<div class="small text-muted">Send the registered LPA to another person or company.</div>
</div>
<div class="ms-3">
<div class="form-check-input-placeholder"></div>
</div>
</label>
</div>
</div>
<div id="correspondence_details" class="<?php echo ($lpa_data && in_array($lpa_data['correspondence_who'], ['Attorney', 'Other'])) ? '' : 'd-none'; ?> mb-5 animate-fade-in">
<h3 class="h6 fw-bold mb-4 text-uppercase tracking-wider text-muted">Correspondence Details</h3>
<div class="row g-4">
<div class="col-md-2">
<label for="correspondence_title" class="form-label fw-semibold">Title</label>
<input type="text" class="form-control" id="correspondence_title" name="correspondence_title" placeholder="Mr/Ms" value="<?php echo htmlspecialchars($lpa_data['correspondence_title'] ?? ''); ?>">
</div>
<div class="col-md-5">
<label for="correspondence_first_name" class="form-label fw-semibold">First Name(s)</label>
<input type="text" class="form-control" id="correspondence_first_name" name="correspondence_first_name" value="<?php echo htmlspecialchars($lpa_data['correspondence_first_name'] ?? ''); ?>">
</div>
<div class="col-md-5">
<label for="correspondence_last_name" class="form-label fw-semibold">Last Name</label>
<input type="text" class="form-control" id="correspondence_last_name" name="correspondence_last_name" value="<?php echo htmlspecialchars($lpa_data['correspondence_last_name'] ?? ''); ?>">
</div>
<div class="col-12">
<label for="correspondence_company_name" class="form-label fw-semibold">Company Name (Optional)</label>
<input type="text" class="form-control" id="correspondence_company_name" name="correspondence_company_name" value="<?php echo htmlspecialchars($lpa_data['correspondence_company_name'] ?? ''); ?>">
</div>
<div class="col-12">
<label for="correspondence_address_line1" class="form-label fw-semibold">Address Line 1</label>
<input type="text" class="form-control" id="correspondence_address_line1" name="correspondence_address_line1" value="<?php echo htmlspecialchars($lpa_data['correspondence_address_line1'] ?? ''); ?>">
</div>
<div class="col-12">
<label for="correspondence_address_line2" class="form-label fw-semibold">Address Line 2 (Optional)</label>
<input type="text" class="form-control" id="correspondence_address_line2" name="correspondence_address_line2" value="<?php echo htmlspecialchars($lpa_data['correspondence_address_line2'] ?? ''); ?>">
</div>
<div class="col-md-8">
<label for="correspondence_address_line3" class="form-label fw-semibold">Address Line 3 (Optional)</label>
<input type="text" class="form-control" id="correspondence_address_line3" name="correspondence_address_line3" value="<?php echo htmlspecialchars($lpa_data['correspondence_address_line3'] ?? ''); ?>">
</div>
<div class="col-md-4">
<label for="correspondence_postcode" class="form-label fw-semibold">Postcode</label>
<input type="text" class="form-control" id="correspondence_postcode" name="correspondence_postcode" value="<?php echo htmlspecialchars($lpa_data['correspondence_postcode'] ?? ''); ?>">
</div>
</div>
<div class="mt-5">
<h3 class="h6 fw-bold mb-4 text-uppercase tracking-wider text-muted">How would the person above prefer to be contacted?</h3>
<div class="row g-3">
<?php
$pref = $lpa_data['correspondence_contact_preference'] ?? 'Post';
?>
<div class="col-6 col-md-3">
<input type="radio" class="btn-check contact-pref-check" name="correspondence_contact_preference" id="pref_post" value="Post" <?php echo ($pref === 'Post') ? 'checked' : ''; ?>>
<label class="btn btn-outline-secondary w-100 py-3" for="pref_post">Post</label>
</div>
<div class="col-6 col-md-3">
<input type="radio" class="btn-check contact-pref-check" name="correspondence_contact_preference" id="pref_phone" value="Phone" <?php echo ($pref === 'Phone') ? 'checked' : ''; ?>>
<label class="btn btn-outline-secondary w-100 py-3" for="pref_phone">Phone</label>
</div>
<div class="col-6 col-md-3">
<input type="radio" class="btn-check contact-pref-check" name="correspondence_contact_preference" id="pref_email" value="Email" <?php echo ($pref === 'Email') ? 'checked' : ''; ?>>
<label class="btn btn-outline-secondary w-100 py-3" for="pref_email">Email</label>
</div>
<div class="col-6 col-md-3">
<input type="radio" class="btn-check contact-pref-check" name="correspondence_contact_preference" id="pref_welsh" value="Welsh" <?php echo ($pref === 'Welsh') ? 'checked' : ''; ?>>
<label class="btn btn-outline-secondary w-100 py-3" for="pref_welsh">Welsh</label>
</div>
</div>
<div id="phone_input_box" class="<?php echo ($pref === 'Phone') ? '' : 'd-none'; ?> mt-4">
<label for="correspondence_phone" class="form-label fw-semibold">Phone Number</label>
<input type="text" class="form-control" id="correspondence_phone" name="correspondence_phone" value="<?php echo htmlspecialchars($lpa_data['correspondence_phone'] ?? ''); ?>">
</div>
<div id="email_input_box" class="<?php echo ($pref === 'Email') ? '' : 'd-none'; ?> mt-4">
<label for="correspondence_email" class="form-label fw-semibold">Email Address</label>
<input type="email" class="form-control" id="correspondence_email" name="correspondence_email" value="<?php echo htmlspecialchars($lpa_data['correspondence_email'] ?? ''); ?>">
</div>
</div>
</div>
<div class="mt-5 d-flex justify-content-between align-items-center">
<a href="apply.php?step=10&id=<?php echo $lpa_id; ?>" class="btn btn-link text-decoration-none text-muted p-0">Back to Step 10</a>
<button type="submit" class="btn btn-primary btn-lg px-5">Continue to Step 12</button>
</div>
</form>
<?php elseif ($step === 12): ?>
<h2 class="h4 fw-bold mb-4">Application fee</h2>
<p class="text-muted mb-5">Specify how you wish to pay the application fee and if you are eligible for any reductions.</p>
<form id="lpaFormStep12" class="lpa-form" method="POST" action="api/save_lpa.php">
<input type="hidden" name="step" value="12">
<input type="hidden" name="lpa_id" value="<?php echo $lpa_id; ?>">
<!-- Section 1: Payment Method -->
<div class="mb-5">
<h3 class="h6 fw-bold mb-4 text-uppercase tracking-wider text-muted">Section 1: How do you want to pay?</h3>
<div class="row g-3">
<div class="col-md-6">
<input type="radio" class="btn-check" name="payment_method" id="pay_card" value="Card" <?php echo ($lpa_data && $lpa_data['payment_method'] === 'Card') ? 'checked' : 'checked'; ?> required>
<label class="btn btn-outline-secondary w-100 p-4 text-start h-100 d-flex align-items-center" for="pay_card">
<div class="flex-grow-1">
<div class="fw-bold text-dark mb-1">Card</div>
<div class="small text-muted">Pay securely over the phone.</div>
</div>
<div class="ms-3">
<div class="form-check-input-placeholder"></div>
</div>
</label>
</div>
<div class="col-md-6">
<input type="radio" class="btn-check" name="payment_method" id="pay_cheque" value="Cheque" <?php echo ($lpa_data && $lpa_data['payment_method'] === 'Cheque') ? 'checked' : ''; ?>>
<label class="btn btn-outline-secondary w-100 p-4 text-start h-100 d-flex align-items-center" for="pay_cheque">
<div class="flex-grow-1">
<div class="fw-bold text-dark mb-1">Cheque</div>
<div class="small text-muted">Send a cheque by post.</div>
</div>
<div class="ms-3">
<div class="form-check-input-placeholder"></div>
</div>
</label>
</div>
</div>
<div id="payment_phone_box" class="<?php echo ($lpa_data && $lpa_data['payment_method'] === 'Cheque') ? 'd-none' : ''; ?> mt-4">
<label for="payment_phone" class="form-label fw-semibold">Phone number for card payment</label>
<input type="text" class="form-control" id="payment_phone" name="payment_phone" value="<?php echo htmlspecialchars($lpa_data['payment_phone'] ?? ''); ?>" placeholder="Enter phone number">
</div>
</div>
<hr class="my-5 text-muted opacity-25">
<!-- Section 2: Reduced Fee -->
<div class="mb-5">
<h3 class="h6 fw-bold mb-4 text-uppercase tracking-wider text-muted">Section 2: Reduced fee eligibility</h3>
<p class="text-muted small mb-4">Are you eligible to pay a reduced fee or no fee at all? (e.g., due to low income or receiving certain benefits)</p>
<div class="row g-3">
<div class="col-md-6">
<input type="radio" class="btn-check" name="reduced_fee_eligibility" id="fee_yes" value="Yes" <?php echo ($lpa_data && $lpa_data['reduced_fee_eligibility'] === 'Yes') ? 'checked' : ''; ?> required>
<label class="btn btn-outline-secondary w-100 p-3 text-center" for="fee_yes">Yes, I am eligible</label>
</div>
<div class="col-md-6">
<input type="radio" class="btn-check" name="reduced_fee_eligibility" id="fee_no" value="No" <?php echo ($lpa_data && $lpa_data['reduced_fee_eligibility'] === 'No') ? 'checked' : 'checked'; ?>>
<label class="btn btn-outline-secondary w-100 p-3 text-center" for="fee_no">No, I am not eligible</label>
</div>
</div>
</div>
<hr class="my-5 text-muted opacity-25">
<!-- Section 3: Repeat Application -->
<div class="mb-5">
<h3 class="h6 fw-bold mb-4 text-uppercase tracking-wider text-muted">Section 3: Repeat application</h3>
<div class="form-check mb-4">
<input class="form-check-input" type="checkbox" name="is_repeat_application" id="is_repeat_application" value="1" <?php echo ($lpa_data && $lpa_data['is_repeat_application']) ? 'checked' : ''; ?>>
<label class="form-check-label fw-semibold" for="is_repeat_application">
This is a repeat application
</label>
<p class="text-muted small mt-1">Check this box if you are resubmitting an application that was previously returned or rejected.</p>
</div>
<div id="repeat_case_box" class="<?php echo ($lpa_data && $lpa_data['is_repeat_application']) ? '' : 'd-none'; ?>">
<label for="repeat_case_number" class="form-label fw-semibold">Case number (from previous application)</label>
<input type="text" class="form-control" id="repeat_case_number" name="repeat_case_number" value="<?php echo htmlspecialchars($lpa_data['repeat_case_number'] ?? ''); ?>" placeholder="Enter case number">
</div>
</div>
<div class="mt-5 d-flex justify-content-between align-items-center">
<a href="apply.php?step=11&id=<?php echo $lpa_id; ?>" class="btn btn-link text-decoration-none text-muted p-0">Back to Step 11</a>
<button type="submit" class="btn btn-primary btn-lg px-5">Continue to Step 13</button>
</div>
</form>
<?php elseif ($step === 13): ?>
<h2 class="h4 fw-bold mb-4">Review Summary</h2>
<p class="text-muted mb-5">Please review all your details before final submission.</p>
<!-- Step 1: Donor -->
<div class="summary-section">
<div class="d-flex justify-content-between align-items-center mb-3">
<h3 class="h5 fw-bold mb-0">1. Donor Details</h3>
<a href="apply.php?step=1&id=<?php echo $lpa_id; ?>" class="edit-link text-primary">Edit Section</a>
</div>
<div class="row g-3">
<div class="col-md-4">
<div class="summary-label">LPA Type</div>
<div class="summary-value"><?php echo htmlspecialchars($lpa_data['lpa_type'] ?? ''); ?></div>
</div>
<div class="col-md-4">
<div class="summary-label">Donor Name</div>
<div class="summary-value"><?php echo htmlspecialchars($lpa_data['donor_name'] ?? ''); ?></div>
</div>
<div class="col-md-4">
<div class="summary-label">Date of Birth</div>
<div class="summary-value"><?php echo htmlspecialchars($lpa_data['donor_dob'] ?? ''); ?></div>
</div>
<div class="col-md-4">
<div class="summary-label">Email</div>
<div class="summary-value"><?php echo htmlspecialchars($lpa_data['customer_email'] ?? ''); ?></div>
</div>
<div class="col-md-8">
<div class="summary-label">Address</div>
<div class="summary-value">
<?php
echo htmlspecialchars($lpa_data['donor_address_line1'] ?? '');
if (!empty($lpa_data['donor_address_line2'])) echo ', ' . htmlspecialchars($lpa_data['donor_address_line2']);
echo ', ' . htmlspecialchars($lpa_data['donor_town'] ?? '');
echo ', ' . htmlspecialchars($lpa_data['donor_postcode'] ?? '');
?>
</div>
</div>
</div>
</div>
<!-- Step 2: Attorneys -->
<div class="summary-section">
<div class="d-flex justify-content-between align-items-center mb-3">
<h3 class="h5 fw-bold mb-0">2. Attorneys</h3>
<a href="apply.php?step=2&id=<?php echo $lpa_id; ?>" class="edit-link text-primary">Edit Section</a>
</div>
<?php if (empty($attorneys)): ?>
<div class="text-muted">No attorneys added.</div>
<?php else: ?>
<div class="row g-4">
<?php foreach ($attorneys as $idx => $att): ?>
<div class="col-md-6">
<div class="p-3 bg-light rounded-3 h-100">
<div class="fw-bold mb-1"><?php echo htmlspecialchars(($att['title'] ? $att['title'] . ' ' : '') . $att['first_name'] . ' ' . $att['last_name']); ?></div>
<div class="small text-muted mb-2"><?php echo htmlspecialchars($att['email']); ?> &bull; <?php echo htmlspecialchars($att['dob']); ?></div>
<div class="small text-dark">
<?php
echo htmlspecialchars($att['address_line1']);
if (!empty($att['address_line2'])) echo ', ' . htmlspecialchars($att['address_line2']);
echo ', ' . htmlspecialchars($att['town']);
echo ', ' . htmlspecialchars($att['postcode']);
?>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<!-- Step 3: Decisions -->
<div class="summary-section">
<div class="d-flex justify-content-between align-items-center mb-3">
<h3 class="h5 fw-bold mb-0">3. Decision Making</h3>
<a href="apply.php?step=3&id=<?php echo $lpa_id; ?>" class="edit-link text-primary">Edit Section</a>
</div>
<div class="summary-value"><?php echo htmlspecialchars($lpa_data['attorney_decision_type'] ?? 'Not specified'); ?></div>
</div>
<!-- Step 4: Replacement Attorneys -->
<div class="summary-section">
<div class="d-flex justify-content-between align-items-center mb-3">
<h3 class="h5 fw-bold mb-0">4. Replacement Attorneys</h3>
<a href="apply.php?step=4&id=<?php echo $lpa_id; ?>" class="edit-link text-primary">Edit Section</a>
</div>
<?php if (empty($replacement_attorneys)): ?>
<div class="text-muted">No replacement attorneys added.</div>
<?php else: ?>
<div class="row g-4">
<?php foreach ($replacement_attorneys as $idx => $att): ?>
<div class="col-md-6">
<div class="p-3 bg-light rounded-3 h-100">
<div class="fw-bold mb-1"><?php echo htmlspecialchars(($att['title'] ? $att['title'] . ' ' : '') . $att['first_name'] . ' ' . $att['last_name']); ?></div>
<div class="small text-muted mb-2"><?php echo htmlspecialchars($att['email']); ?> &bull; <?php echo htmlspecialchars($att['dob']); ?></div>
<div class="small text-dark">
<?php
echo htmlspecialchars($att['address_line1']);
if (!empty($att['address_line2'])) echo ', ' . htmlspecialchars($att['address_line2']);
echo ', ' . htmlspecialchars($att['town']);
echo ', ' . htmlspecialchars($att['postcode']);
?>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<!-- Step 5: Life Sustaining & Witness -->
<div class="summary-section">
<div class="d-flex justify-content-between align-items-center mb-3">
<h3 class="h5 fw-bold mb-0">5. Life-sustaining treatment & Witness</h3>
<a href="apply.php?step=5&id=<?php echo $lpa_id; ?>" class="edit-link text-primary">Edit Section</a>
</div>
<div class="row g-3">
<div class="col-md-6">
<div class="summary-label">Life-sustaining Treatment</div>
<div class="summary-value"><?php echo htmlspecialchars($lpa_data['life_sustaining_treatment'] ?? ''); ?></div>
</div>
<div class="col-md-6">
<div class="summary-label">Donor's Witness</div>
<div class="summary-value">
<?php
echo htmlspecialchars(($lpa_data['witness_first_name'] ?? '') . ' ' . ($lpa_data['witness_last_name'] ?? ''));
if (!empty($lpa_data['witness_postcode'])) echo ' (' . htmlspecialchars($lpa_data['witness_postcode']) . ')';
?>
</div>
</div>
</div>
</div>
<!-- Step 6: Notified Persons -->
<div class="summary-section">
<div class="d-flex justify-content-between align-items-center mb-3">
<h3 class="h5 fw-bold mb-0">6. People to Notify</h3>
<a href="apply.php?step=6&id=<?php echo $lpa_id; ?>" class="edit-link text-primary">Edit Section</a>
</div>
<?php if (empty($notified_persons)): ?>
<div class="text-muted">No people to notify.</div>
<?php else: ?>
<div class="row g-3">
<?php foreach ($notified_persons as $np): ?>
<div class="col-md-4">
<div class="p-2 bg-light rounded">
<div class="fw-bold small"><?php echo htmlspecialchars($np['first_name'] . ' ' . $np['last_name']); ?></div>
<div class="text-muted extra-small"><?php echo htmlspecialchars($np['postcode']); ?></div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<!-- Step 7: Preferences & Instructions -->
<div class="summary-section">
<div class="d-flex justify-content-between align-items-center mb-3">
<h3 class="h5 fw-bold mb-0">7. Preferences and Instructions</h3>
<a href="apply.php?step=7&id=<?php echo $lpa_id; ?>" class="edit-link text-primary">Edit Section</a>
</div>
<div class="row g-3">
<div class="col-12">
<div class="summary-label">Preferences</div>
<div class="summary-value small"><?php echo !empty($lpa_data['preferences']) ? nl2br(htmlspecialchars($lpa_data['preferences'])) : 'None provided'; ?></div>
</div>
<div class="col-12">
<div class="summary-label">Instructions</div>
<div class="summary-value small"><?php echo !empty($lpa_data['instructions']) ? nl2br(htmlspecialchars($lpa_data['instructions'])) : 'None provided'; ?></div>
</div>
</div>
</div>
<!-- Step 8: Certificate Provider -->
<div class="summary-section">
<div class="d-flex justify-content-between align-items-center mb-3">
<h3 class="h5 fw-bold mb-0">8. Certificate Provider</h3>
<a href="apply.php?step=8&id=<?php echo $lpa_id; ?>" class="edit-link text-primary">Edit Section</a>
</div>
<div class="summary-value">
<?php
echo htmlspecialchars(($lpa_data['certificate_provider_title'] ? $lpa_data['certificate_provider_title'] . ' ' : '') . ($lpa_data['certificate_provider_first_name'] ?? '') . ' ' . ($lpa_data['certificate_provider_last_name'] ?? ''));
if (!empty($lpa_data['certificate_provider_postcode'])) echo ', ' . htmlspecialchars($lpa_data['certificate_provider_postcode']);
?>
</div>
</div>
<!-- Step 9: Attorney Witnesses -->
<div class="summary-section">
<div class="d-flex justify-content-between align-items-center mb-3">
<h3 class="h5 fw-bold mb-0">9. Attorney Witnesses</h3>
<a href="apply.php?step=9&id=<?php echo $lpa_id; ?>" class="edit-link text-primary">Edit Section</a>
</div>
<div class="row g-3">
<?php foreach ($all_attorneys as $att): ?>
<div class="col-md-6">
<div class="summary-label">Witness for <?php echo htmlspecialchars($att['first_name']); ?></div>
<div class="summary-value small">
<?php
if (!empty($att['witness_first_name'])) {
echo htmlspecialchars($att['witness_first_name'] . ' ' . $att['witness_last_name']);
echo ' (' . htmlspecialchars($att['witness_postcode']) . ')';
} else {
echo '<span class="text-danger">Not specified</span>';
}
?>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<!-- Step 10: Registration -->
<div class="summary-section">
<div class="d-flex justify-content-between align-items-center mb-3">
<h3 class="h5 fw-bold mb-0">10. Registration</h3>
<a href="apply.php?step=10&id=<?php echo $lpa_id; ?>" class="edit-link text-primary">Edit Section</a>
</div>
<div class="row g-3">
<div class="col-md-6">
<div class="summary-label">Who is registering?</div>
<div class="summary-value"><?php echo ucfirst(htmlspecialchars($lpa_data['registration_who'] ?? '')); ?></div>
</div>
<?php if ($lpa_data['registration_who'] === 'attorneys'): ?>
<div class="col-md-6">
<div class="summary-label">Registering Attorneys</div>
<div class="summary-value small">
<?php
$reg_ids = !empty($lpa_data['registering_attorneys_ids']) ? explode(',', $lpa_data['registering_attorneys_ids']) : [];
$reg_names = [];
foreach ($attorneys as $att) {
if (in_array($att['id'], $reg_ids)) {
$reg_names[] = htmlspecialchars($att['first_name'] . ' ' . $att['last_name']);
}
}
echo !empty($reg_names) ? implode(', ', $reg_names) : 'None selected';
?>
</div>
</div>
<?php endif; ?>
</div>
</div>
<!-- Step 11: Correspondence -->
<div class="summary-section">
<div class="d-flex justify-content-between align-items-center mb-3">
<h3 class="h5 fw-bold mb-0">11. Correspondence</h3>
<a href="apply.php?step=11&id=<?php echo $lpa_id; ?>" class="edit-link text-primary">Edit Section</a>
</div>
<div class="row g-3">
<div class="col-md-4">
<div class="summary-label">Recipient</div>
<div class="summary-value"><?php echo htmlspecialchars($lpa_data['correspondence_who'] ?? ''); ?></div>
</div>
<?php if ($lpa_data['correspondence_who'] !== 'Donor'): ?>
<div class="col-md-4">
<div class="summary-label">Name</div>
<div class="summary-value"><?php echo htmlspecialchars(($lpa_data['correspondence_first_name'] ?? '') . ' ' . ($lpa_data['correspondence_last_name'] ?? '')); ?></div>
</div>
<div class="col-md-4">
<div class="summary-label">Contact Method</div>
<div class="summary-value">
<?php
echo htmlspecialchars($lpa_data['correspondence_contact_preference'] ?? '');
if ($lpa_data['correspondence_contact_preference'] === 'Phone') echo ': ' . htmlspecialchars($lpa_data['correspondence_phone'] ?? '');
if ($lpa_data['correspondence_contact_preference'] === 'Email') echo ': ' . htmlspecialchars($lpa_data['correspondence_email'] ?? '');
?>
</div>
</div>
<?php endif; ?>
</div>
</div>
<!-- Step 12: Payment -->
<div class="summary-section">
<div class="d-flex justify-content-between align-items-center mb-3">
<h3 class="h5 fw-bold mb-0">12. Payment & Fee</h3>
<a href="apply.php?step=12&id=<?php echo $lpa_id; ?>" class="edit-link text-primary">Edit Section</a>
</div>
<div class="row g-3">
<div class="col-md-4">
<div class="summary-label">Payment Method</div>
<div class="summary-value">
<?php
echo htmlspecialchars($lpa_data['payment_method'] ?? '');
if ($lpa_data['payment_method'] === 'Card') echo ' (' . htmlspecialchars($lpa_data['payment_phone'] ?? '') . ')';
?>
</div>
</div>
<div class="col-md-4">
<div class="summary-label">Reduced Fee Eligibility</div>
<div class="summary-value"><?php echo htmlspecialchars($lpa_data['reduced_fee_eligibility'] ?? ''); ?></div>
</div>
<div class="col-md-4">
<div class="summary-label">Repeat Application</div>
<div class="summary-value">
<?php
echo (!empty($lpa_data['is_repeat_application'])) ? 'Yes (Case: ' . htmlspecialchars($lpa_data['repeat_case_number'] ?? '') . ')' : 'No';
?>
</div>
</div>
</div>
</div>
<form id="lpaFormStep13" class="lpa-form" method="POST" action="api/save_lpa.php">
<input type="hidden" name="step" value="13">
<input type="hidden" name="lpa_id" value="<?php echo $lpa_id; ?>">
<div class="mt-5 d-flex justify-content-between align-items-center">
<a href="apply.php?step=12&id=<?php echo $lpa_id; ?>" class="btn btn-link text-decoration-none text-muted p-0">Back to Step 12</a>
<a href="api/generate_pdf.php?id=<?php echo $lpa_id; ?>" class="btn btn-outline-primary btn-lg px-4 me-3"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="me-2"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="7 10 12 15 17 10"></polyline><line x1="12" y1="15" x2="12" y2="3"></line></svg> Download Summary PDF</a>
<button type="submit" class="btn btn-primary btn-lg px-5">Confirm & Submit Application</button>
</div>
</form>
<?php endif; ?>
</div>
</div>
</div>
</div>
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Witness selector logic
const witnessSelectors = document.querySelectorAll('.witness-selector');
witnessSelectors.forEach(selector => {
selector.addEventListener('change', function() {
const attorneyId = this.getAttribute('data-attorney-id');
const newFields = document.getElementById('new_witness_fields_' + attorneyId);
if (this.value === 'new') {
if (newFields) {
newFields.classList.remove('d-none');
newFields.querySelectorAll('input').forEach(input => input.setAttribute('required', 'required'));
}
} else {
if (newFields) {
newFields.classList.add('d-none');
newFields.querySelectorAll('input').forEach(input => input.removeAttribute('required'));
}
}
});
});
// Correspondence logic
const corrRadios = document.querySelectorAll('input[name="correspondence_who"]');
const corrDetails = document.getElementById('correspondence_details');
corrRadios.forEach(radio => {
radio.addEventListener('change', function() {
if (this.value === 'Donor') {
if (corrDetails) {
corrDetails.classList.add('d-none');
corrDetails.querySelectorAll('input').forEach(input => input.removeAttribute('required'));
}
} else {
if (corrDetails) {
corrDetails.classList.remove('d-none');
const addr1 = document.getElementById('correspondence_address_line1');
const pc = document.getElementById('correspondence_postcode');
const fn = document.getElementById('correspondence_first_name');
const ln = document.getElementById('correspondence_last_name');
if (addr1) addr1.setAttribute('required', 'required');
if (pc) pc.setAttribute('required', 'required');
if (fn) fn.setAttribute('required', 'required');
if (ln) ln.setAttribute('required', 'required');
}
}
});
});
// Contact preference logic
const prefRadios = document.querySelectorAll('.contact-pref-check');
const phoneBox = document.getElementById('phone_input_box');
const emailBox = document.getElementById('email_input_box');
prefRadios.forEach(radio => {
radio.addEventListener('change', function() {
if (phoneBox) phoneBox.classList.add('d-none');
if (emailBox) emailBox.classList.add('d-none');
const phoneInput = document.getElementById('correspondence_phone');
const emailInput = document.getElementById('correspondence_email');
if (phoneInput) phoneInput.removeAttribute('required');
if (emailInput) emailInput.removeAttribute('required');
if (this.value === 'Phone') {
if (phoneBox) phoneBox.classList.remove('d-none');
if (phoneInput) phoneInput.setAttribute('required', 'required');
} else if (this.value === 'Email') {
if (emailBox) emailBox.classList.remove('d-none');
if (emailInput) emailInput.setAttribute('required', 'required');
}
});
});
// Payment method logic (Step 12)
const payMethodRadios = document.querySelectorAll('input[name="payment_method"]');
const paymentPhoneBox = document.getElementById('payment_phone_box');
payMethodRadios.forEach(radio => {
radio.addEventListener('change', function() {
const payPhone = document.getElementById('payment_phone');
if (this.value === 'Card') {
if (paymentPhoneBox) paymentPhoneBox.classList.remove('d-none');
if (payPhone) payPhone.setAttribute('required', 'required');
} else {
if (paymentPhoneBox) paymentPhoneBox.classList.add('d-none');
if (payPhone) payPhone.removeAttribute('required');
}
});
});
// Repeat application logic (Step 12)
const repeatCheck = document.getElementById('is_repeat_application');
const repeatBox = document.getElementById('repeat_case_box');
if (repeatCheck) {
repeatCheck.addEventListener('change', function() {
const repeatCase = document.getElementById('repeat_case_number');
if (this.checked) {
if (repeatBox) repeatBox.classList.remove('d-none');
if (repeatCase) repeatCase.setAttribute('required', 'required');
} else {
if (repeatBox) repeatBox.classList.add('d-none');
if (repeatCase) repeatCase.removeAttribute('required');
}
});
}
const deleteNotifiedBtns = document.querySelectorAll('.btn-delete-notified');
deleteNotifiedBtns.forEach(btn => {
btn.addEventListener('click', function() {
if (confirm('Are you sure you want to remove this person?')) {
const personId = btn.getAttribute('data-id');
const lpaId = btn.getAttribute('data-lpa-id');
const formData = new FormData();
formData.append('action', 'delete_notified_person');
formData.append('person_id', personId);
formData.append('lpa_id', lpaId);
fetch('api/save_lpa.php', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.success) {
window.location.reload();
} else {
alert(data.error || 'Failed to remove person.');
}
});
}
});
});
});
</script>
</body>
</html>