diff --git a/app/Controllers/View/EventController.php b/app/Controllers/View/EventController.php index fb86f3a..234bf96 100644 --- a/app/Controllers/View/EventController.php +++ b/app/Controllers/View/EventController.php @@ -13,6 +13,7 @@ use App\Models\InvoiceModel; use App\Models\InvoiceEventModel; use App\Models\ClassSectionModel; use App\Models\PaymentModel; +use App\Models\CalendarModel; use Config\Database; #use ??? use App\Controllers\View\InvoiceController; @@ -127,6 +128,45 @@ class EventController extends ResourceController 'created_by' => session()->get('user_id'), ]); + if ($eventId && $this->request->getPost('add_to_calendar')) { + $calendarModel = new CalendarModel(); + + $title = trim((string)$this->request->getPost('event_name')); + $date = (string)$this->request->getPost('expiration_date'); + $schoolYear = (string)$this->request->getPost('school_year'); + $semester = (string)$this->request->getPost('semester'); + + if ($title !== '' && $date !== '' && $schoolYear !== '') { + $data = [ + 'title' => $title, + 'description' => (string)$this->request->getPost('description'), + 'event_type' => 'Event', + 'date' => $date, + 'notify_parent' => $this->request->getPost('notify_parent') ? 1 : 0, + 'notify_teacher' => $this->request->getPost('notify_teacher') ? 1 : 0, + 'notify_admin' => $this->request->getPost('notify_admin') ? 1 : 0, + 'no_school' => 0, + 'school_year' => $schoolYear, + 'semester' => $semester ?: $this->semester, + ]; + if (!$calendarModel->supportsEventType()) { + unset($data['event_type']); + } + + $dupQuery = $calendarModel + ->where('school_year', $data['school_year']) + ->where('date', $data['date']) + ->where('title', $data['title']); + if ($calendarModel->supportsEventType() && isset($data['event_type'])) { + $dupQuery = $dupQuery->where('event_type', $data['event_type']); + } + $existing = $dupQuery->first(); + if (!$existing) { + $calendarModel->save($data); + } + } + } + return redirect()->to('/administrator/events')->with('success', 'Event created successfully'); } diff --git a/app/Views/administrator/events/create_event.php b/app/Views/administrator/events/create_event.php index 355b85b..c95312a 100644 --- a/app/Views/administrator/events/create_event.php +++ b/app/Views/administrator/events/create_event.php @@ -56,9 +56,56 @@ +
+
School Calendar
+
+
+ + +
+ + +
+
+ Cancel endSection() ?> + +section('scripts') ?> + +endSection() ?> diff --git a/public/uploads/event_flyers/1776521085_7dd87533c474a020760c.png b/public/uploads/event_flyers/1776521085_7dd87533c474a020760c.png new file mode 100644 index 0000000..bdb2be8 Binary files /dev/null and b/public/uploads/event_flyers/1776521085_7dd87533c474a020760c.png differ diff --git a/public/uploads/event_flyers/1776521523_0f6a660c28335611c5a5.png b/public/uploads/event_flyers/1776521523_0f6a660c28335611c5a5.png new file mode 100644 index 0000000..be36e21 Binary files /dev/null and b/public/uploads/event_flyers/1776521523_0f6a660c28335611c5a5.png differ