fix event issues

This commit is contained in:
root
2026-04-19 12:05:10 -04:00
parent 35988e9ce1
commit 596d368b1d
7 changed files with 239 additions and 29 deletions
@@ -28,7 +28,7 @@
<div class="mb-3">
<label class="form-label">Description</label>
<textarea name="description" class="form-control"></textarea>
<textarea id="event_description" name="description" class="form-control"></textarea>
</div>
<div class="mb-3">
@@ -108,17 +108,37 @@
<?= $this->endSection() ?>
<?= $this->section('scripts') ?>
<script src="<?= base_url('assets/tinymce/tinymce.min.js') ?>"></script>
<script>
(function () {
const toggle = document.getElementById('add_to_calendar');
const recipients = document.getElementById('calendar_recipients');
if (!toggle || !recipients) return;
const description = document.getElementById('event_description');
function sync() {
recipients.style.display = toggle.checked ? '' : 'none';
if (toggle && recipients) {
function sync() {
recipients.style.display = toggle.checked ? '' : 'none';
}
toggle.addEventListener('change', sync);
sync();
}
if (description && window.tinymce) {
tinymce.init({
selector: '#event_description',
base_url: '<?= base_url('assets/tinymce') ?>',
suffix: '.min',
license_key: 'gpl',
height: 320,
menubar: true,
branding: false,
promotion: false,
plugins: 'advlist autolink lists link charmap preview anchor searchreplace visualblocks code fullscreen insertdatetime table help wordcount',
toolbar: 'undo redo | blocks | bold italic underline strikethrough forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link table | removeformat | preview code',
convert_urls: false,
content_style: 'body { font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif; font-size: 14px; }'
});
}
toggle.addEventListener('change', sync);
sync();
})();
</script>
<?= $this->endSection() ?>
+76 -3
View File
@@ -4,6 +4,12 @@
<div class="container mt-4">
<h2>Edit Event</h2>
<?php
$defaultCategories = ['Fun Event-1', 'Fun Event-2', 'Fun Event-3'];
$existingCategories = array_map('strval', $categories ?? []);
$allCategories = array_unique(array_merge($defaultCategories, $existingCategories));
?>
<?php if (session()->getFlashdata('error')): ?>
<div class="alert alert-danger"><?= session()->getFlashdata('error') ?></div>
<?php endif; ?>
@@ -23,7 +29,7 @@
<label class="form-label">Category</label>
<select name="event_category" class="form-control" required>
<option value="" disabled <?= empty($event['event_category']) ? 'selected' : '' ?>>Select category</option>
<?php foreach (($categories ?? []) as $category): ?>
<?php foreach ($allCategories as $category): ?>
<option value="<?= esc($category) ?>" <?= (string)($event['event_category'] ?? '') === (string)$category ? 'selected' : '' ?>>
<?= esc(ucwords($category)) ?>
</option>
@@ -33,7 +39,7 @@
<div class="mb-3">
<label class="form-label">Description</label>
<textarea name="description" class="form-control"><?= esc($event['description']) ?></textarea>
<textarea id="event_description" name="description" class="form-control"><?= esc($event['description']) ?></textarea>
</div>
<div class="mb-3">
@@ -44,7 +50,7 @@
<div class="mb-3">
<label class="form-label">Current Flyer</label><br>
<?php if ($event['flyer']): ?>
<img src="<?= base_url('writable/uploads/' . $event['flyer']) ?>" width="150" class="mb-2">
<img src="<?= base_url('uploads/' . ltrim((string) $event['flyer'], '/')) ?>" width="150" class="mb-2">
<?php else: ?>
<div class="text-muted">No flyer uploaded.</div>
<?php endif; ?>
@@ -70,6 +76,37 @@
<input type="text" name="school_year" class="form-control" value="<?= esc($event['school_year']) ?>" required>
</div>
<div class="card mb-3">
<div class="card-header">School Calendar</div>
<div class="card-body">
<div class="form-check mb-2">
<input class="form-check-input" type="checkbox" id="add_to_calendar" name="add_to_calendar" value="1">
<label class="form-check-label" for="add_to_calendar">
Add this event to the school calendar
</label>
</div>
<div id="calendar_recipients" class="ms-3" style="display:none;">
<div class="mb-2 fw-semibold">Visible On Calendars</div>
<div class="d-flex flex-wrap gap-3">
<label class="form-check-label">
<input class="form-check-input me-1" type="checkbox" name="notify_parent" value="1" checked>
Parents
</label>
<label class="form-check-label">
<input class="form-check-input me-1" type="checkbox" name="notify_teacher" value="1" checked>
Teachers
</label>
<label class="form-check-label">
<input class="form-check-input me-1" type="checkbox" name="notify_admin" value="1" checked>
Admins
</label>
</div>
<div class="form-text">If none are selected, the event is visible to everyone.</div>
</div>
</div>
</div>
<div class="card mb-3">
<div class="card-header">Parent Email Broadcast</div>
<div class="card-body">
@@ -89,3 +126,39 @@
</div>
<?= $this->endSection() ?>
<?= $this->section('scripts') ?>
<script src="<?= base_url('assets/tinymce/tinymce.min.js') ?>"></script>
<script>
(function () {
const toggle = document.getElementById('add_to_calendar');
const recipients = document.getElementById('calendar_recipients');
const description = document.getElementById('event_description');
if (toggle && recipients) {
function sync() {
recipients.style.display = toggle.checked ? '' : 'none';
}
toggle.addEventListener('change', sync);
sync();
}
if (description && window.tinymce) {
tinymce.init({
selector: '#event_description',
base_url: '<?= base_url('assets/tinymce') ?>',
suffix: '.min',
license_key: 'gpl',
height: 320,
menubar: true,
branding: false,
promotion: false,
plugins: 'advlist autolink lists link charmap preview anchor searchreplace visualblocks code fullscreen insertdatetime table help wordcount',
toolbar: 'undo redo | blocks | bold italic underline strikethrough forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link table | removeformat | preview code',
convert_urls: false,
content_style: 'body { font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif; font-size: 14px; }'
});
}
})();
</script>
<?= $this->endSection() ?>
@@ -427,6 +427,7 @@ function loadStudentsWithCharges() {
}
const $externalHidden = $('#externalParticipantsHidden');
const $externalSaveButton = $('#externalParticipantSave');
const storageKey = 'eventChargesExternalParticipants';
let externalDrafts = [];
let editingKey = null;
@@ -497,13 +498,12 @@ function loadStudentsWithCharges() {
<td>$${amountDisplay}</td>
<td>${createdDisplay}</td>
<td class="text-center">
<span class="badge bg-warning text-dark">Pending</span>
${isPaid ? '<span class="badge bg-success ms-1 external-paid-badge">Paid on save</span>' : '<span class="badge bg-secondary ms-1 external-paid-badge d-none">Paid on save</span>'}
<span class="badge ${isPaid ? 'bg-success' : 'bg-danger'} external-paid-badge">${isPaid ? 'Paid' : 'Unpaid'}</span>
</td>
<td class="text-center">
<div class="form-check d-inline-flex align-items-center gap-2 justify-content-center m-0">
<input class="form-check-input external-paid-toggle" type="checkbox" data-key="${key}" ${isPaid ? 'checked' : ''}>
<span class="small text-muted">On save</span>
<span class="small text-muted">Paid</span>
</div>
</td>
<td class="text-end d-flex gap-2">
@@ -575,6 +575,7 @@ function loadStudentsWithCharges() {
return;
}
editingKey = key;
$externalSaveButton.text('Save');
$('#modalExternalFirstName').val(entry.firstname);
$('#modalExternalLastName').val(entry.lastname);
$('#modalExternalNote').val(entry.note);
@@ -592,6 +593,7 @@ function loadStudentsWithCharges() {
if (modalElement) {
modalElement.addEventListener('hidden.bs.modal', () => {
editingKey = null;
$externalSaveButton.text('Add to list');
});
}
function clearModalInputs() {
@@ -651,6 +653,7 @@ function loadStudentsWithCharges() {
}
saveExternalDraft(entry);
editingKey = null;
$externalSaveButton.text('Add to list');
clearModalInputs();
if (modalInstance) {
modalInstance.hide();
@@ -687,9 +690,9 @@ function loadStudentsWithCharges() {
.val(paid ? '1' : '0');
const $badge = $(`tr.external-preview[data-key="${key}"] .external-paid-badge`);
if (paid) {
$badge.removeClass('d-none').addClass('bg-success').text('Paid on save');
$badge.removeClass('bg-danger').addClass('bg-success').text('Paid');
} else {
$badge.addClass('d-none');
$badge.removeClass('bg-success').addClass('bg-danger').text('Unpaid');
}
});
$('#event-participant-form').on('submit', function() {
+1 -1
View File
@@ -16,7 +16,7 @@ $amount = ($amountRaw !== null && $amountRaw !== '') ? number_format((float) $am
<p style="margin:0.25rem 0;"><strong>Amount:</strong> $<?= esc($amount) ?></p>
<?php endif; ?>
<?php if (!empty($event['description'])): ?>
<p style="margin:0.75rem 0;"><?= nl2br(esc((string) $event['description'])) ?></p>
<div style="margin:0.75rem 0;"><?= $event['description'] ?></div>
<?php endif; ?>
<?php if (!empty($flyerUrl)): ?>
<div style="margin:1rem 0;">
+50 -8
View File
@@ -24,6 +24,7 @@
</div>
<?php else: ?>
<?php foreach ($activeEvents as $event): ?>
<?php $externalParticipants = $externalParticipantsByEvent[$event['id']] ?? []; ?>
<div class="card mb-4">
<div class="card-body">
@@ -42,6 +43,53 @@
<?php endif; ?>
</div>
<div class="mb-3">
<h6 class="mb-1">Description</h6>
<?php if (!empty($event['description'])): ?>
<div class="mb-0"><?= $event['description'] ?></div>
<?php else: ?>
<p class="mb-0">No description</p>
<?php endif; ?>
</div>
<?php if (!empty($externalParticipants)): ?>
<div class="mb-3">
<h6 class="mb-2">External Participants</h6>
<div class="table-responsive">
<table class="table table-sm table-bordered mb-0">
<thead class="table-light">
<tr>
<th>Student Name</th>
<th>Status</th>
<th>Fee</th>
</tr>
</thead>
<tbody>
<?php foreach ($externalParticipants as $participant): ?>
<?php
$isPaid = !empty($participant['event_paid']) || ((float) ($participant['charged'] ?? 0) <= 0);
?>
<tr>
<td>
<?= esc($participant['name']) ?> <span class="text-muted">(external)</span>
<?php if (!empty($participant['note'])): ?>
<small class="text-muted d-block"><?= esc($participant['note']) ?></small>
<?php endif; ?>
</td>
<td>
<span class="badge bg-<?= $isPaid ? 'success' : 'danger' ?>">
<?= $isPaid ? 'Paid' : 'Unpaid' ?>
</span>
</td>
<td class="text-nowrap">$<?= esc(number_format((float) ($participant['charged'] ?? 0), 2)) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<?php endif; ?>
<!-- Participation Table -->
<form method="post" action="<?= site_url('parent/updateParticipation') ?>">
<?= csrf_field() ?>
@@ -51,11 +99,8 @@
<table class="table table-sm table-bordered">
<thead class="table-light">
<tr>
<th>Student First Name</th>
<th>Student Last Name</th>
<th>Student Name</th>
<th class="text-center">Participate</th>
<th>Description</th>
<th>Event Fees</th>
</tr>
</thead>
<tbody>
@@ -65,8 +110,7 @@
$current = $charges[$key]['participation'] ?? '';
?>
<tr>
<td><?= esc($student['firstname']) ?></td>
<td><?= esc($student['lastname']) ?></td>
<td><?= esc(trim(($student['firstname'] ?? '') . ' ' . ($student['lastname'] ?? ''))) ?></td>
<td class="text-center align-middle">
<div class="d-inline-flex align-items-center gap-3">
<div class="form-check">
@@ -83,8 +127,6 @@
</div>
</div>
</td>
<td><?= esc($event['description'] ?: 'No description') ?></td>
<td class="text-nowrap">$<?= esc(number_format((float) ($event['amount'] ?? 0), 2)) ?></td>
</tr>
<?php endforeach; ?>
</tbody>