From ebd7efe21c8dae9a243e85f0e03c76d1cef31ea4 Mon Sep 17 00:00:00 2001
From: twotalesanimation <80506065+twotalesanimation@users.noreply.github.com>
Date: Mon, 15 Dec 2025 18:07:11 +0200
Subject: [PATCH] added auto course codes
---
src/admin/manage_courses.php | 69 ++++++++++++++++++++++++++++++-
src/processors/process_course.php | 16 +++++++
2 files changed, 84 insertions(+), 1 deletion(-)
diff --git a/src/admin/manage_courses.php b/src/admin/manage_courses.php
index df1f726f..3809bc4b 100644
--- a/src/admin/manage_courses.php
+++ b/src/admin/manage_courses.php
@@ -61,7 +61,8 @@ if ($course_id) {
@@ -151,4 +152,70 @@ if ($course_id) {
});
+
+
diff --git a/src/processors/process_course.php b/src/processors/process_course.php
index 5c93080a..be546a78 100644
--- a/src/processors/process_course.php
+++ b/src/processors/process_course.php
@@ -43,6 +43,22 @@ try {
throw new Exception('Invalid date format');
}
+ // If code not provided, generate from type + date using ABBR_MMDD format
+ if (empty($code)) {
+ $abbrMap = [
+ 'driver_training' => 'DRVTRN',
+ 'bush_mechanics' => 'BUSHMEC',
+ 'rescue_recovery' => 'RESREC',
+ 'ladies_driver_training' => 'LADYTRN'
+ ];
+
+ $abbr = $abbrMap[$course_type] ?? strtoupper(preg_replace('/[^A-Z0-9]/', '', $course_type));
+ // ensure abbr fits (reserve 1 char for underscore and 4 for MMDD)
+ $abbr = substr($abbr, 0, 7);
+ $mmdd = date('md', strtotime($date));
+ $code = strtoupper(substr($abbr . '_' . $mmdd, 0, 12));
+ }
+
if ($capacity <= 0) {
throw new Exception('Capacity must be greater than 0');
}