fix the event print and certificate qr
This commit is contained in:
@@ -224,23 +224,51 @@
|
||||
<?php if (empty($grouped)): ?>
|
||||
<div class="alert alert-info">No charges found.</div>
|
||||
<?php else: ?>
|
||||
<?php
|
||||
$printBaseParams = array_filter([
|
||||
'school_year' => $school_year,
|
||||
'semester' => $semester,
|
||||
'parent_id' => $filterParentId > 0 ? $filterParentId : null,
|
||||
'event_id' => $filterEventId > 0 ? $filterEventId : null,
|
||||
], static fn ($value) => $value !== null && $value !== '');
|
||||
$printAllUrl = site_url('administrator/event-charges/pdf');
|
||||
if (!empty($printBaseParams)) {
|
||||
$printAllUrl .= '?' . http_build_query($printBaseParams);
|
||||
}
|
||||
?>
|
||||
<div class="d-flex justify-content-between align-items-center flex-wrap gap-2 mb-3 no-print">
|
||||
<p class="text-muted mb-0">Click a column header to sort the participants list.</p>
|
||||
<button type="button" class="btn btn-outline-secondary" id="printAllEventCharges">
|
||||
<a href="<?= esc($printAllUrl) ?>"
|
||||
class="btn btn-outline-secondary pdf-print-link"
|
||||
data-base-href="<?= esc($printAllUrl) ?>"
|
||||
data-print-scope="all">
|
||||
Print All Participant Lists
|
||||
</button>
|
||||
</a>
|
||||
</div>
|
||||
<div id="eventChargeCards">
|
||||
<?php foreach ($grouped as $eventId => $data): ?>
|
||||
<?php $eventLabel = $data['label']; ?>
|
||||
<?php $rows = $data['rows']; ?>
|
||||
<?php
|
||||
$singlePrintParams = array_filter([
|
||||
'school_year' => $school_year,
|
||||
'semester' => $semester,
|
||||
'parent_id' => $filterParentId > 0 ? $filterParentId : null,
|
||||
'event_id' => $eventId,
|
||||
], static fn ($value) => $value !== null && $value !== '');
|
||||
$singlePrintUrl = site_url('administrator/event-charges/pdf') . '?' . http_build_query($singlePrintParams);
|
||||
?>
|
||||
<div class="card mb-4 event-card" data-event-id="<?= esc($eventId) ?>">
|
||||
<div class="card-header bg-light fw-semibold event-card-header">
|
||||
<span><?= esc($eventLabel) ?></span>
|
||||
<div class="event-card-header-actions no-print">
|
||||
<button type="button" class="btn btn-outline-secondary btn-sm print-event-card" data-event-id="<?= esc($eventId) ?>">
|
||||
<a href="<?= esc($singlePrintUrl) ?>"
|
||||
class="btn btn-outline-secondary btn-sm pdf-print-link"
|
||||
data-base-href="<?= esc($singlePrintUrl) ?>"
|
||||
data-print-scope="single"
|
||||
data-event-id="<?= esc($eventId) ?>">
|
||||
Print This List
|
||||
</button>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body p-0">
|
||||
@@ -287,7 +315,7 @@
|
||||
. (!empty($returnParams) ? '?' . http_build_query($returnParams) : '')
|
||||
. '#eventTable_' . (int) ($charge['event_id'] ?? 0);
|
||||
?>
|
||||
<tr>
|
||||
<tr data-charge-id="<?= esc((string) ($charge['id'] ?? '')) ?>">
|
||||
<td data-sort-value="<?= esc((string) ($charge['id'] ?? '')) ?>"><?= esc($charge['id']) ?></td>
|
||||
<?php
|
||||
$studentName = $charge['student_firstname']
|
||||
@@ -593,15 +621,6 @@ function loadStudentsWithCharges() {
|
||||
form.appendChild(input);
|
||||
}
|
||||
|
||||
function escapeHtml(value) {
|
||||
const s = String(value ?? '');
|
||||
return s.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
}
|
||||
|
||||
function submitExternalParticipant(payload) {
|
||||
const form = document.createElement('form');
|
||||
form.method = 'post';
|
||||
@@ -690,89 +709,41 @@ function loadStudentsWithCharges() {
|
||||
);
|
||||
}
|
||||
|
||||
function buildPrintableCard(card) {
|
||||
const clone = card.cloneNode(true);
|
||||
clone.querySelectorAll('.no-print').forEach((node) => node.remove());
|
||||
clone.querySelectorAll('.sortable-header').forEach((button) => {
|
||||
const headerText = button.textContent || '';
|
||||
const textNode = document.createTextNode(headerText);
|
||||
button.parentNode.replaceChild(textNode, button);
|
||||
});
|
||||
clone.querySelectorAll('form').forEach((form) => {
|
||||
const cell = form.closest('td');
|
||||
if (!cell) {
|
||||
form.remove();
|
||||
return;
|
||||
}
|
||||
const label = form.querySelector('.form-check-label');
|
||||
const checkbox = form.querySelector('input[type="checkbox"]');
|
||||
const text = label
|
||||
? label.textContent.trim()
|
||||
: (checkbox && checkbox.checked ? 'Paid' : 'Unpaid');
|
||||
cell.textContent = text || '—';
|
||||
});
|
||||
clone.querySelectorAll('tr').forEach((row) => {
|
||||
if (row.children.length > 10) {
|
||||
row.removeChild(row.lastElementChild);
|
||||
}
|
||||
});
|
||||
return clone.outerHTML;
|
||||
}
|
||||
|
||||
function openPrintWindow(title, contentHtml) {
|
||||
const printWindow = window.open('', '_blank', 'noopener,noreferrer,width=1200,height=900');
|
||||
if (!printWindow) {
|
||||
alert('Unable to open the print preview window. Please allow pop-ups for this site.');
|
||||
return;
|
||||
function getTableRowOrder(table) {
|
||||
if (!table || !table.tBodies.length) {
|
||||
return [];
|
||||
}
|
||||
const style = `
|
||||
<style>
|
||||
body { font-family: Arial, sans-serif; margin: 24px; color: #212529; }
|
||||
h1 { font-size: 1.5rem; margin-bottom: 0.25rem; }
|
||||
p { margin-top: 0; color: #6c757d; }
|
||||
.card { border: 1px solid #dee2e6; border-radius: 0.5rem; margin-bottom: 1.5rem; overflow: hidden; }
|
||||
.card-header { background: #f8f9fa; padding: 0.9rem 1rem; font-weight: 700; }
|
||||
.table { width: 100%; border-collapse: collapse; }
|
||||
.table th, .table td { border: 1px solid #dee2e6; padding: 0.55rem 0.7rem; text-align: left; vertical-align: top; }
|
||||
.table thead th, .table tfoot th { background: #f8f9fa; }
|
||||
.badge { display: inline-block; padding: 0.2rem 0.45rem; border-radius: 999px; font-size: 0.8rem; font-weight: 700; }
|
||||
.bg-success { background: #198754; color: #fff; }
|
||||
.bg-danger { background: #dc3545; color: #fff; }
|
||||
.bg-secondary { background: #6c757d; color: #fff; }
|
||||
.text-muted { color: #6c757d; }
|
||||
.small { font-size: 0.875rem; }
|
||||
@media print {
|
||||
body { margin: 0; }
|
||||
}
|
||||
</style>
|
||||
`;
|
||||
printWindow.document.open();
|
||||
printWindow.document.write(`
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>${escapeHtml(title)}</title>
|
||||
${style}
|
||||
</head>
|
||||
<body>
|
||||
<h1>${escapeHtml(title)}</h1>
|
||||
<p>Generated on ${escapeHtml(new Date().toLocaleString())}</p>
|
||||
${contentHtml}
|
||||
<script>
|
||||
window.onload = function() {
|
||||
window.print();
|
||||
};
|
||||
<\/script>
|
||||
</body>
|
||||
</html>
|
||||
`);
|
||||
printWindow.document.close();
|
||||
|
||||
return Array.from(table.tBodies[0].rows)
|
||||
.map((row) => String(row.dataset.chargeId || '').trim())
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
function printEventCards(cards, title) {
|
||||
const printable = cards.map((card) => buildPrintableCard(card)).join('');
|
||||
openPrintWindow(title, printable);
|
||||
function buildPdfUrl(link) {
|
||||
const baseHref = String(link.dataset.baseHref || link.getAttribute('href') || '');
|
||||
const url = new URL(baseHref, window.location.origin);
|
||||
const scope = String(link.dataset.printScope || 'single');
|
||||
|
||||
if (scope === 'all') {
|
||||
document.querySelectorAll('.event-card').forEach((card) => {
|
||||
const eventId = String(card.dataset.eventId || '').trim();
|
||||
const table = card.querySelector('.event-charges-table');
|
||||
const rowOrder = getTableRowOrder(table);
|
||||
if (eventId && rowOrder.length) {
|
||||
url.searchParams.set(`row_order[${eventId}]`, rowOrder.join(','));
|
||||
}
|
||||
});
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
const eventId = String(link.dataset.eventId || '').trim();
|
||||
const table = eventId ? document.getElementById(`eventTable_${eventId}`) : null;
|
||||
const rowOrder = getTableRowOrder(table);
|
||||
if (eventId && rowOrder.length) {
|
||||
url.searchParams.set(`row_order[${eventId}]`, rowOrder.join(','));
|
||||
}
|
||||
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
$('.sortable-header').on('click', function() {
|
||||
@@ -786,22 +757,8 @@ function loadStudentsWithCharges() {
|
||||
sortEventTable(table, columnIndex, sortType, direction);
|
||||
});
|
||||
|
||||
$('.print-event-card').on('click', function() {
|
||||
const eventId = String($(this).data('eventId'));
|
||||
const card = document.querySelector(`.event-card[data-event-id="${eventId}"]`);
|
||||
if (!card) {
|
||||
return;
|
||||
}
|
||||
const title = $(card).find('.card-header span').first().text().trim() || 'Event Participants';
|
||||
printEventCards([card], `${title} Participant List`);
|
||||
});
|
||||
|
||||
$('#printAllEventCharges').on('click', function() {
|
||||
const cards = Array.from(document.querySelectorAll('.event-card'));
|
||||
if (!cards.length) {
|
||||
return;
|
||||
}
|
||||
printEventCards(cards, 'All Event Participant Lists');
|
||||
$('.pdf-print-link').on('click', function() {
|
||||
this.href = buildPdfUrl(this);
|
||||
});
|
||||
|
||||
$('#externalParticipantSave').on('click', function() {
|
||||
|
||||
Reference in New Issue
Block a user