37684-vm/apply.php
2026-02-28 19:00:07 +00:00

336 lines
25 KiB
PHP

<?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 = [];
if ($lpa_id && ($step === 2 || $step === 3)) {
$stmt = db()->prepare("SELECT * FROM lpa_attorneys WHERE lpa_id = ?");
$stmt->execute([$lpa_id]);
$attorneys = $stmt->fetchAll();
}
$num_attorneys = count($attorneys);
?>
<!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">
</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-8">
<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 4</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 "Review & Submit"; break;
}
?>
</span>
</div>
<div class="progress" style="height: 6px;">
<div class="progress-bar" role="progressbar" style="width: <?php echo ($step * 25); ?>%" aria-valuenow="<?php echo ($step * 25); ?>" aria-valuemin="0" aria-valuemax="100"></div>
</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 btn-delete-attorney" data-id="<?php echo $attorney['id']; ?>" data-lpa-id="<?php echo $lpa_id; ?>">Remove</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">Review & Submit</h2>
<p class="text-muted mb-5">Review all the information you have provided before submitting your application. (Step 4 implementation in progress)</p>
<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="/dashboard.php" class="btn btn-primary btn-lg px-5">Go to Dashboard</a>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
</body>
</html>