LPA-Health-V1.6

This commit is contained in:
Flatlogic Bot 2026-03-01 21:26:29 +00:00
parent e1f682ee18
commit ebe00fb7c9
4 changed files with 156 additions and 14 deletions

View File

@ -213,7 +213,7 @@ $pdf->Field('Recipient', $lpa_data['correspondence_who'] ?? '');
if (($lpa_data['correspondence_who'] ?? '') !== 'Donor') {
$pdf->Field('Name', ($lpa_data['correspondence_first_name'] ?? '') . ' ' . ($lpa_data['correspondence_last_name'] ?? ''));
$pdf->Field('Address', ($lpa_data['correspondence_address_line1'] ?? '') . ', ' . ($lpa_data['correspondence_postcode'] ?? ''));
$pdf->Field('Contact Preference', $lpa_data['correspondence_contact_preference'] ?? '');
$pdf->Field('Contact Preference', str_replace(',', ', ', $lpa_data['correspondence_contact_preference'] ?? ''));
}
$pdf->Ln(5);

View File

@ -478,7 +478,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$address2 = $_POST['correspondence_address_line2'] ?? '';
$address3 = $_POST['correspondence_address_line3'] ?? '';
$postcode = $_POST['correspondence_postcode'] ?? '';
$contact_preference = $_POST['correspondence_contact_preference'] ?? 'Post';
$contact_preference = isset($_POST['correspondence_contact_preference']) ? (is_array($_POST['correspondence_contact_preference']) ? implode(',', $_POST['correspondence_contact_preference']) : $_POST['correspondence_contact_preference']) : 'Post';
$phone = $_POST['correspondence_phone'] ?? '';
$email = $_POST['correspondence_email'] ?? '';

View File

@ -807,6 +807,7 @@ foreach ($notified_persons as $np) {
</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>
<option value="later" <?php echo (empty($attorney['witness_first_name']) && !empty($attorney['witness_postcode']) === false && empty($selected) && !empty($attorney['id'])) ? '' : ''; ?>>I will add witness details manually later</option>
</select>
</div>
@ -840,6 +841,14 @@ foreach ($notified_persons as $np) {
<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 class="col-12 mt-2">
<div class="form-check">
<input class="form-check-input manual-witness-checkbox" type="checkbox" name="attorney_witness[<?php echo $attorney['id']; ?>][add_later]" id="add_later_<?php echo $attorney['id']; ?>" value="1">
<label class="form-check-label small" for="add_later_<?php echo $attorney['id']; ?>">
I will add these details manually later
</label>
</div>
</div>
</div>
</div>
</div>
@ -924,7 +933,7 @@ foreach ($notified_persons as $np) {
<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>
<?php echo (!$lpa_data || !isset($lpa_data['correspondence_who']) || $lpa_data['correspondence_who'] === 'Donor') ? 'checked' : ''; ?> required>
<label class="btn btn-outline-secondary w-100 p-3 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>
@ -938,7 +947,7 @@ foreach ($notified_persons as $np) {
<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' : ''; ?>>
<?php echo ($lpa_data && isset($lpa_data['correspondence_who']) && $lpa_data['correspondence_who'] === 'Attorney') ? 'checked' : ''; ?>>
<label class="btn btn-outline-secondary w-100 p-3 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>
@ -952,7 +961,7 @@ foreach ($notified_persons as $np) {
<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' : ''; ?>>
<?php echo ($lpa_data && isset($lpa_data['correspondence_who']) && $lpa_data['correspondence_who'] === 'Other') ? 'checked' : ''; ?>>
<label class="btn btn-outline-secondary w-100 p-3 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>
@ -967,6 +976,29 @@ foreach ($notified_persons as $np) {
<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 id="attorney_selector_container" class="<?php echo ($lpa_data && $lpa_data['correspondence_who'] === 'Attorney') ? '' : 'd-none'; ?> mb-4">
<label for="attorney_selector" class="form-label fw-semibold text-primary">Select from your existing attorneys</label>
<select class="form-select border-primary" id="attorney_selector">
<option value="">-- Choose an attorney --</option>
<?php foreach ($all_attorneys as $att): ?>
<option value='<?php echo json_encode([
"title" => $att["title"],
"first_name" => $att["first_name"],
"last_name" => $att["last_name"],
"address_line1" => $att["address_line1"],
"address_line2" => $att["address_line2"],
"address_line3" => $att["address_line3"],
"postcode" => $att["postcode"],
"email" => $att["email"]
]); ?>'>
<?php echo htmlspecialchars($att['first_name'] . ' ' . $att['last_name']); ?>
</option>
<?php endforeach; ?>
</select>
<div class="form-text mt-2">Selecting an attorney will automatically fill the details below.</div>
</div>
<div class="row g-4">
<div class="col-md-2">
<label for="correspondence_title" class="form-label fw-semibold">Title</label>
@ -1006,32 +1038,33 @@ foreach ($notified_persons as $np) {
<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';
$pref_raw = $lpa_data['correspondence_contact_preference'] ?? 'Post';
$prefs = explode(',', $pref_raw);
?>
<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' : ''; ?>>
<input type="checkbox" class="btn-check contact-pref-check" name="correspondence_contact_preference[]" id="pref_post" value="Post" <?php echo in_array('Post', $prefs) ? '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' : ''; ?>>
<input type="checkbox" class="btn-check contact-pref-check" name="correspondence_contact_preference[]" id="pref_phone" value="Phone" <?php echo in_array('Phone', $prefs) ? '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' : ''; ?>>
<input type="checkbox" class="btn-check contact-pref-check" name="correspondence_contact_preference[]" id="pref_email" value="Email" <?php echo in_array('Email', $prefs) ? '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>
<input type="checkbox" class="btn-check contact-pref-check" name="correspondence_contact_preference[]" id="pref_welsh" value="Welsh" <?php echo in_array('Welsh', $prefs) ? 'checked' : ''; ?>>
<label class="btn btn-outline-secondary w-100 py-3 px-1" for="pref_welsh" style="font-size: 0.75rem; line-height: 1.2;">Welsh (The OPG will write to the recipient in Welsh)</label>
</div>
</div>
<div id="phone_input_box" class="<?php echo ($pref === 'Phone') ? '' : 'd-none'; ?> mt-4">
<div id="phone_input_box" class="<?php echo in_array('Phone', $prefs) ? '' : '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">
<div id="email_input_box" class="<?php echo in_array('Email', $prefs) ? '' : '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>
@ -1432,4 +1465,4 @@ foreach ($notified_persons as $np) {
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
</body>
</html>
</html>

View File

@ -100,4 +100,113 @@ document.addEventListener('DOMContentLoaded', function() {
}
});
});
// Step 10: Witness Selection Toggling
const witnessSelectors = document.querySelectorAll('.witness-selector');
witnessSelectors.forEach(selector => {
selector.addEventListener('change', function() {
const attorneyId = this.getAttribute('data-attorney-id');
const newWitnessFields = document.getElementById('new_witness_fields_' + attorneyId);
if (this.value === 'new') {
newWitnessFields.classList.remove('d-none');
} else {
newWitnessFields.classList.add('d-none');
}
});
});
// Step 10: Manual Witness Checkbox Toggling
const manualWitnessCheckboxes = document.querySelectorAll('.manual-witness-checkbox');
manualWitnessCheckboxes.forEach(checkbox => {
checkbox.addEventListener('change', function() {
const attorneyId = this.id.replace('add_later_', '');
const fieldsContainer = this.closest('.row').querySelectorAll('input:not(.manual-witness-checkbox)');
fieldsContainer.forEach(input => {
input.disabled = this.checked;
if (this.checked) {
input.value = '';
}
});
});
});
// Step 12: Correspondence Toggling
const corrWhoRadios = document.querySelectorAll('input[name="correspondence_who"]');
const corrDetails = document.getElementById('correspondence_details');
const attSelectorContainer = document.getElementById('attorney_selector_container');
if (corrWhoRadios.length > 0) {
corrWhoRadios.forEach(radio => {
radio.addEventListener('change', function() {
if (this.value === 'Attorney' || this.value === 'Other') {
if (corrDetails) corrDetails.classList.remove('d-none');
if (this.value === 'Attorney') {
if (attSelectorContainer) attSelectorContainer.classList.remove('d-none');
} else {
if (attSelectorContainer) attSelectorContainer.classList.add('d-none');
}
} else {
if (corrDetails) corrDetails.classList.add('d-none');
if (attSelectorContainer) attSelectorContainer.classList.add('d-none');
}
});
});
}
// Step 12: Attorney Selector Population
const attSelector = document.getElementById('attorney_selector');
if (attSelector) {
attSelector.addEventListener('change', function() {
if (this.value) {
try {
const data = JSON.parse(this.value);
document.getElementById('correspondence_title').value = data.title || '';
document.getElementById('correspondence_first_name').value = data.first_name || '';
document.getElementById('correspondence_last_name').value = data.last_name || '';
document.getElementById('correspondence_address_line1').value = data.address_line1 || '';
document.getElementById('correspondence_address_line2').value = data.address_line2 || '';
document.getElementById('correspondence_address_line3').value = data.address_line3 || '';
document.getElementById('correspondence_postcode').value = data.postcode || '';
document.getElementById('correspondence_email').value = data.email || '';
} catch (e) {
console.error('Error parsing attorney data', e);
}
}
});
}
// Step 12: Contact Preference Toggling
const contactPrefChecks = document.querySelectorAll('.contact-pref-check');
const phoneBox = document.getElementById('phone_input_box');
const emailBox = document.getElementById('email_input_box');
function updateContactPrefVisibility() {
let phoneSelected = false;
let emailSelected = false;
contactPrefChecks.forEach(check => {
if (check.checked) {
if (check.value === 'Phone') phoneSelected = true;
if (check.value === 'Email') emailSelected = true;
}
});
if (phoneBox) {
if (phoneSelected) phoneBox.classList.remove('d-none');
else phoneBox.classList.add('d-none');
}
if (emailBox) {
if (emailSelected) emailBox.classList.remove('d-none');
else emailBox.classList.add('d-none');
}
}
if (contactPrefChecks.length > 0) {
contactPrefChecks.forEach(check => {
check.addEventListener('change', updateContactPrefVisibility);
});
// Run once on load to set initial state
updateContactPrefVisibility();
}
});